mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
ready for release
git-svn-id: https://pykd.svn.codeplex.com/svn@52944 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
5b7de9d7f8
commit
5f7636ac4b
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgcmd.h"
|
||||
#include "dbgexcept.h"
|
||||
|
||||
@ -104,9 +103,9 @@ dbgCommand( const std::string &command )
|
||||
|
||||
try {
|
||||
|
||||
OutputReader outReader( g_Ext->m_Client );
|
||||
OutputReader outReader( dbgExt->client );
|
||||
|
||||
hres = g_Ext->m_Control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
|
||||
hres = dbgExt->control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::Execute failed" );
|
||||
|
||||
@ -114,11 +113,11 @@ dbgCommand( const std::string &command )
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return "error";
|
||||
|
@ -10,7 +10,5 @@
|
||||
std::string
|
||||
dbgCommand( const std::string &command );
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
63
pykd/dbgdump.cpp
Normal file
63
pykd/dbgdump.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgdump.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgsession.h"
|
||||
#include "dbgsystem.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
dbgLoadDump( const std::string &fileName )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
wchar_t *fileNameW = NULL;
|
||||
|
||||
try {
|
||||
|
||||
fileNameW = new wchar_t [ fileName.size()+ 1 ];
|
||||
|
||||
MultiByteToWideChar(
|
||||
CP_ACP,
|
||||
0,
|
||||
fileName.c_str(),
|
||||
fileName.size() + 1,
|
||||
fileNameW,
|
||||
fileName.size() + 1 );
|
||||
|
||||
hres = dbgExt->client4->OpenDumpFileWide( fileNameW, NULL );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugClient4::OpenDumpFileWide failed" );
|
||||
|
||||
hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
||||
|
||||
dbgSessionStarted = true;
|
||||
|
||||
if ( fileNameW )
|
||||
delete[] fileNameW;
|
||||
|
||||
return "loaded ok";
|
||||
}
|
||||
catch( std::exception& )
|
||||
{
|
||||
//g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
//g_Ext->Out( "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
std::string result = "failed to open dump ";
|
||||
result += fileName;
|
||||
|
||||
if ( fileNameW )
|
||||
delete[] fileNameW;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
10
pykd/dbgdump.h
Normal file
10
pykd/dbgdump.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
dbgLoadDump( const std::string &dumpName );
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
133
pykd/dbgext.cpp
133
pykd/dbgext.cpp
@ -1,12 +1,13 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
#include <wdbgexts.h>
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/module.hpp>
|
||||
#include <boost/python/def.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgprint.h"
|
||||
#include "dbgreg.h"
|
||||
#include "dbgtype.h"
|
||||
@ -15,13 +16,24 @@
|
||||
#include "dbgmem.h"
|
||||
#include "dbgsystem.h"
|
||||
#include "dbgcmd.h"
|
||||
#include "dbgdump.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgsession.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DbgExt *dbgExt = NULL;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOST_PYTHON_MODULE( pykd )
|
||||
{
|
||||
boost::python::def( "createSession", &dbgCreateSession );
|
||||
boost::python::def( "isSessionStart", &dbgIsSessionStart );
|
||||
boost::python::def( "symbolsPath", &dbgSymPath );
|
||||
boost::python::def( "dprint", &DbgPrint::dprint );
|
||||
boost::python::def( "dprintln", &DbgPrint::dprintln );
|
||||
boost::python::def( "loadDump", &dbgLoadDump );
|
||||
boost::python::def( "dbgCommand", &dbgCommand );
|
||||
boost::python::def( "is64bitSystem", is64bitSystem );
|
||||
boost::python::def( "reg", &loadRegister );
|
||||
@ -36,82 +48,82 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
boost::python::class_<typedVarClass>( "typedVarClass" )
|
||||
.def("getAddress", &typedVarClass::getAddress );
|
||||
boost::python::class_<dbgModuleClass>( "dbgModuleClass" )
|
||||
.add_property("begin", &dbgModuleClass::getBegin )
|
||||
.add_property("end", &dbgModuleClass::getEnd )
|
||||
.def("begin", &dbgModuleClass::getBegin )
|
||||
.def("end", &dbgModuleClass::getEnd )
|
||||
.def("name", &dbgModuleClass::getName )
|
||||
.def("contain", &dbgModuleClass::contain );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXT_CLASS : public ExtExtension
|
||||
HRESULT
|
||||
CALLBACK
|
||||
DebugExtensionInitialize(
|
||||
OUT PULONG Version,
|
||||
OUT PULONG Flags )
|
||||
{
|
||||
public:
|
||||
|
||||
virtual HRESULT Initialize(void) {
|
||||
|
||||
HRESULT hr = ExtExtension::Initialize();
|
||||
if ( FAILED( hr ) )
|
||||
return hr;
|
||||
|
||||
Py_Initialize();
|
||||
|
||||
PyImport_AppendInittab("pykd",initpykd );
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
virtual void Uninitialize(void) {
|
||||
*Version = DEBUG_EXTENSION_VERSION( 1, 0 );
|
||||
*Flags = 0;
|
||||
|
||||
PyImport_AppendInittab("pykd", initpykd );
|
||||
|
||||
Py_Initialize();
|
||||
|
||||
Py_Finalize();
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
EXT_COMMAND_METHOD( info );
|
||||
EXT_COMMAND_METHOD( exec );
|
||||
};
|
||||
|
||||
EXT_DECLARE_GLOBALS();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
EXT_COMMAND(
|
||||
info,
|
||||
"Python Info",
|
||||
"" )
|
||||
dbgSessionStarted = true;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
CALLBACK
|
||||
DebugExtensionUninitialize()
|
||||
{
|
||||
Out( "Python Info" );
|
||||
Py_Finalize();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
EXT_COMMAND(
|
||||
exec,
|
||||
"Execute python code",
|
||||
"{f;b;;quite mode}{;x}" )
|
||||
void
|
||||
SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt )
|
||||
{
|
||||
client->QueryInterface( __uuidof(IDebugClient), (void **)&dbgExt->client );
|
||||
client->QueryInterface( __uuidof(IDebugClient4), (void **)&dbgExt->client4 );
|
||||
|
||||
|
||||
client->QueryInterface( __uuidof(IDebugControl), (void **)&dbgExt->control );
|
||||
|
||||
client->QueryInterface( __uuidof(IDebugRegisters), (void **)&dbgExt->registers );
|
||||
|
||||
client->QueryInterface( __uuidof(IDebugSymbols), (void ** )&dbgExt->symbols );
|
||||
client->QueryInterface( __uuidof(IDebugSymbols2), (void ** )&dbgExt->symbols2 );
|
||||
client->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&dbgExt->symbols3 );
|
||||
|
||||
client->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dbgExt->dataSpaces );
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
HRESULT
|
||||
CALLBACK
|
||||
py( PDEBUG_CLIENT4 client, PCSTR args)
|
||||
{
|
||||
bool fromFile = false;
|
||||
|
||||
if ( HasArg( "f" ) )
|
||||
fromFile = true;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
DbgExt ext = { 0 };
|
||||
|
||||
SetupDebugEngine( client, &ext );
|
||||
dbgExt = &ext;
|
||||
|
||||
boost::python::object main = boost::python::import("__main__");
|
||||
|
||||
boost::python::object global(main.attr("__dict__"));
|
||||
|
||||
boost::python::object result;
|
||||
|
||||
if ( fromFile )
|
||||
{
|
||||
result = boost::python::exec_file( GetUnnamedArgStr( 0 ), global, global );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = boost::python::exec( GetUnnamedArgStr( 0 ), global, global );
|
||||
}
|
||||
result = boost::python::exec_file( args, global, global );
|
||||
|
||||
}
|
||||
catch( boost::python::error_already_set const & )
|
||||
{
|
||||
@ -135,9 +147,10 @@ EXT_COMMAND(
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
27
pykd/dbgext.h
Normal file
27
pykd/dbgext.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <dbgeng.h>
|
||||
|
||||
struct DbgExt {
|
||||
|
||||
IDebugClient *client;
|
||||
IDebugClient4 *client4;
|
||||
|
||||
IDebugControl *control;
|
||||
|
||||
IDebugRegisters *registers;
|
||||
|
||||
IDebugSymbols *symbols;
|
||||
IDebugSymbols2 *symbols2;
|
||||
IDebugSymbols3 *symbols3;
|
||||
|
||||
IDebugDataSpaces *dataSpaces;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern DbgExt *dbgExt;
|
||||
|
||||
void
|
||||
SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt );
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgmem.h"
|
||||
|
||||
@ -16,7 +15,7 @@ loadMemory( ULONG64 address, PVOID dest, ULONG length )
|
||||
|
||||
try {
|
||||
|
||||
HRESULT hres = g_Ext->m_Data->ReadVirtual( address, dest, length, NULL );
|
||||
HRESULT hres = dbgExt->dataSpaces->ReadVirtual( address, dest, length, NULL );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugDataSpace::ReadVirtual failed" );
|
||||
|
||||
@ -25,11 +24,11 @@ loadMemory( ULONG64 address, PVOID dest, ULONG length )
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "Kd2Lua unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -62,11 +61,11 @@ compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length )
|
||||
|
||||
try {
|
||||
|
||||
hres = g_Ext->m_Data->ReadVirtual( addr1, m1, length, NULL );
|
||||
hres = dbgExt->dataSpaces->ReadVirtual( addr1, m1, length, NULL );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugDataSpace::ReadVirtual failed" );
|
||||
|
||||
hres = g_Ext->m_Data->ReadVirtual( addr2, m2, length, NULL );
|
||||
hres = dbgExt->dataSpaces->ReadVirtual( addr2, m2, length, NULL );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugDataSpace::ReadVirtual failed" );
|
||||
|
||||
@ -75,11 +74,11 @@ compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length )
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "Kd2Lua unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
delete[] m1;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgmodule.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgmem.h"
|
||||
@ -15,26 +14,26 @@ loadModule( const std::string &moduleName )
|
||||
|
||||
try {
|
||||
ULONG64 moduleBase;
|
||||
hres = g_Ext->m_Symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||
hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" );
|
||||
|
||||
DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
|
||||
hres = g_Ext->m_Symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
|
||||
hres = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
|
||||
|
||||
|
||||
return boost::python::object( dbgModuleClass( moduleBase, moduleParam.Size ) );
|
||||
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) );
|
||||
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return boost::python::object();
|
||||
@ -53,7 +52,7 @@ findModule( ULONG64 addr )
|
||||
|
||||
ULONG moduleIndex;
|
||||
ULONG64 moduleBase;
|
||||
hres = g_Ext->m_Symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase );
|
||||
hres = dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
{
|
||||
@ -61,24 +60,70 @@ findModule( ULONG64 addr )
|
||||
}
|
||||
|
||||
DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
|
||||
hres = g_Ext->m_Symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
|
||||
hres = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
|
||||
|
||||
|
||||
return boost::python::object( dbgModuleClass( moduleBase, moduleParam.Size ) );
|
||||
char moduleName[0x100];
|
||||
|
||||
hres =
|
||||
dbgExt->symbols->GetModuleNames(
|
||||
moduleIndex,
|
||||
0,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
moduleName,
|
||||
sizeof( moduleName ),
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetModuleNames failed" );
|
||||
|
||||
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) );
|
||||
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return boost::python::object();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
dbgModuleClass::reloadSymbols()
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
std::string reloadParam = "/f "; //"/f /s ";
|
||||
reloadParam += m_name;
|
||||
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::Reload failed" );
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -15,8 +15,9 @@ public:
|
||||
m_base( 0 ),
|
||||
m_end( 0 )
|
||||
{}
|
||||
|
||||
dbgModuleClass( ULONG64 base, ULONG size ) :
|
||||
|
||||
dbgModuleClass( const std::string &name, ULONG64 base, ULONG size ) :
|
||||
m_name( name ),
|
||||
m_base( base ),
|
||||
m_end( base + size )
|
||||
{}
|
||||
@ -39,11 +40,21 @@ public:
|
||||
return m_base <= addr && addr <= m_end;
|
||||
}
|
||||
|
||||
std::string
|
||||
getName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void
|
||||
reloadSymbols();
|
||||
|
||||
private:
|
||||
|
||||
ULONG64 m_base;
|
||||
ULONG64 m_end;
|
||||
ULONG64 m_base;
|
||||
|
||||
ULONG64 m_end;
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,16 +1,22 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "dbgprint.h"
|
||||
#include <engextcpp.hpp>
|
||||
#include "dbgext.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void DbgPrint::dprint( const string& str )
|
||||
{
|
||||
g_Ext->Dml( str.c_str() );
|
||||
HRESULT hres = dbgExt->control->ControlledOutput( DEBUG_OUTCTL_AMBIENT_DML, DEBUG_OUTPUT_NORMAL, str.c_str() );
|
||||
if ( FAILED( hres ) )
|
||||
std::cout << str;
|
||||
}
|
||||
|
||||
void DbgPrint::dprintln( const std::string& str )
|
||||
{
|
||||
g_Ext->Dml( str.c_str() );
|
||||
g_Ext->Dml( "\r\n" );
|
||||
}
|
||||
DbgPrint::dprint( str );
|
||||
DbgPrint::dprint( "\r\n" );
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,8 @@ class DbgPrint {
|
||||
public:
|
||||
|
||||
static void dprint( const std::string& str );
|
||||
|
||||
|
||||
static void dprintln( const std::string& str );
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgreg.h"
|
||||
#include "dbgexcept.h"
|
||||
|
||||
@ -12,19 +11,18 @@ using namespace std;
|
||||
boost::python::object
|
||||
loadRegister( const std::string ®isterName )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
|
||||
ULONG registerIndex = 0;
|
||||
|
||||
hres = g_Ext->m_Registers->GetIndexByName( registerName.c_str(), ®isterIndex );
|
||||
hres = dbgExt->registers->GetIndexByName( registerName.c_str(), ®isterIndex );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugRegister::GetIndexByName failed" );
|
||||
|
||||
DEBUG_VALUE debugValue;
|
||||
hres = g_Ext->m_Registers->GetValue( registerIndex, &debugValue );
|
||||
hres = dbgExt->registers->GetValue( registerIndex, &debugValue );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugRegister::GetValue failed" );
|
||||
|
||||
@ -49,11 +47,11 @@ loadRegister( const std::string ®isterName )
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return boost::python::str( "REG_ERR" );
|
||||
|
24
pykd/dbgsession.cpp
Normal file
24
pykd/dbgsession.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "dbgsession.h"
|
||||
#include "dbgext.h"
|
||||
|
||||
DbgExt dbgGlobalSession = { 0 };
|
||||
|
||||
bool dbgSessionStarted = false;
|
||||
|
||||
void
|
||||
dbgCreateSession()
|
||||
{
|
||||
IDebugClient4 *client = NULL;
|
||||
DebugCreate( __uuidof(IDebugClient4), (void **)&client );
|
||||
|
||||
SetupDebugEngine( client, &dbgGlobalSession );
|
||||
dbgExt = &dbgGlobalSession;
|
||||
}
|
||||
|
||||
bool
|
||||
dbgIsSessionStart()
|
||||
{
|
||||
return dbgSessionStarted;
|
||||
}
|
11
pykd/dbgsession.h
Normal file
11
pykd/dbgsession.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
void
|
||||
dbgCreateSession();
|
||||
|
||||
extern
|
||||
bool dbgSessionStarted;
|
||||
|
||||
bool
|
||||
dbgIsSessionStart();
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgsym.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgprint.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -22,7 +22,7 @@ findSymbolForAddress( ULONG64 addr )
|
||||
|
||||
ULONG moduleIndex;
|
||||
ULONG64 moduleBase;
|
||||
hres = g_Ext->m_Symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase );
|
||||
hres = dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
{
|
||||
@ -30,14 +30,14 @@ findSymbolForAddress( ULONG64 addr )
|
||||
}
|
||||
|
||||
char moduleName[0x100];
|
||||
hres = g_Ext->m_Symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, moduleIndex, moduleBase,
|
||||
hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, moduleIndex, moduleBase,
|
||||
moduleName, sizeof( moduleName ), NULL );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol2::GetModuleNameString failed" );
|
||||
|
||||
ULONG entries = 0;
|
||||
hres = g_Ext->m_Symbols3->GetSymbolEntriesByOffset( addr, 0, &debugId, &displace, 1, &entries );
|
||||
hres = dbgExt->symbols3->GetSymbolEntriesByOffset( addr, 0, &debugId, &displace, 1, &entries );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol3::GetSymbolEntriesByOffset failed" );
|
||||
|
||||
@ -50,7 +50,7 @@ findSymbolForAddress( ULONG64 addr )
|
||||
}
|
||||
|
||||
char symbolName[0x100];
|
||||
hres = g_Ext->m_Symbols3->GetSymbolEntryString( &debugId, 0, symbolName, sizeof(symbolName ), NULL );
|
||||
hres = dbgExt->symbols3->GetSymbolEntryString( &debugId, 0, symbolName, sizeof(symbolName ), NULL );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol3::GetSymbolEntryString failed" );
|
||||
|
||||
@ -60,11 +60,11 @@ findSymbolForAddress( ULONG64 addr )
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return boost::python::object( addr );
|
||||
@ -84,7 +84,7 @@ findAddressForSymbol( const std::string &moduleName, const std::string &symbol
|
||||
ModuleSymName += symbolName;
|
||||
|
||||
ULONG64 offset = 0ULL;
|
||||
hres = g_Ext->m_Symbols->GetOffsetByName( ModuleSymName.c_str(), &offset );
|
||||
hres = dbgExt->symbols->GetOffsetByName( ModuleSymName.c_str(), &offset );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetOffsetByName failed" );
|
||||
|
||||
@ -92,11 +92,11 @@ findAddressForSymbol( const std::string &moduleName, const std::string &symbol
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return (ULONG64)~0;
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
#include <exception>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgsystem.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
is64bitSystem()
|
||||
@ -13,21 +13,60 @@ is64bitSystem()
|
||||
HRESULT hres;
|
||||
|
||||
try {
|
||||
hres = g_Ext->m_Control->IsPointer64Bit();
|
||||
|
||||
hres = dbgExt->control->IsPointer64Bit();
|
||||
|
||||
return hres == S_OK;
|
||||
return hres == S_OK;
|
||||
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
dbgSymPath()
|
||||
{
|
||||
HRESULT hres;
|
||||
char *path = NULL;
|
||||
std::string pathStr;
|
||||
|
||||
try {
|
||||
|
||||
ULONG size;
|
||||
dbgExt->symbols->GetSymbolPath( NULL, 0, &size );
|
||||
|
||||
path = new char[ size ];
|
||||
hres = dbgExt->symbols->GetSymbolPath( path, size, NULL );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbols::GetSymbolPath failed" );
|
||||
|
||||
pathStr = path;
|
||||
|
||||
}
|
||||
catch( std::exception &e )
|
||||
{
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
if ( path )
|
||||
delete[] path;
|
||||
|
||||
return pathStr;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
@ -11,4 +13,8 @@ ptrSize() {
|
||||
return is64bitSystem() ? 8 : 4;
|
||||
}
|
||||
|
||||
std::string
|
||||
dbgSymPath();
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <engextcpp.hpp>
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgtype.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgmem.h"
|
||||
@ -76,12 +75,12 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6
|
||||
return valueLoader<void*>( address, ptrSize() );
|
||||
}
|
||||
|
||||
hres = g_Ext->m_Symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||
hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" );
|
||||
|
||||
ULONG typeId;
|
||||
hres = g_Ext->m_Symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId );
|
||||
hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetTypeId failed" );
|
||||
|
||||
@ -91,23 +90,23 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6
|
||||
for ( ULONG i = 0; ; ++i )
|
||||
{
|
||||
char fieldName[100];
|
||||
hres = g_Ext->m_Symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL );
|
||||
hres = dbgExt->symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
break;
|
||||
|
||||
ULONG fieldTypeId;
|
||||
ULONG fieldOffset;
|
||||
hres = g_Ext->m_Symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset );
|
||||
hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol3::GetFieldTypeAndOffset failed" );
|
||||
|
||||
char fieldTypeName[100];
|
||||
hres = g_Ext->m_Symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL );
|
||||
hres = dbgExt->symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL );
|
||||
|
||||
ULONG fieldSize;
|
||||
hres = g_Ext->m_Symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize );
|
||||
hres = dbgExt->symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetTypeName failed" );
|
||||
@ -127,11 +126,11 @@ loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG6
|
||||
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return boost::python::str( "VAR_ERR" );
|
||||
@ -148,29 +147,29 @@ containingRecord( ULONG64 address, const std::string &moduleName, const std::str
|
||||
|
||||
ULONG64 moduleBase;
|
||||
|
||||
hres = g_Ext->m_Symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||
hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" );
|
||||
|
||||
ULONG typeId;
|
||||
hres = g_Ext->m_Symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId );
|
||||
hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugSymbol::GetTypeId failed" );
|
||||
|
||||
ULONG fieldTypeId;
|
||||
ULONG fieldOffset;
|
||||
hres = g_Ext->m_Symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName.c_str(), &fieldTypeId, &fieldOffset );
|
||||
hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName.c_str(), &fieldTypeId, &fieldOffset );
|
||||
|
||||
return loadTypedVar( moduleName, typeName, address - fieldOffset );
|
||||
}
|
||||
|
||||
catch( std::exception &e )
|
||||
{
|
||||
g_Ext->Out( "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
g_Ext->Out( "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
|
||||
return boost::python::str( "VAR_ERR" );
|
||||
|
@ -3,4 +3,4 @@ EXPORTS
|
||||
DebugExtensionUninitialize
|
||||
|
||||
info
|
||||
exec
|
||||
py
|
@ -66,7 +66,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dbgeng.lib engextcpp.lib"
|
||||
AdditionalDependencies="dbgeng.lib "
|
||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\i386";"$(PYTHON_ROOT)\x86\libs";"$(BOOST_ROOT)\stage\lib""
|
||||
ModuleDefinitionFile="pykd.def"
|
||||
@ -149,6 +150,7 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dbgeng.lib engextcpp.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\amd64";"$(PYTHON_ROOT)\x64\libs";"$(BOOST_ROOT)\stage64\lib""
|
||||
ModuleDefinitionFile="pykd.def"
|
||||
@ -225,7 +227,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dbgeng.lib engextcpp.lib"
|
||||
AdditionalDependencies="dbgeng.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\i386";"$(PYTHON_ROOT)\x86\libs";"$(BOOST_ROOT)\stage\lib""
|
||||
ModuleDefinitionFile="pykd.def"
|
||||
@ -305,7 +308,8 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="dbgeng.lib engextcpp.lib"
|
||||
AdditionalDependencies="dbgeng.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).pyd"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""$(DBG_SDK_ROOT)\lib\amd64";"$(PYTHON_ROOT)\x64\libs";"$(BOOST_ROOT)\stage64\lib""
|
||||
ModuleDefinitionFile="pykd.def"
|
||||
@ -353,6 +357,10 @@
|
||||
RelativePath=".\dbgcmd.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgdump.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgext.cpp"
|
||||
>
|
||||
@ -373,6 +381,10 @@
|
||||
RelativePath=".\dbgreg.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsession.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsym.cpp"
|
||||
>
|
||||
@ -435,10 +447,18 @@
|
||||
RelativePath=".\dbgcmd.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgdump.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgexcept.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgext.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgmem.h"
|
||||
>
|
||||
@ -455,6 +475,10 @@
|
||||
RelativePath=".\dbgreg.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsession.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsym.h"
|
||||
>
|
||||
|
@ -25,8 +25,13 @@
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define __field_ecount_opt(x)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user