From 40960bd9b704c9e2b349707b93fe9362c6858591 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 26 Nov 2010 13:55:09 +0000 Subject: [PATCH] [+] added : getProcessorMode, setProcessorMode routines; git-svn-id: https://pykd.svn.codeplex.com/svn@58076 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 3 +- pykd/dbgprocess.cpp | 185 ++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgprocess.h | 34 ++++++++ pykd/dbgstack.cpp | 116 --------------------------- pykd/dbgstack.h | 35 --------- pykd/pykd.vcproj | 8 -- 6 files changed, 221 insertions(+), 160 deletions(-) delete mode 100644 pykd/dbgstack.cpp delete mode 100644 pykd/dbgstack.h diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index ddf495f..5df7720 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -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" ) .def("getAddress", &typedVarClass::getAddress ) .def("sizeof", &typedVarClass::size ); diff --git a/pykd/dbgprocess.cpp b/pykd/dbgprocess.cpp index 368b7f7..b60c0c4 100644 --- a/pykd/dbgprocess.cpp +++ b/pykd/dbgprocess.cpp @@ -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" ); + } +} + +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgprocess.h b/pykd/dbgprocess.h index 3c2b4b2..bb3884a 100644 --- a/pykd/dbgprocess.h +++ b/pykd/dbgprocess.h @@ -2,10 +2,44 @@ #include #include +#include ///////////////////////////////////////////////////////////////////////////////// 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( this ), 0, sizeof(DEBUG_STACK_FRAME) ); + } + + dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame ) + { + memcpy( static_cast( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) ); + } +}; + +boost::python::object +getProcessorMode(); + +void +setProcessorMode( + const std::string &mode ); + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgstack.cpp b/pykd/dbgstack.cpp deleted file mode 100644 index 496f574..0000000 --- a/pykd/dbgstack.cpp +++ /dev/null @@ -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(); -} - - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgstack.h b/pykd/dbgstack.h deleted file mode 100644 index fc28ca4..0000000 --- a/pykd/dbgstack.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include - -///////////////////////////////////////////////////////////////////////////////// - -bool -setImplicitThread( - ULONG64 newThreadAddr, - PULONG64 oldThreadAddr ); - -ULONG64 -getImplicitThread(); - - -boost::python::object -getCurrentStack(); - -class dbgStackFrameClass : public DEBUG_STACK_FRAME { - -public: - - dbgStackFrameClass() - { - memset( static_cast( this ), 0, sizeof(DEBUG_STACK_FRAME) ); - } - - dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame ) - { - memcpy( static_cast( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) ); - } -}; - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/pykd.vcproj b/pykd/pykd.vcproj index 6e4f297..1caedba 100644 --- a/pykd/pykd.vcproj +++ b/pykd/pykd.vcproj @@ -395,10 +395,6 @@ RelativePath=".\dbgsession.cpp" > - - @@ -509,10 +505,6 @@ RelativePath=".\dbgsession.h" > - -