Commit 3018bcdc authored by Aleksey R.'s avatar Aleksey R.
Browse files

Merge branch '0.3.2' into '0.3.2'

Enumerate and read secondary callback (Issue #14)

See merge request pykd/pykd!1
parents e90aa768 15eae98a
[submodule "kdlibcpp"]
path = kdlibcpp
url = https://githomelab.ru/kdlibcpp/kdlibcpp.git
[submodule "kdlibcpp"]
path = kdlibcpp
url = https://githomelab.ru/kdlibcpp/kdlibcpp.git
MIT License
Copyright (c) 2017 pykd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2017 pykd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Pykd - python extension for WinDBG
## Purpose
This project can help to automate debugging and crash dump analysis using Python. It allows one to take the best from both worlds: the expressiveness and convenience of Python with the power of WinDbg!
## Why do I need this?
If you want to automate the debugger but dislike the WinDbg built-in script machine syntax it's time to try again using the handy and powerful Python language. Even if you don't want to create your own script, maybe some existing scripts will be of interest to you?
## Pykd bootstrapper
[Download](/../wikis/Pykd bootstrapper)
## Releases:
[Last Release](/../wikis/Last Release)
## Documentation
[User Manual](/../wikis/User Manual rus)
[API Reference](/../wikis/API Reference)
# Pykd - python extension for WinDBG
## Purpose
This project can help to automate debugging and crash dump analysis using Python. It allows one to take the best from both worlds: the expressiveness and convenience of Python with the power of WinDbg!
## Why do I need this?
If you want to automate the debugger but dislike the WinDbg built-in script machine syntax it's time to try again using the handy and powerful Python language. Even if you don't want to create your own script, maybe some existing scripts will be of interest to you?
## Pykd bootstrapper
[Download](/../wikis/Pykd bootstrapper)
## Releases:
[Last Release](/../wikis/Last Release)
## Documentation
[User Manual](/../wikis/User Manual rus)
[API Reference](/../wikis/API Reference)
Subproject commit 3bb3cbf8e4a206d7bcf08f0d8303e3c59dd4e2b4
Subproject commit 9bfa80d7f415e8697f7c84696d67afda07dbc559
......@@ -590,6 +590,7 @@
<ClInclude Include="pymodule.h" />
<ClInclude Include="pyprocess.h" />
<ClInclude Include="pysymengine.h" />
<ClInclude Include="pytagged.h" />
<ClInclude Include="pythreadstate.h" />
<ClInclude Include="pytypedvar.h" />
<ClInclude Include="pytypeinfo.h" />
......@@ -623,6 +624,7 @@
</ClCompile>
<ClCompile Include="pymodule.cpp" />
<ClCompile Include="pyprocess.cpp" />
<ClCompile Include="pytagged.cpp" />
<ClCompile Include="pytypedvar.cpp" />
<ClCompile Include="pytypeinfo.cpp" />
<ClCompile Include="stdafx.cpp">
......
......@@ -81,6 +81,9 @@
<ClInclude Include="pydataaccess.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pytagged.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
......@@ -248,6 +251,9 @@
<ClCompile Include="pyprocess.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pytagged.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="pykd.def">
......
......@@ -20,6 +20,7 @@
#include "pytypeinfo.h"
#include "pycpucontext.h"
#include "pyprocess.h"
#include "pytagged.h"
using namespace pykd;
......@@ -597,6 +598,12 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "removeSyntheticSymbol", pykd::removeSyntheticSymbol,
"The removeSyntheticSymbol function removes a synthetic symbol from a module in the current proces" );
// secondary callback data
python::def("enumTagged", pykd::enumTagged,
"Return the list of secondary callback data IDs (as a strings)" );
python::def("loadTaggedBuffer", pykd::loadTaggedBuffer,
"Read the buffer of secondary callback data by ID" );
python::class_<kdlib::NumBehavior, boost::noncopyable>( "numVariant", "numVariant", python::no_init )
.def("__init__", python::make_constructor(&NumVariantAdaptor::getVariant) )
.def( "__eq__", &NumVariantAdaptor::eq )
......
#include "stdafx.h"
#include "pytagged.h"
#include "kdlib\tagged.h"
#include "kdlib\exceptions.h"
#include "pythreadstate.h"
#include "stladaptor.h"
#include <rpc.h>
#pragma comment(lib, "Rpcrt4.lib")
namespace pykd {
void __declspec(noreturn) throwRpcStatus( const std::string &functionName, RPC_STATUS status )
{
std::stringstream sstr;
sstr << "Call " << functionName << " failed\n";
sstr << "RPC_STATUS 0x" << std::hex << status;
throw kdlib::DbgException( sstr.str() );
}
python::list enumTagged()
{
std::list<kdlib::TaggedId> ids;
{
AutoRestorePyState pystate;
ids = std::move( kdlib::enumTagged() );
}
python::list result;
for (const auto &id : ids)
{
RPC_WSTR id_str = nullptr;
auto status = ::UuidToString(&id, &id_str);
if (RPC_S_OK != status)
throwRpcStatus("UuidToString", status);
const auto stringFree =
[](RPC_WSTR *str)
{
auto status = ::RpcStringFree(str);
if (RPC_S_OK != status)
throwRpcStatus("RpcStringFree", status);
};
std::unique_ptr<RPC_WSTR, decltype(stringFree)> freeGuard{&id_str, stringFree};
result.append( std::wstring(reinterpret_cast<wchar_t *>(id_str)) );
}
return result;
}
python::list loadTaggedBuffer(const std::wstring &id_str)
{
const auto rcp_str =
reinterpret_cast<RPC_WSTR>( const_cast<wchar_t *>(id_str.c_str()) );
kdlib::TaggedId id;
auto status = ::UuidFromString(rcp_str, &id);
if (RPC_S_OK != status)
throwRpcStatus("UuidFromString", status);
kdlib::TaggedBuffer buff;
{
AutoRestorePyState pystate;
buff = std::move( kdlib::loadTaggedBuffer(id) );
}
return vectorToList(buff);
}
} // namespace pykd
#pragma once
namespace python = boost::python;
namespace pykd {
python::list enumTagged();
python::list loadTaggedBuffer(const std::wstring &id_str);
} // namespace pykd
......@@ -27,6 +27,7 @@ import excepttest
import targetprocess
import ehloadtest
import synsymtest
import taggedtest
pykd.initialize()
......@@ -65,6 +66,7 @@ def getTestSuite( singleName = "" ):
unittest.TestLoader().loadTestsFromTestCase( mspdbtest.MsPdbTest ),
unittest.TestLoader().loadTestsFromTestCase( targetprocess.ProcessTest ),
unittest.TestLoader().loadTestsFromTestCase( ehloadtest.EhLoadTest ),
unittest.TestLoader().loadTestsFromTestCase( taggedtest.TaggedTest ),
#unittest.TestLoader().loadTestsFromTestCase( excepttest.ExceptionTest ),
] )
......
......@@ -50,6 +50,7 @@
<Compile Include="regtest.py" />
<Compile Include="stacktest.py" />
<Compile Include="synsymtest.py" />
<Compile Include="taggedtest.py" />
<Compile Include="target.py" />
<Compile Include="targetprocess.py" />
<Compile Include="testutils.py" />
......
import unittest
import pykd
import sys
import os
class TaggedTest(unittest.TestCase):
def setUp(self):
dump_file = os.path.join( os.path.dirname(sys.argv[0]),
r"..\..\kdlibcpp\kdlib\tests\dumps\win8_x64_mem.cab" )
self.dump_id = pykd.loadDump( dump_file )
self._existing_id = "D03DC06F-D88E-44C5-BA2A-FAE035172D19"
self._non_existing_id = "88597A32-1493-41CA-BF87-2A950DF4CEE0"
def tearDown(self):
pykd.closeDump( self.dump_id )
def testEnum(self):
ids = pykd.enumTagged()
self.assertTrue( self._existing_id.lower() in [i.lower() for i in ids] )
self.assertFalse( self._non_existing_id.lower() in [i.lower() for i in ids] )
def testLoadBuffer(self):
buff = pykd.loadTaggedBuffer( self._existing_id )
self.assertEqual( len(buff), 0x410 )
self.assertRaises( pykd.DbgException, pykd.loadTaggedBuffer, self._non_existing_id )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment