From fff5521dc0cbe4f3b4a3d53d969ba9d1c5016c90 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Wed, 16 Nov 2011 07:36:21 +0000 Subject: [PATCH] [0.1.x] added : ptrByte [0.1.x] added : ptrWord [0.1.x] added : ptrDWord [0.1.x] added : ptrQWord [0.1.x] added : ptrMWord [0.1.x] added : ptrSignByte [0.1.x] added : ptrSignWord [0.1.x] added : ptrSignDWord [0.1.x] added : ptrSignQWord [0.1.x] added : ptrSignMWord [0.1.x] added : ptrPtr git-svn-id: https://pykd.svn.codeplex.com/svn@71386 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.h | 22 +- pykd/dbgext.cpp | 65 +++- pykd/dbgmem.cpp | 690 ++++++++--------------------------- pykd/dbgmem.h | 22 ++ test/scripts/memtest.py | 11 +- test/scripts/pykdtest.py | 4 +- test/targetapp/targetapp.cpp | 2 + 7 files changed, 265 insertions(+), 551 deletions(-) diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 4282d41..df2af70 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -121,26 +121,28 @@ public: ULONG ptrSize(); - LONG64 ptrByte(); + ULONG64 ptrByte( ULONG64 offset ); - LONG64 ptrWord(); + ULONG64 ptrWord( ULONG64 offset ); - LONG64 ptrDWord(); + ULONG64 ptrDWord( ULONG64 offset ); - LONG64 ptrQWord(); + ULONG64 ptrQWord( ULONG64 offset ); - LONG64 ptrMWord(); + ULONG64 ptrMWord( ULONG64 offset ); - ULONG64 ptrSignByte(); + LONG64 ptrSignByte( ULONG64 offset ); - ULONG64 ptrSignWord(); + LONG64 ptrSignWord( ULONG64 offset ); - ULONG64 ptrSignDWord(); + LONG64 ptrSignDWord( ULONG64 offset ); - ULONG64 ptrSignQWord(); + LONG64 ptrSignQWord( ULONG64 offset ); - ULONG64 ptrSignMWord(); + LONG64 ptrSignMWord( ULONG64 offset ); + ULONG64 ptrPtr( ULONG64 offset ); + void readMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE ); void setExecutionStatus( ULONG status ); diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 0a2600f..4cd38f0 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -186,26 +186,48 @@ BOOST_PYTHON_MODULE( pykd ) "Check if it is a dump analyzing ( not living debuggee )" ) .def( "isKernelDebugging", &pykd::DebugClient::isKernelDebugging, "Check if kernel dubugging is running" ) - .def( "loadBytes", &pykd::DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ), + .def( "loadBytes", &DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of unsigned bytes" ) ) - .def( "loadWords", &pykd::DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ), + .def( "loadWords", &DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of unsigned shorts" ) ) - .def( "loadDWords", &pykd::DebugClient::loadDWords, DebugClient_loadDWords( python::args( "offset", "count", "phyAddr" ), + .def( "loadDWords", &DebugClient::loadDWords, DebugClient_loadDWords( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ) - .def( "loadQWords", &pykd::DebugClient::loadQWords, DebugClient_loadQWords( python::args( "offset", "count", "phyAddr" ), + .def( "loadQWords", &DebugClient::loadQWords, DebugClient_loadQWords( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ) - .def( "loadSignBytes", &pykd::DebugClient::loadSignBytes, DebugClient_loadSignBytes( python::args( "offset", "count", "phyAddr" ), + .def( "loadSignBytes", &DebugClient::loadSignBytes, DebugClient_loadSignBytes( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of signed bytes" ) ) - .def( "loadSignWords", &pykd::DebugClient::loadSignWords, DebugClient_loadSignWords( python::args( "offset", "count", "phyAddr" ), + .def( "loadSignWords", &DebugClient::loadSignWords, DebugClient_loadSignWords( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of signed shorts" ) ) - .def( "loadSignDWords", &pykd::DebugClient::loadSignDWords, DebugClient_loadSignDWords( python::args( "offset", "count", "phyAddr" ), + .def( "loadSignDWords", &DebugClient::loadSignDWords, DebugClient_loadSignDWords( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of signed longs" ) ) - .def( "loadSignQWords", &pykd::DebugClient::loadSignQWords, DebugClient_loadSignQWords( python::args( "offset", "count", "phyAddr" ), + .def( "loadSignQWords", &DebugClient::loadSignQWords, DebugClient_loadSignQWords( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of signed long longs" ) ) - .def( "loadChars", &pykd::DebugClient::loadChars, DebugClient_loadChars( python::args( "offset", "count", "phyAddr" ), + .def( "loadChars", &DebugClient::loadChars, DebugClient_loadChars( python::args( "offset", "count", "phyAddr" ), "Load string from target memory" ) ) - .def( "loadWChars", &pykd::DebugClient::loadWChars, DebugClient_loadWChars( python::args( "offset", "count", "phyAddr" ), + .def( "loadWChars", &DebugClient::loadWChars, DebugClient_loadWChars( python::args( "offset", "count", "phyAddr" ), "Load string from target memory" ) ) + .def( "ptrByte", &DebugClient::ptrByte, + "Read an unsigned 1-byte integer from the target memory" ) + .def( "ptrWord", &DebugClient::ptrWord, + "Read an unsigned 2-byte integer from the target memory" ) + .def( "ptrDWord", &DebugClient::ptrDWord, + "Read an unsigned 4-byte integer from the target memory" ) + .def( "ptrQWord", &DebugClient::ptrQWord, + "Read an unsigned 8-byte integer from the target memory" ) + .def( "ptrMWord", &DebugClient::ptrMWord, + "Read an unsigned mashine's word wide integer from the target memory" ) + .def( "ptrSignByte", &DebugClient::ptrSignByte, + "Read an signed 1-byte integer from the target memory" ) + .def( "ptrSignWord", &DebugClient::ptrSignWord, + "Read an signed 2-byte integer from the target memory" ) + .def( "ptrSignDWord", &DebugClient::ptrSignDWord, + "Read an signed 4-byte integer from the target memory" ) + .def( "ptrSignQWord", &DebugClient::ptrSignQWord, + "Read an signed 8-byte integer from the target memory" ) + .def( "ptrSignMWord", &DebugClient::ptrSignMWord, + "Read an signed mashine's word wide integer from the target memory" ) + .def( "ptrPtr", &DebugClient::ptrPtr, + "Read an pointer value from the target memory" ) .def ( "loadExt", &pykd::DebugClient::loadExtension, "Load a debuger extension" ) .def( "loadModule", &pykd::DebugClient::loadModule, @@ -271,6 +293,29 @@ BOOST_PYTHON_MODULE( pykd ) "Load string from target memory" ) ); python::def( "loadWChars", &loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ), "Load string from target memory" ) ); + python::def( "ptrByte", &ptrByte, + "Read an unsigned 1-byte integer from the target memory" ); + python::def( "ptrWord", &ptrWord, + "Read an unsigned 2-byte integer from the target memory" ); + python::def( "ptrDWord", &ptrDWord, + "Read an unsigned 4-byte integer from the target memory" ); + python::def( "ptrQWord", &ptrQWord, + "Read an unsigned 8-byte integer from the target memory" ); + python::def( "ptrMWord", &ptrMWord, + "Read an unsigned mashine's word wide integer from the target memory" ); + python::def( "ptrSignByte", &ptrSignByte, + "Read an signed 1-byte integer from the target memory" ); + python::def( "ptrSignWord", &ptrSignWord, + "Read an signed 2-byte integer from the target memory" ); + python::def( "ptrSignDWord", &ptrSignDWord, + "Read an signed 4-byte integer from the target memory" ); + python::def( "ptrSignQWord", &ptrSignQWord, + "Read an signed 8-byte integer from the target memory" ); + python::def( "ptrSignMWord", &ptrSignMWord, + "Read an signed mashine's word wide integer from the target memory" ); + python::def( "ptrPtr", &ptrPtr, + "Read an pointer value from the target memory" ); + python::def( "loadExt", &pykd::loadExtension, "Load a debuger extension" ); python::def( "loadModule", &pykd::loadModule, diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index b4de26e..a363b1d 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -231,533 +231,167 @@ python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr ) ///////////////////////////////////////////////////////////////////////////////////// +ULONG64 DebugClient::ptrByte( ULONG64 offset ) +{ + unsigned char val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +ULONG64 ptrByte( ULONG64 offset ) +{ + return g_dbgClient->ptrByte( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +ULONG64 DebugClient::ptrWord( ULONG64 offset ) +{ + unsigned short val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +ULONG64 ptrWord( ULONG64 offset ) +{ + return g_dbgClient->ptrWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +ULONG64 DebugClient::ptrDWord( ULONG64 offset ) +{ + unsigned long val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +ULONG64 ptrDWord( ULONG64 offset ) +{ + return g_dbgClient->ptrDWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +ULONG64 DebugClient::ptrQWord( ULONG64 offset ) +{ + unsigned __int64 val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +ULONG64 ptrQWord( ULONG64 offset ) +{ + return g_dbgClient->ptrQWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +ULONG64 DebugClient::ptrMWord( ULONG64 offset ) +{ + return ptrSize() == 8 ? ptrQWord( offset ) : ptrDWord(offset); +} + +ULONG64 ptrMWord( ULONG64 offset ) +{ + return g_dbgClient->ptrMWord( offset ); +} + +ULONG64 DebugClient::ptrPtr( ULONG64 offset ) +{ + return ptrMWord( offset ); +} + +ULONG64 ptrPtr( ULONG64 offset ) +{ + return g_dbgClient->ptrMWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +LONG64 DebugClient::ptrSignByte( ULONG64 offset ) +{ + char val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +LONG64 ptrSignByte( ULONG64 offset ) +{ + return g_dbgClient->ptrSignByte( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +LONG64 DebugClient::ptrSignWord( ULONG64 offset ) +{ + short val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +LONG64 ptrSignWord( ULONG64 offset ) +{ + return g_dbgClient->ptrSignWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +LONG64 DebugClient::ptrSignDWord( ULONG64 offset ) +{ + long val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +LONG64 ptrSignDWord( ULONG64 offset ) +{ + return g_dbgClient->ptrSignDWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +LONG64 DebugClient::ptrSignQWord( ULONG64 offset ) +{ + __int64 val = 0; + + readMemory( offset, &val, sizeof(val), false ); + + return val; +} + +LONG64 ptrSignQWord( ULONG64 offset ) +{ + return g_dbgClient->ptrSignQWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +LONG64 DebugClient::ptrSignMWord( ULONG64 offset ) +{ + return ptrSize() == 8 ? ptrSignQWord( offset ) : ptrSignDWord(offset); +} + +LONG64 ptrSignMWord( ULONG64 offset ) +{ + return g_dbgClient->ptrSignMWord( offset ); +} + +///////////////////////////////////////////////////////////////////////////////////// + }; // end of pykd - - - - - - - - - - - - - - - - - - - - - - - - - - - -//#include -// -//#include "dbgext.h" -//#include "dbgexcept.h" -//#include "dbgmem.h" -//#include "dbgsystem.h" -//#include "dbgio.h" -// -//using namespace std; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//void -//loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr ) -//{ -// address = addr64( address ); -// -// HRESULT hres; -// -// if ( phyAddr == FALSE ) -// { -// hres = dbgExt->dataSpaces->ReadVirtual( address, dest, length, NULL ); -// } -// else -// { -// hres = dbgExt->dataSpaces->ReadPhysical( address, dest, length, NULL ); -// } -// -// if ( FAILED( hres ) ) -// throw MemoryException( address, !!phyAddr ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//ULONG64 -//addr64( ULONG64 addr) -//{ -// HRESULT hres; -// -// try { -// -// ULONG processorMode; -// hres = dbgExt->control->GetActualProcessorType( &processorMode ); -// if ( FAILED( hres ) ) -// throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" ); -// -// switch( processorMode ) -// { -// case IMAGE_FILE_MACHINE_I386: -// if ( *( (ULONG*)&addr + 1 ) == 0 ) -// return (ULONG64)(LONG)addr; -// -// case IMAGE_FILE_MACHINE_AMD64: -// break; -// -// default: -// throw DbgException( "Unknown processor type" ); -// break; -// } -// } -// 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" ); -// } -// -// return addr; -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//bool -//compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr ) -//{ -// HRESULT hres; -// bool result = false; -// -// addr1 = addr64( addr1 ); -// addr2 = addr64( addr2 ); -// -// boost::scoped_array m1(new char[length]); -// boost::scoped_array m2(new char[length]); -// -// try { -// -// if ( phyAddr == FALSE ) -// { -// -// hres = dbgExt->dataSpaces->ReadVirtual( addr1, m1.get(), length, NULL ); -// if ( FAILED( hres ) ) -// throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); -// -// hres = dbgExt->dataSpaces->ReadVirtual( addr2, m2.get(), length, NULL ); -// if ( FAILED( hres ) ) -// throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); -// } -// else -// { -// hres = dbgExt->dataSpaces->ReadPhysical( addr1, m1.get(), length, NULL ); -// if ( FAILED( hres ) ) -// throw DbgException( "IDebugDataSpace::ReadPhysical failed" ); -// -// hres = dbgExt->dataSpaces->ReadPhysical( addr2, m2.get(), length, NULL ); -// if ( FAILED( hres ) ) -// throw DbgException( "IDebugDataSpace::ReadPhysical failed" ); -// } -// -// result = memcmp( m1.get(), m2.get(), length ) == 0; -// -// } -// 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" ); -// } -// -// return result; -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadPtrArray( ULONG64 address, ULONG number ) -//{ -// if ( is64bitSystem() ) -// { -// boost::scoped_array buffer(new ULONG64[number]); -// -// loadMemory( address, buffer.get(), number*sizeof(ULONG64) ); -// -// boost::python::list lst; -// -// for ( ULONG i = 0; i < number; ++i ) -// lst.append( buffer[i] ); -// -// return lst; -// } -// else -// { -// boost::scoped_array buffer(new ULONG[number]); -// -// loadMemory( address, buffer.get(), number*sizeof(ULONG) ); -// -// boost::python::list lst; -// -// for ( ULONG i = 0; i < number; ++i ) -// lst.append( addr64( buffer[i] ) ); -// -// return lst; -// } -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) -//{ -// std::vector buffer(number); -// -// if (number) -// loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); -// -// return boost::python::object(std::string( buffer.begin(), buffer.end() ) ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadWChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) -//{ -// std::vector buffer(number); -// -// loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); -// -// return boost::python::object(std::wstring( buffer.begin(), buffer.end() ) ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//ULONG64 -//loadPtrByPtr( ULONG64 address ) -//{ -// ULONG64 value = 0; -// -// if ( is64bitSystem() ) -// loadMemory( address, &value, sizeof(ULONG64) ); -// else -// { -// loadMemory( address, &value, sizeof(ULONG) ); -// -// value = addr64( value ); -// } -// -// return value; -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//ULONG64 -//loadMWord( ULONG64 address ) -//{ -// ULONG64 value = 0; -// -// if ( is64bitSystem() ) -// loadMemory( address, &value, sizeof(ULONG64) ); -// else -// loadMemory( address, &value, sizeof(ULONG) ); -// -// return value; -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//LONG64 -//loadSignMWord( ULONG64 address ) -//{ -// LONG64 value = 0; -// -// if ( is64bitSystem() ) -// loadMemory( address, &value, sizeof(LONG64) ); -// else -// loadMemory( address, &value, sizeof(LONG) ); -// -// return value; -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//template<> -//boost::python::object -//loadByPtr( ULONG64 address ) -//{ -// char value; -// -// loadMemory( address, &value, sizeof(char) ); -// -// return boost::python::object( (int)value ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadUnicodeStr( ULONG64 address ) -//{ -// USHORT length; -// USHORT maximumLength; -// ULONG64 buffer = 0; -// -// do { -// -// loadMemory( address, &length, sizeof( length ) ); -// -// if ( length == 0 ) -// break; -// -// address += sizeof( length ); -// -// loadMemory( address, &maximumLength, sizeof( maximumLength ) ); -// -// address += sizeof( maximumLength ); -// -// if ( is64bitSystem() ) -// { -// address += address % 8 ? ( 8 - address % 8 ) : 0 ; // выравнивание на 8 байт -// -// loadMemory( address, &buffer, 8 ); -// -// address += 8; -// } -// else -// { -// address += address % 4 ? ( 4 - address % 4 ) : 0 ; // выравнивание на 8 байт -// -// loadMemory( address, &buffer, 4 ); -// -// buffer = addr64( buffer ); -// -// address += 4; -// } -// -// std::vector str(length / 2); -// -// loadMemory( buffer, &str[0], length ); -// -// std::wstring strValue(&str[0], length/2); -// -// return boost::python::object( strValue ); -// -// } while( FALSE ); -// -// return boost::python::object( "" ); -// -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadAnsiStr( ULONG64 address ) -//{ -// USHORT length; -// USHORT maximumLength; -// ULONG64 buffer = 0; -// -// do { -// -// loadMemory( address, &length, sizeof( length ) ); -// -// if ( length == 0 ) -// break; -// -// address += sizeof( length ); -// -// loadMemory( address, &maximumLength, sizeof( maximumLength ) ); -// -// address += sizeof( maximumLength ); -// -// if ( is64bitSystem() ) -// { -// address += address % 8 ? ( 8 - address % 8 ) : 0; // выравнивание на 8 байт -// -// loadMemory( address, &buffer, 8 ); -// -// address += 8; -// } -// else -// { -// address += address % 4 ? ( 4 - address % 4 ) : 0; // выравнивание на 8 байт -// -// loadMemory( address, &buffer, 4 ); -// -// buffer = addr64( buffer ); -// -// address += 4; -// } -// -// -// std::vector str(length); -// -// loadMemory( buffer, &str[0], length ); -// -// std::string strVal ( &str[0], length ); -// -// return boost::python::object( strVal ); -// -// } while( FALSE ); -// -// return boost::python::object( "" ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//void -//loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen ) -//{ -// address = addr64( address ); -// -// HRESULT hres = -// dbgExt->dataSpaces4->ReadMultiByteStringVirtual( -// address, -// bufferLen, -// buffer, -// bufferLen/sizeof(CHAR), -// NULL ); -// -// if ( FAILED( hres ) ) -// throw MemoryException( address ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//void -//loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen ) -//{ -// address = addr64( address ); -// -// HRESULT hres = -// dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( -// address, -// bufferLen, -// buffer, -// bufferLen/sizeof(WCHAR), -// NULL ); -// -// if ( FAILED( hres ) ) -// throw MemoryException( address ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadCStr( ULONG64 address ) -//{ -// const size_t maxLength = 0x1000; -// -// address = addr64( address ); -// -// boost::scoped_array buffer(new char[maxLength]); -// -// HRESULT hres = -// dbgExt->dataSpaces4->ReadMultiByteStringVirtual( -// address, -// maxLength, -// buffer.get(), -// maxLength, -// NULL ); -// -// if ( FAILED( hres ) ) -// throw MemoryException( address ); -// -// return boost::python::object( std::string( buffer.get() ) ); -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadWStr( ULONG64 address ) -//{ -// const size_t maxLength = 0x1000; -// -// address = addr64( address ); -// -// boost::scoped_array buffer(new wchar_t[maxLength]); -// -// HRESULT hres = -// dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( -// address, -// maxLength*sizeof(wchar_t), -// buffer.get(), -// maxLength, -// NULL ); -// -// if ( FAILED( hres ) ) -// throw MemoryException( address ); -// -// return boost::python::object( std::wstring(buffer.get()) ); -//} -// -// -///////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadLinkedList( ULONG64 address ) -//{ -// ULONG64 entryAddress = 0; -// -// boost::python::list objList; -// -// for( entryAddress = loadPtrByPtr( address ); entryAddress != address; entryAddress = loadPtrByPtr( entryAddress ) ) -// objList.append( entryAddress ); -// -// return objList; -//} -// -///////////////////////////////////////////////////////////////////////////////////// -// -//bool -//isOffsetValid( ULONG64 addr ) -//{ -// HRESULT hres; -// -// try { -// -// // нужно подавить возможный вывод в консоль об отсутствующей странице памяти -// OutputReader outputReader( dbgExt->client ); -// -// ULONG offsetInfo; -// -// hres = -// dbgExt->dataSpaces4->GetOffsetInformation( -// DEBUG_DATA_SPACE_VIRTUAL, -// DEBUG_OFFSINFO_VIRTUAL_SOURCE, -// addr, -// &offsetInfo, -// sizeof( offsetInfo ), -// NULL ); -// -// if ( FAILED( hres ) ) -// throw DbgException( "IDebugDataSpace4::GetOffsetInformation failed" ); -// -// return offsetInfo != DEBUG_VSOURCE_INVALID; -// -// } -// 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" ); -// } -// -// return false; -//} -// -///////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index 8d44e75..c784772 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -37,6 +37,28 @@ python::list loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ) python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); +ULONG64 ptrByte( ULONG64 offset ); + +ULONG64 ptrWord( ULONG64 offset ); + +ULONG64 ptrDWord( ULONG64 offset ); + +ULONG64 ptrQWord( ULONG64 offset ); + +ULONG64 ptrMWord( ULONG64 offset ); + +LONG64 ptrSignByte( ULONG64 offset ); + +LONG64 ptrSignWord( ULONG64 offset ); + +LONG64 ptrSignDWord( ULONG64 offset ); + +LONG64 ptrSignQWord( ULONG64 offset ); + +LONG64 ptrSignMWord( ULONG64 offset ); + +ULONG64 ptrPtr( ULONG64 offset ); + /////////////////////////////////////////////////////////////////////////////////// }; diff --git a/test/scripts/memtest.py b/test/scripts/memtest.py index e0f6155..18ecf87 100644 --- a/test/scripts/memtest.py +++ b/test/scripts/memtest.py @@ -63,4 +63,13 @@ class MemoryTest( unittest.TestCase ): testArray = [0, 255, 4294967295L, -9223372036854775808L, -1] self.assertEqual( len(testArray), len(loadArray) ) self.assertEqual( 0, len( [ loadArray[i] for i in xrange(len(testArray)) if loadArray[i] != testArray[i] ] ) ) - + + def testPtrRead( self ): + self.assertEqual( 0x80, pykd.ptrByte( target.module.g_bigValue ) ) + self.assertEqual( 0x8080, pykd.ptrWord( target.module.g_bigValue ) ) + self.assertEqual( 0x80808080, pykd.ptrDWord( target.module.g_bigValue ) ) + self.assertEqual( 0x8080808080808080, pykd.ptrQWord( target.module.g_bigValue ) ) + self.assertEqual( -128, pykd.ptrSignByte( target.module.g_bigValue ) ) + self.assertEqual( -32640, pykd.ptrSignWord( target.module.g_bigValue ) ) + self.assertEqual( -2139062144, pykd.ptrSignDWord( target.module.g_bigValue ) ) + self.assertEqual( -9187201950435737472, pykd.ptrSignQWord( target.module.g_bigValue ) ) diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 5a480d2..5869c0c 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -52,8 +52,8 @@ if __name__ == "__main__": target.module.reload(); suite = getTestSuite() - #suite = getTestSuite( "typeinfo.TypeInfoTest" ) + #suite = getTestSuite( "memtest.MemoryTest.testPtrRead" ) unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite ) - a = raw_input("\npress return\n") \ No newline at end of file + #a = raw_input("\npress return\n") \ No newline at end of file diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index 940ec22..4a8b643 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -85,6 +85,8 @@ struct struct2 { int m_field; }; +__int64 g_bigValue = 0x8080808080808080; + void FuncWithName0() { classChild _classChild;