From 95c135ed382b8b0fccf0755e4c2a2113932092b1 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Wed, 26 Oct 2011 07:10:44 +0000 Subject: [PATCH] [0.1.x] added : disasm class git-svn-id: https://pykd.svn.codeplex.com/svn@70760 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.h | 21 +++++++++++++-------- pykd/dbgext.cpp | 11 +++++++++++ pykd/dbgobj.h | 5 +++++ pykd/disasm.cpp | 42 ++++++++++++++++++++++++++++++++++-------- pykd/disasm.h | 13 ++++++++++--- pykd/module.h | 2 -- pykd/pykd_2008.vcproj | 8 ++++++++ 7 files changed, 81 insertions(+), 21 deletions(-) diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 9ec8700..e4ada33 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -12,6 +12,7 @@ #include "dbgio.h" #include "dbgcmd.h" #include "pyaux.h" +#include "disasm.h" ///////////////////////////////////////////////////////////////////////////////// @@ -59,6 +60,18 @@ public: void attachKernel( const std::wstring ¶m ); + Disasm disasm( ULONG offset = 0 ) { + return Disasm( m_client, offset ); + } + + void dprint( const std::wstring &str, bool dml = false ); + + void dprintln( const std::wstring &str, bool dml = false ); + + void eprint( const std::wstring &str ); + + void eprintln( const std::wstring &str ); + ULONG64 evaluate( const std::wstring &expression ); python::tuple getDebuggeeType(); @@ -98,14 +111,6 @@ public: std::wstring loadWChars( ULONG64 offset, ULONG count, bool phyAddr = FALSE ); - void dprint( const std::wstring &str, bool dml = false ); - - void dprintln( const std::wstring &str, bool dml = false ); - - void eprint( const std::wstring &str ); - - void eprintln( const std::wstring &str ); - void readMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE ); void setExecutionStatus( ULONG status ); diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 6815e79..3554340 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -266,6 +266,17 @@ BOOST_PYTHON_MODULE( pykd ) "Unload module event. Parameter is instance of dbgModuleClass.\n" "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); + python::class_("disasm", "Class disassemble a processor instructions" ) + .def( python::init<>( "constructor" ) ) + .def( python::init( boost::python::args("offset"), "constructor" ) ) + .def( "disasm", &Disasm::disassemble, "Disassemble next instruction" ) + .def( "asm", &Disasm::assembly, "Insert assemblied instuction to current offset" ) + .def( "begin", &Disasm::begin, "Return begin offset" ) + .def( "current", &Disasm::current, "Return current offset" ) + .def( "length", &Disasm::length, "Return current instruction length" ) + .def( "instruction", &Disasm::instruction, "Returm current disassembled instruction" ) + .def( "ea", &Disasm::ea, "Return effective address for last disassembled instruction or 0" ) + .def( "reset", &Disasm::reset, "Reset current offset to begin" ); python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, "Open pdb file for quering debug symbols. Return DiaSymbol of global scope"); diff --git a/pykd/dbgobj.h b/pykd/dbgobj.h index c6ee9e2..a82081b 100644 --- a/pykd/dbgobj.h +++ b/pykd/dbgobj.h @@ -35,6 +35,10 @@ protected: hres = client->QueryInterface( __uuidof(IDebugDataSpaces), (void**)&m_dataSpaces ); if ( FAILED( hres ) ) throw DbgException("QueryInterface IDebugDataSpaces failed"); + + hres = client->QueryInterface( __uuidof(IDebugRegisters), (void**)&m_registers ); + if ( FAILED( hres ) ) + throw DbgException("QueryInterface IDebugDataSpaces failed"); } virtual ~DbgObject() {}; @@ -45,6 +49,7 @@ protected: CComPtr m_symbols; CComPtr m_advanced; CComPtr m_dataSpaces; + CComPtr m_registers; }; diff --git a/pykd/disasm.cpp b/pykd/disasm.cpp index 4780633..a35c0f3 100644 --- a/pykd/disasm.cpp +++ b/pykd/disasm.cpp @@ -1,11 +1,15 @@ #include "stdafx.h" -#include "dbgext.h" #include "disasm.h" #include "dbgexcept.h" +#include "dbgmem.h" +#include "dbgclient.h" + +namespace pykd { ///////////////////////////////////////////////////////////////////////////////// -disasm::disasm( ULONG64 offset ) +Disasm::Disasm( IDebugClient4 *client, ULONG64 offset ) : + DbgObject( client ) { HRESULT hres; @@ -13,7 +17,7 @@ disasm::disasm( ULONG64 offset ) if ( m_beginOffset == 0 ) { - hres = dbgExt->registers->GetInstructionOffset( &m_beginOffset ); + hres = m_registers->GetInstructionOffset( &m_beginOffset ); if ( FAILED( hres ) ) throw DbgException( "IDebugRegisters::GetInstructionOffset failed" ); } @@ -25,7 +29,28 @@ disasm::disasm( ULONG64 offset ) ///////////////////////////////////////////////////////////////////////////////// -void disasm::doDisasm() +Disasm::Disasm( ULONG64 offset ) : + DbgObject( g_dbgClient->client() ) +{ + HRESULT hres; + + m_beginOffset = addr64(offset); + + if ( m_beginOffset == 0 ) + { + hres = m_registers->GetInstructionOffset( &m_beginOffset ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugRegisters::GetInstructionOffset failed" ); + } + + m_currentOffset = m_beginOffset; + + doDisasm(); +} + +///////////////////////////////////////////////////////////////////////////////// + +void Disasm::doDisasm() { HRESULT hres; char buffer[0x100]; @@ -33,7 +58,7 @@ void disasm::doDisasm() ULONG64 endOffset = 0; hres = - dbgExt->control->Disassemble( + m_control->Disassemble( m_currentOffset, DEBUG_DISASM_EFFECTIVE_ADDRESS, buffer, @@ -44,7 +69,7 @@ void disasm::doDisasm() if ( FAILED( hres ) ) throw DbgException( "IDebugControl::Disassemble failed" ); - hres = dbgExt->control->GetDisassembleEffectiveOffset( &m_ea ); + hres = m_control->GetDisassembleEffectiveOffset( &m_ea ); if ( FAILED( hres ) ) m_ea = 0; @@ -56,12 +81,12 @@ void disasm::doDisasm() ///////////////////////////////////////////////////////////////////////////////// std::string -disasm::assembly( const std::string &instr ) +Disasm::assembly( const std::string &instr ) { HRESULT hres; ULONG64 endOffset = 0; - hres = dbgExt->control->Assemble( m_currentOffset, instr.c_str(), &endOffset ); + hres = m_control->Assemble( m_currentOffset, instr.c_str(), &endOffset ); if ( FAILED( hres ) ) throw DbgException( "IDebugControl::Assemble failed" ); @@ -74,3 +99,4 @@ disasm::assembly( const std::string &instr ) ///////////////////////////////////////////////////////////////////////////////// +}; // end pykd namespace diff --git a/pykd/disasm.h b/pykd/disasm.h index 5c54503..59ca560 100644 --- a/pykd/disasm.h +++ b/pykd/disasm.h @@ -1,14 +1,18 @@ #pragma once -#include "dbgmem.h" +#include "dbgobj.h" + +namespace pykd { ///////////////////////////////////////////////////////////////////////////////// -class disasm { +class Disasm : private DbgObject { public: - disasm( ULONG64 offset = 0); + Disasm( IDebugClient4 *client, ULONG64 offset = 0 ); + + Disasm( ULONG64 offset = 0); std::string disassemble() { std::string s = m_disasm; @@ -60,3 +64,6 @@ private: }; ///////////////////////////////////////////////////////////////////////////////// + +} ; // end pykd namespace + diff --git a/pykd/module.h b/pykd/module.h index cc67dc1..56a366a 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -80,8 +80,6 @@ private: ULONG64 m_base; ULONG m_size; pyDia::GlobalScopePtr m_dia; - - }; /////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 8885a94..9ce30fb 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -393,6 +393,10 @@ RelativePath=".\diawrapper.cpp" > + + @@ -487,6 +491,10 @@ RelativePath=".\diawrapper.h" > + +