mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[+] 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
This commit is contained in:
parent
06b508031a
commit
9d45f0c24a
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
#include <wdbgexts.h>
|
#include <wdbgexts.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
#include <boost/python/class.hpp>
|
#include <boost/python/class.hpp>
|
||||||
#include <boost/python/module.hpp>
|
#include <boost/python/module.hpp>
|
||||||
#include <boost/python/def.hpp>
|
#include <boost/python/def.hpp>
|
||||||
|
#include <boost/tokenizer.hpp>
|
||||||
|
|
||||||
#include "dbgext.h"
|
#include "dbgext.h"
|
||||||
#include "dbgprint.h"
|
#include "dbgprint.h"
|
||||||
@ -54,15 +58,16 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
boost::python::def( "loadSignQWords", &loadArray<__int64> );
|
boost::python::def( "loadSignQWords", &loadArray<__int64> );
|
||||||
boost::python::def( "loadPtrs", &loadPtrArray );
|
boost::python::def( "loadPtrs", &loadPtrArray );
|
||||||
boost::python::def( "loadUnicodeString", &loadUnicodeStr );
|
boost::python::def( "loadUnicodeString", &loadUnicodeStr );
|
||||||
boost::python::def( "PtrByte", &loadByPtr<unsigned char> );
|
boost::python::def( "loadAnsiString", &loadAnsiStr );
|
||||||
boost::python::def( "PtrSignByte", &loadByPtr<char> );
|
boost::python::def( "ptrByte", &loadByPtr<unsigned char> );
|
||||||
boost::python::def( "PtrWord", &loadByPtr<unsigned short> );
|
boost::python::def( "ptrSignByte", &loadByPtr<char> );
|
||||||
boost::python::def( "PtrSignWord", &loadByPtr<short> );
|
boost::python::def( "ptrWord", &loadByPtr<unsigned short> );
|
||||||
boost::python::def( "PtrDWord", &loadByPtr<unsigned long> );
|
boost::python::def( "ptrSignWord", &loadByPtr<short> );
|
||||||
boost::python::def( "PtrSignDWord", &loadByPtr<long> );
|
boost::python::def( "ptrDWord", &loadByPtr<unsigned long> );
|
||||||
boost::python::def( "PtrQWord", &loadByPtr<unsigned __int64> );
|
boost::python::def( "ptrSignDWord", &loadByPtr<long> );
|
||||||
boost::python::def( "PtrSignQWord", &loadByPtr<__int64> );
|
boost::python::def( "ptrQWord", &loadByPtr<unsigned __int64> );
|
||||||
boost::python::def( "PtrPtr", &loadPtrByPtr );
|
boost::python::def( "ptrSignQWord", &loadByPtr<__int64> );
|
||||||
|
boost::python::def( "ptrPtr", &loadPtrByPtr );
|
||||||
boost::python::def( "compareMemory", &compareMemory );
|
boost::python::def( "compareMemory", &compareMemory );
|
||||||
boost::python::class_<typedVarClass>( "typedVarClass" )
|
boost::python::class_<typedVarClass>( "typedVarClass" )
|
||||||
.def("getAddress", &typedVarClass::getAddress );
|
.def("getAddress", &typedVarClass::getAddress );
|
||||||
@ -141,7 +146,40 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
|
|||||||
|
|
||||||
boost::python::object result;
|
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 & )
|
catch( boost::python::error_already_set const & )
|
||||||
|
@ -233,3 +233,66 @@ 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( "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
@ -55,6 +55,9 @@ loadPtrArray( ULONG64 address, ULONG number );
|
|||||||
boost::python::object
|
boost::python::object
|
||||||
loadUnicodeStr( ULONG64 address );
|
loadUnicodeStr( ULONG64 address );
|
||||||
|
|
||||||
|
boost::python::object
|
||||||
|
loadAnsiStr( ULONG64 address );
|
||||||
|
|
||||||
bool
|
bool
|
||||||
compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length );
|
compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length );
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "dbgext.h"
|
#include "dbgext.h"
|
||||||
#include "dbgtype.h"
|
#include "dbgtype.h"
|
||||||
#include "dbgexcept.h"
|
#include "dbgexcept.h"
|
||||||
@ -46,7 +48,8 @@ basicTypeNames[] = {
|
|||||||
"unsigned long",
|
"unsigned long",
|
||||||
"long",
|
"long",
|
||||||
"<function>",
|
"<function>",
|
||||||
"void"
|
"void",
|
||||||
|
"double"
|
||||||
};
|
};
|
||||||
|
|
||||||
basicTypeLoader basicTypeLoaders[] = {
|
basicTypeLoader basicTypeLoaders[] = {
|
||||||
@ -57,7 +60,8 @@ basicTypeLoader basicTypeLoaders[] = {
|
|||||||
valueLoader<unsigned long>,
|
valueLoader<unsigned long>,
|
||||||
valueLoader<long>,
|
valueLoader<long>,
|
||||||
valueLoader<void*>,
|
valueLoader<void*>,
|
||||||
voidLoader };
|
voidLoader,
|
||||||
|
valueLoader<double> };
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="true"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
TargetMachine="1"
|
TargetMachine="1"
|
||||||
|
Profile="true"
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCALinkTool"
|
Name="VCALinkTool"
|
||||||
@ -157,6 +158,7 @@
|
|||||||
GenerateDebugInformation="true"
|
GenerateDebugInformation="true"
|
||||||
SubSystem="2"
|
SubSystem="2"
|
||||||
TargetMachine="17"
|
TargetMachine="17"
|
||||||
|
Profile="true"
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCALinkTool"
|
Name="VCALinkTool"
|
||||||
|
@ -36,7 +36,7 @@ def getObjectInDir( dirObj, objName ):
|
|||||||
|
|
||||||
if name.lower() == dirSubName.lower():
|
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 )
|
return getObjectInDir( typedVar( "nt", "_OBJECT_DIRECTORY", dirEntry.Object), objSubName )
|
||||||
else:
|
else:
|
||||||
return dirEntry.Object
|
return dirEntry.Object
|
||||||
@ -57,7 +57,7 @@ def getObjectByName( objName ):
|
|||||||
if objName[0] != '\\':
|
if objName[0] != '\\':
|
||||||
return
|
return
|
||||||
|
|
||||||
rootDir = typedVar( "nt", "_OBJECT_DIRECTORY", PtrPtr( nt.ObpRootDirectoryObject ) )
|
rootDir = typedVar( "nt", "_OBJECT_DIRECTORY", ptrPtr( nt.ObpRootDirectoryObject ) )
|
||||||
|
|
||||||
return getObjectInDir( rootDir, objName[1:] )
|
return getObjectInDir( rootDir, objName[1:] )
|
||||||
|
|
||||||
@ -69,14 +69,14 @@ def printDrvMajorTable( drvName ):
|
|||||||
drvObjPtr = getObjectByName( objName )
|
drvObjPtr = getObjectByName( objName )
|
||||||
|
|
||||||
if drvObjPtr == None:
|
if drvObjPtr == None:
|
||||||
print "object not found"
|
dprintln( "object not found" )
|
||||||
return
|
return
|
||||||
|
|
||||||
drvObj = typedVar( "nt", "_DRIVER_OBJECT", drvObjPtr )
|
drvObj = typedVar( "nt", "_DRIVER_OBJECT", drvObjPtr )
|
||||||
|
|
||||||
|
|
||||||
for i,k in drvObj.MajorFunction.items():
|
for i,k in drvObj.MajorFunction.items():
|
||||||
print "MajorFunction[%d] = %s" % ( i, findSymbol( k ) )
|
dprintln( "MajorFunction[%d] = %s" % ( i, findSymbol( k ) ) )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user