diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 3d1af35..47a698a 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -2,10 +2,14 @@ #include +#include +#include + #include #include #include #include +#include #include "dbgext.h" #include "dbgprint.h" @@ -54,15 +58,16 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "loadSignQWords", &loadArray<__int64> ); boost::python::def( "loadPtrs", &loadPtrArray ); boost::python::def( "loadUnicodeString", &loadUnicodeStr ); - boost::python::def( "PtrByte", &loadByPtr ); - boost::python::def( "PtrSignByte", &loadByPtr ); - boost::python::def( "PtrWord", &loadByPtr ); - boost::python::def( "PtrSignWord", &loadByPtr ); - boost::python::def( "PtrDWord", &loadByPtr ); - boost::python::def( "PtrSignDWord", &loadByPtr ); - boost::python::def( "PtrQWord", &loadByPtr ); - boost::python::def( "PtrSignQWord", &loadByPtr<__int64> ); - boost::python::def( "PtrPtr", &loadPtrByPtr ); + boost::python::def( "loadAnsiString", &loadAnsiStr ); + boost::python::def( "ptrByte", &loadByPtr ); + boost::python::def( "ptrSignByte", &loadByPtr ); + boost::python::def( "ptrWord", &loadByPtr ); + boost::python::def( "ptrSignWord", &loadByPtr ); + boost::python::def( "ptrDWord", &loadByPtr ); + boost::python::def( "ptrSignDWord", &loadByPtr ); + boost::python::def( "ptrQWord", &loadByPtr ); + boost::python::def( "ptrSignQWord", &loadByPtr<__int64> ); + boost::python::def( "ptrPtr", &loadPtrByPtr ); boost::python::def( "compareMemory", &compareMemory ); boost::python::class_( "typedVarClass" ) .def("getAddress", &typedVarClass::getAddress ); @@ -141,7 +146,40 @@ py( PDEBUG_CLIENT4 client, PCSTR args) boost::python::object result; - result = boost::python::exec_file( args, global, global ); + // разбор параметров + typedef boost::char_separator char_separator_t; + typedef boost::tokenizer< char_separator_t > char_tokenizer_t; + + std::string argsStr( args ); + + char_tokenizer_t token( argsStr , char_separator_t( " \t" ) ); + std::vector argsList; + + for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it ) + argsList.push_back( *it ); + + if ( argsList.size() == 0 ) + return S_OK; + + if ( argsList.size() > 1 ) + { + char **pythonArgs = new char* [ argsList.size() - 1 ]; + + for ( size_t i = 0; i < argsList.size() - 1; ++i ) + pythonArgs[i] = const_cast( argsList[i+1].c_str() ); + + PySys_SetArgv( (int)argsList.size() - 1, pythonArgs ); + + delete[] pythonArgs; + } + else + { + char *emptyParam = ""; + + PySys_SetArgv( 1, &emptyParam ); + } + + result = boost::python::exec_file( argsList[0].c_str(), global, global ); } catch( boost::python::error_already_set const & ) diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 45b1b28..0959280 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -232,4 +232,67 @@ loadUnicodeStr( ULONG64 address ) } +/////////////////////////////////////////////////////////////////////////////////// + +boost::python::object +loadAnsiStr( ULONG64 address ) +{ + USHORT length; + USHORT maximumLength; + ULONG64 buffer = 0; + + char *ansiStr = NULL; + + do { + + if ( !loadMemory( address, &length, sizeof( length ) ) ) + break; + + if ( length == 0 ) + break; + + address += sizeof( length ); + + if ( !loadMemory( address, &maximumLength, sizeof( maximumLength ) ) ) + break; + + address += sizeof( maximumLength ); + + if ( is64bitSystem() ) + { + if ( !loadMemory( address, &buffer, 8 ) ) + break; + + address += 8; + } + else + { + if ( !loadMemory( address, &buffer, 4 ) ) + break; + + buffer = addr64( buffer ); + + address += 4; + } + + + ansiStr = new char [ length/2 ]; + + if ( !loadMemory( buffer, ansiStr, length ) ) + break; + + std::string strVal ( ansiStr, length/2 ); + + delete[] ansiStr; + + return boost::python::object( strVal ); + + } while( FALSE ); + + if ( ansiStr ) + delete[] ansiStr; + + return boost::python::object( "" ); +} + /////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index 3036180..6a6b35b 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -55,6 +55,9 @@ loadPtrArray( ULONG64 address, ULONG number ); boost::python::object loadUnicodeStr( ULONG64 address ); +boost::python::object +loadAnsiStr( ULONG64 address ); + bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length ); diff --git a/pykd/dbgtype.cpp b/pykd/dbgtype.cpp index be8bc94..d0600e4 100644 --- a/pykd/dbgtype.cpp +++ b/pykd/dbgtype.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" +#include + #include "dbgext.h" #include "dbgtype.h" #include "dbgexcept.h" @@ -46,7 +48,8 @@ basicTypeNames[] = { "unsigned long", "long", "", - "void" + "void", + "double" }; basicTypeLoader basicTypeLoaders[] = { @@ -57,7 +60,8 @@ basicTypeLoader basicTypeLoaders[] = { valueLoader, valueLoader, valueLoader, - voidLoader }; + voidLoader, + valueLoader }; /////////////////////////////////////////////////////////////////////////////////// // diff --git a/pykd/pykd.vcproj b/pykd/pykd.vcproj index 831316d..63edf08 100644 --- a/pykd/pykd.vcproj +++ b/pykd/pykd.vcproj @@ -74,6 +74,7 @@ GenerateDebugInformation="true" SubSystem="2" TargetMachine="1" + Profile="true" />