[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:
SND\kernelnet_cp 2011-10-26 06:55:20 +00:00 committed by Mikhail I. Izmestev
parent 0c12f39ea7
commit d722dd73df

76
pykd/disasm.cpp Normal file
View 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;
}
/////////////////////////////////////////////////////////////////////////////////