From 64bdab59cc0938a5cd8a422c25b4fba5cc2c4126 Mon Sep 17 00:00:00 2001 From: Alexey R Date: Sun, 25 Feb 2018 10:03:36 +0300 Subject: [PATCH 1/2] upd: kdlibcpp (dev-1.0 -> FETCH_HEAD) --- .gitmodules | 6 +++--- LICENSE | 42 +++++++++++++++++++++--------------------- README.md | 34 +++++++++++++++++----------------- kdlibcpp | 2 +- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4581c11..a1c8259 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "kdlibcpp"] - path = kdlibcpp - url = https://githomelab.ru/kdlibcpp/kdlibcpp.git +[submodule "kdlibcpp"] + path = kdlibcpp + url = https://githomelab.ru/kdlibcpp/kdlibcpp.git diff --git a/LICENSE b/LICENSE index 9228a1b..4928aa4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -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. diff --git a/README.md b/README.md index 9da6bde..a07bf98 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# 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) diff --git a/kdlibcpp b/kdlibcpp index 3bb3cbf..9bfa80d 160000 --- a/kdlibcpp +++ b/kdlibcpp @@ -1 +1 @@ -Subproject commit 3bb3cbf8e4a206d7bcf08f0d8303e3c59dd4e2b4 +Subproject commit 9bfa80d7f415e8697f7c84696d67afda07dbc559 From 15eae98a0fd52678c4baf7c4cfbbc3ebf4dbb3ff Mon Sep 17 00:00:00 2001 From: Date: Mon, 26 Feb 2018 20:14:15 +0300 Subject: [PATCH 2/2] add: secondary callback data (issue #14) --- pykd/pykd_vc120.vcxproj | 2 + pykd/pykd_vc120.vcxproj.filters | 6 +++ pykd/pymod.cpp | 7 +++ pykd/pytagged.cpp | 76 +++++++++++++++++++++++++++++++++ pykd/pytagged.h | 12 ++++++ test/scripts/pykdtest.py | 2 + test/scripts/pykdtest.pyproj | 1 + test/scripts/taggedtest.py | 31 ++++++++++++++ 8 files changed, 137 insertions(+) create mode 100644 pykd/pytagged.cpp create mode 100644 pykd/pytagged.h create mode 100644 test/scripts/taggedtest.py diff --git a/pykd/pykd_vc120.vcxproj b/pykd/pykd_vc120.vcxproj index 92ddd55..e656bf6 100644 --- a/pykd/pykd_vc120.vcxproj +++ b/pykd/pykd_vc120.vcxproj @@ -590,6 +590,7 @@ + @@ -623,6 +624,7 @@ + diff --git a/pykd/pykd_vc120.vcxproj.filters b/pykd/pykd_vc120.vcxproj.filters index 464d7d1..3f4b9b1 100644 --- a/pykd/pykd_vc120.vcxproj.filters +++ b/pykd/pykd_vc120.vcxproj.filters @@ -81,6 +81,9 @@ Header Files + + Header Files + @@ -248,6 +251,9 @@ Source Files + + Source Files + diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index a2218c4..624168a 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -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_( "numVariant", "numVariant", python::no_init ) .def("__init__", python::make_constructor(&NumVariantAdaptor::getVariant) ) .def( "__eq__", &NumVariantAdaptor::eq ) diff --git a/pykd/pytagged.cpp b/pykd/pytagged.cpp new file mode 100644 index 0000000..a20b8d5 --- /dev/null +++ b/pykd/pytagged.cpp @@ -0,0 +1,76 @@ + +#include "stdafx.h" + +#include "pytagged.h" +#include "kdlib\tagged.h" +#include "kdlib\exceptions.h" + +#include "pythreadstate.h" +#include "stladaptor.h" + +#include +#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 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 freeGuard{&id_str, stringFree}; + + result.append( std::wstring(reinterpret_cast(id_str)) ); + } + return result; +} + +python::list loadTaggedBuffer(const std::wstring &id_str) +{ + const auto rcp_str = + reinterpret_cast( const_cast(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 diff --git a/pykd/pytagged.h b/pykd/pytagged.h new file mode 100644 index 0000000..d688e51 --- /dev/null +++ b/pykd/pytagged.h @@ -0,0 +1,12 @@ + +#pragma once + +namespace python = boost::python; + +namespace pykd { + +python::list enumTagged(); + +python::list loadTaggedBuffer(const std::wstring &id_str); + +} // namespace pykd diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 810f0ee..df433b9 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -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 ), ] ) diff --git a/test/scripts/pykdtest.pyproj b/test/scripts/pykdtest.pyproj index 0708c66..61f3761 100644 --- a/test/scripts/pykdtest.pyproj +++ b/test/scripts/pykdtest.pyproj @@ -50,6 +50,7 @@ + diff --git a/test/scripts/taggedtest.py b/test/scripts/taggedtest.py new file mode 100644 index 0000000..49d7a4a --- /dev/null +++ b/test/scripts/taggedtest.py @@ -0,0 +1,31 @@ +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 ) +