mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[pykd] added : class disasm
git-svn-id: https://pykd.svn.codeplex.com/svn@68358 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
9545cf5df0
commit
89c524741a
@ -28,6 +28,7 @@
|
||||
#include "dbgbreak.h"
|
||||
#include "dbgio.h"
|
||||
#include "intbase.h"
|
||||
#include "disasm.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -346,6 +347,17 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Unload module event. Parameter is instance of dbgModuleClass. "
|
||||
"For ignore event method must return DEBUG_STATUS_NO_CHANGE value" );
|
||||
|
||||
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( "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" );
|
||||
|
||||
|
||||
// èñêëþ÷åíèÿ
|
||||
boost::python::class_<DbgException> dbgExceptionClass( "BaseException",
|
||||
"Pykd base exception class",
|
||||
|
49
pykd/disasm.cpp
Normal file
49
pykd/disasm.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "stdafx.h"
|
||||
#include "dbgext.h"
|
||||
#include "disasm.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgmem.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void disasm::doDisasm()
|
||||
{
|
||||
HRESULT hres;
|
||||
char buffer[0x100];
|
||||
ULONG disasmSize = 0;
|
||||
ULONG64 offset = addr64(m_currentOffset);
|
||||
ULONG64 endOffset = 0;
|
||||
|
||||
if ( m_beginOffset == 0 )
|
||||
{
|
||||
ULONG64 currentOffset = 0;
|
||||
|
||||
hres = dbgExt->registers->GetInstructionOffset( ¤tOffset );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugRegisters::GetInstructionOffset failed" );
|
||||
|
||||
offset += currentOffset;
|
||||
}
|
||||
|
||||
hres =
|
||||
dbgExt->control->Disassemble(
|
||||
offset,
|
||||
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 - offset);
|
||||
|
||||
m_disasm = std::string( buffer, disasmSize - 2);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
54
pykd/disasm.h
Normal file
54
pykd/disasm.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class disasm {
|
||||
|
||||
public:
|
||||
|
||||
disasm( ULONG64 offset = 0) :
|
||||
m_beginOffset( offset ),
|
||||
m_currentOffset( offset ) {
|
||||
doDisasm();
|
||||
}
|
||||
|
||||
std::string next() {
|
||||
m_currentOffset += m_length;
|
||||
doDisasm();
|
||||
return m_disasm;
|
||||
}
|
||||
|
||||
|
||||
std::string instruction() const {
|
||||
return m_disasm;
|
||||
}
|
||||
|
||||
ULONG64 begin() const {
|
||||
return m_beginOffset;
|
||||
}
|
||||
|
||||
ULONG64 current() const {
|
||||
return m_currentOffset;
|
||||
}
|
||||
|
||||
ULONG length() const {
|
||||
return m_length;
|
||||
}
|
||||
|
||||
ULONG64 ea() const {
|
||||
return m_ea;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void doDisasm();
|
||||
|
||||
ULONG64 m_beginOffset;
|
||||
ULONG64 m_currentOffset;
|
||||
ULONG64 m_ea;
|
||||
ULONG m_length;
|
||||
|
||||
std::string m_disasm;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -424,6 +424,10 @@
|
||||
RelativePath=".\dbgtype.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\disasm.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pykd.def"
|
||||
>
|
||||
@ -550,6 +554,10 @@
|
||||
RelativePath=".\dbgtype.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\disasm.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\intbase.h"
|
||||
>
|
||||
|
@ -1,14 +1,10 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Version="9,00"
|
||||
Name="pykd"
|
||||
ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}"
|
||||
RootNamespace="pykd"
|
||||
SccProjectName="SAK"
|
||||
SccAuxPath="SAK"
|
||||
SccLocalPath="SAK"
|
||||
SccProvider="SAK"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="0"
|
||||
>
|
||||
@ -417,6 +413,10 @@
|
||||
RelativePath=".\dbgtype.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\disasm.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\pykd.cpp"
|
||||
>
|
||||
@ -539,6 +539,14 @@
|
||||
RelativePath=".\dbgtype.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\disasm.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\intbase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resource.h"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user