diff --git a/pykd/disasm.cpp b/pykd/disasm.cpp index 2326f75..5c5d135 100644 --- a/pykd/disasm.cpp +++ b/pykd/disasm.cpp @@ -50,4 +50,10 @@ Disasm::assembly( const std::string &instr ) ///////////////////////////////////////////////////////////////////////////////// +ULONG64 Disasm::getNearInstruction( LONG delta ) { + return pykd::getNearInstruction( m_currentOffset, delta ); +} + +///////////////////////////////////////////////////////////////////////////////// + }; // end pykd namespace diff --git a/pykd/disasm.h b/pykd/disasm.h index 2c9fdb3..6c89d5b 100644 --- a/pykd/disasm.h +++ b/pykd/disasm.h @@ -23,6 +23,14 @@ public: return disassemble(); } + std::string jumprel(LONG delta) { + m_currentOffset = getNearInstruction(delta); + doDisasm(); + return disassemble(); + } + + ULONG64 getNearInstruction( LONG delta ); + std::string reset() { m_currentOffset = m_beginOffset; doDisasm(); diff --git a/pykd/disasmengine.h b/pykd/disasmengine.h index 9180bab..9efe102 100644 --- a/pykd/disasmengine.h +++ b/pykd/disasmengine.h @@ -4,5 +4,6 @@ namespace pykd { void disasmAssemblay( ULONG64 offset, const std::string &instruction, ULONG64 &nextOffset ); void disasmDisassembly( ULONG64 offset, std::string &instruction, ULONG64 &nextOffset, ULONG64 &ea ); +ULONG64 getNearInstruction( ULONG64 offset, LONG delta ); } // end pykd namespace \ No newline at end of file diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index 4f1e549..f81908a 100644 --- a/pykd/python/pymod.cpp +++ b/pykd/python/pymod.cpp @@ -563,7 +563,11 @@ BOOST_PYTHON_MODULE( pykd ) .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" ); + .def( "reset", &Disasm::reset, "Reset current offset to begin" ) + .def( "findOffset", &Disasm::getNearInstruction, "Return the location of a processor instruction relative to a given location" ) + .def( "jump", &Disasm::jump, "Change current instruction" ) + .def( "jumprel", &Disasm::jumprel, "Change current instruction" ); + python::enum_("eventResult", "Return value of event handler") .value("Proceed", DebugCallbackProceed) diff --git a/pykd/win/dbgasm.cpp b/pykd/win/dbgasm.cpp index f5c3195..6e1a5f5 100644 --- a/pykd/win/dbgasm.cpp +++ b/pykd/win/dbgasm.cpp @@ -49,4 +49,20 @@ void disasmDisassembly( ULONG64 offset, std::string &instruction, ULONG64 &nextO /////////////////////////////////////////////////////////////////////////////// +ULONG64 getNearInstruction( ULONG64 offset, LONG delta ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG64 nearOffset; + + hres = g_dbgEng->control->GetNearInstruction( offset, delta, &nearOffset ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetNearInstruction", hres ); + + return nearOffset; +} + +/////////////////////////////////////////////////////////////////////////////// + } // end pykd namespace