mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 21:03:23 +08:00
[0.0 -> 0.1 ] integrated : disasm.cpp
git-svn-id: https://pykd.svn.codeplex.com/svn@70759 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
0c12f39ea7
commit
d722dd73df
76
pykd/disasm.cpp
Normal file
76
pykd/disasm.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
|
#include "dbgext.h"
|
||||||
|
#include "disasm.h"
|
||||||
|
#include "dbgexcept.h"
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
disasm::disasm( ULONG64 offset )
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
m_beginOffset = addr64(offset);
|
||||||
|
|
||||||
|
if ( m_beginOffset == 0 )
|
||||||
|
{
|
||||||
|
hres = dbgExt->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];
|
||||||
|
ULONG disasmSize = 0;
|
||||||
|
ULONG64 endOffset = 0;
|
||||||
|
|
||||||
|
hres =
|
||||||
|
dbgExt->control->Disassemble(
|
||||||
|
m_currentOffset,
|
||||||
|
DEBUG_DISASM_EFFECTIVE_ADDRESS,
|
||||||
|
buffer,
|
||||||
|
sizeof(buffer),
|
||||||
|
&disasmSize,
|
||||||
|
&endOffset );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugControl::Disassemble failed" );
|
||||||
|
|
||||||
|
hres = dbgExt->control->GetDisassembleEffectiveOffset( &m_ea );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
m_ea = 0;
|
||||||
|
|
||||||
|
m_length = (ULONG)(endOffset - m_currentOffset);
|
||||||
|
|
||||||
|
m_disasm = std::string( buffer, disasmSize - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string
|
||||||
|
disasm::assembly( const std::string &instr )
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
ULONG64 endOffset = 0;
|
||||||
|
hres = dbgExt->control->Assemble( m_currentOffset, instr.c_str(), &endOffset );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugControl::Assemble failed" );
|
||||||
|
|
||||||
|
m_currentOffset = endOffset;
|
||||||
|
|
||||||
|
doDisasm();
|
||||||
|
|
||||||
|
return m_disasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue
Block a user