diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h new file mode 100644 index 0000000..1c4497b --- /dev/null +++ b/pykd/dbgengine.h @@ -0,0 +1,21 @@ +#pragma once + +namespace pykd { + +// manage debug target +ULONG startProcess( const std::wstring &processName ); +void detachProcess( ULONG processId = -1); +void terminateProcess( ULONG processId = -1); + +void debugGo(); + +//manage debug module +ULONG64 findModuleBase( const std::string &moduleName ); +ULONG64 findModuleBase( ULONG64 offset ); +std::string getModuleName( ULONG64 baseOffset ); + +//manage access to target memory +ULONG64 addr64( ULONG64 offset ); + +}; + diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 109526b..bef9f06 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -1,13 +1,13 @@ #include "stdafx.h" -#include <boost/tokenizer.hpp> +//#include <boost/tokenizer.hpp> +// +//#include "windbg.h" +//#include "dbgclient.h" +//#include "dbgpath.h" -#include "windbg.h" -#include "dbgclient.h" -#include "dbgpath.h" - -using namespace pykd; +//using namespace pykd; //////////////////////////////////////////////////////////////////////////////// @@ -32,46 +32,6 @@ BOOL WINAPI DllMain( //////////////////////////////////////////////////////////////////////////////// -extern "C" void initpykd(); - -//////////////////////////////////////////////////////////////////////////////// - -WindbgGlobalSession::WindbgGlobalSession() { - - PyImport_AppendInittab("pykd", initpykd ); - - PyEval_InitThreads(); - - Py_Initialize(); - - main = boost::python::import("__main__"); - - python::object main_namespace = main.attr("__dict__"); - - // ������ ������ from pykd import * - python::object pykd = boost::python::import( "pykd" ); - - python::dict pykd_namespace( pykd.attr("__dict__") ); - - python::list iterkeys( pykd_namespace.iterkeys() ); - - for (int i = 0; i < boost::python::len(iterkeys); i++) - { - std::string key = boost::python::extract<std::string>(iterkeys[i]); - - main_namespace[ key ] = pykd_namespace[ key ]; - } - - pyState = PyEval_SaveThread(); -} - - -volatile LONG WindbgGlobalSession::sessionCount = 0; - -WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL; - -///////////////////////////////////////////////////////////////////////////////// - HRESULT CALLBACK DebugExtensionInitialize( @@ -81,7 +41,7 @@ DebugExtensionInitialize( *Version = DEBUG_EXTENSION_VERSION( 1, 0 ); *Flags = 0; - WindbgGlobalSession::StartWindbgSession(); +// WindbgGlobalSession::StartWindbgSession(); return S_OK; } @@ -92,7 +52,7 @@ VOID CALLBACK DebugExtensionUninitialize() { - WindbgGlobalSession::StopWindbgSession(); +// WindbgGlobalSession::StopWindbgSession(); } //////////////////////////////////////////////////////////////////////////////// @@ -101,113 +61,7 @@ HRESULT CALLBACK py( PDEBUG_CLIENT4 client, PCSTR args ) { - DebugClientPtr dbgClient = DebugClient::createDbgClient( client ); - DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient ); - - WindbgGlobalSession::RestorePyState(); - - PyThreadState *globalInterpreter = PyThreadState_Swap( NULL ); - PyThreadState *localInterpreter = Py_NewInterpreter(); - - try { - - // �������� ������ � ����������� ���� ( ����� ��� ������ exec_file ) - python::object main = python::import("__main__"); - - python::object global(main.attr("__dict__")); - - // ����������� ����/����� ( ����� � ������� ����� ���� ������ print ) - - python::object sys = python::import("sys"); - - sys.attr("stdout") = python::object( dbgClient->dout() ); - sys.attr("stderr") = python::object( dbgClient->dout() ); - sys.attr("stdin") = python::object( dbgClient->din() ); - - // ����������� ������ ��������� ���������� ( ����� ��� ������ traceback � ) - python::object tracebackModule = python::import("traceback"); - - // ������ ���������� - typedef boost::escaped_list_separator<char> 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<std::string> 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<char*>( argsList[i].c_str() ); - - PySys_SetArgv( (int)argsList.size(), pythonArgs ); - - delete[] pythonArgs; - - // ����� ���� � ����� - std::string fullScriptName; - DbgPythonPath dbgPythonPath; - - if ( !dbgPythonPath.getFullFileName( argsList[0], fullScriptName ) ) - { - dbgClient->eprintln( L"script file not found" ); - } - else - try { - - python::object result; - - result = python::exec_file( fullScriptName.c_str(), global, global ); - } - catch( boost::python::error_already_set const & ) - { - // ������ � ������� - PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL; - - PyErr_Fetch( &errtype, &errvalue, &traceback ); - - PyErr_NormalizeException( &errtype, &errvalue, &traceback ); - - std::wstringstream sstr; - - python::object lst = - python::object( tracebackModule.attr("format_exception" ) )( - python::handle<>( errtype ), - python::handle<>( python::allow_null( errvalue ) ), - python::handle<>( python::allow_null( traceback ) ) ); - - sstr << std::endl << std::endl; - - for ( long i = 0; i < python::len(lst); ++i ) - sstr << std::wstring( python::extract<std::wstring>(lst[i]) ) << std::endl; - - dbgClient->eprintln( sstr.str() ); - } - - } - catch(...) - { - dbgClient->eprintln( L"unexpected error" ); - } - - Py_EndInterpreter( localInterpreter ); - PyThreadState_Swap( globalInterpreter ); - - WindbgGlobalSession::SavePyState(); - - DebugClient::setDbgClientCurrent( oldClient ); - - return S_OK; + return S_OK; } //////////////////////////////////////////////////////////////////////////////// @@ -216,49 +70,248 @@ HRESULT CALLBACK pycmd( PDEBUG_CLIENT4 client, PCSTR args ) { - if ( g_dbgClient->client() != client ) - { - DebugClientPtr dbgClient = DebugClient::createDbgClient( client ); - DebugClient::setDbgClientCurrent( dbgClient ); - } - - WindbgGlobalSession::RestorePyState(); - - ULONG mask = 0; - client->GetOutputMask( &mask ); - - try { - - // ��������������� ����������� ������� �� - python::object sys = python::import("sys"); - - sys.attr("stdout") = python::object( DbgOut( client ) ); - sys.attr("stderr") = python::object( DbgOut( client ) ); - sys.attr("stdin") = python::object( DbgIn( client ) ); - - client->SetOutputMask( DEBUG_OUTPUT_NORMAL ); - - PyRun_String( - "__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()", - Py_file_input, - WindbgGlobalSession::global().ptr(), - WindbgGlobalSession::global().ptr() - ); - - // ����� �� �������������� ���������� ����� ���������� raise SystemExit(code) - // ������� ����� ����� �������� ���������� callback �� - PyErr_Clear(); - } - catch(...) - { - //dbgClient->eprintln( L"unexpected error" ); - } - - client->SetOutputMask( mask ); - - WindbgGlobalSession::SavePyState(); - - return S_OK; + return S_OK; } //////////////////////////////////////////////////////////////////////////////// + + + + + + + + + +////////////////////////////////////////////////////////////////////////////////// +// +//extern "C" void initpykd(); +// +////////////////////////////////////////////////////////////////////////////////// +// +//WindbgGlobalSession::WindbgGlobalSession() { +// +// PyImport_AppendInittab("pykd", initpykd ); +// +// PyEval_InitThreads(); +// +// Py_Initialize(); +// +// main = boost::python::import("__main__"); +// +// python::object main_namespace = main.attr("__dict__"); +// +// // ������ ������ from pykd import * +// python::object pykd = boost::python::import( "pykd" ); +// +// python::dict pykd_namespace( pykd.attr("__dict__") ); +// +// python::list iterkeys( pykd_namespace.iterkeys() ); +// +// for (int i = 0; i < boost::python::len(iterkeys); i++) +// { +// std::string key = boost::python::extract<std::string>(iterkeys[i]); +// +// main_namespace[ key ] = pykd_namespace[ key ]; +// } +// +// pyState = PyEval_SaveThread(); +//} +// +// +//volatile LONG WindbgGlobalSession::sessionCount = 0; +// +//WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL; +// +/////////////////////////////////////////////////////////////////////////////////// +// +//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(); +//} +// +////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT +//CALLBACK +//py( PDEBUG_CLIENT4 client, PCSTR args ) +//{ +// DebugClientPtr dbgClient = DebugClient::createDbgClient( client ); +// DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient ); +// +// WindbgGlobalSession::RestorePyState(); +// +// PyThreadState *globalInterpreter = PyThreadState_Swap( NULL ); +// PyThreadState *localInterpreter = Py_NewInterpreter(); +// +// try { +// +// // �������� ������ � ����������� ���� ( ����� ��� ������ exec_file ) +// python::object main = python::import("__main__"); +// +// python::object global(main.attr("__dict__")); +// +// // ����������� ����/����� ( ����� � ������� ����� ���� ������ print ) +// +// python::object sys = python::import("sys"); +// +// sys.attr("stdout") = python::object( dbgClient->dout() ); +// sys.attr("stderr") = python::object( dbgClient->dout() ); +// sys.attr("stdin") = python::object( dbgClient->din() ); +// +// // ����������� ������ ��������� ���������� ( ����� ��� ������ traceback � ) +// python::object tracebackModule = python::import("traceback"); +// +// // ������ ���������� +// typedef boost::escaped_list_separator<char> 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<std::string> 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<char*>( argsList[i].c_str() ); +// +// PySys_SetArgv( (int)argsList.size(), pythonArgs ); +// +// delete[] pythonArgs; +// +// // ����� ���� � ����� +// std::string fullScriptName; +// DbgPythonPath dbgPythonPath; +// +// if ( !dbgPythonPath.getFullFileName( argsList[0], fullScriptName ) ) +// { +// dbgClient->eprintln( L"script file not found" ); +// } +// else +// try { +// +// python::object result; +// +// result = python::exec_file( fullScriptName.c_str(), global, global ); +// } +// catch( boost::python::error_already_set const & ) +// { +// // ������ � ������� +// PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL; +// +// PyErr_Fetch( &errtype, &errvalue, &traceback ); +// +// PyErr_NormalizeException( &errtype, &errvalue, &traceback ); +// +// std::wstringstream sstr; +// +// python::object lst = +// python::object( tracebackModule.attr("format_exception" ) )( +// python::handle<>( errtype ), +// python::handle<>( python::allow_null( errvalue ) ), +// python::handle<>( python::allow_null( traceback ) ) ); +// +// sstr << std::endl << std::endl; +// +// for ( long i = 0; i < python::len(lst); ++i ) +// sstr << std::wstring( python::extract<std::wstring>(lst[i]) ) << std::endl; +// +// dbgClient->eprintln( sstr.str() ); +// } +// +// } +// catch(...) +// { +// dbgClient->eprintln( L"unexpected error" ); +// } +// +// Py_EndInterpreter( localInterpreter ); +// PyThreadState_Swap( globalInterpreter ); +// +// WindbgGlobalSession::SavePyState(); +// +// DebugClient::setDbgClientCurrent( oldClient ); +// +// return S_OK; +//} +// +////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT +//CALLBACK +//pycmd( PDEBUG_CLIENT4 client, PCSTR args ) +//{ +// if ( g_dbgClient->client() != client ) +// { +// DebugClientPtr dbgClient = DebugClient::createDbgClient( client ); +// DebugClient::setDbgClientCurrent( dbgClient ); +// } +// +// WindbgGlobalSession::RestorePyState(); +// +// ULONG mask = 0; +// client->GetOutputMask( &mask ); +// +// try { +// +// // ��������������� ����������� ������� �� +// python::object sys = python::import("sys"); +// +// sys.attr("stdout") = python::object( DbgOut( client ) ); +// sys.attr("stderr") = python::object( DbgOut( client ) ); +// sys.attr("stdin") = python::object( DbgIn( client ) ); +// +// client->SetOutputMask( DEBUG_OUTPUT_NORMAL ); +// +// PyRun_String( +// "__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()", +// Py_file_input, +// WindbgGlobalSession::global().ptr(), +// WindbgGlobalSession::global().ptr() +// ); +// +// // ����� �� �������������� ���������� ����� ���������� raise SystemExit(code) +// // ������� ����� ����� �������� ���������� callback �� +// PyErr_Clear(); +// } +// catch(...) +// { +// //dbgClient->eprintln( L"unexpected error" ); +// } +// +// client->SetOutputMask( mask ); +// +// WindbgGlobalSession::SavePyState(); +// +// return S_OK; +//} +// +////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/module.cpp b/pykd/module.cpp index 5c74aa9..b4adc1d 100644 --- a/pykd/module.cpp +++ b/pykd/module.cpp @@ -1,423 +1,462 @@ #include "stdafx.h" - +#include "dbgengine.h" #include "module.h" -#include "dbgclient.h" -#include "dbgmem.h" namespace pykd { /////////////////////////////////////////////////////////////////////////////////// ModulePtr Module::loadModuleByName( const std::string &moduleName ) { - return g_dbgClient->loadModuleByName( moduleName ); + return ModulePtr( new Module( moduleName ) ); }; ModulePtr Module::loadModuleByOffset( ULONG64 offset ) { - return g_dbgClient->loadModuleByOffset( offset ); + return ModulePtr( new Module( offset ) ); } -/////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// -Module::Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, const std::string& moduleName ) - : DbgObject( client ) - , m_synSymbols(synSymbols) +Module::Module(const std::string &moduleName ) { - HRESULT hres; - + m_base = findModuleBase( moduleName ); m_name = moduleName; - - hres = m_symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &m_base ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); - - DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; - hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); - - m_size = moduleParam.Size; - m_timeDataStamp = moduleParam.TimeDateStamp; - m_checkSum = moduleParam.Checksum; - - char imageName[0x100]; - - hres = m_symbols->GetModuleNameString( - DEBUG_MODNAME_IMAGE, - DEBUG_ANY_ID, - m_base, - imageName, - sizeof( imageName ), - NULL ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); - - m_imageName = std::string( imageName ); } -/////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// -Module::Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, ULONG64 offset ) - : DbgObject( client ) - , m_synSymbols(synSymbols) +Module::Module(ULONG64 offset ) { - HRESULT hres; - - offset = addr64( offset ); - - ULONG moduleIndex; - hres = m_symbols->GetModuleByOffset( offset, 0, &moduleIndex, &m_base ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleByOffset failed" ); - - char moduleName[0x100]; - - hres = m_symbols->GetModuleNameString( - DEBUG_MODNAME_MODULE, - moduleIndex, - 0, - moduleName, - sizeof( moduleName ), - NULL ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); - - m_name = std::string( moduleName ); - - char imageName[0x100]; - - hres = m_symbols->GetModuleNameString( - DEBUG_MODNAME_IMAGE, - DEBUG_ANY_ID, - m_base, - imageName, - sizeof( imageName ), - NULL ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); - - m_imageName = std::string( imageName ); - - DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; - hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); - - m_size = moduleParam.Size; - m_timeDataStamp = moduleParam.TimeDateStamp; - m_checkSum = moduleParam.Checksum; + m_base = findModuleBase( addr64(offset) ); + m_name = getModuleName( m_base ); } -/////////////////////////////////////////////////////////////////////////////////// - -std::string -Module::getPdbName() -{ - HRESULT hres; - - IMAGEHLP_MODULEW64 moduleInfo = {}; - - hres = m_advanced->GetSymbolInformation( - DEBUG_SYMINFO_IMAGEHLP_MODULEW64, - m_base, - 0, - &moduleInfo, - sizeof(moduleInfo), - NULL, - NULL, - 0, - NULL ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" ); - - if (!*moduleInfo.LoadedPdbName) - { - reloadSymbolsImpl(); - - hres = m_advanced->GetSymbolInformation( - DEBUG_SYMINFO_IMAGEHLP_MODULEW64, - m_base, - 0, - &moduleInfo, - sizeof(moduleInfo), - NULL, - NULL, - 0, - NULL ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" ); - } - - char pdbName[ 256 ]; - WideCharToMultiByte( CP_ACP, 0, moduleInfo.LoadedPdbName, 256, pdbName, 256, NULL, NULL ); - - return std::string( pdbName ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -void -Module::reloadSymbolsImpl() -{ - HRESULT hres; - - std::string param = "/f "; - param += m_imageName; - - hres = m_symbols->Reload( param.c_str() ); - if ( FAILED( hres ) ) - throw DbgException("IDebugSymbols::Reload failed" ); -} - - -/////////////////////////////////////////////////////////////////////////////////// - -void -Module::reloadSymbols() -{ - reloadSymbolsImpl(); - - m_dia.reset(); - m_dia = pyDia::GlobalScope::loadPdb( getPdbName() ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVarPtr -Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ) -{ - return TypedVar::getTypedVar( m_client, getTypeByName(typeName), VarDataMemory::factory(m_dataSpaces, addr) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVarPtr -Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr ) -{ - return TypedVar::getTypedVar( m_client, typeInfo, VarDataMemory::factory(m_dataSpaces, addr) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -ULONG64 -Module::getSymbolSize( const std::string &symName ) -{ - try { - - pyDia::SymbolPtr symVar = getDia()->getChildByName( symName ); - - if ( symVar->getSymTag() == SymTagData ) - return symVar->getSize(); - - } catch( const SymbolException& ) - { - } - - return getTypeByName(symName)->getSize(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVarPtr -Module::getTypedVarByName( const std::string &symName ) -{ - HRESULT hres; - - pyDia::SymbolPtr symVar = getDia()->getChildByName( symName ); - - std::string fullName = m_name; - fullName += '!'; - fullName += symName; - - ULONG64 offset; - - hres = m_symbols->GetOffsetByName( fullName.c_str(), &offset ); - - TypeInfoPtr typeInfo = TypeInfo::getTypeInfo( symVar->getType() ); - - if ( FAILED( hres ) ) - { - if ( LocIsConstant == symVar->getLocType() ) - return TypedVar::getTypedVar( m_client, typeInfo, VarDataConst::factory(m_control, symVar) ); - throw DbgException("IDebugSymbols::GetOffsetByName failed" ); - } - - return TypedVar::getTypedVar( m_client, typeInfo, VarDataMemory::factory(m_dataSpaces, offset) ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVarPtr -Module::getTypedVarByAddr( ULONG64 addr ) -{ - HRESULT hres; - - addr = addr64(addr); - - if ( addr < m_base || addr > getEnd() ) - throw DbgException( "address is out of the module space" ); - - char nameBuf[0x100]; - - hres = - m_symbols->GetNameByOffset( - addr, - nameBuf, - sizeof(nameBuf), - NULL, - NULL ); - - std::string fullName( nameBuf ); - - size_t symPos = fullName.find ( '!' ) + 1; - - std::string symbolName; - symbolName.assign( fullName, symPos, fullName.length() - symPos ); - - if ( FAILED(hres) ) - throw DbgException( "failed IDebugSymbols::GetNameByOffset" ); - - return getTypedVarByName( symbolName ); - - //LONG displacement; - //pyDia::SymbolPtr diaSym = - // getDia()->findByRvaImpl((ULONG)(addr - m_base), SymTagData, displacement); - //if (displacement) - // throw DbgException( "not exactly match by RVA" ); - - //return TypedVar::getTypedVar( m_client, TypeInfo::getTypeInfo( diaSym->getType() ), addr ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -ULONG Module::getRvaByName(const std::string &symName) -{ - HRESULT hres; - ULONG64 offset; - - hres = m_symbols->GetOffsetByName( symName.c_str(), &offset ); - if ( SUCCEEDED(hres) ) - return (ULONG)(offset - m_base); - - return (ULONG)m_synSymbols->getRvaByName(m_timeDataStamp, m_checkSum, symName); - - //try { - // pyDia::SymbolPtr sym = getDia()->getChildByName( symName ); - // return sym->getRva(); - //} - //catch (const pyDia::Exception &) { - //} - //return (ULONG)m_synSymbols->getRvaByName(m_timeDataStamp, m_checkSumm, symName); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVarPtr Module::containingRecordByName( ULONG64 address, const std::string &typeName, const std::string &fieldName ) -{ - address = addr64(address); - - TypeInfoPtr typeInfo = getTypeByName( typeName ); - - VarDataPtr varData = - VarDataMemory::factory( - m_dataSpaces, - address - typeInfo->getFieldOffsetByNameRecirsive( fieldName ) - ); - - return TypedVar::getTypedVar( m_client, typeInfo, varData ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -TypedVarPtr Module::containingRecordByType( ULONG64 address, const TypeInfoPtr &typeInfo, const std::string &fieldName ) -{ - address = addr64(address); - - VarDataPtr varData = - VarDataMemory::factory( - m_dataSpaces, - address - typeInfo->getFieldOffsetByNameRecirsive( fieldName ) - ); - - return TypedVar::getTypedVar( m_client, typeInfo, varData ); -} - - -/////////////////////////////////////////////////////////////////////////////////// - -python::list Module::getTypedVarListByTypeName( ULONG64 listHeadAddress, const std::string &typeName, const std::string &listEntryName ) -{ - return getTypedVarListByType( listHeadAddress, getTypeByName( typeName ), listEntryName ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -python::list Module::getTypedVarListByType( ULONG64 listHeadAddress, const TypeInfoPtr &typeInfo, const std::string &listEntryName ) -{ - python::list lst; - - listHeadAddress = addr64( listHeadAddress ); - - ULONG64 entryAddress = 0; - - TypeInfoPtr fieldTypeInfo = typeInfo->getField( listEntryName ); - - if ( fieldTypeInfo->getName() == ( typeInfo->getName() + "*" ) ) - { - for( entryAddress = ptrPtr( listHeadAddress, m_dataSpaces ); addr64(entryAddress) != listHeadAddress && entryAddress != NULL; entryAddress = ptrPtr( entryAddress + typeInfo->getFieldOffsetByNameRecirsive(listEntryName) ) ) - lst.append( getTypedVarByType( typeInfo, entryAddress ) ); - } - else - { - for( entryAddress = ptrPtr( listHeadAddress, m_dataSpaces ); addr64(entryAddress) != listHeadAddress && entryAddress != NULL; entryAddress = ptrPtr( entryAddress ) ) - lst.append( containingRecordByType( entryAddress, typeInfo, listEntryName ) ); - } - - return lst; -} - -/////////////////////////////////////////////////////////////////////////////////// - -python::list Module::getTypedVarArrayByTypeName( ULONG64 addr, const std::string &typeName, ULONG number ) -{ - return getTypedVarArrayByType( addr, getTypeByName( typeName ), number ); -} - -/////////////////////////////////////////////////////////////////////////////////// - -python::list Module::getTypedVarArrayByType( ULONG64 address, const TypeInfoPtr &typeInfo, ULONG number ) -{ - address = addr64(address); - - python::list lst; - - for( ULONG i = 0; i < number; ++i ) - lst.append( getTypedVarByType( typeInfo, address + i * typeInfo->getSize() ) ); - - return lst; -} - -/////////////////////////////////////////////////////////////////////////////////// - -std::string Module::print() -{ - std::stringstream sstr; - - sstr << "Module: " << m_name << std::endl; - sstr << "Start: " << std::hex << m_base << " End: " << getEnd() << " Size: " << m_size << std::endl; - sstr << "Image: " << m_imageName << std::endl; - sstr << "Pdb: " << getPdbName() << std::endl; - sstr << "Timestamp: " << m_timeDataStamp << std::endl; - sstr << "Check Sum: " << m_checkSum << std::endl; - - return sstr.str(); -} - -/////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////// }; // end of namespace pykd + + + + + +//#include "module.h" +//#include "dbgclient.h" +//#include "dbgmem.h" +// +//namespace pykd { +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ModulePtr Module::loadModuleByName( const std::string &moduleName ) { +// return g_dbgClient->loadModuleByName( moduleName ); +//}; +// +//ModulePtr Module::loadModuleByOffset( ULONG64 offset ) { +// return g_dbgClient->loadModuleByOffset( offset ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//Module::Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, const std::string& moduleName ) +// : DbgObject( client ) +// , m_synSymbols(synSymbols) +//{ +// HRESULT hres; +// +// m_name = moduleName; +// +// hres = m_symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &m_base ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); +// +// DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; +// hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); +// +// m_size = moduleParam.Size; +// m_timeDataStamp = moduleParam.TimeDateStamp; +// m_checkSum = moduleParam.Checksum; +// +// char imageName[0x100]; +// +// hres = m_symbols->GetModuleNameString( +// DEBUG_MODNAME_IMAGE, +// DEBUG_ANY_ID, +// m_base, +// imageName, +// sizeof( imageName ), +// NULL ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); +// +// m_imageName = std::string( imageName ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//Module::Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, ULONG64 offset ) +// : DbgObject( client ) +// , m_synSymbols(synSymbols) +//{ +// HRESULT hres; +// +// offset = addr64( offset ); +// +// ULONG moduleIndex; +// hres = m_symbols->GetModuleByOffset( offset, 0, &moduleIndex, &m_base ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleByOffset failed" ); +// +// char moduleName[0x100]; +// +// hres = m_symbols->GetModuleNameString( +// DEBUG_MODNAME_MODULE, +// moduleIndex, +// 0, +// moduleName, +// sizeof( moduleName ), +// NULL ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); +// +// m_name = std::string( moduleName ); +// +// char imageName[0x100]; +// +// hres = m_symbols->GetModuleNameString( +// DEBUG_MODNAME_IMAGE, +// DEBUG_ANY_ID, +// m_base, +// imageName, +// sizeof( imageName ), +// NULL ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); +// +// m_imageName = std::string( imageName ); +// +// DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; +// hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam ); +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); +// +// m_size = moduleParam.Size; +// m_timeDataStamp = moduleParam.TimeDateStamp; +// m_checkSum = moduleParam.Checksum; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//std::string +//Module::getPdbName() +//{ +// HRESULT hres; +// +// IMAGEHLP_MODULEW64 moduleInfo = {}; +// +// hres = m_advanced->GetSymbolInformation( +// DEBUG_SYMINFO_IMAGEHLP_MODULEW64, +// m_base, +// 0, +// &moduleInfo, +// sizeof(moduleInfo), +// NULL, +// NULL, +// 0, +// NULL ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" ); +// +// if (!*moduleInfo.LoadedPdbName) +// { +// reloadSymbolsImpl(); +// +// hres = m_advanced->GetSymbolInformation( +// DEBUG_SYMINFO_IMAGEHLP_MODULEW64, +// m_base, +// 0, +// &moduleInfo, +// sizeof(moduleInfo), +// NULL, +// NULL, +// 0, +// NULL ); +// +// if ( FAILED( hres ) ) +// throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" ); +// } +// +// char pdbName[ 256 ]; +// WideCharToMultiByte( CP_ACP, 0, moduleInfo.LoadedPdbName, 256, pdbName, 256, NULL, NULL ); +// +// return std::string( pdbName ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//void +//Module::reloadSymbolsImpl() +//{ +// HRESULT hres; +// +// std::string param = "/f "; +// param += m_imageName; +// +// hres = m_symbols->Reload( param.c_str() ); +// if ( FAILED( hres ) ) +// throw DbgException("IDebugSymbols::Reload failed" ); +//} +// +// +///////////////////////////////////////////////////////////////////////////////////// +// +//void +//Module::reloadSymbols() +//{ +// reloadSymbolsImpl(); +// +// m_dia.reset(); +// m_dia = pyDia::GlobalScope::loadPdb( getPdbName() ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVarPtr +//Module::getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ) +//{ +// return TypedVar::getTypedVar( m_client, getTypeByName(typeName), VarDataMemory::factory(m_dataSpaces, addr) ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVarPtr +//Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr ) +//{ +// return TypedVar::getTypedVar( m_client, typeInfo, VarDataMemory::factory(m_dataSpaces, addr) ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ULONG64 +//Module::getSymbolSize( const std::string &symName ) +//{ +// try { +// +// pyDia::SymbolPtr symVar = getDia()->getChildByName( symName ); +// +// if ( symVar->getSymTag() == SymTagData ) +// return symVar->getSize(); +// +// } catch( const SymbolException& ) +// { +// } +// +// return getTypeByName(symName)->getSize(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVarPtr +//Module::getTypedVarByName( const std::string &symName ) +//{ +// HRESULT hres; +// +// pyDia::SymbolPtr symVar = getDia()->getChildByName( symName ); +// +// std::string fullName = m_name; +// fullName += '!'; +// fullName += symName; +// +// ULONG64 offset; +// +// hres = m_symbols->GetOffsetByName( fullName.c_str(), &offset ); +// +// TypeInfoPtr typeInfo = TypeInfo::getTypeInfo( symVar->getType() ); +// +// if ( FAILED( hres ) ) +// { +// if ( LocIsConstant == symVar->getLocType() ) +// return TypedVar::getTypedVar( m_client, typeInfo, VarDataConst::factory(m_control, symVar) ); +// throw DbgException("IDebugSymbols::GetOffsetByName failed" ); +// } +// +// return TypedVar::getTypedVar( m_client, typeInfo, VarDataMemory::factory(m_dataSpaces, offset) ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVarPtr +//Module::getTypedVarByAddr( ULONG64 addr ) +//{ +// HRESULT hres; +// +// addr = addr64(addr); +// +// if ( addr < m_base || addr > getEnd() ) +// throw DbgException( "address is out of the module space" ); +// +// char nameBuf[0x100]; +// +// hres = +// m_symbols->GetNameByOffset( +// addr, +// nameBuf, +// sizeof(nameBuf), +// NULL, +// NULL ); +// +// std::string fullName( nameBuf ); +// +// size_t symPos = fullName.find ( '!' ) + 1; +// +// std::string symbolName; +// symbolName.assign( fullName, symPos, fullName.length() - symPos ); +// +// if ( FAILED(hres) ) +// throw DbgException( "failed IDebugSymbols::GetNameByOffset" ); +// +// return getTypedVarByName( symbolName ); +// +// //LONG displacement; +// //pyDia::SymbolPtr diaSym = +// // getDia()->findByRvaImpl((ULONG)(addr - m_base), SymTagData, displacement); +// //if (displacement) +// // throw DbgException( "not exactly match by RVA" ); +// +// //return TypedVar::getTypedVar( m_client, TypeInfo::getTypeInfo( diaSym->getType() ), addr ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//ULONG Module::getRvaByName(const std::string &symName) +//{ +// HRESULT hres; +// ULONG64 offset; +// +// hres = m_symbols->GetOffsetByName( symName.c_str(), &offset ); +// if ( SUCCEEDED(hres) ) +// return (ULONG)(offset - m_base); +// +// return (ULONG)m_synSymbols->getRvaByName(m_timeDataStamp, m_checkSum, symName); +// +// //try { +// // pyDia::SymbolPtr sym = getDia()->getChildByName( symName ); +// // return sym->getRva(); +// //} +// //catch (const pyDia::Exception &) { +// //} +// //return (ULONG)m_synSymbols->getRvaByName(m_timeDataStamp, m_checkSumm, symName); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVarPtr Module::containingRecordByName( ULONG64 address, const std::string &typeName, const std::string &fieldName ) +//{ +// address = addr64(address); +// +// TypeInfoPtr typeInfo = getTypeByName( typeName ); +// +// VarDataPtr varData = +// VarDataMemory::factory( +// m_dataSpaces, +// address - typeInfo->getFieldOffsetByNameRecirsive( fieldName ) +// ); +// +// return TypedVar::getTypedVar( m_client, typeInfo, varData ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//TypedVarPtr Module::containingRecordByType( ULONG64 address, const TypeInfoPtr &typeInfo, const std::string &fieldName ) +//{ +// address = addr64(address); +// +// VarDataPtr varData = +// VarDataMemory::factory( +// m_dataSpaces, +// address - typeInfo->getFieldOffsetByNameRecirsive( fieldName ) +// ); +// +// return TypedVar::getTypedVar( m_client, typeInfo, varData ); +//} +// +// +///////////////////////////////////////////////////////////////////////////////////// +// +//python::list Module::getTypedVarListByTypeName( ULONG64 listHeadAddress, const std::string &typeName, const std::string &listEntryName ) +//{ +// return getTypedVarListByType( listHeadAddress, getTypeByName( typeName ), listEntryName ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//python::list Module::getTypedVarListByType( ULONG64 listHeadAddress, const TypeInfoPtr &typeInfo, const std::string &listEntryName ) +//{ +// python::list lst; +// +// listHeadAddress = addr64( listHeadAddress ); +// +// ULONG64 entryAddress = 0; +// +// TypeInfoPtr fieldTypeInfo = typeInfo->getField( listEntryName ); +// +// if ( fieldTypeInfo->getName() == ( typeInfo->getName() + "*" ) ) +// { +// for( entryAddress = ptrPtr( listHeadAddress, m_dataSpaces ); addr64(entryAddress) != listHeadAddress && entryAddress != NULL; entryAddress = ptrPtr( entryAddress + typeInfo->getFieldOffsetByNameRecirsive(listEntryName) ) ) +// lst.append( getTypedVarByType( typeInfo, entryAddress ) ); +// } +// else +// { +// for( entryAddress = ptrPtr( listHeadAddress, m_dataSpaces ); addr64(entryAddress) != listHeadAddress && entryAddress != NULL; entryAddress = ptrPtr( entryAddress ) ) +// lst.append( containingRecordByType( entryAddress, typeInfo, listEntryName ) ); +// } +// +// return lst; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//python::list Module::getTypedVarArrayByTypeName( ULONG64 addr, const std::string &typeName, ULONG number ) +//{ +// return getTypedVarArrayByType( addr, getTypeByName( typeName ), number ); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//python::list Module::getTypedVarArrayByType( ULONG64 address, const TypeInfoPtr &typeInfo, ULONG number ) +//{ +// address = addr64(address); +// +// python::list lst; +// +// for( ULONG i = 0; i < number; ++i ) +// lst.append( getTypedVarByType( typeInfo, address + i * typeInfo->getSize() ) ); +// +// return lst; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//std::string Module::print() +//{ +// std::stringstream sstr; +// +// sstr << "Module: " << m_name << std::endl; +// sstr << "Start: " << std::hex << m_base << " End: " << getEnd() << " Size: " << m_size << std::endl; +// sstr << "Image: " << m_imageName << std::endl; +// sstr << "Pdb: " << getPdbName() << std::endl; +// sstr << "Timestamp: " << m_timeDataStamp << std::endl; +// sstr << "Check Sum: " << m_checkSum << std::endl; +// +// return sstr.str(); +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//}; // end of namespace pykd +// diff --git a/pykd/module.h b/pykd/module.h index 9a11be1..f1bb3ff 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -1,12 +1,6 @@ #pragma once -#include <string> - -#include "dbgobj.h" -#include "diawrapper.h" -#include "typeinfo.h" -#include "typedvar.h" -#include "synsymbol.h" +#include "intbase.h" namespace pykd { @@ -17,7 +11,7 @@ typedef boost::shared_ptr<Module> ModulePtr; /////////////////////////////////////////////////////////////////////////////////// -class Module : public intBase, private DbgObject { +class Module : public intBase { public: @@ -28,19 +22,15 @@ public: ModulePtr loadModuleByOffset( ULONG64 offset ); public: - - Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, const std::string& moduleName ); - Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, ULONG64 offset ); + Module(const std::string &name ); + + Module(ULONG64 offset ); std::string getName() { return m_name; } - std::string getImageName() { - return m_imageName; - } - ULONG64 getBase() const { return m_base; } @@ -53,94 +43,20 @@ public: return m_size; } - std::string - getPdbName(); - void - reloadSymbols(); - - ULONG64 - getSymbol( const std::string &symbolname ) { - return m_base + getRvaByName(symbolname); + reloadSymbols() + { } - ULONG - getSymbolRva( const std::string &symbolname ) { - return getRvaByName(symbolname); - } - - TypeInfoPtr getTypeByName( const std::string &typeName ) { - return TypeInfo::getTypeInfo( boost::static_pointer_cast<pyDia::Symbol>( getDia() ), typeName); - } - - TypedVarPtr getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ); - - TypedVarPtr getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr ); - - TypedVarPtr getTypedVarByAddr( ULONG64 addr ); - - TypedVarPtr getTypedVarByName( const std::string &symName ); - - TypedVarPtr containingRecordByName( ULONG64 addr, const std::string &typeName, const std::string &fieldName ); - - TypedVarPtr containingRecordByType( ULONG64 addr, const TypeInfoPtr &typeInfo, const std::string &fieldName ); - - python::list getTypedVarListByTypeName( ULONG64 listHeadAddres, const std::string &typeName, const std::string &listEntryName ); - - python::list getTypedVarListByType( ULONG64 listHeadAddres, const TypeInfoPtr &typeInfo, const std::string &listEntryName ); - - python::list getTypedVarArrayByTypeName( ULONG64 addr, const std::string &typeName, ULONG number ); - - python::list getTypedVarArrayByType( ULONG64 addr, const TypeInfoPtr &typeInfo, ULONG number ); - - ULONG64 getSymbolSize( const std::string &symName ); - - pyDia::GlobalScopePtr& getDia() { - if (!m_dia) - { - m_dia = pyDia::GlobalScope::loadPdb( getPdbName() ); - if ( m_dia ) - { - m_dia->setLoadAddress( m_base ); - } - } - - return m_dia; - } - - ULONG getCheckSum() const { - return m_checkSum; - } - - ULONG getTimeDataStamp() const { - return m_timeDataStamp; - } - - std::string print(); - private: - void - reloadSymbolsImpl(); - - - ULONG getRvaByName(const std::string &symName); - BaseTypeVariant getValue() { return BaseTypeVariant(m_base); } - std::string m_name; - std::string m_imageName; ULONG64 m_base; ULONG m_size; - - pyDia::GlobalScopePtr m_dia; - - ULONG m_timeDataStamp; - ULONG m_checkSum; - SynSymbolsPtr m_synSymbols; }; /////////////////////////////////////////////////////////////////////////////////// @@ -148,3 +64,155 @@ private: }; // end pykd namespace + + + + +//#include <string> +// +//#include "dbgobj.h" +//#include "diawrapper.h" +//#include "typeinfo.h" +//#include "typedvar.h" +//#include "synsymbol.h" +// +//namespace pykd { +// +///////////////////////////////////////////////////////////////////////////////////// +// +//class Module; +//typedef boost::shared_ptr<Module> ModulePtr; +// +///////////////////////////////////////////////////////////////////////////////////// +// +//class Module : public intBase, private DbgObject { +// +//public: +// +// static +// ModulePtr loadModuleByName( const std::string &name ); +// +// static +// ModulePtr loadModuleByOffset( ULONG64 offset ); +// +//public: +// +// Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, const std::string& moduleName ); +// +// Module( IDebugClient4 *client, SynSymbolsPtr synSymbols, ULONG64 offset ); +// +// std::string getName() { +// return m_name; +// } +// +// std::string getImageName() { +// return m_imageName; +// } +// +// ULONG64 getBase() const { +// return m_base; +// } +// +// ULONG64 getEnd() const { +// return m_base + m_size; +// } +// +// ULONG getSize() const { +// return m_size; +// } +// +// std::string +// getPdbName(); +// +// void +// reloadSymbols(); +// +// ULONG64 +// getSymbol( const std::string &symbolname ) { +// return m_base + getRvaByName(symbolname); +// } +// +// ULONG +// getSymbolRva( const std::string &symbolname ) { +// return getRvaByName(symbolname); +// } +// +// TypeInfoPtr getTypeByName( const std::string &typeName ) { +// return TypeInfo::getTypeInfo( boost::static_pointer_cast<pyDia::Symbol>( getDia() ), typeName); +// } +// +// TypedVarPtr getTypedVarByTypeName( const std::string &typeName, ULONG64 addr ); +// +// TypedVarPtr getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr ); +// +// TypedVarPtr getTypedVarByAddr( ULONG64 addr ); +// +// TypedVarPtr getTypedVarByName( const std::string &symName ); +// +// TypedVarPtr containingRecordByName( ULONG64 addr, const std::string &typeName, const std::string &fieldName ); +// +// TypedVarPtr containingRecordByType( ULONG64 addr, const TypeInfoPtr &typeInfo, const std::string &fieldName ); +// +// python::list getTypedVarListByTypeName( ULONG64 listHeadAddres, const std::string &typeName, const std::string &listEntryName ); +// +// python::list getTypedVarListByType( ULONG64 listHeadAddres, const TypeInfoPtr &typeInfo, const std::string &listEntryName ); +// +// python::list getTypedVarArrayByTypeName( ULONG64 addr, const std::string &typeName, ULONG number ); +// +// python::list getTypedVarArrayByType( ULONG64 addr, const TypeInfoPtr &typeInfo, ULONG number ); +// +// ULONG64 getSymbolSize( const std::string &symName ); +// +// pyDia::GlobalScopePtr& getDia() { +// if (!m_dia) +// { +// m_dia = pyDia::GlobalScope::loadPdb( getPdbName() ); +// if ( m_dia ) +// { +// m_dia->setLoadAddress( m_base ); +// } +// } +// +// return m_dia; +// } +// +// ULONG getCheckSum() const { +// return m_checkSum; +// } +// +// ULONG getTimeDataStamp() const { +// return m_timeDataStamp; +// } +// +// std::string print(); +// +//private: +// +// void +// reloadSymbolsImpl(); +// +// +// ULONG getRvaByName(const std::string &symName); +// +// BaseTypeVariant getValue() { +// return BaseTypeVariant(m_base); +// } +// +// +// std::string m_name; +// std::string m_imageName; +// ULONG64 m_base; +// ULONG m_size; +// +// pyDia::GlobalScopePtr m_dia; +// +// ULONG m_timeDataStamp; +// ULONG m_checkSum; +// SynSymbolsPtr m_synSymbols; +//}; +// +///////////////////////////////////////////////////////////////////////////////////// +// +//}; // end pykd namespace + + diff --git a/pykd/pyaux.h b/pykd/pyaux.h index 63a4385..3f1a32b 100644 --- a/pykd/pyaux.h +++ b/pykd/pyaux.h @@ -2,7 +2,7 @@ #include <windows.h> -#include "windbg.h" +//#include "windbg.h" namespace pykd { @@ -21,23 +21,23 @@ public: } void saveState() { - if ( !WindbgGlobalSession::isInit() ) + //if ( !WindbgGlobalSession::isInit() ) TlsSetValue( m_index, PyEval_SaveThread() ); - else - WindbgGlobalSession::SavePyState(); + //else + // WindbgGlobalSession::SavePyState(); } void restoreState() { - if ( !WindbgGlobalSession::isInit() ) - { + //if ( !WindbgGlobalSession::isInit() ) + //{ PyThreadState* state = (PyThreadState*)TlsGetValue( m_index ); if ( state ) PyEval_RestoreThread( state ); - } - else - { - WindbgGlobalSession::RestorePyState(); - } + //} + //else + //{ + // WindbgGlobalSession::RestorePyState(); + //} } private: diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index c0ab5c4..87606a6 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -349,30 +349,6 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > - <File - RelativePath=".\bpoint.cpp" - > - </File> - <File - RelativePath=".\context.cpp" - > - </File> - <File - RelativePath=".\cpureg.cpp" - > - </File> - <File - RelativePath=".\dbgclient.cpp" - > - </File> - <File - RelativePath=".\dbgcmd.cpp" - > - </File> - <File - RelativePath=".\dbgevent.cpp" - > - </File> <File RelativePath=".\dbgexcept.cpp" > @@ -381,50 +357,10 @@ RelativePath=".\dbgext.cpp" > </File> - <File - RelativePath=".\dbgio.cpp" - > - </File> - <File - RelativePath=".\dbgmem.cpp" - > - </File> - <File - RelativePath=".\dbgpath.cpp" - > - </File> - <File - RelativePath=".\diadata.cpp" - > - </File> - <File - RelativePath=".\diaprint.cpp" - > - </File> - <File - RelativePath=".\diawrapper.cpp" - > - </File> - <File - RelativePath=".\disasm.cpp" - > - </File> - <File - RelativePath=".\inteventhandler.cpp" - > - </File> - <File - RelativePath=".\livevar.cpp" - > - </File> <File RelativePath=".\module.cpp" > </File> - <File - RelativePath=".\process.cpp" - > - </File> <File RelativePath=".\pykd.def" > @@ -470,31 +406,7 @@ </FileConfiguration> </File> <File - RelativePath=".\stkframe.cpp" - > - </File> - <File - RelativePath=".\synsymbol.cpp" - > - </File> - <File - RelativePath=".\synsymhelpers.cpp" - > - </File> - <File - RelativePath=".\typedvar.cpp" - > - </File> - <File - RelativePath=".\typeinfo.cpp" - > - </File> - <File - RelativePath=".\udtutils.cpp" - > - </File> - <File - RelativePath=".\vardata.cpp" + RelativePath=".\windbgeng.cpp" > </File> </Filter> @@ -504,81 +416,21 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File - RelativePath=".\bpoint.h" - > - </File> - <File - RelativePath=".\context.h" - > - </File> - <File - RelativePath=".\cpureg.h" - > - </File> - <File - RelativePath=".\dbgclient.h" - > - </File> - <File - RelativePath=".\dbgcmd.h" - > - </File> - <File - RelativePath=".\dbgevent.h" + RelativePath=".\dbgengine.h" > </File> <File RelativePath=".\dbgexcept.h" > </File> - <File - RelativePath=".\dbgio.h" - > - </File> - <File - RelativePath=".\dbgmem.h" - > - </File> - <File - RelativePath=".\dbgobj.h" - > - </File> - <File - RelativePath=".\dbgpath.h" - > - </File> - <File - RelativePath=".\diacallback.h" - > - </File> - <File - RelativePath=".\diaregs.h" - > - </File> - <File - RelativePath=".\diawrapper.h" - > - </File> - <File - RelativePath=".\disasm.h" - > - </File> <File RelativePath=".\intbase.h" > </File> - <File - RelativePath=".\inteventhandler.h" - > - </File> <File RelativePath=".\module.h" > </File> - <File - RelativePath=".\process.h" - > - </File> <File RelativePath=".\pyaux.h" > @@ -587,48 +439,12 @@ RelativePath=".\pykdver.h" > </File> - <File - RelativePath=".\resource.h" - > - </File> <File RelativePath=".\stdafx.h" > </File> <File - RelativePath=".\stkframe.h" - > - </File> - <File - RelativePath=".\synsymbol.h" - > - </File> - <File - RelativePath=".\synsymhelpers.h" - > - </File> - <File - RelativePath=".\typedvar.h" - > - </File> - <File - RelativePath=".\typeinfo.h" - > - </File> - <File - RelativePath=".\udtutils.h" - > - </File> - <File - RelativePath=".\utils.h" - > - </File> - <File - RelativePath=".\vardata.h" - > - </File> - <File - RelativePath=".\windbg.h" + RelativePath=".\windbgeng.h" > </File> </Filter> diff --git a/pykd/pykdver.h b/pykd/pykdver.h index 495f84b..1212fef 100644 --- a/pykd/pykdver.h +++ b/pykd/pykdver.h @@ -1,8 +1,8 @@ #define PYKD_VERSION_MAJOR 0 -#define PYKD_VERSION_MINOR 1 +#define PYKD_VERSION_MINOR 2 #define PYKD_VERSION_SUBVERSION 0 -#define PYKD_VERSION_BUILDNO 16 +#define PYKD_VERSION_BUILDNO 0 #define __VER_STR2__(x) #x diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index c1d9753..fb41924 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -4,25 +4,11 @@ #include "stdafx.h" -#include <dia2.h> - -#include "module.h" -#include "diawrapper.h" -#include "dbgclient.h" -#include "dbgio.h" -#include "dbgpath.h" -#include "dbgcmd.h" -#include "dbgevent.h" -#include "typeinfo.h" -#include "typedvar.h" -#include "dbgmem.h" -#include "intbase.h" -#include "process.h" -#include "bpoint.h" -#include "stkframe.h" #include "pykdver.h" - -using namespace pykd; +#include "dbgengine.h" +#include "module.h" +#include "intbase.h" +#include "dbgexcept.h" //////////////////////////////////////////////////////////////////////////////// @@ -32,76 +18,23 @@ static const std::string pykdVersion = PYKD_VERSION_BUILD_STR #endif // _DEBUG ; -//////////////////////////////////////////////////////////////////////////////// +using namespace pykd; -static python::dict genDict(const pyDia::Symbol::ValueNameEntry srcValues[], size_t cntValues) -{ - python::dict resDict; - for (size_t i = 0; i < cntValues; ++i) - resDict[srcValues[i].first] = srcValues[i].second; - return resDict; -} - -//////////////////////////////////////////////////////////////////////////////// - -std::string -getDebuggerImage() -{ - std::vector<char> buffer(MAX_PATH); - GetModuleFileNameExA( GetCurrentProcess(), NULL, &buffer[0], (DWORD)buffer.size() ); - return std::string( &buffer[0] ); -} - -//////////////////////////////////////////////////////////////////////////////// - -BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 ); - -BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, loadChars, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, loadWChars, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, loadBytes, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords_, loadWords, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords_, loadDWords, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords_, loadQWords, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, loadSignBytes, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, loadSignWords, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, loadSignDWords, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, loadSignQWords, 2, 3 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, compareMemory, 3, 4 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( getLocals_, getLocals, 0, 1 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( pyDia_GlobalScope_loadExe, pyDia::GlobalScope::loadExe, 1, 2 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 ); - -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadChars, DebugClient::loadChars, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWChars, DebugClient::loadWChars, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadBytes, DebugClient::loadBytes, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWords, DebugClient::loadWords, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadDWords, DebugClient::loadDWords, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadQWords, DebugClient::loadQWords, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignBytes, DebugClient::loadSignBytes, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignWords, DebugClient::loadSignWords, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignDWords, DebugClient::loadSignDWords, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignQWords, DebugClient::loadSignQWords, 2, 3 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_compareMemory, DebugClient::compareMemory, 3, 4 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_getLocals, DebugClient::getLocals, 0, 1 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_setSoftwareBp, DebugClient::setSoftwareBp, 1, 2 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_setHardwareBp, DebugClient::setHardwareBp, 3, 4 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_getSourceLine, DebugClient::getSourceLine, 0, 1 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( StackFrame_getLocals, StackFrame::getLocals, 0, 1 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( pyDia_Symbol_findChildrenEx, pyDia::Symbol::findChildrenEx, 1, 3 ); - - -#define DEF_PY_CONST_ULONG(x) \ - python::scope().attr(#x) = ULONG(##x) +////////////////////////////////////////////////////////////////////////////////// BOOST_PYTHON_MODULE( pykd ) { python::scope().attr("version") = pykdVersion; - python::def( "debuggerPath", &getDebuggerImage, - "Return full path to the process image that uses pykd" ); + python::def( "startProcess", &startProcess, + "Start process for debugging"); + python::def( "detachProcess", &detachProcess, + "Stop process debugging"); + python::def( "killProcess", &terminateProcess, + "Stop debugging and terminate current process" ); + + python::def( "go", &debugGo, + "Go debugging" ); python::class_<intBase>( "intBase", "intBase", python::no_init ) .def( python::init<python::object&>() ) @@ -147,443 +80,6 @@ BOOST_PYTHON_MODULE( pykd ) python::implicitly_convertible<intBase,ULONG>(); python::implicitly_convertible<intBase,LONG>(); - //python::class_<DebugClient, DebugClientPtr>("dbgClient", "Class representing a debugging session", python::no_init ) - // .def( "addr64", &DebugClient::addr64, - // "Extend address to 64 bits formats" ) - // .def( "breakin", &DebugClient::breakin, - // "Break into debugger" ) - // .def( "compareMemory", &DebugClient::compareMemory, DebugClient_compareMemory( python::args( "offset1", "offset2", "length", "phyAddr" ), - // "Compare two memory buffers by virtual or physical addresses" ) ) - // .def( "loadDump", &DebugClient::loadDump, - // "Load crash dump" ) - // .def( "startProcess", &DebugClient::startProcess, - // "Start process for debugging" ) - // .def( "attachProcess", &DebugClient::attachProcess, - // "Attach debugger to a exsisting process" ) - // .def( "attachKernel", &DebugClient::attachKernel, - // "Attach debugger to a target's kernel" ) - // .def( "detachProcess", &DebugClient::detachProcess, - // "Detach debugger from the current process" ) - // .def( "expr", &DebugClient::evaluate, - // "Evaluate windbg expression" ) - // .def( "findSymbol", &DebugClient::findSymbol, - // "Find symbol by the target virtual memory offset" ) - // .def( "getCurrentProcess", &DebugClient::getCurrentProcess, - // "Return pointer to current process's block" ) - // .def( "getCurrentStack", &DebugClient::getCurrentStack, - // "Return a current stack as a list of stackFrame objects" ) - // .def( "getDebuggeeType", &DebugClient::getDebuggeeType, - // "Return type of the debuggee" ) - // .def( "getImplicitThread", &DebugClient::getImplicitThread, - // "Return implicit thread for current process" ) - // .def( "getExecutionStatus", &DebugClient::getExecutionStatus, - // "Return information about the execution status of the debugger" ) - // .def( "getOffset", &DebugClient::getOffset, - // "Return traget virtual address for specified symbol" ) - // .def( "getPdbFile", &DebugClient::getPdbFile, - // "Return full path to PDB (Program DataBase, debug information) file" ) - // .def( "getProcessorMode", &DebugClient::getProcessorMode, - // "Return current processor mode as string: X86, ARM, IA64 or X64" ) - // .def( "getProcessorType", &DebugClient::getProcessorType, - // "Return type of physical processor: X86, ARM, IA64 or X64" ) - // .def( "getSourceLine", &DebugClient::getSourceLine, DebugClient_getSourceLine( python::args( "offset"), - // "Return source file name, lin and displacement by the specified offset" ) ) - // .def( "getThreadList", &DebugClient::getThreadList, - // "Return list of threads (each item is numeric identifier of thread)" ) - // .def( "go", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_GO>, - // "Change debugger status to DEBUG_STATUS_GO" ) - // .def( "is64bitSystem", &DebugClient::is64bitSystem, - // "Check if target system has 64 address space" ) - // .def( "isDumpAnalyzing", &DebugClient::isDumpAnalyzing, - // "Check if it is a dump analyzing ( not living debuggee )" ) - // .def( "isKernelDebugging", &DebugClient::isKernelDebugging, - // "Check if kernel dubugging is running" ) - // .def( "isValid", &DebugClient::isVaValid, - // "Check if the virtual address is valid" ) - // .def( "killProcess", &DebugClient::terminateProcess, - // "Stop debugging and terminate current process" ) - // .def( "loadBytes", &DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of unsigned bytes" ) ) - // .def( "loadWords", &DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of unsigned shorts" ) ) - // .def( "loadDWords", &DebugClient::loadDWords, DebugClient_loadDWords( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ) - // .def( "loadQWords", &DebugClient::loadQWords, DebugClient_loadQWords( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ) - // .def( "loadSignBytes", &DebugClient::loadSignBytes, DebugClient_loadSignBytes( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of signed bytes" ) ) - // .def( "loadSignWords", &DebugClient::loadSignWords, DebugClient_loadSignWords( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of signed shorts" ) ) - // .def( "loadSignDWords", &DebugClient::loadSignDWords, DebugClient_loadSignDWords( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of signed longs" ) ) - // .def( "loadSignQWords", &DebugClient::loadSignQWords, DebugClient_loadSignQWords( python::args( "offset", "count", "phyAddr" ), - // "Read the block of the target's memory and return it as list of signed long longs" ) ) - // .def( "loadChars", &DebugClient::loadChars, DebugClient_loadChars( python::args( "offset", "count", "phyAddr" ), - // "Load string from target memory" ) ) - // .def( "loadWChars", &DebugClient::loadWChars, DebugClient_loadWChars( python::args( "offset", "count", "phyAddr" ), - // "Load string from target memory" ) ) - // .def( "loadCStr", &DebugClient::loadCStr, - // "Load string from the target buffer containing 0-terminated ansi-string" ) - // .def( "loadWStr", &DebugClient::loadWStr, - // "Load string from the target buffer containing 0-terminated unicode-string" ) - // .def( "loadUnicodeString", &DebugClient::loadUnicodeStr, - // "Return string represention of windows UNICODE_STRING type" ) - // .def( "loadAnsiString", &DebugClient::loadAnsiStr, - // "Return string represention of windows ANSI_STRING type" ) - // .def( "loadPtrList", &DebugClient::loadPtrList, - // "Return list of pointers, each points to next" ) - // .def( "loadPtrs", &DebugClient::loadPtrArray, - // "Read the block of the target's memory and return it as a list of pointers" ) - // .def( "ptrByte", &DebugClient::ptrByte, - // "Read an unsigned 1-byte integer from the target memory" ) - // .def( "ptrWord", &DebugClient::ptrWord, - // "Read an unsigned 2-byte integer from the target memory" ) - // .def( "ptrDWord", &DebugClient::ptrDWord, - // "Read an unsigned 4-byte integer from the target memory" ) - // .def( "ptrQWord", &DebugClient::ptrQWord, - // "Read an unsigned 8-byte integer from the target memory" ) - // .def( "ptrMWord", &DebugClient::ptrMWord, - // "Read an unsigned mashine's word wide integer from the target memory" ) - // .def( "ptrSignByte", &DebugClient::ptrSignByte, - // "Read an signed 1-byte integer from the target memory" ) - // .def( "ptrSignWord", &DebugClient::ptrSignWord, - // "Read an signed 2-byte integer from the target memory" ) - // .def( "ptrSignDWord", &DebugClient::ptrSignDWord, - // "Read an signed 4-byte integer from the target memory" ) - // .def( "ptrSignQWord", &DebugClient::ptrSignQWord, - // "Read an signed 8-byte integer from the target memory" ) - // .def( "ptrSignMWord", &DebugClient::ptrSignMWord, - // "Read an signed mashine's word wide integer from the target memory" ) - // .def( "ptrPtr", &DebugClient::ptrPtr, - // "Read an pointer value from the target memory" ) - // .def("typedVar",&DebugClient::getTypedVarByName, - // "Return a typedVar class instance" ) - // .def("typedVar",&DebugClient::getTypedVarByTypeInfo, - // "Return a typedVar class instance" ) - // .def("typedVar",&DebugClient::getTypedVarByTypeName, - // "Return a typedVar class instance" ) - // .def( "loadExt", &pykd::DebugClient::loadExtension, - // "Load a debuger extension" ) - // .def( "loadModule", &pykd::DebugClient::loadModuleByName, - // "Return instance of Module class" ) - // .def( "loadModule", &pykd::DebugClient::loadModuleByOffset, - // "Return instance of the Module class which posseses specified address" ) - // .def( "dbgCommand", &pykd::DebugClient::dbgCommand, - // "Run a debugger's command and return it's result as a string" ) - // .def( "dprint", &pykd::DebugClient::dprint, - // "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) - // .def( "dprintln", &pykd::DebugClient::dprintln, - // "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) - // .def( "ptrSize", &DebugClient::ptrSize, - // "Return effective pointer size" ) - // .def ( "rdmsr", &DebugClient::loadMSR, - // "Return MSR value" ) - // .def( "reg", &DebugClient::getRegByName, - // "Return a CPU regsiter value by the register's name" ) - // .def( "reg", &DebugClient::getRegByIndex, - // "Return a CPU regsiter value by the register's value" ) - // .def( "setCurrentProcess", &DebugClient::setCurrentProcess, - // "Set current process by address" ) - // .def( "setExecutionStatus", &DebugClient::setExecutionStatus, - // "Requests that the debugger engine enter an executable state" ) - // .def( "setImplicitThread", &DebugClient::setImplicitThread, - // "Set implicit thread for current process" ) - // .def( "setProcessorMode", &DebugClient::setProcessorMode, - // "Set current processor mode by string (X86, ARM, IA64 or X64)" ) - // .def( "sizeof", &DebugClient::getSymbolSize, - // "Return a size of the type or variable" ) - // .def( "step", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_STEP_OVER>, - // "Change debugger status to DEBUG_STATUS_STEP_OVER" ) - // .def( "symbolsPath", &DebugClient::dbgSymPath, - // "Return symbol path" ) - // .def( "trace", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_STEP_INTO>, - // "Change debugger status to DEBUG_STATUS_STEP_INTO" ) - // .def("typedVarList", &DebugClient::getTypedVarListByTypeName, - // "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) - // .def("typedVarList", &DebugClient::getTypedVarListByType, - // "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) - // .def("typedVarArray", &DebugClient::getTypedVarArrayByTypeName, - // "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) - // .def("typedVarArray", &DebugClient::getTypedVarArrayByType, - // "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) - // .def("containingRecord", &DebugClient::containingRecordByName, - // "Return instance of the typedVar class. It's value are loaded from the target memory." - // "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) - // .def("containingRecord", &DebugClient::containingRecordByType, - // "Return instance of the typedVar class. It's value are loaded from the target memory." - // "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) - // .def( "waitForEvent", &DebugClient::waitForEvent, - // "Wait for events that breaks into the debugger" ) - // .def( "wrmsr", &DebugClient::setMSR, - // "Set MSR value" ) - // .def( "getNumberProcessors", &DebugClient::getNumberProcessors, - // "Get the number of actual processors in the machine" ) - // .def( "getPageSize", &DebugClient::getPageSize, - // "Get the page size for the currently executing processor context" ) - // .def( "getContext", &DebugClient::getThreadContext, - // "Get context of current thread (register values)" ) - // .def( "getWow64Context", &DebugClient::getThreadWow64Context, - // "Get WOW64-context of current thread (register values)\n" - // "!wow64exts.r analog") - // .def( "getLocals", &DebugClient::getLocals, DebugClient_getLocals( python::args( "ctx" ), - // "Get list of local variables" ) ) - // .def( "setBp", &DebugClient::setSoftwareBp, DebugClient_setSoftwareBp( python::args( "offset", "callback" ), - // "Set software breakpoint on executiont" ) ) - // .def( "setBp", &DebugClient::setHardwareBp, DebugClient_setHardwareBp( python::args( "offset", "size", "accsessType", "callback" ), - // "Set hardware breakpoint" ) ) - // .def( "getAllBp", &DebugClient::getAllBp, - // "Get all breapoint IDs" ) - // .def( "removeBp", &DebugClient::removeBp, - // "Remove breapoint by IDs" ) - // .def( "removeBp", &DebugClient::removeAllBp, - // "Remove all breapoints" ) - // .def( "addSynSymbol", &DebugClient::addSyntheticSymbol, - // "Add new synthetic symbol for virtual address" ) - // .def( "delAllSynSymbols", &DebugClient::delAllSyntheticSymbols, - // "Delete all synthetic symbol for all modules") - // .def( "delSynSymbol", &DebugClient::delSyntheticSymbol, - // "Delete synthetic symbols by virtual address" ) - // .def( "delSynSymbolsMask", &DebugClient::delSyntheticSymbolsMask, - // "Delete synthetic symbols by mask of module and symbol name"); - - python::def( "addr64", &addr64, - "Extend address to 64 bits formats" ); - python::def( "breakin", &breakin, - "Break into debugger" ); - python::def( "compareMemory", &compareMemory, compareMemory_( python::args( "offset1", "offset2", "length", "phyAddr" ), - "Compare two memory buffers by virtual or physical addresses" ) ); - //python::def( "createDbgClient", (DebugClientPtr(*)())&DebugClient::createDbgClient, - // "create a new instance of the dbgClient class" ); - python::def( "loadDump", &loadDump, - "Load crash dump (only for console)"); - python::def( "startProcess", &startProcess, - "Start process for debugging (only for console)"); - python::def( "attachProcess", &attachProcess, - "Attach debugger to a exsisting process" ); - python::def( "attachKernel", &attachKernel, - "Attach debugger to a kernel target" ); - python::def( "detachProcess", &detachProcess, - "Detach denugger from the current process" ); - python::def( "expr", &evaluate, - "Evaluate windbg expression" ); - python::def( "findSymbol", &findSymbol, - "Find symbol by the target virtual memory offset" ); - python::def( "getCurrentProcess", &getCurrentProcess, - "Return pointer to current process's block" ); - python::def( "getCurrentStack", &getCurrentStack, - "Return a current stack as a list of stackFrame objects" ); - python::def( "getDebuggeeType", &getDebuggeeType, - "Return type of the debuggee" ); - python::def( "getImplicitThread", &getImplicitThread, - "Return implicit thread for current process" ); - python::def( "getExecutionStatus", &getExecutionStatus, - "Return information about the execution status of the debugger" ); - python::def( "getOffset", &getOffset, - "Return traget virtual address for specified symbol" ); - python::def( "getPdbFile", &getPdbFile, - "Return full path to PDB (Program DataBase, debug information) file" ); - python::def( "go", &changeDebuggerStatus<DEBUG_STATUS_GO>, - "Change debugger status to DEBUG_STATUS_GO" ); - python::def( "getProcessorMode", &getProcessorMode, - "Return current processor mode as string: X86, ARM, IA64 or X64" ); - python::def( "getProcessorType", &getProcessorType, - "Return type of physical processor: X86, ARM, IA64 or X64" ); - python::def( "getSourceLine", &getSourceLine, getSourceLine_( python::args( "offset"), - "Return source file name, line and displacement by the specified offset" ) ); - python::def( "getThreadList", &getThreadList, - "Return list of threads (each item is numeric identifier of thread)" ); - python::def( "is64bitSystem", &is64bitSystem, - "Check if target system has 64 address space" ); - python::def( "isDumpAnalyzing", &isDumpAnalyzing, - "Check if it is a dump analyzing ( not living debuggee )" ); - python::def( "isKernelDebugging", &isKernelDebugging, - "Check if kernel dubugging is running" ); - python::def( "isWindbgExt", &WindbgGlobalSession::isInit, - "Check if script works in windbg context" ); - python::def( "isValid", &isVaValid, - "Check if the virtual address is valid" ); - python::def( "killProcess", &terminateProcess, - "Stop debugging and terminate current process" ); - python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as liat of unsigned bytes" ) ); - python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of unsigned shorts" ) ); - python::def( "loadDWords", &loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ); - python::def( "loadQWords", &loadQWords, loadQWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ); - python::def( "loadSignBytes", &loadSignBytes, loadSignBytes_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of signed bytes" ) ); - python::def( "loadSignWords", &loadSignWords, loadSignWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of signed words" ) ); - python::def( "loadSignDWords", &loadSignDWords, loadSignDWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of signed longs" ) ); - python::def( "loadSignQWords", &loadSignQWords, loadSignQWords_( python::args( "offset", "count", "phyAddr" ), - "Read the block of the target's memory and return it as list of signed long longs" ) ); - python::def( "loadChars", &loadChars, loadChars_( python::args( "address", "count", "phyAddr" ), - "Load string from target memory" ) ); - python::def( "loadWChars", &loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ), - "Load string from target memory" ) ); - python::def( "loadCStr", &loadCStr, - "Load string from the target buffer containing 0-terminated ansi-string" ); - python::def( "loadWStr", &loadWStr, - "Load string from the target buffer containing 0-terminated unicode-string" ); - python::def( "loadUnicodeString", &loadUnicodeStr, - "Return string represention of windows UNICODE_STRING type" ); - python::def( "loadAnsiString", &loadAnsiStr, - "Return string represention of windows ANSU_STRING type" ); - python::def( "loadPtrList", &loadPtrList, - "Return list of pointers, each points to next" ); - python::def( "loadPtrs", &loadPtrArray, - "Read the block of the target's memory and return it as a list of pointers" ); - python::def( "ptrByte", &ptrByte, - "Read an unsigned 1-byte integer from the target memory" ); - python::def( "ptrWord", &ptrWord, - "Read an unsigned 2-byte integer from the target memory" ); - python::def( "ptrDWord", (ULONG64(*)(ULONG64))&ptrDWord, - "Read an unsigned 4-byte integer from the target memory" ); - python::def( "ptrQWord", (ULONG64(*)(ULONG64))&ptrQWord, - "Read an unsigned 8-byte integer from the target memory" ); - python::def( "ptrMWord", (ULONG64(*)(ULONG64))&ptrMWord, - "Read an unsigned mashine's word wide integer from the target memory" ); - python::def( "ptrSignByte", &ptrSignByte, - "Read an signed 1-byte integer from the target memory" ); - python::def( "ptrSignWord", &ptrSignWord, - "Read an signed 2-byte integer from the target memory" ); - python::def( "ptrSignDWord", &ptrSignDWord, - "Read an signed 4-byte integer from the target memory" ); - python::def( "ptrSignQWord", &ptrSignQWord, - "Read an signed 8-byte integer from the target memory" ); - python::def( "ptrSignMWord", &ptrSignMWord, - "Read an signed mashine's word wide integer from the target memory" ); - python::def( "ptrPtr", (ULONG64(*)(ULONG64))&ptrPtr, - "Read an pointer value from the target memory" ); - 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"); - python::def( "loadExt", &pykd::loadExtension, - "Load a debuger extension" ); - python::def( "loadModule", &Module::loadModuleByName, - "Return instance of Module class" ); - python::def( "loadModule", &Module::loadModuleByOffset, - "Return instance of the Module class which posseses specified address" ); - python::def( "dbgCommand", &pykd::dbgCommand, - "Run a debugger's command and return it's result as a string" ), - python::def( "dprint", &pykd::dprint, dprint_( boost::python::args( "str", "dml" ), - "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); - python::def( "dprintln", &pykd::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 )" ) ); - python::def( "ptrSize", &ptrSize, - "Return effective pointer size" ); - python::def ( "rdmsr", &loadMSR, - "Return MSR value" ); - python::def( "reg", &getRegByName, - "Return a CPU regsiter value by the register's name" ); - python::def( "reg", &getRegByIndex, - "Return a CPU regsiter value by the register's value" ); - python::def( "setExecutionStatus", &setExecutionStatus, - "Requests that the debugger engine enter an executable state" ); - python::def( "setCurrentProcess", &setCurrentProcess, - "Set current process by address" ); - python::def( "setImplicitThread", &setImplicitThread, - "Set implicit thread for current process" ); - python::def( "setProcessorMode", &setProcessorMode, - "Set current processor mode by string (X86, ARM, IA64 or X64)" ); - python::def( "sizeof", &getSymbolSize, - "Return a size of the type or variable" ); - python::def( "step", &changeDebuggerStatus<DEBUG_STATUS_STEP_OVER>, - "Change debugger status to DEBUG_STATUS_STEP_OVER" ); - python::def( "symbolsPath", &dbgSymPath, - "Return symbol path" ); - python::def( "wrmsr", &setMSR, - "Set MSR value" ); - python::def( "trace", &changeDebuggerStatus<DEBUG_STATUS_STEP_INTO>, - "Change debugger status to DEBUG_STATUS_STEP_INTO" ); - python::def("typedVarList", &getTypedVarListByTypeName, - "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ); - python::def("typedVarList", &getTypedVarListByType, - "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ); - python::def("typedVarArray", &getTypedVarArrayByTypeName, - "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ); - python::def("typedVarArray", &getTypedVarArrayByType, - "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ); - python::def("containingRecord", &containingRecordByName, - "Return instance of the typedVar class. It's value are loaded from the target memory." - "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ); - python::def("containingRecord", &containingRecordByType, - "Return instance of the typedVar class. It's value are loaded from the target memory." - "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ); - python::def( "waitForEvent", &waitForEvent, - "Wait for events that breaks into the debugger" ); - python::def( "getNumberProcessors", &getNumberProcessors, - "Get the number of actual processors in the machine" ); - python::def( "getPageSize", &getPageSize, - "Get the page size for the currently executing processor context" ); - python::def( "getContext", &getThreadContext, - "Get context of current thread (register values)" ); - python::def( "getWow64Context", &getThreadWow64Context, - "Get WOW64-context of current thread (register values)\n" - "!wow64exts.r analog" ); - python::def( "getLocals", &getLocals, getLocals_( python::args( "ctx" ), - "Get list of local variables" ) ); - python::def( "setBp", &setSoftwareBp, setSoftwareBp_( python::args( "offset", "callback" ), - "Set software breakpoint on executiont" ) ); - python::def( "setBp", &setHardwareBp, setHardwareBp_( python::args( "offset", "size", "accsessType", "callback" ) , - "Set hardware breakpoint" ) ); - python::def( "getAllBp", &getAllBp, - "Get all breapoint IDs" ); - python::def( "removeBp", &removeBp, - "Remove breapoint by IDs" ); - python::def( "removeBp", &removeAllBp, - "Remove all breapoints" ); - - python::class_<TypeInfo, TypeInfoPtr, python::bases<intBase>, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init ) - .def("__init__", python::make_constructor(TypeInfo::getTypeInfoByName ) ) - .def( "name", &TypeInfo::getName ) - .def( "size", &TypeInfo::getSize ) - .def( "staticOffset", &TypeInfo::getStaticOffset ) - .def( "fieldOffset", &TypeInfo::getFieldOffsetByNameRecirsive ) - .def( "bitOffset", &TypeInfo::getBitOffset ) - .def( "bitWidth", &TypeInfo::getBitWidth ) - .def( "field", &TypeInfo::getField ) - .def( "asMap", &TypeInfo::asMap ) - .def( "deref", &TypeInfo::deref ) - .def( "__str__", &TypeInfo::print ) - .def( "__getattr__", &TypeInfo::getField ) - .def("__len__", &TypeInfo::getElementCount ) - .def("__getitem__", &TypeInfo::getElementByIndex ); - - python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar", - "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", python::no_init ) - .def("__init__", python::make_constructor(TypedVar::getTypedVarByName) ) - .def("__init__", python::make_constructor(TypedVar::getTypedVarByTypeName) ) - .def("__init__", python::make_constructor(TypedVar::getTypedVarByTypeInfo) ) - .def("getAddress", &TypedVar::getAddress, - "Return virtual address" ) - .def("sizeof", &TypedVar::getSize, - "Return size of a variable in the target memory" ) - .def("fieldOffset", &TypedVar::getFieldOffsetByNameRecirsive, - "Return target field offset" ) - .def("field", &TypedVar::getField, - "Return field of structure as an object attribute" ) - .def( "dataKind", &TypedVar::getDataKind, - "Retrieves the variable classification of a data: DataIsXxx") - .def("deref", &TypedVar::deref, - "Return value by pointer" ) - .def("type", &TypedVar::getType, - "Return typeInfo instance" ) - .def("__getattr__", &TypedVar::getField, - "Return field of structure as an object attribute" ) - .def( "__str__", &TypedVar::print ) - .def("__len__", &TypedVar::getElementCount ) - .def("__getitem__", &TypedVar::getElementByIndex ) - .def("__getitem__", &TypedVar::getElementByIndexPtr ); - python::class_<Module, ModulePtr, python::bases<intBase> >("module", "Class representing executable module", python::no_init ) .def("__init__", python::make_constructor(Module::loadModuleByName) ) .def("__init__", python::make_constructor(Module::loadModuleByOffset) ) @@ -595,412 +91,1075 @@ BOOST_PYTHON_MODULE( pykd ) "Return size of the module" ) .def("name", &Module::getName, "Return name of the module" ) - .def("image", &Module::getImageName, - "Return name of the image of the module" ) - .def("pdb", &Module::getPdbName, - "Return the full path to the module's pdb file ( symbol information )" ) .def("reload", &Module::reloadSymbols, - "(Re)load symbols for the module" ) - .def("offset", &Module::getSymbol, - "Return offset of the symbol" ) - .def("rva", &Module::getSymbolRva, - "Return rva of the symbol" ) - .def( "sizeof", &Module::getSymbolSize, - "Return a size of the type or variable" ) - .def("type", &Module::getTypeByName, - "Return typeInfo class by type name" ) - .def("typedVar", &Module::getTypedVarByAddr, - "Return a typedVar class instance" ) - .def("typedVar",&Module::getTypedVarByName, - "Return a typedVar class instance" ) - .def("typedVar",&Module::getTypedVarByType, - "Return a typedVar class instance" ) - .def("typedVar",&Module::getTypedVarByTypeName, - "Return a typedVar class instance" ) - .def("typedVarList", &Module::getTypedVarListByTypeName, - "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) - .def("typedVarList", &Module::getTypedVarListByType, - "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) - .def("typedVarArray", &Module::getTypedVarArrayByTypeName, - "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) - .def("typedVarArray", &Module::getTypedVarArrayByType, - "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) - .def("containingRecord", &Module::containingRecordByName, - "Return instance of the typedVar class. It's value are loaded from the target memory." - "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) - .def("containingRecord", &Module::containingRecordByType, - "Return instance of the typedVar class. It's value are loaded from the target memory." - "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) - .def("checksum",&Module::getCheckSum, - "Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" ) - .def("timestamp",&Module::getTimeDataStamp, - "Return a low 32 bits of the time stamp of the image: IMAGE_FILE_HEADER.TimeDateStamp" ) - .def("__getattr__", &Module::getSymbol, - "Return address of the symbol" ) - .def( "__str__", &Module::print ); - - python::class_<DbgOut>( "dout", "dout", python::no_init ) - .def( "write", &DbgOut::write ); - - python::class_<DbgIn>( "din", "din", python::no_init ) - .def( "readline", &DbgIn::readline ); - - python::class_<DbgExtension, DbgExtensionPtr>("ext", python::no_init ) - .def( "call", &DbgExtension::call, - "Call debug extension command end return it's result as a string" ); - - python::class_<EventHandlerWrap, boost::noncopyable>( - "eventHandler", "Base class for overriding and handling debug notifications" ) - .def( python::init<>() ) - .def( "reset", &pykd::EventHandler::reset, - "Reset event handler" ) - .def( "onBreakpoint", &pykd::EventHandlerWrap::onBreakpoint, - "Triggered breakpoint event. Parameter is int: ID of breakpoint\n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onException", &pykd::EventHandlerWrap::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", &pykd::EventHandlerWrap::onLoadModule, - "Load module event. Parameter is instance of module.\n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onUnloadModule", &pykd::EventHandlerWrap::onUnloadModule, - "Unload module event. Parameter is base address of unloaded module.\n" - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); - - python::class_<Disasm>("disasm", "Class disassemble a processor instructions" ) - .def( python::init<>( "constructor" ) ) - .def( python::init<ULONG64>( boost::python::args("offset"), "constructor" ) ) - .def( "disasm", &Disasm::disassemble, "Disassemble next instruction" ) - .def( "disasm", &Disasm::jump, "Disassemble from the specified offset" ) - .def( "asm", &Disasm::assembly, "Insert assemblied instuction to current offset" ) - .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" ) - .def( "reset", &Disasm::reset, "Reset current offset to begin" ); - - python::class_<StackFrame>( "stackFrame", - "Class representing a frame of the call stack", python::no_init ) - .def_readonly( "instructionOffset", &StackFrame::m_instructionOffset, - "Return a frame's instruction offset" ) - .def_readonly( "returnOffset", &StackFrame::m_returnOffset, - "Return a frame's return offset" ) - .def_readonly( "frameOffset", &StackFrame::m_frameOffset, - "Return a frame's offset" ) - .def_readonly( "stackOffset", &StackFrame::m_stackOffset, - "Return a frame's stack offset" ) - .def_readonly( "frameNumber", &StackFrame::m_frameNumber, - "Return a frame's number" ) - .def( "getLocals", &StackFrame::getLocals, StackFrame_getLocals( python::args( "ctx" ), - "Get list of local variables for this stack frame" ) ) - .def( "__str__", &StackFrame::print, - "Return stacks frame as a string"); - - python::class_<ThreadContext, ContextPtr>( - "Context", "Context of thread (register values)", python::no_init ) - .def( "ip", &ThreadContext::getIp, - "Get instruction pointer register" ) - .def( "retreg", &ThreadContext::getRetReg, - "Get primary return value register" ) - .def( "csp", &ThreadContext::getSp, - "Get current stack pointer" ) - .def( "get", &ThreadContext::getValue, - "Get register value by ID (CV_REG_XXX)" ) - .def( "get", &ThreadContext::getValueByName, - "Get register value by name" ) - .def( "processorType", &ThreadContext::getProcessorType, - "Get processor ThreadContext as string") - .def( "fork", &ThreadContext::forkByStackFrame, - "Create new thread context by stackFrame") - .def("__len__", &ThreadContext::getCount, - "Return count of registers") - .def("__getitem__", &ThreadContext::getByIndex, - "Return tuple<ID, NAME, VALUE> by index") - .def("__getitem__", &ThreadContext::getValueByName, - "Return register value by name" ) - .def("__getattr__", &ThreadContext::getValueByName, - "Return register value as a attribute of the Context" ) - .def("__str__", &ThreadContext::print, - "Return context as a string" ); - - python::class_<CpuReg, python::bases<intBase> >( - "cpuReg", "CPU regsiter class", boost::python::no_init ) - .def( "name", &CpuReg::name, "The name of the regsiter" ) - .def( "index", &CpuReg::index, "The index of thr register" ); - - python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, - "Open pdb file for querying debug symbols. Return DiaSymbol of global scope"); - python::def( "diaLoadExe", &pyDia::GlobalScope::loadExe, pyDia_GlobalScope_loadExe( python::args( "fileName", "searchPath" ) , - "Load the debug symbols associated with the executable file. Return DiaSymbol of global scope") ); - - python::class_<pyDia::Symbol, pyDia::SymbolPtr>( - "DiaSymbol", "class wrapper for MS DIA Symbol", python::no_init ) - .def( "findEx", &pyDia::Symbol::findChildrenEx, pyDia_Symbol_findChildrenEx( python::args( "symTag", "name", "cmpFlags" ) , - "Retrieves the children of the symbol" ) ) - .def( "find", &pyDia::Symbol::findChildren, - "Retrieves the children of the symbol" ) - .def( "size", &pyDia::Symbol::getSize, - "Retrieves the number of bits or bytes of memory used by the object represented by this symbol" ) - .def( "name", &pyDia::Symbol::getName, - "Retrieves the name of the symbol" ) - .def( "undecoratedName", &pyDia::Symbol::getUndecoratedName, - "Retrieves the undecorated name for a C++ decorated, or linkage, name" ) - .def( "type", &pyDia::Symbol::getType, - "Retrieves the symbol that represents the type for this symbol" ) - .def( "indexType", &pyDia::Symbol::getIndexType, - "Retrieves a reference to the class parent of the symbol" ) - .def( "rva", &pyDia::Symbol::getRva, - "Retrieves the relative virtual address (RVA) of the location") - .def( "va", &pyDia::Symbol::getVa, - "Retrieves the virtual address (VA) of the location") - .def( "symTag", &pyDia::Symbol::getSymTag, - "Retrieves the symbol type classifier: SymTagXxx" ) - .def( "locType", &pyDia::Symbol::getLocType, - "Retrieves the location type of a data symbol: LocIsXxx" ) - .def( "offset", &pyDia::Symbol::getOffset, - "Retrieves the offset of the symbol location" ) - .def( "count", &pyDia::Symbol::getCount, - "Retrieves the number of items in a list or array" ) - .def( "value", (python::object(pyDia::Symbol::*)())&pyDia::Symbol::getValue, - "Retrieves the value of a constant") - .def( "isBasic", &pyDia::Symbol::isBasicType, - "Retrieves a flag of basic type for symbol") - .def( "baseType", &pyDia::Symbol::getBaseType, - "Retrieves the base type for this symbol") - .def( "bitPos", &pyDia::Symbol::getBitPosition, - "Retrieves the bit position of location") - .def( "indexId", &pyDia::Symbol::getIndexId, - "Retrieves the unique symbol identifier") - .def( "udtKind", &pyDia::Symbol::getUdtKind, - "Retrieves the variety of a user-defined type") - .def( "dataKind", &pyDia::Symbol::getDataKind, - "Retrieves the variable classification of a data symbol") - .def("registerId", &pyDia::Symbol::getRegisterId, - "Retrieves the register designator of the location:\n" - "CV_REG_XXX (for IMAGE_FILE_MACHINE_I386) or CV_AMD64_XXX (for IMAGE_FILE_MACHINE_AMD64)") - .def("machineType", &pyDia::Symbol::getMachineType, - "Retrieves the type of the target CPU: IMAGE_FILE_MACHINE_XXX") - .def("section", &pyDia::Symbol::getSection, - "Retrieves the address section of a thunk target") - .def( "__str__", &pyDia::Symbol::print) - .def("__getitem__", &pyDia::Symbol::getChildByName) - .def("__len__", &pyDia::Symbol::getChildCount ) - .def("__getitem__", &pyDia::Symbol::getChildByIndex ) - .def("__eq__", &pyDia::Symbol::eq) - .def("__hash__", &pyDia::Symbol::getIndexId); - - python::class_<pyDia::GlobalScope, pyDia::GlobalScopePtr, python::bases<pyDia::Symbol> >( - "DiaScope", "class wrapper for MS DIA global scope", python::no_init ) - .def("findByRva", &pyDia::GlobalScope::findByRva, - "Find symbol by RVA. Return tuple: (DiaSymbol, offset)") - .def("findByVa", &pyDia::GlobalScope::findByVa, - "Find symbol by VA. Return tuple: (DiaSymbol, offset)") - .def("symbolById", &pyDia::GlobalScope::getSymbolById, - "Retrieves a symbol by its unique identifier: DiaSymbol::indexId()") - .def("loadAddress", &pyDia::GlobalScope::getLoadAddress, - "Retrieves the load address for the executable file that corresponds to the symbols in this symbol store") - .def("setLoadAddress", &pyDia::GlobalScope::setLoadAddress, - "Sets the load address for the executable file that corresponds to the symbols in this symbol store"); - - // CPU type: - DEF_PY_CONST_ULONG(IMAGE_FILE_MACHINE_I386); - DEF_PY_CONST_ULONG(IMAGE_FILE_MACHINE_IA64); - DEF_PY_CONST_ULONG(IMAGE_FILE_MACHINE_AMD64); - - // type of symbol - DEF_PY_CONST_ULONG(SymTagNull); - DEF_PY_CONST_ULONG(SymTagExe); - DEF_PY_CONST_ULONG(SymTagCompiland); - DEF_PY_CONST_ULONG(SymTagCompilandDetails); - DEF_PY_CONST_ULONG(SymTagCompilandEnv); - DEF_PY_CONST_ULONG(SymTagFunction); - DEF_PY_CONST_ULONG(SymTagBlock); - DEF_PY_CONST_ULONG(SymTagData); - DEF_PY_CONST_ULONG(SymTagAnnotation); - DEF_PY_CONST_ULONG(SymTagLabel); - DEF_PY_CONST_ULONG(SymTagPublicSymbol); - DEF_PY_CONST_ULONG(SymTagUDT); - DEF_PY_CONST_ULONG(SymTagEnum); - DEF_PY_CONST_ULONG(SymTagFunctionType); - DEF_PY_CONST_ULONG(SymTagPointerType); - DEF_PY_CONST_ULONG(SymTagArrayType); - DEF_PY_CONST_ULONG(SymTagBaseType); - DEF_PY_CONST_ULONG(SymTagTypedef); - DEF_PY_CONST_ULONG(SymTagBaseClass); - DEF_PY_CONST_ULONG(SymTagFriend); - DEF_PY_CONST_ULONG(SymTagFunctionArgType); - DEF_PY_CONST_ULONG(SymTagFuncDebugStart); - DEF_PY_CONST_ULONG(SymTagFuncDebugEnd); - DEF_PY_CONST_ULONG(SymTagUsingNamespace); - DEF_PY_CONST_ULONG(SymTagVTableShape); - DEF_PY_CONST_ULONG(SymTagVTable); - DEF_PY_CONST_ULONG(SymTagCustom); - DEF_PY_CONST_ULONG(SymTagThunk); - DEF_PY_CONST_ULONG(SymTagCustomType); - DEF_PY_CONST_ULONG(SymTagManagedType); - DEF_PY_CONST_ULONG(SymTagDimension); - python::scope().attr("diaSymTagName") = - genDict(pyDia::Symbol::symTagName, _countof(pyDia::Symbol::symTagName)); - - DEF_PY_CONST_ULONG(DataIsUnknown); - DEF_PY_CONST_ULONG(DataIsLocal); - DEF_PY_CONST_ULONG(DataIsStaticLocal); - DEF_PY_CONST_ULONG(DataIsParam); - DEF_PY_CONST_ULONG(DataIsObjectPtr); - DEF_PY_CONST_ULONG(DataIsFileStatic); - DEF_PY_CONST_ULONG(DataIsGlobal); - DEF_PY_CONST_ULONG(DataIsMember); - DEF_PY_CONST_ULONG(DataIsStaticMember); - DEF_PY_CONST_ULONG(DataIsConstant); - python::scope().attr("diaDataKind") = - genDict(pyDia::Symbol::dataKindName, _countof(pyDia::Symbol::dataKindName)); - - // search options for symbol and file names - DEF_PY_CONST_ULONG(nsfCaseSensitive); - DEF_PY_CONST_ULONG(nsfCaseInsensitive); - DEF_PY_CONST_ULONG(nsfFNameExt); - DEF_PY_CONST_ULONG(nsfRegularExpression); - DEF_PY_CONST_ULONG(nsfUndecoratedName); - DEF_PY_CONST_ULONG(nsCaseSensitive); - DEF_PY_CONST_ULONG(nsCaseInsensitive); - DEF_PY_CONST_ULONG(nsFNameExt); - DEF_PY_CONST_ULONG(nsRegularExpression); - DEF_PY_CONST_ULONG(nsCaseInRegularExpression); - - // location type - DEF_PY_CONST_ULONG(LocIsNull); - DEF_PY_CONST_ULONG(LocIsStatic); - DEF_PY_CONST_ULONG(LocIsTLS); - DEF_PY_CONST_ULONG(LocIsRegRel); - DEF_PY_CONST_ULONG(LocIsThisRel); - DEF_PY_CONST_ULONG(LocIsEnregistered); - DEF_PY_CONST_ULONG(LocIsBitField); - DEF_PY_CONST_ULONG(LocIsSlot); - DEF_PY_CONST_ULONG(LocIsIlRel); - DEF_PY_CONST_ULONG(LocInMetaData); - DEF_PY_CONST_ULONG(LocIsConstant); - python::scope().attr("diaLocTypeName") = - genDict(pyDia::Symbol::locTypeName, _countof(pyDia::Symbol::locTypeName)); - - DEF_PY_CONST_ULONG(btNoType); - DEF_PY_CONST_ULONG(btVoid); - DEF_PY_CONST_ULONG(btChar); - DEF_PY_CONST_ULONG(btWChar); - DEF_PY_CONST_ULONG(btInt); - DEF_PY_CONST_ULONG(btUInt); - DEF_PY_CONST_ULONG(btFloat); - DEF_PY_CONST_ULONG(btBCD); - DEF_PY_CONST_ULONG(btBool); - DEF_PY_CONST_ULONG(btLong); - DEF_PY_CONST_ULONG(btULong); - DEF_PY_CONST_ULONG(btCurrency); - DEF_PY_CONST_ULONG(btDate); - DEF_PY_CONST_ULONG(btVariant); - DEF_PY_CONST_ULONG(btComplex); - DEF_PY_CONST_ULONG(btBit); - DEF_PY_CONST_ULONG(btBSTR); - DEF_PY_CONST_ULONG(btHresult); - python::scope().attr("diaBasicType") = - genDict(pyDia::Symbol::basicTypeName, pyDia::Symbol::cntBasicTypeName); - - DEF_PY_CONST_ULONG(UdtStruct); - DEF_PY_CONST_ULONG(UdtClass); - DEF_PY_CONST_ULONG(UdtUnion); - python::scope().attr("diaUdtKind") = - genDict(pyDia::Symbol::udtKindName, pyDia::Symbol::cntUdtKindName); - - // i386/amd64 cpu registers -#include "diaregs.h" - python::scope().attr("diaI386Regs") = - genDict(pyDia::Symbol::i386RegName, pyDia::Symbol::cntI386RegName); - python::scope().attr("diaAmd64Regs") = - genDict(pyDia::Symbol::amd64RegName, pyDia::Symbol::cntAmd64RegName); - - // exception: - - // wrapper for standart python exceptions - python::register_exception_translator<PyException>( &PyException::exceptionTranslate ); + "(Re)load symbols for the module" ); + //.def("image", &Module::getImageName, + // "Return name of the image of the module" ) + //.def("pdb", &Module::getPdbName, + // "Return the full path to the module's pdb file ( symbol information )" ) + //.def("reload", &Module::reloadSymbols, + // "(Re)load symbols for the module" ) + //.def("offset", &Module::getSymbol, + // "Return offset of the symbol" ) + //.def("rva", &Module::getSymbolRva, + // "Return rva of the symbol" ) + //.def( "sizeof", &Module::getSymbolSize, + // "Return a size of the type or variable" ) + //.def("type", &Module::getTypeByName, + // "Return typeInfo class by type name" ) + //.def("typedVar", &Module::getTypedVarByAddr, + // "Return a typedVar class instance" ) + //.def("typedVar",&Module::getTypedVarByName, + // "Return a typedVar class instance" ) + //.def("typedVar",&Module::getTypedVarByType, + // "Return a typedVar class instance" ) + //.def("typedVar",&Module::getTypedVarByTypeName, + // "Return a typedVar class instance" ) + //.def("typedVarList", &Module::getTypedVarListByTypeName, + // "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) + //.def("typedVarList", &Module::getTypedVarListByType, + // "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) + //.def("typedVarArray", &Module::getTypedVarArrayByTypeName, + // "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) + //.def("typedVarArray", &Module::getTypedVarArrayByType, + // "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) + //.def("containingRecord", &Module::containingRecordByName, + // "Return instance of the typedVar class. It's value are loaded from the target memory." + // "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) + //.def("containingRecord", &Module::containingRecordByType, + // "Return instance of the typedVar class. It's value are loaded from the target memory." + // "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) + //.def("checksum",&Module::getCheckSum, + // "Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" ) + //.def("timestamp",&Module::getTimeDataStamp, + // "Return a low 32 bits of the time stamp of the image: IMAGE_FILE_HEADER.TimeDateStamp" ) + //.def("__getattr__", &Module::getSymbol, + // "Return address of the symbol" ) + //.def( "__str__", &Module::print ); pykd::exception<DbgException>( "BaseException", "Pykd base exception class" ); - pykd::exception<MemoryException,DbgException>( "MemoryException", "Target memory access exception class" ); - pykd::exception<WaitEventException,DbgException>( "WaitEventException", "Debug interface access exception" ); - pykd::exception<SymbolException,DbgException>( "SymbolException", "Symbol exception" ); - pykd::exception<pyDia::Exception,SymbolException>( "DiaException", "Debug interface access exception" ); - pykd::exception<TypeException,SymbolException>( "TypeException", "type exception" ); - pykd::exception<AddSyntheticSymbolException,DbgException>( "AddSynSymbolException", "synthetic symbol exception" ); - pykd::exception<ImplementException,DbgException>( "ImplementException", "implementation exception" ); - - DEF_PY_CONST_ULONG( DEBUG_CLASS_UNINITIALIZED ); - DEF_PY_CONST_ULONG( DEBUG_CLASS_KERNEL ); - DEF_PY_CONST_ULONG( DEBUG_CLASS_USER_WINDOWS ); - - DEF_PY_CONST_ULONG( DEBUG_KERNEL_CONNECTION ); - DEF_PY_CONST_ULONG( DEBUG_KERNEL_LOCAL ); - DEF_PY_CONST_ULONG( DEBUG_KERNEL_EXDI_DRIVER ); - DEF_PY_CONST_ULONG( DEBUG_KERNEL_SMALL_DUMP ); - DEF_PY_CONST_ULONG( DEBUG_KERNEL_DUMP ); - DEF_PY_CONST_ULONG( DEBUG_KERNEL_FULL_DUMP ); - - DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_PROCESS ); - DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_PROCESS_SERVER ); - DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_SMALL_DUMP ); - DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_DUMP ); - - // exception codes - DEF_PY_CONST_ULONG(EXCEPTION_ACCESS_VIOLATION); - DEF_PY_CONST_ULONG(EXCEPTION_DATATYPE_MISALIGNMENT); - DEF_PY_CONST_ULONG(EXCEPTION_BREAKPOINT); - DEF_PY_CONST_ULONG(EXCEPTION_SINGLE_STEP); - DEF_PY_CONST_ULONG(EXCEPTION_ARRAY_BOUNDS_EXCEEDED); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_DENORMAL_OPERAND); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_DIVIDE_BY_ZERO); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_INEXACT_RESULT); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_INVALID_OPERATION); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_OVERFLOW); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_STACK_CHECK); - DEF_PY_CONST_ULONG(EXCEPTION_FLT_UNDERFLOW); - DEF_PY_CONST_ULONG(EXCEPTION_INT_DIVIDE_BY_ZERO); - DEF_PY_CONST_ULONG(EXCEPTION_INT_OVERFLOW); - DEF_PY_CONST_ULONG(EXCEPTION_PRIV_INSTRUCTION); - DEF_PY_CONST_ULONG(EXCEPTION_IN_PAGE_ERROR); - DEF_PY_CONST_ULONG(EXCEPTION_ILLEGAL_INSTRUCTION); - DEF_PY_CONST_ULONG(EXCEPTION_NONCONTINUABLE_EXCEPTION); - DEF_PY_CONST_ULONG(EXCEPTION_STACK_OVERFLOW); - DEF_PY_CONST_ULONG(EXCEPTION_INVALID_DISPOSITION); - DEF_PY_CONST_ULONG(EXCEPTION_GUARD_PAGE); - DEF_PY_CONST_ULONG(EXCEPTION_INVALID_HANDLE); - - // debug status - DEF_PY_CONST_ULONG(DEBUG_STATUS_NO_CHANGE); - DEF_PY_CONST_ULONG(DEBUG_STATUS_GO); - DEF_PY_CONST_ULONG(DEBUG_STATUS_GO_HANDLED); - DEF_PY_CONST_ULONG(DEBUG_STATUS_GO_NOT_HANDLED); - DEF_PY_CONST_ULONG(DEBUG_STATUS_STEP_OVER); - DEF_PY_CONST_ULONG(DEBUG_STATUS_STEP_INTO); - DEF_PY_CONST_ULONG(DEBUG_STATUS_BREAK); - DEF_PY_CONST_ULONG(DEBUG_STATUS_NO_DEBUGGEE); - DEF_PY_CONST_ULONG(DEBUG_STATUS_STEP_BRANCH); - DEF_PY_CONST_ULONG(DEBUG_STATUS_RESTART_REQUESTED); - DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_GO); - DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_STEP_BRANCH); - DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_STEP_OVER); - DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_STEP_INTO); - - // breakpoints constatns - DEF_PY_CONST_ULONG(DEBUG_BREAKPOINT_CODE); - DEF_PY_CONST_ULONG(DEBUG_BREAKPOINT_DATA); - - DEF_PY_CONST_ULONG(DEBUG_BREAK_READ); - DEF_PY_CONST_ULONG(DEBUG_BREAK_WRITE); - DEF_PY_CONST_ULONG(DEBUG_BREAK_EXECUTE); - DEF_PY_CONST_ULONG(DEBUG_BREAK_IO); + //pykd::exception<MemoryException,DbgException>( "MemoryException", "Target memory access exception class" ); + //pykd::exception<WaitEventException,DbgException>( "WaitEventException", "Debug interface access exception" ); + //pykd::exception<SymbolException,DbgException>( "SymbolException", "Symbol exception" ); + //pykd::exception<pyDia::Exception,SymbolException>( "DiaException", "Debug interface access exception" ); + //pykd::exception<TypeException,SymbolException>( "TypeException", "type exception" ); + //pykd::exception<AddSyntheticSymbolException,DbgException>( "AddSynSymbolException", "synthetic symbol exception" ); + //pykd::exception<ImplementException,DbgException>( "ImplementException", "implementation exception" ); } -#undef DEF_PY_CONST_ULONG +////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// \ No newline at end of file + + + + + + + + + + + + + +//#include <dia2.h> +// +//#include "module.h" +//#include "diawrapper.h" +//#include "dbgclient.h" +//#include "dbgio.h" +//#include "dbgpath.h" +//#include "dbgcmd.h" +//#include "dbgevent.h" +//#include "typeinfo.h" +//#include "typedvar.h" +//#include "dbgmem.h" +//#include "intbase.h" +//#include "process.h" +//#include "bpoint.h" +//#include "stkframe.h" +//#include "pykdver.h" +// +//using namespace pykd; +// +////////////////////////////////////////////////////////////////////////////////// +// +//static const std::string pykdVersion = PYKD_VERSION_BUILD_STR +//#ifdef _DEBUG +// " <DBG>" +//#endif // _DEBUG +//; +// +////////////////////////////////////////////////////////////////////////////////// +// +//static python::dict genDict(const pyDia::Symbol::ValueNameEntry srcValues[], size_t cntValues) +//{ +// python::dict resDict; +// for (size_t i = 0; i < cntValues; ++i) +// resDict[srcValues[i].first] = srcValues[i].second; +// return resDict; +//} +// +////////////////////////////////////////////////////////////////////////////////// +// +//std::string +//getDebuggerImage() +//{ +// std::vector<char> buffer(MAX_PATH); +// GetModuleFileNameExA( GetCurrentProcess(), NULL, &buffer[0], (DWORD)buffer.size() ); +// return std::string( &buffer[0] ); +//} +// +////////////////////////////////////////////////////////////////////////////////// +// +//BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 ); +// +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, loadChars, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, loadWChars, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, loadBytes, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords_, loadWords, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadDWords_, loadDWords, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadQWords_, loadQWords, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignBytes_, loadSignBytes, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignWords_, loadSignWords, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignDWords_, loadSignDWords, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( loadSignQWords_, loadSignQWords, 2, 3 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, compareMemory, 3, 4 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( getLocals_, getLocals, 0, 1 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( pyDia_GlobalScope_loadExe, pyDia::GlobalScope::loadExe, 1, 2 ); +//BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 ); +// +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadChars, DebugClient::loadChars, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWChars, DebugClient::loadWChars, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadBytes, DebugClient::loadBytes, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadWords, DebugClient::loadWords, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadDWords, DebugClient::loadDWords, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadQWords, DebugClient::loadQWords, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignBytes, DebugClient::loadSignBytes, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignWords, DebugClient::loadSignWords, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignDWords, DebugClient::loadSignDWords, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadSignQWords, DebugClient::loadSignQWords, 2, 3 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_compareMemory, DebugClient::compareMemory, 3, 4 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_getLocals, DebugClient::getLocals, 0, 1 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_setSoftwareBp, DebugClient::setSoftwareBp, 1, 2 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_setHardwareBp, DebugClient::setHardwareBp, 3, 4 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_getSourceLine, DebugClient::getSourceLine, 0, 1 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( StackFrame_getLocals, StackFrame::getLocals, 0, 1 ); +//BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( pyDia_Symbol_findChildrenEx, pyDia::Symbol::findChildrenEx, 1, 3 ); +// +// +//#define DEF_PY_CONST_ULONG(x) \ +// python::scope().attr(#x) = ULONG(##x) +// +//BOOST_PYTHON_MODULE( pykd ) +//{ +// python::scope().attr("version") = pykdVersion; +// +// python::def( "debuggerPath", &getDebuggerImage, +// "Return full path to the process image that uses pykd" ); +// +// python::class_<intBase>( "intBase", "intBase", python::no_init ) +// .def( python::init<python::object&>() ) +// .def( "__eq__", &intBase::eq ) +// .def( "__ne__", &intBase::ne) +// .def( "__lt__", &intBase::lt) +// .def( "__gt__", &intBase::gt ) +// .def( "__le__", &intBase::le ) +// .def( "__ge__", &intBase::ge ) +// .def( "__add__", &intBase::add ) +// .def( "__radd__", &intBase::add ) +// .def( "__sub__", &intBase::sub ) +// .def( "__rsub__", &intBase::rsub ) +// .def( "__mul__", &intBase::mul ) +// .def( "__rmul__", &intBase::mul ) +// .def( "__div__", &intBase::div ) +// .def( "__rdiv__", &intBase::rdiv ) +// .def( "__mod__", &intBase::mod ) +// .def( "__rmod__", &intBase::rmod ) +// .def( "__rshift__", &intBase::rshift ) +// .def( "__rrshift__", &intBase::rrshift ) +// .def( "__lshift__", &intBase::lshift ) +// .def( "__rlshift__", &intBase::rlshift ) +// .def( "__and__", &intBase::and ) +// .def( "__rand__", &intBase::and ) +// .def( "__or__", &intBase::or ) +// .def( "__ror__", &intBase::or ) +// .def( "__xor__", &intBase::xor ) +// .def( "__rxor__", &intBase::xor ) +// .def( "__neg__", &intBase::neg ) +// .def( "__pos__", &intBase::pos ) +// .def( "__invert__", &intBase::invert ) +// .def( "__nonzero__", &intBase::nonzero ) +// .def( "__str__", &intBase::str ) +// .def( "__hex__", &intBase::hex ) +// .def( "__long__", &intBase::long_ ) +// .def( "__int__", &intBase::int_ ) +// .def( "__index__", &intBase::long_ ) +// .def( "__hash__", &intBase::long_ ); +// +// python::implicitly_convertible<intBase,ULONG64>(); +// python::implicitly_convertible<intBase,LONG64>(); +// python::implicitly_convertible<intBase,ULONG>(); +// python::implicitly_convertible<intBase,LONG>(); +// +// //python::class_<DebugClient, DebugClientPtr>("dbgClient", "Class representing a debugging session", python::no_init ) +// // .def( "addr64", &DebugClient::addr64, +// // "Extend address to 64 bits formats" ) +// // .def( "breakin", &DebugClient::breakin, +// // "Break into debugger" ) +// // .def( "compareMemory", &DebugClient::compareMemory, DebugClient_compareMemory( python::args( "offset1", "offset2", "length", "phyAddr" ), +// // "Compare two memory buffers by virtual or physical addresses" ) ) +// // .def( "loadDump", &DebugClient::loadDump, +// // "Load crash dump" ) +// // .def( "startProcess", &DebugClient::startProcess, +// // "Start process for debugging" ) +// // .def( "attachProcess", &DebugClient::attachProcess, +// // "Attach debugger to a exsisting process" ) +// // .def( "attachKernel", &DebugClient::attachKernel, +// // "Attach debugger to a target's kernel" ) +// // .def( "detachProcess", &DebugClient::detachProcess, +// // "Detach debugger from the current process" ) +// // .def( "expr", &DebugClient::evaluate, +// // "Evaluate windbg expression" ) +// // .def( "findSymbol", &DebugClient::findSymbol, +// // "Find symbol by the target virtual memory offset" ) +// // .def( "getCurrentProcess", &DebugClient::getCurrentProcess, +// // "Return pointer to current process's block" ) +// // .def( "getCurrentStack", &DebugClient::getCurrentStack, +// // "Return a current stack as a list of stackFrame objects" ) +// // .def( "getDebuggeeType", &DebugClient::getDebuggeeType, +// // "Return type of the debuggee" ) +// // .def( "getImplicitThread", &DebugClient::getImplicitThread, +// // "Return implicit thread for current process" ) +// // .def( "getExecutionStatus", &DebugClient::getExecutionStatus, +// // "Return information about the execution status of the debugger" ) +// // .def( "getOffset", &DebugClient::getOffset, +// // "Return traget virtual address for specified symbol" ) +// // .def( "getPdbFile", &DebugClient::getPdbFile, +// // "Return full path to PDB (Program DataBase, debug information) file" ) +// // .def( "getProcessorMode", &DebugClient::getProcessorMode, +// // "Return current processor mode as string: X86, ARM, IA64 or X64" ) +// // .def( "getProcessorType", &DebugClient::getProcessorType, +// // "Return type of physical processor: X86, ARM, IA64 or X64" ) +// // .def( "getSourceLine", &DebugClient::getSourceLine, DebugClient_getSourceLine( python::args( "offset"), +// // "Return source file name, lin and displacement by the specified offset" ) ) +// // .def( "getThreadList", &DebugClient::getThreadList, +// // "Return list of threads (each item is numeric identifier of thread)" ) +// // .def( "go", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_GO>, +// // "Change debugger status to DEBUG_STATUS_GO" ) +// // .def( "is64bitSystem", &DebugClient::is64bitSystem, +// // "Check if target system has 64 address space" ) +// // .def( "isDumpAnalyzing", &DebugClient::isDumpAnalyzing, +// // "Check if it is a dump analyzing ( not living debuggee )" ) +// // .def( "isKernelDebugging", &DebugClient::isKernelDebugging, +// // "Check if kernel dubugging is running" ) +// // .def( "isValid", &DebugClient::isVaValid, +// // "Check if the virtual address is valid" ) +// // .def( "killProcess", &DebugClient::terminateProcess, +// // "Stop debugging and terminate current process" ) +// // .def( "loadBytes", &DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of unsigned bytes" ) ) +// // .def( "loadWords", &DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of unsigned shorts" ) ) +// // .def( "loadDWords", &DebugClient::loadDWords, DebugClient_loadDWords( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ) +// // .def( "loadQWords", &DebugClient::loadQWords, DebugClient_loadQWords( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ) +// // .def( "loadSignBytes", &DebugClient::loadSignBytes, DebugClient_loadSignBytes( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of signed bytes" ) ) +// // .def( "loadSignWords", &DebugClient::loadSignWords, DebugClient_loadSignWords( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of signed shorts" ) ) +// // .def( "loadSignDWords", &DebugClient::loadSignDWords, DebugClient_loadSignDWords( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of signed longs" ) ) +// // .def( "loadSignQWords", &DebugClient::loadSignQWords, DebugClient_loadSignQWords( python::args( "offset", "count", "phyAddr" ), +// // "Read the block of the target's memory and return it as list of signed long longs" ) ) +// // .def( "loadChars", &DebugClient::loadChars, DebugClient_loadChars( python::args( "offset", "count", "phyAddr" ), +// // "Load string from target memory" ) ) +// // .def( "loadWChars", &DebugClient::loadWChars, DebugClient_loadWChars( python::args( "offset", "count", "phyAddr" ), +// // "Load string from target memory" ) ) +// // .def( "loadCStr", &DebugClient::loadCStr, +// // "Load string from the target buffer containing 0-terminated ansi-string" ) +// // .def( "loadWStr", &DebugClient::loadWStr, +// // "Load string from the target buffer containing 0-terminated unicode-string" ) +// // .def( "loadUnicodeString", &DebugClient::loadUnicodeStr, +// // "Return string represention of windows UNICODE_STRING type" ) +// // .def( "loadAnsiString", &DebugClient::loadAnsiStr, +// // "Return string represention of windows ANSI_STRING type" ) +// // .def( "loadPtrList", &DebugClient::loadPtrList, +// // "Return list of pointers, each points to next" ) +// // .def( "loadPtrs", &DebugClient::loadPtrArray, +// // "Read the block of the target's memory and return it as a list of pointers" ) +// // .def( "ptrByte", &DebugClient::ptrByte, +// // "Read an unsigned 1-byte integer from the target memory" ) +// // .def( "ptrWord", &DebugClient::ptrWord, +// // "Read an unsigned 2-byte integer from the target memory" ) +// // .def( "ptrDWord", &DebugClient::ptrDWord, +// // "Read an unsigned 4-byte integer from the target memory" ) +// // .def( "ptrQWord", &DebugClient::ptrQWord, +// // "Read an unsigned 8-byte integer from the target memory" ) +// // .def( "ptrMWord", &DebugClient::ptrMWord, +// // "Read an unsigned mashine's word wide integer from the target memory" ) +// // .def( "ptrSignByte", &DebugClient::ptrSignByte, +// // "Read an signed 1-byte integer from the target memory" ) +// // .def( "ptrSignWord", &DebugClient::ptrSignWord, +// // "Read an signed 2-byte integer from the target memory" ) +// // .def( "ptrSignDWord", &DebugClient::ptrSignDWord, +// // "Read an signed 4-byte integer from the target memory" ) +// // .def( "ptrSignQWord", &DebugClient::ptrSignQWord, +// // "Read an signed 8-byte integer from the target memory" ) +// // .def( "ptrSignMWord", &DebugClient::ptrSignMWord, +// // "Read an signed mashine's word wide integer from the target memory" ) +// // .def( "ptrPtr", &DebugClient::ptrPtr, +// // "Read an pointer value from the target memory" ) +// // .def("typedVar",&DebugClient::getTypedVarByName, +// // "Return a typedVar class instance" ) +// // .def("typedVar",&DebugClient::getTypedVarByTypeInfo, +// // "Return a typedVar class instance" ) +// // .def("typedVar",&DebugClient::getTypedVarByTypeName, +// // "Return a typedVar class instance" ) +// // .def( "loadExt", &pykd::DebugClient::loadExtension, +// // "Load a debuger extension" ) +// // .def( "loadModule", &pykd::DebugClient::loadModuleByName, +// // "Return instance of Module class" ) +// // .def( "loadModule", &pykd::DebugClient::loadModuleByOffset, +// // "Return instance of the Module class which posseses specified address" ) +// // .def( "dbgCommand", &pykd::DebugClient::dbgCommand, +// // "Run a debugger's command and return it's result as a string" ) +// // .def( "dprint", &pykd::DebugClient::dprint, +// // "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) +// // .def( "dprintln", &pykd::DebugClient::dprintln, +// // "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) +// // .def( "ptrSize", &DebugClient::ptrSize, +// // "Return effective pointer size" ) +// // .def ( "rdmsr", &DebugClient::loadMSR, +// // "Return MSR value" ) +// // .def( "reg", &DebugClient::getRegByName, +// // "Return a CPU regsiter value by the register's name" ) +// // .def( "reg", &DebugClient::getRegByIndex, +// // "Return a CPU regsiter value by the register's value" ) +// // .def( "setCurrentProcess", &DebugClient::setCurrentProcess, +// // "Set current process by address" ) +// // .def( "setExecutionStatus", &DebugClient::setExecutionStatus, +// // "Requests that the debugger engine enter an executable state" ) +// // .def( "setImplicitThread", &DebugClient::setImplicitThread, +// // "Set implicit thread for current process" ) +// // .def( "setProcessorMode", &DebugClient::setProcessorMode, +// // "Set current processor mode by string (X86, ARM, IA64 or X64)" ) +// // .def( "sizeof", &DebugClient::getSymbolSize, +// // "Return a size of the type or variable" ) +// // .def( "step", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_STEP_OVER>, +// // "Change debugger status to DEBUG_STATUS_STEP_OVER" ) +// // .def( "symbolsPath", &DebugClient::dbgSymPath, +// // "Return symbol path" ) +// // .def( "trace", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_STEP_INTO>, +// // "Change debugger status to DEBUG_STATUS_STEP_INTO" ) +// // .def("typedVarList", &DebugClient::getTypedVarListByTypeName, +// // "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) +// // .def("typedVarList", &DebugClient::getTypedVarListByType, +// // "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) +// // .def("typedVarArray", &DebugClient::getTypedVarArrayByTypeName, +// // "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) +// // .def("typedVarArray", &DebugClient::getTypedVarArrayByType, +// // "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) +// // .def("containingRecord", &DebugClient::containingRecordByName, +// // "Return instance of the typedVar class. It's value are loaded from the target memory." +// // "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) +// // .def("containingRecord", &DebugClient::containingRecordByType, +// // "Return instance of the typedVar class. It's value are loaded from the target memory." +// // "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) +// // .def( "waitForEvent", &DebugClient::waitForEvent, +// // "Wait for events that breaks into the debugger" ) +// // .def( "wrmsr", &DebugClient::setMSR, +// // "Set MSR value" ) +// // .def( "getNumberProcessors", &DebugClient::getNumberProcessors, +// // "Get the number of actual processors in the machine" ) +// // .def( "getPageSize", &DebugClient::getPageSize, +// // "Get the page size for the currently executing processor context" ) +// // .def( "getContext", &DebugClient::getThreadContext, +// // "Get context of current thread (register values)" ) +// // .def( "getWow64Context", &DebugClient::getThreadWow64Context, +// // "Get WOW64-context of current thread (register values)\n" +// // "!wow64exts.r analog") +// // .def( "getLocals", &DebugClient::getLocals, DebugClient_getLocals( python::args( "ctx" ), +// // "Get list of local variables" ) ) +// // .def( "setBp", &DebugClient::setSoftwareBp, DebugClient_setSoftwareBp( python::args( "offset", "callback" ), +// // "Set software breakpoint on executiont" ) ) +// // .def( "setBp", &DebugClient::setHardwareBp, DebugClient_setHardwareBp( python::args( "offset", "size", "accsessType", "callback" ), +// // "Set hardware breakpoint" ) ) +// // .def( "getAllBp", &DebugClient::getAllBp, +// // "Get all breapoint IDs" ) +// // .def( "removeBp", &DebugClient::removeBp, +// // "Remove breapoint by IDs" ) +// // .def( "removeBp", &DebugClient::removeAllBp, +// // "Remove all breapoints" ) +// // .def( "addSynSymbol", &DebugClient::addSyntheticSymbol, +// // "Add new synthetic symbol for virtual address" ) +// // .def( "delAllSynSymbols", &DebugClient::delAllSyntheticSymbols, +// // "Delete all synthetic symbol for all modules") +// // .def( "delSynSymbol", &DebugClient::delSyntheticSymbol, +// // "Delete synthetic symbols by virtual address" ) +// // .def( "delSynSymbolsMask", &DebugClient::delSyntheticSymbolsMask, +// // "Delete synthetic symbols by mask of module and symbol name"); +// +// python::def( "addr64", &addr64, +// "Extend address to 64 bits formats" ); +// python::def( "breakin", &breakin, +// "Break into debugger" ); +// python::def( "compareMemory", &compareMemory, compareMemory_( python::args( "offset1", "offset2", "length", "phyAddr" ), +// "Compare two memory buffers by virtual or physical addresses" ) ); +// //python::def( "createDbgClient", (DebugClientPtr(*)())&DebugClient::createDbgClient, +// // "create a new instance of the dbgClient class" ); +// python::def( "loadDump", &loadDump, +// "Load crash dump (only for console)"); +// python::def( "startProcess", &startProcess, +// "Start process for debugging (only for console)"); +// python::def( "attachProcess", &attachProcess, +// "Attach debugger to a exsisting process" ); +// python::def( "attachKernel", &attachKernel, +// "Attach debugger to a kernel target" ); +// python::def( "detachProcess", &detachProcess, +// "Detach denugger from the current process" ); +// python::def( "expr", &evaluate, +// "Evaluate windbg expression" ); +// python::def( "findSymbol", &findSymbol, +// "Find symbol by the target virtual memory offset" ); +// python::def( "getCurrentProcess", &getCurrentProcess, +// "Return pointer to current process's block" ); +// python::def( "getCurrentStack", &getCurrentStack, +// "Return a current stack as a list of stackFrame objects" ); +// python::def( "getDebuggeeType", &getDebuggeeType, +// "Return type of the debuggee" ); +// python::def( "getImplicitThread", &getImplicitThread, +// "Return implicit thread for current process" ); +// python::def( "getExecutionStatus", &getExecutionStatus, +// "Return information about the execution status of the debugger" ); +// python::def( "getOffset", &getOffset, +// "Return traget virtual address for specified symbol" ); +// python::def( "getPdbFile", &getPdbFile, +// "Return full path to PDB (Program DataBase, debug information) file" ); +// python::def( "go", &changeDebuggerStatus<DEBUG_STATUS_GO>, +// "Change debugger status to DEBUG_STATUS_GO" ); +// python::def( "getProcessorMode", &getProcessorMode, +// "Return current processor mode as string: X86, ARM, IA64 or X64" ); +// python::def( "getProcessorType", &getProcessorType, +// "Return type of physical processor: X86, ARM, IA64 or X64" ); +// python::def( "getSourceLine", &getSourceLine, getSourceLine_( python::args( "offset"), +// "Return source file name, line and displacement by the specified offset" ) ); +// python::def( "getThreadList", &getThreadList, +// "Return list of threads (each item is numeric identifier of thread)" ); +// python::def( "is64bitSystem", &is64bitSystem, +// "Check if target system has 64 address space" ); +// python::def( "isDumpAnalyzing", &isDumpAnalyzing, +// "Check if it is a dump analyzing ( not living debuggee )" ); +// python::def( "isKernelDebugging", &isKernelDebugging, +// "Check if kernel dubugging is running" ); +// python::def( "isWindbgExt", &WindbgGlobalSession::isInit, +// "Check if script works in windbg context" ); +// python::def( "isValid", &isVaValid, +// "Check if the virtual address is valid" ); +// python::def( "killProcess", &terminateProcess, +// "Stop debugging and terminate current process" ); +// python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as liat of unsigned bytes" ) ); +// python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of unsigned shorts" ) ); +// python::def( "loadDWords", &loadDWords, loadDWords_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of unsigned long ( double word )" ) ); +// python::def( "loadQWords", &loadQWords, loadQWords_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of unsigned long long ( quad word )" ) ); +// python::def( "loadSignBytes", &loadSignBytes, loadSignBytes_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of signed bytes" ) ); +// python::def( "loadSignWords", &loadSignWords, loadSignWords_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of signed words" ) ); +// python::def( "loadSignDWords", &loadSignDWords, loadSignDWords_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of signed longs" ) ); +// python::def( "loadSignQWords", &loadSignQWords, loadSignQWords_( python::args( "offset", "count", "phyAddr" ), +// "Read the block of the target's memory and return it as list of signed long longs" ) ); +// python::def( "loadChars", &loadChars, loadChars_( python::args( "address", "count", "phyAddr" ), +// "Load string from target memory" ) ); +// python::def( "loadWChars", &loadWChars, loadWChars_( python::args( "address", "count", "phyAddr" ), +// "Load string from target memory" ) ); +// python::def( "loadCStr", &loadCStr, +// "Load string from the target buffer containing 0-terminated ansi-string" ); +// python::def( "loadWStr", &loadWStr, +// "Load string from the target buffer containing 0-terminated unicode-string" ); +// python::def( "loadUnicodeString", &loadUnicodeStr, +// "Return string represention of windows UNICODE_STRING type" ); +// python::def( "loadAnsiString", &loadAnsiStr, +// "Return string represention of windows ANSU_STRING type" ); +// python::def( "loadPtrList", &loadPtrList, +// "Return list of pointers, each points to next" ); +// python::def( "loadPtrs", &loadPtrArray, +// "Read the block of the target's memory and return it as a list of pointers" ); +// python::def( "ptrByte", &ptrByte, +// "Read an unsigned 1-byte integer from the target memory" ); +// python::def( "ptrWord", &ptrWord, +// "Read an unsigned 2-byte integer from the target memory" ); +// python::def( "ptrDWord", (ULONG64(*)(ULONG64))&ptrDWord, +// "Read an unsigned 4-byte integer from the target memory" ); +// python::def( "ptrQWord", (ULONG64(*)(ULONG64))&ptrQWord, +// "Read an unsigned 8-byte integer from the target memory" ); +// python::def( "ptrMWord", (ULONG64(*)(ULONG64))&ptrMWord, +// "Read an unsigned mashine's word wide integer from the target memory" ); +// python::def( "ptrSignByte", &ptrSignByte, +// "Read an signed 1-byte integer from the target memory" ); +// python::def( "ptrSignWord", &ptrSignWord, +// "Read an signed 2-byte integer from the target memory" ); +// python::def( "ptrSignDWord", &ptrSignDWord, +// "Read an signed 4-byte integer from the target memory" ); +// python::def( "ptrSignQWord", &ptrSignQWord, +// "Read an signed 8-byte integer from the target memory" ); +// python::def( "ptrSignMWord", &ptrSignMWord, +// "Read an signed mashine's word wide integer from the target memory" ); +// python::def( "ptrPtr", (ULONG64(*)(ULONG64))&ptrPtr, +// "Read an pointer value from the target memory" ); +// 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"); +// python::def( "loadExt", &pykd::loadExtension, +// "Load a debuger extension" ); +// python::def( "loadModule", &Module::loadModuleByName, +// "Return instance of Module class" ); +// python::def( "loadModule", &Module::loadModuleByOffset, +// "Return instance of the Module class which posseses specified address" ); +// python::def( "dbgCommand", &pykd::dbgCommand, +// "Run a debugger's command and return it's result as a string" ), +// python::def( "dprint", &pykd::dprint, dprint_( boost::python::args( "str", "dml" ), +// "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); +// python::def( "dprintln", &pykd::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 )" ) ); +// python::def( "ptrSize", &ptrSize, +// "Return effective pointer size" ); +// python::def ( "rdmsr", &loadMSR, +// "Return MSR value" ); +// python::def( "reg", &getRegByName, +// "Return a CPU regsiter value by the register's name" ); +// python::def( "reg", &getRegByIndex, +// "Return a CPU regsiter value by the register's value" ); +// python::def( "setExecutionStatus", &setExecutionStatus, +// "Requests that the debugger engine enter an executable state" ); +// python::def( "setCurrentProcess", &setCurrentProcess, +// "Set current process by address" ); +// python::def( "setImplicitThread", &setImplicitThread, +// "Set implicit thread for current process" ); +// python::def( "setProcessorMode", &setProcessorMode, +// "Set current processor mode by string (X86, ARM, IA64 or X64)" ); +// python::def( "sizeof", &getSymbolSize, +// "Return a size of the type or variable" ); +// python::def( "step", &changeDebuggerStatus<DEBUG_STATUS_STEP_OVER>, +// "Change debugger status to DEBUG_STATUS_STEP_OVER" ); +// python::def( "symbolsPath", &dbgSymPath, +// "Return symbol path" ); +// python::def( "wrmsr", &setMSR, +// "Set MSR value" ); +// python::def( "trace", &changeDebuggerStatus<DEBUG_STATUS_STEP_INTO>, +// "Change debugger status to DEBUG_STATUS_STEP_INTO" ); +// python::def("typedVarList", &getTypedVarListByTypeName, +// "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ); +// python::def("typedVarList", &getTypedVarListByType, +// "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ); +// python::def("typedVarArray", &getTypedVarArrayByTypeName, +// "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ); +// python::def("typedVarArray", &getTypedVarArrayByType, +// "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ); +// python::def("containingRecord", &containingRecordByName, +// "Return instance of the typedVar class. It's value are loaded from the target memory." +// "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ); +// python::def("containingRecord", &containingRecordByType, +// "Return instance of the typedVar class. It's value are loaded from the target memory." +// "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ); +// python::def( "waitForEvent", &waitForEvent, +// "Wait for events that breaks into the debugger" ); +// python::def( "getNumberProcessors", &getNumberProcessors, +// "Get the number of actual processors in the machine" ); +// python::def( "getPageSize", &getPageSize, +// "Get the page size for the currently executing processor context" ); +// python::def( "getContext", &getThreadContext, +// "Get context of current thread (register values)" ); +// python::def( "getWow64Context", &getThreadWow64Context, +// "Get WOW64-context of current thread (register values)\n" +// "!wow64exts.r analog" ); +// python::def( "getLocals", &getLocals, getLocals_( python::args( "ctx" ), +// "Get list of local variables" ) ); +// python::def( "setBp", &setSoftwareBp, setSoftwareBp_( python::args( "offset", "callback" ), +// "Set software breakpoint on executiont" ) ); +// python::def( "setBp", &setHardwareBp, setHardwareBp_( python::args( "offset", "size", "accsessType", "callback" ) , +// "Set hardware breakpoint" ) ); +// python::def( "getAllBp", &getAllBp, +// "Get all breapoint IDs" ); +// python::def( "removeBp", &removeBp, +// "Remove breapoint by IDs" ); +// python::def( "removeBp", &removeAllBp, +// "Remove all breapoints" ); +// +// python::class_<TypeInfo, TypeInfoPtr, python::bases<intBase>, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init ) +// .def("__init__", python::make_constructor(TypeInfo::getTypeInfoByName ) ) +// .def( "name", &TypeInfo::getName ) +// .def( "size", &TypeInfo::getSize ) +// .def( "staticOffset", &TypeInfo::getStaticOffset ) +// .def( "fieldOffset", &TypeInfo::getFieldOffsetByNameRecirsive ) +// .def( "bitOffset", &TypeInfo::getBitOffset ) +// .def( "bitWidth", &TypeInfo::getBitWidth ) +// .def( "field", &TypeInfo::getField ) +// .def( "asMap", &TypeInfo::asMap ) +// .def( "deref", &TypeInfo::deref ) +// .def( "__str__", &TypeInfo::print ) +// .def( "__getattr__", &TypeInfo::getField ) +// .def("__len__", &TypeInfo::getElementCount ) +// .def("__getitem__", &TypeInfo::getElementByIndex ); +// +// python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar", +// "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", python::no_init ) +// .def("__init__", python::make_constructor(TypedVar::getTypedVarByName) ) +// .def("__init__", python::make_constructor(TypedVar::getTypedVarByTypeName) ) +// .def("__init__", python::make_constructor(TypedVar::getTypedVarByTypeInfo) ) +// .def("getAddress", &TypedVar::getAddress, +// "Return virtual address" ) +// .def("sizeof", &TypedVar::getSize, +// "Return size of a variable in the target memory" ) +// .def("fieldOffset", &TypedVar::getFieldOffsetByNameRecirsive, +// "Return target field offset" ) +// .def("field", &TypedVar::getField, +// "Return field of structure as an object attribute" ) +// .def( "dataKind", &TypedVar::getDataKind, +// "Retrieves the variable classification of a data: DataIsXxx") +// .def("deref", &TypedVar::deref, +// "Return value by pointer" ) +// .def("type", &TypedVar::getType, +// "Return typeInfo instance" ) +// .def("__getattr__", &TypedVar::getField, +// "Return field of structure as an object attribute" ) +// .def( "__str__", &TypedVar::print ) +// .def("__len__", &TypedVar::getElementCount ) +// .def("__getitem__", &TypedVar::getElementByIndex ) +// .def("__getitem__", &TypedVar::getElementByIndexPtr ); +// +// python::class_<Module, ModulePtr, python::bases<intBase> >("module", "Class representing executable module", python::no_init ) +// .def("__init__", python::make_constructor(Module::loadModuleByName) ) +// .def("__init__", python::make_constructor(Module::loadModuleByOffset) ) +// .def("begin", &Module::getBase, +// "Return start address of the module" ) +// .def("end", &Module::getEnd, +// "Return end address of the module" ) +// .def("size", &Module::getSize, +// "Return size of the module" ) +// .def("name", &Module::getName, +// "Return name of the module" ) +// .def("image", &Module::getImageName, +// "Return name of the image of the module" ) +// .def("pdb", &Module::getPdbName, +// "Return the full path to the module's pdb file ( symbol information )" ) +// .def("reload", &Module::reloadSymbols, +// "(Re)load symbols for the module" ) +// .def("offset", &Module::getSymbol, +// "Return offset of the symbol" ) +// .def("rva", &Module::getSymbolRva, +// "Return rva of the symbol" ) +// .def( "sizeof", &Module::getSymbolSize, +// "Return a size of the type or variable" ) +// .def("type", &Module::getTypeByName, +// "Return typeInfo class by type name" ) +// .def("typedVar", &Module::getTypedVarByAddr, +// "Return a typedVar class instance" ) +// .def("typedVar",&Module::getTypedVarByName, +// "Return a typedVar class instance" ) +// .def("typedVar",&Module::getTypedVarByType, +// "Return a typedVar class instance" ) +// .def("typedVar",&Module::getTypedVarByTypeName, +// "Return a typedVar class instance" ) +// .def("typedVarList", &Module::getTypedVarListByTypeName, +// "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) +// .def("typedVarList", &Module::getTypedVarListByType, +// "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) +// .def("typedVarArray", &Module::getTypedVarArrayByTypeName, +// "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) +// .def("typedVarArray", &Module::getTypedVarArrayByType, +// "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) +// .def("containingRecord", &Module::containingRecordByName, +// "Return instance of the typedVar class. It's value are loaded from the target memory." +// "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) +// .def("containingRecord", &Module::containingRecordByType, +// "Return instance of the typedVar class. It's value are loaded from the target memory." +// "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) +// .def("checksum",&Module::getCheckSum, +// "Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" ) +// .def("timestamp",&Module::getTimeDataStamp, +// "Return a low 32 bits of the time stamp of the image: IMAGE_FILE_HEADER.TimeDateStamp" ) +// .def("__getattr__", &Module::getSymbol, +// "Return address of the symbol" ) +// .def( "__str__", &Module::print ); +// +// python::class_<DbgOut>( "dout", "dout", python::no_init ) +// .def( "write", &DbgOut::write ); +// +// python::class_<DbgIn>( "din", "din", python::no_init ) +// .def( "readline", &DbgIn::readline ); +// +// python::class_<DbgExtension, DbgExtensionPtr>("ext", python::no_init ) +// .def( "call", &DbgExtension::call, +// "Call debug extension command end return it's result as a string" ); +// +// python::class_<EventHandlerWrap, boost::noncopyable>( +// "eventHandler", "Base class for overriding and handling debug notifications" ) +// .def( python::init<>() ) +// .def( "reset", &pykd::EventHandler::reset, +// "Reset event handler" ) +// .def( "onBreakpoint", &pykd::EventHandlerWrap::onBreakpoint, +// "Triggered breakpoint event. Parameter is int: ID of breakpoint\n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) +// .def( "onException", &pykd::EventHandlerWrap::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", &pykd::EventHandlerWrap::onLoadModule, +// "Load module event. Parameter is instance of module.\n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) +// .def( "onUnloadModule", &pykd::EventHandlerWrap::onUnloadModule, +// "Unload module event. Parameter is base address of unloaded module.\n" +// "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); +// +// python::class_<Disasm>("disasm", "Class disassemble a processor instructions" ) +// .def( python::init<>( "constructor" ) ) +// .def( python::init<ULONG64>( boost::python::args("offset"), "constructor" ) ) +// .def( "disasm", &Disasm::disassemble, "Disassemble next instruction" ) +// .def( "disasm", &Disasm::jump, "Disassemble from the specified offset" ) +// .def( "asm", &Disasm::assembly, "Insert assemblied instuction to current offset" ) +// .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" ) +// .def( "reset", &Disasm::reset, "Reset current offset to begin" ); +// +// python::class_<StackFrame>( "stackFrame", +// "Class representing a frame of the call stack", python::no_init ) +// .def_readonly( "instructionOffset", &StackFrame::m_instructionOffset, +// "Return a frame's instruction offset" ) +// .def_readonly( "returnOffset", &StackFrame::m_returnOffset, +// "Return a frame's return offset" ) +// .def_readonly( "frameOffset", &StackFrame::m_frameOffset, +// "Return a frame's offset" ) +// .def_readonly( "stackOffset", &StackFrame::m_stackOffset, +// "Return a frame's stack offset" ) +// .def_readonly( "frameNumber", &StackFrame::m_frameNumber, +// "Return a frame's number" ) +// .def( "getLocals", &StackFrame::getLocals, StackFrame_getLocals( python::args( "ctx" ), +// "Get list of local variables for this stack frame" ) ) +// .def( "__str__", &StackFrame::print, +// "Return stacks frame as a string"); +// +// python::class_<ThreadContext, ContextPtr>( +// "Context", "Context of thread (register values)", python::no_init ) +// .def( "ip", &ThreadContext::getIp, +// "Get instruction pointer register" ) +// .def( "retreg", &ThreadContext::getRetReg, +// "Get primary return value register" ) +// .def( "csp", &ThreadContext::getSp, +// "Get current stack pointer" ) +// .def( "get", &ThreadContext::getValue, +// "Get register value by ID (CV_REG_XXX)" ) +// .def( "get", &ThreadContext::getValueByName, +// "Get register value by name" ) +// .def( "processorType", &ThreadContext::getProcessorType, +// "Get processor ThreadContext as string") +// .def( "fork", &ThreadContext::forkByStackFrame, +// "Create new thread context by stackFrame") +// .def("__len__", &ThreadContext::getCount, +// "Return count of registers") +// .def("__getitem__", &ThreadContext::getByIndex, +// "Return tuple<ID, NAME, VALUE> by index") +// .def("__getitem__", &ThreadContext::getValueByName, +// "Return register value by name" ) +// .def("__getattr__", &ThreadContext::getValueByName, +// "Return register value as a attribute of the Context" ) +// .def("__str__", &ThreadContext::print, +// "Return context as a string" ); +// +// python::class_<CpuReg, python::bases<intBase> >( +// "cpuReg", "CPU regsiter class", boost::python::no_init ) +// .def( "name", &CpuReg::name, "The name of the regsiter" ) +// .def( "index", &CpuReg::index, "The index of thr register" ); +// +// python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, +// "Open pdb file for querying debug symbols. Return DiaSymbol of global scope"); +// python::def( "diaLoadExe", &pyDia::GlobalScope::loadExe, pyDia_GlobalScope_loadExe( python::args( "fileName", "searchPath" ) , +// "Load the debug symbols associated with the executable file. Return DiaSymbol of global scope") ); +// +// python::class_<pyDia::Symbol, pyDia::SymbolPtr>( +// "DiaSymbol", "class wrapper for MS DIA Symbol", python::no_init ) +// .def( "findEx", &pyDia::Symbol::findChildrenEx, pyDia_Symbol_findChildrenEx( python::args( "symTag", "name", "cmpFlags" ) , +// "Retrieves the children of the symbol" ) ) +// .def( "find", &pyDia::Symbol::findChildren, +// "Retrieves the children of the symbol" ) +// .def( "size", &pyDia::Symbol::getSize, +// "Retrieves the number of bits or bytes of memory used by the object represented by this symbol" ) +// .def( "name", &pyDia::Symbol::getName, +// "Retrieves the name of the symbol" ) +// .def( "undecoratedName", &pyDia::Symbol::getUndecoratedName, +// "Retrieves the undecorated name for a C++ decorated, or linkage, name" ) +// .def( "type", &pyDia::Symbol::getType, +// "Retrieves the symbol that represents the type for this symbol" ) +// .def( "indexType", &pyDia::Symbol::getIndexType, +// "Retrieves a reference to the class parent of the symbol" ) +// .def( "rva", &pyDia::Symbol::getRva, +// "Retrieves the relative virtual address (RVA) of the location") +// .def( "va", &pyDia::Symbol::getVa, +// "Retrieves the virtual address (VA) of the location") +// .def( "symTag", &pyDia::Symbol::getSymTag, +// "Retrieves the symbol type classifier: SymTagXxx" ) +// .def( "locType", &pyDia::Symbol::getLocType, +// "Retrieves the location type of a data symbol: LocIsXxx" ) +// .def( "offset", &pyDia::Symbol::getOffset, +// "Retrieves the offset of the symbol location" ) +// .def( "count", &pyDia::Symbol::getCount, +// "Retrieves the number of items in a list or array" ) +// .def( "value", (python::object(pyDia::Symbol::*)())&pyDia::Symbol::getValue, +// "Retrieves the value of a constant") +// .def( "isBasic", &pyDia::Symbol::isBasicType, +// "Retrieves a flag of basic type for symbol") +// .def( "baseType", &pyDia::Symbol::getBaseType, +// "Retrieves the base type for this symbol") +// .def( "bitPos", &pyDia::Symbol::getBitPosition, +// "Retrieves the bit position of location") +// .def( "indexId", &pyDia::Symbol::getIndexId, +// "Retrieves the unique symbol identifier") +// .def( "udtKind", &pyDia::Symbol::getUdtKind, +// "Retrieves the variety of a user-defined type") +// .def( "dataKind", &pyDia::Symbol::getDataKind, +// "Retrieves the variable classification of a data symbol") +// .def("registerId", &pyDia::Symbol::getRegisterId, +// "Retrieves the register designator of the location:\n" +// "CV_REG_XXX (for IMAGE_FILE_MACHINE_I386) or CV_AMD64_XXX (for IMAGE_FILE_MACHINE_AMD64)") +// .def("machineType", &pyDia::Symbol::getMachineType, +// "Retrieves the type of the target CPU: IMAGE_FILE_MACHINE_XXX") +// .def("section", &pyDia::Symbol::getSection, +// "Retrieves the address section of a thunk target") +// .def( "__str__", &pyDia::Symbol::print) +// .def("__getitem__", &pyDia::Symbol::getChildByName) +// .def("__len__", &pyDia::Symbol::getChildCount ) +// .def("__getitem__", &pyDia::Symbol::getChildByIndex ) +// .def("__eq__", &pyDia::Symbol::eq) +// .def("__hash__", &pyDia::Symbol::getIndexId); +// +// python::class_<pyDia::GlobalScope, pyDia::GlobalScopePtr, python::bases<pyDia::Symbol> >( +// "DiaScope", "class wrapper for MS DIA global scope", python::no_init ) +// .def("findByRva", &pyDia::GlobalScope::findByRva, +// "Find symbol by RVA. Return tuple: (DiaSymbol, offset)") +// .def("findByVa", &pyDia::GlobalScope::findByVa, +// "Find symbol by VA. Return tuple: (DiaSymbol, offset)") +// .def("symbolById", &pyDia::GlobalScope::getSymbolById, +// "Retrieves a symbol by its unique identifier: DiaSymbol::indexId()") +// .def("loadAddress", &pyDia::GlobalScope::getLoadAddress, +// "Retrieves the load address for the executable file that corresponds to the symbols in this symbol store") +// .def("setLoadAddress", &pyDia::GlobalScope::setLoadAddress, +// "Sets the load address for the executable file that corresponds to the symbols in this symbol store"); +// +// // CPU type: +// DEF_PY_CONST_ULONG(IMAGE_FILE_MACHINE_I386); +// DEF_PY_CONST_ULONG(IMAGE_FILE_MACHINE_IA64); +// DEF_PY_CONST_ULONG(IMAGE_FILE_MACHINE_AMD64); +// +// // type of symbol +// DEF_PY_CONST_ULONG(SymTagNull); +// DEF_PY_CONST_ULONG(SymTagExe); +// DEF_PY_CONST_ULONG(SymTagCompiland); +// DEF_PY_CONST_ULONG(SymTagCompilandDetails); +// DEF_PY_CONST_ULONG(SymTagCompilandEnv); +// DEF_PY_CONST_ULONG(SymTagFunction); +// DEF_PY_CONST_ULONG(SymTagBlock); +// DEF_PY_CONST_ULONG(SymTagData); +// DEF_PY_CONST_ULONG(SymTagAnnotation); +// DEF_PY_CONST_ULONG(SymTagLabel); +// DEF_PY_CONST_ULONG(SymTagPublicSymbol); +// DEF_PY_CONST_ULONG(SymTagUDT); +// DEF_PY_CONST_ULONG(SymTagEnum); +// DEF_PY_CONST_ULONG(SymTagFunctionType); +// DEF_PY_CONST_ULONG(SymTagPointerType); +// DEF_PY_CONST_ULONG(SymTagArrayType); +// DEF_PY_CONST_ULONG(SymTagBaseType); +// DEF_PY_CONST_ULONG(SymTagTypedef); +// DEF_PY_CONST_ULONG(SymTagBaseClass); +// DEF_PY_CONST_ULONG(SymTagFriend); +// DEF_PY_CONST_ULONG(SymTagFunctionArgType); +// DEF_PY_CONST_ULONG(SymTagFuncDebugStart); +// DEF_PY_CONST_ULONG(SymTagFuncDebugEnd); +// DEF_PY_CONST_ULONG(SymTagUsingNamespace); +// DEF_PY_CONST_ULONG(SymTagVTableShape); +// DEF_PY_CONST_ULONG(SymTagVTable); +// DEF_PY_CONST_ULONG(SymTagCustom); +// DEF_PY_CONST_ULONG(SymTagThunk); +// DEF_PY_CONST_ULONG(SymTagCustomType); +// DEF_PY_CONST_ULONG(SymTagManagedType); +// DEF_PY_CONST_ULONG(SymTagDimension); +// python::scope().attr("diaSymTagName") = +// genDict(pyDia::Symbol::symTagName, _countof(pyDia::Symbol::symTagName)); +// +// DEF_PY_CONST_ULONG(DataIsUnknown); +// DEF_PY_CONST_ULONG(DataIsLocal); +// DEF_PY_CONST_ULONG(DataIsStaticLocal); +// DEF_PY_CONST_ULONG(DataIsParam); +// DEF_PY_CONST_ULONG(DataIsObjectPtr); +// DEF_PY_CONST_ULONG(DataIsFileStatic); +// DEF_PY_CONST_ULONG(DataIsGlobal); +// DEF_PY_CONST_ULONG(DataIsMember); +// DEF_PY_CONST_ULONG(DataIsStaticMember); +// DEF_PY_CONST_ULONG(DataIsConstant); +// python::scope().attr("diaDataKind") = +// genDict(pyDia::Symbol::dataKindName, _countof(pyDia::Symbol::dataKindName)); +// +// // search options for symbol and file names +// DEF_PY_CONST_ULONG(nsfCaseSensitive); +// DEF_PY_CONST_ULONG(nsfCaseInsensitive); +// DEF_PY_CONST_ULONG(nsfFNameExt); +// DEF_PY_CONST_ULONG(nsfRegularExpression); +// DEF_PY_CONST_ULONG(nsfUndecoratedName); +// DEF_PY_CONST_ULONG(nsCaseSensitive); +// DEF_PY_CONST_ULONG(nsCaseInsensitive); +// DEF_PY_CONST_ULONG(nsFNameExt); +// DEF_PY_CONST_ULONG(nsRegularExpression); +// DEF_PY_CONST_ULONG(nsCaseInRegularExpression); +// +// // location type +// DEF_PY_CONST_ULONG(LocIsNull); +// DEF_PY_CONST_ULONG(LocIsStatic); +// DEF_PY_CONST_ULONG(LocIsTLS); +// DEF_PY_CONST_ULONG(LocIsRegRel); +// DEF_PY_CONST_ULONG(LocIsThisRel); +// DEF_PY_CONST_ULONG(LocIsEnregistered); +// DEF_PY_CONST_ULONG(LocIsBitField); +// DEF_PY_CONST_ULONG(LocIsSlot); +// DEF_PY_CONST_ULONG(LocIsIlRel); +// DEF_PY_CONST_ULONG(LocInMetaData); +// DEF_PY_CONST_ULONG(LocIsConstant); +// python::scope().attr("diaLocTypeName") = +// genDict(pyDia::Symbol::locTypeName, _countof(pyDia::Symbol::locTypeName)); +// +// DEF_PY_CONST_ULONG(btNoType); +// DEF_PY_CONST_ULONG(btVoid); +// DEF_PY_CONST_ULONG(btChar); +// DEF_PY_CONST_ULONG(btWChar); +// DEF_PY_CONST_ULONG(btInt); +// DEF_PY_CONST_ULONG(btUInt); +// DEF_PY_CONST_ULONG(btFloat); +// DEF_PY_CONST_ULONG(btBCD); +// DEF_PY_CONST_ULONG(btBool); +// DEF_PY_CONST_ULONG(btLong); +// DEF_PY_CONST_ULONG(btULong); +// DEF_PY_CONST_ULONG(btCurrency); +// DEF_PY_CONST_ULONG(btDate); +// DEF_PY_CONST_ULONG(btVariant); +// DEF_PY_CONST_ULONG(btComplex); +// DEF_PY_CONST_ULONG(btBit); +// DEF_PY_CONST_ULONG(btBSTR); +// DEF_PY_CONST_ULONG(btHresult); +// python::scope().attr("diaBasicType") = +// genDict(pyDia::Symbol::basicTypeName, pyDia::Symbol::cntBasicTypeName); +// +// DEF_PY_CONST_ULONG(UdtStruct); +// DEF_PY_CONST_ULONG(UdtClass); +// DEF_PY_CONST_ULONG(UdtUnion); +// python::scope().attr("diaUdtKind") = +// genDict(pyDia::Symbol::udtKindName, pyDia::Symbol::cntUdtKindName); +// +// // i386/amd64 cpu registers +//#include "diaregs.h" +// python::scope().attr("diaI386Regs") = +// genDict(pyDia::Symbol::i386RegName, pyDia::Symbol::cntI386RegName); +// python::scope().attr("diaAmd64Regs") = +// genDict(pyDia::Symbol::amd64RegName, pyDia::Symbol::cntAmd64RegName); +// +// // exception: +// +// // wrapper for standart python exceptions +// python::register_exception_translator<PyException>( &PyException::exceptionTranslate ); +// +// +// pykd::exception<DbgException>( "BaseException", "Pykd base exception class" ); +// pykd::exception<MemoryException,DbgException>( "MemoryException", "Target memory access exception class" ); +// pykd::exception<WaitEventException,DbgException>( "WaitEventException", "Debug interface access exception" ); +// pykd::exception<SymbolException,DbgException>( "SymbolException", "Symbol exception" ); +// pykd::exception<pyDia::Exception,SymbolException>( "DiaException", "Debug interface access exception" ); +// pykd::exception<TypeException,SymbolException>( "TypeException", "type exception" ); +// pykd::exception<AddSyntheticSymbolException,DbgException>( "AddSynSymbolException", "synthetic symbol exception" ); +// pykd::exception<ImplementException,DbgException>( "ImplementException", "implementation exception" ); +// +// DEF_PY_CONST_ULONG( DEBUG_CLASS_UNINITIALIZED ); +// DEF_PY_CONST_ULONG( DEBUG_CLASS_KERNEL ); +// DEF_PY_CONST_ULONG( DEBUG_CLASS_USER_WINDOWS ); +// +// DEF_PY_CONST_ULONG( DEBUG_KERNEL_CONNECTION ); +// DEF_PY_CONST_ULONG( DEBUG_KERNEL_LOCAL ); +// DEF_PY_CONST_ULONG( DEBUG_KERNEL_EXDI_DRIVER ); +// DEF_PY_CONST_ULONG( DEBUG_KERNEL_SMALL_DUMP ); +// DEF_PY_CONST_ULONG( DEBUG_KERNEL_DUMP ); +// DEF_PY_CONST_ULONG( DEBUG_KERNEL_FULL_DUMP ); +// +// DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_PROCESS ); +// DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_PROCESS_SERVER ); +// DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_SMALL_DUMP ); +// DEF_PY_CONST_ULONG( DEBUG_USER_WINDOWS_DUMP ); +// +// // exception codes +// DEF_PY_CONST_ULONG(EXCEPTION_ACCESS_VIOLATION); +// DEF_PY_CONST_ULONG(EXCEPTION_DATATYPE_MISALIGNMENT); +// DEF_PY_CONST_ULONG(EXCEPTION_BREAKPOINT); +// DEF_PY_CONST_ULONG(EXCEPTION_SINGLE_STEP); +// DEF_PY_CONST_ULONG(EXCEPTION_ARRAY_BOUNDS_EXCEEDED); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_DENORMAL_OPERAND); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_DIVIDE_BY_ZERO); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_INEXACT_RESULT); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_INVALID_OPERATION); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_OVERFLOW); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_STACK_CHECK); +// DEF_PY_CONST_ULONG(EXCEPTION_FLT_UNDERFLOW); +// DEF_PY_CONST_ULONG(EXCEPTION_INT_DIVIDE_BY_ZERO); +// DEF_PY_CONST_ULONG(EXCEPTION_INT_OVERFLOW); +// DEF_PY_CONST_ULONG(EXCEPTION_PRIV_INSTRUCTION); +// DEF_PY_CONST_ULONG(EXCEPTION_IN_PAGE_ERROR); +// DEF_PY_CONST_ULONG(EXCEPTION_ILLEGAL_INSTRUCTION); +// DEF_PY_CONST_ULONG(EXCEPTION_NONCONTINUABLE_EXCEPTION); +// DEF_PY_CONST_ULONG(EXCEPTION_STACK_OVERFLOW); +// DEF_PY_CONST_ULONG(EXCEPTION_INVALID_DISPOSITION); +// DEF_PY_CONST_ULONG(EXCEPTION_GUARD_PAGE); +// DEF_PY_CONST_ULONG(EXCEPTION_INVALID_HANDLE); +// +// // debug status +// DEF_PY_CONST_ULONG(DEBUG_STATUS_NO_CHANGE); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_GO); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_GO_HANDLED); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_GO_NOT_HANDLED); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_STEP_OVER); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_STEP_INTO); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_BREAK); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_NO_DEBUGGEE); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_STEP_BRANCH); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_RESTART_REQUESTED); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_GO); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_STEP_BRANCH); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_STEP_OVER); +// DEF_PY_CONST_ULONG(DEBUG_STATUS_REVERSE_STEP_INTO); +// +// // breakpoints constatns +// DEF_PY_CONST_ULONG(DEBUG_BREAKPOINT_CODE); +// DEF_PY_CONST_ULONG(DEBUG_BREAKPOINT_DATA); +// +// DEF_PY_CONST_ULONG(DEBUG_BREAK_READ); +// DEF_PY_CONST_ULONG(DEBUG_BREAK_WRITE); +// DEF_PY_CONST_ULONG(DEBUG_BREAK_EXECUTE); +// DEF_PY_CONST_ULONG(DEBUG_BREAK_IO); +//} +// +//#undef DEF_PY_CONST_ULONG +// +////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/stdafx.h b/pykd/stdafx.h index 14bcf9c..e2a1ef1 100644 --- a/pykd/stdafx.h +++ b/pykd/stdafx.h @@ -54,5 +54,3 @@ namespace python = boost::python; #include <boost/regex.hpp> #include <boost/variant.hpp> -#include <boost\thread\win32\recursive_mutex.hpp> - diff --git a/pykd/windbgeng.cpp b/pykd/windbgeng.cpp new file mode 100644 index 0000000..a990660 --- /dev/null +++ b/pykd/windbgeng.cpp @@ -0,0 +1,209 @@ +#include "stdafx.h" + +#include "windbgeng.h" +#include "dbgexcept.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////////// + +DebugEngine g_dbgEng; + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG startProcess( const std::wstring &processName ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + ULONG opt; + hres = g_dbgEng->control->GetEngineOptions( &opt ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetEngineOptions failed" ); + + opt |= DEBUG_ENGOPT_INITIAL_BREAK; + hres = g_dbgEng->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 = g_dbgEng->client->CreateProcessWide( 0, &cmdLine[0], DEBUG_PROCESS | DETACHED_PROCESS ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient4::CreateProcessWide failed" ); + + hres = g_dbgEng->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::WaitForEvent failed" ); + + ULONG processId = -1; + hres = g_dbgEng->system->GetCurrentProcessId( &processId ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSystemObjects::GetCurrentProcessId failed" ); + + return processId; +} + +/////////////////////////////////////////////////////////////////////////////////// + +void detachProcess( ULONG processId ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + if ( processId != -1 ) + { + hres = g_dbgEng->system->SetCurrentProcessId(processId); + if ( FAILED(hres) ) + throw DbgException( "IDebugSystemObjects::SetCurrentProcessId failed" ); + } + + hres = g_dbgEng->client->DetachCurrentProcess(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::DetachCurrentProcess failed" ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +void terminateProcess( ULONG processId ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + if ( processId != -1 ) + { + hres = g_dbgEng->system->SetCurrentProcessId(processId); + if ( FAILED(hres) ) + throw DbgException( "IDebugSystemObjects::SetCurrentProcessId failed" ); + } + + hres = g_dbgEng->client->TerminateCurrentProcess(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::TerminateCurrentProcess", hres ); + +} + +/////////////////////////////////////////////////////////////////////////////////// + +void debugGo() +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + hres = g_dbgEng->control->SetExecutionStatus( DEBUG_STATUS_GO ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::SetExecutionStatus failed" ); + + ULONG currentStatus; + + do { + hres = g_dbgEng->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::WaitForEvent failed" ); + + hres = g_dbgEng->control->GetExecutionStatus( ¤tStatus ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetExecutionStatus failed" ); + + } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 findModuleBase( const std::string &moduleName ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG64 base; + + hres = g_dbgEng->symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &base ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); + + return base; +} + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 findModuleBase( ULONG64 offset ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG64 base; + ULONG moduleIndex; + + hres = g_dbgEng->symbols->GetModuleByOffset( offset, 0, &moduleIndex, &base ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleByOffset failed" ); + + return base; +} + +/////////////////////////////////////////////////////////////////////////////////// + +std::string getModuleName( ULONG64 baseOffset ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + char moduleName[0x100]; + + hres = g_dbgEng->symbols->GetModuleNameString( + DEBUG_MODNAME_MODULE, + DEBUG_ANY_ID, + baseOffset, + moduleName, + sizeof( moduleName ), + NULL ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleNameString failed" ); + + return std::string( moduleName ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 addr64( ULONG64 addr ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + + ULONG processorMode; + hres = g_dbgEng->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; + } + + return addr; +} + +/////////////////////////////////////////////////////////////////////////////////// + +}; + + diff --git a/pykd/windbgeng.h b/pykd/windbgeng.h new file mode 100644 index 0000000..6b156ff --- /dev/null +++ b/pykd/windbgeng.h @@ -0,0 +1,62 @@ +#pragma once + +#include "dbgengine.h" +#include "dbgexcept.h" +#include "pyaux.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////////// + +class DebugEngine { + +public: + + struct DbgEngBind { + + CComQIPtr<IDebugClient4> client; + CComQIPtr<IDebugControl4> control; + CComQIPtr<IDebugSystemObjects2> system; + CComQIPtr<IDebugSymbols3> symbols; + + DbgEngBind( PDEBUG_CLIENT4 c ) + { + client = c; + control = c; + system = c; + symbols = c; + } + + PyThreadStateSaver pystate; + }; + + DbgEngBind* + operator->() + { + if ( m_bind.get() != NULL ) + return m_bind.get(); + + CComPtr<IDebugClient4> client = NULL; + + HRESULT hres = DebugCreate( __uuidof(IDebugClient4), (void **)&client ); + if ( FAILED( hres ) ) + throw DbgException("DebugCreate failed"); + + m_bind.reset(new DbgEngBind(client) ); + + return m_bind.get(); + } + +private: + + std::auto_ptr<DbgEngBind> m_bind; + +}; + +/////////////////////////////////////////////////////////////////////////////////// + +extern DebugEngine g_dbgEng; + +/////////////////////////////////////////////////////////////////////////////////// + +}; \ No newline at end of file diff --git a/pykd_01_2008.sln b/pykd_02_2008.sln similarity index 100% rename from pykd_01_2008.sln rename to pykd_02_2008.sln diff --git a/pykd_01_2008.vssscc b/pykd_02_2008.vssscc similarity index 100% rename from pykd_01_2008.vssscc rename to pykd_02_2008.vssscc diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py index 6638dbe..20830e4 100644 --- a/test/scripts/moduletest.py +++ b/test/scripts/moduletest.py @@ -7,14 +7,14 @@ import target import pykd class ModuleTest( unittest.TestCase ): - + def testCtor( self ): - self.assertEqual( target.module.name(), pykd.module(target.module.begin() ).name() ) - self.assertEqual( target.module.name(), pykd.module(target.module.name() ).name() ) + self.assertEqual( target.module.name(), pykd.module(target.module.begin() ).name() ) + self.assertEqual( target.module.name(), pykd.module(target.module.name() ).name() ) def testName( self ): self.assertEqual( target.moduleName, target.module.name() ) - + def testSize( self ): self.assertNotEqual( 0, target.module.size() ) @@ -26,40 +26,40 @@ class ModuleTest( unittest.TestCase ): def testEnd( self ): self.assertEqual( target.module.size(), target.module.end() - target.module.begin() ) - def testPdb( self ): - self.assertNotEqual( "", target.module.pdb() ) +# def testPdb( self ): +# self.assertNotEqual( "", target.module.pdb() ) - def testImage( self ): - self.assertEqual( target.module.name() + ".exe", target.module.image() ) +# def testImage( self ): +# self.assertEqual( target.module.name() + ".exe", target.module.image() ) - def testFindModule( self ): +# def testFindModule( self ): - try: - pykd.loadModule( target.module.begin() - 0x10 ) - self.assertTrue( False ) - except pykd.BaseException: - self.assertTrue( True ) +# try: +# pykd.loadModule( target.module.begin() - 0x10 ) +# self.assertTrue( False ) +# except pykd.BaseException: +# self.assertTrue( True ) - self.assertNotEqual( None, pykd.loadModule( target.module.begin() ) ) - self.assertNotEqual( None, pykd.loadModule( target.module.begin() + 0x10) ) +# self.assertNotEqual( None, pykd.loadModule( target.module.begin() ) ) +# self.assertNotEqual( None, pykd.loadModule( target.module.begin() + 0x10) ) - try: - pykd.loadModule( target.module.end() ) - self.assertTrue( False ) - except pykd.BaseException: - self.assertTrue( True ) +# try: +# pykd.loadModule( target.module.end() ) +# self.assertTrue( False ) +# except pykd.BaseException: +# self.assertTrue( True ) - try: - pykd.loadModule( target.module.end() + 0x10 ) - self.assertTrue( False ) - except pykd.BaseException: - self.assertTrue( True ) +# try: +# pykd.loadModule( target.module.end() + 0x10 ) +# self.assertTrue( False ) +# except pykd.BaseException: +# self.assertTrue( True ) - def testSymbol( self ): - self.assertEqual( target.module.rva("FuncWithName0"), target.module.offset("FuncWithName0") - target.module.begin() ) - self.assertEqual( target.module.rva("FuncWithName0"), target.module.FuncWithName0 - target.module.begin() ) +# def testSymbol( self ): +# self.assertEqual( target.module.rva("FuncWithName0"), target.module.offset("FuncWithName0") - target.module.begin() ) +# self.assertEqual( target.module.rva("FuncWithName0"), target.module.FuncWithName0 - target.module.begin() ) - def testType( self ): - self.assertEqual( "structTest", target.module.type("structTest").name() ); - self.assertEqual( "structTest", target.module.type("g_structTest").name() ); +# def testType( self ): +# self.assertEqual( "structTest", target.module.type("structTest").name() ); +# self.assertEqual( "structTest", target.module.type("g_structTest").name() ); diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 535ca32..5151d2a 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -8,83 +8,143 @@ import unittest # Dynamically append current pykd.pyd path to PYTHONPATH sys.path.insert(0, os.path.dirname(sys.argv[1])) + import pykd import target -import basetest -import typeinfo -import regtest import moduletest -import diatest -import dbgcmd -import clienttest -import eventtest -import typedvar -import memtest import intbase -import synsymtest -import ehloadtest -import thrdctxtest -import localstest -import ehexcepttest - + def getTestSuite( singleName = "" ): if singleName == "": return unittest.TestSuite( - [ unittest.TestLoader().loadTestsFromTestCase( basetest.BaseTest ), - unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ), - unittest.TestLoader().loadTestsFromTestCase( diatest.DiaTest ), - unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ), - unittest.TestLoader().loadTestsFromTestCase( typedvar.TypedVarTest ), - unittest.TestLoader().loadTestsFromTestCase( dbgcmd.DbgcmdTest ), - unittest.TestLoader().loadTestsFromTestCase( clienttest.DbgClientTest ), - unittest.TestLoader().loadTestsFromTestCase( eventtest.EventTest ), - unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ), - unittest.TestLoader().loadTestsFromTestCase( intbase.IntBaseTest ), - unittest.TestLoader().loadTestsFromTestCase( synsymtest.SynSymTest ), - unittest.TestLoader().loadTestsFromTestCase( thrdctxtest.ThreadContextTest ), - unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest ), - ] ) + [ + unittest.TestLoader().loadTestsFromTestCase( target.TargetTest ), + unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ), + unittest.TestLoader().loadTestsFromTestCase( intbase.IntBaseTest ), + ] ) else: return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) ) -def getNewProcessTestSuite(): - return unittest.TestSuite( - [ - unittest.TestLoader().loadTestsFromTestCase( ehloadtest.EhLoadTest ), - # unittest.TestLoader().loadTestsFromTestCase( localstest.LocalVarsTest ), - # unittest.TestLoader().loadTestsFromTestCase( ehexcepttest.EhExceptionBreakpointTest ), - ] ) - - if __name__ == "__main__": print "\nTesting PyKd ver. " + pykd.version - + target.appPath = sys.argv[1] - target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0] - print "Test module: %s" % target.appPath + #print "Test module: %s" % target.appPath - pykd.startProcess( target.appPath ) - - target.module = pykd.loadModule( target.moduleName ) + processId = pykd.startProcess( target.appPath ) + target.module = pykd.module( target.moduleName ) target.module.reload(); - + pykd.go() + + unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() ) - print "" + pykd.killProcess( processId ) - oneProcessTests = getTestSuite() + + + + + + + +#import target +#import moduletest + +#import basetest +#import typeinfo +#import regtest +#import moduletest +#import diatest +#import dbgcmd +#import clienttest +#import eventtest +#import typedvar +#import memtest +#import intbase +#import synsymtest +#import ehloadtest +#import thrdctxtest +#import localstest +#import ehexcepttest + +#def getTestSuite( singleName = "" ): +# if singleName == "": +# return unittest.TestSuite( +# [ +# unittest.TestLoader().loadTestsFromTestCase( target.TargetTest ), +# unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ), + + +# unittest.TestLoader().loadTestsFromTestCase( basetest.BaseTest ), +# unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ), +# unittest.TestLoader().loadTestsFromTestCase( diatest.DiaTest ), +# unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ), +# unittest.TestLoader().loadTestsFromTestCase( typedvar.TypedVarTest ), +# unittest.TestLoader().loadTestsFromTestCase( dbgcmd.DbgcmdTest ), +# unittest.TestLoader().loadTestsFromTestCase( clienttest.DbgClientTest ), +# unittest.TestLoader().loadTestsFromTestCase( eventtest.EventTest ), +# unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ), +# unittest.TestLoader().loadTestsFromTestCase( intbase.IntBaseTest ), +# unittest.TestLoader().loadTestsFromTestCase( synsymtest.SynSymTest ), +# unittest.TestLoader().loadTestsFromTestCase( thrdctxtest.ThreadContextTest ), +# unittest.TestLoader().loadTestsFromTestCase( regtest.CpuRegTest ), +# ] ) +# else: +# return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) ) + +#def getNewProcessTestSuite(): +# return unittest.TestSuite( +# [ +# unittest.TestLoader().loadTestsFromTestCase( ehloadtest.EhLoadTest ), +# # unittest.TestLoader().loadTestsFromTestCase( localstest.LocalVarsTest ), +# # unittest.TestLoader().loadTestsFromTestCase( ehexcepttest.EhExceptionBreakpointTest ), +# ] ) + + +#if __name__ == "__main__": + +# print "\nTesting PyKd ver. " + pykd.version + +# target.appPath = sys.argv[1] + +# unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() ) + + + + + + + + + #target.appPath = sys.argv[1] + + #target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0] + #print "Test module: %s" % target.appPath + + #pykd.startProcess( target.appPath ) + + #target.module = pykd.loadModule( target.moduleName ) + #target.module.reload(); + + #pykd.go() + + #print "" + + #oneProcessTests = getTestSuite() + #oneProcessTests = getTestSuite( "diatest.DiaTest.testFind" ) #oneProcessTests = getTestSuite( "typedvar.TypedVarTest.testTypeVarArg" ) #oneProcessTests = getTestSuite( "typeinfo.TypeInfoTest.testCreateByName" ) #oneProcessTests = getTestSuite( "typedvar.TypedVarTest.testBitField" ) - unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( oneProcessTests ) + #unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( oneProcessTests ) - pykd.killProcess() + #pykd.killProcess() - unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getNewProcessTestSuite() ) + #unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getNewProcessTestSuite() ) - raw_input("\npress return\n") + #raw_input("\npress return\n") diff --git a/test/scripts/target.py b/test/scripts/target.py index 2fcf817..904bcde 100644 --- a/test/scripts/target.py +++ b/test/scripts/target.py @@ -2,7 +2,22 @@ # # +import unittest +import pykd + +appPath = None module = None moduleName = None -dbgext = None -appPath = None + +class TargetTest( unittest.TestCase ): + + def testStartStop(self): + processId = pykd.startProcess( appPath ) + pykd.killProcess( processId ) + + + +#module = None +#moduleName = None +#dbgext = None +#appPath = None