diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index bed696d..11c9f46 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -152,6 +152,10 @@ public: std::wstring loadWStr( ULONG64 offset ); + std::string loadAnsiStr( ULONG64 address ); + + std::wstring loadUnicodeStr( ULONG64 address ); + ULONG ptrSize(); ULONG64 ptrByte( ULONG64 offset ); diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index d646326..aad4161 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -207,6 +207,10 @@ BOOST_PYTHON_MODULE( pykd ) "Load string from the target buffer containing 0-terminated ansi-string" ) .def( "loadWStr", &DebugClient::loadWStr, "Load string from the target buffer containing 0-terminated unicode-string" ) + .def( "loadUnicodeString", &DebugClient::loadUnicodeStr, + "Return string represention of windows UNICODE_STRING type" ) + .def( "loadAnsiString", &DebugClient::loadAnsiStr, + "Return string represention of windows ANSU_STRING type" ) .def( "ptrByte", &DebugClient::ptrByte, "Read an unsigned 1-byte integer from the target memory" ) .def( "ptrWord", &DebugClient::ptrWord, @@ -342,6 +346,10 @@ BOOST_PYTHON_MODULE( pykd ) "Load string from the target buffer containing 0-terminated ansi-string" ); python::def( "loadWStr", &loadWStr, "Load string from the target buffer containing 0-terminated unicode-string" ); + python::def( "loadUnicodeString", &loadUnicodeStr, + "Return string represention of windows UNICODE_STRING type" ); + python::def( "loadAnsiString", &loadAnsiStr, + "Return string represention of windows ANSU_STRING type" ); python::def( "ptrByte", &ptrByte, "Read an unsigned 1-byte integer from the target memory" ); python::def( "ptrWord", &ptrWord, diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 836de29..a8dabc7 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -526,5 +526,102 @@ bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr ) ///////////////////////////////////////////////////////////////////////////////////// +std::wstring DebugClient::loadUnicodeStr( ULONG64 address ) +{ + USHORT length; + USHORT maximumLength; + ULONG64 buffer = 0; + + readMemory( m_dataSpaces, address, &length, sizeof( length ) ); + + if ( length == 0 ) + return L""; + + address += sizeof( length ); + + readMemory( m_dataSpaces, address, &maximumLength, sizeof( maximumLength ) ); + + address += sizeof( maximumLength ); + + if ( is64bitSystem() ) + { + address += address % 8 ? ( 8 - address % 8 ) : 0 ; // выравнивание на 8 байт + + buffer = ptrPtr( address ); + + address += 8; + } + else + { + address += address % 4 ? ( 4 - address % 4 ) : 0 ; // выравнивание на 8 байт + + buffer = addr64( ptrPtr( address ) ); + + address += 4; + } + + std::vector str(length / 2); + + readMemory( m_dataSpaces, buffer, &str[0], length ); + + return std::wstring (&str[0], length/2); +} + +std::wstring loadUnicodeStr( ULONG64 address ) +{ + return g_dbgClient->loadUnicodeStr( address ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +std::string DebugClient::loadAnsiStr( ULONG64 address ) +{ + USHORT length; + USHORT maximumLength; + ULONG64 buffer = 0; + + readMemory( m_dataSpaces, address, &length, sizeof( length ) ); + + if ( length == 0 ) + return ""; + + address += sizeof( length ); + + readMemory( m_dataSpaces, address, &maximumLength, sizeof( maximumLength ) ); + + address += sizeof( maximumLength ); + + if ( is64bitSystem() ) + { + address += address % 8 ? ( 8 - address % 8 ) : 0 ; // выравнивание на 8 байт + + buffer = ptrPtr( address ); + + address += 8; + } + else + { + address += address % 4 ? ( 4 - address % 4 ) : 0 ; // выравнивание на 8 байт + + buffer = addr64( ptrPtr( address ) ); + + address += 4; + } + + std::vector str(length); + + readMemory( m_dataSpaces, buffer, &str[0], length ); + + return std::string (&str[0], length); +} + + +std::string loadAnsiStr( ULONG64 address ) +{ + return g_dbgClient->loadAnsiStr( address ); +} + +///////////////////////////////////////////////////////////////////////////////////// + }; // end of pykd diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index 4c6ee63..3268e26 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -82,6 +82,10 @@ ULONG64 ptrPtr( ULONG64 offset, IDebugDataSpaces4* dbgDataSpace ); bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr = FALSE ); +std::wstring loadUnicodeStr( ULONG64 address ); + +std::string loadAnsiStr( ULONG64 address ); + /////////////////////////////////////////////////////////////////////////////////// }; diff --git a/pykd/pykd.rc b/pykd/pykd.rc index a193c1b..2683666 100644 --- a/pykd/pykd.rc +++ b/pykd/pykd.rc @@ -53,8 +53,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,1,0,0 - PRODUCTVERSION 0,1,0,0 + FILEVERSION 0,1,0,1 + PRODUCTVERSION 0,1,0,1 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -70,11 +70,11 @@ BEGIN BLOCK "041904b0" BEGIN VALUE "FileDescription", "pykd - python extension for windbg" - VALUE "FileVersion", "0, 1, 0, 0" + VALUE "FileVersion", "0, 1, 0, 1" VALUE "InternalName", "pykd" VALUE "OriginalFilename", "pykd.dll" VALUE "ProductName", "pykd - python extension for windbg" - VALUE "ProductVersion", "0, 1, 0, 0" + VALUE "ProductVersion", "0, 1, 0, 1" END END BLOCK "VarFileInfo" diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index f123fed..f2d1b40 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -149,7 +149,6 @@ listStruct1 g_listItem13 = { 300 }; _EX_ListHead->Blink = (Entry);\ } - void FuncWithName0() { classChild _classChild; @@ -180,6 +179,11 @@ void FuncWithName0() std::cout << strArray[0]; std::cout << (*ptrIntMatrix)[0][1]; std::cout << g_struct3.m_noArrayField; + std::cout << g_structWithBits.m_bit5; + std::cout << ptrStrArray; + std::cout << g_structTest1.m_field2; + std::cout << ptrIntMatrix1; + std::cout << g_bigValue; } void FuncWithName1(int a)