From 9d45f0c24a9d72e3df7f64d52071f2344e8c955f Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996> Date: Thu, 29 Jul 2010 14:39:49 +0000 Subject: [PATCH] [+] added: loadAnsiStr [+] fixed: issue #6747 ( windbg script's call parameters passing into python script added ) git-svn-id: https://pykd.svn.codeplex.com/svn@53258 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 58 +++++++++++++++++++++++++++++++++++-------- pykd/dbgmem.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgmem.h | 3 +++ pykd/dbgtype.cpp | 8 ++++-- pykd/pykd.vcproj | 2 ++ samples/drvobj.py | 8 +++--- 6 files changed, 126 insertions(+), 16 deletions(-) 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 <wdbgexts.h> +#include <vector> +#include <string> + #include <boost/python.hpp> #include <boost/python/class.hpp> #include <boost/python/module.hpp> #include <boost/python/def.hpp> +#include <boost/tokenizer.hpp> #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<unsigned char> ); - boost::python::def( "PtrSignByte", &loadByPtr<char> ); - boost::python::def( "PtrWord", &loadByPtr<unsigned short> ); - boost::python::def( "PtrSignWord", &loadByPtr<short> ); - boost::python::def( "PtrDWord", &loadByPtr<unsigned long> ); - boost::python::def( "PtrSignDWord", &loadByPtr<long> ); - boost::python::def( "PtrQWord", &loadByPtr<unsigned __int64> ); - boost::python::def( "PtrSignQWord", &loadByPtr<__int64> ); - boost::python::def( "PtrPtr", &loadPtrByPtr ); + boost::python::def( "loadAnsiString", &loadAnsiStr ); + boost::python::def( "ptrByte", &loadByPtr<unsigned char> ); + boost::python::def( "ptrSignByte", &loadByPtr<char> ); + boost::python::def( "ptrWord", &loadByPtr<unsigned short> ); + boost::python::def( "ptrSignWord", &loadByPtr<short> ); + boost::python::def( "ptrDWord", &loadByPtr<unsigned long> ); + boost::python::def( "ptrSignDWord", &loadByPtr<long> ); + boost::python::def( "ptrQWord", &loadByPtr<unsigned __int64> ); + boost::python::def( "ptrSignQWord", &loadByPtr<__int64> ); + boost::python::def( "ptrPtr", &loadPtrByPtr ); boost::python::def( "compareMemory", &compareMemory ); boost::python::class_<typedVarClass>( "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> 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<std::string> 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<char*>( 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 <map> + #include "dbgext.h" #include "dbgtype.h" #include "dbgexcept.h" @@ -46,7 +48,8 @@ basicTypeNames[] = { "unsigned long", "long", "<function>", - "void" + "void", + "double" }; basicTypeLoader basicTypeLoaders[] = { @@ -57,7 +60,8 @@ basicTypeLoader basicTypeLoaders[] = { valueLoader<unsigned long>, valueLoader<long>, valueLoader<void*>, - voidLoader }; + voidLoader, + valueLoader<double> }; /////////////////////////////////////////////////////////////////////////////////// // 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" /> <Tool Name="VCALinkTool" @@ -157,6 +158,7 @@ GenerateDebugInformation="true" SubSystem="2" TargetMachine="17" + Profile="true" /> <Tool Name="VCALinkTool" diff --git a/samples/drvobj.py b/samples/drvobj.py index 47f66c1..4bdf2ce 100644 --- a/samples/drvobj.py +++ b/samples/drvobj.py @@ -36,7 +36,7 @@ def getObjectInDir( dirObj, objName ): if name.lower() == dirSubName.lower(): - if objHeader.Type == PtrPtr( nt.ObpDirectoryObjectType ): + if objHeader.Type == ptrPtr( nt.ObpDirectoryObjectType ): return getObjectInDir( typedVar( "nt", "_OBJECT_DIRECTORY", dirEntry.Object), objSubName ) else: return dirEntry.Object @@ -57,7 +57,7 @@ def getObjectByName( objName ): if objName[0] != '\\': return - rootDir = typedVar( "nt", "_OBJECT_DIRECTORY", PtrPtr( nt.ObpRootDirectoryObject ) ) + rootDir = typedVar( "nt", "_OBJECT_DIRECTORY", ptrPtr( nt.ObpRootDirectoryObject ) ) return getObjectInDir( rootDir, objName[1:] ) @@ -69,14 +69,14 @@ def printDrvMajorTable( drvName ): drvObjPtr = getObjectByName( objName ) if drvObjPtr == None: - print "object not found" + dprintln( "object not found" ) return drvObj = typedVar( "nt", "_DRIVER_OBJECT", drvObjPtr ) for i,k in drvObj.MajorFunction.items(): - print "MajorFunction[%d] = %s" % ( i, findSymbol( k ) ) + dprintln( "MajorFunction[%d] = %s" % ( i, findSymbol( k ) ) )