Commit 26c2b2d1 authored by SND\kernelnet_cp's avatar SND\kernelnet_cp
Browse files

[pykd] refactored: disasm class


git-svn-id: https://pykd.svn.codeplex.com/svn@69944 9b283d60-5439-405e-af05-b73fd8c4d996
parent 9603376e
......@@ -221,7 +221,6 @@ BOOST_PYTHON_MODULE( pykd )
"Delete synthetic symbols by virtual address" );
boost::python::def( "delSynSymbolsMask", &delSyntheticSymbolsMask,
"Delete synthetic symbols by mask of module and symbol name");
boost::python::def( "assembly", &assembly, "Assemble a single processor instruction" );
boost::python::class_<TypeInfo>( "typeInfo",
"Class representing non-primitive type info: structure, union, etc. attributes is a fields of non-primitive type" )
......@@ -380,12 +379,14 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::class_<disasm>("disasm", "Class disassemble a processor instructions", boost::python::no_init )
.def( boost::python::init<>( "constructor" ) )
.def( boost::python::init<ULONG64>( boost::python::args("offset"), "constructor" ) )
.def( "next", &disasm::next, "Disassemble next instruction" )
.def( "disasm", &disasm::disassemble, "Disassemble next instruction" )
.def( "sasm", &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( "ea", &disasm::ea, "Return effective address for last disassembled instruction or 0" )
.def( "reset", &disasm::reset, "Reset current offset to begin" );
//
......
......@@ -2,32 +2,39 @@
#include "dbgext.h"
#include "disasm.h"
#include "dbgexcept.h"
#include "dbgmem.h"
/////////////////////////////////////////////////////////////////////////////////
void disasm::doDisasm()
disasm::disasm( ULONG64 offset )
{
HRESULT hres;
char buffer[0x100];
ULONG disasmSize = 0;
ULONG64 offset = addr64(m_currentOffset);
ULONG64 endOffset = 0;
m_beginOffset = addr64(offset);
if ( m_beginOffset == 0 )
{
ULONG64 currentOffset = 0;
hres = dbgExt->registers->GetInstructionOffset( &currentOffset );
hres = dbgExt->registers->GetInstructionOffset( &m_beginOffset );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegisters::GetInstructionOffset failed" );
offset += currentOffset;
}
m_currentOffset = m_beginOffset;
doDisasm();
}
/////////////////////////////////////////////////////////////////////////////////
void disasm::doDisasm()
{
HRESULT hres;
char buffer[0x100];
ULONG disasmSize = 0;
ULONG64 endOffset = 0;
hres =
dbgExt->control->Disassemble(
offset,
m_currentOffset,
DEBUG_DISASM_EFFECTIVE_ADDRESS,
buffer,
sizeof(buffer),
......@@ -41,24 +48,29 @@ void disasm::doDisasm()
if ( FAILED( hres ) )
m_ea = 0;
m_length = (ULONG)(endOffset - offset);
m_length = (ULONG)(endOffset - m_currentOffset);
m_disasm = std::string( buffer, disasmSize - 2);
}
/////////////////////////////////////////////////////////////////////////////////
ULONG64
assembly( ULONG64 offset, const std::string &instr )
std::string
disasm::assembly( const std::string &instr )
{
HRESULT hres;
ULONG64 endOffset = 0;
hres = dbgExt->control->Assemble( offset, instr.c_str(), &endOffset );
hres = dbgExt->control->Assemble( m_currentOffset, instr.c_str(), &endOffset );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::Assemble failed" );
throw DbgException( "IDebugControl::Assemble failed" );
m_currentOffset = endOffset;
doDisasm();
return endOffset;
return m_disasm;
}
/////////////////////////////////////////////////////////////////////////////////
\ No newline at end of file
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dbgmem.h"
/////////////////////////////////////////////////////////////////////////////////
class disasm {
public:
disasm( ULONG64 offset = 0) :
m_beginOffset( offset ),
m_currentOffset( offset ) {
doDisasm();
}
disasm( ULONG64 offset = 0);
std::string next() {
std::string disassemble() {
std::string s = m_disasm;
m_currentOffset += m_length;
doDisasm();
return s;
}
std::string reset() {
m_currentOffset = m_beginOffset;
doDisasm();
return m_disasm;
}
}
std::string
assembly( const std::string &instr );
std::string instruction() const {
return m_disasm;
......@@ -51,7 +59,4 @@ private:
std::string m_disasm;
};
ULONG64
assembly( ULONG64 offset, const std::string &instr );
/////////////////////////////////////////////////////////////////////////////////
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment