[0.1.x] cleaned project

git-svn-id: https://pykd.svn.codeplex.com/svn@69712 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-09-12 06:59:11 +00:00 committed by Mikhail I. Izmestev
parent 1eea32e3cf
commit 7329a9f7bc
47 changed files with 7524 additions and 7679 deletions

View File

@ -1,162 +1,162 @@
#include "stdafx.h"
#include <boost/format.hpp>
#include "dbgbreak.h"
#include "dbgexcept.h"
#include "pyaux.h"
///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::breakpointMap dbgBreakpointClass::m_breakMap;
///////////////////////////////////////////////////////////////////////////////
HRESULT dbgBreakpointClass::onBreakpointEvnet( IDebugBreakpoint* bp )
{
PyThread_StateSave pyThreadSave;
try {
breakpointMap::iterator it = m_breakMap.find( bp );
if ( it != m_breakMap.end() )
{
boost::python::object &callback = it->second->m_callback;
if (!callback.is_none())
return boost::python::extract<HRESULT>( callback() );
return DEBUG_STATUS_BREAK;
}
}
catch(...)
{
}
return DEBUG_STATUS_NO_CHANGE;
}
///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset, boost::python::object &callback )
: m_offset(offset)
, m_callback(callback)
, m_breakpoint(NULL)
{
set();
}
///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset)
: m_offset(offset)
, m_breakpoint(NULL)
{
// m_callback is None, see dbgBreakpointClass::onBreakpointEvnet
set();
}
///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::~dbgBreakpointClass()
{
remove();
}
///////////////////////////////////////////////////////////////////////////////
bool
dbgBreakpointClass::set()
{
HRESULT hres;
try {
if ( m_breakpoint )
return true;
hres = dbgExt->control->AddBreakpoint( DEBUG_BREAKPOINT_CODE, DEBUG_ANY_ID, &m_breakpoint );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::AddBreakpoint failed" );
hres = m_breakpoint->SetOffset( m_offset );
if ( FAILED( hres ) )
throw DbgException( "IDebugBreakpoint::SetOffset failed" );
hres = m_breakpoint->SetFlags( DEBUG_BREAKPOINT_ENABLED );
if ( FAILED( hres ) )
throw DbgException( "IDebugBreakpoint::SetFlags failed" );
m_breakMap.insert( std::make_pair( m_breakpoint, this ) );
return true;
}
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" );
}
remove();
return false;
}
///////////////////////////////////////////////////////////////////////////////
void
dbgBreakpointClass::remove()
{
if ( m_breakpoint )
{
dbgExt->control->RemoveBreakpoint( m_breakpoint );
breakpointMap::iterator bp = m_breakMap.find( m_breakpoint );
if ( bp != m_breakMap.end() )
m_breakMap.erase( bp );
m_breakpoint = NULL;
}
}
///////////////////////////////////////////////////////////////////////////////
std::string
dbgBreakpointClass::print() const
{
HRESULT status = S_OK;
try
{
if (!m_breakpoint)
return "not set";
DEBUG_BREAKPOINT_PARAMETERS params;
status = m_breakpoint->GetParameters(&params);
if (FAILED(status))
throw DbgException("IDebugBreakpoint::GetParameters failed");
boost::format fmt("%1$2d %2%%3% %4%:*** ");
fmt % params.Id
% (params.Flags & DEBUG_BREAKPOINT_ENABLED ? 'e' : 'd')
% 'u'
% params.CurrentPassCount;
return fmt.str();
}
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" );
}
return "";
}
///////////////////////////////////////////////////////////////////////////////
//#include <boost/format.hpp>
//
//#include "dbgbreak.h"
//#include "dbgexcept.h"
//#include "pyaux.h"
//
/////////////////////////////////////////////////////////////////////////////////
//
//dbgBreakpointClass::breakpointMap dbgBreakpointClass::m_breakMap;
//
/////////////////////////////////////////////////////////////////////////////////
//
//HRESULT dbgBreakpointClass::onBreakpointEvnet( IDebugBreakpoint* bp )
//{
// PyThread_StateSave pyThreadSave;
//
// try {
//
// breakpointMap::iterator it = m_breakMap.find( bp );
// if ( it != m_breakMap.end() )
// {
// boost::python::object &callback = it->second->m_callback;
// if (!callback.is_none())
// return boost::python::extract<HRESULT>( callback() );
//
// return DEBUG_STATUS_BREAK;
// }
//
// }
// catch(...)
// {
// }
//
// return DEBUG_STATUS_NO_CHANGE;
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset, boost::python::object &callback )
// : m_offset(offset)
// , m_callback(callback)
// , m_breakpoint(NULL)
//{
// set();
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset)
// : m_offset(offset)
// , m_breakpoint(NULL)
//{
// // m_callback is None, see dbgBreakpointClass::onBreakpointEvnet
// set();
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//dbgBreakpointClass::~dbgBreakpointClass()
//{
// remove();
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//bool
//dbgBreakpointClass::set()
//{
// HRESULT hres;
//
// try {
//
// if ( m_breakpoint )
// return true;
//
// hres = dbgExt->control->AddBreakpoint( DEBUG_BREAKPOINT_CODE, DEBUG_ANY_ID, &m_breakpoint );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::AddBreakpoint failed" );
//
// hres = m_breakpoint->SetOffset( m_offset );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugBreakpoint::SetOffset failed" );
//
// hres = m_breakpoint->SetFlags( DEBUG_BREAKPOINT_ENABLED );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugBreakpoint::SetFlags failed" );
//
// m_breakMap.insert( std::make_pair( m_breakpoint, this ) );
//
// return true;
// }
// 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" );
// }
//
// remove();
//
// return false;
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//void
//dbgBreakpointClass::remove()
//{
// if ( m_breakpoint )
// {
// dbgExt->control->RemoveBreakpoint( m_breakpoint );
//
// breakpointMap::iterator bp = m_breakMap.find( m_breakpoint );
// if ( bp != m_breakMap.end() )
// m_breakMap.erase( bp );
//
// m_breakpoint = NULL;
// }
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgBreakpointClass::print() const
//{
// HRESULT status = S_OK;
//
// try
// {
// if (!m_breakpoint)
// return "not set";
//
// DEBUG_BREAKPOINT_PARAMETERS params;
// status = m_breakpoint->GetParameters(&params);
// if (FAILED(status))
// throw DbgException("IDebugBreakpoint::GetParameters failed");
//
// boost::format fmt("%1$2d %2%%3% %4%:*** ");
// fmt % params.Id
// % (params.Flags & DEBUG_BREAKPOINT_ENABLED ? 'e' : 'd')
// % 'u'
// % params.CurrentPassCount;
//
// return fmt.str();
// }
// 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" );
// }
//
// return "";
//}
//
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,46 +1,46 @@
#pragma once
#include <map>
#include "dbgext.h"
/////////////////////////////////////////////////////////////////////////////////
class dbgBreakpointClass {
public:
dbgBreakpointClass( ULONG64 offset, boost::python::object &callback );
dbgBreakpointClass( ULONG64 offset );
~dbgBreakpointClass();
bool
set();
void
remove();
std::string
print() const;
private:
ULONG64 m_offset;
IDebugBreakpoint *m_breakpoint;
boost::python::object m_callback;
private:
typedef std::map<IDebugBreakpoint*, dbgBreakpointClass*> breakpointMap;
static breakpointMap m_breakMap;
public:
static HRESULT onBreakpointEvnet( IDebugBreakpoint* bp );
};
/////////////////////////////////////////////////////////////////////////////////
//#include <map>
//#include "dbgext.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//class dbgBreakpointClass {
//
//public:
//
// dbgBreakpointClass( ULONG64 offset, boost::python::object &callback );
// dbgBreakpointClass( ULONG64 offset );
//
// ~dbgBreakpointClass();
//
// bool
// set();
//
// void
// remove();
//
// std::string
// print() const;
//
//private:
//
// ULONG64 m_offset;
//
// IDebugBreakpoint *m_breakpoint;
//
// boost::python::object m_callback;
//
//private:
//
// typedef std::map<IDebugBreakpoint*, dbgBreakpointClass*> breakpointMap;
// static breakpointMap m_breakMap;
//
//public:
//
// static HRESULT onBreakpointEvnet( IDebugBreakpoint* bp );
//
//};
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,53 +1,53 @@
#pragma once
#include "dbgext.h"
#include "dbgeventcb.h"
///////////////////////////////////////////////////////////////////////////////
class dbgClient {
public:
dbgClient()
{
m_callbacks = NULL;
IDebugClient4 *client = NULL;
DebugCreate( __uuidof(IDebugClient4), (void **)&client );
m_ext = new DbgExt( client );
client->Release();
}
~dbgClient()
{
removeEventsMgr();
delete m_ext;
}
void startEventsMgr() {
m_callbacks = new DbgEventCallbacksManager( m_ext->client );
}
void removeEventsMgr() {
if ( m_callbacks )
{
delete m_callbacks;
m_callbacks = NULL;
}
}
private:
DbgExt *m_ext;
DbgEventCallbacksManager *m_callbacks;
};
extern dbgClient g_dbgClient;
///////////////////////////////////////////////////////////////////////////////
//#include "dbgext.h"
//#include "dbgeventcb.h"
//
/////////////////////////////////////////////////////////////////////////////////
//
//class dbgClient {
//
//public:
//
// dbgClient()
// {
// m_callbacks = NULL;
//
// IDebugClient4 *client = NULL;
// DebugCreate( __uuidof(IDebugClient4), (void **)&client );
//
// m_ext = new DbgExt( client );
//
// client->Release();
// }
//
// ~dbgClient()
// {
// removeEventsMgr();
//
// delete m_ext;
// }
//
// void startEventsMgr() {
//
// m_callbacks = new DbgEventCallbacksManager( m_ext->client );
// }
//
// void removeEventsMgr() {
//
// if ( m_callbacks )
// {
// delete m_callbacks;
// m_callbacks = NULL;
// }
// }
//
//private:
//
// DbgExt *m_ext;
// DbgEventCallbacksManager *m_callbacks;
//};
//
//extern dbgClient g_dbgClient;
//
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,132 +1,132 @@
#include "stdafx.h"
#include <boost/format.hpp>
#include "dbgext.h"
#include "dbgcmd.h"
#include "dbgexcept.h"
#include "dbgio.h"
#include "dbgsystem.h"
///////////////////////////////////////////////////////////////////////////////
std::string
dbgCommand( const std::string &command )
{
HRESULT hres;
OutputReader outReader( dbgExt->client );
{
PyThread_StateRestore pyThreadRestore;
hres = dbgExt->control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
}
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::Execute failed" );
return std::string( outReader.Line() );
}
///////////////////////////////////////////////////////////////////////////////
dbgExtensionClass::dbgExtensionClass( const char* path ) : m_path(path)
{
HRESULT hres;
hres = dbgExt->control->AddExtension( path, 0, &m_handle );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::AddExtension failed" );
}
///////////////////////////////////////////////////////////////////////////////
dbgExtensionClass::~dbgExtensionClass()
{
if ( m_handle )
dbgExt->control->RemoveExtension( m_handle );
}
///////////////////////////////////////////////////////////////////////////////
std::string
dbgExtensionClass::call( const std::string &command, const std::string params )
{
HRESULT hres;
OutputReader outReader( dbgExt->client );
hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::CallExtension failed" );
return std::string( outReader.Line() );
}
///////////////////////////////////////////////////////////////////////////////
std::string
dbgExtensionClass::print() const
{
return m_handle ? m_path : "";
}
///////////////////////////////////////////////////////////////////////////////
ULONG64
evaluate( const std::string &expression )
{
HRESULT hres;
ULONG64 value = 0;
DEBUG_VALUE debugValue = {};
ULONG remainderIndex = 0;
if ( is64bitSystem() )
{
hres = dbgExt->control->Evaluate(
expression.c_str(),
DEBUG_VALUE_INT64,
&debugValue,
&remainderIndex );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::Evaluate failed" );
if ( remainderIndex == expression.length() )
value = debugValue.I64;
}
else
{
hres = dbgExt->control->Evaluate(
expression.c_str(),
DEBUG_VALUE_INT32,
&debugValue,
&remainderIndex );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::Evaluate failed" );
if ( remainderIndex == expression.length() )
value = debugValue.I32;
}
return value;
}
///////////////////////////////////////////////////////////////////////////////
void
breakin()
{
HRESULT hres;
{
PyThread_StateRestore pyThreadRestore;
hres = dbgExt->control->SetInterrupt( DEBUG_INTERRUPT_ACTIVE );
}
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetInterrupt" );
}
///////////////////////////////////////////////////////////////////////////////
//
//#include <boost/format.hpp>
//
//#include "dbgext.h"
//#include "dbgcmd.h"
//#include "dbgexcept.h"
//#include "dbgio.h"
//#include "dbgsystem.h"
//
/////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgCommand( const std::string &command )
//{
// HRESULT hres;
//
// OutputReader outReader( dbgExt->client );
// {
// PyThread_StateRestore pyThreadRestore;
//
// hres = dbgExt->control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
// }
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::Execute failed" );
//
// return std::string( outReader.Line() );
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//dbgExtensionClass::dbgExtensionClass( const char* path ) : m_path(path)
//{
// HRESULT hres;
//
// hres = dbgExt->control->AddExtension( path, 0, &m_handle );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::AddExtension failed" );
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//dbgExtensionClass::~dbgExtensionClass()
//{
// if ( m_handle )
// dbgExt->control->RemoveExtension( m_handle );
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgExtensionClass::call( const std::string &command, const std::string params )
//{
// HRESULT hres;
//
// OutputReader outReader( dbgExt->client );
//
// hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::CallExtension failed" );
//
// return std::string( outReader.Line() );
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgExtensionClass::print() const
//{
// return m_handle ? m_path : "";
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//evaluate( const std::string &expression )
//{
// HRESULT hres;
// ULONG64 value = 0;
//
// DEBUG_VALUE debugValue = {};
// ULONG remainderIndex = 0;
//
// if ( is64bitSystem() )
// {
// hres = dbgExt->control->Evaluate(
// expression.c_str(),
// DEBUG_VALUE_INT64,
// &debugValue,
// &remainderIndex );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::Evaluate failed" );
//
// if ( remainderIndex == expression.length() )
// value = debugValue.I64;
// }
// else
// {
// hres = dbgExt->control->Evaluate(
// expression.c_str(),
// DEBUG_VALUE_INT32,
// &debugValue,
// &remainderIndex );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::Evaluate failed" );
//
// if ( remainderIndex == expression.length() )
// value = debugValue.I32;
// }
//
// return value;
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//void
//breakin()
//{
// HRESULT hres;
//
// {
// PyThread_StateRestore pyThreadRestore;
// hres = dbgExt->control->SetInterrupt( DEBUG_INTERRUPT_ACTIVE );
// }
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::SetInterrupt" );
//}
//
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,86 +1,86 @@
#pragma once
#include <string>
#include <map>
#include "pyaux.h"
/////////////////////////////////////////////////////////////////////////////////
std::string
dbgCommand( const std::string &command );
template <ULONG status>
void
setExecutionStatus()
{
HRESULT hres;
hres = dbgExt->control->SetExecutionStatus( status );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
ULONG currentStatus;
do {
{
PyThread_StateRestore pyThreadRestore;
hres = dbgExt->control->WaitForEvent( 0, INFINITE );
}
if ( FAILED( hres ) )
{
if (E_UNEXPECTED == hres)
throw WaitEventException();
throw DbgException( "IDebugControl::WaitForEvent failed" );
}
hres = dbgExt->control->GetExecutionStatus( &currentStatus );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetExecutionStatus failed" );
} while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
}
/////////////////////////////////////////////////////////////////////////////////
class dbgExtensionClass {
public:
dbgExtensionClass() :
m_handle( NULL )
{}
dbgExtensionClass( const char* path );
~dbgExtensionClass();
std::string
call( const std::string &command, const std::string param );
std::string
print() const;
private:
ULONG64 m_handle;
std::string m_path;
};
/////////////////////////////////////////////////////////////////////////////////
ULONG64
evaluate( const std::string &expression );
/////////////////////////////////////////////////////////////////////////////////
void
breakin();
/////////////////////////////////////////////////////////////////////////////////
//#include <string>
//#include <map>
//#include "pyaux.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgCommand( const std::string &command );
//
//template <ULONG status>
//void
//setExecutionStatus()
//{
// HRESULT hres;
//
// hres = dbgExt->control->SetExecutionStatus( status );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::SetExecutionStatus failed" );
//
// ULONG currentStatus;
//
// do {
//
// {
// PyThread_StateRestore pyThreadRestore;
// hres = dbgExt->control->WaitForEvent( 0, INFINITE );
// }
//
// if ( FAILED( hres ) )
// {
// if (E_UNEXPECTED == hres)
// throw WaitEventException();
//
// throw DbgException( "IDebugControl::WaitForEvent failed" );
// }
//
// hres = dbgExt->control->GetExecutionStatus( &currentStatus );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::GetExecutionStatus failed" );
//
// } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
//
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//class dbgExtensionClass {
//
//public:
//
// dbgExtensionClass() :
// m_handle( NULL )
// {}
//
// dbgExtensionClass( const char* path );
//
// ~dbgExtensionClass();
//
// std::string
// call( const std::string &command, const std::string param );
//
// std::string
// print() const;
//
//private:
//
// ULONG64 m_handle;
// std::string m_path;
//};
//
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//evaluate( const std::string &expression );
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//breakin();
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,101 +1,101 @@
#include "stdafx.h"
#include "dbgext.h"
#include "dbgdump.h"
#include "dbgexcept.h"
#include "dbgeventcb.h"
#include "dbgsystem.h"
#include "dbgcmd.h"
#include "dbgclient.h"
/////////////////////////////////////////////////////////////////////////////////
static
bool dbgStarted = false;
/////////////////////////////////////////////////////////////////////////////////
void
dbgLoadDump( const std::wstring &fileName )
{
HRESULT hres;
if ( dbgStarted || isWindbgExt() )
throw DbgException( "debugger is alread attached" );
g_dbgClient.startEventsMgr();
hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), 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" );
dbgStarted = true;
}
/////////////////////////////////////////////////////////////////////////////////
void
startProcess( const std::wstring &processName )
{
HRESULT hres;
if ( dbgStarted || isWindbgExt() )
throw DbgException( "debugger is alread attached" );
g_dbgClient.startEventsMgr();
ULONG opt;
hres = dbgExt->control->GetEngineOptions( &opt );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetEngineOptions failed" );
opt |= DEBUG_ENGOPT_INITIAL_BREAK;
hres = dbgExt->control->SetEngineOptions( opt );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetEngineOptions failed" );
std::vector< std::wstring::value_type> cmdLine( processName.size() + 1 );
wcscpy_s( &cmdLine[0], cmdLine.size(), processName.c_str() );
hres = dbgExt->client4->CreateProcessWide( 0, &cmdLine[0], DEBUG_PROCESS | DETACHED_PROCESS );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient4::CreateProcessWide failed" );
hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::WaitForEvent failed" );
dbgStarted = true;
}
/////////////////////////////////////////////////////////////////////////////////
void
attachProcess( ULONG processId )
{
HRESULT hres;
hres = dbgExt->client->AttachProcess( 0, processId, 0 );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::AttachProcess failed" );
}
/////////////////////////////////////////////////////////////////////////////////
void
attachKernel( const std::wstring param )
{
HRESULT hres;
hres = dbgExt->client5->AttachKernelWide( DEBUG_ATTACH_KERNEL_CONNECTION, param.c_str() );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient5::AttachKernelWide failed" );
}
/////////////////////////////////////////////////////////////////////////////////
//#include "dbgext.h"
//#include "dbgdump.h"
//#include "dbgexcept.h"
//#include "dbgeventcb.h"
//#include "dbgsystem.h"
//#include "dbgcmd.h"
//#include "dbgclient.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//static
//bool dbgStarted = false;
//
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//dbgLoadDump( const std::wstring &fileName )
//{
// HRESULT hres;
//
// if ( dbgStarted || isWindbgExt() )
// throw DbgException( "debugger is alread attached" );
//
// g_dbgClient.startEventsMgr();
//
// hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), 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" );
//
// dbgStarted = true;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//startProcess( const std::wstring &processName )
//{
// HRESULT hres;
//
// if ( dbgStarted || isWindbgExt() )
// throw DbgException( "debugger is alread attached" );
//
// g_dbgClient.startEventsMgr();
//
// ULONG opt;
// hres = dbgExt->control->GetEngineOptions( &opt );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::GetEngineOptions failed" );
//
// opt |= DEBUG_ENGOPT_INITIAL_BREAK;
// hres = dbgExt->control->SetEngineOptions( opt );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::SetEngineOptions failed" );
//
// std::vector< std::wstring::value_type> cmdLine( processName.size() + 1 );
// wcscpy_s( &cmdLine[0], cmdLine.size(), processName.c_str() );
//
// hres = dbgExt->client4->CreateProcessWide( 0, &cmdLine[0], DEBUG_PROCESS | DETACHED_PROCESS );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugClient4::CreateProcessWide failed" );
//
// hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::WaitForEvent failed" );
//
// dbgStarted = true;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//attachProcess( ULONG processId )
//{
// HRESULT hres;
//
// hres = dbgExt->client->AttachProcess( 0, processId, 0 );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugClient::AttachProcess failed" );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//attachKernel( const std::wstring param )
//{
// HRESULT hres;
//
// hres = dbgExt->client5->AttachKernelWide( DEBUG_ATTACH_KERNEL_CONNECTION, param.c_str() );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugClient5::AttachKernelWide failed" );
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,19 +1,19 @@
#pragma once
#include <string>
/////////////////////////////////////////////////////////////////////////////////
void
dbgLoadDump( const std::wstring &dumpName );
void
startProcess( const std::wstring &processName );
void
attachProcess( ULONG processId );
void
attachKernel( const std::wstring param );
/////////////////////////////////////////////////////////////////////////////////
//#include <string>
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//dbgLoadDump( const std::wstring &dumpName );
//
//void
//startProcess( const std::wstring &processName );
//
//void
//attachProcess( ULONG processId );
//
//void
//attachKernel( const std::wstring param );
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -3,215 +3,215 @@
///////////////////////////////////////////////////////////////////////////////////
//
#include "stdafx.h"
#include "dbgevent.h"
#include "dbgio.h"
#include "dbgexcept.h"
#include "pyaux.h"
///////////////////////////////////////////////////////////////////////////////////
debugEvent::debugEvent()
{
HRESULT hres;
hres = dbgExt->client->CreateClient( &m_debugClient );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::CreateClient" );
hres = m_debugClient->SetEventCallbacks(this);
if (FAILED(hres))
throw DbgException( "IDebugClient::SetEventCallbacks" );
}
///////////////////////////////////////////////////////////////////////////////////
debugEvent::~debugEvent()
{
m_debugClient->SetEventCallbacks( NULL );
m_debugClient->Release();
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::GetInterestMask(
__out PULONG Mask
)
{
*Mask = 0;
*Mask |= DEBUG_EVENT_LOAD_MODULE;
*Mask |= DEBUG_EVENT_UNLOAD_MODULE;
*Mask |= DEBUG_EVENT_SESSION_STATUS;
*Mask |= DEBUG_EVENT_EXCEPTION;
*Mask |= DEBUG_EVENT_BREAKPOINT;
return S_OK;
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::Breakpoint(
__in PDEBUG_BREAKPOINT Bp
)
{
boost::python::dict bpParameters;
HRESULT hres;
ULONG Value = 0;
ULONG Value2 = 0;
ULONG64 Value64 = 0;
std::string str;
#define _ADD_BP_ULONG(x) \
hres = Bp->Get##x(&Value); \
BOOST_ASSERT( SUCCEEDED( hres ) || hres == E_NOINTERFACE ); \
if (SUCCEEDED( hres )) \
bpParameters[#x] = Value;
#define _ADD_BP_ULONG2(x, n1, n2) \
hres = Bp->Get##x(&Value, &Value2); \
BOOST_ASSERT( SUCCEEDED( hres ) || hres == E_NOINTERFACE ); \
if (SUCCEEDED( hres )) \
{ \
bpParameters[n1] = Value; bpParameters[n2] = Value2; \
}
#define _ADD_BP_ULONG64(x) \
hres = Bp->Get##x(&Value64); \
BOOST_ASSERT( SUCCEEDED( hres ) || hres == E_NOINTERFACE ); \
if (SUCCEEDED( hres )) \
bpParameters[#x] = Value64;
#define _ADD_BP_STR(x) \
Value = 0; \
Bp->Get##x(NULL, 0, &Value); \
if (Value) \
{ \
str.resize(Value + 1); \
BOOST_VERIFY( SUCCEEDED( \
Bp->Get##x(&str[0], (ULONG)str.size(), NULL) \
) ); \
if (!str.empty()) bpParameters[#x] = str.c_str(); \
}
_ADD_BP_ULONG(Id);
_ADD_BP_ULONG2(Type, "BreakType", "ProcType");
_ADD_BP_ULONG(Flags);
_ADD_BP_ULONG64(Offset);
_ADD_BP_ULONG2(DataParameters, "Size", "AccessType");
_ADD_BP_ULONG(PassCount);
_ADD_BP_ULONG(CurrentPassCount);
_ADD_BP_ULONG(MatchThreadId);
_ADD_BP_STR(Command);
_ADD_BP_STR(OffsetExpression);
#undef _ADD_BP_ULONG
#undef _ADD_BP_ULONG2
#undef _ADD_BP_ULONG64
#undef _ADD_BP_STR
PyThread_StateSave pyThreadSave;
return onException(bpParameters);
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::Exception(
__in PEXCEPTION_RECORD64 Exception,
__in ULONG FirstChance
)
{
boost::python::list exceptParams;
boost::python::dict exceptData;
// build list of parameters
for (ULONG i = 0; i < Exception->NumberParameters; ++i)
exceptParams.append(Exception->ExceptionInformation[i]);
// build dict of exception data
#define _ADD_EXCEPTION_ENTRY(x) exceptData[#x] = Exception->Exception##x
_ADD_EXCEPTION_ENTRY(Code);
_ADD_EXCEPTION_ENTRY(Flags);
_ADD_EXCEPTION_ENTRY(Record);
_ADD_EXCEPTION_ENTRY(Address);
#undef _ADD_EXCEPTION_ENTRY
exceptData["Parameters"] = exceptParams;
exceptData["FirstChance"] = (0 != FirstChance);
PyThread_StateSave pyThreadSave;
return onException(exceptData);
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::LoadModule(
__in ULONG64 ImageFileHandle,
__in ULONG64 BaseOffset,
__in ULONG ModuleSize,
__in PCSTR ModuleName,
__in PCSTR ImageName,
__in ULONG CheckSum,
__in ULONG TimeDateStamp
)
{
std::auto_ptr<OutputReader> silentMode( new OutputReader(dbgExt->client) );
ULONG64 moduleBase;
ULONG moduleSize;
std::string moduleName;
queryModuleParams(BaseOffset, moduleName, moduleBase, moduleSize);
dbgModuleClass module(moduleName, moduleBase, moduleSize);
silentMode.reset();
PyThread_StateSave pyThreadSave;
return onLoadModule( module );
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::UnloadModule(
__in PCSTR ImageBaseName,
__in ULONG64 BaseOffset
)
{
std::auto_ptr<OutputReader> silentMode( new OutputReader(dbgExt->client) );
ULONG64 moduleBase;
ULONG moduleSize;
std::string moduleName;
queryModuleParams(BaseOffset, moduleName, moduleBase, moduleSize);
dbgModuleClass module(moduleName, moduleBase, moduleSize);
silentMode.reset();
PyThread_StateSave pyThreadSave;
return onUnloadModule( module );
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::SessionStatus(
__in ULONG Status
)
{
PyThread_StateSave pyThreadSave;
return onChangeSessionStatus( Status );
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT debugEvent::ChangeDebuggeeState(
__in ULONG Flags,
__in ULONG64 Argument
)
{
PyThread_StateSave pyThreadSave;
return onChangeDebugeeState();
}
///////////////////////////////////////////////////////////////////////////////////
//#include "dbgevent.h"
//#include "dbgio.h"
//#include "dbgexcept.h"
//#include "pyaux.h"
//
/////////////////////////////////////////////////////////////////////////////////////
//
//debugEvent::debugEvent()
//{
// HRESULT hres;
//
// hres = dbgExt->client->CreateClient( &m_debugClient );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugClient::CreateClient" );
//
// hres = m_debugClient->SetEventCallbacks(this);
// if (FAILED(hres))
// throw DbgException( "IDebugClient::SetEventCallbacks" );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//debugEvent::~debugEvent()
//{
// m_debugClient->SetEventCallbacks( NULL );
//
// m_debugClient->Release();
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::GetInterestMask(
// __out PULONG Mask
//)
//{
// *Mask = 0;
//
// *Mask |= DEBUG_EVENT_LOAD_MODULE;
// *Mask |= DEBUG_EVENT_UNLOAD_MODULE;
// *Mask |= DEBUG_EVENT_SESSION_STATUS;
// *Mask |= DEBUG_EVENT_EXCEPTION;
// *Mask |= DEBUG_EVENT_BREAKPOINT;
//
// return S_OK;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::Breakpoint(
// __in PDEBUG_BREAKPOINT Bp
//)
//{
// boost::python::dict bpParameters;
//
// HRESULT hres;
// ULONG Value = 0;
// ULONG Value2 = 0;
// ULONG64 Value64 = 0;
// std::string str;
//
//#define _ADD_BP_ULONG(x) \
// hres = Bp->Get##x(&Value); \
// BOOST_ASSERT( SUCCEEDED( hres ) || hres == E_NOINTERFACE ); \
// if (SUCCEEDED( hres )) \
// bpParameters[#x] = Value;
//
//#define _ADD_BP_ULONG2(x, n1, n2) \
// hres = Bp->Get##x(&Value, &Value2); \
// BOOST_ASSERT( SUCCEEDED( hres ) || hres == E_NOINTERFACE ); \
// if (SUCCEEDED( hres )) \
// { \
// bpParameters[n1] = Value; bpParameters[n2] = Value2; \
// }
//
//#define _ADD_BP_ULONG64(x) \
// hres = Bp->Get##x(&Value64); \
// BOOST_ASSERT( SUCCEEDED( hres ) || hres == E_NOINTERFACE ); \
// if (SUCCEEDED( hres )) \
// bpParameters[#x] = Value64;
//
//#define _ADD_BP_STR(x) \
// Value = 0; \
// Bp->Get##x(NULL, 0, &Value); \
// if (Value) \
// { \
// str.resize(Value + 1); \
// BOOST_VERIFY( SUCCEEDED( \
// Bp->Get##x(&str[0], (ULONG)str.size(), NULL) \
// ) ); \
// if (!str.empty()) bpParameters[#x] = str.c_str(); \
// }
//
// _ADD_BP_ULONG(Id);
// _ADD_BP_ULONG2(Type, "BreakType", "ProcType");
// _ADD_BP_ULONG(Flags);
// _ADD_BP_ULONG64(Offset);
// _ADD_BP_ULONG2(DataParameters, "Size", "AccessType");
// _ADD_BP_ULONG(PassCount);
// _ADD_BP_ULONG(CurrentPassCount);
// _ADD_BP_ULONG(MatchThreadId);
// _ADD_BP_STR(Command);
// _ADD_BP_STR(OffsetExpression);
//
//#undef _ADD_BP_ULONG
//#undef _ADD_BP_ULONG2
//#undef _ADD_BP_ULONG64
//#undef _ADD_BP_STR
//
// PyThread_StateSave pyThreadSave;
// return onException(bpParameters);
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::Exception(
// __in PEXCEPTION_RECORD64 Exception,
// __in ULONG FirstChance
//)
//{
// boost::python::list exceptParams;
// boost::python::dict exceptData;
//
// // build list of parameters
// for (ULONG i = 0; i < Exception->NumberParameters; ++i)
// exceptParams.append(Exception->ExceptionInformation[i]);
//
// // build dict of exception data
//#define _ADD_EXCEPTION_ENTRY(x) exceptData[#x] = Exception->Exception##x
// _ADD_EXCEPTION_ENTRY(Code);
// _ADD_EXCEPTION_ENTRY(Flags);
// _ADD_EXCEPTION_ENTRY(Record);
// _ADD_EXCEPTION_ENTRY(Address);
//#undef _ADD_EXCEPTION_ENTRY
//
// exceptData["Parameters"] = exceptParams;
//
// exceptData["FirstChance"] = (0 != FirstChance);
//
// PyThread_StateSave pyThreadSave;
// return onException(exceptData);
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::LoadModule(
// __in ULONG64 ImageFileHandle,
// __in ULONG64 BaseOffset,
// __in ULONG ModuleSize,
// __in PCSTR ModuleName,
// __in PCSTR ImageName,
// __in ULONG CheckSum,
// __in ULONG TimeDateStamp
//)
//{
// std::auto_ptr<OutputReader> silentMode( new OutputReader(dbgExt->client) );
//
// ULONG64 moduleBase;
// ULONG moduleSize;
// std::string moduleName;
//
// queryModuleParams(BaseOffset, moduleName, moduleBase, moduleSize);
// dbgModuleClass module(moduleName, moduleBase, moduleSize);
// silentMode.reset();
//
// PyThread_StateSave pyThreadSave;
// return onLoadModule( module );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::UnloadModule(
// __in PCSTR ImageBaseName,
// __in ULONG64 BaseOffset
//)
//{
// std::auto_ptr<OutputReader> silentMode( new OutputReader(dbgExt->client) );
//
// ULONG64 moduleBase;
// ULONG moduleSize;
// std::string moduleName;
//
// queryModuleParams(BaseOffset, moduleName, moduleBase, moduleSize);
// dbgModuleClass module(moduleName, moduleBase, moduleSize);
// silentMode.reset();
//
// PyThread_StateSave pyThreadSave;
// return onUnloadModule( module );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::SessionStatus(
// __in ULONG Status
//)
//{
// PyThread_StateSave pyThreadSave;
// return onChangeSessionStatus( Status );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT debugEvent::ChangeDebuggeeState(
// __in ULONG Flags,
// __in ULONG64 Argument
//)
//{
// PyThread_StateSave pyThreadSave;
// return onChangeDebugeeState();
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//

View File

@ -1,191 +1,132 @@
/////////////////////////////////////////////////////////////////////////////////
// user-customizing debug event handler
/////////////////////////////////////////////////////////////////////////////////
#include "dbgeventcb.h"
#include "dbgmodule.h"
#include "pyaux.h"
/////////////////////////////////////////////////////////////////////////////////
class debugEvent : public DebugBaseEventCallbacks
{
public:
debugEvent();
virtual ~debugEvent();
virtual ULONG onBreakpoint(boost::python::dict &/*bpParameters*/) = 0;
virtual ULONG onException(boost::python::dict &/*exceptData*/) = 0;
virtual ULONG onLoadModule(const dbgModuleClass &/* module */) = 0;
virtual ULONG onUnloadModule(const dbgModuleClass &/* module */) = 0;
virtual ULONG onChangeSessionStatus( ULONG status ) = 0;
virtual ULONG onChangeDebugeeState() = 0;
private:
STDMETHOD_(ULONG, AddRef)() { return 1; }
STDMETHOD_(ULONG, Release)() { return 1; }
STDMETHOD(GetInterestMask)(
__out PULONG Mask
);
STDMETHOD(Breakpoint)(
__in PDEBUG_BREAKPOINT Bp
);
STDMETHOD(Exception)(
__in PEXCEPTION_RECORD64 Exception,
__in ULONG FirstChance
);
STDMETHOD(LoadModule)(
__in ULONG64 ImageFileHandle,
__in ULONG64 BaseOffset,
__in ULONG ModuleSize,
__in PCSTR ModuleName,
__in PCSTR ImageName,
__in ULONG CheckSum,
__in ULONG TimeDateStamp
);
STDMETHOD(UnloadModule)(
__in PCSTR ImageBaseName,
__in ULONG64 BaseOffset
);
STDMETHOD(SessionStatus)(
__in ULONG Status
);
STDMETHOD(ChangeDebuggeeState)(
__in ULONG Flags,
__in ULONG64 Argument );
private:
IDebugClient *m_debugClient;
};
/////////////////////////////////////////////////////////////////////////////////
class debugEventWrap : public boost::python::wrapper<debugEvent>, public debugEvent
{
public:
ULONG onBreakpoint(boost::python::dict &bpParameters) {
return handler<boost::python::dict &>("onBreakpoint", bpParameters);
}
ULONG onException(boost::python::dict &exceptData) {
return handler<boost::python::dict &>("onException", exceptData);
}
ULONG onLoadModule(const dbgModuleClass &module) {
return handler<const dbgModuleClass &>("onLoadModule", module );
}
ULONG onUnloadModule(const dbgModuleClass &module) {
return handler<const dbgModuleClass &>("onUnloadModule", module );
}
ULONG onChangeSessionStatus( ULONG status ) {
return handler( "onChangeSessionStatus", status );
}
ULONG onChangeDebugeeState() {
return handler( "onChangeDebugeeState" );
}
private:
template<typename Arg1Type>
ULONG handler( const char* handlerName, Arg1Type arg1 )
{
if (boost::python::override pythonHandler = get_override( handlerName ))
return pythonHandler(arg1);
return DEBUG_STATUS_NO_CHANGE;
}
ULONG handler( const char* handlerName )
{
if (boost::python::override pythonHandler = get_override( handlerName ))
return pythonHandler();
return DEBUG_STATUS_NO_CHANGE;
}
};
/////////////////////////////////////////////////////////////////////////////////
#pragma once
///////////////////////////////////////////////////////////////////////////////////
//// user-customizing debug event handler
///////////////////////////////////////////////////////////////////////////////////
//
//#include <set>
//#include "dbgeventcb.h"
//#include "dbgmodule.h"
//#include "pyaux.h"
//
//#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
//#include <boost/interprocess/sync/scoped_lock.hpp>
///////////////////////////////////////////////////////////////////////////////////
//
//class debugEvent
//class debugEvent : public DebugBaseEventCallbacks
//{
//public:
//
// debugEvent();
//
// virtual ~debugEvent();
//
// virtual ULONG onLoadModule(const dbgModuleClass &/* module */)
// {
// return DEBUG_STATUS_NO_CHANGE;
// }
// virtual ULONG onBreakpoint(boost::python::dict &/*bpParameters*/) = 0;
//
// virtual ULONG onUnloadModule(const dbgModuleClass &/* module */)
// {
// return DEBUG_STATUS_NO_CHANGE;
// }
// virtual ULONG onException(boost::python::dict &/*exceptData*/) = 0;
//
// virtual ULONG onChangeSessionState( ULONG state )
// {
// return DEBUG_STATUS_NO_CHANGE;
// }
// virtual ULONG onLoadModule(const dbgModuleClass &/* module */) = 0;
//
// virtual ULONG onUnloadModule(const dbgModuleClass &/* module */) = 0;
//
// // call from debug engine
// static ULONG moduleLoaded(__in ULONG64 addr);
// static ULONG moduleUnloaded(__in ULONG64 addr);
// static ULONG sessionStatus(__in ULONG status );
// virtual ULONG onChangeSessionStatus( ULONG status ) = 0;
//
// virtual ULONG onChangeDebugeeState() = 0;
//
//private:
//
// typedef std::set<debugEvent *> modCallbacksColl;
// static modCallbacksColl modCallbacks;
// STDMETHOD_(ULONG, AddRef)() { return 1; }
// STDMETHOD_(ULONG, Release)() { return 1; }
//
// STDMETHOD(GetInterestMask)(
// __out PULONG Mask
// );
//
// STDMETHOD(Breakpoint)(
// __in PDEBUG_BREAKPOINT Bp
// );
//
//
// //typedef boost::interprocess::interprocess_recursive_mutex modCallbacksLock;
// //static modCallbacksLock modCallbacksMtx;
// //typedef boost::interprocess::scoped_lock<modCallbacksLock> modCallbacksScopedLock;
// STDMETHOD(Exception)(
// __in PEXCEPTION_RECORD64 Exception,
// __in ULONG FirstChance
// );
//
// STDMETHOD(LoadModule)(
// __in ULONG64 ImageFileHandle,
// __in ULONG64 BaseOffset,
// __in ULONG ModuleSize,
// __in PCSTR ModuleName,
// __in PCSTR ImageName,
// __in ULONG CheckSum,
// __in ULONG TimeDateStamp
// );
//
// STDMETHOD(UnloadModule)(
// __in PCSTR ImageBaseName,
// __in ULONG64 BaseOffset
// );
//
// STDMETHOD(SessionStatus)(
// __in ULONG Status
// );
//
// STDMETHOD(ChangeDebuggeeState)(
// __in ULONG Flags,
// __in ULONG64 Argument );
//
//private:
//
// IDebugClient *m_debugClient;
//};
//
//// python wrapper for debugEvent
//struct debugEventWrap : debugEvent, boost::python::wrapper<debugEvent>
///////////////////////////////////////////////////////////////////////////////////
//
//class debugEventWrap : public boost::python::wrapper<debugEvent>, public debugEvent
//{
// ULONG onLoadModule(const dbgModuleClass &module);
// ULONG onLoadModuleDef(const dbgModuleClass &module)
// {
// return debugEvent::onLoadModule(module);
//
//public:
//
// ULONG onBreakpoint(boost::python::dict &bpParameters) {
// return handler<boost::python::dict &>("onBreakpoint", bpParameters);
// }
//
// ULONG onUnloadModule(const dbgModuleClass &module);
// ULONG onUnloadModuleDef(const dbgModuleClass &module)
// ULONG onException(boost::python::dict &exceptData) {
// return handler<boost::python::dict &>("onException", exceptData);
// }
//
// ULONG onLoadModule(const dbgModuleClass &module) {
// return handler<const dbgModuleClass &>("onLoadModule", module );
// }
//
// ULONG onUnloadModule(const dbgModuleClass &module) {
// return handler<const dbgModuleClass &>("onUnloadModule", module );
// }
//
// ULONG onChangeSessionStatus( ULONG status ) {
// return handler( "onChangeSessionStatus", status );
// }
//
// ULONG onChangeDebugeeState() {
// return handler( "onChangeDebugeeState" );
// }
//
//private:
//
// template<typename Arg1Type>
// ULONG handler( const char* handlerName, Arg1Type arg1 )
// {
// return debugEvent::onUnloadModule(module);
// if (boost::python::override pythonHandler = get_override( handlerName ))
// return pythonHandler(arg1);
//
// return DEBUG_STATUS_NO_CHANGE;
// }
//
// ULONG handler( const char* handlerName )
// {
// if (boost::python::override pythonHandler = get_override( handlerName ))
// return pythonHandler();
//
// return DEBUG_STATUS_NO_CHANGE;
// }
//};
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,153 +1,153 @@
#include "stdafx.h"
#include "dbgeng.h"
#include "dbgext.h"
#include "dbgeventcb.h"
#include "dbgexcept.h"
#include "dbgmodule.h"
#include "dbgsynsym.h"
#include "dbgbreak.h"
#include "dbgevent.h"
///////////////////////////////////////////////////////////////////////////////////
DbgEventCallbacksManager::DbgEventCallbacksManager( IDebugClient *client )
{
m_debugClient = client;
m_debugClient->AddRef();
HRESULT hres;
hres = m_debugClient->SetEventCallbacks(this);
if (FAILED(hres))
throw DbgException( "IDebugClient::SetEventCallbacks" );
}
///////////////////////////////////////////////////////////////////////////////////
DbgEventCallbacksManager::~DbgEventCallbacksManager()
{
if ( m_debugClient )
{
m_debugClient->SetEventCallbacks( NULL );
m_debugClient->Release();
}
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacksManager::GetInterestMask(
__out PULONG Mask
)
{
*Mask =
DEBUG_EVENT_CHANGE_SYMBOL_STATE |
DEBUG_EVENT_BREAKPOINT;
// DEBUG_EVENT_LOAD_MODULE |
// DEBUG_EVENT_UNLOAD_MODULE
return S_OK;
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacksManager::ChangeSymbolState(
__in ULONG Flags,
__in ULONG64 Argument
)
{
if ((DEBUG_CSS_LOADS & Flags))
{
if (Argument)
{
DEBUG_MODULE_PARAMETERS dbgModuleParameters;
HRESULT hres = dbgExt->symbols3->GetModuleParameters(
1,
&Argument,
0,
&dbgModuleParameters);
if (SUCCEEDED(hres))
{
ModuleInfo moduleInfo(dbgModuleParameters);
restoreSyntheticSymbolForModule(moduleInfo);
}
return S_OK;
}
//// f.e. is case ".reload /f image.exe", if for image.exe no symbols
restoreSyntheticSymbolForAllModules();
return S_OK;
}
return DEBUG_STATUS_NO_CHANGE;
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacksManager::Breakpoint(
__in IDebugBreakpoint * bp
)
{
return dbgBreakpointClass::onBreakpointEvnet( bp );
}
///////////////////////////////////////////////////////////////////////////////////
//#include "dbgeng.h"
//#include "dbgext.h"
//#include "dbgeventcb.h"
//#include "dbgexcept.h"
//#include "dbgmodule.h"
//#include "dbgsynsym.h"
//#include "dbgbreak.h"
//#include "dbgevent.h"
//
//HRESULT DbgEventCallbacksManager::LoadModule(
// __in ULONG64 ImageFileHandle,
// __in ULONG64 BaseOffset,
// __in ULONG ModuleSize,
// __in PCSTR ModuleName,
// __in PCSTR ImageName,
// __in ULONG CheckSum,
// __in ULONG TimeDateStamp
//)
/////////////////////////////////////////////////////////////////////////////////////
//
//DbgEventCallbacksManager::DbgEventCallbacksManager( IDebugClient *client )
//{
// try
// {
// return debugEvent::moduleLoaded(BaseOffset);
// }
// catch (std::exception &)
// {
// }
// return DEBUG_STATUS_NO_CHANGE;
// m_debugClient = client;
// m_debugClient->AddRef();
//
// HRESULT hres;
//
// hres = m_debugClient->SetEventCallbacks(this);
// if (FAILED(hres))
// throw DbgException( "IDebugClient::SetEventCallbacks" );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT DbgEventCallbacksManager::UnloadModule(
// __in PCSTR ImageBaseName,
// __in ULONG64 BaseOffset
//DbgEventCallbacksManager::~DbgEventCallbacksManager()
//{
// if ( m_debugClient )
// {
// m_debugClient->SetEventCallbacks( NULL );
// m_debugClient->Release();
// }
//}
//
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT DbgEventCallbacksManager::GetInterestMask(
// __out PULONG Mask
//)
//{
// try
// {
// return debugEvent::moduleUnloaded(BaseOffset);
// }
// catch (std::exception &)
// {
// }
// return DEBUG_STATUS_NO_CHANGE;
// *Mask =
// DEBUG_EVENT_CHANGE_SYMBOL_STATE |
// DEBUG_EVENT_BREAKPOINT;
//// DEBUG_EVENT_LOAD_MODULE |
//// DEBUG_EVENT_UNLOAD_MODULE
// return S_OK;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT DbgEventCallbacksManager::SessionStatus(
// __in ULONG status
//HRESULT DbgEventCallbacksManager::ChangeSymbolState(
// __in ULONG Flags,
// __in ULONG64 Argument
//)
//{
// try
// {
// return debugEvent::sessionStatus( status );
// }
// catch( std::exception& )
// if ((DEBUG_CSS_LOADS & Flags))
// {
// if (Argument)
// {
// DEBUG_MODULE_PARAMETERS dbgModuleParameters;
// HRESULT hres = dbgExt->symbols3->GetModuleParameters(
// 1,
// &Argument,
// 0,
// &dbgModuleParameters);
//
// if (SUCCEEDED(hres))
// {
// ModuleInfo moduleInfo(dbgModuleParameters);
// restoreSyntheticSymbolForModule(moduleInfo);
// }
//
// return S_OK;
// }
//
// //// f.e. is case ".reload /f image.exe", if for image.exe no symbols
// restoreSyntheticSymbolForAllModules();
//
// return S_OK;
// }
//
// return DEBUG_STATUS_NO_CHANGE;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//HRESULT DbgEventCallbacksManager::Breakpoint(
// __in IDebugBreakpoint * bp
//)
//{
// return dbgBreakpointClass::onBreakpointEvnet( bp );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
////
////HRESULT DbgEventCallbacksManager::LoadModule(
//// __in ULONG64 ImageFileHandle,
//// __in ULONG64 BaseOffset,
//// __in ULONG ModuleSize,
//// __in PCSTR ModuleName,
//// __in PCSTR ImageName,
//// __in ULONG CheckSum,
//// __in ULONG TimeDateStamp
////)
////{
//// try
//// {
//// return debugEvent::moduleLoaded(BaseOffset);
//// }
//// catch (std::exception &)
//// {
//// }
//// return DEBUG_STATUS_NO_CHANGE;
////}
////
///////////////////////////////////////////////////////////////////////////////////////
////
////HRESULT DbgEventCallbacksManager::UnloadModule(
//// __in PCSTR ImageBaseName,
//// __in ULONG64 BaseOffset
////)
////{
//// try
//// {
//// return debugEvent::moduleUnloaded(BaseOffset);
//// }
//// catch (std::exception &)
//// {
//// }
//// return DEBUG_STATUS_NO_CHANGE;
////}
////
///////////////////////////////////////////////////////////////////////////////////////
////
////HRESULT DbgEventCallbacksManager::SessionStatus(
//// __in ULONG status
////)
////{
//// try
//// {
//// return debugEvent::sessionStatus( status );
//// }
//// catch( std::exception& )
//// {
//// }
////
//// return DEBUG_STATUS_NO_CHANGE;
////}
////
///////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,64 +1,64 @@
#pragma once
#include <dbgeng.h>
//////////////////////////////////////////////////////////////////////////////
// monitoring and processing debug events
class DbgEventCallbacksManager : public DebugBaseEventCallbacks
{
public:
DbgEventCallbacksManager( IDebugClient *client = NULL );
virtual ~DbgEventCallbacksManager();
private:
/////////////////////////////////////////////////////////////////////////////////
// IUnknown interface implementation
STDMETHOD_(ULONG, AddRef)() { return 1; }
STDMETHOD_(ULONG, Release)() { return 1; }
/////////////////////////////////////////////////////////////////////////////////
// IDebugEventCallbacks interface implementation
STDMETHOD(GetInterestMask)(
__out PULONG Mask
);
STDMETHOD(ChangeSymbolState)(
__in ULONG Flags,
__in ULONG64 Argument
);
STDMETHOD(Breakpoint)(
__in PDEBUG_BREAKPOINT Bp
);
/* STDMETHOD(LoadModule)(
__in ULONG64 ImageFileHandle,
__in ULONG64 BaseOffset,
__in ULONG ModuleSize,
__in PCSTR ModuleName,
__in PCSTR ImageName,
__in ULONG CheckSum,
__in ULONG TimeDateStamp
);
STDMETHOD(UnloadModule)(
__in PCSTR ImageBaseName,
__in ULONG64 BaseOffset
);
STDMETHOD(SessionStatus)(
__in ULONG status
); */
private:
IDebugClient *m_debugClient;
};
//////////////////////////////////////////////////////////////////////////////
//#include <dbgeng.h>
//
////////////////////////////////////////////////////////////////////////////////
//
//// monitoring and processing debug events
//class DbgEventCallbacksManager : public DebugBaseEventCallbacks
//{
//public:
//
// DbgEventCallbacksManager( IDebugClient *client = NULL );
//
// virtual ~DbgEventCallbacksManager();
//
//private:
//
// /////////////////////////////////////////////////////////////////////////////////
// // IUnknown interface implementation
//
// STDMETHOD_(ULONG, AddRef)() { return 1; }
// STDMETHOD_(ULONG, Release)() { return 1; }
//
// /////////////////////////////////////////////////////////////////////////////////
// // IDebugEventCallbacks interface implementation
//
// STDMETHOD(GetInterestMask)(
// __out PULONG Mask
// );
//
// STDMETHOD(ChangeSymbolState)(
// __in ULONG Flags,
// __in ULONG64 Argument
// );
//
// STDMETHOD(Breakpoint)(
// __in PDEBUG_BREAKPOINT Bp
// );
//
///* STDMETHOD(LoadModule)(
// __in ULONG64 ImageFileHandle,
// __in ULONG64 BaseOffset,
// __in ULONG ModuleSize,
// __in PCSTR ModuleName,
// __in PCSTR ImageName,
// __in ULONG CheckSum,
// __in ULONG TimeDateStamp
// );
//
// STDMETHOD(UnloadModule)(
// __in PCSTR ImageBaseName,
// __in ULONG64 BaseOffset
// );
//
// STDMETHOD(SessionStatus)(
// __in ULONG status
// ); */
//
//private:
// IDebugClient *m_debugClient;
//};
//
////////////////////////////////////////////////////////////////////////////////

View File

@ -1,51 +1,51 @@
#include "stdafx.h"
#include "dbgexcept.h"
/////////////////////////////////////////////////////////////////////////////////
// òèïû èñêëþ÷åíèé
PyObject *baseExceptionType = NULL;
PyObject *eventExceptionType = NULL;
PyObject *typeExceptionType = NULL;
PyObject *memoryExceptionType = NULL;
/////////////////////////////////////////////////////////////////////////////////
void DbgException::exceptionTranslate( const DbgException &e )
{
boost::python::object pyExcept(e);
PyErr_SetObject( baseExceptionType, pyExcept.ptr());
}
/////////////////////////////////////////////////////////////////////////////////
void WaitEventException::exceptionTranslate( const WaitEventException &e )
{
boost::python::object pyExcept(e);
PyErr_SetObject( eventExceptionType, pyExcept.ptr());
}
/////////////////////////////////////////////////////////////////////////////////
void TypeException::exceptionTranslate( const TypeException &e )
{
boost::python::object pyExcept(e);
PyErr_SetObject( typeExceptionType, pyExcept.ptr());
}
/////////////////////////////////////////////////////////////////////////////////
void MemoryException::translate( const MemoryException &e )
{
boost::python::object pyExcept(e);
PyErr_SetObject( memoryExceptionType, pyExcept.ptr());
}
/////////////////////////////////////////////////////////////////////////////////
//#include "dbgexcept.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//// òèïû èñêëþ÷åíèé
//
//PyObject *baseExceptionType = NULL;
//PyObject *eventExceptionType = NULL;
//PyObject *typeExceptionType = NULL;
//PyObject *memoryExceptionType = NULL;
//
//
//
///////////////////////////////////////////////////////////////////////////////////
//
//void DbgException::exceptionTranslate( const DbgException &e )
//{
// boost::python::object pyExcept(e);
//
// PyErr_SetObject( baseExceptionType, pyExcept.ptr());
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void WaitEventException::exceptionTranslate( const WaitEventException &e )
//{
// boost::python::object pyExcept(e);
//
// PyErr_SetObject( eventExceptionType, pyExcept.ptr());
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void TypeException::exceptionTranslate( const TypeException &e )
//{
// boost::python::object pyExcept(e);
//
// PyErr_SetObject( typeExceptionType, pyExcept.ptr());
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void MemoryException::translate( const MemoryException &e )
//{
// boost::python::object pyExcept(e);
//
// PyErr_SetObject( memoryExceptionType, pyExcept.ptr());
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,131 +1,131 @@
#pragma once
#include <exception>
#include <string>
/////////////////////////////////////////////////////////////////////////////////
class DbgException : public std::exception
{
public:
DbgException( const std::string &desc ) :
std::exception( desc.c_str() )
{}
const char* getDesc() const {
return what();
}
static
void
exceptionTranslate(const DbgException &e );
};
class WaitEventException : public DbgException
{
public:
WaitEventException()
: DbgException( "none of the targets could generate events" )
{
}
static void exceptionTranslate(const WaitEventException &e);
};
/////////////////////////////////////////////////////////////////////////////////
class TypeException : public DbgException
{
public:
TypeException() :
DbgException( "type operation invalid" )
{}
TypeException( const std::string &desc ) :
DbgException( desc )
{}
static
void
exceptionTranslate(const TypeException &e );
};
/////////////////////////////////////////////////////////////////////////////////
class IndexException : public DbgException
{
public:
IndexException() :
DbgException( "Index out of range" )
{}
static
void
translate(const IndexException &e ) {
PyErr_SetString(PyExc_IndexError, "Index out of range");
}
};
/////////////////////////////////////////////////////////////////////////////////
class MemoryException : public DbgException
{
public:
MemoryException( ULONG64 targetAddr ) :
m_targetAddress( targetAddr ),
DbgException( MemoryException::DescMaker( targetAddr, false ).desc() )
{}
MemoryException( ULONG64 targetAddr, bool phyAddr ) :
m_targetAddress( targetAddr ),
DbgException( MemoryException::DescMaker( targetAddr, phyAddr ).desc() )
{}
static
void
translate( const MemoryException &e );
ULONG64
getAddress() const {
return m_targetAddress;
}
private:
ULONG64 m_targetAddress;
class DescMaker {
public:
DescMaker( ULONG64 addr, bool phyAddr )
{
std::stringstream sstr;
if ( phyAddr )
sstr << "Memory exception at 0x" << std::hex << addr << " target physical address";
else
sstr << "Memory exception at 0x" << std::hex << addr << " target virtual address";
m_desc = sstr.str();
}
const std::string&
desc() const {
return m_desc;
}
private:
std::string m_desc;
};
};
/////////////////////////////////////////////////////////////////////////////////
extern PyObject *baseExceptionType;
extern PyObject *eventExceptionType;
extern PyObject *typeExceptionType;
extern PyObject *memoryExceptionType;
/////////////////////////////////////////////////////////////////////////////////
//#include <exception>
//#include <string>
//
///////////////////////////////////////////////////////////////////////////////////
//
//class DbgException : public std::exception
//{
//public:
//
// DbgException( const std::string &desc ) :
// std::exception( desc.c_str() )
// {}
//
// const char* getDesc() const {
// return what();
// }
//
// static
// void
// exceptionTranslate(const DbgException &e );
//};
//
//class WaitEventException : public DbgException
//{
//public:
// WaitEventException()
// : DbgException( "none of the targets could generate events" )
// {
// }
//
// static void exceptionTranslate(const WaitEventException &e);
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//class TypeException : public DbgException
//{
//public:
//
// TypeException() :
// DbgException( "type operation invalid" )
// {}
//
// TypeException( const std::string &desc ) :
// DbgException( desc )
// {}
//
// static
// void
// exceptionTranslate(const TypeException &e );
//
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//class IndexException : public DbgException
//{
//public:
//
// IndexException() :
// DbgException( "Index out of range" )
// {}
//
// static
// void
// translate(const IndexException &e ) {
// PyErr_SetString(PyExc_IndexError, "Index out of range");
// }
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//class MemoryException : public DbgException
//{
//public:
//
// MemoryException( ULONG64 targetAddr ) :
// m_targetAddress( targetAddr ),
// DbgException( MemoryException::DescMaker( targetAddr, false ).desc() )
// {}
//
// MemoryException( ULONG64 targetAddr, bool phyAddr ) :
// m_targetAddress( targetAddr ),
// DbgException( MemoryException::DescMaker( targetAddr, phyAddr ).desc() )
// {}
//
// static
// void
// translate( const MemoryException &e );
//
// ULONG64
// getAddress() const {
// return m_targetAddress;
// }
//
//private:
//
// ULONG64 m_targetAddress;
//
// class DescMaker {
// public:
// DescMaker( ULONG64 addr, bool phyAddr )
// {
// std::stringstream sstr;
// if ( phyAddr )
// sstr << "Memory exception at 0x" << std::hex << addr << " target physical address";
// else
// sstr << "Memory exception at 0x" << std::hex << addr << " target virtual address";
// m_desc = sstr.str();
// }
//
// const std::string&
// desc() const {
// return m_desc;
// }
//
// private:
// std::string m_desc;
// };
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//extern PyObject *baseExceptionType;
//extern PyObject *eventExceptionType;
//extern PyObject *typeExceptionType;
//extern PyObject *memoryExceptionType;
//
///////////////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +1,43 @@
#pragma once
#include <dbgeng.h>
#include <dbghelp.h>
class DbgExt {
public:
IDebugClient *client;
IDebugClient4 *client4;
IDebugClient5 *client5;
IDebugControl *control;
IDebugControl4 *control4;
IDebugRegisters *registers;
IDebugSymbols *symbols;
IDebugSymbols2 *symbols2;
IDebugSymbols3 *symbols3;
IDebugDataSpaces *dataSpaces;
IDebugDataSpaces4 *dataSpaces4;
IDebugAdvanced2 *advanced2;
IDebugSystemObjects *system;
IDebugSystemObjects2 *system2;
DbgExt( IDebugClient4 *client );
~DbgExt();
private:
DbgExt *m_previosExt;
};
extern DbgExt *dbgExt;
bool isWindbgExt();
//#include <dbgeng.h>
//#include <dbghelp.h>
//
//class DbgExt {
//
//public:
//
// IDebugClient *client;
// IDebugClient4 *client4;
// IDebugClient5 *client5;
//
// IDebugControl *control;
// IDebugControl4 *control4;
//
// IDebugRegisters *registers;
//
// IDebugSymbols *symbols;
// IDebugSymbols2 *symbols2;
// IDebugSymbols3 *symbols3;
//
// IDebugDataSpaces *dataSpaces;
// IDebugDataSpaces4 *dataSpaces4;
//
// IDebugAdvanced2 *advanced2;
//
// IDebugSystemObjects *system;
// IDebugSystemObjects2 *system2;
//
// DbgExt( IDebugClient4 *client );
//
// ~DbgExt();
//
//private:
//
// DbgExt *m_previosExt;
//};
//
//extern DbgExt *dbgExt;
//
//
//bool isWindbgExt();

View File

@ -1,34 +1,34 @@
#include "stdafx.h"
#include <iostream>
#include <Fcntl.h>
#include "dbgio.h"
#include "dbgext.h"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////
void dbgPrint::dprint( const boost::python::object& obj, bool dml )
{
std::wstring str = boost::python::extract<std::wstring>( obj );
HRESULT hres = dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() );
std::wcout << str;
}
/////////////////////////////////////////////////////////////////////////////////
void dbgPrint::dprintln( const boost::python::object& obj, bool dml )
{
std::wstring str = boost::python::extract<std::wstring>( obj );
str += L"\r\n";
dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() );
std::wcout << str;
}
/////////////////////////////////////////////////////////////////////////////////
//#include <iostream>
//#include <Fcntl.h>
//
//#include "dbgio.h"
//#include "dbgext.h"
//
//using namespace std;
//
///////////////////////////////////////////////////////////////////////////////////
//
//void dbgPrint::dprint( const boost::python::object& obj, bool dml )
//{
// std::wstring str = boost::python::extract<std::wstring>( obj );
//
// HRESULT hres = dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() );
//
// std::wcout << str;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void dbgPrint::dprintln( const boost::python::object& obj, bool dml )
//{
// std::wstring str = boost::python::extract<std::wstring>( obj );
// str += L"\r\n";
//
// dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() );
//
// std::wcout << str;
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,224 +1,224 @@
#pragma once
#include <string>
#include <dbgeng.h>
#include "dbgext.h"
//#include <string>
//#include <dbgeng.h>
//
//#include "dbgext.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//class dbgPrint {
//
//public:
//
// static void dprint( const boost::python::object& obj, bool dml = false );
//
// static void dprintln( const boost::python::object& obj, bool dml = false );
//
//};
//
/////////////////////////////////////////////////////////////////////////////////
class dbgPrint {
public:
static void dprint( const boost::python::object& obj, bool dml = false );
static void dprintln( const boost::python::object& obj, bool dml = false );
};
///////////////////////////////////////////////////////////////////////////////
// êëàññ äëÿ ïåðåõâàòà âûâîäà â îòëàä÷èê
class OutputReader : public IDebugOutputCallbacks {
public:
OutputReader( IDebugClient *debugClient )
{
HRESULT hres;
try {
m_debugClient = debugClient;
m_debugClient->AddRef();
hres = m_debugClient->GetOutputCallbacks( &m_previousCallback );
if ( FAILED( hres ) )
{
throw hres;
}
hres = m_debugClient->SetOutputCallbacks( this );
if ( FAILED( hres ) )
{
throw hres;
}
} catch( ... )
{
m_debugClient->Release();
m_debugClient = NULL;
}
}
~OutputReader()
{
if ( m_debugClient )
{
m_debugClient->SetOutputCallbacks( m_previousCallback );
m_debugClient->Release();
}
}
const std::string&
Line() const {
return m_readLine;
}
private:
// IUnknown.
STDMETHOD(QueryInterface)(
__in REFIID InterfaceId,
__out PVOID* Interface ) {
return E_NOINTERFACE;
}
STDMETHOD_(ULONG, AddRef)() {
return 1L;
}
STDMETHOD_(ULONG, Release)() {
return 0L;
}
STDMETHOD(Output)(
__in ULONG Mask,
__in PCSTR Text )
{
if ( Mask == DEBUG_OUTPUT_NORMAL )
{
m_readLine += std::string( Text );
}
return S_OK;
}
private:
std::string m_readLine;
IDebugClient *m_debugClient;
IDebugOutputCallbacks *m_previousCallback;
};
///////////////////////////////////////////////////////////////////////////////
class InputReader : public IDebugInputCallbacks {
public:
InputReader( IDebugClient *debugClient )
{
HRESULT hres;
try {
m_debugClient = debugClient;
m_debugClient->AddRef();
hres = m_debugClient->GetInputCallbacks( &m_previousCallback );
if ( FAILED( hres ) )
{
throw hres;
}
hres = m_debugClient->SetInputCallbacks( this );
if ( FAILED( hres ) )
{
throw hres;
}
} catch( ... )
{
m_debugClient->Release();
m_debugClient = NULL;
}
}
~InputReader()
{
if ( m_debugClient )
{
m_debugClient->SetInputCallbacks( m_previousCallback );
m_debugClient->Release();
}
}
private:
// IUnknown.
STDMETHOD(QueryInterface)(
__in REFIID InterfaceId,
__out PVOID* Interface ) {
return E_NOINTERFACE;
}
STDMETHOD_(ULONG, AddRef)() {
return 1L;
}
STDMETHOD_(ULONG, Release)() {
return 0L;
}
STDMETHOD( EndInput )() {
return S_OK;
}
STDMETHOD( StartInput )(
IN ULONG BufferSize ) {
return S_OK;
}
private:
IDebugClient *m_debugClient;
IDebugInputCallbacks *m_previousCallback;
};
//
//// êëàññ äëÿ ïåðåõâàòà âûâîäà â îòëàä÷èê
//
//class OutputReader : public IDebugOutputCallbacks {
//
//public:
//
// OutputReader( IDebugClient *debugClient )
// {
// HRESULT hres;
//
// try {
//
// m_debugClient = debugClient;
// m_debugClient->AddRef();
//
// hres = m_debugClient->GetOutputCallbacks( &m_previousCallback );
// if ( FAILED( hres ) )
// {
// throw hres;
// }
//
// hres = m_debugClient->SetOutputCallbacks( this );
// if ( FAILED( hres ) )
// {
// throw hres;
// }
//
// } catch( ... )
// {
// m_debugClient->Release();
// m_debugClient = NULL;
// }
// }
//
// ~OutputReader()
// {
// if ( m_debugClient )
// {
// m_debugClient->SetOutputCallbacks( m_previousCallback );
// m_debugClient->Release();
// }
// }
//
// const std::string&
// Line() const {
// return m_readLine;
// }
//
//private:
//
// // IUnknown.
// STDMETHOD(QueryInterface)(
// __in REFIID InterfaceId,
// __out PVOID* Interface ) {
// return E_NOINTERFACE;
// }
//
// STDMETHOD_(ULONG, AddRef)() {
// return 1L;
// }
//
//
// STDMETHOD_(ULONG, Release)() {
// return 0L;
// }
//
// STDMETHOD(Output)(
// __in ULONG Mask,
// __in PCSTR Text )
// {
// if ( Mask == DEBUG_OUTPUT_NORMAL )
// {
// m_readLine += std::string( Text );
// }
//
// return S_OK;
// }
//
//private:
//
// std::string m_readLine;
//
// IDebugClient *m_debugClient;
//
// IDebugOutputCallbacks *m_previousCallback;
//};
//
/////////////////////////////////////////////////////////////////////////////////
class dbgOut {
public:
void
write( const boost::python::object &str ) {
dbgPrint::dprint( str );
}
};
/////////////////////////////////////////////////////////////////////////////////
class dbgIn {
public:
std::string
readline() {
char str[100];
ULONG inputSize;
OutputReader outputReader( dbgExt->client );
dbgExt->control->Input( str, sizeof(str), &inputSize );
return std::string( str );
}
};
/////////////////////////////////////////////////////////////////////////////////
//
//class InputReader : public IDebugInputCallbacks {
//
//public:
//
// InputReader( IDebugClient *debugClient )
// {
// HRESULT hres;
//
// try {
//
// m_debugClient = debugClient;
// m_debugClient->AddRef();
//
// hres = m_debugClient->GetInputCallbacks( &m_previousCallback );
// if ( FAILED( hres ) )
// {
// throw hres;
// }
//
// hres = m_debugClient->SetInputCallbacks( this );
// if ( FAILED( hres ) )
// {
// throw hres;
// }
//
// } catch( ... )
// {
// m_debugClient->Release();
// m_debugClient = NULL;
// }
// }
//
// ~InputReader()
// {
// if ( m_debugClient )
// {
// m_debugClient->SetInputCallbacks( m_previousCallback );
// m_debugClient->Release();
// }
// }
//
//
//private:
//
// // IUnknown.
// STDMETHOD(QueryInterface)(
// __in REFIID InterfaceId,
// __out PVOID* Interface ) {
// return E_NOINTERFACE;
// }
//
// STDMETHOD_(ULONG, AddRef)() {
// return 1L;
// }
//
//
// STDMETHOD_(ULONG, Release)() {
// return 0L;
// }
//
// STDMETHOD( EndInput )() {
// return S_OK;
// }
//
// STDMETHOD( StartInput )(
// IN ULONG BufferSize ) {
// return S_OK;
// }
//
//private:
//
// IDebugClient *m_debugClient;
//
// IDebugInputCallbacks *m_previousCallback;
//
//};
//
//
///////////////////////////////////////////////////////////////////////////////////
//
//class dbgOut {
//
//public:
//
// void
// write( const boost::python::object &str ) {
// dbgPrint::dprint( str );
// }
//
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//class dbgIn {
//
//public:
//
// std::string
// readline() {
//
// char str[100];
// ULONG inputSize;
//
// OutputReader outputReader( dbgExt->client );
//
// dbgExt->control->Input( str, sizeof(str), &inputSize );
//
// return std::string( str );
// }
//
//};
//
///////////////////////////////////////////////////////////////////////////////////
//

File diff suppressed because it is too large Load Diff

View File

@ -1,90 +1,90 @@
#pragma once
#include <boost/scoped_array.hpp>
/////////////////////////////////////////////////////////////////////////////////
void
loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr = FALSE );
ULONG64
loadPtrByPtr( ULONG64 address );
ULONG64
loadMWord( ULONG64 address );
LONG64
loadSignMWord( ULONG64 address );
template<typename T>
boost::python::object
loadArray( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE )
{
boost::scoped_array<T> buffer(new T[number]);
loadMemory( address, buffer.get(), number*sizeof(T), phyAddr );
boost::python::list lst;
for ( ULONG i = 0; i < number; ++i )
lst.append( buffer[i] );
return lst;
}
boost::python::object
loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE );
boost::python::object
loadWChars( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE );
template<typename T>
boost::python::object
loadByPtr( ULONG64 address )
{
T value;
loadMemory( address, &value, sizeof(T) );
return boost::python::object( value );
}
template<>
boost::python::object
loadByPtr<char>( ULONG64 address );
boost::python::object
loadPtrArray( ULONG64 address, ULONG number );
boost::python::object
loadUnicodeStr( ULONG64 address );
boost::python::object
loadAnsiStr( ULONG64 address );
boost::python::object
loadCStr( ULONG64 address );
void
loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen );
boost::python::object
loadWStr( ULONG64 address );
void
loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen );
bool
compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE );
ULONG64
addr64( ULONG64 addr );
boost::python::object
loadLinkedList( ULONG64 address );
bool
isOffsetValid( ULONG64 addr );
/////////////////////////////////////////////////////////////////////////////////
//#include <boost/scoped_array.hpp>
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr = FALSE );
//
//ULONG64
//loadPtrByPtr( ULONG64 address );
//
//ULONG64
//loadMWord( ULONG64 address );
//
//LONG64
//loadSignMWord( ULONG64 address );
//
//
//template<typename T>
//boost::python::object
//loadArray( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE )
//{
// boost::scoped_array<T> buffer(new T[number]);
//
// loadMemory( address, buffer.get(), number*sizeof(T), phyAddr );
//
// boost::python::list lst;
//
// for ( ULONG i = 0; i < number; ++i )
// lst.append( buffer[i] );
//
// return lst;
//}
//
//boost::python::object
//loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE );
//
//boost::python::object
//loadWChars( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE );
//
//template<typename T>
//boost::python::object
//loadByPtr( ULONG64 address )
//{
// T value;
//
// loadMemory( address, &value, sizeof(T) );
//
// return boost::python::object( value );
//}
//
//template<>
//boost::python::object
//loadByPtr<char>( ULONG64 address );
//
//boost::python::object
//loadPtrArray( ULONG64 address, ULONG number );
//
//boost::python::object
//loadUnicodeStr( ULONG64 address );
//
//boost::python::object
//loadAnsiStr( ULONG64 address );
//
//boost::python::object
//loadCStr( ULONG64 address );
//
//void
//loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen );
//
//boost::python::object
//loadWStr( ULONG64 address );
//
//void
//loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen );
//
//bool
//compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE );
//
//ULONG64
//addr64( ULONG64 addr );
//
//boost::python::object
//loadLinkedList( ULONG64 address );
//
//bool
//isOffsetValid( ULONG64 addr );
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,345 +1,345 @@
#include "stdafx.h"
#include <boost/format.hpp>
#include "dbgext.h"
#include "dbgmem.h"
#include "dbgmodule.h"
#include "dbgexcept.h"
#include "dbgsym.h"
#include "dbgio.h"
#include "dbgsynsym.h"
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
loadModule( const std::string &moduleName )
{
HRESULT hres;
ULONG64 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 = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) );
}
/////////////////////////////////////////////////////////////////////////////////
void queryModuleParams(
__in ULONG64 addr,
__out std::string &name,
__out ULONG64 &base,
__out ULONG &size
)
{
addr = addr64( addr );
ULONG moduleIndex;
HRESULT hres =
dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &base);
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetModuleByOffset failed" );
DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
hres = dbgExt->symbols->GetModuleParameters( 1, &base, 0, &moduleParam );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
size = moduleParam.Size;
ULONG moduleNameChars = 0;
dbgExt->symbols->GetModuleNames(
moduleIndex,
0,
NULL,
0,
NULL,
NULL,
0,
&moduleNameChars,
NULL,
0,
NULL );
name.resize(moduleNameChars + 1);
hres = dbgExt->symbols->GetModuleNames(
moduleIndex,
0,
NULL,
0,
NULL,
&name[0],
(ULONG)name.size(),
NULL,
NULL,
0,
NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetModuleNames failed" );
}
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
findModule( ULONG64 addr )
{
ULONG64 moduleBase;
ULONG moduleSize;
std::string moduleName;
queryModuleParams(addr, moduleName, moduleBase, moduleSize);
return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleSize ) );
}
/////////////////////////////////////////////////////////////////////////////////
dbgModuleClass::dbgModuleClass( const std::string &name, ULONG64 base, ULONG size ) :
m_name( name ),
m_base( addr64(base) ),
m_end( addr64(base) + size )
{
reloadSymbols();
std::string pattern = name + "!*";
ULONG64 enumHandle = 0;
HRESULT hres = dbgExt->symbols->StartSymbolMatch( pattern.c_str(), &enumHandle );
while( SUCCEEDED( hres ) )
{
char nameBuf[0x100];
ULONG64 offset = 0;
hres =
dbgExt->symbols->GetNextSymbolMatch(
enumHandle,
nameBuf,
sizeof( nameBuf ),
NULL,
&offset );
if ( FAILED( hres ) )
break;
std::string symbolName( nameBuf );
symbolName.erase( 0, name.size() + 1 );
m_offsets.insert( std::make_pair( symbolName, offset ) );
}
if ( enumHandle )
dbgExt->symbols->EndSymbolMatch( enumHandle );
memset( &m_debugInfo, 0, sizeof( m_debugInfo ) );
hres = dbgExt->advanced2->GetSymbolInformation(
DEBUG_SYMINFO_IMAGEHLP_MODULEW64,
base,
0,
&m_debugInfo,
sizeof( m_debugInfo ),
NULL,
NULL,
0,
NULL );
if ( SUCCEEDED( hres ) )
getImagePath();
}
/////////////////////////////////////////////////////////////////////////////////
void
dbgModuleClass::reloadSymbols()
{
HRESULT hres;
static const char *szReloadParam = "/f "; //"/f /s ";
std::string reloadParam = szReloadParam;
reloadParam += m_name;
{
// try reload module by entered name, "silent mode"
OutputReader outputReader( dbgExt->client );
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
}
if ( FAILED( hres ) )
{
// failed => try reload symbols by image file name
char szImageName[MAX_PATH/2];
HRESULT hres2 = dbgExt->symbols2->GetModuleNameString(
DEBUG_MODNAME_IMAGE,
DEBUG_ANY_ID,
m_base,
szImageName,
_countof(szImageName),
NULL);
if (SUCCEEDED(hres2))
{
PCSTR szImageFileName = strrchr(szImageName, '\\');
if (!szImageFileName)
szImageFileName = szImageName;
else
++szImageFileName;
reloadParam = szReloadParam;
reloadParam += szImageFileName;
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
}
}
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::Reload failed" );
}
/////////////////////////////////////////////////////////////////////////////////
ULONG64
dbgModuleClass::getOffset( const std::string &symName )
{
OffsetMap::iterator offset = m_offsets.find( symName );
if ( offset != m_offsets.end() )
{
return offset->second;
}
ModuleInfo moduleInfo(m_debugInfo);
ULONG64 syntheticOffset = getSyntheticSymbol(moduleInfo, symName);
if ( syntheticOffset == 0 )
throw DbgException( "failed to find offset for symbol" );
return syntheticOffset;
}
/////////////////////////////////////////////////////////////////////////////////
bool dbgModuleClass::addSyntheticSymbol(
ULONG64 offset,
ULONG size,
const std::string &symName
)
{
ModuleInfo moduleInfo(m_debugInfo);
return ::addSyntheticSymbolForModule(offset, size, symName, moduleInfo);
}
/////////////////////////////////////////////////////////////////////////////////
void dbgModuleClass::delAllSyntheticSymbols()
{
ModuleInfo moduleInfo(m_debugInfo);
::delAllSyntheticSymbolsForModule(moduleInfo);
}
/////////////////////////////////////////////////////////////////////////////////
ULONG dbgModuleClass::delSyntheticSymbol(
ULONG64 offset
)
{
ModuleInfo moduleInfo(m_debugInfo);
return ::delSyntheticSymbolForModule(offset, moduleInfo);
}
/////////////////////////////////////////////////////////////////////////////////
ULONG dbgModuleClass::delSyntheticSymbolsMask( const std::string &symName )
{
return ::delSyntheticSymbolsMask(m_name, symName);
}
/////////////////////////////////////////////////////////////////////////////////
void
dbgModuleClass::getImagePath()
{
HRESULT hres;
ULONG pathSize = 0;
hres = dbgExt->symbols3->GetSymbolPathWide( NULL, 0, &pathSize );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
std::vector<WCHAR> pathBuffer(pathSize);
hres = dbgExt->symbols3->GetSymbolPathWide( &pathBuffer[0], pathSize, NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
std::wstring symPath( &pathBuffer[0], pathSize );
std::wstring altName = m_debugInfo.CVData;
altName = altName.substr( 0, altName.find_last_of(L".") );
std::wstring imageName = m_debugInfo.LoadedImageName;
altName += imageName.substr( imageName.find_last_of(L".") );
for ( size_t offset = 0; offset < symPath.length(); )
{
size_t newOffset = symPath.find( L";", offset );
std::wstring subPath = symPath.substr( offset, newOffset - offset );
std::wstringstream sstr;
sstr << subPath << L"\\" << m_debugInfo.LoadedImageName << L"\\" << std::hex <<
m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
m_debugInfo.LoadedImageName;
if( (_waccess( sstr.str().c_str(), 0 )) != -1 )
{
m_imageFullName = sstr.str();
break;
}
std::wstringstream altstr;
altstr << subPath << L"\\" << altName << L"\\" << std::hex <<
m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
altName;
if( (_waccess( altstr.str().c_str(), 0 )) != -1 )
{
m_imageFullName = altstr.str();
break;
}
if ( newOffset == std::wstring::npos )
break;
offset = newOffset + 1;
}
}
std::string
dbgModuleClass::print() const
{
const char * format_string(dbgExt->control->IsPointer64Bit() == S_OK ?
"%1$016x %2$016x %3$20s %4$20s" : "%1$08x %2$08x %3$20s %4$20s");
boost::format fmt(format_string);
std::vector<char> v(MAX_PATH);
::WideCharToMultiByte(
CP_ACP,
0,
m_imageFullName.c_str(),
-1,
&v[0],
(ULONG)v.size(),
0,
0);
std::string fullname(&v[0]);
fmt % m_base % (m_end - m_base) % m_name % fullname;
return fmt.str();
}
/////////////////////////////////////////////////////////////////////////////////
//#include <boost/format.hpp>
//
//#include "dbgext.h"
//#include "dbgmem.h"
//#include "dbgmodule.h"
//#include "dbgexcept.h"
//#include "dbgsym.h"
//#include "dbgio.h"
//#include "dbgsynsym.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//loadModule( const std::string &moduleName )
//{
// HRESULT hres;
//
// ULONG64 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 = dbgExt->symbols->GetModuleParameters( 1, &moduleBase, 0, &moduleParam );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
//
//
// return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleParam.Size ) );
//
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void queryModuleParams(
// __in ULONG64 addr,
// __out std::string &name,
// __out ULONG64 &base,
// __out ULONG &size
//)
//{
// addr = addr64( addr );
//
// ULONG moduleIndex;
// HRESULT hres =
// dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &base);
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::GetModuleByOffset failed" );
//
// DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
// hres = dbgExt->symbols->GetModuleParameters( 1, &base, 0, &moduleParam );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
// size = moduleParam.Size;
//
// ULONG moduleNameChars = 0;
// dbgExt->symbols->GetModuleNames(
// moduleIndex,
// 0,
// NULL,
// 0,
// NULL,
// NULL,
// 0,
// &moduleNameChars,
// NULL,
// 0,
// NULL );
// name.resize(moduleNameChars + 1);
// hres = dbgExt->symbols->GetModuleNames(
// moduleIndex,
// 0,
// NULL,
// 0,
// NULL,
// &name[0],
// (ULONG)name.size(),
// NULL,
// NULL,
// 0,
// NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::GetModuleNames failed" );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//findModule( ULONG64 addr )
//{
// ULONG64 moduleBase;
// ULONG moduleSize;
// std::string moduleName;
//
// queryModuleParams(addr, moduleName, moduleBase, moduleSize);
//
// return boost::python::object( dbgModuleClass( moduleName, moduleBase, moduleSize ) );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//dbgModuleClass::dbgModuleClass( const std::string &name, ULONG64 base, ULONG size ) :
// m_name( name ),
// m_base( addr64(base) ),
// m_end( addr64(base) + size )
//{
// reloadSymbols();
//
// std::string pattern = name + "!*";
// ULONG64 enumHandle = 0;
//
// HRESULT hres = dbgExt->symbols->StartSymbolMatch( pattern.c_str(), &enumHandle );
//
// while( SUCCEEDED( hres ) )
// {
// char nameBuf[0x100];
// ULONG64 offset = 0;
//
// hres =
// dbgExt->symbols->GetNextSymbolMatch(
// enumHandle,
// nameBuf,
// sizeof( nameBuf ),
// NULL,
// &offset );
//
// if ( FAILED( hres ) )
// break;
//
// std::string symbolName( nameBuf );
//
// symbolName.erase( 0, name.size() + 1 );
//
// m_offsets.insert( std::make_pair( symbolName, offset ) );
// }
//
// if ( enumHandle )
// dbgExt->symbols->EndSymbolMatch( enumHandle );
//
// memset( &m_debugInfo, 0, sizeof( m_debugInfo ) );
//
// hres = dbgExt->advanced2->GetSymbolInformation(
// DEBUG_SYMINFO_IMAGEHLP_MODULEW64,
// base,
// 0,
// &m_debugInfo,
// sizeof( m_debugInfo ),
// NULL,
// NULL,
// 0,
// NULL );
//
// if ( SUCCEEDED( hres ) )
// getImagePath();
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//dbgModuleClass::reloadSymbols()
//{
// HRESULT hres;
//
// static const char *szReloadParam = "/f "; //"/f /s ";
// std::string reloadParam = szReloadParam;
// reloadParam += m_name;
//
// {
// // try reload module by entered name, "silent mode"
// OutputReader outputReader( dbgExt->client );
// hres = dbgExt->symbols->Reload( reloadParam.c_str() );
// }
// if ( FAILED( hres ) )
// {
// // failed => try reload symbols by image file name
// char szImageName[MAX_PATH/2];
// HRESULT hres2 = dbgExt->symbols2->GetModuleNameString(
// DEBUG_MODNAME_IMAGE,
// DEBUG_ANY_ID,
// m_base,
// szImageName,
// _countof(szImageName),
// NULL);
// if (SUCCEEDED(hres2))
// {
// PCSTR szImageFileName = strrchr(szImageName, '\\');
// if (!szImageFileName)
// szImageFileName = szImageName;
// else
// ++szImageFileName;
//
// reloadParam = szReloadParam;
// reloadParam += szImageFileName;
// hres = dbgExt->symbols->Reload( reloadParam.c_str() );
// }
// }
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::Reload failed" );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//dbgModuleClass::getOffset( const std::string &symName )
//{
// OffsetMap::iterator offset = m_offsets.find( symName );
// if ( offset != m_offsets.end() )
// {
// return offset->second;
// }
//
// ModuleInfo moduleInfo(m_debugInfo);
// ULONG64 syntheticOffset = getSyntheticSymbol(moduleInfo, symName);
//
// if ( syntheticOffset == 0 )
// throw DbgException( "failed to find offset for symbol" );
//
// return syntheticOffset;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//bool dbgModuleClass::addSyntheticSymbol(
// ULONG64 offset,
// ULONG size,
// const std::string &symName
//)
//{
// ModuleInfo moduleInfo(m_debugInfo);
// return ::addSyntheticSymbolForModule(offset, size, symName, moduleInfo);
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void dbgModuleClass::delAllSyntheticSymbols()
//{
// ModuleInfo moduleInfo(m_debugInfo);
// ::delAllSyntheticSymbolsForModule(moduleInfo);
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG dbgModuleClass::delSyntheticSymbol(
// ULONG64 offset
//)
//{
// ModuleInfo moduleInfo(m_debugInfo);
// return ::delSyntheticSymbolForModule(offset, moduleInfo);
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG dbgModuleClass::delSyntheticSymbolsMask( const std::string &symName )
//{
// return ::delSyntheticSymbolsMask(m_name, symName);
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//dbgModuleClass::getImagePath()
//{
// HRESULT hres;
//
// ULONG pathSize = 0;
// hres = dbgExt->symbols3->GetSymbolPathWide( NULL, 0, &pathSize );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
//
// std::vector<WCHAR> pathBuffer(pathSize);
//
// hres = dbgExt->symbols3->GetSymbolPathWide( &pathBuffer[0], pathSize, NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol3::GetImagePathWide failed" );
//
// std::wstring symPath( &pathBuffer[0], pathSize );
//
// std::wstring altName = m_debugInfo.CVData;
// altName = altName.substr( 0, altName.find_last_of(L".") );
//
// std::wstring imageName = m_debugInfo.LoadedImageName;
// altName += imageName.substr( imageName.find_last_of(L".") );
//
// for ( size_t offset = 0; offset < symPath.length(); )
// {
// size_t newOffset = symPath.find( L";", offset );
// std::wstring subPath = symPath.substr( offset, newOffset - offset );
//
// std::wstringstream sstr;
//
// sstr << subPath << L"\\" << m_debugInfo.LoadedImageName << L"\\" << std::hex <<
// m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
// m_debugInfo.LoadedImageName;
//
// if( (_waccess( sstr.str().c_str(), 0 )) != -1 )
// {
// m_imageFullName = sstr.str();
// break;
// }
//
//
// std::wstringstream altstr;
//
// altstr << subPath << L"\\" << altName << L"\\" << std::hex <<
// m_debugInfo.TimeDateStamp << m_debugInfo.ImageSize << L"\\" <<
// altName;
//
// if( (_waccess( altstr.str().c_str(), 0 )) != -1 )
// {
// m_imageFullName = altstr.str();
// break;
// }
//
// if ( newOffset == std::wstring::npos )
// break;
//
// offset = newOffset + 1;
// }
//}
//
//std::string
//dbgModuleClass::print() const
//{
// const char * format_string(dbgExt->control->IsPointer64Bit() == S_OK ?
// "%1$016x %2$016x %3$20s %4$20s" : "%1$08x %2$08x %3$20s %4$20s");
// boost::format fmt(format_string);
// std::vector<char> v(MAX_PATH);
// ::WideCharToMultiByte(
// CP_ACP,
// 0,
// m_imageFullName.c_str(),
// -1,
// &v[0],
// (ULONG)v.size(),
// 0,
// 0);
// std::string fullname(&v[0]);
// fmt % m_base % (m_end - m_base) % m_name % fullname;
// return fmt.str();
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,177 +1,177 @@
#pragma once
#include <string>
#include <map>
#include "dbgext.h"
#include "dbgmem.h"
/////////////////////////////////////////////////////////////////////////////////
// global unique module data
// WARNING: add only numeric field or change operator <
struct ModuleInfo
{
ULONG64 m_base;
ULONG m_timeDataStamp;
ULONG m_checkSumm;
ModuleInfo()
: m_base(0)
, m_timeDataStamp(0)
, m_checkSumm(0)
{
}
ModuleInfo(
const ModuleInfo &rhs
) : m_base(rhs.m_base)
, m_timeDataStamp(rhs.m_timeDataStamp)
, m_checkSumm(rhs.m_checkSumm)
{
}
ModuleInfo(
const IMAGEHLP_MODULEW64 &dbgImageHelperInfo
) : m_base(addr64(dbgImageHelperInfo.BaseOfImage))
, m_timeDataStamp(dbgImageHelperInfo.TimeDateStamp)
, m_checkSumm(dbgImageHelperInfo.CheckSum)
{
}
ModuleInfo(
const DEBUG_MODULE_PARAMETERS &dbgModuleParameters
) : m_base(addr64(dbgModuleParameters.Base))
, m_timeDataStamp(dbgModuleParameters.TimeDateStamp)
, m_checkSumm(dbgModuleParameters.Checksum)
{
}
bool operator ==(const ModuleInfo &rhs) const
{
return m_base == rhs.m_base
&& m_timeDataStamp == rhs.m_timeDataStamp
&& m_checkSumm == rhs.m_checkSumm;
}
bool operator < (const ModuleInfo &rhs) const
{
return memcmp(this, &rhs, sizeof(ModuleInfo)) < 0;
}
};
/////////////////////////////////////////////////////////////////////////////////
class dbgModuleClass {
public:
dbgModuleClass() :
m_base( 0 ),
m_end( 0 )
{}
dbgModuleClass( const std::string &name, ULONG64 base, ULONG size );
ULONG64
getBegin() const {
return m_base;
}
ULONG64
getEnd() const {
return m_end;
}
ULONG
getSize() const {
return (ULONG)( m_end - m_base );
}
bool
contain( ULONG64 addr ) const {
if ( *( (ULONG*)&addr + 1 ) == 0 )
*( (ULONG*)&addr + 1 ) = 0xFFFFFFFF;
return m_base <= addr && addr <= m_end;
}
std::string
getName() const {
return m_name;
}
void
reloadSymbols();
ULONG64
getOffset( const std::string &symName );
std::wstring
getImageSymbolName() const {
return m_imageFullName;
}
std::wstring
getPdbName() const {
return std::wstring( m_debugInfo.LoadedPdbName );
}
ULONG
getCheckSum() const {
return m_debugInfo.CheckSum;
}
ULONG
getTimeStamp() const {
return m_debugInfo.TimeDateStamp;
}
bool
addSyntheticSymbol( ULONG64 offset, ULONG size, const std::string &symName );
void
delAllSyntheticSymbols();
ULONG
delSyntheticSymbol( ULONG64 offset );
ULONG
delSyntheticSymbolsMask( const std::string &symName );
std::string
print() const;
private:
ULONG64 m_base;
ULONG64 m_end;
std::string m_name;
std::wstring m_imageFullName;
IMAGEHLP_MODULEW64 m_debugInfo;
typedef std::map<std::string, ULONG64> OffsetMap;
OffsetMap m_offsets;
void
getImagePath();
};
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
loadModule( const std::string &moduleName );
// query module parameters (for construct dbgModuleClass) by virtual address
// error : DbgException exception
void queryModuleParams(
__in ULONG64 addr,
__out std::string &name,
__out ULONG64 &base,
__out ULONG &size
);
boost::python::object
findModule( ULONG64 addr );
/////////////////////////////////////////////////////////////////////////////////
//#include <string>
//#include <map>
//
//#include "dbgext.h"
//#include "dbgmem.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//// global unique module data
//// WARNING: add only numeric field or change operator <
//struct ModuleInfo
//{
// ULONG64 m_base;
// ULONG m_timeDataStamp;
// ULONG m_checkSumm;
//
// ModuleInfo()
// : m_base(0)
// , m_timeDataStamp(0)
// , m_checkSumm(0)
// {
// }
// ModuleInfo(
// const ModuleInfo &rhs
// ) : m_base(rhs.m_base)
// , m_timeDataStamp(rhs.m_timeDataStamp)
// , m_checkSumm(rhs.m_checkSumm)
// {
// }
// ModuleInfo(
// const IMAGEHLP_MODULEW64 &dbgImageHelperInfo
// ) : m_base(addr64(dbgImageHelperInfo.BaseOfImage))
// , m_timeDataStamp(dbgImageHelperInfo.TimeDateStamp)
// , m_checkSumm(dbgImageHelperInfo.CheckSum)
// {
// }
// ModuleInfo(
// const DEBUG_MODULE_PARAMETERS &dbgModuleParameters
// ) : m_base(addr64(dbgModuleParameters.Base))
// , m_timeDataStamp(dbgModuleParameters.TimeDateStamp)
// , m_checkSumm(dbgModuleParameters.Checksum)
// {
// }
//
// bool operator ==(const ModuleInfo &rhs) const
// {
// return m_base == rhs.m_base
// && m_timeDataStamp == rhs.m_timeDataStamp
// && m_checkSumm == rhs.m_checkSumm;
// }
// bool operator < (const ModuleInfo &rhs) const
// {
// return memcmp(this, &rhs, sizeof(ModuleInfo)) < 0;
// }
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//class dbgModuleClass {
//
//public:
//
// dbgModuleClass() :
// m_base( 0 ),
// m_end( 0 )
// {}
//
// dbgModuleClass( const std::string &name, ULONG64 base, ULONG size );
//
// ULONG64
// getBegin() const {
// return m_base;
// }
//
// ULONG64
// getEnd() const {
// return m_end;
// }
//
// ULONG
// getSize() const {
// return (ULONG)( m_end - m_base );
// }
//
// bool
// contain( ULONG64 addr ) const {
// if ( *( (ULONG*)&addr + 1 ) == 0 )
// *( (ULONG*)&addr + 1 ) = 0xFFFFFFFF;
//
// return m_base <= addr && addr <= m_end;
// }
//
// std::string
// getName() const {
// return m_name;
// }
//
// void
// reloadSymbols();
//
// ULONG64
// getOffset( const std::string &symName );
//
// std::wstring
// getImageSymbolName() const {
// return m_imageFullName;
// }
//
// std::wstring
// getPdbName() const {
// return std::wstring( m_debugInfo.LoadedPdbName );
// }
//
// ULONG
// getCheckSum() const {
// return m_debugInfo.CheckSum;
// }
//
// ULONG
// getTimeStamp() const {
// return m_debugInfo.TimeDateStamp;
// }
//
// bool
// addSyntheticSymbol( ULONG64 offset, ULONG size, const std::string &symName );
//
// void
// delAllSyntheticSymbols();
//
// ULONG
// delSyntheticSymbol( ULONG64 offset );
//
// ULONG
// delSyntheticSymbolsMask( const std::string &symName );
//
// std::string
// print() const;
//
//private:
//
// ULONG64 m_base;
//
// ULONG64 m_end;
//
// std::string m_name;
//
// std::wstring m_imageFullName;
//
// IMAGEHLP_MODULEW64 m_debugInfo;
//
// typedef std::map<std::string, ULONG64> OffsetMap;
// OffsetMap m_offsets;
//
// void
// getImagePath();
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//loadModule( const std::string &moduleName );
//
//// query module parameters (for construct dbgModuleClass) by virtual address
//// error : DbgException exception
//void queryModuleParams(
// __in ULONG64 addr,
// __out std::string &name,
// __out ULONG64 &base,
// __out ULONG &size
//);
//
//boost::python::object
//findModule( ULONG64 addr );
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,148 +1,148 @@
#include "stdafx.h"
#include "dbgpath.h"
#include <boost/tokenizer.hpp>
///////////////////////////////////////////////////////////////////////////////
DbgPythonPath::DbgPythonPath()
{
DWORD enviromentSize = 0;
enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize );
std::vector<char> enviromentBuffer(enviromentSize);
if (!enviromentBuffer.empty())
{
GetEnvironmentVariableA( "PYTHONPATH", &enviromentBuffer[0], enviromentSize );
typedef boost::escaped_list_separator<char> char_separator_t;
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
std::string pytonPath( &enviromentBuffer[0] );
char_tokenizer_t token( pytonPath, char_separator_t( "", "; \t", "\"" ) );
for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it )
{
if ( *it != "" )
m_pathList.push_back( *it );
}
}
}
///////////////////////////////////////////////////////////////////////////////
std::string
DbgPythonPath::getStr() const
{
std::string str;
std::vector<std::string>::const_iterator it = m_pathList.begin();
for ( ; it != m_pathList.end(); ++it )
{
str += *it;
str += ";";
}
return str;
}
///////////////////////////////////////////////////////////////////////////////
bool
DbgPythonPath::findPath(
const std::string &fileName,
std::string &fullFileName,
std::string &filePath ) const
{
std::vector< std::string > extPathList;
boost::python::object sys = boost::python::import( "sys");
boost::python::list pathList( sys.attr("path") );
boost::python::ssize_t n = boost::python::len(pathList);
for(boost::python::ssize_t i=0;i<n;i++)
extPathList.push_back( boost::python::extract<std::string>( pathList[i] ) );
bool pyExt = fileName.rfind( ".py" ) == fileName.length() - 3;
// 1. Èùåì â ðàáî÷åé äèðåêòîðèè
DWORD bufSize =
SearchPathA(
NULL,
fileName.c_str(),
pyExt ? NULL : ".py",
0,
NULL,
NULL );
if ( bufSize > 0 )
{
bufSize += 1;
std::vector<char> fullFileNameCStr(bufSize);
char *partFileNameCStr = NULL;
SearchPathA(
NULL,
fileName.c_str(),
pyExt ? NULL : ".py",
bufSize,
&fullFileNameCStr[0],
&partFileNameCStr );
fullFileName = std::string( &fullFileNameCStr[0] );
if ( !fullFileName.empty() )
{
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
return true;
}
}
// 2. Èùåì âî âñåõ äèðåêòîðèÿõ, óêàçàííûõ â m_pathList
std::vector<std::string>::const_iterator it = extPathList.begin();
for ( ; it != extPathList.end(); ++it )
{
DWORD bufSize =
SearchPathA(
(*it).c_str(),
fileName.c_str(),
pyExt ? NULL : ".py",
0,
NULL,
NULL );
if ( bufSize > 0 )
{
bufSize += 1;
std::vector<char> fullFileNameCStr(bufSize);
char *partFileNameCStr = NULL;
bufSize = SearchPathA(
(*it).c_str(),
fileName.c_str(),
pyExt ? NULL : ".py",
bufSize,
&fullFileNameCStr[0],
&partFileNameCStr );
fullFileName = std::string( &fullFileNameCStr[0] );
if ( !fullFileName.empty() )
{
filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
return true;
}
}
}
return false;
}
//////////////////////////////////////////////////////////////////////////////
//#include "dbgpath.h"
//
//#include <boost/tokenizer.hpp>
//
/////////////////////////////////////////////////////////////////////////////////
//
//
//
//DbgPythonPath::DbgPythonPath()
//{
// DWORD enviromentSize = 0;
//
// enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize );
//
// std::vector<char> enviromentBuffer(enviromentSize);
//
// if (!enviromentBuffer.empty())
// {
// GetEnvironmentVariableA( "PYTHONPATH", &enviromentBuffer[0], enviromentSize );
//
// typedef boost::escaped_list_separator<char> char_separator_t;
// typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
//
// std::string pytonPath( &enviromentBuffer[0] );
//
// char_tokenizer_t token( pytonPath, char_separator_t( "", "; \t", "\"" ) );
//
// for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it )
// {
// if ( *it != "" )
// m_pathList.push_back( *it );
// }
// }
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//std::string
//DbgPythonPath::getStr() const
//{
// std::string str;
// std::vector<std::string>::const_iterator it = m_pathList.begin();
//
// for ( ; it != m_pathList.end(); ++it )
// {
// str += *it;
// str += ";";
// }
//
// return str;
//}
//
/////////////////////////////////////////////////////////////////////////////////
//
//bool
//DbgPythonPath::findPath(
// const std::string &fileName,
// std::string &fullFileName,
// std::string &filePath ) const
//{
// std::vector< std::string > extPathList;
//
// boost::python::object sys = boost::python::import( "sys");
//
// boost::python::list pathList( sys.attr("path") );
//
// boost::python::ssize_t n = boost::python::len(pathList);
// for(boost::python::ssize_t i=0;i<n;i++)
// extPathList.push_back( boost::python::extract<std::string>( pathList[i] ) );
//
// bool pyExt = fileName.rfind( ".py" ) == fileName.length() - 3;
//
// // 1. Èùåì â ðàáî÷åé äèðåêòîðèè
// DWORD bufSize =
// SearchPathA(
// NULL,
// fileName.c_str(),
// pyExt ? NULL : ".py",
// 0,
// NULL,
// NULL );
//
// if ( bufSize > 0 )
// {
// bufSize += 1;
// std::vector<char> fullFileNameCStr(bufSize);
// char *partFileNameCStr = NULL;
//
// SearchPathA(
// NULL,
// fileName.c_str(),
// pyExt ? NULL : ".py",
// bufSize,
// &fullFileNameCStr[0],
// &partFileNameCStr );
//
// fullFileName = std::string( &fullFileNameCStr[0] );
// if ( !fullFileName.empty() )
// {
// filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
// return true;
// }
// }
//
// // 2. Èùåì âî âñåõ äèðåêòîðèÿõ, óêàçàííûõ â m_pathList
//
// std::vector<std::string>::const_iterator it = extPathList.begin();
//
// for ( ; it != extPathList.end(); ++it )
// {
// DWORD bufSize =
// SearchPathA(
// (*it).c_str(),
// fileName.c_str(),
// pyExt ? NULL : ".py",
// 0,
// NULL,
// NULL );
//
// if ( bufSize > 0 )
// {
// bufSize += 1;
// std::vector<char> fullFileNameCStr(bufSize);
// char *partFileNameCStr = NULL;
//
// bufSize = SearchPathA(
// (*it).c_str(),
// fileName.c_str(),
// pyExt ? NULL : ".py",
// bufSize,
// &fullFileNameCStr[0],
// &partFileNameCStr );
//
// fullFileName = std::string( &fullFileNameCStr[0] );
// if ( !fullFileName.empty() )
// {
// filePath = std::string( &fullFileNameCStr[0], partFileNameCStr );
// return true;
// }
// }
// }
//
// return false;
//}
//
////////////////////////////////////////////////////////////////////////////////

View File

@ -1,32 +1,32 @@
#pragma once
#include <string>
///////////////////////////////////////////////////////////////////////////////
class DbgPythonPath
{
public:
DbgPythonPath();
std::string
getStr() const;
bool
findPath(
const std::string &fileName,
std::string &fullFileName,
std::string &filePath ) const;
private:
std::vector< std::string > m_pathList;
};
//extern DbgPythonPath& dbgPythonPath;
///////////////////////////////////////////////////////////////////////////////
//#include <string>
//
/////////////////////////////////////////////////////////////////////////////////
//
//class DbgPythonPath
//{
//public:
//
// DbgPythonPath();
//
// std::string
// getStr() const;
//
// bool
// findPath(
// const std::string &fileName,
// std::string &fullFileName,
// std::string &filePath ) const;
//
//
//private:
//
// std::vector< std::string > m_pathList;
//
//};
//
////extern DbgPythonPath& dbgPythonPath;
//
//
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,289 +1,289 @@
#include "stdafx.h"
#include <boost/format.hpp>
#include <boost/scoped_array.hpp>
#include "dbgprocess.h"
#include "dbgext.h"
#include "dbgexcept.h"
#include "dbgtype.h"
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
getThreadList()
{
HRESULT hres;
ULONG i;
ULONG oldThreadId = 0;
ULONG threadCount;
hres = dbgExt->system->GetNumberThreads( &threadCount );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects::GetNumberThreads failed" );
boost::scoped_array<ULONG> ids(new ULONG[threadCount]);
hres = dbgExt->system->GetThreadIdsByIndex( 0, threadCount, ids.get(), NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects::GetThreadIdsByIndex failed" );
hres = dbgExt->system->GetCurrentThreadId( &oldThreadId );
boost::python::list threadList;
for ( i = 0; i < threadCount; ++i )
{
dbgExt->system->SetCurrentThreadId( ids[i] );
ULONG64 threadOffset;
hres = dbgExt->system->GetCurrentThreadDataOffset( &threadOffset );
if ( FAILED( hres ) )
{
dbgExt->system->SetCurrentThreadId( oldThreadId );
throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" );
}
threadList.append( threadOffset );
}
return threadList;
}
/////////////////////////////////////////////////////////////////////////////////
void
setImplicitThread(
ULONG64 newThreadAddr )
{
HRESULT hres;
newThreadAddr = addr64(newThreadAddr);
hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" );
}
/////////////////////////////////////////////////////////////////////////////////
ULONG64
getImplicitThread()
{
HRESULT hres;
ULONG64 threadOffset = -1;
hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
return threadOffset;
}
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
getCurrentStack()
{
HRESULT hres;
ULONG currentScope = 0;
hres = dbgExt->symbols3->GetCurrentScopeFrameIndex( &currentScope );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" );
boost::scoped_array<DEBUG_STACK_FRAME> frames(new DEBUG_STACK_FRAME [ 1000 ]);
ULONG filledFrames;
hres = dbgExt->control->GetStackTrace( 0, 0, 0, frames.get(), 1000, &filledFrames );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetStackTrace failed" );
boost::python::list frameList;
for ( ULONG i = 0; i < filledFrames; ++i )
{
dbgStackFrameClass frame( frames[i] );
boost::python::object frameObj( frame );
hres = dbgExt->symbols->SetScope( NULL, &frames[i], NULL, sizeof(DEBUG_STACK_FRAME) );
if ( SUCCEEDED( hres ) )
frameObj.attr( "locals" ) = getLocals();
frameList.append( frameObj );
}
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
return frameList;
}
/////////////////////////////////////////////////////////////////////////////////
std::string
getProcessorMode()
{
HRESULT hres;
ULONG processorMode;
hres = dbgExt->control->GetEffectiveProcessorType( &processorMode );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" );
switch( processorMode )
{
case IMAGE_FILE_MACHINE_I386:
return "X86";
case IMAGE_FILE_MACHINE_ARM:
return "ARM";
case IMAGE_FILE_MACHINE_IA64:
return "IA64";
case IMAGE_FILE_MACHINE_AMD64:
return "X64";
}
throw DbgException( "Unknown CPU type" );
}
/////////////////////////////////////////////////////////////////////////////////
void
setProcessorMode(
const std::string &mode )
{
HRESULT hres;
ULONG processorMode = ~0;
if ( mode == "X86" )
processorMode = IMAGE_FILE_MACHINE_I386;
else if ( mode == "ARM" )
processorMode = IMAGE_FILE_MACHINE_ARM;
else if ( mode == "IA64" )
processorMode = IMAGE_FILE_MACHINE_IA64;
else if ( mode == "X64" )
processorMode = IMAGE_FILE_MACHINE_AMD64;
else
throw DbgException( "Unknown processor type" );
hres = dbgExt->control->SetEffectiveProcessorType( processorMode );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetEffectiveProcessorType failed" );
}
/////////////////////////////////////////////////////////////////////////////////
ULONG64
getCurrentProcess()
{
HRESULT hres;
ULONG64 processAddr = 0;
hres = dbgExt->system2->GetImplicitProcessDataOffset( &processAddr );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" );
return processAddr;
}
/////////////////////////////////////////////////////////////////////////////////
VOID
setCurrentProcess(
ULONG64 processAddr )
{
HRESULT hres;
processAddr = addr64(processAddr);
hres = dbgExt->system2->SetImplicitProcessDataOffset( processAddr );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects2::SetImplicitProcessDataOffset failed" );
}
/////////////////////////////////////////////////////////////////////////////////
dbgStackFrameClass::dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame )
{
memcpy( static_cast<DEBUG_STACK_FRAME*>( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) );
}
/////////////////////////////////////////////////////////////////////////////////
std::string
dbgStackFrameClass::print() const
{
boost::format fmt(dbgExt->control->IsPointer64Bit() == S_OK ? "%1$4d %2$16x" : "%1$4d %2$08x");
fmt % FrameNumber % ReturnOffset;
return fmt.str();
}
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
getLocals()
{
HRESULT hres;
CComPtr<IDebugSymbolGroup> localSymbols;
CComPtr<IDebugSymbolGroup2> localSymbols2;
hres = dbgExt->symbols->GetScopeSymbolGroup( DEBUG_SCOPE_GROUP_ARGUMENTS|DEBUG_SCOPE_GROUP_LOCALS, NULL, &localSymbols );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbols::GetScopeSymbolGroup failed" );
hres = localSymbols->QueryInterface( __uuidof(IDebugSymbolGroup2), (void**) &localSymbols2 );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbols::QueryInterface failed to get IDebugSymbolGroup2" );
ULONG localNumber;
hres = localSymbols->GetNumberSymbols( &localNumber );
boost::python::dict arr;
for ( ULONG i = 0; i < localNumber; ++i )
{
char varName[0x100];
hres = localSymbols->GetSymbolName( i, varName, sizeof(varName), NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbolGroup::GetSymbolName failed" );
DEBUG_SYMBOL_PARAMETERS symbolParam = {};
hres = localSymbols->GetSymbolParameters( i, 1, &symbolParam );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbolGroup::GetSymbolParameters failed" );
char typeName[0x100];
hres = dbgExt->symbols->GetTypeName( symbolParam.Module, symbolParam.TypeId, typeName, sizeof(typeName), NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbols::GetTypeName failed" );
char moduleName[0x100];
hres = dbgExt->symbols2->GetModuleNameString(
DEBUG_MODNAME_MODULE,
DEBUG_ANY_ID,
symbolParam.Module,
moduleName,
sizeof(moduleName),
NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbols2::GetModuleNameString failed" );
ULONG64 varOffset;
hres = localSymbols2->GetSymbolOffset( i, &varOffset );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbolGroup2::GetSymbolOffset failed" );
arr[ varName ] = TypedVar( moduleName, typeName, varOffset );
}
return arr;
}
/////////////////////////////////////////////////////////////////////////////////
//#include <boost/format.hpp>
//#include <boost/scoped_array.hpp>
//
//#include "dbgprocess.h"
//#include "dbgext.h"
//#include "dbgexcept.h"
//#include "dbgtype.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//getThreadList()
//{
// HRESULT hres;
// ULONG i;
// ULONG oldThreadId = 0;
//
// ULONG threadCount;
// hres = dbgExt->system->GetNumberThreads( &threadCount );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSystemObjects::GetNumberThreads failed" );
//
// boost::scoped_array<ULONG> ids(new ULONG[threadCount]);
// hres = dbgExt->system->GetThreadIdsByIndex( 0, threadCount, ids.get(), NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSystemObjects::GetThreadIdsByIndex failed" );
//
// hres = dbgExt->system->GetCurrentThreadId( &oldThreadId );
//
// boost::python::list threadList;
//
// for ( i = 0; i < threadCount; ++i )
// {
// dbgExt->system->SetCurrentThreadId( ids[i] );
//
// ULONG64 threadOffset;
// hres = dbgExt->system->GetCurrentThreadDataOffset( &threadOffset );
//
// if ( FAILED( hres ) )
// {
// dbgExt->system->SetCurrentThreadId( oldThreadId );
// throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" );
// }
//
// threadList.append( threadOffset );
// }
//
// return threadList;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//setImplicitThread(
// ULONG64 newThreadAddr )
//{
// HRESULT hres;
//
// newThreadAddr = addr64(newThreadAddr);
// hres = dbgExt->system2->SetImplicitThreadDataOffset( newThreadAddr );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSystemObjects2::SetImplicitThreadDataOffset failed" );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//getImplicitThread()
//{
// HRESULT hres;
// ULONG64 threadOffset = -1;
//
// hres = dbgExt->system2->GetImplicitThreadDataOffset( &threadOffset );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSystemObjects2::GetImplicitThreadDataOffset failed" );
//
// return threadOffset;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//getCurrentStack()
//{
// HRESULT hres;
// ULONG currentScope = 0;
//
// hres = dbgExt->symbols3->GetCurrentScopeFrameIndex( &currentScope );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" );
//
// boost::scoped_array<DEBUG_STACK_FRAME> frames(new DEBUG_STACK_FRAME [ 1000 ]);
//
// ULONG filledFrames;
// hres = dbgExt->control->GetStackTrace( 0, 0, 0, frames.get(), 1000, &filledFrames );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::GetStackTrace failed" );
//
// boost::python::list frameList;
//
// for ( ULONG i = 0; i < filledFrames; ++i )
// {
// dbgStackFrameClass frame( frames[i] );
//
// boost::python::object frameObj( frame );
//
// hres = dbgExt->symbols->SetScope( NULL, &frames[i], NULL, sizeof(DEBUG_STACK_FRAME) );
// if ( SUCCEEDED( hres ) )
// frameObj.attr( "locals" ) = getLocals();
//
// frameList.append( frameObj );
// }
//
// dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
//
// return frameList;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//std::string
//getProcessorMode()
//{
// HRESULT hres;
//
// ULONG processorMode;
// hres = dbgExt->control->GetEffectiveProcessorType( &processorMode );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" );
//
// switch( processorMode )
// {
// case IMAGE_FILE_MACHINE_I386:
// return "X86";
//
// case IMAGE_FILE_MACHINE_ARM:
// return "ARM";
//
// case IMAGE_FILE_MACHINE_IA64:
// return "IA64";
//
// case IMAGE_FILE_MACHINE_AMD64:
// return "X64";
// }
//
// throw DbgException( "Unknown CPU type" );
//
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//void
//setProcessorMode(
// const std::string &mode )
//{
// HRESULT hres;
// ULONG processorMode = ~0;
//
// if ( mode == "X86" )
// processorMode = IMAGE_FILE_MACHINE_I386;
// else if ( mode == "ARM" )
// processorMode = IMAGE_FILE_MACHINE_ARM;
// else if ( mode == "IA64" )
// processorMode = IMAGE_FILE_MACHINE_IA64;
// else if ( mode == "X64" )
// processorMode = IMAGE_FILE_MACHINE_AMD64;
// else
// throw DbgException( "Unknown processor type" );
//
// hres = dbgExt->control->SetEffectiveProcessorType( processorMode );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::SetEffectiveProcessorType failed" );
//
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//getCurrentProcess()
//{
// HRESULT hres;
// ULONG64 processAddr = 0;
//
// hres = dbgExt->system2->GetImplicitProcessDataOffset( &processAddr );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSystemObjects2::GetImplicitProcessDataOffset failed" );
//
// return processAddr;
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//VOID
//setCurrentProcess(
// ULONG64 processAddr )
//{
// HRESULT hres;
//
// processAddr = addr64(processAddr);
// hres = dbgExt->system2->SetImplicitProcessDataOffset( processAddr );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSystemObjects2::SetImplicitProcessDataOffset failed" );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//dbgStackFrameClass::dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame )
//{
// memcpy( static_cast<DEBUG_STACK_FRAME*>( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) );
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgStackFrameClass::print() const
//{
// boost::format fmt(dbgExt->control->IsPointer64Bit() == S_OK ? "%1$4d %2$16x" : "%1$4d %2$08x");
// fmt % FrameNumber % ReturnOffset;
// return fmt.str();
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//getLocals()
//{
// HRESULT hres;
// CComPtr<IDebugSymbolGroup> localSymbols;
// CComPtr<IDebugSymbolGroup2> localSymbols2;
//
// hres = dbgExt->symbols->GetScopeSymbolGroup( DEBUG_SCOPE_GROUP_ARGUMENTS|DEBUG_SCOPE_GROUP_LOCALS, NULL, &localSymbols );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbols::GetScopeSymbolGroup failed" );
//
// hres = localSymbols->QueryInterface( __uuidof(IDebugSymbolGroup2), (void**) &localSymbols2 );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbols::QueryInterface failed to get IDebugSymbolGroup2" );
//
// ULONG localNumber;
// hres = localSymbols->GetNumberSymbols( &localNumber );
//
// boost::python::dict arr;
//
// for ( ULONG i = 0; i < localNumber; ++i )
// {
// char varName[0x100];
//
// hres = localSymbols->GetSymbolName( i, varName, sizeof(varName), NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbolGroup::GetSymbolName failed" );
//
// DEBUG_SYMBOL_PARAMETERS symbolParam = {};
// hres = localSymbols->GetSymbolParameters( i, 1, &symbolParam );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbolGroup::GetSymbolParameters failed" );
//
// char typeName[0x100];
// hres = dbgExt->symbols->GetTypeName( symbolParam.Module, symbolParam.TypeId, typeName, sizeof(typeName), NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbols::GetTypeName failed" );
//
// char moduleName[0x100];
// hres = dbgExt->symbols2->GetModuleNameString(
// DEBUG_MODNAME_MODULE,
// DEBUG_ANY_ID,
// symbolParam.Module,
// moduleName,
// sizeof(moduleName),
// NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbols2::GetModuleNameString failed" );
//
//
// ULONG64 varOffset;
// hres = localSymbols2->GetSymbolOffset( i, &varOffset );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbolGroup2::GetSymbolOffset failed" );
//
// arr[ varName ] = TypedVar( moduleName, typeName, varOffset );
// }
//
// return arr;
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,54 +1,54 @@
#pragma once
#include <dbgeng.h>
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
getThreadList();
void
setImplicitThread(
ULONG64 newThreadAddr );
ULONG64
getImplicitThread();
boost::python::object
getCurrentStack();
boost::python::object
getLocals();
class dbgStackFrameClass : public DEBUG_STACK_FRAME {
public:
dbgStackFrameClass()
{
memset( static_cast<DEBUG_STACK_FRAME*>( this ), 0, sizeof(DEBUG_STACK_FRAME) );
}
dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame );
std::string
print() const;
};
//#include <dbgeng.h>
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
std::string
getProcessorMode();
void
setProcessorMode(
const std::string &mode );
ULONG64
getCurrentProcess();
VOID
setCurrentProcess(
ULONG64 processAddr );
/////////////////////////////////////////////////////////////////////////////////
//getThreadList();
//
//void
//setImplicitThread(
// ULONG64 newThreadAddr );
//
//ULONG64
//getImplicitThread();
//
//boost::python::object
//getCurrentStack();
//
//boost::python::object
//getLocals();
//
//
//class dbgStackFrameClass : public DEBUG_STACK_FRAME {
//
//public:
//
// dbgStackFrameClass()
// {
// memset( static_cast<DEBUG_STACK_FRAME*>( this ), 0, sizeof(DEBUG_STACK_FRAME) );
// }
//
// dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame );
//
// std::string
// print() const;
//};
//
////boost::python::object
//std::string
//getProcessorMode();
//
//void
//setProcessorMode(
// const std::string &mode );
//
//ULONG64
//getCurrentProcess();
//
//VOID
//setCurrentProcess(
// ULONG64 processAddr );
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,162 +1,162 @@
#include "stdafx.h"
#include "dbgext.h"
#include "dbgreg.h"
#include "dbgexcept.h"
using namespace std;
///////////////////////////////////////////////////////////////////////////////////
cpuReg::cpuReg( std::string regName )
{
HRESULT hres;
m_name = regName;
m_lived = false;
hres = dbgExt->registers->GetIndexByName( m_name.c_str(), &m_index );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegister::GetIndexByName failed" );
reloadValue();
}
///////////////////////////////////////////////////////////////////////////////////
cpuReg::cpuReg( ULONG index )
{
HRESULT hres;
m_index = index;
m_lived = false;
ULONG nameSize = 0;
hres =
dbgExt->registers->GetDescription(
m_index,
NULL,
0,
&nameSize,
NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegister::GetDescription failed" );
std::vector<char> nameBuffer(nameSize);
hres =
dbgExt->registers->GetDescription(
m_index,
&nameBuffer[0],
nameSize,
NULL,
NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegister::GetDescription failed" );
m_name = std::string( &nameBuffer[0] );
reloadValue();
}
///////////////////////////////////////////////////////////////////////////////////
void cpuReg::reloadValue() const
{
HRESULT hres;
DEBUG_VALUE debugValue;
hres = dbgExt->registers->GetValue( m_index, &debugValue );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegister::GetValue failed" );
switch( debugValue.Type )
{
case DEBUG_VALUE_INT8:
m_value = debugValue.I8;
break;
case DEBUG_VALUE_INT16:
m_value = debugValue.I16;
break;
case DEBUG_VALUE_INT32:
m_value = debugValue.I32;
break;
case DEBUG_VALUE_INT64:
m_value = debugValue.I64;
break;
}
}
///////////////////////////////////////////////////////////////////////////////////
boost::python::object
loadRegister( const std::string &registerName )
{
HRESULT hres;
ULONG registerIndex = 0;
hres = dbgExt->registers->GetIndexByName( registerName.c_str(), &registerIndex );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegister::GetIndexByName failed" );
DEBUG_VALUE debugValue;
hres = dbgExt->registers->GetValue( registerIndex, &debugValue );
if ( FAILED( hres ) )
throw DbgException( "IDebugRegister::GetValue failed" );
switch( debugValue.Type )
{
case DEBUG_VALUE_INT8:
return boost::python::long_( debugValue.I8 );
break;
case DEBUG_VALUE_INT16:
return boost::python::long_( debugValue.I16 );
break;
case DEBUG_VALUE_INT32:
return boost::python::long_( debugValue.I32 );
break;
case DEBUG_VALUE_INT64:
return boost::python::long_(debugValue.I64 );
break;
}
throw DbgException( "Invalid register value" );
}
///////////////////////////////////////////////////////////////////////////////////
ULONG64
loadMSR( ULONG msr )
{
HRESULT hres;
ULONG64 value;
hres = dbgExt->dataSpaces->ReadMsr( msr, &value );
if ( FAILED( hres ) )
throw DbgException( "IDebugDataSpaces::ReadMsr failed" );
return value;
}
///////////////////////////////////////////////////////////////////////////////////
void setMSR( ULONG msr, ULONG64 value)
{
HRESULT hres;
hres = dbgExt->dataSpaces->WriteMsr(msr, value);
if ( FAILED( hres ) )
throw DbgException( "IDebugDataSpaces::WriteMsr failed" );
}
///////////////////////////////////////////////////////////////////////////////////
//#include "dbgext.h"
//#include "dbgreg.h"
//#include "dbgexcept.h"
//
//using namespace std;
//
/////////////////////////////////////////////////////////////////////////////////////
//
//cpuReg::cpuReg( std::string regName )
//{
// HRESULT hres;
//
// m_name = regName;
// m_lived = false;
//
// hres = dbgExt->registers->GetIndexByName( m_name.c_str(), &m_index );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugRegister::GetIndexByName failed" );
//
// reloadValue();
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//cpuReg::cpuReg( ULONG index )
//{
// HRESULT hres;
//
// m_index = index;
// m_lived = false;
//
// ULONG nameSize = 0;
//
// hres =
// dbgExt->registers->GetDescription(
// m_index,
// NULL,
// 0,
// &nameSize,
// NULL );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugRegister::GetDescription failed" );
//
// std::vector<char> nameBuffer(nameSize);
//
// hres =
// dbgExt->registers->GetDescription(
// m_index,
// &nameBuffer[0],
// nameSize,
// NULL,
// NULL );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugRegister::GetDescription failed" );
//
// m_name = std::string( &nameBuffer[0] );
//
// reloadValue();
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//void cpuReg::reloadValue() const
//{
// HRESULT hres;
//
// DEBUG_VALUE debugValue;
// hres = dbgExt->registers->GetValue( m_index, &debugValue );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugRegister::GetValue failed" );
//
// switch( debugValue.Type )
// {
// case DEBUG_VALUE_INT8:
// m_value = debugValue.I8;
// break;
//
// case DEBUG_VALUE_INT16:
// m_value = debugValue.I16;
// break;
//
// case DEBUG_VALUE_INT32:
// m_value = debugValue.I32;
// break;
//
// case DEBUG_VALUE_INT64:
// m_value = debugValue.I64;
// break;
// }
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//loadRegister( const std::string &registerName )
//{
// HRESULT hres;
//
// ULONG registerIndex = 0;
//
// hres = dbgExt->registers->GetIndexByName( registerName.c_str(), &registerIndex );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugRegister::GetIndexByName failed" );
//
// DEBUG_VALUE debugValue;
// hres = dbgExt->registers->GetValue( registerIndex, &debugValue );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugRegister::GetValue failed" );
//
// switch( debugValue.Type )
// {
// case DEBUG_VALUE_INT8:
// return boost::python::long_( debugValue.I8 );
// break;
//
// case DEBUG_VALUE_INT16:
// return boost::python::long_( debugValue.I16 );
// break;
//
// case DEBUG_VALUE_INT32:
// return boost::python::long_( debugValue.I32 );
// break;
//
// case DEBUG_VALUE_INT64:
// return boost::python::long_(debugValue.I64 );
// break;
// }
//
// throw DbgException( "Invalid register value" );
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//loadMSR( ULONG msr )
//{
// HRESULT hres;
// ULONG64 value;
//
// hres = dbgExt->dataSpaces->ReadMsr( msr, &value );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugDataSpaces::ReadMsr failed" );
//
// return value;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//void setMSR( ULONG msr, ULONG64 value)
//{
// HRESULT hres;
//
// hres = dbgExt->dataSpaces->WriteMsr(msr, value);
// if ( FAILED( hres ) )
// throw DbgException( "IDebugDataSpaces::WriteMsr failed" );
//}
//
/////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,61 +1,61 @@
#pragma once
#include <string>
#include <list>
#include "intbase.h"
/////////////////////////////////////////////////////////////////////////////////
class cpuReg : public intBase {
public :
cpuReg( std::string regName );
cpuReg( ULONG index );
std::string
name() const {
return m_name;
}
ULONG
index() const {
return m_index;
}
void beLive() {
m_lived = true;
}
ULONG64 value() const
{
if ( m_lived )
reloadValue();
return intBase::value();
}
private:
void reloadValue() const;
std::string m_name;
ULONG m_index;
bool m_lived;
};
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
loadRegister( const std::string &registerName );
ULONG64
loadMSR( ULONG msr );
void setMSR( ULONG msr, ULONG64 val);
/////////////////////////////////////////////////////////////////////////////////
//#include <string>
//#include <list>
//
//#include "intbase.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//class cpuReg : public intBase {
//
//public :
//
// cpuReg( std::string regName );
//
// cpuReg( ULONG index );
//
// std::string
// name() const {
// return m_name;
// }
//
// ULONG
// index() const {
// return m_index;
// }
//
// void beLive() {
// m_lived = true;
// }
//
// ULONG64 value() const
// {
// if ( m_lived )
// reloadValue();
//
// return intBase::value();
// }
//
//private:
//
// void reloadValue() const;
//
// std::string m_name;
//
// ULONG m_index;
//
// bool m_lived;
//};
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//loadRegister( const std::string &registerName );
//
//ULONG64
//loadMSR( ULONG msr );
//
//void setMSR( ULONG msr, ULONG64 val);
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,78 +1,78 @@
#include "stdafx.h"
#include "dbgext.h"
#include "dbgsym.h"
#include "dbgexcept.h"
#include "dbgmem.h"
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
findSymbolForAddress( ULONG64 addr )
{
HRESULT hres;
try {
addr = addr64( addr );
ULONG moduleIndex;
ULONG64 moduleBase;
hres = dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase );
if ( FAILED( hres ) )
{
return boost::python::object();
}
char moduleName[0x100];
hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, moduleIndex, moduleBase,
moduleName, sizeof( moduleName ), NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol2::GetModuleNameString failed" );
char symbolName[0x100];
ULONG64 displace = 0;
hres = dbgExt->symbols->GetNameByOffset( addr, symbolName, sizeof(symbolName), NULL, &displace );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetNameByOffset failed" );
std::stringstream ss;
displace == 0 ? ss << symbolName : ss << symbolName << '+' << std::hex << displace;
return boost::python::object( ss.str() );
}
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" );
}
return boost::python::object();
}
/////////////////////////////////////////////////////////////////////////////////
ULONG64
findAddressForSymbol( const std::string &moduleName, const std::string &symbolName )
{
HRESULT hres;
std::string ModuleSymName = moduleName;
ModuleSymName += "!";
ModuleSymName += symbolName;
ULONG64 offset = 0ULL;
hres = dbgExt->symbols->GetOffsetByName( ModuleSymName.c_str(), &offset );
if ( SUCCEEDED( hres ) )
return offset;
throw DbgException( "failed to find offset for symbol" );
}
/////////////////////////////////////////////////////////////////////////////////
//#include "dbgext.h"
//#include "dbgsym.h"
//#include "dbgexcept.h"
//#include "dbgmem.h"
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//findSymbolForAddress( ULONG64 addr )
//{
// HRESULT hres;
//
// try {
//
// addr = addr64( addr );
//
// ULONG moduleIndex;
// ULONG64 moduleBase;
// hres = dbgExt->symbols->GetModuleByOffset( addr, 0, &moduleIndex, &moduleBase );
//
// if ( FAILED( hres ) )
// {
// return boost::python::object();
// }
//
// char moduleName[0x100];
// hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, moduleIndex, moduleBase,
// moduleName, sizeof( moduleName ), NULL );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol2::GetModuleNameString failed" );
//
// char symbolName[0x100];
// ULONG64 displace = 0;
// hres = dbgExt->symbols->GetNameByOffset( addr, symbolName, sizeof(symbolName), NULL, &displace );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbol::GetNameByOffset failed" );
//
// std::stringstream ss;
// displace == 0 ? ss << symbolName : ss << symbolName << '+' << std::hex << displace;
//
// return boost::python::object( ss.str() );
//
// }
// 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" );
// }
//
// return boost::python::object();
//}
//
///////////////////////////////////////////////////////////////////////////////////
//
//ULONG64
//findAddressForSymbol( const std::string &moduleName, const std::string &symbolName )
//{
// HRESULT hres;
//
// std::string ModuleSymName = moduleName;
// ModuleSymName += "!";
// ModuleSymName += symbolName;
//
// ULONG64 offset = 0ULL;
// hres = dbgExt->symbols->GetOffsetByName( ModuleSymName.c_str(), &offset );
// if ( SUCCEEDED( hres ) )
// return offset;
//
// throw DbgException( "failed to find offset for symbol" );
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,13 +1,13 @@
#pragma once
#include <string>
/////////////////////////////////////////////////////////////////////////////////
boost::python::object
findSymbolForAddress( ULONG64 addr );
ULONG64
findAddressForSymbol( const std::string &moduleName, const std::string &symbolName );
/////////////////////////////////////////////////////////////////////////////////
//#include <string>
//
///////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//findSymbolForAddress( ULONG64 addr );
//
//ULONG64
//findAddressForSymbol( const std::string &moduleName, const std::string &symbolName );
//
///////////////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -1,56 +1,56 @@
#pragma once
/////////////////////////////////////////////////////////////////////////////////
// Global functions
bool addSyntheticSymbol(
ULONG64 addr,
ULONG size,
const std::string &symName
);
void delAllSyntheticSymbols();
ULONG delSyntheticSymbol(
ULONG64 addr
);
ULONG delSyntheticSymbolsMask(
const std::string &moduleName,
const std::string &symName
);
/////////////////////////////////////////////////////////////////////////////////
// Functions for dbgModuleClass
ULONG64 getSyntheticSymbol(
const ModuleInfo &moduleInfo,
const std::string &symName
);
bool addSyntheticSymbolForModule(
ULONG64 offset,
ULONG size,
const std::string &symName,
const ModuleInfo &moduleInfo
);
ULONG delSyntheticSymbolForModule(
ULONG64 offset,
const ModuleInfo &moduleInfo
);
void delAllSyntheticSymbolsForModule(
const ModuleInfo &moduleInfo
);
/////////////////////////////////////////////////////////////////////////////////
// External callbacks
void restoreSyntheticSymbolForModule(
const ModuleInfo &moduleInfo );
void restoreSyntheticSymbolForAllModules();
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//// Global functions
//
//bool addSyntheticSymbol(
// ULONG64 addr,
// ULONG size,
// const std::string &symName
//);
//
//void delAllSyntheticSymbols();
//
//ULONG delSyntheticSymbol(
// ULONG64 addr
//);
//
//ULONG delSyntheticSymbolsMask(
// const std::string &moduleName,
// const std::string &symName
//);
//
///////////////////////////////////////////////////////////////////////////////////
//// Functions for dbgModuleClass
//
//ULONG64 getSyntheticSymbol(
// const ModuleInfo &moduleInfo,
// const std::string &symName
//);
//
//bool addSyntheticSymbolForModule(
// ULONG64 offset,
// ULONG size,
// const std::string &symName,
// const ModuleInfo &moduleInfo
//);
//
//ULONG delSyntheticSymbolForModule(
// ULONG64 offset,
// const ModuleInfo &moduleInfo
//);
//
//void delAllSyntheticSymbolsForModule(
// const ModuleInfo &moduleInfo
//);
//
///////////////////////////////////////////////////////////////////////////////////
//// External callbacks
//
//void restoreSyntheticSymbolForModule(
// const ModuleInfo &moduleInfo );
//
//void restoreSyntheticSymbolForAllModules();
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,210 +1,210 @@
#include "stdafx.h"
#include <exception>
#include "dbgext.h"
#include "dbgexcept.h"
#include "dbgsystem.h"
#include "dbgio.h"
///////////////////////////////////////////////////////////////////////////////////
bool
is64bitSystem()
{
HRESULT hres;
try {
hres = dbgExt->control->IsPointer64Bit();
return hres == S_OK;
}
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" );
}
return false;
}
///////////////////////////////////////////////////////////////////////////////////
int
ptrSize()
{
return is64bitSystem() ? 8 : 4;
}
///////////////////////////////////////////////////////////////////////////////////
std::string
dbgSymPath()
{
HRESULT hres;
std::string pathStr;
try {
ULONG size;
dbgExt->symbols->GetSymbolPath( NULL, 0, &size );
std::vector<char> path(size);
hres = dbgExt->symbols->GetSymbolPath( &path[0], size, NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbols::GetSymbolPath failed" );
pathStr = &path[0];
}
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" );
}
return pathStr;
}
///////////////////////////////////////////////////////////////////////////////////
std::string
getPdbFile( ULONG64 moduleBase )
{
HRESULT hres;
try {
IMAGEHLP_MODULEW64 imageHelpInfo = { 0 };
hres =
dbgExt->advanced2->GetSymbolInformation(
DEBUG_SYMINFO_IMAGEHLP_MODULEW64,
moduleBase,
0,
&imageHelpInfo,
sizeof( imageHelpInfo ),
NULL,
NULL,
0,
NULL );
char fileName[ 256 ];
WideCharToMultiByte( CP_ACP, 0, imageHelpInfo.LoadedPdbName, 256, fileName, 256, NULL, NULL );
return std::string( fileName );
}
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" );
}
return std::string();
}
///////////////////////////////////////////////////////////////////////////////////
void
reloadModule( const char * moduleName )
{
HRESULT hres;
try {
// ïîäàâèòü âûâîä ñîîáùåíèé îá îòñóòñòâèè ñèìâîëîâ
OutputReader outputReader( dbgExt->client );
hres = dbgExt->symbols->Reload( moduleName );
//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" );
}
}
///////////////////////////////////////////////////////////////////////////////////
bool
isKernelDebugging()
{
HRESULT hres;
bool result = false;
try {
ULONG debugClass, debugQualifier;
hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetDebuggeeType failed" );
result = debugClass == DEBUG_CLASS_KERNEL;
}
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" );
}
return result;
}
///////////////////////////////////////////////////////////////////////////////////
bool
isDumpAnalyzing()
{
HRESULT hres;
bool result = false;
try {
ULONG debugClass, debugQualifier;
hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetDebuggeeType failed" );
result = debugQualifier >= DEBUG_DUMP_SMALL;
}
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" );
}
return result;
}
///////////////////////////////////////////////////////////////////////////////////
//#include <exception>
//#include "dbgext.h"
//#include "dbgexcept.h"
//#include "dbgsystem.h"
//#include "dbgio.h"
//
/////////////////////////////////////////////////////////////////////////////////////
//
//bool
//is64bitSystem()
//{
// HRESULT hres;
//
// try {
//
// hres = dbgExt->control->IsPointer64Bit();
//
// return hres == S_OK;
//
// }
// 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" );
// }
//
// return false;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//int
//ptrSize()
//{
// return is64bitSystem() ? 8 : 4;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//std::string
//dbgSymPath()
//{
// HRESULT hres;
// std::string pathStr;
//
// try {
//
// ULONG size;
// dbgExt->symbols->GetSymbolPath( NULL, 0, &size );
//
// std::vector<char> path(size);
// hres = dbgExt->symbols->GetSymbolPath( &path[0], size, NULL );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugSymbols::GetSymbolPath failed" );
//
// pathStr = &path[0];
//
// }
// 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" );
// }
//
// return pathStr;
//}
//
//
/////////////////////////////////////////////////////////////////////////////////////
//
//std::string
//getPdbFile( ULONG64 moduleBase )
//{
// HRESULT hres;
//
// try {
//
//
// IMAGEHLP_MODULEW64 imageHelpInfo = { 0 };
//
// hres =
// dbgExt->advanced2->GetSymbolInformation(
// DEBUG_SYMINFO_IMAGEHLP_MODULEW64,
// moduleBase,
// 0,
// &imageHelpInfo,
// sizeof( imageHelpInfo ),
// NULL,
// NULL,
// 0,
// NULL );
//
// char fileName[ 256 ];
// WideCharToMultiByte( CP_ACP, 0, imageHelpInfo.LoadedPdbName, 256, fileName, 256, NULL, NULL );
//
// return std::string( fileName );
//
// }
// 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" );
// }
//
// return std::string();
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//void
//reloadModule( const char * moduleName )
//{
// HRESULT hres;
//
// try {
//
// // ïîäàâèòü âûâîä ñîîáùåíèé îá îòñóòñòâèè ñèìâîëîâ
// OutputReader outputReader( dbgExt->client );
//
// hres = dbgExt->symbols->Reload( moduleName );
//
// //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" );
// }
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//bool
//isKernelDebugging()
//{
// HRESULT hres;
// bool result = false;
//
// try {
//
// ULONG debugClass, debugQualifier;
//
// hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::GetDebuggeeType failed" );
//
// result = debugClass == DEBUG_CLASS_KERNEL;
//
// }
// 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" );
// }
//
// return result;
//}
//
/////////////////////////////////////////////////////////////////////////////////////
//
//bool
//isDumpAnalyzing()
//{
// HRESULT hres;
// bool result = false;
//
// try {
//
// ULONG debugClass, debugQualifier;
//
// hres = dbgExt->control->GetDebuggeeType( &debugClass, &debugQualifier );
//
// if ( FAILED( hres ) )
// throw DbgException( "IDebugControl::GetDebuggeeType failed" );
//
// result = debugQualifier >= DEBUG_DUMP_SMALL;
//
// }
// 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" );
// }
//
// return result;
//}
//
/////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,31 +1,31 @@
#pragma once
#include <string>
/////////////////////////////////////////////////////////////////////////////////
bool
is64bitSystem();
int
ptrSize();
std::string
dbgSymPath();
std::string
getPdbFile( ULONG64 moduleBase );
std::string
getImageFile( ULONG64 moduleBase );
void
reloadModule( const char * moduleName );
bool
isKernelDebugging();
bool
isDumpAnalyzing();
/////////////////////////////////////////////////////////////////////////////////
//#include <string>
//
///////////////////////////////////////////////////////////////////////////////////
//
//bool
//is64bitSystem();
//
//int
//ptrSize();
//
//std::string
//dbgSymPath();
//
//std::string
//getPdbFile( ULONG64 moduleBase );
//
//std::string
//getImageFile( ULONG64 moduleBase );
//
//void
//reloadModule( const char * moduleName );
//
//bool
//isKernelDebugging();
//
//bool
//isDumpAnalyzing();
//
///////////////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -1,295 +1,295 @@
#pragma once
#include <string>
#include <map>
#include "dbgmem.h"
#include "dbgsystem.h"
#include <boost/python/slice.hpp>
///////////////////////////////////////////////////////////////////////////////////
class TypedVar;
class TypeInfo;
///////////////////////////////////////////////////////////////////////////////////
class TypeInfo {
public:
TypeInfo() :
m_size(0),
m_arraySize( 0 ),
m_parentOffset( 0 ),
m_align( 0 ),
m_isFreezed( false ),
m_isBaseType( false ),
m_isPointer( false ),
m_alignReq(1)
{}
TypeInfo( const std::string customName, ULONG align = 0) :
m_typeName( customName ),
m_size( 0 ),
m_arraySize( 0 ),
m_parentOffset( 0 ),
m_isFreezed( false ),
m_align( align ),
m_isBaseType( false ),
m_isPointer( false ),
m_alignReq(1)
{}
TypeInfo( const std::string &moduleName, const std::string &typeName );
TypeInfo( const std::string &moduleName, ULONG64 moduleBase, ULONG typeId );
static
const TypeInfo&
get( const std::string &moduleName, const std::string &typeName );
ULONG
size() const {
return m_size;
}
ULONG
count() const {
assert( m_size != 0 && m_arraySize >= m_size );
return m_arraySize / m_size;
}
ULONG
fullSize() const {
return m_arraySize;
}
const std::string
name() const {
return m_typeName;
}
const std::string
moduleName() const {
return m_moduleName;
}
boost::python::object
load( void* buffer, size_t bufferLength ) const;
std::string
printField( size_t index, void* buffer, size_t bufferLength ) const;
std::string
print() const;
TypeInfo
getField( const std::string &fieldName ) const;
TypeInfo
getFieldAt( size_t index ) const;
ULONG
getFieldOffset() const {
return m_parentOffset;
}
boost::python::object
getFieldByIndex( boost::python::object &index ) const;
size_t
getFieldCount() const {
return m_fields.size();
}
void
appendField( const TypeInfo &typeInfo, const std::string &fieldName, ULONG count = 1 );
bool
isBaseType() const {
return m_isBaseType;
}
bool
isPtr() const {
return m_isPointer;
}
bool
isEnum() const {
return !m_isBaseType && !m_isPointer && m_fields.size() == 0 && m_size == 4;
}
boost::python::object
loadVar( ULONG64 targetOffset, ULONG count = 1) const;
void setAlignReq(ULONG alignReq) {
m_alignReq = alignReq;
}
public:
typedef std::map< std::pair<std::string, std::string>, TypeInfo> TypeInfoMap;
template< typename TTypeInfo>
struct TypeFieldT {
std::string name;
ULONG offset;
ULONG size;
TTypeInfo type;
TypeFieldT( const std::string &name_, const TTypeInfo &type_, ULONG size_, ULONG offset_ ) :
name( name_ ),
size( size_ ),
offset( offset_ ),
type( type_ )
{}
std::string print() const;
};
typedef TypeFieldT<TypeInfo> TypeField;
typedef std::vector<TypeField> TypeFieldList;
private:
ULONG getAlignReq() const;
void addField(
const std::string &name_,
const TypeInfo &type_,
ULONG size_,
ULONG offset_
);
typedef
boost::python::object
(*basicTypeLoader)( void* address, size_t size );
typedef
std::string
(*basicTypePrinter)( void* address, size_t size );
static TypeInfoMap g_typeInfoCache;
static const char* basicTypeNames[];
static size_t basicTypeSizes[];
static basicTypeLoader basicTypeLoaders[];
static basicTypePrinter basicTypePrinters[];
ULONG m_size;
ULONG m_arraySize;
std::string m_typeName;
std::string m_moduleName;
TypeFieldList m_fields;
bool m_isPointer;
bool m_isBaseType;
bool m_isFreezed;
ULONG m_align;
ULONG m_alignReq;
ULONG m_parentOffset;
static bool checkBaseType( const std::string &typeName );
static ULONG getBaseTypeSize( const std::string &typeName );
};
///////////////////////////////////////////////////////////////////////////////////
class TypedVar {
public:
TypedVar() :
m_targetOffset ( 0 )
{}
TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset ) :
m_typeInfo( typeInfo ),
m_targetOffset( addr64(targetOffset) )
{}
TypedVar( const std::string &moduleName, const std::string &typeName, ULONG64 targetOffset ) :
m_typeInfo( moduleName, typeName ),
m_targetOffset( addr64(targetOffset) )
{}
TypedVar( ULONG64 targetOffset );
TypedVar( const std::string &symbolName );
ULONG64
getAddress() const {
return m_targetOffset;
}
ULONG
getSize() const {
return m_typeInfo.fullSize();
}
static
boost::python::object
getFieldWrap( PyObject* self, const std::string &fieldName );
boost::python::object
getField( boost::python::object &pyobj, const std::string &fieldName );
ULONG64 getTargetOffset() const {
return m_targetOffset;
}
std::string data();
std::string print();
private:
void reallocBuffer();
TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset, char* buffer, size_t bufferLength );
ULONG64 m_targetOffset;
TypeInfo m_typeInfo;
std::vector<char> m_buffer;
};
///////////////////////////////////////////////////////////////////////////////////
boost::python::object
loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName );
boost::python::object
loadTypedVarArray( ULONG64 address, const std::string &moduleName, const std::string &typeName, long number );
boost::python::object
containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName );
ULONG
sizeofType( const std::string &moduleName, const std::string &typeName );
///////////////////////////////////////////////////////////////////////////////////
//#include <string>
//#include <map>
//
//#include "dbgmem.h"
//#include "dbgsystem.h"
//
//#include <boost/python/slice.hpp>
//
/////////////////////////////////////////////////////////////////////////////////////
//
//class TypedVar;
//class TypeInfo;
//
/////////////////////////////////////////////////////////////////////////////////////
//
//class TypeInfo {
//
//public:
//
// TypeInfo() :
// m_size(0),
// m_arraySize( 0 ),
// m_parentOffset( 0 ),
// m_align( 0 ),
// m_isFreezed( false ),
// m_isBaseType( false ),
// m_isPointer( false ),
// m_alignReq(1)
// {}
//
// TypeInfo( const std::string customName, ULONG align = 0) :
// m_typeName( customName ),
// m_size( 0 ),
// m_arraySize( 0 ),
// m_parentOffset( 0 ),
// m_isFreezed( false ),
// m_align( align ),
// m_isBaseType( false ),
// m_isPointer( false ),
// m_alignReq(1)
// {}
//
// TypeInfo( const std::string &moduleName, const std::string &typeName );
//
// TypeInfo( const std::string &moduleName, ULONG64 moduleBase, ULONG typeId );
//
// static
// const TypeInfo&
// get( const std::string &moduleName, const std::string &typeName );
//
// ULONG
// size() const {
// return m_size;
// }
//
// ULONG
// count() const {
// assert( m_size != 0 && m_arraySize >= m_size );
// return m_arraySize / m_size;
// }
//
// ULONG
// fullSize() const {
// return m_arraySize;
// }
//
// const std::string
// name() const {
// return m_typeName;
// }
//
// const std::string
// moduleName() const {
// return m_moduleName;
// }
//
// boost::python::object
// load( void* buffer, size_t bufferLength ) const;
//
// std::string
// printField( size_t index, void* buffer, size_t bufferLength ) const;
//
// std::string
// print() const;
//
// TypeInfo
// getField( const std::string &fieldName ) const;
//
// TypeInfo
// getFieldAt( size_t index ) const;
//
// ULONG
// getFieldOffset() const {
// return m_parentOffset;
// }
//
// boost::python::object
// getFieldByIndex( boost::python::object &index ) const;
//
// size_t
// getFieldCount() const {
// return m_fields.size();
// }
//
// void
// appendField( const TypeInfo &typeInfo, const std::string &fieldName, ULONG count = 1 );
//
// bool
// isBaseType() const {
// return m_isBaseType;
// }
//
// bool
// isPtr() const {
// return m_isPointer;
// }
//
// bool
// isEnum() const {
// return !m_isBaseType && !m_isPointer && m_fields.size() == 0 && m_size == 4;
// }
//
// boost::python::object
// loadVar( ULONG64 targetOffset, ULONG count = 1) const;
//
// void setAlignReq(ULONG alignReq) {
// m_alignReq = alignReq;
// }
//
//public:
//
// typedef std::map< std::pair<std::string, std::string>, TypeInfo> TypeInfoMap;
//
// template< typename TTypeInfo>
// struct TypeFieldT {
//
// std::string name;
//
// ULONG offset;
//
// ULONG size;
//
// TTypeInfo type;
//
// TypeFieldT( const std::string &name_, const TTypeInfo &type_, ULONG size_, ULONG offset_ ) :
// name( name_ ),
// size( size_ ),
// offset( offset_ ),
// type( type_ )
// {}
//
// std::string print() const;
// };
//
// typedef TypeFieldT<TypeInfo> TypeField;
//
// typedef std::vector<TypeField> TypeFieldList;
//
//private:
//
// ULONG getAlignReq() const;
//
// void addField(
// const std::string &name_,
// const TypeInfo &type_,
// ULONG size_,
// ULONG offset_
// );
//
// typedef
// boost::python::object
// (*basicTypeLoader)( void* address, size_t size );
//
// typedef
// std::string
// (*basicTypePrinter)( void* address, size_t size );
//
// static TypeInfoMap g_typeInfoCache;
//
// static const char* basicTypeNames[];
//
// static size_t basicTypeSizes[];
//
// static basicTypeLoader basicTypeLoaders[];
//
// static basicTypePrinter basicTypePrinters[];
//
// ULONG m_size;
//
// ULONG m_arraySize;
//
// std::string m_typeName;
//
// std::string m_moduleName;
//
// TypeFieldList m_fields;
//
// bool m_isPointer;
//
// bool m_isBaseType;
//
// bool m_isFreezed;
//
// ULONG m_align;
//
// ULONG m_alignReq;
//
// ULONG m_parentOffset;
//
// static bool checkBaseType( const std::string &typeName );
//
// static ULONG getBaseTypeSize( const std::string &typeName );
//};
//
//
/////////////////////////////////////////////////////////////////////////////////////
//
//class TypedVar {
//
//public:
//
// TypedVar() :
// m_targetOffset ( 0 )
// {}
//
// TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset ) :
// m_typeInfo( typeInfo ),
// m_targetOffset( addr64(targetOffset) )
// {}
//
// TypedVar( const std::string &moduleName, const std::string &typeName, ULONG64 targetOffset ) :
// m_typeInfo( moduleName, typeName ),
// m_targetOffset( addr64(targetOffset) )
// {}
//
// TypedVar( ULONG64 targetOffset );
//
// TypedVar( const std::string &symbolName );
//
// ULONG64
// getAddress() const {
// return m_targetOffset;
// }
//
// ULONG
// getSize() const {
// return m_typeInfo.fullSize();
// }
//
// static
// boost::python::object
// getFieldWrap( PyObject* self, const std::string &fieldName );
//
// boost::python::object
// getField( boost::python::object &pyobj, const std::string &fieldName );
//
// ULONG64 getTargetOffset() const {
// return m_targetOffset;
// }
//
// std::string data();
//
// std::string print();
//
//private:
//
// void reallocBuffer();
//
// TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset, char* buffer, size_t bufferLength );
//
// ULONG64 m_targetOffset;
//
// TypeInfo m_typeInfo;
//
// std::vector<char> m_buffer;
//};
//
/////////////////////////////////////////////////////////////////////////////////////
//
//boost::python::object
//loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName );
//
//boost::python::object
//loadTypedVarArray( ULONG64 address, const std::string &moduleName, const std::string &typeName, long number );
//
//boost::python::object
//containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName );
//
//ULONG
//sizeofType( const std::string &moduleName, const std::string &typeName );
//
/////////////////////////////////////////////////////////////////////////////////////
//

View File

@ -1,49 +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( &currentOffset );
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);
}
/////////////////////////////////////////////////////////////////////////////////
//#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( &currentOffset );
// 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);
//}
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,54 +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;
};
/////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//
//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;
//};
//
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,88 +1,88 @@
#pragma once
class intBase : boost::integer_arithmetic<intBase>
{
public:
explicit intBase( ULONG64 val = 0 ) : m_value( val) {}
virtual ~intBase() {}
operator ULONG64() const {
return value();
}
intBase& operator= ( ULONG64 val ) {
setValue( val );
return *this;
}
virtual ULONG64 value() const {
return m_value;
}
virtual void setValue( ULONG64 value) {
m_value = value;
}
std::string
str() const {
std::stringstream ss;
ss << value();
return ss.str();
}
std::string
hex() const {
std::stringstream ss;
ss << std::hex << value();
return ss.str();
}
template <class T>
intBase& operator+=(T const& rhs)
{ m_value += rhs; return *this; }
template <class T>
intBase& operator-=(T const& rhs)
{ m_value -= rhs; return *this; }
template <class T>
intBase& operator*=(T const& rhs)
{ m_value *= rhs; return *this; }
template <class T>
intBase& operator/=(T const& rhs)
{ m_value /= rhs; return *this; }
template <class T>
intBase& operator%=(T const& rhs)
{ m_value %= rhs; return *this; }
template <class T>
intBase& operator&=(T const& rhs)
{ m_value &= rhs; return *this; }
template <class T>
intBase& operator|=(T const& rhs)
{ m_value |= rhs; return *this; }
template <class T>
intBase& operator^=(T const& rhs)
{ m_value ^= rhs; return *this; }
template <class T>
intBase& operator<<=(T const& rhs)
{ m_value <<= rhs; return *this; }
template <class T>
intBase& operator>>=(T const& rhs)
{ m_value >>= rhs; return *this; }
protected:
mutable ULONG64 m_value;
};
//class intBase : boost::integer_arithmetic<intBase>
//{
//
//public:
//
// explicit intBase( ULONG64 val = 0 ) : m_value( val) {}
//
// virtual ~intBase() {}
//
// operator ULONG64() const {
// return value();
// }
//
// intBase& operator= ( ULONG64 val ) {
// setValue( val );
// return *this;
// }
//
// virtual ULONG64 value() const {
// return m_value;
// }
//
// virtual void setValue( ULONG64 value) {
// m_value = value;
// }
//
// std::string
// str() const {
// std::stringstream ss;
// ss << value();
// return ss.str();
// }
//
// std::string
// hex() const {
// std::stringstream ss;
// ss << std::hex << value();
// return ss.str();
// }
//
// template <class T>
// intBase& operator+=(T const& rhs)
// { m_value += rhs; return *this; }
//
// template <class T>
// intBase& operator-=(T const& rhs)
// { m_value -= rhs; return *this; }
//
// template <class T>
// intBase& operator*=(T const& rhs)
// { m_value *= rhs; return *this; }
//
// template <class T>
// intBase& operator/=(T const& rhs)
// { m_value /= rhs; return *this; }
//
// template <class T>
// intBase& operator%=(T const& rhs)
// { m_value %= rhs; return *this; }
//
// template <class T>
// intBase& operator&=(T const& rhs)
// { m_value &= rhs; return *this; }
//
// template <class T>
// intBase& operator|=(T const& rhs)
// { m_value |= rhs; return *this; }
//
// template <class T>
// intBase& operator^=(T const& rhs)
// { m_value ^= rhs; return *this; }
//
// template <class T>
// intBase& operator<<=(T const& rhs)
// { m_value <<= rhs; return *this; }
//
// template <class T>
// intBase& operator>>=(T const& rhs)
// { m_value >>= rhs; return *this; }
//
//protected:
//
// mutable ULONG64 m_value;
//
//};

View File

@ -1,57 +1,57 @@
#pragma once
///////////////////////////////////////////////////////////////////////////////
typedef PyThreadState *PyThreadStatePtr;
extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
// --> call back
// { PyThread_StateSave state( winext->getThreadState() );
// do_callback();
// }
/////////////////////////////////////////////////////////////////////////////////
//
// Ĺńëč ęîëáĺę áűë âűçâŕí č ďđč ýňîě ó ňĺęůĺăî ďîňîęŕ ńîőđŕíĺí ęîíňĺęńň ( áűë âűçîâ setExecutionStatus )
// ňî ďĺđĺä âűďîëíĺíčĺě ďčňîíîâńęîăî ęîäŕ íóćíî âîńńňŕíîâčňü ęîíňĺęńň, ŕ ďîńëĺ âîçâđŕňŕ óďđŕâëĺíč˙,
// ńíîâŕ ńîőđŕíčňü ĺăî
class PyThread_StateSave {
public:
PyThread_StateSave()
: m_bRestored(false)
{
if (ptrPyThreadState)
{
PyEval_RestoreThread( ptrPyThreadState );
m_bRestored = true;
}
}
~PyThread_StateSave() {
if ( m_bRestored )
ptrPyThreadState = PyEval_SaveThread();
}
private:
bool m_bRestored;
};
// { PyThread_StateRestore state;
// long_or_block_opreration();
// }
class PyThread_StateRestore
{
public:
PyThread_StateRestore() {
ptrPyThreadState = PyEval_SaveThread();
}
~PyThread_StateRestore() {
PyEval_RestoreThread( ptrPyThreadState );
}
};
///////////////////////////////////////////////////////////////////////////////
//typedef PyThreadState *PyThreadStatePtr;
//extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
//
//// --> call back
//// { PyThread_StateSave state( winext->getThreadState() );
//// do_callback();
//// }
////
//// Ĺńëč ęîëáĺę áűë âűçâŕí č ďđč ýňîě ó ňĺęůĺăî ďîňîęŕ ńîőđŕíĺí ęîíňĺęńň ( áűë âűçîâ setExecutionStatus )
//// ňî ďĺđĺä âűďîëíĺíčĺě ďčňîíîâńęîăî ęîäŕ íóćíî âîńńňŕíîâčňü ęîíňĺęńň, ŕ ďîńëĺ âîçâđŕňŕ óďđŕâëĺíč˙,
//// ńíîâŕ ńîőđŕíčňü ĺăî
//
//class PyThread_StateSave {
//
//public:
//
// PyThread_StateSave()
// : m_bRestored(false)
// {
// if (ptrPyThreadState)
// {
// PyEval_RestoreThread( ptrPyThreadState );
// m_bRestored = true;
// }
// }
//
// ~PyThread_StateSave() {
// if ( m_bRestored )
// ptrPyThreadState = PyEval_SaveThread();
// }
//
//private:
// bool m_bRestored;
//};
//
//// { PyThread_StateRestore state;
//// long_or_block_opreration();
//// }
//
//class PyThread_StateRestore
//{
//public:
//
// PyThread_StateRestore() {
// ptrPyThreadState = PyEval_SaveThread();
// }
//
// ~PyThread_StateRestore() {
// PyEval_RestoreThread( ptrPyThreadState );
// }
//};
//
/////////////////////////////////////////////////////////////////////////////////

View File

@ -5,4 +5,3 @@ EXPORTS
info
py
pycmd
pythonpath

View File

@ -53,8 +53,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,19,0
PRODUCTVERSION 0,0,19,0
FILEVERSION 0,1,0,0
PRODUCTVERSION 0,1,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -70,11 +70,11 @@ BEGIN
BLOCK "041904b0"
BEGIN
VALUE "FileDescription", "pykd - python extension for windbg"
VALUE "FileVersion", "0, 0, 19, 0"
VALUE "FileVersion", "0, 1, 0, 0"
VALUE "InternalName", "pykd"
VALUE "OriginalFilename", "pykd.dll"
VALUE "ProductName", "pykd - python extension for windbg"
VALUE "ProductVersion", "0, 0, 19, 0"
VALUE "ProductVersion", "0, 1, 0, 0"
END
END
BLOCK "VarFileInfo"

View File

@ -349,82 +349,10 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\dbgbreak.cpp"
>
</File>
<File
RelativePath=".\dbgcmd.cpp"
>
</File>
<File
RelativePath=".\dbgdump.cpp"
>
</File>
<File
RelativePath=".\dbgevent.cpp"
>
</File>
<File
RelativePath=".\dbgeventcb.cpp"
>
</File>
<File
RelativePath=".\dbgexcept.cpp"
>
</File>
<File
RelativePath=".\dbgext.cpp"
>
</File>
<File
RelativePath=".\dbgio.cpp"
>
</File>
<File
RelativePath=".\dbgmem.cpp"
>
</File>
<File
RelativePath=".\dbgmodule.cpp"
>
</File>
<File
RelativePath=".\dbgpath.cpp"
>
</File>
<File
RelativePath=".\dbgprocess.cpp"
>
</File>
<File
RelativePath=".\dbgreg.cpp"
>
</File>
<File
RelativePath=".\dbgsym.cpp"
>
</File>
<File
RelativePath=".\dbgsynsym.cpp"
>
</File>
<File
RelativePath=".\dbgsystem.cpp"
>
</File>
<File
RelativePath=".\dbgtype.cpp"
>
</File>
<File
RelativePath=".\disasm.cpp"
>
</File>
<File
RelativePath=".\pykd.cpp"
>
</File>
<File
RelativePath=".\pykd.def"
>
@ -471,90 +399,6 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\dbgbreak.h"
>
</File>
<File
RelativePath=".\dbgclient.h"
>
</File>
<File
RelativePath=".\dbgcmd.h"
>
</File>
<File
RelativePath=".\dbgdump.h"
>
</File>
<File
RelativePath=".\dbgevent.h"
>
</File>
<File
RelativePath=".\dbgeventcb.h"
>
</File>
<File
RelativePath=".\dbgexcept.h"
>
</File>
<File
RelativePath=".\dbgext.h"
>
</File>
<File
RelativePath=".\dbgio.h"
>
</File>
<File
RelativePath=".\dbgmem.h"
>
</File>
<File
RelativePath=".\dbgmodule.h"
>
</File>
<File
RelativePath=".\dbgpath.h"
>
</File>
<File
RelativePath=".\dbgprocess.h"
>
</File>
<File
RelativePath=".\dbgreg.h"
>
</File>
<File
RelativePath=".\dbgsym.h"
>
</File>
<File
RelativePath=".\dbgsynsym.h"
>
</File>
<File
RelativePath=".\dbgsystem.h"
>
</File>
<File
RelativePath=".\dbgtype.h"
>
</File>
<File
RelativePath=".\disasm.h"
>
</File>
<File
RelativePath=".\intbase.h"
>
</File>
<File
RelativePath=".\pyaux.h"
>
</File>
<File
RelativePath=".\resource.h"
>

View File

@ -30,32 +30,32 @@
#include <windows.h>
#include <atlbase.h>
#ifndef __field_ecount_opt
#define __field_ecount_opt(x)
#endif // __field_ecount_opt
#define BOOST_PYTHON_STATIC_LIB
#pragma warning(push)
// 'return' : conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data
#pragma warning(disable:4244)
#include <boost/python.hpp>
#include <boost/python/object.hpp>
#pragma warning(pop)
#include <vector>
template <typename TElem>
TElem *getVectorBuffer(std::vector<TElem> &vec)
{
return vec.size() ? &vec[0] : NULL;
}
template <typename TElem>
const TElem *getVectorBuffer(const std::vector<TElem> &vec)
{
return vec.size() ? &vec[0] : NULL;
}
// TODO: reference additional headers your program requires here
//
//#ifndef __field_ecount_opt
//#define __field_ecount_opt(x)
//#endif // __field_ecount_opt
//
//
//#define BOOST_PYTHON_STATIC_LIB
//
//#pragma warning(push)
//// 'return' : conversion from 'Py_ssize_t' to 'unsigned int', possible loss of data
//#pragma warning(disable:4244)
//#include <boost/python.hpp>
//#include <boost/python/object.hpp>
//#pragma warning(pop)
//
//#include <vector>
//
//template <typename TElem>
//TElem *getVectorBuffer(std::vector<TElem> &vec)
//{
// return vec.size() ? &vec[0] : NULL;
//}
//template <typename TElem>
//const TElem *getVectorBuffer(const std::vector<TElem> &vec)
//{
// return vec.size() ? &vec[0] : NULL;
//}
//
//// TODO: reference additional headers your program requires here

View File

@ -20,8 +20,8 @@ def getTestSuite( singleName = "" ):
if singleName == "":
return unittest.TestSuite(
[ unittest.TestLoader().loadTestsFromTestCase( basetest.BaseTest ),
unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ),
unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest )
# unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ),
# unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest )
] )
else:
return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) )

View File

@ -1,34 +1,34 @@
import unittest
import pykd
import target
#import unittest
#import pykd
#import target
class CpuRegTest( unittest.TestCase ):
#class CpuRegTest( unittest.TestCase ):
def testBasic(self):
try:
reg = pykd.cpuReg(0)
self.assertTrue(True)
except pykd.BaseException:
pass
# def testBasic(self):
# try:
# reg = pykd.cpuReg(0)
# self.assertTrue(True)
# except pykd.BaseException:
# pass
def testGPR(self):
# def testGPR(self):
if pykd.is64bitSystem():
# if pykd.is64bitSystem():
rax = pykd.cpuReg("rax")
self.assertEqual( rax, pykd.reg("rax") )
# rax = pykd.cpuReg("rax")
# self.assertEqual( rax, pykd.reg("rax") )
rip = pykd.cpuReg("rip")
self.assertEqual( rip, pykd.reg("rip") )
# rip = pykd.cpuReg("rip")
# self.assertEqual( rip, pykd.reg("rip") )
else:
# else:
eax = pykd.cpuReg("eax")
self.assertEqual( eax, pykd.reg("eax") )
# eax = pykd.cpuReg("eax")
# self.assertEqual( eax, pykd.reg("eax") )
eip = pykd.cpuReg("eip")
self.assertEqual( eip, pykd.reg("eip") )
# eip = pykd.cpuReg("eip")
# self.assertEqual( eip, pykd.reg("eip") )

View File

@ -2,78 +2,78 @@
#
#
import unittest
import pykd
import target
#import unittest
#import pykd
#import target
class TypeInfoTest( unittest.TestCase ):
#class TypeInfoTest( unittest.TestCase ):
def testBasicTypes(self):
self.assertEqual( pykd.char_t.name(), "char" )
self.assertEqual( pykd.char_t.size(), 1 )
self.assertEqual( pykd.uchar_t.name(), "unsigned char" )
self.assertEqual( pykd.uchar_t.size(), 1 )
# def testBasicTypes(self):
# self.assertEqual( pykd.char_t.name(), "char" )
# self.assertEqual( pykd.char_t.size(), 1 )
# self.assertEqual( pykd.uchar_t.name(), "unsigned char" )
# self.assertEqual( pykd.uchar_t.size(), 1 )
def testSimpleStruct(self):
ti = pykd.typeInfo( target.moduleName, "Type1" )
self.assertTrue( hasattr( ti, "field1" ) )
self.assertTrue( hasattr( ti, "field2" ) )
self.assertTrue( hasattr( ti, "field3" ) )
# def testSimpleStruct(self):
# ti = pykd.typeInfo( target.moduleName, "Type1" )
# self.assertTrue( hasattr( ti, "field1" ) )
# self.assertTrue( hasattr( ti, "field2" ) )
# self.assertTrue( hasattr( ti, "field3" ) )
tv = pykd.typedVar( ti, target.module.var1 )
self.assertEqual( tv.field1, -121 )
self.assertEqual( tv.field2, 220 )
# tv = pykd.typedVar( ti, target.module.var1 )
# self.assertEqual( tv.field1, -121 )
# self.assertEqual( tv.field2, 220 )
# self.assertLess( tv.field3 - 1.0095, 0.0001 )
def testEnumField(self):
ti = pykd.typeInfo( target.moduleName, "Type2" )
self.assertEqual( hasattr( ti, "field1" ), True )
# def testEnumField(self):
# ti = pykd.typeInfo( target.moduleName, "Type2" )
# self.assertEqual( hasattr( ti, "field1" ), True )
tv = pykd.typedVar( ti, target.module.var2 )
self.assertEqual( tv.field1, 100 )
# tv = pykd.typedVar( ti, target.module.var2 )
# self.assertEqual( tv.field1, 100 )
def testNamespace(self):
ti1 = pykd.typeInfo( target.moduleName, "Namespace1::Class1" )
ti2 = pykd.typeInfo( target.moduleName, "Namespace1::Namespace2::Class2" )
var3 = pykd.typedVar( ti1, pykd.getOffset( target.moduleName, "Namespace1::var3" ) )
var4 = pykd.typedVar( ti1, pykd.getOffset( target.moduleName, "Namespace1::Namespace2::var4" ) )
self.assertEqual( var3.m_field1, 50 )
# def testNamespace(self):
# ti1 = pykd.typeInfo( target.moduleName, "Namespace1::Class1" )
# ti2 = pykd.typeInfo( target.moduleName, "Namespace1::Namespace2::Class2" )
# var3 = pykd.typedVar( ti1, pykd.getOffset( target.moduleName, "Namespace1::var3" ) )
# var4 = pykd.typedVar( ti1, pykd.getOffset( target.moduleName, "Namespace1::Namespace2::var4" ) )
# self.assertEqual( var3.m_field1, 50 )
def testTemplates(self):
ti3 = pykd.typeInfo( target.moduleName, "Namespace3::Class3<int>" )
var5 = pykd.typedVar( ti3, pykd.getOffset( target.moduleName, "Namespace3::var5" ) )
self.assertEqual( var5.m_field1, 5 )
# def testTemplates(self):
# ti3 = pykd.typeInfo( target.moduleName, "Namespace3::Class3<int>" )
# var5 = pykd.typedVar( ti3, pykd.getOffset( target.moduleName, "Namespace3::var5" ) )
# self.assertEqual( var5.m_field1, 5 )
def testNestedStruct(self):
ti4 = pykd.typeInfo( target.moduleName, "Type4" )
self.assertTrue( hasattr( ti4, "field1" ) )
self.assertTrue( hasattr( ti4, "field2" ) )
self.assertTrue( hasattr( ti4, "field3" ) )
self.assertTrue( hasattr( ti4, "field4" ) )
self.assertTrue( hasattr( ti4, "field4" ) )
self.assertTrue( hasattr( ti4.field4, "field41" ) )
# def testNestedStruct(self):
# ti4 = pykd.typeInfo( target.moduleName, "Type4" )
# self.assertTrue( hasattr( ti4, "field1" ) )
# self.assertTrue( hasattr( ti4, "field2" ) )
# self.assertTrue( hasattr( ti4, "field3" ) )
# self.assertTrue( hasattr( ti4, "field4" ) )
# self.assertTrue( hasattr( ti4, "field4" ) )
# self.assertTrue( hasattr( ti4.field4, "field41" ) )
def testPtrField(self):
v6 = pykd.typedVar( target.moduleName, "Type6", pykd.getOffset( target.moduleName, "var6" ) )
self.assertEqual( v6.field1, 10 )
self.assertEqual( v6.field2.field1, 10 )
self.assertEqual( v6.field2.field2, 20 )
self.assertNotEqual( v6.field2, 0 )
self.assertEqual( v6.field3[0].field1, 10 )
self.assertEqual( v6.field3[1].field2, 20 )
# def testPtrField(self):
# v6 = pykd.typedVar( target.moduleName, "Type6", pykd.getOffset( target.moduleName, "var6" ) )
# self.assertEqual( v6.field1, 10 )
# self.assertEqual( v6.field2.field1, 10 )
# self.assertEqual( v6.field2.field2, 20 )
# self.assertNotEqual( v6.field2, 0 )
# self.assertEqual( v6.field3[0].field1, 10 )
# self.assertEqual( v6.field3[1].field2, 20 )
def testArrayField(self):
v7 = pykd.typedVar( target.moduleName, "Type7", pykd.getOffset( target.moduleName, "var7" ) )
self.assertEqual( v7.field1[1].field1, 10 )
self.assertEqual( v7.field1[5].field2, 20 )
self.assertEqual( v7.field2[1][0].field1, 10 )
self.assertEqual( v7.field2[0][1].field2, 20 )
# def testArrayField(self):
# v7 = pykd.typedVar( target.moduleName, "Type7", pykd.getOffset( target.moduleName, "var7" ) )
# self.assertEqual( v7.field1[1].field1, 10 )
# self.assertEqual( v7.field1[5].field2, 20 )
# self.assertEqual( v7.field2[1][0].field1, 10 )
# self.assertEqual( v7.field2[0][1].field2, 20 )
def testTypedVarByAddress(self):
var5 = pykd.typedVar( pykd.getOffset( target.moduleName, "Namespace3::var5" ) )
self.assertEqual( var5.m_field1, 5 )
# def testTypedVarByAddress(self):
# var5 = pykd.typedVar( pykd.getOffset( target.moduleName, "Namespace3::var5" ) )
# self.assertEqual( var5.m_field1, 5 )
def testTypedVarBySymbolName(self):
var5 = pykd.typedVar( "Namespace3::var5" )
self.assertEqual( var5.m_field1, 5 )
# def testTypedVarBySymbolName(self):
# var5 = pykd.typedVar( "Namespace3::var5" )
# self.assertEqual( var5.m_field1, 5 )

View File

@ -1,190 +1,190 @@
#include "stdafx.h"
#include <string>
///////////////////////////////////////////////////////////////////////////////
// áàçîâûé òèïû
char charVar = -100;
unsigned char ucharVar = 200;
///////////////////////////////////////////////////////////////////////////////
struct Type1 {
char field1;
unsigned char field2;
double field3;
};
Type1 var1 = { -121, 220, 1.0095f };
///////////////////////////////////////////////////////////////////////////////
enum Enum1 {
Enum1Val1 = 100,
Enum1Val2 = 200,
Enum1Val3 = 300
};
struct Type2 {
Enum1 field1;
};
Type2 var2 = { Enum1Val1 };
///////////////////////////////////////////////////////////////////////////////
namespace Namespace1 {
class Class1 {
public:
Class1( unsigned long v1 ) :
m_field1( v1 )
{}
private:
unsigned long m_field1;
};
Class1 var3( 50 );
namespace Namespace2 {
class Class2 {
public:
Class2( const std::string &str ) :
m_field1 ( str )
{}
private:
std::string m_field1;
};
Class2 var4( "hello" );
};
};
///////////////////////////////////////////////////////////////////////////////
namespace Namespace3
{
template<typename T>
class Class3
{
public:
Class3(T val): m_field1 (val)
{
}
private:
T m_field1;
};
Class3<int> var5(5);
};
///////////////////////////////////////////////////////////////////////////////
#pragma pack( push, 4 )
struct Type4
{
int field1;
struct {
int field2;
int field3;
};
struct {
int field41;
} field4;
};
Type4 var4 = {};
#pragma pack( pop )
///////////////////////////////////////////////////////////////////////////////
class Type5 {
private:
int field1;
int field2;
public:
Type5() : field1(10), field2(20) {}
};
class Type6 {
private:
int field1;
Type5 *field2;
Type5 *field3[2];
Type5 **field4;
public:
Type6() {
field1 = 10;
field2 = new Type5;
field3[0] = new Type5;
field3[1] = new Type5;
field4 = &field2;
}
~Type6() {
delete field2;
}
};
Type6 var6;
///////////////////////////////////////////////////////////////////////////////
class Type7 {
private:
Type5 field1[10];
Type5 field2[2][2];
int field3[2][2][2];
};
Type7 var7;
///////////////////////////////////////////////////////////////////////////////
//#include <string>
//
/////////////////////////////////////////////////////////////////////////////////
//
//// áàçîâûé òèïû
//
//char charVar = -100;
//unsigned char ucharVar = 200;
//
/////////////////////////////////////////////////////////////////////////////////
//
//struct Type1 {
//
// char field1;
//
// unsigned char field2;
//
// double field3;
//};
//
//Type1 var1 = { -121, 220, 1.0095f };
//
/////////////////////////////////////////////////////////////////////////////////
//
//
//enum Enum1 {
//
// Enum1Val1 = 100,
// Enum1Val2 = 200,
// Enum1Val3 = 300
//};
//
//struct Type2 {
//
// Enum1 field1;
//
//};
//
//
//Type2 var2 = { Enum1Val1 };
//
/////////////////////////////////////////////////////////////////////////////////
//
//
//namespace Namespace1 {
//
//
// class Class1 {
//
// public:
//
// Class1( unsigned long v1 ) :
// m_field1( v1 )
// {}
//
// private:
//
// unsigned long m_field1;
//
// };
//
// Class1 var3( 50 );
//
// namespace Namespace2 {
//
// class Class2 {
//
// public:
//
// Class2( const std::string &str ) :
// m_field1 ( str )
// {}
//
// private:
//
// std::string m_field1;
// };
//
// Class2 var4( "hello" );
//
// };
//};
//
/////////////////////////////////////////////////////////////////////////////////
//
//namespace Namespace3
//{
//
// template<typename T>
// class Class3
// {
// public:
// Class3(T val): m_field1 (val)
// {
// }
// private:
// T m_field1;
// };
//
// Class3<int> var5(5);
//
//};
/////////////////////////////////////////////////////////////////////////////////
//
//#pragma pack( push, 4 )
//
//struct Type4
//{
// int field1;
//
// struct {
//
// int field2;
//
// int field3;
// };
//
// struct {
//
// int field41;
//
// } field4;
//
//};
//
//Type4 var4 = {};
//
//#pragma pack( pop )
//
/////////////////////////////////////////////////////////////////////////////////
//
//class Type5 {
//
//private:
//
// int field1;
// int field2;
//
//public:
//
// Type5() : field1(10), field2(20) {}
//};
//
//class Type6 {
//
//private:
//
// int field1;
// Type5 *field2;
// Type5 *field3[2];
// Type5 **field4;
//
//public:
//
// Type6() {
// field1 = 10;
// field2 = new Type5;
// field3[0] = new Type5;
// field3[1] = new Type5;
//
// field4 = &field2;
// }
//
// ~Type6() {
// delete field2;
// }
//
//};
//
//Type6 var6;
//
/////////////////////////////////////////////////////////////////////////////////
//
//class Type7 {
//
//private:
//
// Type5 field1[10];
//
// Type5 field2[2][2];
//
// int field3[2][2][2];
//
//};
//
//Type7 var7;
//
/////////////////////////////////////////////////////////////////////////////////