diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index e4ada33..be399cb 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -107,6 +107,14 @@ public: python::list loadQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + python::list loadSignBytes( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + + python::list loadSignWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + + python::list loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + + python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + std::string loadChars( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); std::wstring loadWChars( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); @@ -148,6 +156,9 @@ private: python::list loadArray( ULONG64 offset, ULONG count, bool phyAddr ); + //python::list + //loadArray( ULONG64 offset, ULONG count, bool phyAddr ); + DebugClient( IDebugClient4 *client ) : DbgObject( client ) {} PyThreadStateSaver m_pyThreadState; diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 269149b..8468951 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -62,13 +62,20 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, loadBytes, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords_, loadWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords_, loadDWords, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords_, loadQWords, 2, 3 ); - +BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, loadSignBytes, 2, 3 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, loadSignWords, 2, 3 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, loadSignDWords, 2, 3 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, loadSignQWords, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadChars, DebugClient::loadChars, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWChars, DebugClient::loadWChars, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadBytes, DebugClient::loadBytes, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWords, DebugClient::loadWords, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadDWords, DebugClient::loadDWords, 2, 3 ); BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadQWords, DebugClient::loadQWords, 2, 3 ); +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignBytes, DebugClient::loadSignBytes, 2, 3 ); +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignWords, DebugClient::loadSignWords, 2, 3 ); +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignDWords, DebugClient::loadSignDWords, 2, 3 ); +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignQWords, DebugClient::loadSignQWords, 2, 3 ); #define DEF_PY_CONST_ULONG(x) \ @@ -187,6 +194,14 @@ BOOST_PYTHON_MODULE( pykd ) "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" ), "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" ), + "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" ), + "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" ), + "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" ), + "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" ), "Load string from target memory" ) ) .def( "loadWChars", &pykd::DebugClient::loadWChars, DebugClient_loadWChars( python::args( "offset", "count", "phyAddr" ), @@ -237,11 +252,19 @@ BOOST_PYTHON_MODULE( pykd ) python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as liat of unsigned bytes" ) ); python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of unsigned shorts" ) ); + "Read the block of the target's memory and return it as list of unsigned shorts" ) ); python::def( "loadDWords", &loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ); + "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ); python::def( "loadQWords", &loadQWords, 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 )" ) ); + "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ); + python::def( "loadSignBytes", &loadSignBytes, loadSignBytes_( python::args( "offset", "count", "phyAddr" ), + "Read the block of the target's memory and return it as list of signed bytes" ) ); + python::def( "loadSignWords", &loadSignWords, loadSignWords_( python::args( "offset", "count", "phyAddr" ), + "Read the block of the target's memory and return it as list of signed words" ) ); + python::def( "loadSignDWords", &loadSignDWords, loadSignDWords_( python::args( "offset", "count", "phyAddr" ), + "Read the block of the target's memory and return it as list of signed longs" ) ); + python::def( "loadSignQWords", &loadSignQWords, loadSignQWords_( python::args( "offset", "count", "phyAddr" ), + "Read the block of the target's memory and return it as list of signed long longs" ) ); python::def( "loadChars", &loadChars, loadChars_( python::args( "address", "count", "phyAddr" ), "Load string from target memory" ) ); python::def( "loadWChars", &loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ), diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index ab580dd..b4de26e 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -7,6 +7,18 @@ namespace pykd { ///////////////////////////////////////////////////////////////////////////////////// +template +struct PyListType +{ + typedef T ElementType; +}; + +template<> +struct PyListType +{ + typedef int ElementType; +}; + template python::list DebugClient::loadArray( ULONG64 offset, ULONG count, bool phyAddr ) @@ -19,7 +31,7 @@ DebugClient::loadArray( ULONG64 offset, ULONG count, bool phyAddr ) python::list lst; for( ULONG i = 0; i < count; ++i ) - lst.append( buffer[i] ); + lst.append( static_cast::ElementType> (buffer[i]) ); return lst; } @@ -171,6 +183,53 @@ python::list loadQWords( ULONG64 offset, ULONG count, bool phyAddr ) ///////////////////////////////////////////////////////////////////////////////////// +python::list DebugClient::loadSignBytes( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return loadArray( offset, count, phyAddr ); +} + +python::list loadSignBytes( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return g_dbgClient->loadSignBytes( offset, count, phyAddr ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +python::list DebugClient::loadSignWords( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return loadArray( offset, count, phyAddr ); +} + +python::list loadSignWords( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return g_dbgClient->loadSignWords( offset, count, phyAddr ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +python::list DebugClient::loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return loadArray( offset, count, phyAddr ); +} + +python::list loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return g_dbgClient->loadSignDWords( offset, count, phyAddr ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +python::list DebugClient::loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return loadArray<__int64>( offset, count, phyAddr ); +} + +python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr ) +{ + return g_dbgClient->loadSignQWords( offset, count, phyAddr ); +} + +///////////////////////////////////////////////////////////////////////////////////// }; // end of pykd diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index 12c18e1..8d44e75 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -29,103 +29,15 @@ python::list loadDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); python::list loadQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); +python::list loadSignBytes( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + +python::list loadSignWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + +python::list loadSignDWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + +python::list loadSignQWords( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); + /////////////////////////////////////////////////////////////////////////////////// }; - - - - - - - - -//#include -// -/////////////////////////////////////////////////////////////////////////////////// -// -//void -//loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr = FALSE ); -// -//ULONG64 -//loadPtrByPtr( ULONG64 address ); -// -//ULONG64 -//loadMWord( ULONG64 address ); -// -//LONG64 -//loadSignMWord( ULONG64 address ); -// -// -//template -//boost::python::object -//loadArray( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE ) -//{ -// boost::scoped_array buffer(new T[number]); -// -// loadMemory( address, buffer.get(), number*sizeof(T), phyAddr ); -// -// boost::python::list lst; -// -// for ( ULONG i = 0; i < number; ++i ) -// lst.append( buffer[i] ); -// -// return lst; -//} -// -//boost::python::object -//loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE ); -// -//boost::python::object -//loadWChars( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE ); -// -//template -//boost::python::object -//loadByPtr( ULONG64 address ) -//{ -// T value; -// -// loadMemory( address, &value, sizeof(T) ); -// -// return boost::python::object( value ); -//} -// -//template<> -//boost::python::object -//loadByPtr( ULONG64 address ); -// -//boost::python::object -//loadPtrArray( ULONG64 address, ULONG number ); -// -//boost::python::object -//loadUnicodeStr( ULONG64 address ); -// -//boost::python::object -//loadAnsiStr( ULONG64 address ); -// -//boost::python::object -//loadCStr( ULONG64 address ); -// -//void -//loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen ); -// -//boost::python::object -//loadWStr( ULONG64 address ); -// -//void -//loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen ); -// -//bool -//compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE ); -// -//ULONG64 -//addr64( ULONG64 addr ); -// -//boost::python::object -//loadLinkedList( ULONG64 address ); -// -//bool -//isOffsetValid( ULONG64 addr ); -// -/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/test/scripts/basetest.py b/test/scripts/basetest.py index 1751815..05bf89c 100644 --- a/test/scripts/basetest.py +++ b/test/scripts/basetest.py @@ -52,6 +52,7 @@ class BaseTest( unittest.TestCase ): self.assertTrue( hasattr(pykd, 'loadModule') ) self.assertTrue( hasattr(pykd, 'loadPtrs') ) self.assertTrue( hasattr(pykd, 'loadQWords') ) + self.assertTrue( hasattr(pykd, 'loadSignBytes') ) self.assertTrue( hasattr(pykd, 'loadSignDWords') ) self.assertTrue( hasattr(pykd, 'loadSignQWords') ) self.assertTrue( hasattr(pykd, 'loadSignWords') ) diff --git a/test/scripts/memtest.py b/test/scripts/memtest.py index 69d31ac..e0f6155 100644 --- a/test/scripts/memtest.py +++ b/test/scripts/memtest.py @@ -24,18 +24,43 @@ class MemoryTest( unittest.TestCase ): def testLoadWords( self ): loadArray = pykd.loadWords( target.module.ushortArray, 5 ) - testArray = [ 0, 10, 0xFF, 0xFFF, 0xFFFF ] + testArray = [ 0, 10, 0xFF, 0x8000, 0xFFFF ] self.assertEqual( len(testArray), len(loadArray) ) self.assertEqual( 0, len( [ loadArray[i] for i in xrange(len(testArray)) if loadArray[i] != testArray[i] ] ) ) def testLoadDWords( self ): loadArray = pykd.loadDWords( target.module.ulongArray, 5 ) - testArray = [ 0, 0xFF, 0xFFF, 0xFFFF, 0xFFFFFFFF ] + testArray = [ 0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF ] self.assertEqual( len(testArray), len(loadArray) ) self.assertEqual( 0, len( [ loadArray[i] for i in xrange(len(testArray)) if loadArray[i] != testArray[i] ] ) ) def testLoadQWords( self ): loadArray = pykd.loadQWords( target.module.ulonglongArray, 5 ) - testArray = [ 0, 0xFF, 0xFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF ] + testArray = [ 0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF ] self.assertEqual( len(testArray), len(loadArray) ) - self.assertEqual( 0, len( [ loadArray[i] for i in xrange(len(testArray)) if loadArray[i] != testArray[i] ] ) ) \ No newline at end of file + self.assertEqual( 0, len( [ loadArray[i] for i in xrange(len(testArray)) if loadArray[i] != testArray[i] ] ) ) + + def testLoadSignBytes( self ): + charArray = pykd.loadSignBytes( target.module.ucharArray, 5 ) + testArray = [ 0, 10, 0x78, -128, -1 ] + self.assertEqual( 5, len(charArray) ) + self.assertEqual( 0, len( [ charArray[i] for i in xrange(len(testArray)) if charArray[i] != testArray[i] ] ) ) + + def testLoadSignWords( self ): + loadArray = pykd.loadSignWords( target.module.ushortArray, 5 ) + testArray = [ 0, 10, 255, -32768, -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 testLoadSignDWords( self ): + loadArray = pykd.loadSignDWords( target.module.ulongArray, 5 ) + testArray = [0, 255, 32768, -2147483648, -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 testLoadSignQWords( self ): + loadArray = pykd.loadSignQWords( target.module.ulonglongArray, 5 ) + 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] ] ) ) + diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index f51e8bb..8afdca0 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -59,9 +59,9 @@ char helloStr[] = "Hello"; wchar_t helloWStr[] = L"Hello"; unsigned char ucharArray[] = {0, 10, 0x78, 128, 0xFF }; -unsigned short ushortArray[] = {0, 10, 0xFF, 0xFFF, 0xFFFF }; -unsigned long ulongArray[] = {0, 0xFF, 0xFFF, 0xFFFF, 0xFFFFFFFF }; -unsigned __int64 ulonglongArray[] = {0, 0xFF, 0xFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF }; +unsigned short ushortArray[] = {0, 10, 0xFF, 0x8000, 0xFFFF }; +unsigned long ulongArray[] = {0, 0xFF, 0x8000, 0x80000000, 0xFFFFFFFF }; +unsigned __int64 ulonglongArray[] = {0, 0xFF, 0xFFFFFFFF, 0x8000000000000000, 0xFFFFFFFFFFFFFFFF }; class classChild : public classBase { public: