[0.1.x] added : disasm class

git-svn-id: https://pykd.svn.codeplex.com/svn@70760 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-10-26 07:10:44 +00:00 committed by Mikhail I. Izmestev
parent d722dd73df
commit 95c135ed38
7 changed files with 81 additions and 21 deletions

View File

@ -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 &param );
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 );

View File

@ -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>("disasm", "Class disassemble a processor instructions" )
.def( python::init<>( "constructor" ) )
.def( python::init<ULONG64>( 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");

View File

@ -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<IDebugSymbols3> m_symbols;
CComPtr<IDebugAdvanced2> m_advanced;
CComPtr<IDebugDataSpaces> m_dataSpaces;
CComPtr<IDebugRegisters> m_registers;
};

View File

@ -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

View File

@ -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

View File

@ -80,8 +80,6 @@ private:
ULONG64 m_base;
ULONG m_size;
pyDia::GlobalScopePtr m_dia;
};
///////////////////////////////////////////////////////////////////////////////////

View File

@ -393,6 +393,10 @@
RelativePath=".\diawrapper.cpp"
>
</File>
<File
RelativePath=".\disasm.cpp"
>
</File>
<File
RelativePath=".\module.cpp"
>
@ -487,6 +491,10 @@
RelativePath=".\diawrapper.h"
>
</File>
<File
RelativePath=".\disasm.h"
>
</File>
<File
RelativePath=".\intbase.h"
>