diff --git a/pykd/dbgbreak.cpp b/pykd/dbgbreak.cpp index 3f6088e..8657962 100644 --- a/pykd/dbgbreak.cpp +++ b/pykd/dbgbreak.cpp @@ -1,162 +1,162 @@ #include "stdafx.h" -#include - -#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( 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(¶ms); - 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 ""; -} - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +//#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( 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(¶ms); +// 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 ""; +//} +// +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgbreak.h b/pykd/dbgbreak.h index a6609e6..b8f3d0d 100644 --- a/pykd/dbgbreak.h +++ b/pykd/dbgbreak.h @@ -1,46 +1,46 @@ #pragma once -#include -#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 breakpointMap; - static breakpointMap m_breakMap; - -public: - - static HRESULT onBreakpointEvnet( IDebugBreakpoint* bp ); - -}; - -///////////////////////////////////////////////////////////////////////////////// +//#include +//#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 breakpointMap; +// static breakpointMap m_breakMap; +// +//public: +// +// static HRESULT onBreakpointEvnet( IDebugBreakpoint* bp ); +// +//}; +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index f7f3f1c..c971f10 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -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; - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#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; +// +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgcmd.cpp b/pykd/dbgcmd.cpp index c25cbd6..21bd33a 100644 --- a/pykd/dbgcmd.cpp +++ b/pykd/dbgcmd.cpp @@ -1,132 +1,132 @@ #include "stdafx.h" - -#include - -#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" ); -} - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +// +//#include +// +//#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" ); +//} +// +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgcmd.h b/pykd/dbgcmd.h index d59ad02..021ff6c 100644 --- a/pykd/dbgcmd.h +++ b/pykd/dbgcmd.h @@ -1,86 +1,86 @@ #pragma once -#include -#include -#include "pyaux.h" - -///////////////////////////////////////////////////////////////////////////////// - -std::string -dbgCommand( const std::string &command ); - -template -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( ¤tStatus ); - - 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(); - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +//#include +//#include "pyaux.h" +// +/////////////////////////////////////////////////////////////////////////////////// +// +//std::string +//dbgCommand( const std::string &command ); +// +//template +//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( ¤tStatus ); +// +// 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(); +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgdump.cpp b/pykd/dbgdump.cpp index d51128d..6b15fd2 100644 --- a/pykd/dbgdump.cpp +++ b/pykd/dbgdump.cpp @@ -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" ); -} - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#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" ); +//} +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgdump.h b/pykd/dbgdump.h index 725979e..793d0d2 100644 --- a/pykd/dbgdump.h +++ b/pykd/dbgdump.h @@ -1,19 +1,19 @@ #pragma once -#include - -///////////////////////////////////////////////////////////////////////////////// - -void -dbgLoadDump( const std::wstring &dumpName ); - -void -startProcess( const std::wstring &processName ); - -void -attachProcess( ULONG processId ); - -void -attachKernel( const std::wstring param ); - -///////////////////////////////////////////////////////////////////////////////// +//#include +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void +//dbgLoadDump( const std::wstring &dumpName ); +// +//void +//startProcess( const std::wstring &processName ); +// +//void +//attachProcess( ULONG processId ); +// +//void +//attachKernel( const std::wstring param ); +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgevent.cpp b/pykd/dbgevent.cpp index 3d47ab9..3125cd4 100644 --- a/pykd/dbgevent.cpp +++ b/pykd/dbgevent.cpp @@ -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 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 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 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 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(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// diff --git a/pykd/dbgevent.h b/pykd/dbgevent.h index ffdfa77..084e5bd 100644 --- a/pykd/dbgevent.h +++ b/pykd/dbgevent.h @@ -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, public debugEvent -{ - -public: - - ULONG onBreakpoint(boost::python::dict &bpParameters) { - return handler("onBreakpoint", bpParameters); - } - - ULONG onException(boost::python::dict &exceptData) { - return handler("onException", exceptData); - } - - ULONG onLoadModule(const dbgModuleClass &module) { - return handler("onLoadModule", module ); - } - - ULONG onUnloadModule(const dbgModuleClass &module) { - return handler("onUnloadModule", module ); - } - - ULONG onChangeSessionStatus( ULONG status ) { - return handler( "onChangeSessionStatus", status ); - } - - ULONG onChangeDebugeeState() { - return handler( "onChangeDebugeeState" ); - } - -private: - - template - 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 +//#include "dbgeventcb.h" +//#include "dbgmodule.h" +//#include "pyaux.h" // -//#include -//#include +/////////////////////////////////////////////////////////////////////////////////// // -//class debugEvent +//class debugEvent : public DebugBaseEventCallbacks //{ +//public: +// // debugEvent(); +// // virtual ~debugEvent(); // -// virtual ULONG onLoadModule(const dbgModuleClass &/* module */) -// { -// return DEBUG_STATUS_NO_CHANGE; -// } -// -// virtual ULONG onUnloadModule(const dbgModuleClass &/* module */) -// { -// return DEBUG_STATUS_NO_CHANGE; -// } -// -// virtual ULONG onChangeSessionState( ULONG state ) -// { -// return DEBUG_STATUS_NO_CHANGE; -// } -// +// virtual ULONG onBreakpoint(boost::python::dict &/*bpParameters*/) = 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 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: // -// typedef std::set modCallbacksColl; -// static modCallbacksColl modCallbacks; -// -// -// //typedef boost::interprocess::interprocess_recursive_mutex modCallbacksLock; -// //static modCallbacksLock modCallbacksMtx; -// //typedef boost::interprocess::scoped_lock modCallbacksScopedLock; +// IDebugClient *m_debugClient; //}; // -//// python wrapper for debugEvent -//struct debugEventWrap : debugEvent, boost::python::wrapper +/////////////////////////////////////////////////////////////////////////////////// +// +//class debugEventWrap : public boost::python::wrapper, 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("onBreakpoint", bpParameters); // } // -// ULONG onUnloadModule(const dbgModuleClass &module); -// ULONG onUnloadModuleDef(const dbgModuleClass &module) +// ULONG onException(boost::python::dict &exceptData) { +// return handler("onException", exceptData); +// } +// +// ULONG onLoadModule(const dbgModuleClass &module) { +// return handler("onLoadModule", module ); +// } +// +// ULONG onUnloadModule(const dbgModuleClass &module) { +// return handler("onUnloadModule", module ); +// } +// +// ULONG onChangeSessionStatus( ULONG status ) { +// return handler( "onChangeSessionStatus", status ); +// } +// +// ULONG onChangeDebugeeState() { +// return handler( "onChangeDebugeeState" ); +// } +// +//private: +// +// template +// 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; // } //}; // /////////////////////////////////////////////////////////////////////////////////// + diff --git a/pykd/dbgeventcb.cpp b/pykd/dbgeventcb.cpp index d80112a..5f9c769 100644 --- a/pykd/dbgeventcb.cpp +++ b/pykd/dbgeventcb.cpp @@ -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 ); -} - -/////////////////////////////////////////////////////////////////////////////////// -// -//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; -//} +//#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::UnloadModule( -// __in PCSTR ImageBaseName, -// __in ULONG64 BaseOffset -//) +//DbgEventCallbacksManager::DbgEventCallbacksManager( IDebugClient *client ) //{ -// 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& ) -// { -// } +// 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 ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +//// +////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; +////} +//// +/////////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgeventcb.h b/pykd/dbgeventcb.h index 3ed5e1c..9dd194f 100644 --- a/pykd/dbgeventcb.h +++ b/pykd/dbgeventcb.h @@ -1,64 +1,64 @@ #pragma once -#include - -////////////////////////////////////////////////////////////////////////////// - -// 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; -}; - -////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +//////////////////////////////////////////////////////////////////////////////// +// +//// 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; +//}; +// +//////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgexcept.cpp b/pykd/dbgexcept.cpp index cb1b63e..35cfeb3 100644 --- a/pykd/dbgexcept.cpp +++ b/pykd/dbgexcept.cpp @@ -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()); -} - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#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()); +//} +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgexcept.h b/pykd/dbgexcept.h index a7b873c..da906a2 100644 --- a/pykd/dbgexcept.h +++ b/pykd/dbgexcept.h @@ -1,131 +1,131 @@ #pragma once -#include -#include - -///////////////////////////////////////////////////////////////////////////////// - -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; - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +//#include +// +/////////////////////////////////////////////////////////////////////////////////// +// +//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; +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 26befd6..99f5ecf 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -1,710 +1,8 @@ #include "stdafx.h" -#include +#include -#include - -#include -#include -#include -#include - -#include "dbgext.h" -#include "dbgreg.h" -#include "dbgtype.h" -#include "dbgmodule.h" -#include "dbgsym.h" -#include "dbgmem.h" -#include "dbgsystem.h" -#include "dbgcmd.h" -#include "dbgdump.h" -#include "dbgexcept.h" -#include "dbgeventcb.h" -#include "dbgpath.h" -#include "dbgprocess.h" -#include "dbgsynsym.h" -#include "dbgclient.h" -#include "dbgevent.h" -#include "dbgbreak.h" -#include "dbgio.h" -#include "intbase.h" -#include "disasm.h" - -////////////////////////////////////////////////////////////////////////////// - -// указатель на текущий интерфейс -DbgExt *dbgExt = NULL; - -// глобальный клиент -dbgClient g_dbgClient; - -// контескт исполнения нити питона -__declspec( thread ) PyThreadStatePtr ptrPyThreadState = NULL; - -////////////////////////////////////////////////////////////////////////////// - -BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, dbgPrint::dprint, 1, 2 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, dbgPrint::dprintln, 1, 2 ) - -BOOST_PYTHON_FUNCTION_OVERLOADS( loadCharsOv, loadChars, 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadWCharsOv, loadWChars, 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes, loadArray, 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords, loadArray, 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords, loadArray, 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords, loadArray , 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes, loadArray , 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords, loadArray , 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords, loadArray , 2, 3 ) -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords, loadArray<__int64>, 2, 3 ) - -BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemoryOver, compareMemory, 3, 4 ) - -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( appendOver, TypeInfo::appendField, 2, 3 ) -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( loadOver, TypeInfo::loadVar, 1, 2 ) - - -#define DEF_PY_CONST(x) \ - boost::python::scope().attr(#x) = ##x - -#define DEF_PY_GLOBAL(x,y) \ - boost::python::scope().attr(x) = ##y - - -BOOST_PYTHON_MODULE( pykd ) -{ - boost::python::def( "go", &setExecutionStatus, - "Change debugger status to DEBUG_STATUS_GO" ); - boost::python::def( "trace", &setExecutionStatus, - "Change debugger status to DEBUG_STATUS_STEP_INTO" ); - boost::python::def( "step", &setExecutionStatus, - "Change debugger status to DEBUG_STATUS_STEP_OVER" ); - boost::python::def( "breakin", &breakin, - "Break into debugger" ); - boost::python::def( "expr", &evaluate, - "Evaluate windbg expression" ); - boost::python::def( "isWindbgExt", &isWindbgExt, - "Check if script works in windbg context" ); - boost::python::def( "symbolsPath", &dbgSymPath, - "Return symbol path" ); - boost::python::def( "dprint", &dbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), - "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )") ); - boost::python::def( "dprintln", &dbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), - "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); - boost::python::def( "loadDump", &dbgLoadDump, - "Load crash dump (only for console)"); - boost::python::def( "startProcess", &startProcess, - "Start process for debugging (only for console)"); - boost::python::def( "attachProcess", &attachProcess, - "Attach debugger to a exsisting process" ); - boost::python::def( "attachKernel", &attachKernel, - "Attach debugger to a kernel target" ); - boost::python::def( "dbgCommand", &dbgCommand, - "Execute debugger command. For example: dbgCommand( \"lmvm nt\" )" ); - boost::python::def( "isValid", &isOffsetValid, - "Check if virtual address is valid" ); - boost::python::def( "is64bitSystem", &is64bitSystem, - "Check if target system has 64 address space" ); - boost::python::def( "isKernelDebugging", &isKernelDebugging, - "Check if kernel dubugging is running" ); - boost::python::def( "isDumpAnalyzing", &isDumpAnalyzing, - "Check if it is a dump analyzing ( not living debuggee )" ); - boost::python::def( "ptrSize", ptrSize, - "Return pointer size ( in bytes )" ); - boost::python::def( "reg", &loadRegister, - "Return CPU's register value" ); - boost::python::def( "rdmsr", &loadMSR, - "Return MSR value" ); - boost::python::def( "wrmsr", &setMSR, - "Set MSR value" ); - boost::python::def( "typedVarList", &loadTypedVarList, - "Return list of typedVarClass instances. Each item represents one item of the linked list in the target memory" ); - boost::python::def( "typedVarArray", &loadTypedVarArray, - "Return list of typedVarClass instances. Each item represents one item of the counted array the target memory" ); - boost::python::def( "containingRecord", &containingRecord, - "Return instance of the typedVarClass. It's value are loaded from the target memory." - "The start address is calculated by the same method as standard macro CONTAINING_RECORD" ); - boost::python::def( "sizeof", &sizeofType, - "Return size of type" ); - boost::python::def( "loadModule", &loadModule, - "Return instance of the dbgModuleClass" ); - boost::python::def( "findSymbol", &findSymbolForAddress, - "Return symbol for specified target address if it exists" ); - boost::python::def( "getOffset", &findAddressForSymbol, - "Return target address for specified symbol" ); - boost::python::def( "findModule", &findModule, - "Return instance of the dbgModuleClass which posseses specified address" ); - boost::python::def( "addr64", &addr64, - "Extend address to 64 bits formats ( for x86 )" ); - boost::python::def( "loadChars", loadChars, loadCharsOv( boost::python::args( "address", "number", "phyAddr" ), - "Load string from the target buffer" ) ); - boost::python::def( "loadWChars", loadWChars, loadWCharsOv( boost::python::args( "address", "number", "phyAddr" ), - "Load unicode string from the target buffer" ) ); - boost::python::def( "loadBytes", &loadArray, loadBytes( boost::python::args( "address", "number", "phyAddr" ), - "Return list of unsigned bytes" ) ); - boost::python::def( "loadWords", &loadArray, loadWords( boost::python::args( "address", "number", "phyAddr" ), - "Return list of unsigned words (2-bytes )" ) ); - boost::python::def( "loadDWords", &loadArray, loadDWords( boost::python::args( "address", "number", "phyAddr" ), - "Return list of unsigned dwords (4-bytes)" ) ); - boost::python::def( "loadQWords", &loadArray, loadQWords( boost::python::args( "address", "number", "phyAddr" ), - "Return list of unsigned qwords (8-butes)" ) ); - boost::python::def( "loadSignBytes", &loadArray, loadSignBytes( boost::python::args( "address", "number", "phyAddr" ), - "Return list of signed bytes" ) ); - boost::python::def( "loadSignWords", &loadArray, loadSignWords( boost::python::args( "address", "number", "phyAddr" ), - "Return list of signed words (2-bytes)" ) ); - boost::python::def( "loadSignDWords", &loadArray, loadSignDWords( boost::python::args( "address", "number", "phyAddr" ), - "Return list of signed dwords (4-bytes)" ) ); - boost::python::def( "loadSignQWords", &loadArray<__int64>, loadSignQWords( boost::python::args( "address", "number", "phyAddr" ), - "Return list of signed qwords (8-bytes)" ) ); - boost::python::def( "loadPtrs", &loadPtrArray, - "Return list of pointers" ); - boost::python::def( "loadUnicodeString", &loadUnicodeStr, - "Return string represention of windows UNICODE_STRING type" ); - boost::python::def( "loadAnsiString", &loadAnsiStr, - "Return string represention of windows ANSU_STRING type" ); - boost::python::def( "loadCStr", &loadCStr, - "Load string from the target buffer containing 0-terminated ansi-string" ); - boost::python::def( "loadWStr", &loadWStr, - "Load string from the target buffer containing 0-terminated unicode-string" ); - boost::python::def( "loadLinkedList", &loadLinkedList, - "Return list of instances of the typedVarClass loaded from linked list in the target memory" ); - boost::python::def( "ptrByte", &loadByPtr, - "Return 1-byte unsigned value loaded by pointer" ); - boost::python::def( "ptrSignByte", &loadByPtr, - "Return 1-byte signed value loaded by pointer" ); - boost::python::def( "ptrWord", &loadByPtr, - "Return 2-byte unsigned value loaded by pointer" ); - boost::python::def( "ptrSignWord", &loadByPtr, - "Return 2-byte signed value loaded by pointer" ); - boost::python::def( "ptrDWord", &loadByPtr, - "Return 4-byte unsigned value loaded by pointer" ); - boost::python::def( "ptrSignDWord", &loadByPtr, - "Return 4-byte signed value loaded by pointer" ); - boost::python::def( "ptrQWord", &loadByPtr, - "Return 8-byte unsigned value loaded by pointer" ); - boost::python::def( "ptrSignQWord", &loadByPtr<__int64>, - "Return 8-byte signed value loaded by pointer" ); - boost::python::def( "ptrPtr", &loadPtrByPtr, - "Return pointer value loaded by pointer" ); - boost::python::def( "ptrMWord", &loadMWord, - "Return unsigned machine word ( 4-bytes for x86 and 8-bytes for x64 ) loaded by pointer" ); - boost::python::def( "ptrSignMWord", &loadSignMWord, - "Return signed machine word ( 4-bytes for x86 and 8-bytes for x64 ) loaded by pointer" ); - boost::python::def( "compareMemory", &compareMemory, compareMemoryOver( boost::python::args( "addr1", "addr2", "length", "phyAddr" ), - "Compare two memory buffers by virtual or physical addresses" ) ); - boost::python::def( "getCurrentStack", &getCurrentStack, - "Return list of dbgStackFrameClass for current stack" ); - boost::python::def( "locals", &getLocals, - "Return dict of locals variables (each item is typedVarClass)" ); - boost::python::def( "reloadModule", &reloadModule, - "Reload symbols by module name" ); - boost::python::def( "getPdbFile", &getPdbFile, - "Return full path to PDB (Program DataBase, debug information) file" ); - boost::python::def( "getImplicitThread", &getImplicitThread, - "Return implicit thread for current process" ); - boost::python::def( "setImplicitThread", &setImplicitThread, - "Set implicit thread for current process" ); - boost::python::def( "getThreadList", &getThreadList, - "Return list of threads (each item is numeric address of thread)" ); - boost::python::def( "getCurrentProcess", &getCurrentProcess, - "Return current process (numeric address)" ); - boost::python::def( "setCurrentProcess", &setCurrentProcess, - "Set current process by address" ); - boost::python::def( "getProcessorMode", &getProcessorMode, - "Return current processor mode as string: X86, ARM, IA64 or X64" ); - boost::python::def( "setProcessorMode", &setProcessorMode, - "Set current processor mode by string (X86, ARM, IA64 or X64)" ); - boost::python::def( "addSynSymbol", &addSyntheticSymbol, - "Add new synthetic symbol for virtual address" ); - boost::python::def( "delAllSynSymbols", &delAllSyntheticSymbols, - "Delete all synthetic symbol for all modules"); - boost::python::def( "delSynSymbol", &delSyntheticSymbol, - "Delete synthetic symbols by virtual address" ); - boost::python::def( "delSynSymbolsMask", &delSyntheticSymbolsMask, - "Delete synthetic symbols by mask of module and symbol name"); - - - boost::python::class_( "typeInfo", - "Class representing non-primitive type info: structure, union, etc. attributes is a fields of non-primitive type" ) - .def(boost::python::init( boost::python::args("module", "type"), "constructor" ) ) - .def(boost::python::init( boost::python::args("typeName"), "constructor" ) ) - .def(boost::python::init( boost::python::args("typeName", "align"), "constructor" ) ) - .def("size", &TypeInfo::size, - "Return full size of non-primitive type" ) - .def("name", &TypeInfo::name, - "Return type's name" ) - .def("__str__", &TypeInfo::print, - "Return a nice string represention: print names and offsets of fields" ) - .def("__getattr__", &TypeInfo::getField ) - .def("__len__", &TypeInfo::getFieldCount ) - .def("__getitem__", &TypeInfo::getFieldByIndex ) - .def("append", &TypeInfo::appendField, appendOver( boost::python::args("type", "fieldName", "count"), - "add new field for typeInfo" ) ) - .def("offset", &TypeInfo::getFieldOffset, - "Return offset while type is part of the more complex type" ) - .def("setAlignReq", &TypeInfo::setAlignReq, - "Set alignment requirement" ) - .def("load", &TypeInfo::loadVar, loadOver( boost::python::args( "offset", "count"), - "Create instance of the typedVar class with this typeInfo" ) ); - - DEF_PY_GLOBAL( "char_t", TypeInfo("", "char") ); - DEF_PY_GLOBAL( "uchar_t", TypeInfo("", "unsigned char") ); - DEF_PY_GLOBAL( "short_t", TypeInfo("", "short") ); - DEF_PY_GLOBAL( "ushort_t", TypeInfo("", "unsigned short") ); - DEF_PY_GLOBAL( "long_t", TypeInfo("", "long") ); - DEF_PY_GLOBAL( "ulong_t", TypeInfo("", "unsigned long") ); - DEF_PY_GLOBAL( "int_t", TypeInfo("", "int") ); - DEF_PY_GLOBAL( "uint_t", TypeInfo("", "unsigned int") ); - DEF_PY_GLOBAL( "ptr_t", TypeInfo("", "void*") ); - DEF_PY_GLOBAL( "double_t", TypeInfo("", "double") ); - DEF_PY_GLOBAL( "longlong_t", TypeInfo("", "int64") ); - DEF_PY_GLOBAL( "ulonglong_t", TypeInfo("", "unsigned int64") ); - - boost::python::class_( "typedVar", - "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance" ) - .def(boost::python::init(boost::python::args("typeInfo", "address"), - "constructor" ) ) - .def(boost::python::init(boost::python::args("moduleName", "typeName", "address"), - "constructor" ) ) - .def(boost::python::init(boost::python::args("address"), - "constructor" ) ) - .def(boost::python::init(boost::python::args("symbolName"), - "constructor" ) ) - .def("getAddress", &TypedVar::getAddress, - "Return virtual address" ) - .def("sizeof", &TypedVar::getSize, - "Return size of a variable in the target memory" ) - .def("data", &TypedVar::data, - "Return raw string object with data stream" ) - .def("__getattr__", &TypedVar::getFieldWrap, - "Return field of structure as an object attribute" ) - .def("__str__", &TypedVar::print, - "Return a nice string represention: print names and offsets of fields" ); - - boost::python::class_( "dbgModuleClass", - "Class representing module in the target memory" ) - .def("begin", &dbgModuleClass::getBegin, - "Return start address of the module" ) - .def("end", &dbgModuleClass::getEnd, - "Return end address of the module" ) - .def("size", &dbgModuleClass::getSize, - "Return size of the module" ) - .def("name", &dbgModuleClass::getName, - "Return name of the module" ) - .def("contain", &dbgModuleClass::contain, - "Check if the address belongs to the module") - .def("image", &dbgModuleClass::getImageSymbolName, - "Return the full path to the module's image file" ) - .def("pdb", &dbgModuleClass::getPdbName, - "Return the full path to the module's pdb file ( symbol information )" ) - .def("checksum", &dbgModuleClass::getCheckSum, - "Return checksum of the module ( from PE header )" ) - .def("timestamp", &dbgModuleClass::getTimeStamp, - "Return timestamp of the module ( from PE header )" ) - .def("addSynSymbol", &dbgModuleClass::addSyntheticSymbol, - "Add synthetic symbol for the module" ) - .def("delAllSynSymbols", &dbgModuleClass::delAllSyntheticSymbols, - "Remove all synthetic symbols for the module" ) - .def("delSynSymbol", &dbgModuleClass::delSyntheticSymbol, - "Remove specified synthetic symbol for the module" ) - .def("delSynSymbolsMask", &dbgModuleClass::delSyntheticSymbolsMask ) - .def("__getattr__", &dbgModuleClass::getOffset, - "Return address of the symbol" ) - .def("__str__", &dbgModuleClass::print, - "Return a nice string represention of the dbgModuleClass" ); - - boost::python::class_( - "ext", - "windbg extension wrapper", - boost::python::init( boost::python::args("path"), "__init__ dbgExtensionClass" ) ) - .def("call", &dbgExtensionClass::call, - "Call extension command" ) - .def("__str__", &dbgExtensionClass::print, - "Return a nice string represention of the dbgExtensionClass" ); - - boost::python::class_( "dbgStackFrameClass", - "Class representing a frame of the call satck" ) - .def_readonly( "instructionOffset", &dbgStackFrameClass::InstructionOffset, - "Return a frame's instruction offset" ) - .def_readonly( "returnOffset", &dbgStackFrameClass::ReturnOffset, - "Return a frame's return offset" ) - .def_readonly( "frameOffset", &dbgStackFrameClass::FrameOffset, - "Return a frame's offset" ) - .def_readonly( "stackOffset", &dbgStackFrameClass::StackOffset, - "Return a frame's stack offset" ) - .def_readonly( "frameNumber", &dbgStackFrameClass::FrameNumber, - "Return a frame's number" ) - .def( "__str__", &dbgStackFrameClass::print, - "Return a nice string represention of the dbgStackFrameClass" ); - - boost::python::class_( "windbgOut", "windbgOut" ) - .def( "write", &dbgOut::write ); - - boost::python::class_( "windbgIn", "windbgIn" ) - .def( "readline", &dbgIn::readline ); - - boost::python::class_( "bp", - "Class representing breakpoint", - boost::python::init( boost::python::args("offset", "callback"), - "Break point: user callback" ) ) - .def( boost::python::init< ULONG64 >( boost::python::args("offset"), - "Break point constructor: always break" ) ) - .def( "set", &dbgBreakpointClass::set, - "Set a breakpoint at the specified address" ) - .def( "remove", &dbgBreakpointClass::remove, - "Remove a breakpoint set before" ) - .def( "__str__", &dbgBreakpointClass::print, - "Return a nice string represention of the breakpoint class" ); - - boost::python::class_( "debugEvent", - "Base class for debug events handlers" ) - .def( "onBreakpoint", &debugEventWrap::onBreakpoint, - "Triggered breakpoint event. Parameter is dict:\n" - "{\"Id\":int, \"BreakType\":int, \"ProcType\":int, \"Flags\":int, \"Offset\":int," - " \"Size\":int, \"AccessType\":int, \"PassCount\":int, \"CurrentPassCount\":int," - " \"MatchThreadId\":int, \"Command\":str, \"OffsetExpression\":str}\n" - "Detailed information: http://msdn.microsoft.com/en-us/library/ff539284(VS.85).aspx \n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onException", &debugEventWrap::onException, - "Exception event. Parameter is dict:\n" - "{\"Code\":int, \"Flags\":int, \"Record\":int, \"Address\":int," - " \"Parameters\":[int], \"FirstChance\":bool}\n" - "Detailed information: http://msdn.microsoft.com/en-us/library/aa363082(VS.85).aspx \n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onLoadModule", &debugEventWrap::onLoadModule, - "Load module event. Parameter is instance of dbgModuleClass.\n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onUnloadModule", &debugEventWrap::onUnloadModule, - "Unload module event. Parameter is instance of dbgModuleClass.\n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); - - boost::python::class_("disasm", "Class disassemble a processor instructions", boost::python::no_init ) - .def( boost::python::init<>( "constructor" ) ) - .def( boost::python::init( boost::python::args("offset"), "constructor" ) ) - .def( "next", &disasm::next, "Disassemble next instruction" ) - .def( "begin", &disasm::begin, "Return begin offset" ) - .def( "current", &disasm::current, "Return current offset" ) - .def( "length", &disasm::length, "Return current instruction length" ) - .def( "instruction", &disasm::instruction, "Returm current disassembled instruction" ) - .def( "ea", &disasm::ea, "Return effective address for last disassembled instruction or 0" ); - - - // исключения - boost::python::class_ dbgExceptionClass( "BaseException", - "Pykd base exception class", - boost::python::no_init ); - //boost::python::init() ); - - dbgExceptionClass - .def( boost::python::init( boost::python::args("desc"), "constructor" ) ) - .def( "desc", &DbgException::getDesc, - "Get exception description" ); - - boost::python::class_ > waitExceptionClass( "WaitEventException", - "Type exception class", - boost::python::no_init ); - - boost::python::class_ > typeExceptionClass( "TypeException", - "Type exception class", - boost::python::no_init ); - - boost::python::class_ > memoryExceptionClass( "MemoryException", - "Memory exception class", - boost::python::no_init ); - - memoryExceptionClass - .def( boost::python::init( boost::python::args("targetAddress"), "constructor" ) ) - .def( "getAddress", &MemoryException::getAddress, - "Return target address" ); - - baseExceptionType = dbgExceptionClass.ptr(); - eventExceptionType = waitExceptionClass.ptr(); - typeExceptionType = typeExceptionClass.ptr(); - memoryExceptionType = memoryExceptionClass.ptr(); - - boost::python::register_exception_translator( &DbgException::exceptionTranslate ); - boost::python::register_exception_translator( &WaitEventException::exceptionTranslate ); - boost::python::register_exception_translator( &TypeException::exceptionTranslate ); - boost::python::register_exception_translator( &IndexException::translate); - boost::python::register_exception_translator( &MemoryException::translate ); - - boost::python::class_( - "intBase", - "intBase") - .def( boost::python::init<>() ) - .def( boost::python::init( boost::python::args("value"), "constructor" ) ) - - .def( "value", &intBase::value ) - .def( int_( boost::python::self ) ) - //.def( boost::python::self = long() ) - - .def( boost::python::self + long() ) - .def( long() + boost::python::self ) - .def( boost::python::self += long() ) - .def( boost::python::self + boost::python::self ) - .def( boost::python::self += boost::python::self ) - - .def( boost::python::self - long() ) - .def( long() - boost::python::self ) - .def( boost::python::self -= long() ) - .def( boost::python::self - boost::python::self ) - .def( boost::python::self -= boost::python::self ) - - .def( boost::python::self * long() ) - .def( long() * boost::python::self ) - .def( boost::python::self *= long() ) - .def( boost::python::self * boost::python::self ) - .def( boost::python::self *= boost::python::self ) - - .def( boost::python::self / long() ) - .def( long() / boost::python::self ) - .def( boost::python::self /= long() ) - .def( boost::python::self / boost::python::self ) - .def( boost::python::self /= boost::python::self ) - - .def( boost::python::self % long() ) - .def( long() % boost::python::self ) - .def( boost::python::self %= long() ) - .def( boost::python::self % boost::python::self ) - .def( boost::python::self %= boost::python::self ) - - .def( boost::python::self & long() ) - .def( long() & boost::python::self ) - .def( boost::python::self &= long() ) - .def( boost::python::self & boost::python::self ) - .def( boost::python::self &= boost::python::self ) - - .def( boost::python::self | long() ) - .def( long() | boost::python::self ) - .def( boost::python::self |= long() ) - .def( boost::python::self | boost::python::self ) - .def( boost::python::self |= boost::python::self ) - - .def( boost::python::self ^ long() ) - .def( long() ^ boost::python::self ) - .def( boost::python::self ^= long() ) - .def( boost::python::self ^ boost::python::self ) - .def( boost::python::self ^= boost::python::self ) - - .def( boost::python::self << long() ) - .def( boost::python::self <<= long() ) - - .def( boost::python::self >> long() ) - .def( boost::python::self >>= long() ) - - .def( boost::python::self < long() ) - .def( boost::python::self < boost::python::self ) - - .def( boost::python::self <= long() ) - .def( boost::python::self <= boost::python::self ) - - .def( boost::python::self == long() ) - .def( boost::python::self == boost::python::self ) - - .def( boost::python::self >= long() ) - .def( boost::python::self >= boost::python::self ) - - .def( boost::python::self > long() ) - .def( boost::python::self > boost::python::self ) - - .def( boost::python::self != long() ) - .def( boost::python::self != boost::python::self ) - - .def( ~boost::python::self ) - .def( !boost::python::self ) - - .def( "__str__", &intBase::str ) - .def( "__hex__", &intBase::hex ); - - boost::python::class_ >( - "cpuReg", - "CPU regsiter class", - boost::python::no_init ) - .def( boost::python::init(boost::python::args("name"), "constructor" ) ) - .def( boost::python::init(boost::python::args("index"), "constructor" ) ) - .def( "name", &cpuReg::name, "The name of the regsiter" ) - .def( "index", &cpuReg::index, "The index of thr register" ) - .def( "beLive", &cpuReg::beLive, "Turn the object to live: its value will be following the target register value" ); - - - // debug status - DEF_PY_CONST(DEBUG_STATUS_NO_CHANGE); - DEF_PY_CONST(DEBUG_STATUS_GO); - DEF_PY_CONST(DEBUG_STATUS_GO_HANDLED); - DEF_PY_CONST(DEBUG_STATUS_GO_NOT_HANDLED); - DEF_PY_CONST(DEBUG_STATUS_STEP_OVER); - DEF_PY_CONST(DEBUG_STATUS_STEP_INTO); - DEF_PY_CONST(DEBUG_STATUS_BREAK); - DEF_PY_CONST(DEBUG_STATUS_NO_DEBUGGEE); - DEF_PY_CONST(DEBUG_STATUS_STEP_BRANCH); - DEF_PY_CONST(DEBUG_STATUS_IGNORE_EVENT); - DEF_PY_CONST(DEBUG_STATUS_RESTART_REQUESTED); - DEF_PY_CONST(DEBUG_STATUS_REVERSE_GO); - DEF_PY_CONST(DEBUG_STATUS_REVERSE_STEP_BRANCH); - DEF_PY_CONST(DEBUG_STATUS_REVERSE_STEP_OVER); - DEF_PY_CONST(DEBUG_STATUS_REVERSE_STEP_INTO); - - // debug status additional mask - DEF_PY_CONST(DEBUG_STATUS_INSIDE_WAIT); - DEF_PY_CONST(DEBUG_STATUS_WAIT_TIMEOUT); - - // break point type - DEF_PY_CONST(DEBUG_BREAKPOINT_CODE); - DEF_PY_CONST(DEBUG_BREAKPOINT_DATA); - DEF_PY_CONST(DEBUG_BREAKPOINT_TIME); - - // break point flag - DEF_PY_CONST(DEBUG_BREAKPOINT_GO_ONLY); - DEF_PY_CONST(DEBUG_BREAKPOINT_DEFERRED); - DEF_PY_CONST(DEBUG_BREAKPOINT_ENABLED); - DEF_PY_CONST(DEBUG_BREAKPOINT_ADDER_ONLY); - DEF_PY_CONST(DEBUG_BREAKPOINT_ONE_SHOT); - - // break point access type - DEF_PY_CONST(DEBUG_BREAK_READ); - DEF_PY_CONST(DEBUG_BREAK_WRITE); - DEF_PY_CONST(DEBUG_BREAK_EXECUTE); - DEF_PY_CONST(DEBUG_BREAK_IO); - - // exception flags - DEF_PY_CONST(EXCEPTION_NONCONTINUABLE); - - // debug events - DEF_PY_CONST(DEBUG_EVENT_BREAKPOINT); - DEF_PY_CONST(DEBUG_EVENT_EXCEPTION); - DEF_PY_CONST(DEBUG_EVENT_CREATE_THREAD); - DEF_PY_CONST(DEBUG_EVENT_EXIT_THREAD); - DEF_PY_CONST(DEBUG_EVENT_CREATE_PROCESS); - DEF_PY_CONST(DEBUG_EVENT_EXIT_PROCESS); - DEF_PY_CONST(DEBUG_EVENT_LOAD_MODULE); - DEF_PY_CONST(DEBUG_EVENT_UNLOAD_MODULE); - DEF_PY_CONST(DEBUG_EVENT_SYSTEM_ERROR); - DEF_PY_CONST(DEBUG_EVENT_SESSION_STATUS); - DEF_PY_CONST(DEBUG_EVENT_CHANGE_DEBUGGEE_STATE); - DEF_PY_CONST(DEBUG_EVENT_CHANGE_ENGINE_STATE); - DEF_PY_CONST(DEBUG_EVENT_CHANGE_SYMBOL_STATE); - - // debugger type - //_DEF_PY_CONST(DEBUG_CLASS_UNINITIALIZED); - //_DEF_PY_CONST(DEBUG_CLASS_KERNEL); - //_DEF_PY_CONST(DEBUG_CLASS_USER_WINDOWS); - //_DEF_PY_CONST(DEBUG_CLASS_IMAGE_FILE); - // - //_DEF_PY_CONST(DEBUG_KERNEL_CONNECTION); - //_DEF_PY_CONST(DEBUG_KERNEL_LOCAL); - //_DEF_PY_CONST(DEBUG_KERNEL_EXDI_DRIVER); - //_DEF_PY_CONST(DEBUG_KERNEL_IDNA); - //_DEF_PY_CONST(DEBUG_KERNEL_SMALL_DUMP); - //_DEF_PY_CONST(DEBUG_KERNEL_DUMP); - //_DEF_PY_CONST(DEBUG_KERNEL_FULL_DUMP); - - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_PROCESS); - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_PROCESS_SERVER); - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_IDNA); - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_SMALL_DUMP); - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_SMALL_DUMP); - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_DUMP); - //_DEF_PY_CONST(DEBUG_USER_WINDOWS_DUMP_WINDOWS_CE); -} - -#undef _DEF_PY_CONST - -///////////////////////////////////////////////////////////////////////////////// - -class WindbgGlobalSession -{ -public: - - static - boost::python::object - global() { - return windbgGlobalSession->main.attr("__dict__"); - } - - static - VOID - StartWindbgSession() { - if ( 1 == InterlockedIncrement( &sessionCount ) ) - { - windbgGlobalSession = new WindbgGlobalSession(); - } - } - - static - VOID - StopWindbgSession() { - if ( 0 == InterlockedDecrement( &sessionCount ) ) - { - delete windbgGlobalSession; - windbgGlobalSession = NULL; - } - } - - static - bool isInit() { - return windbgGlobalSession != NULL; - } - - -private: - - WindbgGlobalSession() { - - PyImport_AppendInittab("pykd", initpykd ); - - Py_Initialize(); - - main = boost::python::import("__main__"); - - boost::python::object main_namespace = main.attr("__dict__"); - - - // делаем аналог from pykd import * - boost::python::object pykd = boost::python::import( "pykd" ); - - boost::python::dict pykd_namespace( pykd.attr("__dict__") ); - - boost::python::list iterkeys( pykd_namespace.iterkeys() ); - - for (int i = 0; i < boost::python::len(iterkeys); i++) - { - std::string key = boost::python::extract(iterkeys[i]); - - main_namespace[ key ] = pykd_namespace[ key ]; - } - - //// перенаправление стандартных потоков ВВ - //boost::python::object sys = boost::python::import( "sys"); - // - //dbgOut dout; - //sys.attr("stdout") = boost::python::object( dout ); - - //dbgIn din; - //sys.attr("stdin") = boost::python::object( din ); - // - g_dbgClient.startEventsMgr(); - } - - ~WindbgGlobalSession() { - Py_Finalize(); - g_dbgClient.removeEventsMgr(); - } - - boost::python::object main; - - static volatile LONG sessionCount; - - static WindbgGlobalSession *windbgGlobalSession; -}; - -volatile LONG WindbgGlobalSession::sessionCount = 0; - -WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL; - -bool isWindbgExt() { - return WindbgGlobalSession::isInit(); -} - -///////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// HRESULT CALLBACK @@ -714,402 +12,1165 @@ DebugExtensionInitialize( { *Version = DEBUG_EXTENSION_VERSION( 1, 0 ); *Flags = 0; - - WindbgGlobalSession::StartWindbgSession(); return S_OK; } +//////////////////////////////////////////////////////////////////////////////// VOID CALLBACK DebugExtensionUninitialize() { - WindbgGlobalSession::StopWindbgSession(); } -DbgExt::DbgExt( IDebugClient4 *masterClient ) -{ - client = NULL; - masterClient->QueryInterface( __uuidof(IDebugClient), (void **)&client ); - - client4 = NULL; - masterClient->QueryInterface( __uuidof(IDebugClient4), (void **)&client4 ); - - client5 = NULL; - masterClient->QueryInterface( __uuidof(IDebugClient5), (void **)&client5 ); - - control = NULL; - masterClient->QueryInterface( __uuidof(IDebugControl), (void **)&control ); - - control4 = NULL; - masterClient->QueryInterface( __uuidof(IDebugControl4), (void **)&control4 ); - - registers = NULL; - masterClient->QueryInterface( __uuidof(IDebugRegisters), (void **)®isters ); - - symbols = NULL; - masterClient->QueryInterface( __uuidof(IDebugSymbols), (void ** )&symbols ); - - symbols2 = NULL; - masterClient->QueryInterface( __uuidof(IDebugSymbols2), (void ** )&symbols2 ); - - symbols3 = NULL; - masterClient->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&symbols3 ); - - dataSpaces = NULL; - masterClient->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dataSpaces ); - - dataSpaces4 = NULL; - masterClient->QueryInterface( __uuidof(IDebugDataSpaces4), (void **)&dataSpaces4 ); - - advanced2 = NULL; - masterClient->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&advanced2 ); - - system = NULL; - masterClient->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&system ); - - system2 = NULL; - masterClient->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&system2 ); +//////////////////////////////////////////////////////////////////////////////// - m_previosExt = dbgExt; - dbgExt = this; -} - -DbgExt::~DbgExt() -{ - BOOST_ASSERT(dbgExt == this); - dbgExt = m_previosExt; - - if ( client ) - client->Release(); - - if ( client4 ) - client4->Release(); - - if ( client5 ) - client5->Release(); - - if ( control ) - control->Release(); - - if ( control4 ) - control4->Release(); - - if ( registers ) - registers->Release(); - - if ( symbols ) - symbols->Release(); - - if ( symbols2 ) - symbols2->Release(); - - if ( symbols3 ) - symbols3->Release(); - - if ( dataSpaces ) - dataSpaces->Release(); - - if ( dataSpaces4 ) - dataSpaces4->Release(); - - if ( advanced2 ) - advanced2->Release(); - - if ( system ) - system->Release(); - - if ( system2 ) - system2->Release(); -} - -///////////////////////////////////////////////////////////////////////////////// - HRESULT CALLBACK -py( PDEBUG_CLIENT4 client, PCSTR args) +py( PDEBUG_CLIENT4 client, PCSTR args ) { - DbgExt ext( client ); - - PyThreadState *globalInterpreter = PyThreadState_Swap( NULL ); - PyThreadState *localInterpreter = Py_NewInterpreter(); - - try { - - boost::python::import( "pykd" ); - - boost::python::object main = boost::python::import("__main__"); - - boost::python::object global(main.attr("__dict__")); - - // перенаправление стандартных потоков ВВ - boost::python::object sys = boost::python::import("sys"); - - boost::python::object tracebackModule = boost::python::import("traceback"); - - dbgOut dout; - sys.attr("stdout") = boost::python::object( dout ); - - dbgIn din; - sys.attr("stdin") = boost::python::object( din ); - - // разбор параметров - typedef boost::escaped_list_separator char_separator_t; - typedef boost::tokenizer< char_separator_t > char_tokenizer_t; - - std::string argsStr( args ); - - char_tokenizer_t token( argsStr , char_separator_t( "", " \t", "\"" ) ); - std::vector argsList; - - for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it ) - { - if ( *it != "" ) - argsList.push_back( *it ); - } - - if ( argsList.size() == 0 ) - return S_OK; - - char **pythonArgs = new char* [ argsList.size() ]; - - for ( size_t i = 0; i < argsList.size(); ++i ) - pythonArgs[i] = const_cast( argsList[i].c_str() ); - - PySys_SetArgv( (int)argsList.size(), pythonArgs ); - - delete[] pythonArgs; - - - // найти путь к файлу - std::string fullFileName; - std::string filePath; - DbgPythonPath dbgPythonPath; - - - if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) ) - { - try { - - boost::python::object result; - - result = boost::python::exec_file( fullFileName.c_str(), global, global ); - } - catch( boost::python::error_already_set const & ) - { - // ошибка в скрипте - PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL; - - PyErr_Fetch( &errtype, &errvalue, &traceback ); - - if(errvalue != NULL) - { - PyObject *errvalueStr= PyObject_Str(errvalue); - - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING( errvalueStr ) ); - - if ( traceback ) - { - boost::python::object traceObj( boost::python::handle<>( boost::python::borrowed( traceback ) ) ); - - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "\nTraceback:\n" ); - - boost::python::object pFunc( tracebackModule.attr("format_tb") ); - boost::python::list traceList( pFunc( traceObj ) ); - - for ( long i = 0; i < boost::python::len(traceList); ++i ) - { - std::string traceLine = boost::python::extract(traceList[i]); - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, traceLine.c_str() ); - } - } - - Py_DECREF(errvalueStr); - } - - Py_XDECREF(errvalue); - Py_XDECREF(errtype); - Py_XDECREF(traceback); - } - } - else - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "script file not found\n" ); - } - } - - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" ); - } - - Py_EndInterpreter( localInterpreter ); - PyThreadState_Swap( globalInterpreter ); - - return S_OK; + return S_OK; } -///////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// HRESULT CALLBACK pycmd( PDEBUG_CLIENT4 client, PCSTR args ) { - DbgExt ext( client ); - - try { - - // перенаправление стандартных потоков ВВ - boost::python::object sys = boost::python::import("sys"); - - dbgOut dout; - sys.attr("stdout") = boost::python::object( dout ); - - dbgIn din; - sys.attr("stdin") = boost::python::object( din ); - - boost::python::object syntaxError = boost::python::import("exceptions").attr("SyntaxError"); - - boost::python::object tracebackModule = boost::python::import("traceback"); - - std::string commandBuffer; - - bool commandCompleted = true; - - do { - - if ( commandCompleted ) - { - dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, ">>>" ); - } - else - { - dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, "..." ); - } - - { - char str[100]; - ULONG inputSize; - - OutputReader outputReader( (IDebugClient*)client ); - HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize ); - - if ( FAILED( hres ) ) - throw; - - if ( commandCompleted ) - { - if ( std::string( str ) == "" ) - break; - - commandBuffer = str; - } - else - { - if ( std::string( str ) == "" ) - commandCompleted = true; - else - { - commandBuffer.append("\n"); - commandBuffer.append( str ); - } - } - } - - if ( commandCompleted ) - { - try { - - boost::python::exec( commandBuffer.c_str(), WindbgGlobalSession::global(), WindbgGlobalSession::global() ); - - commandBuffer.clear(); - - } - catch( boost::python::error_already_set const & ) - { - PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL, *errvalueStr = NULL; - - PyErr_Fetch( &errtype, &errvalue, &traceback ); - - if ( errtype && errvalue ) - { - errvalueStr = PyObject_Str(errvalue); - - do { - - if ( PyErr_GivenExceptionMatches( syntaxError.ptr(), errtype ) ) - { - boost::python::tuple errValueObj( boost::python::handle<>( boost::python::borrowed(errvalue) ) ); - - if ( errValueObj[0] == "unexpected EOF while parsing" ) - { - commandCompleted = false; - break; - } - } - - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING(errvalueStr) ); - - if ( traceback ) - { - boost::python::object traceObj( boost::python::handle<>( boost::python::borrowed( traceback ) ) ); - - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "\nTraceback:\n" ); - - boost::python::object pFunc( tracebackModule.attr("format_tb") ); - boost::python::list traceList( pFunc( traceObj ) ); - - for ( long i = 0; i < boost::python::len(traceList); ++i ) - { - std::string traceLine = boost::python::extract(traceList[i]); - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, traceLine.c_str() ); - } - } - - } while( FALSE ); - - Py_XDECREF(errvalueStr); - Py_XDECREF(errvalue); - Py_XDECREF(errtype); - Py_XDECREF(traceback); - } - else - { - Py_XDECREF(errvalue); - Py_XDECREF(errtype); - Py_XDECREF(traceback); - - throw; - } - } - } - - } while( true ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" ); - } - - return S_OK; -} - -///////////////////////////////////////////////////////////////////////////////// - -HRESULT -CALLBACK -pythonpath( PDEBUG_CLIENT4 client, PCSTR args ) -{ - //DbgExt ext; - - //SetupDebugEngine( client, &ext ); - //dbgExt = &ext; - - ////DbgPrint::dprintln( dbgPythonPath.getStr() ); - return S_OK; } -///////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +HRESULT +CALLBACK +info( PDEBUG_CLIENT4 client, PCSTR args ) +{ + return S_OK; +} + +//////////////////////////////////////////////////////////////////////////////// + + + + + + + + + +//#include +// +//#include +// +//#include +//#include +//#include +//#include +// +//#include "dbgext.h" +//#include "dbgreg.h" +//#include "dbgtype.h" +//#include "dbgmodule.h" +//#include "dbgsym.h" +//#include "dbgmem.h" +//#include "dbgsystem.h" +//#include "dbgcmd.h" +//#include "dbgdump.h" +//#include "dbgexcept.h" +//#include "dbgeventcb.h" +//#include "dbgpath.h" +//#include "dbgprocess.h" +//#include "dbgsynsym.h" +//#include "dbgclient.h" +//#include "dbgevent.h" +//#include "dbgbreak.h" +//#include "dbgio.h" +//#include "intbase.h" +//#include "disasm.h" +// +//////////////////////////////////////////////////////////////////////////////// +// +//// указатель на текущий интерфейс +//DbgExt *dbgExt = NULL; +// +//// глобальный клиент +//dbgClient g_dbgClient; +// +//// контескт исполнения нити питона +//__declspec( thread ) PyThreadStatePtr ptrPyThreadState = NULL; +// +//////////////////////////////////////////////////////////////////////////////// +// +//BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, dbgPrint::dprint, 1, 2 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, dbgPrint::dprintln, 1, 2 ) +// +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadCharsOv, loadChars, 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadWCharsOv, loadWChars, 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes, loadArray, 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords, loadArray, 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords, loadArray, 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords, loadArray , 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes, loadArray , 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords, loadArray , 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords, loadArray , 2, 3 ) +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords, loadArray<__int64>, 2, 3 ) +// +//BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemoryOver, compareMemory, 3, 4 ) +// +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( appendOver, TypeInfo::appendField, 2, 3 ) +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( loadOver, TypeInfo::loadVar, 1, 2 ) +// +// +//#define DEF_PY_CONST(x) \ +// boost::python::scope().attr(#x) = ##x +// +//#define DEF_PY_GLOBAL(x,y) \ +// boost::python::scope().attr(x) = ##y +// +// +//BOOST_PYTHON_MODULE( pykd ) +//{ +// boost::python::def( "go", &setExecutionStatus, +// "Change debugger status to DEBUG_STATUS_GO" ); +// boost::python::def( "trace", &setExecutionStatus, +// "Change debugger status to DEBUG_STATUS_STEP_INTO" ); +// boost::python::def( "step", &setExecutionStatus, +// "Change debugger status to DEBUG_STATUS_STEP_OVER" ); +// boost::python::def( "breakin", &breakin, +// "Break into debugger" ); +// boost::python::def( "expr", &evaluate, +// "Evaluate windbg expression" ); +// boost::python::def( "isWindbgExt", &isWindbgExt, +// "Check if script works in windbg context" ); +// boost::python::def( "symbolsPath", &dbgSymPath, +// "Return symbol path" ); +// boost::python::def( "dprint", &dbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), +// "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )") ); +// boost::python::def( "dprintln", &dbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), +// "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); +// boost::python::def( "loadDump", &dbgLoadDump, +// "Load crash dump (only for console)"); +// boost::python::def( "startProcess", &startProcess, +// "Start process for debugging (only for console)"); +// boost::python::def( "attachProcess", &attachProcess, +// "Attach debugger to a exsisting process" ); +// boost::python::def( "attachKernel", &attachKernel, +// "Attach debugger to a kernel target" ); +// boost::python::def( "dbgCommand", &dbgCommand, +// "Execute debugger command. For example: dbgCommand( \"lmvm nt\" )" ); +// boost::python::def( "isValid", &isOffsetValid, +// "Check if virtual address is valid" ); +// boost::python::def( "is64bitSystem", &is64bitSystem, +// "Check if target system has 64 address space" ); +// boost::python::def( "isKernelDebugging", &isKernelDebugging, +// "Check if kernel dubugging is running" ); +// boost::python::def( "isDumpAnalyzing", &isDumpAnalyzing, +// "Check if it is a dump analyzing ( not living debuggee )" ); +// boost::python::def( "ptrSize", ptrSize, +// "Return pointer size ( in bytes )" ); +// boost::python::def( "reg", &loadRegister, +// "Return CPU's register value" ); +// boost::python::def( "rdmsr", &loadMSR, +// "Return MSR value" ); +// boost::python::def( "wrmsr", &setMSR, +// "Set MSR value" ); +// boost::python::def( "typedVarList", &loadTypedVarList, +// "Return list of typedVarClass instances. Each item represents one item of the linked list in the target memory" ); +// boost::python::def( "typedVarArray", &loadTypedVarArray, +// "Return list of typedVarClass instances. Each item represents one item of the counted array the target memory" ); +// boost::python::def( "containingRecord", &containingRecord, +// "Return instance of the typedVarClass. It's value are loaded from the target memory." +// "The start address is calculated by the same method as standard macro CONTAINING_RECORD" ); +// boost::python::def( "sizeof", &sizeofType, +// "Return size of type" ); +// boost::python::def( "loadModule", &loadModule, +// "Return instance of the dbgModuleClass" ); +// boost::python::def( "findSymbol", &findSymbolForAddress, +// "Return symbol for specified target address if it exists" ); +// boost::python::def( "getOffset", &findAddressForSymbol, +// "Return target address for specified symbol" ); +// boost::python::def( "findModule", &findModule, +// "Return instance of the dbgModuleClass which posseses specified address" ); +// boost::python::def( "addr64", &addr64, +// "Extend address to 64 bits formats ( for x86 )" ); +// boost::python::def( "loadChars", loadChars, loadCharsOv( boost::python::args( "address", "number", "phyAddr" ), +// "Load string from the target buffer" ) ); +// boost::python::def( "loadWChars", loadWChars, loadWCharsOv( boost::python::args( "address", "number", "phyAddr" ), +// "Load unicode string from the target buffer" ) ); +// boost::python::def( "loadBytes", &loadArray, loadBytes( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of unsigned bytes" ) ); +// boost::python::def( "loadWords", &loadArray, loadWords( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of unsigned words (2-bytes )" ) ); +// boost::python::def( "loadDWords", &loadArray, loadDWords( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of unsigned dwords (4-bytes)" ) ); +// boost::python::def( "loadQWords", &loadArray, loadQWords( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of unsigned qwords (8-butes)" ) ); +// boost::python::def( "loadSignBytes", &loadArray, loadSignBytes( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of signed bytes" ) ); +// boost::python::def( "loadSignWords", &loadArray, loadSignWords( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of signed words (2-bytes)" ) ); +// boost::python::def( "loadSignDWords", &loadArray, loadSignDWords( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of signed dwords (4-bytes)" ) ); +// boost::python::def( "loadSignQWords", &loadArray<__int64>, loadSignQWords( boost::python::args( "address", "number", "phyAddr" ), +// "Return list of signed qwords (8-bytes)" ) ); +// boost::python::def( "loadPtrs", &loadPtrArray, +// "Return list of pointers" ); +// boost::python::def( "loadUnicodeString", &loadUnicodeStr, +// "Return string represention of windows UNICODE_STRING type" ); +// boost::python::def( "loadAnsiString", &loadAnsiStr, +// "Return string represention of windows ANSU_STRING type" ); +// boost::python::def( "loadCStr", &loadCStr, +// "Load string from the target buffer containing 0-terminated ansi-string" ); +// boost::python::def( "loadWStr", &loadWStr, +// "Load string from the target buffer containing 0-terminated unicode-string" ); +// boost::python::def( "loadLinkedList", &loadLinkedList, +// "Return list of instances of the typedVarClass loaded from linked list in the target memory" ); +// boost::python::def( "ptrByte", &loadByPtr, +// "Return 1-byte unsigned value loaded by pointer" ); +// boost::python::def( "ptrSignByte", &loadByPtr, +// "Return 1-byte signed value loaded by pointer" ); +// boost::python::def( "ptrWord", &loadByPtr, +// "Return 2-byte unsigned value loaded by pointer" ); +// boost::python::def( "ptrSignWord", &loadByPtr, +// "Return 2-byte signed value loaded by pointer" ); +// boost::python::def( "ptrDWord", &loadByPtr, +// "Return 4-byte unsigned value loaded by pointer" ); +// boost::python::def( "ptrSignDWord", &loadByPtr, +// "Return 4-byte signed value loaded by pointer" ); +// boost::python::def( "ptrQWord", &loadByPtr, +// "Return 8-byte unsigned value loaded by pointer" ); +// boost::python::def( "ptrSignQWord", &loadByPtr<__int64>, +// "Return 8-byte signed value loaded by pointer" ); +// boost::python::def( "ptrPtr", &loadPtrByPtr, +// "Return pointer value loaded by pointer" ); +// boost::python::def( "ptrMWord", &loadMWord, +// "Return unsigned machine word ( 4-bytes for x86 and 8-bytes for x64 ) loaded by pointer" ); +// boost::python::def( "ptrSignMWord", &loadSignMWord, +// "Return signed machine word ( 4-bytes for x86 and 8-bytes for x64 ) loaded by pointer" ); +// boost::python::def( "compareMemory", &compareMemory, compareMemoryOver( boost::python::args( "addr1", "addr2", "length", "phyAddr" ), +// "Compare two memory buffers by virtual or physical addresses" ) ); +// boost::python::def( "getCurrentStack", &getCurrentStack, +// "Return list of dbgStackFrameClass for current stack" ); +// boost::python::def( "locals", &getLocals, +// "Return dict of locals variables (each item is typedVarClass)" ); +// boost::python::def( "reloadModule", &reloadModule, +// "Reload symbols by module name" ); +// boost::python::def( "getPdbFile", &getPdbFile, +// "Return full path to PDB (Program DataBase, debug information) file" ); +// boost::python::def( "getImplicitThread", &getImplicitThread, +// "Return implicit thread for current process" ); +// boost::python::def( "setImplicitThread", &setImplicitThread, +// "Set implicit thread for current process" ); +// boost::python::def( "getThreadList", &getThreadList, +// "Return list of threads (each item is numeric address of thread)" ); +// boost::python::def( "getCurrentProcess", &getCurrentProcess, +// "Return current process (numeric address)" ); +// boost::python::def( "setCurrentProcess", &setCurrentProcess, +// "Set current process by address" ); +// boost::python::def( "getProcessorMode", &getProcessorMode, +// "Return current processor mode as string: X86, ARM, IA64 or X64" ); +// boost::python::def( "setProcessorMode", &setProcessorMode, +// "Set current processor mode by string (X86, ARM, IA64 or X64)" ); +// boost::python::def( "addSynSymbol", &addSyntheticSymbol, +// "Add new synthetic symbol for virtual address" ); +// boost::python::def( "delAllSynSymbols", &delAllSyntheticSymbols, +// "Delete all synthetic symbol for all modules"); +// boost::python::def( "delSynSymbol", &delSyntheticSymbol, +// "Delete synthetic symbols by virtual address" ); +// boost::python::def( "delSynSymbolsMask", &delSyntheticSymbolsMask, +// "Delete synthetic symbols by mask of module and symbol name"); +// +// +// boost::python::class_( "typeInfo", +// "Class representing non-primitive type info: structure, union, etc. attributes is a fields of non-primitive type" ) +// .def(boost::python::init( boost::python::args("module", "type"), "constructor" ) ) +// .def(boost::python::init( boost::python::args("typeName"), "constructor" ) ) +// .def(boost::python::init( boost::python::args("typeName", "align"), "constructor" ) ) +// .def("size", &TypeInfo::size, +// "Return full size of non-primitive type" ) +// .def("name", &TypeInfo::name, +// "Return type's name" ) +// .def("__str__", &TypeInfo::print, +// "Return a nice string represention: print names and offsets of fields" ) +// .def("__getattr__", &TypeInfo::getField ) +// .def("__len__", &TypeInfo::getFieldCount ) +// .def("__getitem__", &TypeInfo::getFieldByIndex ) +// .def("append", &TypeInfo::appendField, appendOver( boost::python::args("type", "fieldName", "count"), +// "add new field for typeInfo" ) ) +// .def("offset", &TypeInfo::getFieldOffset, +// "Return offset while type is part of the more complex type" ) +// .def("setAlignReq", &TypeInfo::setAlignReq, +// "Set alignment requirement" ) +// .def("load", &TypeInfo::loadVar, loadOver( boost::python::args( "offset", "count"), +// "Create instance of the typedVar class with this typeInfo" ) ); +// +// DEF_PY_GLOBAL( "char_t", TypeInfo("", "char") ); +// DEF_PY_GLOBAL( "uchar_t", TypeInfo("", "unsigned char") ); +// DEF_PY_GLOBAL( "short_t", TypeInfo("", "short") ); +// DEF_PY_GLOBAL( "ushort_t", TypeInfo("", "unsigned short") ); +// DEF_PY_GLOBAL( "long_t", TypeInfo("", "long") ); +// DEF_PY_GLOBAL( "ulong_t", TypeInfo("", "unsigned long") ); +// DEF_PY_GLOBAL( "int_t", TypeInfo("", "int") ); +// DEF_PY_GLOBAL( "uint_t", TypeInfo("", "unsigned int") ); +// DEF_PY_GLOBAL( "ptr_t", TypeInfo("", "void*") ); +// DEF_PY_GLOBAL( "double_t", TypeInfo("", "double") ); +// DEF_PY_GLOBAL( "longlong_t", TypeInfo("", "int64") ); +// DEF_PY_GLOBAL( "ulonglong_t", TypeInfo("", "unsigned int64") ); +// +// boost::python::class_( "typedVar", +// "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance" ) +// .def(boost::python::init(boost::python::args("typeInfo", "address"), +// "constructor" ) ) +// .def(boost::python::init(boost::python::args("moduleName", "typeName", "address"), +// "constructor" ) ) +// .def(boost::python::init(boost::python::args("address"), +// "constructor" ) ) +// .def(boost::python::init(boost::python::args("symbolName"), +// "constructor" ) ) +// .def("getAddress", &TypedVar::getAddress, +// "Return virtual address" ) +// .def("sizeof", &TypedVar::getSize, +// "Return size of a variable in the target memory" ) +// .def("data", &TypedVar::data, +// "Return raw string object with data stream" ) +// .def("__getattr__", &TypedVar::getFieldWrap, +// "Return field of structure as an object attribute" ) +// .def("__str__", &TypedVar::print, +// "Return a nice string represention: print names and offsets of fields" ); +// +// boost::python::class_( "dbgModuleClass", +// "Class representing module in the target memory" ) +// .def("begin", &dbgModuleClass::getBegin, +// "Return start address of the module" ) +// .def("end", &dbgModuleClass::getEnd, +// "Return end address of the module" ) +// .def("size", &dbgModuleClass::getSize, +// "Return size of the module" ) +// .def("name", &dbgModuleClass::getName, +// "Return name of the module" ) +// .def("contain", &dbgModuleClass::contain, +// "Check if the address belongs to the module") +// .def("image", &dbgModuleClass::getImageSymbolName, +// "Return the full path to the module's image file" ) +// .def("pdb", &dbgModuleClass::getPdbName, +// "Return the full path to the module's pdb file ( symbol information )" ) +// .def("checksum", &dbgModuleClass::getCheckSum, +// "Return checksum of the module ( from PE header )" ) +// .def("timestamp", &dbgModuleClass::getTimeStamp, +// "Return timestamp of the module ( from PE header )" ) +// .def("addSynSymbol", &dbgModuleClass::addSyntheticSymbol, +// "Add synthetic symbol for the module" ) +// .def("delAllSynSymbols", &dbgModuleClass::delAllSyntheticSymbols, +// "Remove all synthetic symbols for the module" ) +// .def("delSynSymbol", &dbgModuleClass::delSyntheticSymbol, +// "Remove specified synthetic symbol for the module" ) +// .def("delSynSymbolsMask", &dbgModuleClass::delSyntheticSymbolsMask ) +// .def("__getattr__", &dbgModuleClass::getOffset, +// "Return address of the symbol" ) +// .def("__str__", &dbgModuleClass::print, +// "Return a nice string represention of the dbgModuleClass" ); +// +// boost::python::class_( +// "ext", +// "windbg extension wrapper", +// boost::python::init( boost::python::args("path"), "__init__ dbgExtensionClass" ) ) +// .def("call", &dbgExtensionClass::call, +// "Call extension command" ) +// .def("__str__", &dbgExtensionClass::print, +// "Return a nice string represention of the dbgExtensionClass" ); +// +// boost::python::class_( "dbgStackFrameClass", +// "Class representing a frame of the call satck" ) +// .def_readonly( "instructionOffset", &dbgStackFrameClass::InstructionOffset, +// "Return a frame's instruction offset" ) +// .def_readonly( "returnOffset", &dbgStackFrameClass::ReturnOffset, +// "Return a frame's return offset" ) +// .def_readonly( "frameOffset", &dbgStackFrameClass::FrameOffset, +// "Return a frame's offset" ) +// .def_readonly( "stackOffset", &dbgStackFrameClass::StackOffset, +// "Return a frame's stack offset" ) +// .def_readonly( "frameNumber", &dbgStackFrameClass::FrameNumber, +// "Return a frame's number" ) +// .def( "__str__", &dbgStackFrameClass::print, +// "Return a nice string represention of the dbgStackFrameClass" ); +// +// boost::python::class_( "windbgOut", "windbgOut" ) +// .def( "write", &dbgOut::write ); +// +// boost::python::class_( "windbgIn", "windbgIn" ) +// .def( "readline", &dbgIn::readline ); +// +// boost::python::class_( "bp", +// "Class representing breakpoint", +// boost::python::init( boost::python::args("offset", "callback"), +// "Break point: user callback" ) ) +// .def( boost::python::init< ULONG64 >( boost::python::args("offset"), +// "Break point constructor: always break" ) ) +// .def( "set", &dbgBreakpointClass::set, +// "Set a breakpoint at the specified address" ) +// .def( "remove", &dbgBreakpointClass::remove, +// "Remove a breakpoint set before" ) +// .def( "__str__", &dbgBreakpointClass::print, +// "Return a nice string represention of the breakpoint class" ); +// +// boost::python::class_( "debugEvent", +// "Base class for debug events handlers" ) +// .def( "onBreakpoint", &debugEventWrap::onBreakpoint, +// "Triggered breakpoint event. Parameter is dict:\n" +// "{\"Id\":int, \"BreakType\":int, \"ProcType\":int, \"Flags\":int, \"Offset\":int," +// " \"Size\":int, \"AccessType\":int, \"PassCount\":int, \"CurrentPassCount\":int," +// " \"MatchThreadId\":int, \"Command\":str, \"OffsetExpression\":str}\n" +// "Detailed information: http://msdn.microsoft.com/en-us/library/ff539284(VS.85).aspx \n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) +// .def( "onException", &debugEventWrap::onException, +// "Exception event. Parameter is dict:\n" +// "{\"Code\":int, \"Flags\":int, \"Record\":int, \"Address\":int," +// " \"Parameters\":[int], \"FirstChance\":bool}\n" +// "Detailed information: http://msdn.microsoft.com/en-us/library/aa363082(VS.85).aspx \n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) +// .def( "onLoadModule", &debugEventWrap::onLoadModule, +// "Load module event. Parameter is instance of dbgModuleClass.\n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) +// .def( "onUnloadModule", &debugEventWrap::onUnloadModule, +// "Unload module event. Parameter is instance of dbgModuleClass.\n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); +// +// boost::python::class_("disasm", "Class disassemble a processor instructions", boost::python::no_init ) +// .def( boost::python::init<>( "constructor" ) ) +// .def( boost::python::init( boost::python::args("offset"), "constructor" ) ) +// .def( "next", &disasm::next, "Disassemble next instruction" ) +// .def( "begin", &disasm::begin, "Return begin offset" ) +// .def( "current", &disasm::current, "Return current offset" ) +// .def( "length", &disasm::length, "Return current instruction length" ) +// .def( "instruction", &disasm::instruction, "Returm current disassembled instruction" ) +// .def( "ea", &disasm::ea, "Return effective address for last disassembled instruction or 0" ); +// +// +// // исключения +// boost::python::class_ dbgExceptionClass( "BaseException", +// "Pykd base exception class", +// boost::python::no_init ); +// //boost::python::init() ); +// +// dbgExceptionClass +// .def( boost::python::init( boost::python::args("desc"), "constructor" ) ) +// .def( "desc", &DbgException::getDesc, +// "Get exception description" ); +// +// boost::python::class_ > waitExceptionClass( "WaitEventException", +// "Type exception class", +// boost::python::no_init ); +// +// boost::python::class_ > typeExceptionClass( "TypeException", +// "Type exception class", +// boost::python::no_init ); +// +// boost::python::class_ > memoryExceptionClass( "MemoryException", +// "Memory exception class", +// boost::python::no_init ); +// +// memoryExceptionClass +// .def( boost::python::init( boost::python::args("targetAddress"), "constructor" ) ) +// .def( "getAddress", &MemoryException::getAddress, +// "Return target address" ); +// +// baseExceptionType = dbgExceptionClass.ptr(); +// eventExceptionType = waitExceptionClass.ptr(); +// typeExceptionType = typeExceptionClass.ptr(); +// memoryExceptionType = memoryExceptionClass.ptr(); +// +// boost::python::register_exception_translator( &DbgException::exceptionTranslate ); +// boost::python::register_exception_translator( &WaitEventException::exceptionTranslate ); +// boost::python::register_exception_translator( &TypeException::exceptionTranslate ); +// boost::python::register_exception_translator( &IndexException::translate); +// boost::python::register_exception_translator( &MemoryException::translate ); +// +// boost::python::class_( +// "intBase", +// "intBase") +// .def( boost::python::init<>() ) +// .def( boost::python::init( boost::python::args("value"), "constructor" ) ) +// +// .def( "value", &intBase::value ) +// .def( int_( boost::python::self ) ) +// //.def( boost::python::self = long() ) +// +// .def( boost::python::self + long() ) +// .def( long() + boost::python::self ) +// .def( boost::python::self += long() ) +// .def( boost::python::self + boost::python::self ) +// .def( boost::python::self += boost::python::self ) +// +// .def( boost::python::self - long() ) +// .def( long() - boost::python::self ) +// .def( boost::python::self -= long() ) +// .def( boost::python::self - boost::python::self ) +// .def( boost::python::self -= boost::python::self ) +// +// .def( boost::python::self * long() ) +// .def( long() * boost::python::self ) +// .def( boost::python::self *= long() ) +// .def( boost::python::self * boost::python::self ) +// .def( boost::python::self *= boost::python::self ) +// +// .def( boost::python::self / long() ) +// .def( long() / boost::python::self ) +// .def( boost::python::self /= long() ) +// .def( boost::python::self / boost::python::self ) +// .def( boost::python::self /= boost::python::self ) +// +// .def( boost::python::self % long() ) +// .def( long() % boost::python::self ) +// .def( boost::python::self %= long() ) +// .def( boost::python::self % boost::python::self ) +// .def( boost::python::self %= boost::python::self ) +// +// .def( boost::python::self & long() ) +// .def( long() & boost::python::self ) +// .def( boost::python::self &= long() ) +// .def( boost::python::self & boost::python::self ) +// .def( boost::python::self &= boost::python::self ) +// +// .def( boost::python::self | long() ) +// .def( long() | boost::python::self ) +// .def( boost::python::self |= long() ) +// .def( boost::python::self | boost::python::self ) +// .def( boost::python::self |= boost::python::self ) +// +// .def( boost::python::self ^ long() ) +// .def( long() ^ boost::python::self ) +// .def( boost::python::self ^= long() ) +// .def( boost::python::self ^ boost::python::self ) +// .def( boost::python::self ^= boost::python::self ) +// +// .def( boost::python::self << long() ) +// .def( boost::python::self <<= long() ) +// +// .def( boost::python::self >> long() ) +// .def( boost::python::self >>= long() ) +// +// .def( boost::python::self < long() ) +// .def( boost::python::self < boost::python::self ) +// +// .def( boost::python::self <= long() ) +// .def( boost::python::self <= boost::python::self ) +// +// .def( boost::python::self == long() ) +// .def( boost::python::self == boost::python::self ) +// +// .def( boost::python::self >= long() ) +// .def( boost::python::self >= boost::python::self ) +// +// .def( boost::python::self > long() ) +// .def( boost::python::self > boost::python::self ) +// +// .def( boost::python::self != long() ) +// .def( boost::python::self != boost::python::self ) +// +// .def( ~boost::python::self ) +// .def( !boost::python::self ) +// +// .def( "__str__", &intBase::str ) +// .def( "__hex__", &intBase::hex ); +// +// boost::python::class_ >( +// "cpuReg", +// "CPU regsiter class", +// boost::python::no_init ) +// .def( boost::python::init(boost::python::args("name"), "constructor" ) ) +// .def( boost::python::init(boost::python::args("index"), "constructor" ) ) +// .def( "name", &cpuReg::name, "The name of the regsiter" ) +// .def( "index", &cpuReg::index, "The index of thr register" ) +// .def( "beLive", &cpuReg::beLive, "Turn the object to live: its value will be following the target register value" ); +// +// +// // debug status +// DEF_PY_CONST(DEBUG_STATUS_NO_CHANGE); +// DEF_PY_CONST(DEBUG_STATUS_GO); +// DEF_PY_CONST(DEBUG_STATUS_GO_HANDLED); +// DEF_PY_CONST(DEBUG_STATUS_GO_NOT_HANDLED); +// DEF_PY_CONST(DEBUG_STATUS_STEP_OVER); +// DEF_PY_CONST(DEBUG_STATUS_STEP_INTO); +// DEF_PY_CONST(DEBUG_STATUS_BREAK); +// DEF_PY_CONST(DEBUG_STATUS_NO_DEBUGGEE); +// DEF_PY_CONST(DEBUG_STATUS_STEP_BRANCH); +// DEF_PY_CONST(DEBUG_STATUS_IGNORE_EVENT); +// DEF_PY_CONST(DEBUG_STATUS_RESTART_REQUESTED); +// DEF_PY_CONST(DEBUG_STATUS_REVERSE_GO); +// DEF_PY_CONST(DEBUG_STATUS_REVERSE_STEP_BRANCH); +// DEF_PY_CONST(DEBUG_STATUS_REVERSE_STEP_OVER); +// DEF_PY_CONST(DEBUG_STATUS_REVERSE_STEP_INTO); +// +// // debug status additional mask +// DEF_PY_CONST(DEBUG_STATUS_INSIDE_WAIT); +// DEF_PY_CONST(DEBUG_STATUS_WAIT_TIMEOUT); +// +// // break point type +// DEF_PY_CONST(DEBUG_BREAKPOINT_CODE); +// DEF_PY_CONST(DEBUG_BREAKPOINT_DATA); +// DEF_PY_CONST(DEBUG_BREAKPOINT_TIME); +// +// // break point flag +// DEF_PY_CONST(DEBUG_BREAKPOINT_GO_ONLY); +// DEF_PY_CONST(DEBUG_BREAKPOINT_DEFERRED); +// DEF_PY_CONST(DEBUG_BREAKPOINT_ENABLED); +// DEF_PY_CONST(DEBUG_BREAKPOINT_ADDER_ONLY); +// DEF_PY_CONST(DEBUG_BREAKPOINT_ONE_SHOT); +// +// // break point access type +// DEF_PY_CONST(DEBUG_BREAK_READ); +// DEF_PY_CONST(DEBUG_BREAK_WRITE); +// DEF_PY_CONST(DEBUG_BREAK_EXECUTE); +// DEF_PY_CONST(DEBUG_BREAK_IO); +// +// // exception flags +// DEF_PY_CONST(EXCEPTION_NONCONTINUABLE); +// +// // debug events +// DEF_PY_CONST(DEBUG_EVENT_BREAKPOINT); +// DEF_PY_CONST(DEBUG_EVENT_EXCEPTION); +// DEF_PY_CONST(DEBUG_EVENT_CREATE_THREAD); +// DEF_PY_CONST(DEBUG_EVENT_EXIT_THREAD); +// DEF_PY_CONST(DEBUG_EVENT_CREATE_PROCESS); +// DEF_PY_CONST(DEBUG_EVENT_EXIT_PROCESS); +// DEF_PY_CONST(DEBUG_EVENT_LOAD_MODULE); +// DEF_PY_CONST(DEBUG_EVENT_UNLOAD_MODULE); +// DEF_PY_CONST(DEBUG_EVENT_SYSTEM_ERROR); +// DEF_PY_CONST(DEBUG_EVENT_SESSION_STATUS); +// DEF_PY_CONST(DEBUG_EVENT_CHANGE_DEBUGGEE_STATE); +// DEF_PY_CONST(DEBUG_EVENT_CHANGE_ENGINE_STATE); +// DEF_PY_CONST(DEBUG_EVENT_CHANGE_SYMBOL_STATE); +// +// // debugger type +// //_DEF_PY_CONST(DEBUG_CLASS_UNINITIALIZED); +// //_DEF_PY_CONST(DEBUG_CLASS_KERNEL); +// //_DEF_PY_CONST(DEBUG_CLASS_USER_WINDOWS); +// //_DEF_PY_CONST(DEBUG_CLASS_IMAGE_FILE); +// // +// //_DEF_PY_CONST(DEBUG_KERNEL_CONNECTION); +// //_DEF_PY_CONST(DEBUG_KERNEL_LOCAL); +// //_DEF_PY_CONST(DEBUG_KERNEL_EXDI_DRIVER); +// //_DEF_PY_CONST(DEBUG_KERNEL_IDNA); +// //_DEF_PY_CONST(DEBUG_KERNEL_SMALL_DUMP); +// //_DEF_PY_CONST(DEBUG_KERNEL_DUMP); +// //_DEF_PY_CONST(DEBUG_KERNEL_FULL_DUMP); +// +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_PROCESS); +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_PROCESS_SERVER); +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_IDNA); +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_SMALL_DUMP); +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_SMALL_DUMP); +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_DUMP); +// //_DEF_PY_CONST(DEBUG_USER_WINDOWS_DUMP_WINDOWS_CE); +//} +// +//#undef _DEF_PY_CONST +// +/////////////////////////////////////////////////////////////////////////////////// +// +//class WindbgGlobalSession +//{ +//public: +// +// static +// boost::python::object +// global() { +// return windbgGlobalSession->main.attr("__dict__"); +// } +// +// static +// VOID +// StartWindbgSession() { +// if ( 1 == InterlockedIncrement( &sessionCount ) ) +// { +// windbgGlobalSession = new WindbgGlobalSession(); +// } +// } +// +// static +// VOID +// StopWindbgSession() { +// if ( 0 == InterlockedDecrement( &sessionCount ) ) +// { +// delete windbgGlobalSession; +// windbgGlobalSession = NULL; +// } +// } +// +// static +// bool isInit() { +// return windbgGlobalSession != NULL; +// } +// +// +//private: +// +// WindbgGlobalSession() { +// +// PyImport_AppendInittab("pykd", initpykd ); +// +// Py_Initialize(); +// +// main = boost::python::import("__main__"); +// +// boost::python::object main_namespace = main.attr("__dict__"); +// +// +// // делаем аналог from pykd import * +// boost::python::object pykd = boost::python::import( "pykd" ); +// +// boost::python::dict pykd_namespace( pykd.attr("__dict__") ); +// +// boost::python::list iterkeys( pykd_namespace.iterkeys() ); +// +// for (int i = 0; i < boost::python::len(iterkeys); i++) +// { +// std::string key = boost::python::extract(iterkeys[i]); +// +// main_namespace[ key ] = pykd_namespace[ key ]; +// } +// +// //// перенаправление стандартных потоков ВВ +// //boost::python::object sys = boost::python::import( "sys"); +// // +// //dbgOut dout; +// //sys.attr("stdout") = boost::python::object( dout ); +// +// //dbgIn din; +// //sys.attr("stdin") = boost::python::object( din ); +// // +// g_dbgClient.startEventsMgr(); +// } +// +// ~WindbgGlobalSession() { +// Py_Finalize(); +// g_dbgClient.removeEventsMgr(); +// } +// +// boost::python::object main; +// +// static volatile LONG sessionCount; +// +// static WindbgGlobalSession *windbgGlobalSession; +//}; +// +//volatile LONG WindbgGlobalSession::sessionCount = 0; +// +//WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL; +// +//bool isWindbgExt() { +// return WindbgGlobalSession::isInit(); +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT +//CALLBACK +//DebugExtensionInitialize( +// OUT PULONG Version, +// OUT PULONG Flags ) +//{ +// *Version = DEBUG_EXTENSION_VERSION( 1, 0 ); +// *Flags = 0; +// +// WindbgGlobalSession::StartWindbgSession(); +// +// return S_OK; +//} +// +// +//VOID +//CALLBACK +//DebugExtensionUninitialize() +//{ +// WindbgGlobalSession::StopWindbgSession(); +//} +// +//DbgExt::DbgExt( IDebugClient4 *masterClient ) +//{ +// client = NULL; +// masterClient->QueryInterface( __uuidof(IDebugClient), (void **)&client ); +// +// client4 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugClient4), (void **)&client4 ); +// +// client5 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugClient5), (void **)&client5 ); +// +// control = NULL; +// masterClient->QueryInterface( __uuidof(IDebugControl), (void **)&control ); +// +// control4 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugControl4), (void **)&control4 ); +// +// registers = NULL; +// masterClient->QueryInterface( __uuidof(IDebugRegisters), (void **)®isters ); +// +// symbols = NULL; +// masterClient->QueryInterface( __uuidof(IDebugSymbols), (void ** )&symbols ); +// +// symbols2 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugSymbols2), (void ** )&symbols2 ); +// +// symbols3 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&symbols3 ); +// +// dataSpaces = NULL; +// masterClient->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dataSpaces ); +// +// dataSpaces4 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugDataSpaces4), (void **)&dataSpaces4 ); +// +// advanced2 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&advanced2 ); +// +// system = NULL; +// masterClient->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&system ); +// +// system2 = NULL; +// masterClient->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&system2 ); +// +// m_previosExt = dbgExt; +// dbgExt = this; +//} +// +//DbgExt::~DbgExt() +//{ +// BOOST_ASSERT(dbgExt == this); +// dbgExt = m_previosExt; +// +// if ( client ) +// client->Release(); +// +// if ( client4 ) +// client4->Release(); +// +// if ( client5 ) +// client5->Release(); +// +// if ( control ) +// control->Release(); +// +// if ( control4 ) +// control4->Release(); +// +// if ( registers ) +// registers->Release(); +// +// if ( symbols ) +// symbols->Release(); +// +// if ( symbols2 ) +// symbols2->Release(); +// +// if ( symbols3 ) +// symbols3->Release(); +// +// if ( dataSpaces ) +// dataSpaces->Release(); +// +// if ( dataSpaces4 ) +// dataSpaces4->Release(); +// +// if ( advanced2 ) +// advanced2->Release(); +// +// if ( system ) +// system->Release(); +// +// if ( system2 ) +// system2->Release(); +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT +//CALLBACK +//py( PDEBUG_CLIENT4 client, PCSTR args) +//{ +// DbgExt ext( client ); +// +// PyThreadState *globalInterpreter = PyThreadState_Swap( NULL ); +// PyThreadState *localInterpreter = Py_NewInterpreter(); +// +// try { +// +// boost::python::import( "pykd" ); +// +// boost::python::object main = boost::python::import("__main__"); +// +// boost::python::object global(main.attr("__dict__")); +// +// // перенаправление стандартных потоков ВВ +// boost::python::object sys = boost::python::import("sys"); +// +// boost::python::object tracebackModule = boost::python::import("traceback"); +// +// dbgOut dout; +// sys.attr("stdout") = boost::python::object( dout ); +// +// dbgIn din; +// sys.attr("stdin") = boost::python::object( din ); +// +// // разбор параметров +// typedef boost::escaped_list_separator char_separator_t; +// typedef boost::tokenizer< char_separator_t > char_tokenizer_t; +// +// std::string argsStr( args ); +// +// char_tokenizer_t token( argsStr , char_separator_t( "", " \t", "\"" ) ); +// std::vector argsList; +// +// for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it ) +// { +// if ( *it != "" ) +// argsList.push_back( *it ); +// } +// +// if ( argsList.size() == 0 ) +// return S_OK; +// +// char **pythonArgs = new char* [ argsList.size() ]; +// +// for ( size_t i = 0; i < argsList.size(); ++i ) +// pythonArgs[i] = const_cast( argsList[i].c_str() ); +// +// PySys_SetArgv( (int)argsList.size(), pythonArgs ); +// +// delete[] pythonArgs; +// +// +// // найти путь к файлу +// std::string fullFileName; +// std::string filePath; +// DbgPythonPath dbgPythonPath; +// +// +// if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) ) +// { +// try { +// +// boost::python::object result; +// +// result = boost::python::exec_file( fullFileName.c_str(), global, global ); +// } +// catch( boost::python::error_already_set const & ) +// { +// // ошибка в скрипте +// PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL; +// +// PyErr_Fetch( &errtype, &errvalue, &traceback ); +// +// if(errvalue != NULL) +// { +// PyObject *errvalueStr= PyObject_Str(errvalue); +// +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING( errvalueStr ) ); +// +// if ( traceback ) +// { +// boost::python::object traceObj( boost::python::handle<>( boost::python::borrowed( traceback ) ) ); +// +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "\nTraceback:\n" ); +// +// boost::python::object pFunc( tracebackModule.attr("format_tb") ); +// boost::python::list traceList( pFunc( traceObj ) ); +// +// for ( long i = 0; i < boost::python::len(traceList); ++i ) +// { +// std::string traceLine = boost::python::extract(traceList[i]); +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, traceLine.c_str() ); +// } +// } +// +// Py_DECREF(errvalueStr); +// } +// +// Py_XDECREF(errvalue); +// Py_XDECREF(errtype); +// Py_XDECREF(traceback); +// } +// } +// else +// { +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "script file not found\n" ); +// } +// } +// +// catch(...) +// { +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" ); +// } +// +// Py_EndInterpreter( localInterpreter ); +// PyThreadState_Swap( globalInterpreter ); +// +// return S_OK; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT +//CALLBACK +//pycmd( PDEBUG_CLIENT4 client, PCSTR args ) +//{ +// DbgExt ext( client ); +// +// try { +// +// // перенаправление стандартных потоков ВВ +// boost::python::object sys = boost::python::import("sys"); +// +// dbgOut dout; +// sys.attr("stdout") = boost::python::object( dout ); +// +// dbgIn din; +// sys.attr("stdin") = boost::python::object( din ); +// +// boost::python::object syntaxError = boost::python::import("exceptions").attr("SyntaxError"); +// +// boost::python::object tracebackModule = boost::python::import("traceback"); +// +// std::string commandBuffer; +// +// bool commandCompleted = true; +// +// do { +// +// if ( commandCompleted ) +// { +// dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, ">>>" ); +// } +// else +// { +// dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, "..." ); +// } +// +// { +// char str[100]; +// ULONG inputSize; +// +// OutputReader outputReader( (IDebugClient*)client ); +// HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize ); +// +// if ( FAILED( hres ) ) +// throw; +// +// if ( commandCompleted ) +// { +// if ( std::string( str ) == "" ) +// break; +// +// commandBuffer = str; +// } +// else +// { +// if ( std::string( str ) == "" ) +// commandCompleted = true; +// else +// { +// commandBuffer.append("\n"); +// commandBuffer.append( str ); +// } +// } +// } +// +// if ( commandCompleted ) +// { +// try { +// +// boost::python::exec( commandBuffer.c_str(), WindbgGlobalSession::global(), WindbgGlobalSession::global() ); +// +// commandBuffer.clear(); +// +// } +// catch( boost::python::error_already_set const & ) +// { +// PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL, *errvalueStr = NULL; +// +// PyErr_Fetch( &errtype, &errvalue, &traceback ); +// +// if ( errtype && errvalue ) +// { +// errvalueStr = PyObject_Str(errvalue); +// +// do { +// +// if ( PyErr_GivenExceptionMatches( syntaxError.ptr(), errtype ) ) +// { +// boost::python::tuple errValueObj( boost::python::handle<>( boost::python::borrowed(errvalue) ) ); +// +// if ( errValueObj[0] == "unexpected EOF while parsing" ) +// { +// commandCompleted = false; +// break; +// } +// } +// +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING(errvalueStr) ); +// +// if ( traceback ) +// { +// boost::python::object traceObj( boost::python::handle<>( boost::python::borrowed( traceback ) ) ); +// +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "\nTraceback:\n" ); +// +// boost::python::object pFunc( tracebackModule.attr("format_tb") ); +// boost::python::list traceList( pFunc( traceObj ) ); +// +// for ( long i = 0; i < boost::python::len(traceList); ++i ) +// { +// std::string traceLine = boost::python::extract(traceList[i]); +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, traceLine.c_str() ); +// } +// } +// +// } while( FALSE ); +// +// Py_XDECREF(errvalueStr); +// Py_XDECREF(errvalue); +// Py_XDECREF(errtype); +// Py_XDECREF(traceback); +// } +// else +// { +// Py_XDECREF(errvalue); +// Py_XDECREF(errtype); +// Py_XDECREF(traceback); +// +// throw; +// } +// } +// } +// +// } while( true ); +// } +// catch(...) +// { +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" ); +// } +// +// return S_OK; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT +//CALLBACK +//pythonpath( PDEBUG_CLIENT4 client, PCSTR args ) +//{ +// //DbgExt ext; +// +// //SetupDebugEngine( client, &ext ); +// //dbgExt = &ext; +// +// ////DbgPrint::dprintln( dbgPythonPath.getStr() ); +// +// return S_OK; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// diff --git a/pykd/dbgext.h b/pykd/dbgext.h index 39c0f55..0f09f6e 100644 --- a/pykd/dbgext.h +++ b/pykd/dbgext.h @@ -1,43 +1,43 @@ #pragma once -#include -#include - -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 +//#include +// +//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(); diff --git a/pykd/dbgio.cpp b/pykd/dbgio.cpp index f49bb38..6ae906e 100644 --- a/pykd/dbgio.cpp +++ b/pykd/dbgio.cpp @@ -1,34 +1,34 @@ #include "stdafx.h" -#include -#include - -#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( 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( 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 +//#include +// +//#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( 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( 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; +//} +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgio.h b/pykd/dbgio.h index 5294afb..1301477 100644 --- a/pykd/dbgio.h +++ b/pykd/dbgio.h @@ -1,224 +1,224 @@ #pragma once -#include -#include - -#include "dbgext.h" - +//#include +//#include +// +//#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 ); +// } +// +//}; +// +/////////////////////////////////////////////////////////////////////////////////// +// diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index b6e23d9..52561dc 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -1,503 +1,503 @@ #include "stdafx.h" -#include - -#include "dbgext.h" -#include "dbgexcept.h" -#include "dbgmem.h" -#include "dbgsystem.h" -#include "dbgio.h" - -using namespace std; - -/////////////////////////////////////////////////////////////////////////////////// - -void -loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr ) -{ - address = addr64( address ); - - HRESULT hres; - - if ( phyAddr == FALSE ) - { - hres = dbgExt->dataSpaces->ReadVirtual( address, dest, length, NULL ); - } - else - { - hres = dbgExt->dataSpaces->ReadPhysical( address, dest, length, NULL ); - } - - if ( FAILED( hres ) ) - throw MemoryException( address, !!phyAddr ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -ULONG64 -addr64( ULONG64 addr) -{ - HRESULT hres; - - try { - - ULONG processorMode; - hres = dbgExt->control->GetActualProcessorType( &processorMode ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" ); - - switch( processorMode ) - { - case IMAGE_FILE_MACHINE_I386: - if ( *( (ULONG*)&addr + 1 ) == 0 ) - return (ULONG64)(LONG)addr; - - case IMAGE_FILE_MACHINE_AMD64: - break; - - default: - throw DbgException( "Unknown processor type" ); - break; - } - } - 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 addr; -} - -/////////////////////////////////////////////////////////////////////////////////// - -bool -compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr ) -{ - HRESULT hres; - bool result = false; - - addr1 = addr64( addr1 ); - addr2 = addr64( addr2 ); - - boost::scoped_array m1(new char[length]); - boost::scoped_array m2(new char[length]); - - try { - - if ( phyAddr == FALSE ) - { - - hres = dbgExt->dataSpaces->ReadVirtual( addr1, m1.get(), length, NULL ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); - - hres = dbgExt->dataSpaces->ReadVirtual( addr2, m2.get(), length, NULL ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); - } - else - { - hres = dbgExt->dataSpaces->ReadPhysical( addr1, m1.get(), length, NULL ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugDataSpace::ReadPhysical failed" ); - - hres = dbgExt->dataSpaces->ReadPhysical( addr2, m2.get(), length, NULL ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugDataSpace::ReadPhysical failed" ); - } - - result = memcmp( m1.get(), m2.get(), length ) == 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 result; -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadPtrArray( ULONG64 address, ULONG number ) -{ - if ( is64bitSystem() ) - { - boost::scoped_array buffer(new ULONG64[number]); - - loadMemory( address, buffer.get(), number*sizeof(ULONG64) ); - - boost::python::list lst; - - for ( ULONG i = 0; i < number; ++i ) - lst.append( buffer[i] ); - - return lst; - } - else - { - boost::scoped_array buffer(new ULONG[number]); - - loadMemory( address, buffer.get(), number*sizeof(ULONG) ); - - boost::python::list lst; - - for ( ULONG i = 0; i < number; ++i ) - lst.append( addr64( buffer[i] ) ); - - return lst; - } -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) -{ - std::vector buffer(number); - - if (number) - loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); - - return boost::python::object(std::string( buffer.begin(), buffer.end() ) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadWChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) -{ - std::vector buffer(number); - - loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); - - return boost::python::object(std::wstring( buffer.begin(), buffer.end() ) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -ULONG64 -loadPtrByPtr( ULONG64 address ) -{ - ULONG64 value = 0; - - if ( is64bitSystem() ) - loadMemory( address, &value, sizeof(ULONG64) ); - else - { - loadMemory( address, &value, sizeof(ULONG) ); - - value = addr64( value ); - } - - return value; -} - -/////////////////////////////////////////////////////////////////////////////////// - -ULONG64 -loadMWord( ULONG64 address ) -{ - ULONG64 value = 0; - - if ( is64bitSystem() ) - loadMemory( address, &value, sizeof(ULONG64) ); - else - loadMemory( address, &value, sizeof(ULONG) ); - - return value; -} - -/////////////////////////////////////////////////////////////////////////////////// - -LONG64 -loadSignMWord( ULONG64 address ) -{ - LONG64 value = 0; - - if ( is64bitSystem() ) - loadMemory( address, &value, sizeof(LONG64) ); - else - loadMemory( address, &value, sizeof(LONG) ); - - return value; -} - -/////////////////////////////////////////////////////////////////////////////////// - -template<> -boost::python::object -loadByPtr( ULONG64 address ) -{ - char value; - - loadMemory( address, &value, sizeof(char) ); - - return boost::python::object( (int)value ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadUnicodeStr( ULONG64 address ) -{ - USHORT length; - USHORT maximumLength; - ULONG64 buffer = 0; - - do { - - loadMemory( address, &length, sizeof( length ) ); - - if ( length == 0 ) - break; - - address += sizeof( length ); - - loadMemory( address, &maximumLength, sizeof( maximumLength ) ); - - address += sizeof( maximumLength ); - - if ( is64bitSystem() ) - { - address += address % 8 ? ( 8 - address % 8 ) : 0 ; // выравнивание на 8 байт - - loadMemory( address, &buffer, 8 ); - - address += 8; - } - else - { - address += address % 4 ? ( 4 - address % 4 ) : 0 ; // выравнивание на 8 байт - - loadMemory( address, &buffer, 4 ); - - buffer = addr64( buffer ); - - address += 4; - } - - std::vector str(length / 2); - - loadMemory( buffer, &str[0], length ); - - std::wstring strValue(&str[0], length/2); - - return boost::python::object( strValue ); - - } while( FALSE ); - - return boost::python::object( "" ); - -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadAnsiStr( ULONG64 address ) -{ - USHORT length; - USHORT maximumLength; - ULONG64 buffer = 0; - - do { - - loadMemory( address, &length, sizeof( length ) ); - - if ( length == 0 ) - break; - - address += sizeof( length ); - - loadMemory( address, &maximumLength, sizeof( maximumLength ) ); - - address += sizeof( maximumLength ); - - if ( is64bitSystem() ) - { - address += address % 8 ? ( 8 - address % 8 ) : 0; // выравнивание на 8 байт - - loadMemory( address, &buffer, 8 ); - - address += 8; - } - else - { - address += address % 4 ? ( 4 - address % 4 ) : 0; // выравнивание на 8 байт - - loadMemory( address, &buffer, 4 ); - - buffer = addr64( buffer ); - - address += 4; - } - - - std::vector str(length); - - loadMemory( buffer, &str[0], length ); - - std::string strVal ( &str[0], length ); - - return boost::python::object( strVal ); - - } while( FALSE ); - - return boost::python::object( "" ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -void -loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen ) -{ - address = addr64( address ); - - HRESULT hres = - dbgExt->dataSpaces4->ReadMultiByteStringVirtual( - address, - bufferLen, - buffer, - bufferLen/sizeof(CHAR), - NULL ); - - if ( FAILED( hres ) ) - throw MemoryException( address ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -void -loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen ) -{ - address = addr64( address ); - - HRESULT hres = - dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( - address, - bufferLen, - buffer, - bufferLen/sizeof(WCHAR), - NULL ); - - if ( FAILED( hres ) ) - throw MemoryException( address ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadCStr( ULONG64 address ) -{ - const size_t maxLength = 0x1000; - - address = addr64( address ); - - boost::scoped_array buffer(new char[maxLength]); - - HRESULT hres = - dbgExt->dataSpaces4->ReadMultiByteStringVirtual( - address, - maxLength, - buffer.get(), - maxLength, - NULL ); - - if ( FAILED( hres ) ) - throw MemoryException( address ); - - return boost::python::object( std::string( buffer.get() ) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadWStr( ULONG64 address ) -{ - const size_t maxLength = 0x1000; - - address = addr64( address ); - - boost::scoped_array buffer(new wchar_t[maxLength]); - - HRESULT hres = - dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( - address, - maxLength*sizeof(wchar_t), - buffer.get(), - maxLength, - NULL ); - - if ( FAILED( hres ) ) - throw MemoryException( address ); - - return boost::python::object( std::wstring(buffer.get()) ); -} - - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadLinkedList( ULONG64 address ) -{ - ULONG64 entryAddress = 0; - - boost::python::list objList; - - for( entryAddress = loadPtrByPtr( address ); entryAddress != address; entryAddress = loadPtrByPtr( entryAddress ) ) - objList.append( entryAddress ); - - return objList; -} - -/////////////////////////////////////////////////////////////////////////////////// - -bool -isOffsetValid( ULONG64 addr ) -{ - HRESULT hres; - - try { - - // нужно подавить возможный вывод в консоль об отсутствующей странице памяти - OutputReader outputReader( dbgExt->client ); - - ULONG offsetInfo; - - hres = - dbgExt->dataSpaces4->GetOffsetInformation( - DEBUG_DATA_SPACE_VIRTUAL, - DEBUG_OFFSINFO_VIRTUAL_SOURCE, - addr, - &offsetInfo, - sizeof( offsetInfo ), - NULL ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugDataSpace4::GetOffsetInformation failed" ); - - return offsetInfo != DEBUG_VSOURCE_INVALID; - - } - 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; -} - -/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +//#include "dbgext.h" +//#include "dbgexcept.h" +//#include "dbgmem.h" +//#include "dbgsystem.h" +//#include "dbgio.h" +// +//using namespace std; +// +///////////////////////////////////////////////////////////////////////////////////// +// +//void +//loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr ) +//{ +// address = addr64( address ); +// +// HRESULT hres; +// +// if ( phyAddr == FALSE ) +// { +// hres = dbgExt->dataSpaces->ReadVirtual( address, dest, length, NULL ); +// } +// else +// { +// hres = dbgExt->dataSpaces->ReadPhysical( address, dest, length, NULL ); +// } +// +// if ( FAILED( hres ) ) +// throw MemoryException( address, !!phyAddr ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ULONG64 +//addr64( ULONG64 addr) +//{ +// HRESULT hres; +// +// try { +// +// ULONG processorMode; +// hres = dbgExt->control->GetActualProcessorType( &processorMode ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" ); +// +// switch( processorMode ) +// { +// case IMAGE_FILE_MACHINE_I386: +// if ( *( (ULONG*)&addr + 1 ) == 0 ) +// return (ULONG64)(LONG)addr; +// +// case IMAGE_FILE_MACHINE_AMD64: +// break; +// +// default: +// throw DbgException( "Unknown processor type" ); +// break; +// } +// } +// 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 addr; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//bool +//compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr ) +//{ +// HRESULT hres; +// bool result = false; +// +// addr1 = addr64( addr1 ); +// addr2 = addr64( addr2 ); +// +// boost::scoped_array m1(new char[length]); +// boost::scoped_array m2(new char[length]); +// +// try { +// +// if ( phyAddr == FALSE ) +// { +// +// hres = dbgExt->dataSpaces->ReadVirtual( addr1, m1.get(), length, NULL ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); +// +// hres = dbgExt->dataSpaces->ReadVirtual( addr2, m2.get(), length, NULL ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugDataSpace::ReadVirtual failed" ); +// } +// else +// { +// hres = dbgExt->dataSpaces->ReadPhysical( addr1, m1.get(), length, NULL ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugDataSpace::ReadPhysical failed" ); +// +// hres = dbgExt->dataSpaces->ReadPhysical( addr2, m2.get(), length, NULL ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugDataSpace::ReadPhysical failed" ); +// } +// +// result = memcmp( m1.get(), m2.get(), length ) == 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 result; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadPtrArray( ULONG64 address, ULONG number ) +//{ +// if ( is64bitSystem() ) +// { +// boost::scoped_array buffer(new ULONG64[number]); +// +// loadMemory( address, buffer.get(), number*sizeof(ULONG64) ); +// +// boost::python::list lst; +// +// for ( ULONG i = 0; i < number; ++i ) +// lst.append( buffer[i] ); +// +// return lst; +// } +// else +// { +// boost::scoped_array buffer(new ULONG[number]); +// +// loadMemory( address, buffer.get(), number*sizeof(ULONG) ); +// +// boost::python::list lst; +// +// for ( ULONG i = 0; i < number; ++i ) +// lst.append( addr64( buffer[i] ) ); +// +// return lst; +// } +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) +//{ +// std::vector buffer(number); +// +// if (number) +// loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); +// +// return boost::python::object(std::string( buffer.begin(), buffer.end() ) ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadWChars( ULONG64 address, ULONG number, BOOLEAN phyAddr ) +//{ +// std::vector buffer(number); +// +// loadMemory( address, &buffer[0], (ULONG)buffer.size(), phyAddr ); +// +// return boost::python::object(std::wstring( buffer.begin(), buffer.end() ) ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ULONG64 +//loadPtrByPtr( ULONG64 address ) +//{ +// ULONG64 value = 0; +// +// if ( is64bitSystem() ) +// loadMemory( address, &value, sizeof(ULONG64) ); +// else +// { +// loadMemory( address, &value, sizeof(ULONG) ); +// +// value = addr64( value ); +// } +// +// return value; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ULONG64 +//loadMWord( ULONG64 address ) +//{ +// ULONG64 value = 0; +// +// if ( is64bitSystem() ) +// loadMemory( address, &value, sizeof(ULONG64) ); +// else +// loadMemory( address, &value, sizeof(ULONG) ); +// +// return value; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//LONG64 +//loadSignMWord( ULONG64 address ) +//{ +// LONG64 value = 0; +// +// if ( is64bitSystem() ) +// loadMemory( address, &value, sizeof(LONG64) ); +// else +// loadMemory( address, &value, sizeof(LONG) ); +// +// return value; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//template<> +//boost::python::object +//loadByPtr( ULONG64 address ) +//{ +// char value; +// +// loadMemory( address, &value, sizeof(char) ); +// +// return boost::python::object( (int)value ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadUnicodeStr( ULONG64 address ) +//{ +// USHORT length; +// USHORT maximumLength; +// ULONG64 buffer = 0; +// +// do { +// +// loadMemory( address, &length, sizeof( length ) ); +// +// if ( length == 0 ) +// break; +// +// address += sizeof( length ); +// +// loadMemory( address, &maximumLength, sizeof( maximumLength ) ); +// +// address += sizeof( maximumLength ); +// +// if ( is64bitSystem() ) +// { +// address += address % 8 ? ( 8 - address % 8 ) : 0 ; // выравнивание на 8 байт +// +// loadMemory( address, &buffer, 8 ); +// +// address += 8; +// } +// else +// { +// address += address % 4 ? ( 4 - address % 4 ) : 0 ; // выравнивание на 8 байт +// +// loadMemory( address, &buffer, 4 ); +// +// buffer = addr64( buffer ); +// +// address += 4; +// } +// +// std::vector str(length / 2); +// +// loadMemory( buffer, &str[0], length ); +// +// std::wstring strValue(&str[0], length/2); +// +// return boost::python::object( strValue ); +// +// } while( FALSE ); +// +// return boost::python::object( "" ); +// +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadAnsiStr( ULONG64 address ) +//{ +// USHORT length; +// USHORT maximumLength; +// ULONG64 buffer = 0; +// +// do { +// +// loadMemory( address, &length, sizeof( length ) ); +// +// if ( length == 0 ) +// break; +// +// address += sizeof( length ); +// +// loadMemory( address, &maximumLength, sizeof( maximumLength ) ); +// +// address += sizeof( maximumLength ); +// +// if ( is64bitSystem() ) +// { +// address += address % 8 ? ( 8 - address % 8 ) : 0; // выравнивание на 8 байт +// +// loadMemory( address, &buffer, 8 ); +// +// address += 8; +// } +// else +// { +// address += address % 4 ? ( 4 - address % 4 ) : 0; // выравнивание на 8 байт +// +// loadMemory( address, &buffer, 4 ); +// +// buffer = addr64( buffer ); +// +// address += 4; +// } +// +// +// std::vector str(length); +// +// loadMemory( buffer, &str[0], length ); +// +// std::string strVal ( &str[0], length ); +// +// return boost::python::object( strVal ); +// +// } while( FALSE ); +// +// return boost::python::object( "" ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//void +//loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen ) +//{ +// address = addr64( address ); +// +// HRESULT hres = +// dbgExt->dataSpaces4->ReadMultiByteStringVirtual( +// address, +// bufferLen, +// buffer, +// bufferLen/sizeof(CHAR), +// NULL ); +// +// if ( FAILED( hres ) ) +// throw MemoryException( address ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//void +//loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen ) +//{ +// address = addr64( address ); +// +// HRESULT hres = +// dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( +// address, +// bufferLen, +// buffer, +// bufferLen/sizeof(WCHAR), +// NULL ); +// +// if ( FAILED( hres ) ) +// throw MemoryException( address ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadCStr( ULONG64 address ) +//{ +// const size_t maxLength = 0x1000; +// +// address = addr64( address ); +// +// boost::scoped_array buffer(new char[maxLength]); +// +// HRESULT hres = +// dbgExt->dataSpaces4->ReadMultiByteStringVirtual( +// address, +// maxLength, +// buffer.get(), +// maxLength, +// NULL ); +// +// if ( FAILED( hres ) ) +// throw MemoryException( address ); +// +// return boost::python::object( std::string( buffer.get() ) ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadWStr( ULONG64 address ) +//{ +// const size_t maxLength = 0x1000; +// +// address = addr64( address ); +// +// boost::scoped_array buffer(new wchar_t[maxLength]); +// +// HRESULT hres = +// dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( +// address, +// maxLength*sizeof(wchar_t), +// buffer.get(), +// maxLength, +// NULL ); +// +// if ( FAILED( hres ) ) +// throw MemoryException( address ); +// +// return boost::python::object( std::wstring(buffer.get()) ); +//} +// +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadLinkedList( ULONG64 address ) +//{ +// ULONG64 entryAddress = 0; +// +// boost::python::list objList; +// +// for( entryAddress = loadPtrByPtr( address ); entryAddress != address; entryAddress = loadPtrByPtr( entryAddress ) ) +// objList.append( entryAddress ); +// +// return objList; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//bool +//isOffsetValid( ULONG64 addr ) +//{ +// HRESULT hres; +// +// try { +// +// // нужно подавить возможный вывод в консоль об отсутствующей странице памяти +// OutputReader outputReader( dbgExt->client ); +// +// ULONG offsetInfo; +// +// hres = +// dbgExt->dataSpaces4->GetOffsetInformation( +// DEBUG_DATA_SPACE_VIRTUAL, +// DEBUG_OFFSINFO_VIRTUAL_SOURCE, +// addr, +// &offsetInfo, +// sizeof( offsetInfo ), +// NULL ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugDataSpace4::GetOffsetInformation failed" ); +// +// return offsetInfo != DEBUG_VSOURCE_INVALID; +// +// } +// 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; +//} +// +///////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index d97cc76..4d62b88 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -1,90 +1,90 @@ #pragma once -#include - -///////////////////////////////////////////////////////////////////////////////// - -void -loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr = FALSE ); - -ULONG64 -loadPtrByPtr( ULONG64 address ); - -ULONG64 -loadMWord( ULONG64 address ); - -LONG64 -loadSignMWord( ULONG64 address ); - - -template -boost::python::object -loadArray( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE ) -{ - boost::scoped_array 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 -boost::python::object -loadByPtr( ULONG64 address ) -{ - T value; - - loadMemory( address, &value, sizeof(T) ); - - return boost::python::object( value ); -} - -template<> -boost::python::object -loadByPtr( 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 ); - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void +//loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr = FALSE ); +// +//ULONG64 +//loadPtrByPtr( ULONG64 address ); +// +//ULONG64 +//loadMWord( ULONG64 address ); +// +//LONG64 +//loadSignMWord( ULONG64 address ); +// +// +//template +//boost::python::object +//loadArray( ULONG64 address, ULONG number, BOOLEAN phyAddr = FALSE ) +//{ +// boost::scoped_array 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 +//boost::python::object +//loadByPtr( ULONG64 address ) +//{ +// T value; +// +// loadMemory( address, &value, sizeof(T) ); +// +// return boost::python::object( value ); +//} +// +//template<> +//boost::python::object +//loadByPtr( 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 ); +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmodule.cpp b/pykd/dbgmodule.cpp index 4ca1a06..a7f619f 100644 --- a/pykd/dbgmodule.cpp +++ b/pykd/dbgmodule.cpp @@ -1,345 +1,345 @@ #include "stdafx.h" -#include - -#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 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 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(); -} - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +//#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 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 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(); +//} +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgmodule.h b/pykd/dbgmodule.h index 92d9002..cc6e59a 100644 --- a/pykd/dbgmodule.h +++ b/pykd/dbgmodule.h @@ -1,177 +1,177 @@ #pragma once -#include -#include - -#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 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 +//#include +// +//#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 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 ); +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgpath.cpp b/pykd/dbgpath.cpp index 10be731..4599d51 100644 --- a/pykd/dbgpath.cpp +++ b/pykd/dbgpath.cpp @@ -1,148 +1,148 @@ #include "stdafx.h" -#include "dbgpath.h" - -#include - -/////////////////////////////////////////////////////////////////////////////// - - - -DbgPythonPath::DbgPythonPath() -{ - DWORD enviromentSize = 0; - - enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize ); - - std::vector enviromentBuffer(enviromentSize); - - if (!enviromentBuffer.empty()) - { - GetEnvironmentVariableA( "PYTHONPATH", &enviromentBuffer[0], enviromentSize ); - - typedef boost::escaped_list_separator 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::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( 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 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::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 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 +// +///////////////////////////////////////////////////////////////////////////////// +// +// +// +//DbgPythonPath::DbgPythonPath() +//{ +// DWORD enviromentSize = 0; +// +// enviromentSize = GetEnvironmentVariableA( "PYTHONPATH", NULL, enviromentSize ); +// +// std::vector enviromentBuffer(enviromentSize); +// +// if (!enviromentBuffer.empty()) +// { +// GetEnvironmentVariableA( "PYTHONPATH", &enviromentBuffer[0], enviromentSize ); +// +// typedef boost::escaped_list_separator 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::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( 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 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::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 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; +//} +// +//////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgpath.h b/pykd/dbgpath.h index 3f790f1..f73eb57 100644 --- a/pykd/dbgpath.h +++ b/pykd/dbgpath.h @@ -1,32 +1,32 @@ #pragma once -#include - -/////////////////////////////////////////////////////////////////////////////// - -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; - - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +///////////////////////////////////////////////////////////////////////////////// +// +//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; +// +// +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgprocess.cpp b/pykd/dbgprocess.cpp index 78284fe..c67f2a2 100644 --- a/pykd/dbgprocess.cpp +++ b/pykd/dbgprocess.cpp @@ -1,289 +1,289 @@ #include "stdafx.h" -#include -#include - -#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 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( ¤tScope ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" ); - - boost::scoped_array 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( 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 localSymbols; - CComPtr 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 +//#include +// +//#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 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( ¤tScope ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" ); +// +// boost::scoped_array 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( 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 localSymbols; +// CComPtr 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; +//} +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgprocess.h b/pykd/dbgprocess.h index 1425c7b..1fb0052 100644 --- a/pykd/dbgprocess.h +++ b/pykd/dbgprocess.h @@ -1,54 +1,54 @@ #pragma once -#include - -///////////////////////////////////////////////////////////////////////////////// - -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( this ), 0, sizeof(DEBUG_STACK_FRAME) ); - } - - dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame ); - - std::string - print() const; -}; - +//#include +// +/////////////////////////////////////////////////////////////////////////////////// +// //boost::python::object -std::string -getProcessorMode(); - -void -setProcessorMode( - const std::string &mode ); - -ULONG64 -getCurrentProcess(); - -VOID -setCurrentProcess( - ULONG64 processAddr ); - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//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( 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 ); +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgreg.cpp b/pykd/dbgreg.cpp index b1511bd..0c530d7 100644 --- a/pykd/dbgreg.cpp +++ b/pykd/dbgreg.cpp @@ -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 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 ®isterName ) -{ - HRESULT hres; - - ULONG registerIndex = 0; - - hres = dbgExt->registers->GetIndexByName( registerName.c_str(), ®isterIndex ); - 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 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 ®isterName ) +//{ +// HRESULT hres; +// +// ULONG registerIndex = 0; +// +// hres = dbgExt->registers->GetIndexByName( registerName.c_str(), ®isterIndex ); +// 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" ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgreg.h b/pykd/dbgreg.h index 8ee6d4d..856a1b6 100644 --- a/pykd/dbgreg.h +++ b/pykd/dbgreg.h @@ -1,61 +1,61 @@ #pragma once -#include -#include - -#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 ®isterName ); - -ULONG64 -loadMSR( ULONG msr ); - -void setMSR( ULONG msr, ULONG64 val); - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +//#include +// +//#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 ®isterName ); +// +//ULONG64 +//loadMSR( ULONG msr ); +// +//void setMSR( ULONG msr, ULONG64 val); +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgsym.cpp b/pykd/dbgsym.cpp index b205f97..0fcfcee 100644 --- a/pykd/dbgsym.cpp +++ b/pykd/dbgsym.cpp @@ -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" ); -} - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#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" ); +//} +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgsym.h b/pykd/dbgsym.h index 8fd6b41..7ce45a2 100644 --- a/pykd/dbgsym.h +++ b/pykd/dbgsym.h @@ -1,13 +1,13 @@ #pragma once -#include - -///////////////////////////////////////////////////////////////////////////////// - -boost::python::object -findSymbolForAddress( ULONG64 addr ); - -ULONG64 -findAddressForSymbol( const std::string &moduleName, const std::string &symbolName ); - -///////////////////////////////////////////////////////////////////////////////// +//#include +// +/////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//findSymbolForAddress( ULONG64 addr ); +// +//ULONG64 +//findAddressForSymbol( const std::string &moduleName, const std::string &symbolName ); +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsynsym.cpp b/pykd/dbgsynsym.cpp index 70e2dba..6dcede1 100644 --- a/pykd/dbgsynsym.cpp +++ b/pykd/dbgsynsym.cpp @@ -1,651 +1,651 @@ #include "stdafx.h" -#include -#include -#include -#include - -#include "dbgext.h" -#include "dbgmem.h" -#include "dbgmodule.h" -#include "dbgexcept.h" -#include "dbgsynsym.h" - -///////////////////////////////////////////////////////////////////////////////// - -struct SyntheticSymbol -{ - std::string m_name; - ULONG m_size; - - SyntheticSymbol() - : m_size(0) - { - } - SyntheticSymbol( - const std::string &name - ) : m_name(name) - , m_size(0) - { - } - SyntheticSymbol( - const SyntheticSymbol &rhs - ) : m_name(rhs.m_name) - , m_size(rhs.m_size) - { - } - - bool operator ==(const SyntheticSymbol &rhs) const - { - return m_name == rhs.m_name; - } -}; - -///////////////////////////////////////////////////////////////////////////////// - -// map of one module synthetic symbols -typedef std::map SynSymbolsForModule; - -// global synthetic symbols map by modules -typedef std::map SynSymbolsMap; - -// synchro-object for global synthetic symbols map -typedef boost::interprocess::interprocess_recursive_mutex SynSymbolsMapLockType; -typedef boost::interprocess::interprocess_mutex SynSymbolsMapLockWriteType; - -// scoped lock synchro-object for global synthetic symbols map -typedef boost::interprocess::scoped_lock SynSymbolsMapScopedLock; -typedef boost::interprocess::scoped_lock SynSymbolsMapScopedLockWrite; - -static struct _GlobalSyntheticSymbolMap : public SynSymbolsMap -{ - SynSymbolsMapLockType m_Lock; - SynSymbolsMapLockWriteType m_LockWrite; -} g_SyntheticSymbolMap; - -#define _SynSymbolsMapScopedLock() \ - SynSymbolsMapScopedLock _lock(g_SyntheticSymbolMap.m_Lock) -#define _SynSymbolsMapScopedLockWrite() \ - _SynSymbolsMapScopedLock(); \ - SynSymbolsMapScopedLockWrite _lockw(g_SyntheticSymbolMap.m_LockWrite) - - -///////////////////////////////////////////////////////////////////////////////// - -bool addSyntheticSymbol( - ULONG64 addr, - ULONG size, - const std::string &symName -) -{ - try - { - - DEBUG_MODULE_AND_ID dbgModuleAndId = { 0 }; - addr = addr64(addr); - HRESULT hres = - dbgExt->symbols3->AddSyntheticSymbol( - addr, - size, - symName.c_str(), - DEBUG_ADDSYNTHSYM_DEFAULT, - &dbgModuleAndId); - if ( FAILED( hres ) ) - throw DbgException( "call IDebugSymbol3::AddSyntheticSymbol(...) failed" ); - - DEBUG_MODULE_PARAMETERS dbgModuleParameters; - hres = dbgExt->symbols->GetModuleParameters( - 1, - &dbgModuleAndId.ModuleBase, - 0, - &dbgModuleParameters); - if ( FAILED( hres ) ) - { - dbgExt->symbols3->RemoveSyntheticSymbol(&dbgModuleAndId); - throw DbgException( "call IDebugSymbol3::GetModuleParameters(...) failed" ); - } - - _SynSymbolsMapScopedLockWrite(); - - ModuleInfo moduleInfo(dbgModuleParameters); - SynSymbolsForModule &mapSynSymbolsForModule = - g_SyntheticSymbolMap[moduleInfo]; - - ULONG64 addrSymbolOffset = addr - moduleInfo.m_base; - SyntheticSymbol &synSymbol = mapSynSymbolsForModule[addrSymbolOffset]; - - synSymbol.m_name = symName; - synSymbol.m_size = size; - - 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" ); - } - return false; -} - -///////////////////////////////////////////////////////////////////////////////// - -bool addSyntheticSymbolForModule( - ULONG64 offset, - ULONG size, - const std::string &symName, - const ModuleInfo &moduleInfo -) -{ - try - { - DEBUG_MODULE_AND_ID dbgModuleAndId = { 0 }; - offset = addr64(offset); - HRESULT hres = - dbgExt->symbols3->AddSyntheticSymbol( - offset + moduleInfo.m_base, - size, - symName.c_str(), - DEBUG_ADDSYNTHSYM_DEFAULT, - &dbgModuleAndId); - if ( FAILED( hres ) ) - throw DbgException( "call IDebugSymbol3::AddSyntheticSymbol(...) failed" ); - - { - DEBUG_MODULE_PARAMETERS dbgModuleParameters; - hres = dbgExt->symbols->GetModuleParameters( - 1, - &dbgModuleAndId.ModuleBase, - 0, - &dbgModuleParameters); - if ( FAILED( hres ) ) - { - dbgExt->symbols3->RemoveSyntheticSymbol(&dbgModuleAndId); - throw DbgException( "call IDebugSymbol3::GetModuleParameters(...) failed" ); - } - ModuleInfo gettedModuleInfo(dbgModuleParameters); - if (!(gettedModuleInfo == moduleInfo)) - { - // module mismatch - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd!" __FUNCTION__ " mismatch modules\n" ); - dbgExt->symbols3->RemoveSyntheticSymbol(&dbgModuleAndId); - return false; - } - } - - _SynSymbolsMapScopedLockWrite(); - - SynSymbolsForModule &mapSynSymbolsForModule = - g_SyntheticSymbolMap[moduleInfo]; - - SyntheticSymbol &synSymbol = mapSynSymbolsForModule[offset]; - - synSymbol.m_name = symName; - synSymbol.m_size = size; - - 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" ); - } - return false; -} - -///////////////////////////////////////////////////////////////////////////////// - -struct SynSymbolNameCmp -{ - SynSymbolNameCmp(const std::string &symName ) : m_symName(symName) { } - bool operator() (const std::pair &rhs) const - { - return m_symName == rhs.second.m_name; - } - const std::string &m_symName; -}; - -///////////////////////////////////////////////////////////////////////////////// - -ULONG64 getSyntheticSymbol( - const ModuleInfo &moduleInfo, - const std::string &symName -) -{ - ULONG64 nAddress = 0; - - try - { - _SynSymbolsMapScopedLock(); - - // try find module - SynSymbolsMap::const_iterator itSynSymbols = - g_SyntheticSymbolMap.find( moduleInfo ); - if (itSynSymbols != g_SyntheticSymbolMap.end()) - { - // try find symbol by name - const SynSymbolsForModule &mapSynSymbolsForModule = itSynSymbols->second; - SynSymbolNameCmp nameCmp(symName); - - // FIXME: get first matched by name - SynSymbolsForModule::const_iterator itSynSymbol = - find_if( - mapSynSymbolsForModule.begin(), - mapSynSymbolsForModule.end(), - nameCmp); - if (itSynSymbol != mapSynSymbolsForModule.end()) - nAddress = moduleInfo.m_base + itSynSymbol->first; - } - } - 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 nAddress; -} - -///////////////////////////////////////////////////////////////////////////////// - -// remove synthetic symbols by array of DEBUG_MODULE_AND_ID -inline ULONG RemoveSyntheticSymbols( - const std::vector &arrSymbols -) -{ - ULONG nResult = 0; - for (ULONG i = 0; i < arrSymbols.size(); ++i) - { - HRESULT hres = - dbgExt->symbols3->RemoveSyntheticSymbol( - const_cast(&arrSymbols[i])); - if (FAILED(hres)) - continue; - ++nResult; - } - return nResult; -} - -///////////////////////////////////////////////////////////////////////////////// - -static ULONG RemoveSynSymbolsByAddress(ULONG64 addr) -{ - ULONG nEntries = 0; - dbgExt->symbols3->GetSymbolEntriesByOffset( - addr, - 0, - NULL, - NULL, - 0, - &nEntries); - if (nEntries) - { - std::vector arrSymbols(nEntries); - HRESULT hres = dbgExt->symbols3->GetSymbolEntriesByOffset( - addr, - 0, - &arrSymbols[0], - NULL, - (ULONG)arrSymbols.size(), - NULL); - if (SUCCEEDED(hres)) - return RemoveSyntheticSymbols(arrSymbols); - } - return 0; -} - -///////////////////////////////////////////////////////////////////////////////// - -static void DeleteSynSymbolsForModule( - const std::pair &synSymbolsForModule -) -{ - DEBUG_MODULE_PARAMETERS dbgModuleParameters; - HRESULT hres = dbgExt->symbols->GetModuleParameters( - 1, - const_cast(&synSymbolsForModule.first.m_base), - 0, - &dbgModuleParameters); - if ( FAILED( hres ) ) - return; - ModuleInfo gettedModuleInfo(dbgModuleParameters); - if (gettedModuleInfo == synSymbolsForModule.first) - { - // no clear - global map will be cleared on exit - SynSymbolsForModule::const_iterator itSynSymbol = - synSymbolsForModule.second.begin(); - while (itSynSymbol != synSymbolsForModule.second.end()) - { - RemoveSynSymbolsByAddress( - gettedModuleInfo.m_base + itSynSymbol->first); - ++itSynSymbol; - } - } -} - -///////////////////////////////////////////////////////////////////////////////// - -void delAllSyntheticSymbols() -{ - try - { - _SynSymbolsMapScopedLockWrite(); - - for_each( - g_SyntheticSymbolMap.begin(), - g_SyntheticSymbolMap.end(), - DeleteSynSymbolsForModule); - g_SyntheticSymbolMap.clear(); - } - 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" ); - } -} - -///////////////////////////////////////////////////////////////////////////////// - -void delAllSyntheticSymbolsForModule( - const ModuleInfo &moduleInfo -) -{ - try - { - _SynSymbolsMapScopedLockWrite(); - - SynSymbolsMap::iterator itSynSymbols = - g_SyntheticSymbolMap.find(moduleInfo); - if (itSynSymbols != g_SyntheticSymbolMap.end()) - { - std::pair synSymbolsForModule( - moduleInfo, itSynSymbols->second); - DeleteSynSymbolsForModule(synSymbolsForModule); - g_SyntheticSymbolMap.erase(itSynSymbols); - } - } - 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" ); - } -} - -///////////////////////////////////////////////////////////////////////////////// - -ULONG delSyntheticSymbolForModuleNoLock( - ULONG64 offset, - const ModuleInfo &moduleInfo -) -{ - SynSymbolsMap::iterator itSynSymbols = - g_SyntheticSymbolMap.find(moduleInfo); - if (itSynSymbols != g_SyntheticSymbolMap.end()) - { - offset = addr64(offset); - SynSymbolsForModule::iterator itSynSymbol = - itSynSymbols->second.find( offset ); - if (itSynSymbol != itSynSymbols->second.end()) - { - ULONG nResult = - RemoveSynSymbolsByAddress(moduleInfo.m_base + offset); - itSynSymbols->second.erase(itSynSymbol); - return nResult; - } - } - return 0; -} - -///////////////////////////////////////////////////////////////////////////////// - -ULONG delSyntheticSymbol( - ULONG64 addr -) -{ - try - { - // query module information - addr = addr64(addr); - ULONG64 ptrModuleBase; - HRESULT hres = - dbgExt->symbols->GetModuleByOffset(addr, 0, NULL, &ptrModuleBase); - if ( SUCCEEDED(hres) ) - { - DEBUG_MODULE_PARAMETERS dbgModuleParameters; - hres = - dbgExt->symbols->GetModuleParameters( - 1, - &ptrModuleBase, - 0, - &dbgModuleParameters); - if ( SUCCEEDED(hres) ) - { - _SynSymbolsMapScopedLockWrite(); - - ModuleInfo moduleInfo(dbgModuleParameters); - return - delSyntheticSymbolForModuleNoLock( - addr - moduleInfo.m_base, - moduleInfo); - } - } - } - 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 0; -} - -///////////////////////////////////////////////////////////////////////////////// - -ULONG delSyntheticSymbolForModule( - ULONG64 offset, - const ModuleInfo &moduleInfo -) -{ - try - { - _SynSymbolsMapScopedLockWrite(); - return delSyntheticSymbolForModuleNoLock(offset, moduleInfo); - } - 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 0; -} - -///////////////////////////////////////////////////////////////////////////////// - -// remove synthetic symbols from global map -inline void RemoveSyntheticSymbolsFromMap( - const std::vector &arrSymbols -) -{ - for (ULONG i = 0; i < arrSymbols.size(); ++i) - { - DEBUG_SYMBOL_ENTRY dbgSymbolEntry; - HRESULT hres = dbgExt->symbols3->GetSymbolEntryInformation( - const_cast(&arrSymbols[i]), - &dbgSymbolEntry); - if (FAILED(hres)) - continue; - - DEBUG_MODULE_PARAMETERS dbgModuleParameters; - hres = dbgExt->symbols->GetModuleParameters( - 1, - &dbgSymbolEntry.ModuleBase, - 0, - &dbgModuleParameters); - if (FAILED(hres)) - continue; - - ModuleInfo moduleInfo(dbgModuleParameters); - SynSymbolsMap::iterator itSynSymbols = - g_SyntheticSymbolMap.find(moduleInfo); - if (itSynSymbols != g_SyntheticSymbolMap.end()) - { - ULONG64 offset = dbgSymbolEntry.Offset - dbgSymbolEntry.ModuleBase; - SynSymbolsForModule::iterator itSynSymbol = - itSynSymbols->second.find( offset ); - if (itSynSymbol != itSynSymbols->second.end()) - itSynSymbols->second.erase(itSynSymbol); - } - } -} - -///////////////////////////////////////////////////////////////////////////////// - -ULONG delSyntheticSymbolsMask( - const std::string &moduleName, - const std::string &symName -) -{ - ULONG nResult = 0; - - try - { - std::string symMask = moduleName + "!" + symName; - ULONG nEntries = 0; - dbgExt->symbols3->GetSymbolEntriesByName( - symMask.c_str(), - 0, - NULL, - 0, - &nEntries); - if (nEntries) - { - std::vector arrSymbols(nEntries); - HRESULT hres = dbgExt->symbols3->GetSymbolEntriesByName( - symMask.c_str(), - 0, - &arrSymbols[0], - (ULONG)arrSymbols.size(), - NULL); - if (FAILED(hres)) - throw DbgException( "call IDebugSymbol3::GetSymbolEntriesByOffset(...) failed" ); - - { - _SynSymbolsMapScopedLockWrite(); - RemoveSyntheticSymbolsFromMap(arrSymbols); - } - - return RemoveSyntheticSymbols(arrSymbols); - } - } - 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 nResult; -} - -///////////////////////////////////////////////////////////////////////////////// - -static void restoreSyntheticSymbolForModuleNoLock( - const ModuleInfo &moduleInfo -) -{ - SynSymbolsMap::const_iterator itSynSymbols = - g_SyntheticSymbolMap.find( moduleInfo ); - if (itSynSymbols != g_SyntheticSymbolMap.end()) - { - SynSymbolsForModule::const_iterator itSynSymbol = - itSynSymbols->second.begin(); - while (itSynSymbol != itSynSymbols->second.end()) - { - DEBUG_MODULE_AND_ID dbgModuleAndId; - dbgExt->symbols3->AddSyntheticSymbol( - moduleInfo.m_base + itSynSymbol->first, - itSynSymbol->second.m_size, - itSynSymbol->second.m_name.c_str(), - DEBUG_ADDSYNTHSYM_DEFAULT, - &dbgModuleAndId); - - ++itSynSymbol; - } - } -} - -///////////////////////////////////////////////////////////////////////////////// - -void restoreSyntheticSymbolForModule( - const ModuleInfo &moduleInfo -) -{ - _SynSymbolsMapScopedLock(); - - // see (**1) - restoreSyntheticSymbolForModuleNoLock(moduleInfo); -} - -///////////////////////////////////////////////////////////////////////////////// - -void restoreSyntheticSymbolForAllModules() -{ - try - { - _SynSymbolsMapScopedLock(); - - if (g_SyntheticSymbolMap.empty()) - return; - - ULONG nLoaded; - ULONG nUnloaded; - - HRESULT hres = dbgExt->symbols3->GetNumberModules(&nLoaded, &nUnloaded); - if (SUCCEEDED(hres) && (nLoaded || nUnloaded)) - { - std::vector arrModules(nLoaded + nUnloaded); - hres = - dbgExt->symbols3->GetModuleParameters( - (ULONG)arrModules.size(), - NULL, - 0, - &arrModules[0]); - if (SUCCEEDED(hres)) - { - for (ULONG i = 0; i < arrModules.size(); ++i) - { - ModuleInfo moduleInfo(arrModules[i]); - restoreSyntheticSymbolForModuleNoLock(moduleInfo); - } - } - } - } - catch (...) - { - } -} - -///////////////////////////////////////////////////////////////////////////////// +//#include +//#include +//#include +//#include +// +//#include "dbgext.h" +//#include "dbgmem.h" +//#include "dbgmodule.h" +//#include "dbgexcept.h" +//#include "dbgsynsym.h" +// +/////////////////////////////////////////////////////////////////////////////////// +// +//struct SyntheticSymbol +//{ +// std::string m_name; +// ULONG m_size; +// +// SyntheticSymbol() +// : m_size(0) +// { +// } +// SyntheticSymbol( +// const std::string &name +// ) : m_name(name) +// , m_size(0) +// { +// } +// SyntheticSymbol( +// const SyntheticSymbol &rhs +// ) : m_name(rhs.m_name) +// , m_size(rhs.m_size) +// { +// } +// +// bool operator ==(const SyntheticSymbol &rhs) const +// { +// return m_name == rhs.m_name; +// } +//}; +// +/////////////////////////////////////////////////////////////////////////////////// +// +//// map of one module synthetic symbols +//typedef std::map SynSymbolsForModule; +// +//// global synthetic symbols map by modules +//typedef std::map SynSymbolsMap; +// +//// synchro-object for global synthetic symbols map +//typedef boost::interprocess::interprocess_recursive_mutex SynSymbolsMapLockType; +//typedef boost::interprocess::interprocess_mutex SynSymbolsMapLockWriteType; +// +//// scoped lock synchro-object for global synthetic symbols map +//typedef boost::interprocess::scoped_lock SynSymbolsMapScopedLock; +//typedef boost::interprocess::scoped_lock SynSymbolsMapScopedLockWrite; +// +//static struct _GlobalSyntheticSymbolMap : public SynSymbolsMap +//{ +// SynSymbolsMapLockType m_Lock; +// SynSymbolsMapLockWriteType m_LockWrite; +//} g_SyntheticSymbolMap; +// +//#define _SynSymbolsMapScopedLock() \ +// SynSymbolsMapScopedLock _lock(g_SyntheticSymbolMap.m_Lock) +//#define _SynSymbolsMapScopedLockWrite() \ +// _SynSymbolsMapScopedLock(); \ +// SynSymbolsMapScopedLockWrite _lockw(g_SyntheticSymbolMap.m_LockWrite) +// +// +/////////////////////////////////////////////////////////////////////////////////// +// +//bool addSyntheticSymbol( +// ULONG64 addr, +// ULONG size, +// const std::string &symName +//) +//{ +// try +// { +// +// DEBUG_MODULE_AND_ID dbgModuleAndId = { 0 }; +// addr = addr64(addr); +// HRESULT hres = +// dbgExt->symbols3->AddSyntheticSymbol( +// addr, +// size, +// symName.c_str(), +// DEBUG_ADDSYNTHSYM_DEFAULT, +// &dbgModuleAndId); +// if ( FAILED( hres ) ) +// throw DbgException( "call IDebugSymbol3::AddSyntheticSymbol(...) failed" ); +// +// DEBUG_MODULE_PARAMETERS dbgModuleParameters; +// hres = dbgExt->symbols->GetModuleParameters( +// 1, +// &dbgModuleAndId.ModuleBase, +// 0, +// &dbgModuleParameters); +// if ( FAILED( hres ) ) +// { +// dbgExt->symbols3->RemoveSyntheticSymbol(&dbgModuleAndId); +// throw DbgException( "call IDebugSymbol3::GetModuleParameters(...) failed" ); +// } +// +// _SynSymbolsMapScopedLockWrite(); +// +// ModuleInfo moduleInfo(dbgModuleParameters); +// SynSymbolsForModule &mapSynSymbolsForModule = +// g_SyntheticSymbolMap[moduleInfo]; +// +// ULONG64 addrSymbolOffset = addr - moduleInfo.m_base; +// SyntheticSymbol &synSymbol = mapSynSymbolsForModule[addrSymbolOffset]; +// +// synSymbol.m_name = symName; +// synSymbol.m_size = size; +// +// 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" ); +// } +// return false; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//bool addSyntheticSymbolForModule( +// ULONG64 offset, +// ULONG size, +// const std::string &symName, +// const ModuleInfo &moduleInfo +//) +//{ +// try +// { +// DEBUG_MODULE_AND_ID dbgModuleAndId = { 0 }; +// offset = addr64(offset); +// HRESULT hres = +// dbgExt->symbols3->AddSyntheticSymbol( +// offset + moduleInfo.m_base, +// size, +// symName.c_str(), +// DEBUG_ADDSYNTHSYM_DEFAULT, +// &dbgModuleAndId); +// if ( FAILED( hres ) ) +// throw DbgException( "call IDebugSymbol3::AddSyntheticSymbol(...) failed" ); +// +// { +// DEBUG_MODULE_PARAMETERS dbgModuleParameters; +// hres = dbgExt->symbols->GetModuleParameters( +// 1, +// &dbgModuleAndId.ModuleBase, +// 0, +// &dbgModuleParameters); +// if ( FAILED( hres ) ) +// { +// dbgExt->symbols3->RemoveSyntheticSymbol(&dbgModuleAndId); +// throw DbgException( "call IDebugSymbol3::GetModuleParameters(...) failed" ); +// } +// ModuleInfo gettedModuleInfo(dbgModuleParameters); +// if (!(gettedModuleInfo == moduleInfo)) +// { +// // module mismatch +// dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd!" __FUNCTION__ " mismatch modules\n" ); +// dbgExt->symbols3->RemoveSyntheticSymbol(&dbgModuleAndId); +// return false; +// } +// } +// +// _SynSymbolsMapScopedLockWrite(); +// +// SynSymbolsForModule &mapSynSymbolsForModule = +// g_SyntheticSymbolMap[moduleInfo]; +// +// SyntheticSymbol &synSymbol = mapSynSymbolsForModule[offset]; +// +// synSymbol.m_name = symName; +// synSymbol.m_size = size; +// +// 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" ); +// } +// return false; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//struct SynSymbolNameCmp +//{ +// SynSymbolNameCmp(const std::string &symName ) : m_symName(symName) { } +// bool operator() (const std::pair &rhs) const +// { +// return m_symName == rhs.second.m_name; +// } +// const std::string &m_symName; +//}; +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG64 getSyntheticSymbol( +// const ModuleInfo &moduleInfo, +// const std::string &symName +//) +//{ +// ULONG64 nAddress = 0; +// +// try +// { +// _SynSymbolsMapScopedLock(); +// +// // try find module +// SynSymbolsMap::const_iterator itSynSymbols = +// g_SyntheticSymbolMap.find( moduleInfo ); +// if (itSynSymbols != g_SyntheticSymbolMap.end()) +// { +// // try find symbol by name +// const SynSymbolsForModule &mapSynSymbolsForModule = itSynSymbols->second; +// SynSymbolNameCmp nameCmp(symName); +// +// // FIXME: get first matched by name +// SynSymbolsForModule::const_iterator itSynSymbol = +// find_if( +// mapSynSymbolsForModule.begin(), +// mapSynSymbolsForModule.end(), +// nameCmp); +// if (itSynSymbol != mapSynSymbolsForModule.end()) +// nAddress = moduleInfo.m_base + itSynSymbol->first; +// } +// } +// 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 nAddress; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//// remove synthetic symbols by array of DEBUG_MODULE_AND_ID +//inline ULONG RemoveSyntheticSymbols( +// const std::vector &arrSymbols +//) +//{ +// ULONG nResult = 0; +// for (ULONG i = 0; i < arrSymbols.size(); ++i) +// { +// HRESULT hres = +// dbgExt->symbols3->RemoveSyntheticSymbol( +// const_cast(&arrSymbols[i])); +// if (FAILED(hres)) +// continue; +// ++nResult; +// } +// return nResult; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//static ULONG RemoveSynSymbolsByAddress(ULONG64 addr) +//{ +// ULONG nEntries = 0; +// dbgExt->symbols3->GetSymbolEntriesByOffset( +// addr, +// 0, +// NULL, +// NULL, +// 0, +// &nEntries); +// if (nEntries) +// { +// std::vector arrSymbols(nEntries); +// HRESULT hres = dbgExt->symbols3->GetSymbolEntriesByOffset( +// addr, +// 0, +// &arrSymbols[0], +// NULL, +// (ULONG)arrSymbols.size(), +// NULL); +// if (SUCCEEDED(hres)) +// return RemoveSyntheticSymbols(arrSymbols); +// } +// return 0; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//static void DeleteSynSymbolsForModule( +// const std::pair &synSymbolsForModule +//) +//{ +// DEBUG_MODULE_PARAMETERS dbgModuleParameters; +// HRESULT hres = dbgExt->symbols->GetModuleParameters( +// 1, +// const_cast(&synSymbolsForModule.first.m_base), +// 0, +// &dbgModuleParameters); +// if ( FAILED( hres ) ) +// return; +// ModuleInfo gettedModuleInfo(dbgModuleParameters); +// if (gettedModuleInfo == synSymbolsForModule.first) +// { +// // no clear - global map will be cleared on exit +// SynSymbolsForModule::const_iterator itSynSymbol = +// synSymbolsForModule.second.begin(); +// while (itSynSymbol != synSymbolsForModule.second.end()) +// { +// RemoveSynSymbolsByAddress( +// gettedModuleInfo.m_base + itSynSymbol->first); +// ++itSynSymbol; +// } +// } +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void delAllSyntheticSymbols() +//{ +// try +// { +// _SynSymbolsMapScopedLockWrite(); +// +// for_each( +// g_SyntheticSymbolMap.begin(), +// g_SyntheticSymbolMap.end(), +// DeleteSynSymbolsForModule); +// g_SyntheticSymbolMap.clear(); +// } +// 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" ); +// } +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void delAllSyntheticSymbolsForModule( +// const ModuleInfo &moduleInfo +//) +//{ +// try +// { +// _SynSymbolsMapScopedLockWrite(); +// +// SynSymbolsMap::iterator itSynSymbols = +// g_SyntheticSymbolMap.find(moduleInfo); +// if (itSynSymbols != g_SyntheticSymbolMap.end()) +// { +// std::pair synSymbolsForModule( +// moduleInfo, itSynSymbols->second); +// DeleteSynSymbolsForModule(synSymbolsForModule); +// g_SyntheticSymbolMap.erase(itSynSymbols); +// } +// } +// 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" ); +// } +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG delSyntheticSymbolForModuleNoLock( +// ULONG64 offset, +// const ModuleInfo &moduleInfo +//) +//{ +// SynSymbolsMap::iterator itSynSymbols = +// g_SyntheticSymbolMap.find(moduleInfo); +// if (itSynSymbols != g_SyntheticSymbolMap.end()) +// { +// offset = addr64(offset); +// SynSymbolsForModule::iterator itSynSymbol = +// itSynSymbols->second.find( offset ); +// if (itSynSymbol != itSynSymbols->second.end()) +// { +// ULONG nResult = +// RemoveSynSymbolsByAddress(moduleInfo.m_base + offset); +// itSynSymbols->second.erase(itSynSymbol); +// return nResult; +// } +// } +// return 0; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG delSyntheticSymbol( +// ULONG64 addr +//) +//{ +// try +// { +// // query module information +// addr = addr64(addr); +// ULONG64 ptrModuleBase; +// HRESULT hres = +// dbgExt->symbols->GetModuleByOffset(addr, 0, NULL, &ptrModuleBase); +// if ( SUCCEEDED(hres) ) +// { +// DEBUG_MODULE_PARAMETERS dbgModuleParameters; +// hres = +// dbgExt->symbols->GetModuleParameters( +// 1, +// &ptrModuleBase, +// 0, +// &dbgModuleParameters); +// if ( SUCCEEDED(hres) ) +// { +// _SynSymbolsMapScopedLockWrite(); +// +// ModuleInfo moduleInfo(dbgModuleParameters); +// return +// delSyntheticSymbolForModuleNoLock( +// addr - moduleInfo.m_base, +// moduleInfo); +// } +// } +// } +// 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 0; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG delSyntheticSymbolForModule( +// ULONG64 offset, +// const ModuleInfo &moduleInfo +//) +//{ +// try +// { +// _SynSymbolsMapScopedLockWrite(); +// return delSyntheticSymbolForModuleNoLock(offset, moduleInfo); +// } +// 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 0; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//// remove synthetic symbols from global map +//inline void RemoveSyntheticSymbolsFromMap( +// const std::vector &arrSymbols +//) +//{ +// for (ULONG i = 0; i < arrSymbols.size(); ++i) +// { +// DEBUG_SYMBOL_ENTRY dbgSymbolEntry; +// HRESULT hres = dbgExt->symbols3->GetSymbolEntryInformation( +// const_cast(&arrSymbols[i]), +// &dbgSymbolEntry); +// if (FAILED(hres)) +// continue; +// +// DEBUG_MODULE_PARAMETERS dbgModuleParameters; +// hres = dbgExt->symbols->GetModuleParameters( +// 1, +// &dbgSymbolEntry.ModuleBase, +// 0, +// &dbgModuleParameters); +// if (FAILED(hres)) +// continue; +// +// ModuleInfo moduleInfo(dbgModuleParameters); +// SynSymbolsMap::iterator itSynSymbols = +// g_SyntheticSymbolMap.find(moduleInfo); +// if (itSynSymbols != g_SyntheticSymbolMap.end()) +// { +// ULONG64 offset = dbgSymbolEntry.Offset - dbgSymbolEntry.ModuleBase; +// SynSymbolsForModule::iterator itSynSymbol = +// itSynSymbols->second.find( offset ); +// if (itSynSymbol != itSynSymbols->second.end()) +// itSynSymbols->second.erase(itSynSymbol); +// } +// } +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG delSyntheticSymbolsMask( +// const std::string &moduleName, +// const std::string &symName +//) +//{ +// ULONG nResult = 0; +// +// try +// { +// std::string symMask = moduleName + "!" + symName; +// ULONG nEntries = 0; +// dbgExt->symbols3->GetSymbolEntriesByName( +// symMask.c_str(), +// 0, +// NULL, +// 0, +// &nEntries); +// if (nEntries) +// { +// std::vector arrSymbols(nEntries); +// HRESULT hres = dbgExt->symbols3->GetSymbolEntriesByName( +// symMask.c_str(), +// 0, +// &arrSymbols[0], +// (ULONG)arrSymbols.size(), +// NULL); +// if (FAILED(hres)) +// throw DbgException( "call IDebugSymbol3::GetSymbolEntriesByOffset(...) failed" ); +// +// { +// _SynSymbolsMapScopedLockWrite(); +// RemoveSyntheticSymbolsFromMap(arrSymbols); +// } +// +// return RemoveSyntheticSymbols(arrSymbols); +// } +// } +// 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 nResult; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//static void restoreSyntheticSymbolForModuleNoLock( +// const ModuleInfo &moduleInfo +//) +//{ +// SynSymbolsMap::const_iterator itSynSymbols = +// g_SyntheticSymbolMap.find( moduleInfo ); +// if (itSynSymbols != g_SyntheticSymbolMap.end()) +// { +// SynSymbolsForModule::const_iterator itSynSymbol = +// itSynSymbols->second.begin(); +// while (itSynSymbol != itSynSymbols->second.end()) +// { +// DEBUG_MODULE_AND_ID dbgModuleAndId; +// dbgExt->symbols3->AddSyntheticSymbol( +// moduleInfo.m_base + itSynSymbol->first, +// itSynSymbol->second.m_size, +// itSynSymbol->second.m_name.c_str(), +// DEBUG_ADDSYNTHSYM_DEFAULT, +// &dbgModuleAndId); +// +// ++itSynSymbol; +// } +// } +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void restoreSyntheticSymbolForModule( +// const ModuleInfo &moduleInfo +//) +//{ +// _SynSymbolsMapScopedLock(); +// +// // see (**1) +// restoreSyntheticSymbolForModuleNoLock(moduleInfo); +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void restoreSyntheticSymbolForAllModules() +//{ +// try +// { +// _SynSymbolsMapScopedLock(); +// +// if (g_SyntheticSymbolMap.empty()) +// return; +// +// ULONG nLoaded; +// ULONG nUnloaded; +// +// HRESULT hres = dbgExt->symbols3->GetNumberModules(&nLoaded, &nUnloaded); +// if (SUCCEEDED(hres) && (nLoaded || nUnloaded)) +// { +// std::vector arrModules(nLoaded + nUnloaded); +// hres = +// dbgExt->symbols3->GetModuleParameters( +// (ULONG)arrModules.size(), +// NULL, +// 0, +// &arrModules[0]); +// if (SUCCEEDED(hres)) +// { +// for (ULONG i = 0; i < arrModules.size(); ++i) +// { +// ModuleInfo moduleInfo(arrModules[i]); +// restoreSyntheticSymbolForModuleNoLock(moduleInfo); +// } +// } +// } +// } +// catch (...) +// { +// } +//} +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsynsym.h b/pykd/dbgsynsym.h index 16abe6a..b2e9f49 100644 --- a/pykd/dbgsynsym.h +++ b/pykd/dbgsynsym.h @@ -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(); +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsystem.cpp b/pykd/dbgsystem.cpp index 25f003a..ac17891 100644 --- a/pykd/dbgsystem.cpp +++ b/pykd/dbgsystem.cpp @@ -1,210 +1,210 @@ #include "stdafx.h" -#include -#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 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 +//#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 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; +//} +// +///////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgsystem.h b/pykd/dbgsystem.h index 7b52da9..41a0c27 100644 --- a/pykd/dbgsystem.h +++ b/pykd/dbgsystem.h @@ -1,31 +1,31 @@ #pragma once -#include - -///////////////////////////////////////////////////////////////////////////////// - -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(); - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +/////////////////////////////////////////////////////////////////////////////////// +// +//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(); +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgtype.cpp b/pykd/dbgtype.cpp index bca22ae..280e3f0 100644 --- a/pykd/dbgtype.cpp +++ b/pykd/dbgtype.cpp @@ -1,1113 +1,1113 @@ #include "stdafx.h" -#include - -#include - -#include "dbgext.h" -#include "dbgtype.h" -#include "dbgexcept.h" -#include "dbgmem.h" -#include "dbgsystem.h" -#include "dbgmem.h" - -using namespace std; - -/////////////////////////////////////////////////////////////////////////////////// - -TypeInfo::TypeInfoMap TypeInfo::g_typeInfoCache; - -/////////////////////////////////////////////////////////////////////////////////// - -TypeInfo::TypeInfo( const std::string &moduleName, const std::string &typeName ) - : m_align(0) - , m_alignReq(1) -{ - HRESULT hres; - bool baseType = checkBaseType(typeName); - - TypeInfoMap::iterator findIt = baseType ? - g_typeInfoCache.find( std::make_pair("",typeName) ) : - g_typeInfoCache.find( std::make_pair(moduleName,typeName) ); - - if ( findIt != g_typeInfoCache.end() ) - { - *this = findIt->second; - return; - } - - m_typeName = typeName; - - m_isPointer = false; - m_isBaseType = false; - m_isFreezed = true; - m_parentOffset = 0; - - if ( !baseType ) - m_moduleName = moduleName; - - do { - - if ( typeName.find("*") < typeName.size() ) - { - m_isPointer = true; - m_size = ptrSize(); - break; - } - - if ( baseType ) - { - m_isBaseType = true; - m_size = getBaseTypeSize( typeName ); - break; - } - - ULONG64 moduleBase = 0; - hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); - if ( FAILED( hres ) ) - throw TypeException(); - - ULONG typeId = 0; - hres = dbgExt->symbols->GetTypeId( moduleBase, m_typeName.c_str(), &typeId ); - if ( FAILED( hres ) ) - throw TypeException(); - - hres = dbgExt->symbols->GetTypeSize( moduleBase, typeId, &m_size ); - if ( FAILED( hres ) ) - throw TypeException(); - - for ( ULONG i = 0; ; ++i ) - { - char fieldName[100]; - hres = dbgExt->symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL ); - if ( FAILED( hres ) ) - break; - - ULONG fieldTypeId; - ULONG fieldOffset; - hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset ); - - if ( FAILED( hres ) ) - throw TypeException(); - - ULONG fieldSize; - hres = dbgExt->symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize ); - if ( FAILED( hres ) ) - throw TypeException(); - - char fieldTypeName[100]; - hres = dbgExt->symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL ); - if ( FAILED( hres ) ) - throw TypeException(); - - std::string fieldTypeNameStr( fieldTypeName ); - - if ( fieldTypeNameStr == "__unnamed" - || fieldTypeNameStr.find("") < fieldTypeNameStr.size() ) - { - addField( fieldName, TypeInfo( moduleName, moduleBase, fieldTypeId ), fieldSize, fieldOffset ); - } - else - { - addField( fieldName, TypeInfo( moduleName, fieldTypeName ), fieldSize, fieldOffset ); - } - } - - } while( FALSE ); - - m_arraySize = m_size; - - g_typeInfoCache.insert( std::make_pair( std::make_pair( m_moduleName, m_typeName), *this) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypeInfo::TypeInfo( const std::string &moduleName, ULONG64 moduleBase, ULONG typeId ) - : m_align(0) - , m_alignReq(1) -{ - HRESULT hres; - - m_isPointer = false; - m_isBaseType = false; - m_isFreezed = true; - m_parentOffset = 0; - - hres = dbgExt->symbols->GetTypeSize( moduleBase, typeId, &m_size ); - if ( FAILED( hres ) ) - throw TypeException(); - - for ( ULONG i = 0; ; ++i ) - { - char fieldName[100]; - hres = dbgExt->symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL ); - if ( FAILED( hres ) ) - break; - - ULONG fieldTypeId; - ULONG fieldOffset; - hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset ); - - if ( FAILED( hres ) ) - throw TypeException(); - - ULONG fieldSize; - hres = dbgExt->symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize ); - if ( FAILED( hres ) ) - throw TypeException(); - - char fieldTypeName[100]; - hres = dbgExt->symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL ); - if ( FAILED( hres ) ) - throw TypeException(); - - std::string fieldTypeNameStr( fieldTypeName ); - - if ( fieldTypeNameStr == "__unnamed" - || fieldTypeNameStr.find("") < fieldTypeNameStr.size() ) - { - addField( fieldName, TypeInfo( moduleName, moduleBase, fieldTypeId ), fieldSize, fieldOffset ); - } - else - { - addField( fieldName, TypeInfo( moduleName, fieldTypeName ), fieldSize, fieldOffset ); - } - } - - m_arraySize = m_size; -} - -/////////////////////////////////////////////////////////////////////////////////// - -const TypeInfo& -TypeInfo::get( const std::string &moduleName, const std::string &typeName ) -{ - TypeInfoMap::iterator findIt = g_typeInfoCache.find( std::make_pair(moduleName,typeName) ); - - if ( findIt != g_typeInfoCache.end() ) - return findIt->second; - - TypeInfo type( moduleName, typeName ); - - return g_typeInfoCache.insert( std::make_pair( std::make_pair( moduleName, typeName), type) ).first->second; -} - -/////////////////////////////////////////////////////////////////////////////////// - -std::string -TypeInfo::print() const -{ - std::stringstream sstream; - - if ( m_typeName.size() != 0 ) - { - if ( m_moduleName.size() != 0 ) - sstream << m_moduleName << "!"; - - sstream << m_typeName; - } - else - sstream << "unnamed"; - - if ( m_arraySize > m_size ) - { - sstream << " size = " << dec << m_arraySize << "(0x" << hex << m_arraySize << ") " << dec << "[" << m_arraySize/m_size << "]"; - } - else - { - sstream << " size = " << dec << m_size << "(0x" << hex << m_size << ")" << endl; - } - - TypeFieldList::const_iterator it = m_fields.begin(); - for(;it != m_fields.end(); ++it ) - { - sstream << "\t" << it->print() << std::endl; - } - - return sstream.str(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypeInfo -TypeInfo::getField( const std::string &fieldName ) const -{ - TypeFieldList::const_iterator it = m_fields.begin(); - for(;it != m_fields.end(); ++it ) - { - if ( it->name == fieldName ) - { - TypeInfo tinf = it->type; - - tinf.m_parentOffset = m_parentOffset + it->offset; - tinf.m_arraySize = it->size; - - return tinf; - } - } - - throw TypeException(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypeInfo -TypeInfo::getFieldAt( size_t index ) const -{ - TypeInfo tinf = m_fields[index].type; - - tinf.m_parentOffset = m_parentOffset + m_fields[index].offset; - tinf.m_arraySize = m_fields[index].size; - - return tinf; -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -TypeInfo::getFieldByIndex( boost::python::object &obj ) const -{ - if ( PyInt_Check( obj.ptr() ) ) - { - long index = PyInt_AsLong(obj.ptr()); - - if ( index > (long)m_fields.size() ) - throw IndexException(); - - if ( index < 0 ) - { - index = (long)m_fields.size() - abs(index); - if ( index < 0 ) - throw IndexException(); - } - - TypeInfo tinf = m_fields[index].type; - tinf.m_parentOffset = m_fields[index].offset; - return boost::python::object( tinf ); - } - else - { - boost::python::slice sl( boost::python::detail::borrowed_reference( obj.ptr() ) ); - - boost::python::slice::range< TypeFieldList::const_iterator > bounds; - - bounds = sl.get_indicies( m_fields.begin(), m_fields.end() ); - - boost::python::list valList; - - do { - - TypeInfo tinf = bounds.start->type; - tinf.m_parentOffset = bounds.start->offset; - - valList.append( tinf ); - - if ( bounds.start == bounds.stop) - break; - - std::advance( bounds.start, bounds.step); - - } while( true ); - - return valList; - } - - throw IndexException(); - - return boost::python::object(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -void -TypeInfo::appendField( const TypeInfo &typeInfo, const std::string &fieldName, ULONG count ) -{ - if ( m_isFreezed ) - throw TypeException(); - - if ( count == 0 ) - throw TypeException(); - - if ( count == 1 && typeInfo.m_typeName.find("[]") != std::string::npos ) - throw TypeException(); - - TypeFieldList::const_iterator it = m_fields.begin(); - for(;it != m_fields.end(); ++it ) - { - if ( it->name == fieldName ) - throw TypeException(); - } - - if ( count > 1 && typeInfo.m_typeName.find("[]") == std::string::npos ) - { - TypeInfo arrayInfo( typeInfo ); - arrayInfo.m_typeName += "[]"; - appendField( arrayInfo, fieldName, count ); - return; - } - - ULONG offset = m_size; - offset += offset % ( m_align ? m_align : typeInfo.getAlignReq() ); - - const ULONG addSize = typeInfo.size() * count; - addField( fieldName, typeInfo, addSize, offset ); - m_size = offset + addSize; - m_arraySize = offset + addSize; -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -TypeInfo::loadVar( ULONG64 targetOffset, ULONG count ) const -{ - if ( count == 0 ) - throw TypeException(); - - if ( count == 1 ) - { - boost::python::object obj( TypedVar( *this, targetOffset ) ); - - return obj; - } - else - { - boost::python::list lst; - - for( ULONG i = 0; i < count; ++i ) - lst.append( TypedVar( *this, targetOffset + m_size*i ) ); - - return lst; - } -} - -/////////////////////////////////////////////////////////////////////////////////// - -template< typename valType> -boost::python::object -valueLoader( void* address, size_t size ) -{ - if ( size == sizeof(valType) ) - { - valType v = *(valType*)address; - - return boost::python::object( v ); - } - else - { - boost::python::list arr; - - for ( unsigned int i = 0; i < size / sizeof(valType); ++i ) - { - valType v = *( (valType*)address + i ); - arr.append( v ); - } - - return arr; - } - - throw TypeException(); -} - -template<> -boost::python::object -valueLoader( void* address, size_t size ) -{ - if ( size == sizeof(char) ) - { - int v = *(char*)address; - - return boost::python::object( v ); - } - else - { - boost::python::list arr; - - for ( unsigned int i = 0; i < size / sizeof(char); ++i ) - { - int v = *( (char*)address + i ); - arr.append( v ); - } - - return arr; - } - - throw TypeException(); -} - - -template<> -boost::python::object -valueLoader( void* address, size_t size ) -{ - - if ( is64bitSystem() ) - { - if ( size == sizeof(ULONG64) ) - { - return boost::python::object( *(PULONG64)address ); - } - else - { - boost::python::list arr; - - for ( unsigned int i = 0; i < size / sizeof(ULONG64); ++i ) - { - ULONG64 v = *( (PULONG64)address + i ); - arr.append( v ); - } - - return arr; - } - } - else - { - if ( size == sizeof(ULONG) ) - { - return boost::python::object( addr64( *(PULONG)address ) ); - } - else - { - boost::python::list arr; - - for ( unsigned int i = 0; i < size / sizeof(ULONG); ++i ) - { - ULONG64 v = addr64(*( (PULONG)address + i ) ); - arr.append( v ); - } - - return arr; - } - } - - throw TypeException(); -} - -template<> -boost::python::object -valueLoader( void* address, size_t size ) -{ - return boost::python::object(); -} - - - -template -std::string -valuePrinter( void* address, size_t size ) -{ - std::stringstream sstr; - - if ( size == sizeof(valType) ) - { - valType v = *(valType*)address; - - sstr << v << hex << " (0x" << v << ")"; - } - else - { - - for ( unsigned int i = 0; i < size / sizeof(valType); ++i ) - { - valType v = *( (valType*)address + i ); - sstr << endl << "\t[" << dec << i << "] " << dec << v << " (" << hex << v << ")"; - } - } - - return sstr.str(); -} - -template<> -std::string -valuePrinter( void* address, size_t size ) -{ - if ( is64bitSystem() ) - { - return valuePrinter( address, size ); - } - - return valuePrinter( address, size ); -} - -template <> -std::string -valuePrinter( void* address, size_t size ) -{ - std::stringstream sstr; - - if ( size == sizeof(unsigned char) ) - { - unsigned int v = *(unsigned char*)address; - - sstr << v; - } - else - { - - for ( unsigned int i = 0; i < size / sizeof(unsigned char); ++i ) - { - unsigned int v = *( (unsigned char*)address + i ); - sstr << endl << "\t[" << dec << i << "] " << dec << v << " (" << hex << v << ")"; - } - } - - return sstr.str(); -} - - -template <> -std::string -valuePrinter( void* address, size_t size ) -{ - std::stringstream sstr; - - if ( size == sizeof(unsigned char) ) - { - int v = *(char*)address; - - sstr << v; - } - else - { - - for ( unsigned int i = 0; i < size / sizeof(unsigned char); ++i ) - { - int v = *( (char*)address + i ); - sstr << endl << "\t[" << dec << i << "] " << dec << v << " (" << hex << v << ")"; - } - } - - return sstr.str(); -} - - -template<> -std::string -valuePrinter( void* address, size_t size ) -{ - return ""; -} - - -const char* TypeInfo::basicTypeNames[] = { - "unsigned char", - "char", - "unsigned short", - "short", - "unsigned long", - "long", - "int", - "unsigned int", - "", - "void", - "double", - "int64", - "unsigned int64", - "ptr" -}; - - -size_t TypeInfo::basicTypeSizes[] = { - sizeof( unsigned char ), - sizeof( char ), - sizeof( unsigned short ), - sizeof( short ), - sizeof( unsigned long ), - sizeof( long ), - sizeof( int ), - sizeof( unsigned int ), - sizeof( void* ), - 0, - sizeof( double ), - sizeof( __int64 ), - sizeof( unsigned __int64 ) -}; - - -TypeInfo::basicTypeLoader TypeInfo::basicTypeLoaders[] = { - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader, - valueLoader<__int64>, - valueLoader - }; - -TypeInfo::basicTypePrinter TypeInfo::basicTypePrinters[] = { - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter, - valuePrinter<__int64>, - valuePrinter -}; - -bool -TypeInfo::checkBaseType( const std::string &typeName ) -{ - for ( int i = 0; i < sizeof( basicTypeNames ) / sizeof( char* ); ++i ) - { - if ( typeName == basicTypeNames[i] ) - return true; - - if ( typeName == ( std::string( basicTypeNames[i] ) + "*" ) ) - return true; - - if ( typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) - return true; - - if ( typeName == ( std::string( basicTypeNames[i] ) + "*[]" ) ) - return true; - } - - return false; -} - -/////////////////////////////////////////////////////////////////////////////////// - -ULONG -TypeInfo::getBaseTypeSize( const std::string &typeName ) -{ - for ( int i = 0; i < sizeof( basicTypeSizes ) / sizeof( size_t ); ++i ) - { - if ( typeName == basicTypeNames[i] || - typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) - { - return (ULONG)basicTypeSizes[i]; - } - } - - return 0; -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -TypeInfo::load( void* buffer, size_t bufferLength ) const -{ - if ( bufferLength < m_size ) - throw TypeException(); - - if ( m_isPointer ) - { - return valueLoader( buffer, bufferLength ); - } - - if ( m_isBaseType ) - { - for ( int i = 0; i < sizeof( basicTypeNames ) / sizeof( char* ); ++i ) - { - if ( m_typeName == basicTypeNames[i] ) - return basicTypeLoaders[i]( buffer, m_size ); - - if ( m_typeName == ( std::string( basicTypeNames[i] ) + "*" ) ) - return valueLoader( buffer, ptrSize() ); - - if ( m_typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) - return basicTypeLoaders[i]( buffer, m_arraySize ); - - if ( m_typeName == ( std::string( basicTypeNames[i] ) + "*[]" ) ) - return valueLoader( buffer, ptrSize()*count() ); - } - } - - if ( isEnum() ) - { - return valueLoader( buffer, bufferLength ); - } - - throw TypeException(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -template<> -std::string -TypeInfo::TypeField::print() const -{ - std::stringstream sstr; - - sstr << hex << "+" << offset << " "; - sstr << type.m_typeName << " "; - sstr << name; - - return sstr.str(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -std::string -TypeInfo::printField( size_t index, void* buffer, size_t bufferLength ) const -{ - stringstream sstr; - const TypeField &field = m_fields[index]; - const TypeInfo &fieldType = field.type; - ULONG offset = field.offset; - ULONG count = field.size / fieldType.size(); - - if ( fieldType.m_isPointer ) - { - sstr << hex << "+" << offset; - sstr << " " << field.name; - sstr << " " << fieldType.name(); - sstr << " " << hex << valuePrinter( (char*)buffer + offset, field.size ); - sstr << endl; - return sstr.str(); - } - - if ( fieldType.m_isBaseType ) - { - for ( int i = 0; i < sizeof( basicTypeNames ) / sizeof( char* ); ++i ) - { - if ( fieldType.m_typeName == basicTypeNames[i] || - fieldType.m_typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) - { - sstr << hex << "+" << offset; - sstr << " " << field.name; - sstr << " " << fieldType.name(); - sstr << " " << basicTypePrinters[i]( (char*)buffer + offset, field.size ); - sstr << endl; - return sstr.str(); - } - } - - throw TypeException(); - } - - if ( count == 1 ) - { - sstr << hex << "+" << offset; - sstr << " " << field.name; - sstr << " " << fieldType.name(); - sstr << endl; - } - else - { - sstr << hex << "+" << offset; - sstr << " " << field.name; - sstr << " " << fieldType.name() << "[" << dec << count << "]"; - sstr << endl; - } - - return sstr.str(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVar::TypedVar( ULONG64 targetOffset ) : - m_targetOffset( addr64(targetOffset) ) -{ - HRESULT hres; - - ULONG typeId; - ULONG64 module; - hres = dbgExt->symbols->GetOffsetTypeId( m_targetOffset, &typeId, &module ); - if ( FAILED( hres ) ) - throw TypeException(); - - char moduleName[0x100]; - hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, DEBUG_ANY_ID, module, - moduleName, sizeof( moduleName ), NULL ); - if ( FAILED( hres ) ) - throw TypeException(); - - m_typeInfo = TypeInfo( moduleName , addr64(module), typeId ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVar::TypedVar( const std::string &symbolName ) -{ - HRESULT hres; - - ULONG typeId; - ULONG64 module; - hres = dbgExt->symbols->GetSymbolTypeId( symbolName.c_str(), &typeId, &module ); - if ( FAILED( hres ) ) - throw TypeException(); - - char moduleName[0x100]; - hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, DEBUG_ANY_ID, module, - moduleName, sizeof( moduleName ), NULL ); - if ( FAILED( hres ) ) - throw TypeException(); - - m_typeInfo = TypeInfo( moduleName , addr64(module), typeId ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVar::TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset, char* buffer, size_t bufferLength ) : - m_typeInfo( typeInfo ), - m_targetOffset( addr64(targetOffset) ) -{ - if ( bufferLength < typeInfo.size() ) - throw TypeException(); - - m_buffer.insert( m_buffer.begin(), buffer, buffer + bufferLength ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -TypedVar::getFieldWrap( PyObject* self, const std::string &fieldName ) -{ - boost::python::object pyobj( boost::python::handle<>( boost::python::borrowed(self) ) ); - - TypedVar &tv = boost::python::extract( pyobj ); - - return tv.getField( pyobj, fieldName ); -} - -void TypedVar::reallocBuffer() -{ - const size_t fullSize = m_typeInfo.fullSize(); - if (m_buffer.size() < fullSize) - { - assert(fullSize); - m_buffer.resize( fullSize ); - loadMemory( m_targetOffset, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); - } -} - -boost::python::object -TypedVar::getField( boost::python::object &pyobj, const std::string &fieldName ) -{ - reallocBuffer(); - - TypeInfo typeInfo = m_typeInfo.getField( fieldName ); - - // относительный оффсет - ULONG offset = typeInfo.getFieldOffset() - m_typeInfo.getFieldOffset(); - - if ( typeInfo.isBaseType() || typeInfo.isPtr() || typeInfo.isEnum() ) - { - pyobj.attr(fieldName.c_str()) = typeInfo.load( &(m_buffer.begin() + offset)[0], typeInfo.fullSize() ); - } - else - { - if ( typeInfo.count() == 1 ) - { - if (m_buffer.size()) - { - pyobj.attr(fieldName.c_str()) = - boost::python::object( - TypedVar( - typeInfo, - m_targetOffset + offset, - &m_buffer[0] + offset, - typeInfo.size() ) ); - } - } - else - { - boost::python::list arr; - - for ( unsigned int i = 0; i < typeInfo.count(); ++i ) - { - if (m_buffer.size()) - { - arr.append( - boost::python::object( - TypedVar( - typeInfo, - m_targetOffset + offset + i*typeInfo.size(), - &m_buffer[0] + offset + i*typeInfo.size(), - typeInfo.size() ) ) ); - } - } - - pyobj.attr(fieldName.c_str()) = arr; - } - } - - return pyobj.attr(fieldName.c_str()); -} - +//#include +// +//#include +// +//#include "dbgext.h" +//#include "dbgtype.h" +//#include "dbgexcept.h" +//#include "dbgmem.h" +//#include "dbgsystem.h" +//#include "dbgmem.h" +// +//using namespace std; +// ///////////////////////////////////////////////////////////////////////////////////// - -std::string -TypedVar::data() -{ - reallocBuffer(); - return std::string( getVectorBuffer(m_buffer), m_buffer.size() ); -} - +// +//TypeInfo::TypeInfoMap TypeInfo::g_typeInfoCache; +// ///////////////////////////////////////////////////////////////////////////////////// - -std::string -TypedVar::print() -{ - reallocBuffer(); - - stringstream sstr; - - if ( m_typeInfo.name().size() != 0 ) - { - if ( m_typeInfo.moduleName().size() ) - sstr << m_typeInfo.moduleName() << "!"; - - sstr << m_typeInfo.name(); - } - else - sstr << "unnamed"; - - sstr << " address = " << hex << "0x" << getTargetOffset(); - sstr << " size = " << dec << m_typeInfo.fullSize() << " (0x" << hex << m_typeInfo.fullSize() << ")" << endl; - - - for ( size_t i = 0; i < m_typeInfo.getFieldCount(); ++i ) - { - sstr << m_typeInfo.printField( i, (PVOID)getVectorBuffer(m_buffer), (ULONG)m_buffer.size() ); - - //TypeInfo fieldType = m_typeInfo.getFieldAt( i ); - - //// относительный оффсет - //ULONG offset = fieldType.getFieldOffset() - m_typeInfo.getFieldOffset(); - - //if ( fieldType.isBaseType() || fieldType.isPtr() ) - //{ - // sstr << hex << "+" << offset << " " << fieldType.name(); - // sstr << fieldType.printValue( &(m_buffer.begin() + offset)[0], fieldType.fullSize() ); - //} - //else - //{ - // if ( fieldType.count() == 1 ) - // { - // sstr << hex << "+" << offset << " " << fieldType.name() << endl; - // } - // else - // { - // sstr << hex << "+" << offset << " " << fieldType.name() << "[" << dec << "]" << endl; - // } - //} - } - - return sstr.str(); -} - +// +//TypeInfo::TypeInfo( const std::string &moduleName, const std::string &typeName ) +// : m_align(0) +// , m_alignReq(1) +//{ +// HRESULT hres; +// bool baseType = checkBaseType(typeName); +// +// TypeInfoMap::iterator findIt = baseType ? +// g_typeInfoCache.find( std::make_pair("",typeName) ) : +// g_typeInfoCache.find( std::make_pair(moduleName,typeName) ); +// +// if ( findIt != g_typeInfoCache.end() ) +// { +// *this = findIt->second; +// return; +// } +// +// m_typeName = typeName; +// +// m_isPointer = false; +// m_isBaseType = false; +// m_isFreezed = true; +// m_parentOffset = 0; +// +// if ( !baseType ) +// m_moduleName = moduleName; +// +// do { +// +// if ( typeName.find("*") < typeName.size() ) +// { +// m_isPointer = true; +// m_size = ptrSize(); +// break; +// } +// +// if ( baseType ) +// { +// m_isBaseType = true; +// m_size = getBaseTypeSize( typeName ); +// break; +// } +// +// ULONG64 moduleBase = 0; +// hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// ULONG typeId = 0; +// hres = dbgExt->symbols->GetTypeId( moduleBase, m_typeName.c_str(), &typeId ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// hres = dbgExt->symbols->GetTypeSize( moduleBase, typeId, &m_size ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// for ( ULONG i = 0; ; ++i ) +// { +// char fieldName[100]; +// hres = dbgExt->symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL ); +// if ( FAILED( hres ) ) +// break; +// +// ULONG fieldTypeId; +// ULONG fieldOffset; +// hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset ); +// +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// ULONG fieldSize; +// hres = dbgExt->symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// char fieldTypeName[100]; +// hres = dbgExt->symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// std::string fieldTypeNameStr( fieldTypeName ); +// +// if ( fieldTypeNameStr == "__unnamed" +// || fieldTypeNameStr.find("") < fieldTypeNameStr.size() ) +// { +// addField( fieldName, TypeInfo( moduleName, moduleBase, fieldTypeId ), fieldSize, fieldOffset ); +// } +// else +// { +// addField( fieldName, TypeInfo( moduleName, fieldTypeName ), fieldSize, fieldOffset ); +// } +// } +// +// } while( FALSE ); +// +// m_arraySize = m_size; +// +// g_typeInfoCache.insert( std::make_pair( std::make_pair( m_moduleName, m_typeName), *this) ); +//} +// ///////////////////////////////////////////////////////////////////////////////////// - -ULONG TypeInfo::getAlignReq() const -{ - if (isBaseType()) - return size(); - - if (isPtr()) - return ptrSize(); - - return m_alignReq; -} - +// +//TypeInfo::TypeInfo( const std::string &moduleName, ULONG64 moduleBase, ULONG typeId ) +// : m_align(0) +// , m_alignReq(1) +//{ +// HRESULT hres; +// +// m_isPointer = false; +// m_isBaseType = false; +// m_isFreezed = true; +// m_parentOffset = 0; +// +// hres = dbgExt->symbols->GetTypeSize( moduleBase, typeId, &m_size ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// for ( ULONG i = 0; ; ++i ) +// { +// char fieldName[100]; +// hres = dbgExt->symbols2->GetFieldName( moduleBase, typeId, i, fieldName, sizeof(fieldName), NULL ); +// if ( FAILED( hres ) ) +// break; +// +// ULONG fieldTypeId; +// ULONG fieldOffset; +// hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName, &fieldTypeId, &fieldOffset ); +// +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// ULONG fieldSize; +// hres = dbgExt->symbols->GetTypeSize( moduleBase, fieldTypeId, &fieldSize ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// char fieldTypeName[100]; +// hres = dbgExt->symbols->GetTypeName( moduleBase, fieldTypeId, fieldTypeName, sizeof(fieldTypeName), NULL ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// std::string fieldTypeNameStr( fieldTypeName ); +// +// if ( fieldTypeNameStr == "__unnamed" +// || fieldTypeNameStr.find("") < fieldTypeNameStr.size() ) +// { +// addField( fieldName, TypeInfo( moduleName, moduleBase, fieldTypeId ), fieldSize, fieldOffset ); +// } +// else +// { +// addField( fieldName, TypeInfo( moduleName, fieldTypeName ), fieldSize, fieldOffset ); +// } +// } +// +// m_arraySize = m_size; +//} +// ///////////////////////////////////////////////////////////////////////////////////// - -void TypeInfo::addField( - const std::string &name_, - const TypeInfo &type_, - ULONG size_, - ULONG offset_ -) -{ - m_alignReq = max(m_alignReq, type_.getAlignReq()); - m_fields.push_back( TypeField( name_, type_, size_, offset_ ) ); -} - +// +//const TypeInfo& +//TypeInfo::get( const std::string &moduleName, const std::string &typeName ) +//{ +// TypeInfoMap::iterator findIt = g_typeInfoCache.find( std::make_pair(moduleName,typeName) ); +// +// if ( findIt != g_typeInfoCache.end() ) +// return findIt->second; +// +// TypeInfo type( moduleName, typeName ); +// +// return g_typeInfoCache.insert( std::make_pair( std::make_pair( moduleName, typeName), type) ).first->second; +//} +// ///////////////////////////////////////////////////////////////////////////////////// - -ULONG -sizeofType( const std::string &moduleName, const std::string &typeName ) -{ - return TypeInfo::get( moduleName, typeName ).size(); -} - +// +//std::string +//TypeInfo::print() const +//{ +// std::stringstream sstream; +// +// if ( m_typeName.size() != 0 ) +// { +// if ( m_moduleName.size() != 0 ) +// sstream << m_moduleName << "!"; +// +// sstream << m_typeName; +// } +// else +// sstream << "unnamed"; +// +// if ( m_arraySize > m_size ) +// { +// sstream << " size = " << dec << m_arraySize << "(0x" << hex << m_arraySize << ") " << dec << "[" << m_arraySize/m_size << "]"; +// } +// else +// { +// sstream << " size = " << dec << m_size << "(0x" << hex << m_size << ")" << endl; +// } +// +// TypeFieldList::const_iterator it = m_fields.begin(); +// for(;it != m_fields.end(); ++it ) +// { +// sstream << "\t" << it->print() << std::endl; +// } +// +// return sstream.str(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypeInfo +//TypeInfo::getField( const std::string &fieldName ) const +//{ +// TypeFieldList::const_iterator it = m_fields.begin(); +// for(;it != m_fields.end(); ++it ) +// { +// if ( it->name == fieldName ) +// { +// TypeInfo tinf = it->type; +// +// tinf.m_parentOffset = m_parentOffset + it->offset; +// tinf.m_arraySize = it->size; +// +// return tinf; +// } +// } +// +// throw TypeException(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypeInfo +//TypeInfo::getFieldAt( size_t index ) const +//{ +// TypeInfo tinf = m_fields[index].type; +// +// tinf.m_parentOffset = m_parentOffset + m_fields[index].offset; +// tinf.m_arraySize = m_fields[index].size; +// +// return tinf; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//TypeInfo::getFieldByIndex( boost::python::object &obj ) const +//{ +// if ( PyInt_Check( obj.ptr() ) ) +// { +// long index = PyInt_AsLong(obj.ptr()); +// +// if ( index > (long)m_fields.size() ) +// throw IndexException(); +// +// if ( index < 0 ) +// { +// index = (long)m_fields.size() - abs(index); +// if ( index < 0 ) +// throw IndexException(); +// } +// +// TypeInfo tinf = m_fields[index].type; +// tinf.m_parentOffset = m_fields[index].offset; +// return boost::python::object( tinf ); +// } +// else +// { +// boost::python::slice sl( boost::python::detail::borrowed_reference( obj.ptr() ) ); +// +// boost::python::slice::range< TypeFieldList::const_iterator > bounds; +// +// bounds = sl.get_indicies( m_fields.begin(), m_fields.end() ); +// +// boost::python::list valList; +// +// do { +// +// TypeInfo tinf = bounds.start->type; +// tinf.m_parentOffset = bounds.start->offset; +// +// valList.append( tinf ); +// +// if ( bounds.start == bounds.stop) +// break; +// +// std::advance( bounds.start, bounds.step); +// +// } while( true ); +// +// return valList; +// } +// +// throw IndexException(); +// +// return boost::python::object(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//void +//TypeInfo::appendField( const TypeInfo &typeInfo, const std::string &fieldName, ULONG count ) +//{ +// if ( m_isFreezed ) +// throw TypeException(); +// +// if ( count == 0 ) +// throw TypeException(); +// +// if ( count == 1 && typeInfo.m_typeName.find("[]") != std::string::npos ) +// throw TypeException(); +// +// TypeFieldList::const_iterator it = m_fields.begin(); +// for(;it != m_fields.end(); ++it ) +// { +// if ( it->name == fieldName ) +// throw TypeException(); +// } +// +// if ( count > 1 && typeInfo.m_typeName.find("[]") == std::string::npos ) +// { +// TypeInfo arrayInfo( typeInfo ); +// arrayInfo.m_typeName += "[]"; +// appendField( arrayInfo, fieldName, count ); +// return; +// } +// +// ULONG offset = m_size; +// offset += offset % ( m_align ? m_align : typeInfo.getAlignReq() ); +// +// const ULONG addSize = typeInfo.size() * count; +// addField( fieldName, typeInfo, addSize, offset ); +// m_size = offset + addSize; +// m_arraySize = offset + addSize; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//TypeInfo::loadVar( ULONG64 targetOffset, ULONG count ) const +//{ +// if ( count == 0 ) +// throw TypeException(); +// +// if ( count == 1 ) +// { +// boost::python::object obj( TypedVar( *this, targetOffset ) ); +// +// return obj; +// } +// else +// { +// boost::python::list lst; +// +// for( ULONG i = 0; i < count; ++i ) +// lst.append( TypedVar( *this, targetOffset + m_size*i ) ); +// +// return lst; +// } +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//template< typename valType> +//boost::python::object +//valueLoader( void* address, size_t size ) +//{ +// if ( size == sizeof(valType) ) +// { +// valType v = *(valType*)address; +// +// return boost::python::object( v ); +// } +// else +// { +// boost::python::list arr; +// +// for ( unsigned int i = 0; i < size / sizeof(valType); ++i ) +// { +// valType v = *( (valType*)address + i ); +// arr.append( v ); +// } +// +// return arr; +// } +// +// throw TypeException(); +//} +// +//template<> +//boost::python::object +//valueLoader( void* address, size_t size ) +//{ +// if ( size == sizeof(char) ) +// { +// int v = *(char*)address; +// +// return boost::python::object( v ); +// } +// else +// { +// boost::python::list arr; +// +// for ( unsigned int i = 0; i < size / sizeof(char); ++i ) +// { +// int v = *( (char*)address + i ); +// arr.append( v ); +// } +// +// return arr; +// } +// +// throw TypeException(); +//} +// +// +//template<> +//boost::python::object +//valueLoader( void* address, size_t size ) +//{ +// +// if ( is64bitSystem() ) +// { +// if ( size == sizeof(ULONG64) ) +// { +// return boost::python::object( *(PULONG64)address ); +// } +// else +// { +// boost::python::list arr; +// +// for ( unsigned int i = 0; i < size / sizeof(ULONG64); ++i ) +// { +// ULONG64 v = *( (PULONG64)address + i ); +// arr.append( v ); +// } +// +// return arr; +// } +// } +// else +// { +// if ( size == sizeof(ULONG) ) +// { +// return boost::python::object( addr64( *(PULONG)address ) ); +// } +// else +// { +// boost::python::list arr; +// +// for ( unsigned int i = 0; i < size / sizeof(ULONG); ++i ) +// { +// ULONG64 v = addr64(*( (PULONG)address + i ) ); +// arr.append( v ); +// } +// +// return arr; +// } +// } +// +// throw TypeException(); +//} +// +//template<> +//boost::python::object +//valueLoader( void* address, size_t size ) +//{ +// return boost::python::object(); +//} +// +// +// +//template +//std::string +//valuePrinter( void* address, size_t size ) +//{ +// std::stringstream sstr; +// +// if ( size == sizeof(valType) ) +// { +// valType v = *(valType*)address; +// +// sstr << v << hex << " (0x" << v << ")"; +// } +// else +// { +// +// for ( unsigned int i = 0; i < size / sizeof(valType); ++i ) +// { +// valType v = *( (valType*)address + i ); +// sstr << endl << "\t[" << dec << i << "] " << dec << v << " (" << hex << v << ")"; +// } +// } +// +// return sstr.str(); +//} +// +//template<> +//std::string +//valuePrinter( void* address, size_t size ) +//{ +// if ( is64bitSystem() ) +// { +// return valuePrinter( address, size ); +// } +// +// return valuePrinter( address, size ); +//} +// +//template <> +//std::string +//valuePrinter( void* address, size_t size ) +//{ +// std::stringstream sstr; +// +// if ( size == sizeof(unsigned char) ) +// { +// unsigned int v = *(unsigned char*)address; +// +// sstr << v; +// } +// else +// { +// +// for ( unsigned int i = 0; i < size / sizeof(unsigned char); ++i ) +// { +// unsigned int v = *( (unsigned char*)address + i ); +// sstr << endl << "\t[" << dec << i << "] " << dec << v << " (" << hex << v << ")"; +// } +// } +// +// return sstr.str(); +//} +// +// +//template <> +//std::string +//valuePrinter( void* address, size_t size ) +//{ +// std::stringstream sstr; +// +// if ( size == sizeof(unsigned char) ) +// { +// int v = *(char*)address; +// +// sstr << v; +// } +// else +// { +// +// for ( unsigned int i = 0; i < size / sizeof(unsigned char); ++i ) +// { +// int v = *( (char*)address + i ); +// sstr << endl << "\t[" << dec << i << "] " << dec << v << " (" << hex << v << ")"; +// } +// } +// +// return sstr.str(); +//} +// +// +//template<> +//std::string +//valuePrinter( void* address, size_t size ) +//{ +// return ""; +//} +// +// +//const char* TypeInfo::basicTypeNames[] = { +// "unsigned char", +// "char", +// "unsigned short", +// "short", +// "unsigned long", +// "long", +// "int", +// "unsigned int", +// "", +// "void", +// "double", +// "int64", +// "unsigned int64", +// "ptr" +//}; +// +// +//size_t TypeInfo::basicTypeSizes[] = { +// sizeof( unsigned char ), +// sizeof( char ), +// sizeof( unsigned short ), +// sizeof( short ), +// sizeof( unsigned long ), +// sizeof( long ), +// sizeof( int ), +// sizeof( unsigned int ), +// sizeof( void* ), +// 0, +// sizeof( double ), +// sizeof( __int64 ), +// sizeof( unsigned __int64 ) +//}; +// +// +//TypeInfo::basicTypeLoader TypeInfo::basicTypeLoaders[] = { +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader, +// valueLoader<__int64>, +// valueLoader +// }; +// +//TypeInfo::basicTypePrinter TypeInfo::basicTypePrinters[] = { +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter, +// valuePrinter<__int64>, +// valuePrinter +//}; +// +//bool +//TypeInfo::checkBaseType( const std::string &typeName ) +//{ +// for ( int i = 0; i < sizeof( basicTypeNames ) / sizeof( char* ); ++i ) +// { +// if ( typeName == basicTypeNames[i] ) +// return true; +// +// if ( typeName == ( std::string( basicTypeNames[i] ) + "*" ) ) +// return true; +// +// if ( typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) +// return true; +// +// if ( typeName == ( std::string( basicTypeNames[i] ) + "*[]" ) ) +// return true; +// } +// +// return false; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ULONG +//TypeInfo::getBaseTypeSize( const std::string &typeName ) +//{ +// for ( int i = 0; i < sizeof( basicTypeSizes ) / sizeof( size_t ); ++i ) +// { +// if ( typeName == basicTypeNames[i] || +// typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) +// { +// return (ULONG)basicTypeSizes[i]; +// } +// } +// +// return 0; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//TypeInfo::load( void* buffer, size_t bufferLength ) const +//{ +// if ( bufferLength < m_size ) +// throw TypeException(); +// +// if ( m_isPointer ) +// { +// return valueLoader( buffer, bufferLength ); +// } +// +// if ( m_isBaseType ) +// { +// for ( int i = 0; i < sizeof( basicTypeNames ) / sizeof( char* ); ++i ) +// { +// if ( m_typeName == basicTypeNames[i] ) +// return basicTypeLoaders[i]( buffer, m_size ); +// +// if ( m_typeName == ( std::string( basicTypeNames[i] ) + "*" ) ) +// return valueLoader( buffer, ptrSize() ); +// +// if ( m_typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) +// return basicTypeLoaders[i]( buffer, m_arraySize ); +// +// if ( m_typeName == ( std::string( basicTypeNames[i] ) + "*[]" ) ) +// return valueLoader( buffer, ptrSize()*count() ); +// } +// } +// +// if ( isEnum() ) +// { +// return valueLoader( buffer, bufferLength ); +// } +// +// throw TypeException(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//template<> +//std::string +//TypeInfo::TypeField::print() const +//{ +// std::stringstream sstr; +// +// sstr << hex << "+" << offset << " "; +// sstr << type.m_typeName << " "; +// sstr << name; +// +// return sstr.str(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//std::string +//TypeInfo::printField( size_t index, void* buffer, size_t bufferLength ) const +//{ +// stringstream sstr; +// const TypeField &field = m_fields[index]; +// const TypeInfo &fieldType = field.type; +// ULONG offset = field.offset; +// ULONG count = field.size / fieldType.size(); +// +// if ( fieldType.m_isPointer ) +// { +// sstr << hex << "+" << offset; +// sstr << " " << field.name; +// sstr << " " << fieldType.name(); +// sstr << " " << hex << valuePrinter( (char*)buffer + offset, field.size ); +// sstr << endl; +// return sstr.str(); +// } +// +// if ( fieldType.m_isBaseType ) +// { +// for ( int i = 0; i < sizeof( basicTypeNames ) / sizeof( char* ); ++i ) +// { +// if ( fieldType.m_typeName == basicTypeNames[i] || +// fieldType.m_typeName == ( std::string( basicTypeNames[i] ) + "[]" ) ) +// { +// sstr << hex << "+" << offset; +// sstr << " " << field.name; +// sstr << " " << fieldType.name(); +// sstr << " " << basicTypePrinters[i]( (char*)buffer + offset, field.size ); +// sstr << endl; +// return sstr.str(); +// } +// } +// +// throw TypeException(); +// } +// +// if ( count == 1 ) +// { +// sstr << hex << "+" << offset; +// sstr << " " << field.name; +// sstr << " " << fieldType.name(); +// sstr << endl; +// } +// else +// { +// sstr << hex << "+" << offset; +// sstr << " " << field.name; +// sstr << " " << fieldType.name() << "[" << dec << count << "]"; +// sstr << endl; +// } +// +// return sstr.str(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVar::TypedVar( ULONG64 targetOffset ) : +// m_targetOffset( addr64(targetOffset) ) +//{ +// HRESULT hres; +// +// ULONG typeId; +// ULONG64 module; +// hres = dbgExt->symbols->GetOffsetTypeId( m_targetOffset, &typeId, &module ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// char moduleName[0x100]; +// hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, DEBUG_ANY_ID, module, +// moduleName, sizeof( moduleName ), NULL ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// m_typeInfo = TypeInfo( moduleName , addr64(module), typeId ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVar::TypedVar( const std::string &symbolName ) +//{ +// HRESULT hres; +// +// ULONG typeId; +// ULONG64 module; +// hres = dbgExt->symbols->GetSymbolTypeId( symbolName.c_str(), &typeId, &module ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// char moduleName[0x100]; +// hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, DEBUG_ANY_ID, module, +// moduleName, sizeof( moduleName ), NULL ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// m_typeInfo = TypeInfo( moduleName , addr64(module), typeId ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVar::TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset, char* buffer, size_t bufferLength ) : +// m_typeInfo( typeInfo ), +// m_targetOffset( addr64(targetOffset) ) +//{ +// if ( bufferLength < typeInfo.size() ) +// throw TypeException(); +// +// m_buffer.insert( m_buffer.begin(), buffer, buffer + bufferLength ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//TypedVar::getFieldWrap( PyObject* self, const std::string &fieldName ) +//{ +// boost::python::object pyobj( boost::python::handle<>( boost::python::borrowed(self) ) ); +// +// TypedVar &tv = boost::python::extract( pyobj ); +// +// return tv.getField( pyobj, fieldName ); +//} +// +//void TypedVar::reallocBuffer() +//{ +// const size_t fullSize = m_typeInfo.fullSize(); +// if (m_buffer.size() < fullSize) +// { +// assert(fullSize); +// m_buffer.resize( fullSize ); +// loadMemory( m_targetOffset, (PVOID)&m_buffer[0], (ULONG)m_buffer.size() ); +// } +//} +// +//boost::python::object +//TypedVar::getField( boost::python::object &pyobj, const std::string &fieldName ) +//{ +// reallocBuffer(); +// +// TypeInfo typeInfo = m_typeInfo.getField( fieldName ); +// +// // относительный оффсет +// ULONG offset = typeInfo.getFieldOffset() - m_typeInfo.getFieldOffset(); +// +// if ( typeInfo.isBaseType() || typeInfo.isPtr() || typeInfo.isEnum() ) +// { +// pyobj.attr(fieldName.c_str()) = typeInfo.load( &(m_buffer.begin() + offset)[0], typeInfo.fullSize() ); +// } +// else +// { +// if ( typeInfo.count() == 1 ) +// { +// if (m_buffer.size()) +// { +// pyobj.attr(fieldName.c_str()) = +// boost::python::object( +// TypedVar( +// typeInfo, +// m_targetOffset + offset, +// &m_buffer[0] + offset, +// typeInfo.size() ) ); +// } +// } +// else +// { +// boost::python::list arr; +// +// for ( unsigned int i = 0; i < typeInfo.count(); ++i ) +// { +// if (m_buffer.size()) +// { +// arr.append( +// boost::python::object( +// TypedVar( +// typeInfo, +// m_targetOffset + offset + i*typeInfo.size(), +// &m_buffer[0] + offset + i*typeInfo.size(), +// typeInfo.size() ) ) ); +// } +// } +// +// pyobj.attr(fieldName.c_str()) = arr; +// } +// } +// +// return pyobj.attr(fieldName.c_str()); +//} +// +/////////////////////////////////////////////////////////////////////////////////////// +// +//std::string +//TypedVar::data() +//{ +// reallocBuffer(); +// return std::string( getVectorBuffer(m_buffer), m_buffer.size() ); +//} +// +/////////////////////////////////////////////////////////////////////////////////////// +// +//std::string +//TypedVar::print() +//{ +// reallocBuffer(); +// +// stringstream sstr; +// +// if ( m_typeInfo.name().size() != 0 ) +// { +// if ( m_typeInfo.moduleName().size() ) +// sstr << m_typeInfo.moduleName() << "!"; +// +// sstr << m_typeInfo.name(); +// } +// else +// sstr << "unnamed"; +// +// sstr << " address = " << hex << "0x" << getTargetOffset(); +// sstr << " size = " << dec << m_typeInfo.fullSize() << " (0x" << hex << m_typeInfo.fullSize() << ")" << endl; +// +// +// for ( size_t i = 0; i < m_typeInfo.getFieldCount(); ++i ) +// { +// sstr << m_typeInfo.printField( i, (PVOID)getVectorBuffer(m_buffer), (ULONG)m_buffer.size() ); +// +// //TypeInfo fieldType = m_typeInfo.getFieldAt( i ); +// +// //// относительный оффсет +// //ULONG offset = fieldType.getFieldOffset() - m_typeInfo.getFieldOffset(); +// +// //if ( fieldType.isBaseType() || fieldType.isPtr() ) +// //{ +// // sstr << hex << "+" << offset << " " << fieldType.name(); +// // sstr << fieldType.printValue( &(m_buffer.begin() + offset)[0], fieldType.fullSize() ); +// //} +// //else +// //{ +// // if ( fieldType.count() == 1 ) +// // { +// // sstr << hex << "+" << offset << " " << fieldType.name() << endl; +// // } +// // else +// // { +// // sstr << hex << "+" << offset << " " << fieldType.name() << "[" << dec << "]" << endl; +// // } +// //} +// } +// +// return sstr.str(); +//} +// +/////////////////////////////////////////////////////////////////////////////////////// +// +//ULONG TypeInfo::getAlignReq() const +//{ +// if (isBaseType()) +// return size(); +// +// if (isPtr()) +// return ptrSize(); +// +// return m_alignReq; +//} +// +/////////////////////////////////////////////////////////////////////////////////////// +// +//void TypeInfo::addField( +// const std::string &name_, +// const TypeInfo &type_, +// ULONG size_, +// ULONG offset_ +//) +//{ +// m_alignReq = max(m_alignReq, type_.getAlignReq()); +// m_fields.push_back( TypeField( name_, type_, size_, offset_ ) ); +//} +// +/////////////////////////////////////////////////////////////////////////////////////// +// +//ULONG +//sizeofType( const std::string &moduleName, const std::string &typeName ) +//{ +// return TypeInfo::get( moduleName, typeName ).size(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName ) +//{ +// address = addr64(address); +// +// HRESULT hres; +// ULONG64 moduleBase; +// +// hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// ULONG typeId; +// hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// ULONG fieldTypeId; +// ULONG fieldOffset; +// hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName.c_str(), &fieldTypeId, &fieldOffset ); +// if ( FAILED( hres ) ) +// throw TypeException(); +// +// TypedVar var( moduleName, typeName, address - fieldOffset ); +// +// return boost::python::object( var ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//boost::python::object +//loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName ) +//{ +// address = addr64(address); +// +// ULONG64 entryAddress = 0; +// +// const TypeInfo &typeInfo = TypeInfo::get( moduleName, typeName ); +// +// boost::python::list objList; +// +// +// TypeInfo fieldType = typeInfo.getField( listEntryName ); +// +// if ( fieldType.name() == ( typeName + "*" ) ) +// { +// for( entryAddress = loadPtrByPtr( address ); entryAddress != address && entryAddress != NULL; entryAddress = loadPtrByPtr( entryAddress + fieldType.getFieldOffset() ) ) +// objList.append( TypedVar( moduleName, typeName, entryAddress ) ); +// } +// else +// { +// for( entryAddress = loadPtrByPtr( address ); entryAddress != address && entryAddress != NULL; entryAddress = loadPtrByPtr( entryAddress ) ) +// objList.append( containingRecord( entryAddress, moduleName, typeName, listEntryName ) ); +// } +// +// return objList; +//} +// /////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName ) -{ - address = addr64(address); - - HRESULT hres; - ULONG64 moduleBase; - - hres = dbgExt->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &moduleBase ); - if ( FAILED( hres ) ) - throw TypeException(); - - ULONG typeId; - hres = dbgExt->symbols->GetTypeId( moduleBase, typeName.c_str(), &typeId ); - if ( FAILED( hres ) ) - throw TypeException(); - - ULONG fieldTypeId; - ULONG fieldOffset; - hres = dbgExt->symbols3->GetFieldTypeAndOffset( moduleBase, typeId, fieldName.c_str(), &fieldTypeId, &fieldOffset ); - if ( FAILED( hres ) ) - throw TypeException(); - - TypedVar var( moduleName, typeName, address - fieldOffset ); - - return boost::python::object( var ); -} - +// +//boost::python::object +//loadTypedVarArray( ULONG64 address, const std::string &moduleName, const std::string &typeName, long number ) +//{ +// address = addr64(address); +// +// const TypeInfo &typeInfo = TypeInfo::get( moduleName, typeName ); +// +// boost::python::list objList; +// +// for( long i = 0; i < number; ++i ) +// objList.append( TypedVar(typeInfo, address + i * typeInfo.size() ) ); +// +// return objList; +//} +// /////////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName ) -{ - address = addr64(address); - - ULONG64 entryAddress = 0; - - const TypeInfo &typeInfo = TypeInfo::get( moduleName, typeName ); - - boost::python::list objList; - - - TypeInfo fieldType = typeInfo.getField( listEntryName ); - - if ( fieldType.name() == ( typeName + "*" ) ) - { - for( entryAddress = loadPtrByPtr( address ); entryAddress != address && entryAddress != NULL; entryAddress = loadPtrByPtr( entryAddress + fieldType.getFieldOffset() ) ) - objList.append( TypedVar( moduleName, typeName, entryAddress ) ); - } - else - { - for( entryAddress = loadPtrByPtr( address ); entryAddress != address && entryAddress != NULL; entryAddress = loadPtrByPtr( entryAddress ) ) - objList.append( containingRecord( entryAddress, moduleName, typeName, listEntryName ) ); - } - - return objList; -} - -///////////////////////////////////////////////////////////////////////////////// - -boost::python::object -loadTypedVarArray( ULONG64 address, const std::string &moduleName, const std::string &typeName, long number ) -{ - address = addr64(address); - - const TypeInfo &typeInfo = TypeInfo::get( moduleName, typeName ); - - boost::python::list objList; - - for( long i = 0; i < number; ++i ) - objList.append( TypedVar(typeInfo, address + i * typeInfo.size() ) ); - - return objList; -} - -///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgtype.h b/pykd/dbgtype.h index c362ba2..3af00ab 100644 --- a/pykd/dbgtype.h +++ b/pykd/dbgtype.h @@ -1,295 +1,295 @@ #pragma once -#include -#include - -#include "dbgmem.h" -#include "dbgsystem.h" - -#include - -/////////////////////////////////////////////////////////////////////////////////// - -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, 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 TypeField; - - typedef std::vector 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 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 +//#include +// +//#include "dbgmem.h" +//#include "dbgsystem.h" +// +//#include +// +///////////////////////////////////////////////////////////////////////////////////// +// +//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, 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 TypeField; +// +// typedef std::vector 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 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 ); +// +///////////////////////////////////////////////////////////////////////////////////// +// diff --git a/pykd/disasm.cpp b/pykd/disasm.cpp index b2b3b5f..51b2679 100644 --- a/pykd/disasm.cpp +++ b/pykd/disasm.cpp @@ -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( ¤tOffset ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugRegisters::GetInstructionOffset failed" ); - - offset += currentOffset; - } - - hres = - dbgExt->control->Disassemble( - offset, - DEBUG_DISASM_EFFECTIVE_ADDRESS, - buffer, - sizeof(buffer), - &disasmSize, - &endOffset ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::Disassemble failed" ); - - hres = dbgExt->control->GetDisassembleEffectiveOffset( &m_ea ); - if ( FAILED( hres ) ) - m_ea = 0; - - m_length = (ULONG)(endOffset - offset); - - m_disasm = std::string( buffer, disasmSize - 2); -} - -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include "dbgext.h" +//#include "disasm.h" +//#include "dbgexcept.h" +//#include "dbgmem.h" +// +/////////////////////////////////////////////////////////////////////////////////// +// +//void disasm::doDisasm() +//{ +// HRESULT hres; +// char buffer[0x100]; +// ULONG disasmSize = 0; +// ULONG64 offset = addr64(m_currentOffset); +// ULONG64 endOffset = 0; +// +// if ( m_beginOffset == 0 ) +// { +// ULONG64 currentOffset = 0; +// +// hres = dbgExt->registers->GetInstructionOffset( ¤tOffset ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugRegisters::GetInstructionOffset failed" ); +// +// offset += currentOffset; +// } +// +// hres = +// dbgExt->control->Disassemble( +// offset, +// DEBUG_DISASM_EFFECTIVE_ADDRESS, +// buffer, +// sizeof(buffer), +// &disasmSize, +// &endOffset ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugControl::Disassemble failed" ); +// +// hres = dbgExt->control->GetDisassembleEffectiveOffset( &m_ea ); +// if ( FAILED( hres ) ) +// m_ea = 0; +// +// m_length = (ULONG)(endOffset - offset); +// +// m_disasm = std::string( buffer, disasmSize - 2); +//} +// +/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/disasm.h b/pykd/disasm.h index 95ba472..6b78285 100644 --- a/pykd/disasm.h +++ b/pykd/disasm.h @@ -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; +//}; +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/intbase.h b/pykd/intbase.h index 2808172..fd35205 100644 --- a/pykd/intbase.h +++ b/pykd/intbase.h @@ -1,88 +1,88 @@ #pragma once -class intBase : boost::integer_arithmetic -{ - -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 - intBase& operator+=(T const& rhs) - { m_value += rhs; return *this; } - - template - intBase& operator-=(T const& rhs) - { m_value -= rhs; return *this; } - - template - intBase& operator*=(T const& rhs) - { m_value *= rhs; return *this; } - - template - intBase& operator/=(T const& rhs) - { m_value /= rhs; return *this; } - - template - intBase& operator%=(T const& rhs) - { m_value %= rhs; return *this; } - - template - intBase& operator&=(T const& rhs) - { m_value &= rhs; return *this; } - - template - intBase& operator|=(T const& rhs) - { m_value |= rhs; return *this; } - - template - intBase& operator^=(T const& rhs) - { m_value ^= rhs; return *this; } - - template - intBase& operator<<=(T const& rhs) - { m_value <<= rhs; return *this; } - - template - intBase& operator>>=(T const& rhs) - { m_value >>= rhs; return *this; } - -protected: - - mutable ULONG64 m_value; - -}; \ No newline at end of file +//class intBase : boost::integer_arithmetic +//{ +// +//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 +// intBase& operator+=(T const& rhs) +// { m_value += rhs; return *this; } +// +// template +// intBase& operator-=(T const& rhs) +// { m_value -= rhs; return *this; } +// +// template +// intBase& operator*=(T const& rhs) +// { m_value *= rhs; return *this; } +// +// template +// intBase& operator/=(T const& rhs) +// { m_value /= rhs; return *this; } +// +// template +// intBase& operator%=(T const& rhs) +// { m_value %= rhs; return *this; } +// +// template +// intBase& operator&=(T const& rhs) +// { m_value &= rhs; return *this; } +// +// template +// intBase& operator|=(T const& rhs) +// { m_value |= rhs; return *this; } +// +// template +// intBase& operator^=(T const& rhs) +// { m_value ^= rhs; return *this; } +// +// template +// intBase& operator<<=(T const& rhs) +// { m_value <<= rhs; return *this; } +// +// template +// intBase& operator>>=(T const& rhs) +// { m_value >>= rhs; return *this; } +// +//protected: +// +// mutable ULONG64 m_value; +// +//}; \ No newline at end of file diff --git a/pykd/pyaux.h b/pykd/pyaux.h index 843dc31..1fb5987 100644 --- a/pykd/pyaux.h +++ b/pykd/pyaux.h @@ -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 ); - } -}; - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//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 ); +// } +//}; +// +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/pykd.def b/pykd/pykd.def index 3ed8bab..17ee93b 100644 --- a/pykd/pykd.def +++ b/pykd/pykd.def @@ -5,4 +5,3 @@ EXPORTS info py pycmd - pythonpath diff --git a/pykd/pykd.rc b/pykd/pykd.rc index 54ff864..a193c1b 100644 --- a/pykd/pykd.rc +++ b/pykd/pykd.rc @@ -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" diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 6a58a96..6e2b4b6 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -349,82 +349,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -471,90 +399,6 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pykd/stdafx.h b/pykd/stdafx.h index 94377b2..deeb631 100644 --- a/pykd/stdafx.h +++ b/pykd/stdafx.h @@ -30,32 +30,32 @@ #include #include - -#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 -#include -#pragma warning(pop) - -#include - -template -TElem *getVectorBuffer(std::vector &vec) -{ - return vec.size() ? &vec[0] : NULL; -} -template -const TElem *getVectorBuffer(const std::vector &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 +//#include +//#pragma warning(pop) +// +//#include +// +//template +//TElem *getVectorBuffer(std::vector &vec) +//{ +// return vec.size() ? &vec[0] : NULL; +//} +//template +//const TElem *getVectorBuffer(const std::vector &vec) +//{ +// return vec.size() ? &vec[0] : NULL; +//} +// +//// TODO: reference additional headers your program requires here diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index f9d537f..f0f6820 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -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 ) ) diff --git a/test/scripts/regtest.py b/test/scripts/regtest.py index 301bed6..1864ff9 100644 --- a/test/scripts/regtest.py +++ b/test/scripts/regtest.py @@ -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") ) \ No newline at end of file diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index da24562..6a23d19 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -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" ) - 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" ) +# 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 ) diff --git a/test/targetapp/types.cpp b/test/targetapp/types.cpp index 94a2abd..3e84ec2 100644 --- a/test/targetapp/types.cpp +++ b/test/targetapp/types.cpp @@ -1,190 +1,190 @@ #include "stdafx.h" -#include - -/////////////////////////////////////////////////////////////////////////////// - -// базовый типы - -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 - class Class3 - { - public: - Class3(T val): m_field1 (val) - { - } - private: - T m_field1; - }; - - Class3 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; - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//#include +// +///////////////////////////////////////////////////////////////////////////////// +// +//// базовый типы +// +//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 +// class Class3 +// { +// public: +// Class3(T val): m_field1 (val) +// { +// } +// private: +// T m_field1; +// }; +// +// Class3 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; +// +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file