mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 12:53:23 +08:00
[+] added : getProcessorMode, setProcessorMode routines;
git-svn-id: https://pykd.svn.codeplex.com/svn@58076 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
5cff86598c
commit
40960bd9b7
@ -25,7 +25,6 @@
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgsession.h"
|
||||
#include "dbgcallback.h"
|
||||
#include "dbgstack.h"
|
||||
#include "dbgpath.h"
|
||||
#include "dbginput.h"
|
||||
#include "dbgprocess.h"
|
||||
@ -136,6 +135,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
boost::python::def( "getImplicitThread", &getImplicitThread );
|
||||
boost::python::def( "setImplicitThread", &setImplicitThread );
|
||||
boost::python::def( "getThreadList", &getThreadList );
|
||||
boost::python::def( "getProcessorMode", &getProcessorMode );
|
||||
boost::python::def( "setProcessorMode", &setProcessorMode );
|
||||
boost::python::class_<typedVarClass>( "typedVarClass" )
|
||||
.def("getAddress", &typedVarClass::getAddress )
|
||||
.def("sizeof", &typedVarClass::size );
|
||||
|
@ -67,3 +67,188 @@ getThreadList()
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
setImplicitThread(
|
||||
ULONG64 newThreadAddr )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG64
|
||||
getImplicitThread()
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
ULONG64 threadOffset = -1;
|
||||
|
||||
hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
|
||||
|
||||
return threadOffset;
|
||||
|
||||
}
|
||||
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 -1;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boost::python::object
|
||||
getCurrentStack()
|
||||
{
|
||||
HRESULT hres;
|
||||
PDEBUG_STACK_FRAME frames = NULL;
|
||||
|
||||
try {
|
||||
|
||||
frames = new DEBUG_STACK_FRAME [ 1000 ];
|
||||
|
||||
ULONG filledFrames;
|
||||
hres = dbgExt->control->GetStackTrace( 0, 0, 0, frames, 1000, &filledFrames );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::GetStackTrace failed" );
|
||||
|
||||
boost::python::list frameList;
|
||||
|
||||
for ( ULONG i = 0; i < filledFrames; ++i )
|
||||
{
|
||||
frameList.append( boost::python::object( dbgStackFrameClass( frames[i] ) ) );
|
||||
}
|
||||
|
||||
if ( frames )
|
||||
delete[] frames;
|
||||
|
||||
return frameList;
|
||||
|
||||
}
|
||||
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" );
|
||||
}
|
||||
|
||||
if ( frames )
|
||||
delete[] frames;
|
||||
|
||||
return boost::python::object();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boost::python::object
|
||||
getProcessorMode()
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
ULONG processorMode;
|
||||
hres = dbgExt->control->GetEffectiveProcessorType( &processorMode );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" );
|
||||
|
||||
switch( processorMode )
|
||||
{
|
||||
case IMAGE_FILE_MACHINE_I386:
|
||||
return boost::python::str("X86");
|
||||
|
||||
case IMAGE_FILE_MACHINE_ARM:
|
||||
return boost::python::str("ARM");
|
||||
|
||||
case IMAGE_FILE_MACHINE_IA64:
|
||||
return boost::python::str("IA64");
|
||||
|
||||
case IMAGE_FILE_MACHINE_AMD64:
|
||||
return boost::python::str("X64");
|
||||
|
||||
}
|
||||
}
|
||||
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 boost::python::object();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
setProcessorMode(
|
||||
const std::string &mode )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
ULONG processorMode = ~0;
|
||||
|
||||
if ( mode == "X86" )
|
||||
processorMode = IMAGE_FILE_MACHINE_I386;
|
||||
else if ( mode == "ARM" )
|
||||
processorMode = IMAGE_FILE_MACHINE_ARM;
|
||||
else if ( mode == "IA64" )
|
||||
processorMode = IMAGE_FILE_MACHINE_IA64;
|
||||
else if ( mode == "X64" )
|
||||
processorMode = IMAGE_FILE_MACHINE_AMD64;
|
||||
else
|
||||
throw DbgException( "Unknown processor type" );
|
||||
|
||||
hres = dbgExt->control->SetEffectiveProcessorType( processorMode );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::SetEffectiveProcessorType failed" );
|
||||
|
||||
}
|
||||
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" );
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -2,10 +2,44 @@
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
#include <dbgeng.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boost::python::object
|
||||
getThreadList();
|
||||
|
||||
bool
|
||||
setImplicitThread(
|
||||
ULONG64 newThreadAddr );
|
||||
|
||||
ULONG64
|
||||
getImplicitThread();
|
||||
|
||||
|
||||
boost::python::object
|
||||
getCurrentStack();
|
||||
|
||||
class dbgStackFrameClass : public DEBUG_STACK_FRAME {
|
||||
|
||||
public:
|
||||
|
||||
dbgStackFrameClass()
|
||||
{
|
||||
memset( static_cast<DEBUG_STACK_FRAME*>( this ), 0, sizeof(DEBUG_STACK_FRAME) );
|
||||
}
|
||||
|
||||
dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame )
|
||||
{
|
||||
memcpy( static_cast<DEBUG_STACK_FRAME*>( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) );
|
||||
}
|
||||
};
|
||||
|
||||
boost::python::object
|
||||
getProcessorMode();
|
||||
|
||||
void
|
||||
setProcessorMode(
|
||||
const std::string &mode );
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -1,116 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgstack.h"
|
||||
#include "dbgexcept.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
setImplicitThread(
|
||||
ULONG64 newThreadAddr,
|
||||
PULONG64 oldThreadAddr )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
*oldThreadAddr = getImplicitThread();
|
||||
if ( *oldThreadAddr == -1 )
|
||||
return false;
|
||||
|
||||
hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG64
|
||||
getImplicitThread()
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
ULONG64 threadOffset = -1;
|
||||
|
||||
hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
|
||||
|
||||
return threadOffset;
|
||||
|
||||
}
|
||||
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 -1;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
boost::python::object
|
||||
getCurrentStack()
|
||||
{
|
||||
HRESULT hres;
|
||||
PDEBUG_STACK_FRAME frames = NULL;
|
||||
|
||||
try {
|
||||
|
||||
frames = new DEBUG_STACK_FRAME [ 1000 ];
|
||||
|
||||
ULONG filledFrames;
|
||||
hres = dbgExt->control->GetStackTrace( 0, 0, 0, frames, 1000, &filledFrames );
|
||||
|
||||
boost::python::list frameList;
|
||||
|
||||
for ( ULONG i = 0; i < filledFrames; ++i )
|
||||
{
|
||||
frameList.append( boost::python::object( dbgStackFrameClass( frames[i] ) ) );
|
||||
}
|
||||
|
||||
if ( frames )
|
||||
delete[] frames;
|
||||
|
||||
return frameList;
|
||||
|
||||
}
|
||||
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" );
|
||||
}
|
||||
|
||||
if ( frames )
|
||||
delete[] frames;
|
||||
|
||||
return boost::python::object();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/object.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
setImplicitThread(
|
||||
ULONG64 newThreadAddr,
|
||||
PULONG64 oldThreadAddr );
|
||||
|
||||
ULONG64
|
||||
getImplicitThread();
|
||||
|
||||
|
||||
boost::python::object
|
||||
getCurrentStack();
|
||||
|
||||
class dbgStackFrameClass : public DEBUG_STACK_FRAME {
|
||||
|
||||
public:
|
||||
|
||||
dbgStackFrameClass()
|
||||
{
|
||||
memset( static_cast<DEBUG_STACK_FRAME*>( this ), 0, sizeof(DEBUG_STACK_FRAME) );
|
||||
}
|
||||
|
||||
dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame )
|
||||
{
|
||||
memcpy( static_cast<DEBUG_STACK_FRAME*>( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) );
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -395,10 +395,6 @@
|
||||
RelativePath=".\dbgsession.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgstack.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsym.cpp"
|
||||
>
|
||||
@ -509,10 +505,6 @@
|
||||
RelativePath=".\dbgsession.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgstack.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsym.h"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user