From 69e93336d95db995a7ca2f9212b87e28c90f1b6e Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Tue, 9 Nov 2010 09:33:19 +0000 Subject: [PATCH] [+] added: loadCStr, loadWStr routine added ( loading c-style string ) git-svn-id: https://pykd.svn.codeplex.com/svn@57285 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 3 ++ pykd/dbgext.h | 1 + pykd/dbgmem.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgmem.h | 6 ++++ 4 files changed, 94 insertions(+) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 502189f..4d2b04d 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -102,6 +102,8 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "loadPtrs", &loadPtrArray ); boost::python::def( "loadUnicodeString", &loadUnicodeStr ); boost::python::def( "loadAnsiString", &loadAnsiStr ); + boost::python::def( "loadCStr", &loadCStr ); + boost::python::def( "loadWStr", &loadWStr ); boost::python::def( "loadLinkedList", &loadLinkedList ); boost::python::def( "ptrByte", &loadByPtr ); boost::python::def( "ptrSignByte", &loadByPtr ); @@ -189,6 +191,7 @@ SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt ) client->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&dbgExt->symbols3 ); client->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dbgExt->dataSpaces ); + client->QueryInterface( __uuidof(IDebugDataSpaces4), (void **)&dbgExt->dataSpaces4 ); client->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&dbgExt->advanced2 ); diff --git a/pykd/dbgext.h b/pykd/dbgext.h index f3798a2..db267f7 100644 --- a/pykd/dbgext.h +++ b/pykd/dbgext.h @@ -17,6 +17,7 @@ struct DbgExt { IDebugSymbols3 *symbols3; IDebugDataSpaces *dataSpaces; + IDebugDataSpaces4 *dataSpaces4; IDebugAdvanced2 *advanced2; diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index a59789b..e7cbe73 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -322,6 +322,90 @@ loadAnsiStr( ULONG64 address ) /////////////////////////////////////////////////////////////////////////////////// +boost::python::object +loadCStr( ULONG64 address ) +{ + const size_t maxLength = 0x1000; + boost::python::object strObj( std::string("") ); + + address = addr64( address ); + + char* buffer = new char[maxLength]; + + try { + + HRESULT hres = + dbgExt->dataSpaces4->ReadMultiByteStringVirtual( + address, + maxLength, + buffer, + maxLength, + NULL ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugDataSpace4::ReadMultiByteStringVirtual failed" ); + + strObj = boost::python::object( std::string( buffer ) ); + + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + delete[] buffer; + + return strObj; +} + +/////////////////////////////////////////////////////////////////////////////////// + +boost::python::object +loadWStr( ULONG64 address ) +{ + const size_t maxLength = 0x1000; + boost::python::object strObj( std::wstring(L"") ); + + address = addr64( address ); + + wchar_t* buffer = new wchar_t[maxLength]; + + try { + + HRESULT hres = + dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( + address, + maxLength*sizeof(wchar_t), + buffer, + maxLength, + NULL ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugDataSpace4::ReadUnicodeStringVirtualWide failed" ); + + strObj = boost::python::object( std::wstring(buffer) ); + + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + delete[] buffer; + + return strObj; +} + +/////////////////////////////////////////////////////////////////////////////////// + boost::python::object loadLinkedList( ULONG64 address ) { diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index addb7d4..2b9be0b 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -59,6 +59,12 @@ loadUnicodeStr( ULONG64 address ); boost::python::object loadAnsiStr( ULONG64 address ); +boost::python::object +loadCStr( ULONG64 address ); + +boost::python::object +loadWStr( ULONG64 address ); + bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE );