From 1931d9be5f67cd41d4ddacc87d1f450fda8c5813 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Thu, 2 Aug 2012 09:14:03 +0000 Subject: [PATCH] [0.2.x] added : typeInfo class git-svn-id: https://pykd.svn.codeplex.com/svn@78452 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgengine.h | 1 + pykd/dbgext.cpp | 2 + pykd/dia/diadata.cpp | 563 +++++++++++++++++++++ pykd/dia/diawrapper.cpp | 252 +++++++++- pykd/dia/diawrapper.h | 86 ++-- pykd/diadata.cpp | 509 ------------------- pykd/module.cpp | 21 + pykd/module.h | 7 + pykd/pykd_2008.vcproj | 16 + pykd/pymod.cpp | 32 +- pykd/stdafx.h | 4 +- pykd/typeinfo.cpp | 120 +++-- pykd/typeinfo.h | 1009 +++++++++++++++++++------------------- pykd/win/dbgeng.cpp | 20 + test/scripts/pykdtest.py | 4 +- 15 files changed, 1543 insertions(+), 1103 deletions(-) create mode 100644 pykd/dia/diadata.cpp delete mode 100644 pykd/diadata.cpp diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index 3010872..bea4307 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -15,6 +15,7 @@ ULONG ptrSize(); //manage debug module ULONG64 findModuleBase( const std::string &moduleName ); ULONG64 findModuleBase( ULONG64 offset ); +ULONG64 findModuleBySymbol( const std::string &symbolName ); std::string getModuleName( ULONG64 baseOffset ); std::string getModuleImageName( ULONG64 baseOffset ); std::string getModuleSymbolFileName( ULONG64 baseOffset ); diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index bef9f06..35b3bd3 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -1,6 +1,8 @@ #include "stdafx.h" +#include + //#include // //#include "windbg.h" diff --git a/pykd/dia/diadata.cpp b/pykd/dia/diadata.cpp new file mode 100644 index 0000000..8757e66 --- /dev/null +++ b/pykd/dia/diadata.cpp @@ -0,0 +1,563 @@ +#include "stdafx.h" +#include "diawrapper.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////// + +#define _DEF_BASIC_TYPE(x) DiaSymbol::ValueNameEntry(bt##x, #x) +const DiaSymbol::ValueNameEntry DiaSymbol::basicTypeName[] = { + _DEF_BASIC_TYPE(NoType), + _DEF_BASIC_TYPE(Void), + _DEF_BASIC_TYPE(Char), + _DEF_BASIC_TYPE(WChar), + _DEF_BASIC_TYPE(Int), + _DEF_BASIC_TYPE(UInt), + _DEF_BASIC_TYPE(Float), + _DEF_BASIC_TYPE(BCD), + _DEF_BASIC_TYPE(Bool), + _DEF_BASIC_TYPE(Long), + _DEF_BASIC_TYPE(ULong), + _DEF_BASIC_TYPE(Currency), + _DEF_BASIC_TYPE(Date), + _DEF_BASIC_TYPE(Variant), + _DEF_BASIC_TYPE(Complex), + _DEF_BASIC_TYPE(Bit), + _DEF_BASIC_TYPE(BSTR), + _DEF_BASIC_TYPE(Hresult) +}; +#undef _DEF_BASIC_TYPE + +const size_t DiaSymbol::cntBasicTypeName = _countof(DiaSymbol::basicTypeName); + +/////////////////////////////////////////////////////////////////////////////// + +} //pykd namespace end + + + + + + + + + + + + + + + + + + + + +// +//#include "diawrapper.h" +//#include "utils.h" +// +//namespace pyDia { +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_SYM_TAG_VAL(x) Symbol::ValueNameEntry(SymTag##x, #x) +//const Symbol::ValueNameEntry Symbol::symTagName[SymTagMax] = { +// _DEF_SYM_TAG_VAL(Null), +// _DEF_SYM_TAG_VAL(Exe), +// _DEF_SYM_TAG_VAL(Compiland), +// _DEF_SYM_TAG_VAL(CompilandDetails), +// _DEF_SYM_TAG_VAL(CompilandEnv), +// _DEF_SYM_TAG_VAL(Function), +// _DEF_SYM_TAG_VAL(Block), +// _DEF_SYM_TAG_VAL(Data), +// _DEF_SYM_TAG_VAL(Annotation), +// _DEF_SYM_TAG_VAL(Label), +// _DEF_SYM_TAG_VAL(PublicSymbol), +// _DEF_SYM_TAG_VAL(UDT), +// _DEF_SYM_TAG_VAL(Enum), +// _DEF_SYM_TAG_VAL(FunctionType), +// _DEF_SYM_TAG_VAL(PointerType), +// _DEF_SYM_TAG_VAL(ArrayType), +// _DEF_SYM_TAG_VAL(BaseType), +// _DEF_SYM_TAG_VAL(Typedef), +// _DEF_SYM_TAG_VAL(BaseClass), +// _DEF_SYM_TAG_VAL(Friend), +// _DEF_SYM_TAG_VAL(FunctionArgType), +// _DEF_SYM_TAG_VAL(FuncDebugStart), +// _DEF_SYM_TAG_VAL(FuncDebugEnd), +// _DEF_SYM_TAG_VAL(UsingNamespace), +// _DEF_SYM_TAG_VAL(VTableShape), +// _DEF_SYM_TAG_VAL(VTable), +// _DEF_SYM_TAG_VAL(Custom), +// _DEF_SYM_TAG_VAL(Thunk), +// _DEF_SYM_TAG_VAL(CustomType), +// _DEF_SYM_TAG_VAL(ManagedType), +// _DEF_SYM_TAG_VAL(Dimension) +//}; +//#undef _DEF_SYM_TAG_VAL +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_DATA_KIND_VAL(x) Symbol::ValueNameEntry(DataIs##x, #x) +//const Symbol::ValueNameEntry Symbol::dataKindName[DataIsConstant + 1] = { +// _DEF_DATA_KIND_VAL(Unknown), +// _DEF_DATA_KIND_VAL(Local), +// _DEF_DATA_KIND_VAL(StaticLocal), +// _DEF_DATA_KIND_VAL(Param), +// _DEF_DATA_KIND_VAL(ObjectPtr), +// _DEF_DATA_KIND_VAL(FileStatic), +// _DEF_DATA_KIND_VAL(Global), +// _DEF_DATA_KIND_VAL(Member), +// _DEF_DATA_KIND_VAL(StaticMember), +// _DEF_DATA_KIND_VAL(Constant) +//}; +//#undef _DEF_DATA_KIND_VAL +// +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_LOC_TYPE(x) Symbol::ValueNameEntry(LocIs##x, #x) +//const Symbol::ValueNameEntry Symbol::locTypeName[LocTypeMax] = { +// _DEF_LOC_TYPE(Null), +// _DEF_LOC_TYPE(Static), +// _DEF_LOC_TYPE(TLS), +// _DEF_LOC_TYPE(RegRel), +// _DEF_LOC_TYPE(ThisRel), +// _DEF_LOC_TYPE(Enregistered), +// _DEF_LOC_TYPE(BitField), +// _DEF_LOC_TYPE(Slot), +// _DEF_LOC_TYPE(IlRel), +// Symbol::ValueNameEntry(LocInMetaData, "InMetaData"), +// _DEF_LOC_TYPE(Constant) +//}; +//#undef _DEF_LOC_TYPE +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_BASIC_TYPE(x) Symbol::ValueNameEntry(bt##x, #x) +//const Symbol::ValueNameEntry Symbol::basicTypeName[] = { +// _DEF_BASIC_TYPE(NoType), +// _DEF_BASIC_TYPE(Void), +// _DEF_BASIC_TYPE(Char), +// _DEF_BASIC_TYPE(WChar), +// _DEF_BASIC_TYPE(Int), +// _DEF_BASIC_TYPE(UInt), +// _DEF_BASIC_TYPE(Float), +// _DEF_BASIC_TYPE(BCD), +// _DEF_BASIC_TYPE(Bool), +// _DEF_BASIC_TYPE(Long), +// _DEF_BASIC_TYPE(ULong), +// _DEF_BASIC_TYPE(Currency), +// _DEF_BASIC_TYPE(Date), +// _DEF_BASIC_TYPE(Variant), +// _DEF_BASIC_TYPE(Complex), +// _DEF_BASIC_TYPE(Bit), +// _DEF_BASIC_TYPE(BSTR), +// _DEF_BASIC_TYPE(Hresult) +//}; +//#undef _DEF_BASIC_TYPE +// +//const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName); +// +//std::string Symbol::getBasicTypeName( ULONG basicType ) +//{ +// for ( size_t i = 0; i < Symbol::cntBasicTypeName; ++i ) +// { +// if ( basicType == Symbol::basicTypeName[i].first ) +// return std::string( Symbol::basicTypeName[i].second ); +// } +// +// std::stringstream sstr; +// +// sstr << "faild to find basic type with index %d" << basicType; +// +// throw Exception( sstr.str() ); +//} +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_UDT_KIND(x) Symbol::ValueNameEntry(Udt##x, #x) +//const Symbol::ValueNameEntry Symbol::udtKindName[] = { +// _DEF_UDT_KIND(Struct), +// _DEF_UDT_KIND(Class), +// _DEF_UDT_KIND(Union) +//}; +//#undef _DEF_UDT_KIND +// +//const size_t Symbol::cntUdtKindName = _countof(udtKindName); +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_I386_REG(x) Symbol::ValueNameEntry(CV_REG_##x, #x) +//const Symbol::ValueNameEntry Symbol::i386RegName[] = { +// _DEF_I386_REG(AL), +// _DEF_I386_REG(CL), +// _DEF_I386_REG(DL), +// _DEF_I386_REG(BL), +// _DEF_I386_REG(AH), +// _DEF_I386_REG(CH), +// _DEF_I386_REG(DH), +// _DEF_I386_REG(BH), +// _DEF_I386_REG(AX), +// _DEF_I386_REG(CX), +// _DEF_I386_REG(DX), +// _DEF_I386_REG(BX), +// _DEF_I386_REG(SP), +// _DEF_I386_REG(BP), +// _DEF_I386_REG(SI), +// _DEF_I386_REG(DI), +// _DEF_I386_REG(EAX), +// _DEF_I386_REG(ECX), +// _DEF_I386_REG(EDX), +// _DEF_I386_REG(EBX), +// _DEF_I386_REG(ESP), +// _DEF_I386_REG(EBP), +// _DEF_I386_REG(ESI), +// _DEF_I386_REG(EDI), +// _DEF_I386_REG(ES), +// _DEF_I386_REG(CS), +// _DEF_I386_REG(SS), +// _DEF_I386_REG(DS), +// _DEF_I386_REG(FS), +// _DEF_I386_REG(GS), +// _DEF_I386_REG(IP), +// _DEF_I386_REG(FLAGS ), +// _DEF_I386_REG(EIP), +// _DEF_I386_REG(EFLAGS), +// _DEF_I386_REG(TEMP), +// _DEF_I386_REG(TEMPH), +// _DEF_I386_REG(QUOTE), +// _DEF_I386_REG(PCDR3), +// _DEF_I386_REG(PCDR4), +// _DEF_I386_REG(PCDR5), +// _DEF_I386_REG(PCDR6), +// _DEF_I386_REG(PCDR7), +// _DEF_I386_REG(CR0), +// _DEF_I386_REG(CR1), +// _DEF_I386_REG(CR2), +// _DEF_I386_REG(CR3), +// _DEF_I386_REG(CR4), +// _DEF_I386_REG(DR0), +// _DEF_I386_REG(DR1), +// _DEF_I386_REG(DR2), +// _DEF_I386_REG(DR3), +// _DEF_I386_REG(DR4), +// _DEF_I386_REG(DR5), +// _DEF_I386_REG(DR6), +// _DEF_I386_REG(DR7), +// _DEF_I386_REG(GDTR), +// _DEF_I386_REG(GDTL), +// _DEF_I386_REG(IDTR), +// _DEF_I386_REG(IDTL), +// _DEF_I386_REG(LDTR), +// _DEF_I386_REG(TR) +//}; +//#undef _DEF_I386_REG +// +//const size_t Symbol::cntI386RegName = _countof(i386RegName); +// +////////////////////////////////////////////////////////////////////////////////// +// +//#define _DEF_AMD64_REG(x) Symbol::ValueNameEntry(CV_AMD64_##x, #x) +//const Symbol::ValueNameEntry Symbol::amd64RegName[] = { +// _DEF_AMD64_REG(AL), +// _DEF_AMD64_REG(CL), +// _DEF_AMD64_REG(DL), +// _DEF_AMD64_REG(BL), +// _DEF_AMD64_REG(AH), +// _DEF_AMD64_REG(CH), +// _DEF_AMD64_REG(DH), +// _DEF_AMD64_REG(BH), +// _DEF_AMD64_REG(AX), +// _DEF_AMD64_REG(CX), +// _DEF_AMD64_REG(DX), +// _DEF_AMD64_REG(BX), +// _DEF_AMD64_REG(SP), +// _DEF_AMD64_REG(BP), +// _DEF_AMD64_REG(SI), +// _DEF_AMD64_REG(DI), +// _DEF_AMD64_REG(EAX), +// _DEF_AMD64_REG(ECX), +// _DEF_AMD64_REG(EDX), +// _DEF_AMD64_REG(EBX), +// _DEF_AMD64_REG(ESP), +// _DEF_AMD64_REG(EBP), +// _DEF_AMD64_REG(ESI), +// _DEF_AMD64_REG(EDI), +// _DEF_AMD64_REG(ES), +// _DEF_AMD64_REG(CS), +// _DEF_AMD64_REG(SS), +// _DEF_AMD64_REG(DS), +// _DEF_AMD64_REG(FS), +// _DEF_AMD64_REG(GS), +// _DEF_AMD64_REG(FLAGS), +// _DEF_AMD64_REG(RIP), +// _DEF_AMD64_REG(EFLAGS), +// _DEF_AMD64_REG(CR0), +// _DEF_AMD64_REG(CR1), +// _DEF_AMD64_REG(CR2), +// _DEF_AMD64_REG(CR3), +// _DEF_AMD64_REG(CR4), +// _DEF_AMD64_REG(CR8), +// _DEF_AMD64_REG(DR0), +// _DEF_AMD64_REG(DR1), +// _DEF_AMD64_REG(DR2), +// _DEF_AMD64_REG(DR3), +// _DEF_AMD64_REG(DR4), +// _DEF_AMD64_REG(DR5), +// _DEF_AMD64_REG(DR6), +// _DEF_AMD64_REG(DR7), +// _DEF_AMD64_REG(DR8), +// _DEF_AMD64_REG(DR9), +// _DEF_AMD64_REG(DR10), +// _DEF_AMD64_REG(DR11), +// _DEF_AMD64_REG(DR12), +// _DEF_AMD64_REG(DR13), +// _DEF_AMD64_REG(DR14), +// _DEF_AMD64_REG(DR15), +// _DEF_AMD64_REG(GDTR), +// _DEF_AMD64_REG(GDTL), +// _DEF_AMD64_REG(IDTR), +// _DEF_AMD64_REG(IDTL), +// _DEF_AMD64_REG(LDTR), +// _DEF_AMD64_REG(TR), +// _DEF_AMD64_REG(ST0), +// _DEF_AMD64_REG(ST1), +// _DEF_AMD64_REG(ST2), +// _DEF_AMD64_REG(ST3), +// _DEF_AMD64_REG(ST4), +// _DEF_AMD64_REG(ST5), +// _DEF_AMD64_REG(ST6), +// _DEF_AMD64_REG(ST7), +// _DEF_AMD64_REG(CTRL), +// _DEF_AMD64_REG(STAT), +// _DEF_AMD64_REG(TAG), +// _DEF_AMD64_REG(FPIP), +// _DEF_AMD64_REG(FPCS), +// _DEF_AMD64_REG(FPDO), +// _DEF_AMD64_REG(FPDS), +// _DEF_AMD64_REG(ISEM), +// _DEF_AMD64_REG(FPEIP), +// _DEF_AMD64_REG(FPEDO), +// _DEF_AMD64_REG(MM0), +// _DEF_AMD64_REG(MM1), +// _DEF_AMD64_REG(MM2), +// _DEF_AMD64_REG(MM3), +// _DEF_AMD64_REG(MM4), +// _DEF_AMD64_REG(MM5), +// _DEF_AMD64_REG(MM6), +// _DEF_AMD64_REG(MM7), +// _DEF_AMD64_REG(XMM0), +// _DEF_AMD64_REG(XMM1), +// _DEF_AMD64_REG(XMM2), +// _DEF_AMD64_REG(XMM3), +// _DEF_AMD64_REG(XMM4), +// _DEF_AMD64_REG(XMM5), +// _DEF_AMD64_REG(XMM6), +// _DEF_AMD64_REG(XMM7), +// _DEF_AMD64_REG(XMM0_0), +// _DEF_AMD64_REG(XMM0_1), +// _DEF_AMD64_REG(XMM0_2), +// _DEF_AMD64_REG(XMM0_3), +// _DEF_AMD64_REG(XMM1_0), +// _DEF_AMD64_REG(XMM1_1), +// _DEF_AMD64_REG(XMM1_2), +// _DEF_AMD64_REG(XMM1_3), +// _DEF_AMD64_REG(XMM2_0), +// _DEF_AMD64_REG(XMM2_1), +// _DEF_AMD64_REG(XMM2_2), +// _DEF_AMD64_REG(XMM2_3), +// _DEF_AMD64_REG(XMM3_0), +// _DEF_AMD64_REG(XMM3_1), +// _DEF_AMD64_REG(XMM3_2), +// _DEF_AMD64_REG(XMM3_3), +// _DEF_AMD64_REG(XMM4_0), +// _DEF_AMD64_REG(XMM4_1), +// _DEF_AMD64_REG(XMM4_2), +// _DEF_AMD64_REG(XMM4_3), +// _DEF_AMD64_REG(XMM5_0), +// _DEF_AMD64_REG(XMM5_1), +// _DEF_AMD64_REG(XMM5_2), +// _DEF_AMD64_REG(XMM5_3), +// _DEF_AMD64_REG(XMM6_0), +// _DEF_AMD64_REG(XMM6_1), +// _DEF_AMD64_REG(XMM6_2), +// _DEF_AMD64_REG(XMM6_3), +// _DEF_AMD64_REG(XMM7_0), +// _DEF_AMD64_REG(XMM7_1), +// _DEF_AMD64_REG(XMM7_2), +// _DEF_AMD64_REG(XMM7_3), +// _DEF_AMD64_REG(XMM0L), +// _DEF_AMD64_REG(XMM1L), +// _DEF_AMD64_REG(XMM2L), +// _DEF_AMD64_REG(XMM3L), +// _DEF_AMD64_REG(XMM4L), +// _DEF_AMD64_REG(XMM5L), +// _DEF_AMD64_REG(XMM6L), +// _DEF_AMD64_REG(XMM7L), +// _DEF_AMD64_REG(XMM0H), +// _DEF_AMD64_REG(XMM1H), +// _DEF_AMD64_REG(XMM2H), +// _DEF_AMD64_REG(XMM3H), +// _DEF_AMD64_REG(XMM4H), +// _DEF_AMD64_REG(XMM5H), +// _DEF_AMD64_REG(XMM6H), +// _DEF_AMD64_REG(XMM7H), +// _DEF_AMD64_REG(MXCSR), +// _DEF_AMD64_REG(EMM0L), +// _DEF_AMD64_REG(EMM1L), +// _DEF_AMD64_REG(EMM2L), +// _DEF_AMD64_REG(EMM3L), +// _DEF_AMD64_REG(EMM4L), +// _DEF_AMD64_REG(EMM5L), +// _DEF_AMD64_REG(EMM6L), +// _DEF_AMD64_REG(EMM7L), +// _DEF_AMD64_REG(EMM0H), +// _DEF_AMD64_REG(EMM1H), +// _DEF_AMD64_REG(EMM2H), +// _DEF_AMD64_REG(EMM3H), +// _DEF_AMD64_REG(EMM4H), +// _DEF_AMD64_REG(EMM5H), +// _DEF_AMD64_REG(EMM6H), +// _DEF_AMD64_REG(EMM7H), +// _DEF_AMD64_REG(MM00), +// _DEF_AMD64_REG(MM01), +// _DEF_AMD64_REG(MM10), +// _DEF_AMD64_REG(MM11), +// _DEF_AMD64_REG(MM20), +// _DEF_AMD64_REG(MM21), +// _DEF_AMD64_REG(MM30), +// _DEF_AMD64_REG(MM31), +// _DEF_AMD64_REG(MM40), +// _DEF_AMD64_REG(MM41), +// _DEF_AMD64_REG(MM50), +// _DEF_AMD64_REG(MM51), +// _DEF_AMD64_REG(MM60), +// _DEF_AMD64_REG(MM61), +// _DEF_AMD64_REG(MM70), +// _DEF_AMD64_REG(MM71), +// _DEF_AMD64_REG(XMM8), +// _DEF_AMD64_REG(XMM9), +// _DEF_AMD64_REG(XMM10), +// _DEF_AMD64_REG(XMM11), +// _DEF_AMD64_REG(XMM12), +// _DEF_AMD64_REG(XMM13), +// _DEF_AMD64_REG(XMM14), +// _DEF_AMD64_REG(XMM15), +// _DEF_AMD64_REG(XMM8_0), +// _DEF_AMD64_REG(XMM8_1), +// _DEF_AMD64_REG(XMM8_2), +// _DEF_AMD64_REG(XMM8_3), +// _DEF_AMD64_REG(XMM9_0), +// _DEF_AMD64_REG(XMM9_1), +// _DEF_AMD64_REG(XMM9_2), +// _DEF_AMD64_REG(XMM9_3), +// _DEF_AMD64_REG(XMM10_0), +// _DEF_AMD64_REG(XMM10_1), +// _DEF_AMD64_REG(XMM10_2), +// _DEF_AMD64_REG(XMM10_3), +// _DEF_AMD64_REG(XMM11_0), +// _DEF_AMD64_REG(XMM11_1), +// _DEF_AMD64_REG(XMM11_2), +// _DEF_AMD64_REG(XMM11_3), +// _DEF_AMD64_REG(XMM12_0), +// _DEF_AMD64_REG(XMM12_1), +// _DEF_AMD64_REG(XMM12_2), +// _DEF_AMD64_REG(XMM12_3), +// _DEF_AMD64_REG(XMM13_0), +// _DEF_AMD64_REG(XMM13_1), +// _DEF_AMD64_REG(XMM13_2), +// _DEF_AMD64_REG(XMM13_3), +// _DEF_AMD64_REG(XMM14_0), +// _DEF_AMD64_REG(XMM14_1), +// _DEF_AMD64_REG(XMM14_2), +// _DEF_AMD64_REG(XMM14_3), +// _DEF_AMD64_REG(XMM15_0), +// _DEF_AMD64_REG(XMM15_1), +// _DEF_AMD64_REG(XMM15_2), +// _DEF_AMD64_REG(XMM15_3), +// _DEF_AMD64_REG(XMM8L), +// _DEF_AMD64_REG(XMM9L), +// _DEF_AMD64_REG(XMM10L), +// _DEF_AMD64_REG(XMM11L), +// _DEF_AMD64_REG(XMM12L), +// _DEF_AMD64_REG(XMM13L), +// _DEF_AMD64_REG(XMM14L), +// _DEF_AMD64_REG(XMM15L), +// _DEF_AMD64_REG(XMM8H), +// _DEF_AMD64_REG(XMM9H), +// _DEF_AMD64_REG(XMM10H), +// _DEF_AMD64_REG(XMM11H), +// _DEF_AMD64_REG(XMM12H), +// _DEF_AMD64_REG(XMM13H), +// _DEF_AMD64_REG(XMM14H), +// _DEF_AMD64_REG(XMM15H), +// _DEF_AMD64_REG(EMM8L), +// _DEF_AMD64_REG(EMM9L), +// _DEF_AMD64_REG(EMM10L), +// _DEF_AMD64_REG(EMM11L), +// _DEF_AMD64_REG(EMM12L), +// _DEF_AMD64_REG(EMM13L), +// _DEF_AMD64_REG(EMM14L), +// _DEF_AMD64_REG(EMM15L), +// _DEF_AMD64_REG(EMM8H), +// _DEF_AMD64_REG(EMM9H), +// _DEF_AMD64_REG(EMM10H), +// _DEF_AMD64_REG(EMM11H), +// _DEF_AMD64_REG(EMM12H), +// _DEF_AMD64_REG(EMM13H), +// _DEF_AMD64_REG(EMM14H), +// _DEF_AMD64_REG(EMM15H), +// _DEF_AMD64_REG(SIL), +// _DEF_AMD64_REG(DIL), +// _DEF_AMD64_REG(BPL), +// _DEF_AMD64_REG(SPL), +// _DEF_AMD64_REG(RAX), +// _DEF_AMD64_REG(RBX), +// _DEF_AMD64_REG(RCX), +// _DEF_AMD64_REG(RDX), +// _DEF_AMD64_REG(RSI), +// _DEF_AMD64_REG(RDI), +// _DEF_AMD64_REG(RBP), +// _DEF_AMD64_REG(RSP), +// _DEF_AMD64_REG(R8), +// _DEF_AMD64_REG(R9), +// _DEF_AMD64_REG(R10), +// _DEF_AMD64_REG(R11), +// _DEF_AMD64_REG(R12), +// _DEF_AMD64_REG(R13), +// _DEF_AMD64_REG(R14), +// _DEF_AMD64_REG(R15), +// _DEF_AMD64_REG(R8B), +// _DEF_AMD64_REG(R9B), +// _DEF_AMD64_REG(R10B), +// _DEF_AMD64_REG(R11B), +// _DEF_AMD64_REG(R12B), +// _DEF_AMD64_REG(R13B), +// _DEF_AMD64_REG(R14B), +// _DEF_AMD64_REG(R15B), +// _DEF_AMD64_REG(R8W), +// _DEF_AMD64_REG(R9W), +// _DEF_AMD64_REG(R10W), +// _DEF_AMD64_REG(R11W), +// _DEF_AMD64_REG(R12W), +// _DEF_AMD64_REG(R13W), +// _DEF_AMD64_REG(R14W), +// _DEF_AMD64_REG(R15W), +// _DEF_AMD64_REG(R8D), +// _DEF_AMD64_REG(R9D), +// _DEF_AMD64_REG(R10D), +// _DEF_AMD64_REG(R11D), +// _DEF_AMD64_REG(R12D), +// _DEF_AMD64_REG(R13D), +// _DEF_AMD64_REG(R14D), +// _DEF_AMD64_REG(R15D) +//}; +//#undef _DEF_AMD64_REG +// +//const size_t Symbol::cntAmd64RegName= _countof(amd64RegName); +// +////////////////////////////////////////////////////////////////////////////////// +// +//} diff --git a/pykd/dia/diawrapper.cpp b/pykd/dia/diawrapper.cpp index 585fe52..20ea6bf 100644 --- a/pykd/dia/diawrapper.cpp +++ b/pykd/dia/diawrapper.cpp @@ -5,7 +5,7 @@ namespace pykd { -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// const std::string DiaException::descPrefix("pyDia: "); @@ -72,6 +72,23 @@ SymbolPtr loadSymbolFile(const std::string &filePath) return SymbolPtr( new DiaSymbol( _globalScope ) ); } +////////////////////////////////////////////////////////////////////////////////// + +std::string getBasicTypeName( ULONG basicType ) +{ + for ( size_t i = 0; i < DiaSymbol::cntBasicTypeName; ++i ) + { + if ( basicType == DiaSymbol::basicTypeName[i].first ) + return std::string( DiaSymbol::basicTypeName[i].second ); + } + + std::stringstream sstr; + + sstr << "faild to find basic type with index %d" << basicType; + + throw DiaException( sstr.str() ); +} + //////////////////////////////////////////////////////////////////////////////// DiaSymbol::DiaSymbol(__inout DiaSymbolPtr &_symbol ) @@ -80,6 +97,127 @@ DiaSymbol::DiaSymbol(__inout DiaSymbolPtr &_symbol ) m_symbol->get_machineType(&m_machineType); } +////////////////////////////////////////////////////////////////////////////////// + +DiaSymbol::DiaSymbol( IDiaSymbol *_symbol ) +{ + m_symbol = _symbol; + m_symbol->get_machineType(&m_machineType); +} + +////////////////////////////////////////////////////////////////////////////////// + +SymbolPtrList DiaSymbol::findChildren( + ULONG symTag, + const std::string &name, + bool caseSensitive + ) +{ + DiaEnumSymbolsPtr symbols; + HRESULT hres; + + if ( name.empty() ) + { + hres = m_symbol->findChildren( + static_cast(symTag), + NULL, + caseSensitive ? nsCaseSensitive : nsCaseInsensitive, + &symbols); + + } + else + { + hres = m_symbol->findChildren( + static_cast(symTag), + toWStr(name), + caseSensitive ? nsCaseSensitive : nsCaseInsensitive, + &symbols); + } + + if (S_OK != hres) + throw DiaException("Call IDiaSymbol::findChildren", hres); + + SymbolPtrList childList; + + DiaSymbolPtr child; + ULONG celt; + while ( SUCCEEDED(symbols->Next(1, &child, &celt)) && (celt == 1) ) + { + childList.push_back( SymbolPtr( new DiaSymbol(child) ) ); + child = NULL; + } + + return childList; +} + +////////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getBaseType() +{ + return callSymbol(get_baseType); +} + +////////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getBitPosition() +{ + return callSymbol(get_bitPosition); +} + +////////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getChildCount(ULONG symTag) +{ + DiaEnumSymbolsPtr symbols; + HRESULT hres = + m_symbol->findChildren( + static_cast(symTag), + NULL, + nsCaseSensitive, + &symbols); + if (S_OK != hres) + throw DiaException("Call IDiaSymbol::findChildren", hres); + + LONG count; + hres = symbols->get_Count(&count); + if (S_OK != hres) + throw DiaException("Call IDiaEnumSymbols::get_Count", hres); + + return count; +} + +//////////////////////////////////////////////////////////////////////////////// + +SymbolPtr DiaSymbol::getChildByIndex(ULONG symTag, ULONG _index ) +{ + DiaEnumSymbolsPtr symbols; + HRESULT hres = + m_symbol->findChildren( + static_cast(symTag), + NULL, + nsCaseSensitive, + &symbols); + if (S_OK != hres) + throw DiaException("Call IDiaSymbol::findChildren", hres); + + LONG count; + hres = symbols->get_Count(&count); + if (S_OK != hres) + throw DiaException("Call IDiaEnumSymbols::get_Count", hres); + + if (LONG(_index) >= count) + { + throw PyException( PyExc_IndexError, "Index out of range"); + } + + DiaSymbolPtr child; + hres = symbols->Item(_index, &child); + if (S_OK != hres) + throw DiaException("Call IDiaEnumSymbols::Item", hres); + + return SymbolPtr( new DiaSymbol(child) ); +} + //////////////////////////////////////////////////////////////////////////////// SymbolPtr DiaSymbol::getChildByName(const std::string &_name) @@ -87,10 +225,11 @@ SymbolPtr DiaSymbol::getChildByName(const std::string &_name) DiaEnumSymbolsPtr symbols; HRESULT hres = m_symbol->findChildren( - SymTagNull, + ::SymTagNull, toWStr(_name), nsCaseSensitive, &symbols); + if (S_OK != hres) throw DiaException("Call IDiaSymbol::findChildren", hres); @@ -113,6 +252,41 @@ SymbolPtr DiaSymbol::getChildByName(const std::string &_name) return SymbolPtr( new DiaSymbol(child) ); } +////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getCount() +{ + return callSymbol(get_count); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getDataKind() +{ + return callSymbol(get_dataKind); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getLocType() +{ + return callSymbol(get_locationType); +} + +////////////////////////////////////////////////////////////////////////////// + +std::string DiaSymbol::getName() +{ + autoBstr retValue( callSymbol(get_name) ); + return retValue.asStr(); +} +//////////////////////////////////////////////////////////////////////////////// + +LONG DiaSymbol::getOffset() +{ + return callSymbol(get_offset); +} + //////////////////////////////////////////////////////////////////////////////// ULONG DiaSymbol::getRva() @@ -122,6 +296,80 @@ ULONG DiaSymbol::getRva() //////////////////////////////////////////////////////////////////////////////// +ULONGLONG DiaSymbol::getSize() +{ + return callSymbol(get_length); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getSymTag() +{ + return callSymbol(get_symTag); +} + +//////////////////////////////////////////////////////////////////////////////// + +SymbolPtr DiaSymbol::getType() +{ + return SymbolPtr( new DiaSymbol( callSymbol(get_type) ) ); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONGLONG DiaSymbol::getVa() +{ + return callSymbol(get_virtualAddress); +} + +//////////////////////////////////////////////////////////////////////////////// + +void DiaSymbol::getValue( VARIANT &vtValue) +{ + HRESULT hres = m_symbol->get_value(&vtValue); + if (S_OK != hres) + throw DiaException("Call IDiaSymbol::get_value", hres); +} + +////////////////////////////////////////////////////////////////////////////// + +int DiaSymbol::getVirtualBasePointerOffset() +{ + return callSymbol(get_virtualBasePointerOffset); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getVirtualBaseDispIndex() +{ + return callSymbol(get_virtualBaseDispIndex); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONG DiaSymbol::getVirtualBaseDispSize() +{ + SymbolPtr baseTableType = SymbolPtr( new DiaSymbol( callSymbol(get_virtualBaseTableType) ) ); + + return (ULONG)baseTableType->getType()->getSize(); +} + +////////////////////////////////////////////////////////////////////////////// + +bool DiaSymbol::isVirtualBaseClass() +{ + return !!callSymbol(get_virtualBaseClass); +} + +////////////////////////////////////////////////////////////////////////////// + +//bool DiaSymbol::isIndirectVirtualBaseClass() +//{ +// return !!callSymbol(get_indirectVirtualBaseClass); +//} + +////////////////////////////////////////////////////////////////////////////// + }; // pykd nemaspace end diff --git a/pykd/dia/diawrapper.h b/pykd/dia/diawrapper.h index fd65d4e..aaac6a5 100644 --- a/pykd/dia/diawrapper.h +++ b/pykd/dia/diawrapper.h @@ -4,6 +4,8 @@ #include "symengine.h" #include "dbgexcept.h" +#include + namespace pykd { ////////////////////////////////////////////////////////////////////////////// @@ -46,21 +48,19 @@ private: class DiaSymbol : public Symbol { public: - DiaSymbol(__inout DiaSymbolPtr &_symbol ); + DiaSymbol( DiaSymbolPtr &_symbol ); + + DiaSymbol( IDiaSymbol *_symbol ); SymbolPtr getChildByName(const std::string &_name); ULONG getRva(); - - - - - //SymbolPtrList findChildrenImpl( - // ULONG symTag, - // const std::string &name = "", - // DWORD nameCmpFlags = 0 - //); + SymbolPtrList findChildren( + ULONG symTag, + const std::string &name = "", + bool caseSensitive = FALSE + ); //python::list findChildrenEx( // ULONG symTag, @@ -78,67 +78,67 @@ public: // return toPyList( findChildrenImpl(SymTagNull, name, nsfCaseSensitive) ); //} - //ULONGLONG getSize(); + ULONGLONG getSize(); + + std::string getName(); - //std::string getName(); //std::string getUndecoratedName(); - //SymbolPtr getType(); + SymbolPtr getType(); //SymbolPtr getIndexType(); - //ULONG getSymTag(); + ULONG getSymTag(); //ULONG getRva(); - //ULONGLONG getVa(); + ULONGLONG getVa(); - //ULONG getLocType(); + ULONG getLocType(); - //LONG getOffset(); + LONG getOffset(); - //ULONG getCount(); + ULONG getCount(); //static void getValueImpl(IDiaSymbol *_symbol, VARIANT &vtValue); //python::object getValue(); - //void getValue( VARIANT &vtValue); + + void getValue( VARIANT &vtValue); //bool isBasicType(); - //bool isVirtualBaseClass(); + bool isVirtualBaseClass(); //bool isIndirectVirtualBaseClass(); - //ULONG getBaseType(); + ULONG getBaseType(); - //ULONG getBitPosition(); + ULONG getBitPosition(); //ULONG getIndexId(); //ULONG getUdtKind(); - //ULONG getDataKind(); + ULONG getDataKind(); //ULONG getRegisterId(); - //ULONG getMachineType() const { - // return m_machineType; - //} + ULONG getMachineType() { + return m_machineType; + } //SymbolPtr getChildByName(const std::string &_name); - //template - //ULONG getChildCount(); + ULONG getChildCount( ULONG symTag ); - //ULONG getChildCount() { - // return getChildCount(); - //} + ULONG getChildCount() { + return getChildCount(SymTagNull); + } - //template - //SymbolPtr getChildByIndex(ULONG _index ); + SymbolPtr getChildByIndex(ULONG symTag, ULONG _index ); - //SymbolPtr getChildByIndex(ULONG _index ) { - // return getChildByIndex( _index ); - //} + SymbolPtr getChildByIndex(ULONG _index ) { + return getChildByIndex( SymTagNull, _index ); + } // //bool isConstant(); @@ -146,16 +146,16 @@ public: //bool eq(Symbol &rhs); - //int getVirtualBasePointerOffset(); + int getVirtualBasePointerOffset(); - //ULONG getVirtualBaseDispIndex(); + ULONG getVirtualBaseDispIndex(); - //ULONG getVirtualBaseDispSize(); + ULONG getVirtualBaseDispSize(); //ULONG getSection(); public: - //typedef std::pair ValueNameEntry; + typedef std::pair ValueNameEntry; //static const ValueNameEntry dataKindName[DataIsConstant + 1]; @@ -163,8 +163,8 @@ public: //static const ValueNameEntry locTypeName[LocTypeMax]; - //static const ValueNameEntry basicTypeName[]; - //static const size_t cntBasicTypeName; + static const ValueNameEntry basicTypeName[]; + static const size_t cntBasicTypeName; //static const ValueNameEntry udtKindName[]; //static const size_t cntUdtKindName; @@ -175,7 +175,7 @@ public: //static const ValueNameEntry amd64RegName[]; //static const size_t cntAmd64RegName; - //static std::string getBasicTypeName( ULONG basicType ); + static std::string getBasicTypeName( ULONG basicType ); protected: diff --git a/pykd/diadata.cpp b/pykd/diadata.cpp deleted file mode 100644 index aa345d9..0000000 --- a/pykd/diadata.cpp +++ /dev/null @@ -1,509 +0,0 @@ -#include "stdafx.h" - -#include "diawrapper.h" -#include "utils.h" - -namespace pyDia { - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_SYM_TAG_VAL(x) Symbol::ValueNameEntry(SymTag##x, #x) -const Symbol::ValueNameEntry Symbol::symTagName[SymTagMax] = { - _DEF_SYM_TAG_VAL(Null), - _DEF_SYM_TAG_VAL(Exe), - _DEF_SYM_TAG_VAL(Compiland), - _DEF_SYM_TAG_VAL(CompilandDetails), - _DEF_SYM_TAG_VAL(CompilandEnv), - _DEF_SYM_TAG_VAL(Function), - _DEF_SYM_TAG_VAL(Block), - _DEF_SYM_TAG_VAL(Data), - _DEF_SYM_TAG_VAL(Annotation), - _DEF_SYM_TAG_VAL(Label), - _DEF_SYM_TAG_VAL(PublicSymbol), - _DEF_SYM_TAG_VAL(UDT), - _DEF_SYM_TAG_VAL(Enum), - _DEF_SYM_TAG_VAL(FunctionType), - _DEF_SYM_TAG_VAL(PointerType), - _DEF_SYM_TAG_VAL(ArrayType), - _DEF_SYM_TAG_VAL(BaseType), - _DEF_SYM_TAG_VAL(Typedef), - _DEF_SYM_TAG_VAL(BaseClass), - _DEF_SYM_TAG_VAL(Friend), - _DEF_SYM_TAG_VAL(FunctionArgType), - _DEF_SYM_TAG_VAL(FuncDebugStart), - _DEF_SYM_TAG_VAL(FuncDebugEnd), - _DEF_SYM_TAG_VAL(UsingNamespace), - _DEF_SYM_TAG_VAL(VTableShape), - _DEF_SYM_TAG_VAL(VTable), - _DEF_SYM_TAG_VAL(Custom), - _DEF_SYM_TAG_VAL(Thunk), - _DEF_SYM_TAG_VAL(CustomType), - _DEF_SYM_TAG_VAL(ManagedType), - _DEF_SYM_TAG_VAL(Dimension) -}; -#undef _DEF_SYM_TAG_VAL - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_DATA_KIND_VAL(x) Symbol::ValueNameEntry(DataIs##x, #x) -const Symbol::ValueNameEntry Symbol::dataKindName[DataIsConstant + 1] = { - _DEF_DATA_KIND_VAL(Unknown), - _DEF_DATA_KIND_VAL(Local), - _DEF_DATA_KIND_VAL(StaticLocal), - _DEF_DATA_KIND_VAL(Param), - _DEF_DATA_KIND_VAL(ObjectPtr), - _DEF_DATA_KIND_VAL(FileStatic), - _DEF_DATA_KIND_VAL(Global), - _DEF_DATA_KIND_VAL(Member), - _DEF_DATA_KIND_VAL(StaticMember), - _DEF_DATA_KIND_VAL(Constant) -}; -#undef _DEF_DATA_KIND_VAL - - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_LOC_TYPE(x) Symbol::ValueNameEntry(LocIs##x, #x) -const Symbol::ValueNameEntry Symbol::locTypeName[LocTypeMax] = { - _DEF_LOC_TYPE(Null), - _DEF_LOC_TYPE(Static), - _DEF_LOC_TYPE(TLS), - _DEF_LOC_TYPE(RegRel), - _DEF_LOC_TYPE(ThisRel), - _DEF_LOC_TYPE(Enregistered), - _DEF_LOC_TYPE(BitField), - _DEF_LOC_TYPE(Slot), - _DEF_LOC_TYPE(IlRel), - Symbol::ValueNameEntry(LocInMetaData, "InMetaData"), - _DEF_LOC_TYPE(Constant) -}; -#undef _DEF_LOC_TYPE - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_BASIC_TYPE(x) Symbol::ValueNameEntry(bt##x, #x) -const Symbol::ValueNameEntry Symbol::basicTypeName[] = { - _DEF_BASIC_TYPE(NoType), - _DEF_BASIC_TYPE(Void), - _DEF_BASIC_TYPE(Char), - _DEF_BASIC_TYPE(WChar), - _DEF_BASIC_TYPE(Int), - _DEF_BASIC_TYPE(UInt), - _DEF_BASIC_TYPE(Float), - _DEF_BASIC_TYPE(BCD), - _DEF_BASIC_TYPE(Bool), - _DEF_BASIC_TYPE(Long), - _DEF_BASIC_TYPE(ULong), - _DEF_BASIC_TYPE(Currency), - _DEF_BASIC_TYPE(Date), - _DEF_BASIC_TYPE(Variant), - _DEF_BASIC_TYPE(Complex), - _DEF_BASIC_TYPE(Bit), - _DEF_BASIC_TYPE(BSTR), - _DEF_BASIC_TYPE(Hresult) -}; -#undef _DEF_BASIC_TYPE - -const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName); - -std::string Symbol::getBasicTypeName( ULONG basicType ) -{ - for ( size_t i = 0; i < Symbol::cntBasicTypeName; ++i ) - { - if ( basicType == Symbol::basicTypeName[i].first ) - return std::string( Symbol::basicTypeName[i].second ); - } - - std::stringstream sstr; - - sstr << "faild to find basic type with index %d" << basicType; - - throw Exception( sstr.str() ); -} - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_UDT_KIND(x) Symbol::ValueNameEntry(Udt##x, #x) -const Symbol::ValueNameEntry Symbol::udtKindName[] = { - _DEF_UDT_KIND(Struct), - _DEF_UDT_KIND(Class), - _DEF_UDT_KIND(Union) -}; -#undef _DEF_UDT_KIND - -const size_t Symbol::cntUdtKindName = _countof(udtKindName); - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_I386_REG(x) Symbol::ValueNameEntry(CV_REG_##x, #x) -const Symbol::ValueNameEntry Symbol::i386RegName[] = { - _DEF_I386_REG(AL), - _DEF_I386_REG(CL), - _DEF_I386_REG(DL), - _DEF_I386_REG(BL), - _DEF_I386_REG(AH), - _DEF_I386_REG(CH), - _DEF_I386_REG(DH), - _DEF_I386_REG(BH), - _DEF_I386_REG(AX), - _DEF_I386_REG(CX), - _DEF_I386_REG(DX), - _DEF_I386_REG(BX), - _DEF_I386_REG(SP), - _DEF_I386_REG(BP), - _DEF_I386_REG(SI), - _DEF_I386_REG(DI), - _DEF_I386_REG(EAX), - _DEF_I386_REG(ECX), - _DEF_I386_REG(EDX), - _DEF_I386_REG(EBX), - _DEF_I386_REG(ESP), - _DEF_I386_REG(EBP), - _DEF_I386_REG(ESI), - _DEF_I386_REG(EDI), - _DEF_I386_REG(ES), - _DEF_I386_REG(CS), - _DEF_I386_REG(SS), - _DEF_I386_REG(DS), - _DEF_I386_REG(FS), - _DEF_I386_REG(GS), - _DEF_I386_REG(IP), - _DEF_I386_REG(FLAGS ), - _DEF_I386_REG(EIP), - _DEF_I386_REG(EFLAGS), - _DEF_I386_REG(TEMP), - _DEF_I386_REG(TEMPH), - _DEF_I386_REG(QUOTE), - _DEF_I386_REG(PCDR3), - _DEF_I386_REG(PCDR4), - _DEF_I386_REG(PCDR5), - _DEF_I386_REG(PCDR6), - _DEF_I386_REG(PCDR7), - _DEF_I386_REG(CR0), - _DEF_I386_REG(CR1), - _DEF_I386_REG(CR2), - _DEF_I386_REG(CR3), - _DEF_I386_REG(CR4), - _DEF_I386_REG(DR0), - _DEF_I386_REG(DR1), - _DEF_I386_REG(DR2), - _DEF_I386_REG(DR3), - _DEF_I386_REG(DR4), - _DEF_I386_REG(DR5), - _DEF_I386_REG(DR6), - _DEF_I386_REG(DR7), - _DEF_I386_REG(GDTR), - _DEF_I386_REG(GDTL), - _DEF_I386_REG(IDTR), - _DEF_I386_REG(IDTL), - _DEF_I386_REG(LDTR), - _DEF_I386_REG(TR) -}; -#undef _DEF_I386_REG - -const size_t Symbol::cntI386RegName = _countof(i386RegName); - -//////////////////////////////////////////////////////////////////////////////// - -#define _DEF_AMD64_REG(x) Symbol::ValueNameEntry(CV_AMD64_##x, #x) -const Symbol::ValueNameEntry Symbol::amd64RegName[] = { - _DEF_AMD64_REG(AL), - _DEF_AMD64_REG(CL), - _DEF_AMD64_REG(DL), - _DEF_AMD64_REG(BL), - _DEF_AMD64_REG(AH), - _DEF_AMD64_REG(CH), - _DEF_AMD64_REG(DH), - _DEF_AMD64_REG(BH), - _DEF_AMD64_REG(AX), - _DEF_AMD64_REG(CX), - _DEF_AMD64_REG(DX), - _DEF_AMD64_REG(BX), - _DEF_AMD64_REG(SP), - _DEF_AMD64_REG(BP), - _DEF_AMD64_REG(SI), - _DEF_AMD64_REG(DI), - _DEF_AMD64_REG(EAX), - _DEF_AMD64_REG(ECX), - _DEF_AMD64_REG(EDX), - _DEF_AMD64_REG(EBX), - _DEF_AMD64_REG(ESP), - _DEF_AMD64_REG(EBP), - _DEF_AMD64_REG(ESI), - _DEF_AMD64_REG(EDI), - _DEF_AMD64_REG(ES), - _DEF_AMD64_REG(CS), - _DEF_AMD64_REG(SS), - _DEF_AMD64_REG(DS), - _DEF_AMD64_REG(FS), - _DEF_AMD64_REG(GS), - _DEF_AMD64_REG(FLAGS), - _DEF_AMD64_REG(RIP), - _DEF_AMD64_REG(EFLAGS), - _DEF_AMD64_REG(CR0), - _DEF_AMD64_REG(CR1), - _DEF_AMD64_REG(CR2), - _DEF_AMD64_REG(CR3), - _DEF_AMD64_REG(CR4), - _DEF_AMD64_REG(CR8), - _DEF_AMD64_REG(DR0), - _DEF_AMD64_REG(DR1), - _DEF_AMD64_REG(DR2), - _DEF_AMD64_REG(DR3), - _DEF_AMD64_REG(DR4), - _DEF_AMD64_REG(DR5), - _DEF_AMD64_REG(DR6), - _DEF_AMD64_REG(DR7), - _DEF_AMD64_REG(DR8), - _DEF_AMD64_REG(DR9), - _DEF_AMD64_REG(DR10), - _DEF_AMD64_REG(DR11), - _DEF_AMD64_REG(DR12), - _DEF_AMD64_REG(DR13), - _DEF_AMD64_REG(DR14), - _DEF_AMD64_REG(DR15), - _DEF_AMD64_REG(GDTR), - _DEF_AMD64_REG(GDTL), - _DEF_AMD64_REG(IDTR), - _DEF_AMD64_REG(IDTL), - _DEF_AMD64_REG(LDTR), - _DEF_AMD64_REG(TR), - _DEF_AMD64_REG(ST0), - _DEF_AMD64_REG(ST1), - _DEF_AMD64_REG(ST2), - _DEF_AMD64_REG(ST3), - _DEF_AMD64_REG(ST4), - _DEF_AMD64_REG(ST5), - _DEF_AMD64_REG(ST6), - _DEF_AMD64_REG(ST7), - _DEF_AMD64_REG(CTRL), - _DEF_AMD64_REG(STAT), - _DEF_AMD64_REG(TAG), - _DEF_AMD64_REG(FPIP), - _DEF_AMD64_REG(FPCS), - _DEF_AMD64_REG(FPDO), - _DEF_AMD64_REG(FPDS), - _DEF_AMD64_REG(ISEM), - _DEF_AMD64_REG(FPEIP), - _DEF_AMD64_REG(FPEDO), - _DEF_AMD64_REG(MM0), - _DEF_AMD64_REG(MM1), - _DEF_AMD64_REG(MM2), - _DEF_AMD64_REG(MM3), - _DEF_AMD64_REG(MM4), - _DEF_AMD64_REG(MM5), - _DEF_AMD64_REG(MM6), - _DEF_AMD64_REG(MM7), - _DEF_AMD64_REG(XMM0), - _DEF_AMD64_REG(XMM1), - _DEF_AMD64_REG(XMM2), - _DEF_AMD64_REG(XMM3), - _DEF_AMD64_REG(XMM4), - _DEF_AMD64_REG(XMM5), - _DEF_AMD64_REG(XMM6), - _DEF_AMD64_REG(XMM7), - _DEF_AMD64_REG(XMM0_0), - _DEF_AMD64_REG(XMM0_1), - _DEF_AMD64_REG(XMM0_2), - _DEF_AMD64_REG(XMM0_3), - _DEF_AMD64_REG(XMM1_0), - _DEF_AMD64_REG(XMM1_1), - _DEF_AMD64_REG(XMM1_2), - _DEF_AMD64_REG(XMM1_3), - _DEF_AMD64_REG(XMM2_0), - _DEF_AMD64_REG(XMM2_1), - _DEF_AMD64_REG(XMM2_2), - _DEF_AMD64_REG(XMM2_3), - _DEF_AMD64_REG(XMM3_0), - _DEF_AMD64_REG(XMM3_1), - _DEF_AMD64_REG(XMM3_2), - _DEF_AMD64_REG(XMM3_3), - _DEF_AMD64_REG(XMM4_0), - _DEF_AMD64_REG(XMM4_1), - _DEF_AMD64_REG(XMM4_2), - _DEF_AMD64_REG(XMM4_3), - _DEF_AMD64_REG(XMM5_0), - _DEF_AMD64_REG(XMM5_1), - _DEF_AMD64_REG(XMM5_2), - _DEF_AMD64_REG(XMM5_3), - _DEF_AMD64_REG(XMM6_0), - _DEF_AMD64_REG(XMM6_1), - _DEF_AMD64_REG(XMM6_2), - _DEF_AMD64_REG(XMM6_3), - _DEF_AMD64_REG(XMM7_0), - _DEF_AMD64_REG(XMM7_1), - _DEF_AMD64_REG(XMM7_2), - _DEF_AMD64_REG(XMM7_3), - _DEF_AMD64_REG(XMM0L), - _DEF_AMD64_REG(XMM1L), - _DEF_AMD64_REG(XMM2L), - _DEF_AMD64_REG(XMM3L), - _DEF_AMD64_REG(XMM4L), - _DEF_AMD64_REG(XMM5L), - _DEF_AMD64_REG(XMM6L), - _DEF_AMD64_REG(XMM7L), - _DEF_AMD64_REG(XMM0H), - _DEF_AMD64_REG(XMM1H), - _DEF_AMD64_REG(XMM2H), - _DEF_AMD64_REG(XMM3H), - _DEF_AMD64_REG(XMM4H), - _DEF_AMD64_REG(XMM5H), - _DEF_AMD64_REG(XMM6H), - _DEF_AMD64_REG(XMM7H), - _DEF_AMD64_REG(MXCSR), - _DEF_AMD64_REG(EMM0L), - _DEF_AMD64_REG(EMM1L), - _DEF_AMD64_REG(EMM2L), - _DEF_AMD64_REG(EMM3L), - _DEF_AMD64_REG(EMM4L), - _DEF_AMD64_REG(EMM5L), - _DEF_AMD64_REG(EMM6L), - _DEF_AMD64_REG(EMM7L), - _DEF_AMD64_REG(EMM0H), - _DEF_AMD64_REG(EMM1H), - _DEF_AMD64_REG(EMM2H), - _DEF_AMD64_REG(EMM3H), - _DEF_AMD64_REG(EMM4H), - _DEF_AMD64_REG(EMM5H), - _DEF_AMD64_REG(EMM6H), - _DEF_AMD64_REG(EMM7H), - _DEF_AMD64_REG(MM00), - _DEF_AMD64_REG(MM01), - _DEF_AMD64_REG(MM10), - _DEF_AMD64_REG(MM11), - _DEF_AMD64_REG(MM20), - _DEF_AMD64_REG(MM21), - _DEF_AMD64_REG(MM30), - _DEF_AMD64_REG(MM31), - _DEF_AMD64_REG(MM40), - _DEF_AMD64_REG(MM41), - _DEF_AMD64_REG(MM50), - _DEF_AMD64_REG(MM51), - _DEF_AMD64_REG(MM60), - _DEF_AMD64_REG(MM61), - _DEF_AMD64_REG(MM70), - _DEF_AMD64_REG(MM71), - _DEF_AMD64_REG(XMM8), - _DEF_AMD64_REG(XMM9), - _DEF_AMD64_REG(XMM10), - _DEF_AMD64_REG(XMM11), - _DEF_AMD64_REG(XMM12), - _DEF_AMD64_REG(XMM13), - _DEF_AMD64_REG(XMM14), - _DEF_AMD64_REG(XMM15), - _DEF_AMD64_REG(XMM8_0), - _DEF_AMD64_REG(XMM8_1), - _DEF_AMD64_REG(XMM8_2), - _DEF_AMD64_REG(XMM8_3), - _DEF_AMD64_REG(XMM9_0), - _DEF_AMD64_REG(XMM9_1), - _DEF_AMD64_REG(XMM9_2), - _DEF_AMD64_REG(XMM9_3), - _DEF_AMD64_REG(XMM10_0), - _DEF_AMD64_REG(XMM10_1), - _DEF_AMD64_REG(XMM10_2), - _DEF_AMD64_REG(XMM10_3), - _DEF_AMD64_REG(XMM11_0), - _DEF_AMD64_REG(XMM11_1), - _DEF_AMD64_REG(XMM11_2), - _DEF_AMD64_REG(XMM11_3), - _DEF_AMD64_REG(XMM12_0), - _DEF_AMD64_REG(XMM12_1), - _DEF_AMD64_REG(XMM12_2), - _DEF_AMD64_REG(XMM12_3), - _DEF_AMD64_REG(XMM13_0), - _DEF_AMD64_REG(XMM13_1), - _DEF_AMD64_REG(XMM13_2), - _DEF_AMD64_REG(XMM13_3), - _DEF_AMD64_REG(XMM14_0), - _DEF_AMD64_REG(XMM14_1), - _DEF_AMD64_REG(XMM14_2), - _DEF_AMD64_REG(XMM14_3), - _DEF_AMD64_REG(XMM15_0), - _DEF_AMD64_REG(XMM15_1), - _DEF_AMD64_REG(XMM15_2), - _DEF_AMD64_REG(XMM15_3), - _DEF_AMD64_REG(XMM8L), - _DEF_AMD64_REG(XMM9L), - _DEF_AMD64_REG(XMM10L), - _DEF_AMD64_REG(XMM11L), - _DEF_AMD64_REG(XMM12L), - _DEF_AMD64_REG(XMM13L), - _DEF_AMD64_REG(XMM14L), - _DEF_AMD64_REG(XMM15L), - _DEF_AMD64_REG(XMM8H), - _DEF_AMD64_REG(XMM9H), - _DEF_AMD64_REG(XMM10H), - _DEF_AMD64_REG(XMM11H), - _DEF_AMD64_REG(XMM12H), - _DEF_AMD64_REG(XMM13H), - _DEF_AMD64_REG(XMM14H), - _DEF_AMD64_REG(XMM15H), - _DEF_AMD64_REG(EMM8L), - _DEF_AMD64_REG(EMM9L), - _DEF_AMD64_REG(EMM10L), - _DEF_AMD64_REG(EMM11L), - _DEF_AMD64_REG(EMM12L), - _DEF_AMD64_REG(EMM13L), - _DEF_AMD64_REG(EMM14L), - _DEF_AMD64_REG(EMM15L), - _DEF_AMD64_REG(EMM8H), - _DEF_AMD64_REG(EMM9H), - _DEF_AMD64_REG(EMM10H), - _DEF_AMD64_REG(EMM11H), - _DEF_AMD64_REG(EMM12H), - _DEF_AMD64_REG(EMM13H), - _DEF_AMD64_REG(EMM14H), - _DEF_AMD64_REG(EMM15H), - _DEF_AMD64_REG(SIL), - _DEF_AMD64_REG(DIL), - _DEF_AMD64_REG(BPL), - _DEF_AMD64_REG(SPL), - _DEF_AMD64_REG(RAX), - _DEF_AMD64_REG(RBX), - _DEF_AMD64_REG(RCX), - _DEF_AMD64_REG(RDX), - _DEF_AMD64_REG(RSI), - _DEF_AMD64_REG(RDI), - _DEF_AMD64_REG(RBP), - _DEF_AMD64_REG(RSP), - _DEF_AMD64_REG(R8), - _DEF_AMD64_REG(R9), - _DEF_AMD64_REG(R10), - _DEF_AMD64_REG(R11), - _DEF_AMD64_REG(R12), - _DEF_AMD64_REG(R13), - _DEF_AMD64_REG(R14), - _DEF_AMD64_REG(R15), - _DEF_AMD64_REG(R8B), - _DEF_AMD64_REG(R9B), - _DEF_AMD64_REG(R10B), - _DEF_AMD64_REG(R11B), - _DEF_AMD64_REG(R12B), - _DEF_AMD64_REG(R13B), - _DEF_AMD64_REG(R14B), - _DEF_AMD64_REG(R15B), - _DEF_AMD64_REG(R8W), - _DEF_AMD64_REG(R9W), - _DEF_AMD64_REG(R10W), - _DEF_AMD64_REG(R11W), - _DEF_AMD64_REG(R12W), - _DEF_AMD64_REG(R13W), - _DEF_AMD64_REG(R14W), - _DEF_AMD64_REG(R15W), - _DEF_AMD64_REG(R8D), - _DEF_AMD64_REG(R9D), - _DEF_AMD64_REG(R10D), - _DEF_AMD64_REG(R11D), - _DEF_AMD64_REG(R12D), - _DEF_AMD64_REG(R13D), - _DEF_AMD64_REG(R14D), - _DEF_AMD64_REG(R15D) -}; -#undef _DEF_AMD64_REG - -const size_t Symbol::cntAmd64RegName= _countof(amd64RegName); - -//////////////////////////////////////////////////////////////////////////////// - -} diff --git a/pykd/module.cpp b/pykd/module.cpp index e97d78f..7d51f90 100644 --- a/pykd/module.cpp +++ b/pykd/module.cpp @@ -80,6 +80,27 @@ ULONG Module::getRvaByName(const std::string &symName) ///////////////////////////////////////////////////////////////////////////////////// +ULONG64 +Module::getSymbolSize( const std::string &symName ) +{ + try { + + SymbolPtr &symScope = getSymScope(); + + SymbolPtr child = symScope->getChildByName( symName ); + + if ( child->getSymTag() == SymTagData ) + return child->getSize(); + + } catch( const SymbolException& ) + { + } + + return getTypeByName(symName)->getSize(); +} + +///////////////////////////////////////////////////////////////////////////////////// + std::string Module::print() { std::stringstream sstr; diff --git a/pykd/module.h b/pykd/module.h index 9b65632..c7d91d0 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -2,6 +2,7 @@ #include "intbase.h" #include "symengine.h" +#include "typeinfo.h" namespace pykd { @@ -73,6 +74,12 @@ public: return m_timeDataStamp; } + TypeInfoPtr getTypeByName( const std::string &typeName ) { + return TypeInfo::getTypeInfo( boost::static_pointer_cast( getSymScope() ), typeName); + } + + ULONG64 getSymbolSize( const std::string &symName ); + std::string print(); private: diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 3264249..89d0f05 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -409,6 +409,14 @@ /> + + + + + + + + diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index e02df50..3c907a0 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -13,6 +13,7 @@ #include "intbase.h" #include "dbgexcept.h" #include "dbgmem.h" +#include "typeinfo.h" using namespace pykd; @@ -56,7 +57,12 @@ BOOST_PYTHON_MODULE( pykd ) python::def( "go", &debugGo, "Go debugging" ); + // system properties + python::def( "ptrSize", &ptrSize, + "Return effective pointer size" ); + // Manage target memory access + python::def( "isValid", &isVaValid, "Check if the virtual address is valid" ); python::def( "compareMemory", &compareMemory, compareMemory_( python::args( "offset1", "offset2", "length", "phyAddr" ), @@ -118,6 +124,9 @@ BOOST_PYTHON_MODULE( pykd ) python::def( "loadPtrs", &loadPtrArray, "Read the block of the target's memory and return it as a list of pointers" ); + // typed and vaiables + python::def( "sizeof", &TypeInfo::getSymbolSize, + "Return a size of the type or variable" ); python::class_( "intBase", "intBase", python::no_init ) .def( python::init() ) @@ -186,8 +195,8 @@ BOOST_PYTHON_MODULE( pykd ) "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("type", &Module::getTypeByName, + "Return typeInfo class by type name" ) //.def("typedVar", &Module::getTypedVarByAddr, // "Return a typedVar class instance" ) //.def("typedVar",&Module::getTypedVarByName, @@ -218,12 +227,29 @@ BOOST_PYTHON_MODULE( pykd ) "Return address of the symbol" ) .def( "__str__", &Module::print ); + python::class_, 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 ); + + pykd::exception( "BaseException", "Pykd base exception class" ); pykd::exception( "MemoryException", "Target memory access exception class" ); //pykd::exception( "WaitEventException", "Debug interface access exception" ); pykd::exception( "SymbolException", "Symbol exception" ); //pykd::exception( "DiaException", "Debug interface access exception" ); - //pykd::exception( "TypeException", "type exception" ); + pykd::exception( "TypeException", "type exception" ); //pykd::exception( "AddSynSymbolException", "synthetic symbol exception" ); //pykd::exception( "ImplementException", "implementation exception" ); } diff --git a/pykd/stdafx.h b/pykd/stdafx.h index e2a1ef1..b79c250 100644 --- a/pykd/stdafx.h +++ b/pykd/stdafx.h @@ -31,9 +31,9 @@ #include #include -#include +//#include -#include +//#include // //#ifndef __field_ecount_opt diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index 3869780..e1633fa 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -3,20 +3,80 @@ #include #include "typeinfo.h" -#include "dbgclient.h" +#include "dbgengine.h" +#include "module.h" namespace pykd { ///////////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr TypeInfo::getTypeInfoByName( const std::string &typeName ) +static const boost::regex moduleSymMatch("^(?:([^!]*)!)?([^!]+)$"); + +void splitSymName( const std::string &fullName, std::string &moduleName, std::string &symbolName ) { - return g_dbgClient->getTypeInfoByName( typeName ); + boost::cmatch matchResult; + + //OutputReader outputDiscard( m_client ); + + if ( !boost::regex_match( fullName.c_str(), matchResult, moduleSymMatch ) ) + { + std::stringstream sstr; + sstr << "invalid symbol name: " << fullName; + throw SymbolException( sstr.str() ); + } + + symbolName = std::string( matchResult[2].first, matchResult[2].second ); + + if ( matchResult[1].matched ) + { + moduleName = std::string( matchResult[1].first, matchResult[1].second ); + + return; + } + + ULONG64 baseOffset = 0; + baseOffset = findModuleBySymbol( symbolName ); + + moduleName = getModuleName( baseOffset ); } ///////////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr TypeInfo::getTypeInfo( pyDia::SymbolPtr &typeSym ) +TypeInfoPtr TypeInfo::getTypeInfoByName( const std::string &typeName ) +{ + std::string moduleName; + std::string symName; + + if ( TypeInfo::isBaseType( typeName ) ) + return TypeInfo::getBaseTypeInfo( typeName ); + + splitSymName( typeName, moduleName, symName ); + + ModulePtr module = Module::loadModuleByName( moduleName ); + + return module->getTypeByName( symName ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +ULONG64 TypeInfo::getSymbolSize( const std::string &fullName ) +{ + std::string moduleName; + std::string symName; + + if ( TypeInfo::isBaseType( fullName ) ) + return TypeInfo::getBaseTypeInfo( fullName )->getSize(); + + splitSymName( fullName, moduleName, symName ); + + ModulePtr module = Module::loadModuleByName( moduleName ); + + return module->getSymbolSize( symName ); +} + +///////////////////////////////////////////////////////////////////////////////////// + +TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &typeSym ) { const ULONG symTag = typeSym->getSymTag(); switch( symTag ) @@ -86,7 +146,7 @@ BaseTypeVariant TypeInfo::getValue() ///////////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr TypeInfo::getTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName ) +TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &symScope, const std::string &symName ) { size_t pos = symName.find_first_of( "*[" ); @@ -104,11 +164,11 @@ TypeInfoPtr TypeInfo::getTypeInfo( pyDia::SymbolPtr &symScope, const std::strin ///////////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr TypeInfo::getTypeInfo( pyDia::SymbolPtr &symScope, pyDia::SymbolPtr &symChild ) +TypeInfoPtr TypeInfo::getTypeInfo( SymbolPtr &symScope, SymbolPtr &symChild ) { CComVariant constVal; - pyDia::SymbolPtr symType = symChild; + SymbolPtr symType = symChild; if ( symType->getSymTag() == SymTagData ) { if ( symType->getLocType() == LocIsBitField ) @@ -203,9 +263,9 @@ TypeInfo::getBaseTypeInfo( const std::string &symName ) ///////////////////////////////////////////////////////////////////////////////////// TypeInfoPtr -TypeInfo::getBaseTypeInfo( pyDia::SymbolPtr &symbol ) +TypeInfo::getBaseTypeInfo( SymbolPtr &symbol ) { - std::string symName = symbol->getBasicTypeName( symbol->getBaseType() ); + std::string symName = getBasicTypeName( symbol->getBaseType() ); if ( symName == "Int" || symName == "UInt" ) { @@ -225,7 +285,7 @@ TypeInfo::getBaseTypeInfo( pyDia::SymbolPtr &symbol ) ///////////////////////////////////////////////////////////////////////////////////// -BitFieldTypeInfo::BitFieldTypeInfo( pyDia::SymbolPtr &symbol ) +BitFieldTypeInfo::BitFieldTypeInfo( SymbolPtr &symbol ) { m_bitWidth = (ULONG)symbol->getSize(); m_bitPos = (ULONG)symbol->getBitPosition(); @@ -242,9 +302,9 @@ BitFieldTypeInfo::BitFieldTypeInfo( pyDia::SymbolPtr &symbol ) /////////////////////////////////////////////////////////////////////////////////// -PointerTypeInfo::PointerTypeInfo( pyDia::SymbolPtr &symbol ) +PointerTypeInfo::PointerTypeInfo( SymbolPtr &symbol ) { - pyDia::SymbolPtr pointTo = symbol->getType(); + SymbolPtr pointTo = symbol->getType(); try { m_derefType = TypeInfo::getTypeInfo( pointTo ); @@ -280,7 +340,7 @@ PointerTypeInfo::PointerTypeInfo( pyDia::SymbolPtr &symbol ) ///////////////////////////////////////////////////////////////////////////////////// -PointerTypeInfo::PointerTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName ) +PointerTypeInfo::PointerTypeInfo( SymbolPtr &symScope, const std::string &symName ) { try { @@ -309,7 +369,7 @@ ULONG PointerTypeInfo::getSize() ///////////////////////////////////////////////////////////////////////////////////// -ArrayTypeInfo::ArrayTypeInfo( pyDia::SymbolPtr &symbol ) +ArrayTypeInfo::ArrayTypeInfo( SymbolPtr &symbol ) { m_derefType = TypeInfo::getTypeInfo( symbol->getType() ); m_count = symbol->getCount(); @@ -317,7 +377,7 @@ ArrayTypeInfo::ArrayTypeInfo( pyDia::SymbolPtr &symbol ) ///////////////////////////////////////////////////////////////////////////////////// -ArrayTypeInfo::ArrayTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName, ULONG count ) +ArrayTypeInfo::ArrayTypeInfo( SymbolPtr &symScope, const std::string &symName, ULONG count ) { m_derefType = TypeInfo::getTypeInfo( symScope, symName ); m_count = count; @@ -410,7 +470,7 @@ static const boost::regex arrayMatch("^(.*)\\[(\\d+)\\]$"); static const boost::regex symbolMatch("^([\\*]*)([^\\(\\)\\*\\[\\]]*)([\\(\\)\\*\\[\\]\\d]*)$"); -TypeInfoPtr TypeInfo::getComplexType( pyDia::SymbolPtr &symScope, const std::string &symName ) +TypeInfoPtr TypeInfo::getComplexType( SymbolPtr &symScope, const std::string &symName ) { ULONG ptrSize = (symScope->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; @@ -427,7 +487,7 @@ TypeInfoPtr TypeInfo::getComplexType( pyDia::SymbolPtr &symScope, const std::str return getRecurciveComplexType( basePtr, std::string( matchResult[3].first, matchResult[3].second ), ptrSize ); } - pyDia::SymbolPtr lowestSymbol = symScope->getChildByName( innerSymName ); + SymbolPtr lowestSymbol = symScope->getChildByName( innerSymName ); if ( lowestSymbol->getSymTag() == SymTagData ) { @@ -502,8 +562,8 @@ ULONG UdtTypeInfo::getFieldCount() ///////////////////////////////////////////////////////////////////////////////////// void UdtTypeInfo::getFields( - pyDia::SymbolPtr &rootSym, - pyDia::SymbolPtr &baseVirtualSym, + SymbolPtr &rootSym, + SymbolPtr &baseVirtualSym, ULONG startOffset, LONG virtualBasePtr, ULONG virtualDispIndex, @@ -513,7 +573,7 @@ void UdtTypeInfo::getFields( for ( ULONG i = 0; i < childCount; ++i ) { - pyDia::SymbolPtr childSym = rootSym->getChildByIndex( i ); + SymbolPtr childSym = rootSym->getChildByIndex( i ); ULONG symTag = childSym->getSymTag(); @@ -521,7 +581,7 @@ void UdtTypeInfo::getFields( { if ( !childSym->isVirtualBaseClass() ) { - getFields( childSym, pyDia::SymbolPtr(), startOffset + childSym->getOffset() ); + getFields( childSym, SymbolPtr(), startOffset + childSym->getOffset() ); } } else @@ -579,11 +639,11 @@ void UdtTypeInfo::getFields( void UdtTypeInfo::getVirtualFields() { - ULONG childCount = m_dia->getChildCount(); + ULONG childCount = m_dia->getChildCount(SymTagBaseClass); for ( ULONG i = 0; i < childCount; ++i ) { - pyDia::SymbolPtr childSym = m_dia->getChildByIndex( i ); + SymbolPtr childSym = m_dia->getChildByIndex( i ); if ( !childSym->isVirtualBaseClass() ) continue; @@ -604,7 +664,7 @@ void UdtTypeInfo::refreshFields() { if ( m_fields.empty() ) { - getFields( m_dia, pyDia::SymbolPtr() ); + getFields( m_dia, SymbolPtr() ); getVirtualFields(); } } @@ -666,7 +726,7 @@ TypeInfoPtr EnumTypeInfo::getFieldByIndex( ULONG index ) if ( index >= m_dia->getChildCount() ) throw TypeException( m_dia->getName(), ": field not found" ); - pyDia::SymbolPtr field = m_dia->getChildByIndex(index); + SymbolPtr field = m_dia->getChildByIndex(index); if ( !field ) throw TypeException( m_dia->getName(), ": field not found" ); @@ -681,7 +741,7 @@ std::string EnumTypeInfo::getFieldNameByIndex( ULONG index ) if ( index >= m_dia->getChildCount() ) throw TypeException( m_dia->getName(), ": field not found" ); - pyDia::SymbolPtr field = m_dia->getChildByIndex(index); + SymbolPtr field = m_dia->getChildByIndex(index); if ( !field ) throw TypeException( m_dia->getName(), ": field not found" ); @@ -702,9 +762,9 @@ python::dict EnumTypeInfo::asMap() { python::dict dct; - pyDia::SymbolPtrList symbolsList = m_dia->findChildrenImpl(SymTagData, "", nsfCaseSensitive ); + SymbolPtrList symbolsList = m_dia->findChildren(SymTagData, "", TRUE ); - for ( pyDia::SymbolPtrList::iterator it = symbolsList.begin(); it != symbolsList.end(); it++ ) + for ( SymbolPtrList::iterator it = symbolsList.begin(); it != symbolsList.end(); it++ ) { CComVariant val; @@ -724,9 +784,9 @@ std::string EnumTypeInfo::print() sstr << "enum: " << getName() << std::endl; - pyDia::SymbolPtrList symbolsList = m_dia->findChildrenImpl(SymTagData, "", nsfCaseSensitive ); + SymbolPtrList symbolsList = m_dia->findChildren(SymTagData, "", true ); - for ( pyDia::SymbolPtrList::iterator it = symbolsList.begin(); it != symbolsList.end(); it++ ) + for ( SymbolPtrList::iterator it = symbolsList.begin(); it != symbolsList.end(); it++ ) { CComVariant val; (*it)->getValue( val ); diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index 2c6a51a..e700bc6 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -1,5 +1,14 @@ #pragma once +#include + +#include + +#include "udtutils.h" +#include "intbase.h" +#include "symengine.h" +#include "dbgexcept.h" + namespace pykd { /////////////////////////////////////////////////////////////////////////////////// @@ -7,529 +16,503 @@ namespace pykd { class TypeInfo; typedef boost::shared_ptr TypeInfoPtr; -class TypeInfo : boost::noncopyable, public intBase { +/////////////////////////////////////////////////////////////////////////////////// + +class TypeInfo : boost::noncopyable, public intBase, public boost::enable_shared_from_this { public: static TypeInfoPtr getTypeInfoByName( const std::string &symName ); + static + ULONG64 getSymbolSize( const std::string &symName ); + + static + TypeInfoPtr getTypeInfo( SymbolPtr &symScope, const std::string &symName ); + + static + TypeInfoPtr getTypeInfo( SymbolPtr &symScope, SymbolPtr &symChild ); + + static + TypeInfoPtr getTypeInfo( SymbolPtr &symbol ); + + static + TypeInfoPtr getBaseTypeInfo( const std::string &name ); + + static + TypeInfoPtr getBaseTypeInfo( SymbolPtr &symbol ); + + static + bool isBaseType( const std::string &name ); + +public: + + TypeInfo() : + m_staticOffset( 0 ), + m_constant( false ), + m_staticMember( false ), + m_virtualMember( false ), + m_virtualBasePtr( 0 ), + m_virtualDispIndex( 0 ), + m_virtualDispSize( 0 ) + { + m_constantValue.vt = VT_EMPTY; + } + + virtual std::string print() { + std::stringstream sstr; + sstr << "Type name: " << getName(); + sstr << " Size: 0x" << std::hex << getSize() << " (" << std::dec << getSize() << ")"; + return sstr.str(); + } + + virtual std::string getName() = 0; + + virtual ULONG getSize() = 0; + + virtual TypeInfoPtr getField( const std::string &fieldName ) { + throw TypeException( getName(), "type is not a struct" ); + } + + virtual TypeInfoPtr getFieldByIndex( ULONG index ) { + throw TypeException( getName(), "type is not a struct" ); + } + + virtual std::string getFieldNameByIndex( ULONG index ) { + throw TypeException( getName(), "type is not a struct" ); + } + + virtual ULONG getFieldOffsetByNameRecirsive( const std::string &fieldName ) { + throw TypeException( getName(), "type is not a struct" ); + } + virtual ULONG getFieldOffsetByNameNotRecursively( const std::string &fieldName ) { + throw TypeException( getName(), "type is not a struct" ); + } + + virtual ULONG getFieldOffsetByIndex( ULONG index ) { + throw TypeException( getName(), "type is not a struct" ); + } + + virtual ULONG getFieldCount() { + throw TypeException( getName(), "type is not a struct" ); + } + + virtual BaseTypeVariant getValue(); + + virtual bool isBasicType() { + return false; + } + + virtual bool isPointer() { + return false; + } + + virtual bool isArray() { + return false; + } + + virtual bool isUserDefined() { + return false; + } + + virtual bool isBitField() { + return false; + } + + virtual bool isEnum() { + return false; + } + + virtual ULONG getCount() { + throw TypeException( getName(), "type is not an array" ); + } + + virtual TypeInfoPtr getElementType() { + throw TypeException( getName(), "type is not an array" ); + } + + virtual ULONG getBitOffset() { + return 0; + } + + virtual ULONG getBitWidth() { + return 8 * getSize(); + } + + virtual python::dict asMap() { + throw TypeException( getName(), "type cannot be converted to a dict" ); + } + + virtual TypeInfoPtr deref() { + throw TypeException( getName(), "type is not a pointer" ); + } + + virtual ULONG getElementCount() { + throw PyException( PyExc_TypeError, "object has no len()" ); + } + + virtual python::tuple getElementByIndex( ULONG index ) { + throw PyException( PyExc_TypeError, "object is unsubscriptable"); + } + + void setConstant( const VARIANT& var ) + { + m_constant = true; + m_constantValue = var; + } + bool isConstant() const + { + return m_constant == true; + } + + bool isStaticMember() const + { + return m_staticMember == true; + } + + bool isVirtualMember() const + { + return m_virtualMember == true; + } + + void setStaticOffset( ULONG64 offset ) { + m_staticOffset = offset; + m_staticMember = true; + } + + void setVirtualBase( TypeInfoPtr virtualBase, LONG virtualBasePtr, ULONG virtualDispIndex, ULONG virtualDispSize ) + { + m_virtualMember = true; + m_virtualBaseType = virtualBase; + m_virtualBasePtr = virtualBasePtr; + m_virtualDispIndex = virtualDispIndex; + m_virtualDispSize = virtualDispSize; + } + + ULONG64 getStaticOffset(); + + void getVirtualDisplacement( ULONG &virtualBasePtr, ULONG &virtualDispIndex, ULONG &virtualDispSize ) { + virtualBasePtr = m_virtualBasePtr; + virtualDispIndex = m_virtualDispIndex; + virtualDispSize = m_virtualDispSize; + }; + + TypeInfoPtr getVirtualBase() { + return m_virtualBaseType; + } + +protected: + + std::string getComplexName(); + + static + TypeInfoPtr getComplexType( SymbolPtr &symScope, const std::string &symName ); + + static + TypeInfoPtr getRecurciveComplexType( TypeInfoPtr &lowestType, std::string &suffix, ULONG ptrSize ); + + ULONG64 m_staticOffset; + + bool m_constant; + + bool m_staticMember; + + bool m_virtualMember; + + VARIANT m_constantValue; + + LONG m_virtualBasePtr; + + ULONG m_virtualDispIndex; + + ULONG m_virtualDispSize; + + TypeInfoPtr m_virtualBaseType; }; /////////////////////////////////////////////////////////////////////////////////// -}; //end pykd namespace +template +class TypeInfoWrapper : public TypeInfo +{ +public: + TypeInfoWrapper( const std::string &name ) : + m_name(name) + {} + +private: + + virtual std::string getName() { + return m_name; + } + + virtual ULONG getSize() { + return sizeof(T); + } + + virtual bool isBasicType() { + return true; + } + + std::string m_name; + +}; + +/////////////////////////////////////////////////////////////////////////////////// + +class BitFieldTypeInfo : public TypeInfo +{ +public: + + BitFieldTypeInfo( SymbolPtr &symbol ); + + virtual std::string getName() { + return m_name; + } + + virtual ULONG getSize() { + return m_size; + } + + virtual bool isBitField() { + return true; + } + + virtual ULONG getBitOffset() { + return m_bitPos; + } + + virtual ULONG getBitWidth() { + return m_bitWidth; + } + +private: + + ULONG m_size; + ULONG m_bitWidth; + ULONG m_bitPos; + std::string m_name; +}; + +/////////////////////////////////////////////////////////////////////////////////// + +class UdtTypeInfo : public TypeInfo +{ +public: + + UdtTypeInfo (SymbolPtr &symbol ) : + m_dia( symbol ), + m_fields( symbol->getName() ) + { + } + +protected: + + virtual std::string getName() { + return m_dia->getName(); + } + + virtual ULONG getSize() { + return (ULONG)m_dia->getSize(); + } + + virtual TypeInfoPtr getField( const std::string &fieldName ) { + return lookupField(fieldName).m_type; + } + + virtual TypeInfoPtr getFieldByIndex( ULONG index ) { + return lookupField(index).m_type; + } + + virtual std::string getFieldNameByIndex( ULONG index ) { + return lookupField(index).m_name; + } + + virtual ULONG getFieldOffsetByNameRecirsive( const std::string &fieldName ) { + return UdtUtils::getFiledOffsetRecirsive( shared_from_this(), fieldName ); + } + + virtual ULONG getFieldOffsetByNameNotRecursively( const std::string &fieldName ) { + return lookupField(fieldName).m_offset; + } + + virtual ULONG getFieldOffsetByIndex( ULONG index ) { + return lookupField(index).m_offset; + } + + virtual ULONG getFieldCount(); + + virtual bool isUserDefined() { + return true; + } + + virtual ULONG getElementCount() { + return getFieldCount(); + } + + virtual python::tuple getElementByIndex( ULONG index ) { + return python::make_tuple( getFieldNameByIndex(index), getFieldByIndex(index) ); + } + + virtual std::string print(); + + SymbolPtr m_dia; + + UdtUtils::FieldCollection m_fields; + + void getFields( + SymbolPtr &rootSym, + SymbolPtr &baseVirtualSym, + ULONG startOffset = 0, + LONG virtualBasePtr = 0, + ULONG virtualDispIndex = 0, + ULONG m_virtualDispSize = 0 ); + void getVirtualFields(); -//#include -// -//#include -// -//#include "udtutils.h" -//#include "diawrapper.h" -//#include "intbase.h" -// -//namespace pykd { -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class TypeInfo; -//typedef boost::shared_ptr TypeInfoPtr; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class TypeInfo : boost::noncopyable, public intBase, public boost::enable_shared_from_this { -// -//public: -// -// static -// TypeInfoPtr getTypeInfoByName( const std::string &symName ); -// -// static -// TypeInfoPtr getTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName ); -// -// static -// TypeInfoPtr getTypeInfo( pyDia::SymbolPtr &symScope, pyDia::SymbolPtr &symChild ); -// -// static -// TypeInfoPtr getTypeInfo( pyDia::SymbolPtr &symbol ); -// -// static -// TypeInfoPtr getBaseTypeInfo( const std::string &name ); -// -// static -// TypeInfoPtr getBaseTypeInfo( pyDia::SymbolPtr &symbol ); -// -// static -// bool isBaseType( const std::string &name ); -// -//public: -// -// TypeInfo() : -// m_staticOffset( 0 ), -// m_constant( false ), -// m_staticMember( false ), -// m_virtualMember( false ), -// m_virtualBasePtr( 0 ), -// m_virtualDispIndex( 0 ), -// m_virtualDispSize( 0 ) -// { -// m_constantValue.vt = VT_EMPTY; -// } -// -// virtual std::string print() { -// std::stringstream sstr; -// sstr << "Type name: " << getName(); -// sstr << " Size: 0x" << std::hex << getSize() << " (" << std::dec << getSize() << ")"; -// return sstr.str(); -// } -// -// virtual std::string getName() = 0; -// -// virtual ULONG getSize() = 0; -// -// virtual TypeInfoPtr getField( const std::string &fieldName ) { -// throw TypeException( getName(), "type is not a struct" ); -// } -// -// virtual TypeInfoPtr getFieldByIndex( ULONG index ) { -// throw TypeException( getName(), "type is not a struct" ); -// } -// -// virtual std::string getFieldNameByIndex( ULONG index ) { -// throw TypeException( getName(), "type is not a struct" ); -// } -// -// virtual ULONG getFieldOffsetByNameRecirsive( const std::string &fieldName ) { -// throw TypeException( getName(), "type is not a struct" ); -// } -// virtual ULONG getFieldOffsetByNameNotRecursively( const std::string &fieldName ) { -// throw TypeException( getName(), "type is not a struct" ); -// } -// -// virtual ULONG getFieldOffsetByIndex( ULONG index ) { -// throw TypeException( getName(), "type is not a struct" ); -// } -// -// virtual ULONG getFieldCount() { -// throw TypeException( getName(), "type is not a struct" ); -// } -// -// virtual BaseTypeVariant getValue(); -// -// virtual bool isBasicType() { -// return false; -// } -// -// virtual bool isPointer() { -// return false; -// } -// -// virtual bool isArray() { -// return false; -// } -// -// virtual bool isUserDefined() { -// return false; -// } -// -// virtual bool isBitField() { -// return false; -// } -// -// virtual bool isEnum() { -// return false; -// } -// -// virtual ULONG getCount() { -// throw TypeException( getName(), "type is not an array" ); -// } -// -// virtual TypeInfoPtr getElementType() { -// throw TypeException( getName(), "type is not an array" ); -// } -// -// virtual ULONG getBitOffset() { -// return 0; -// } -// -// virtual ULONG getBitWidth() { -// return 8 * getSize(); -// } -// -// virtual python::dict asMap() { -// throw TypeException( getName(), "type cannot be converted to a dict" ); -// } -// -// virtual TypeInfoPtr deref() { -// throw TypeException( getName(), "type is not a pointer" ); -// } -// -// virtual ULONG getElementCount() { -// throw PyException( PyExc_TypeError, "object has no len()" ); -// } -// -// virtual python::tuple getElementByIndex( ULONG index ) { -// throw PyException( PyExc_TypeError, "object is unsubscriptable"); -// } -// -// void setConstant( const VARIANT& var ) -// { -// m_constant = true; -// m_constantValue = var; -// } -// bool isConstant() const -// { -// return m_constant == true; -// } -// -// bool isStaticMember() const -// { -// return m_staticMember == true; -// } -// -// bool isVirtualMember() const -// { -// return m_virtualMember == true; -// } -// -// void setStaticOffset( ULONG64 offset ) { -// m_staticOffset = offset; -// m_staticMember = true; -// } -// -// void setVirtualBase( TypeInfoPtr virtualBase, LONG virtualBasePtr, ULONG virtualDispIndex, ULONG virtualDispSize ) -// { -// m_virtualMember = true; -// m_virtualBaseType = virtualBase; -// m_virtualBasePtr = virtualBasePtr; -// m_virtualDispIndex = virtualDispIndex; -// m_virtualDispSize = virtualDispSize; -// } -// -// ULONG64 getStaticOffset(); -// -// void getVirtualDisplacement( ULONG &virtualBasePtr, ULONG &virtualDispIndex, ULONG &virtualDispSize ) { -// virtualBasePtr = m_virtualBasePtr; -// virtualDispIndex = m_virtualDispIndex; -// virtualDispSize = m_virtualDispSize; -// }; -// -// TypeInfoPtr getVirtualBase() { -// return m_virtualBaseType; -// } -// -//protected: -// -// std::string getComplexName(); -// -// static -// TypeInfoPtr getComplexType( pyDia::SymbolPtr &symScope, const std::string &symName ); -// -// static -// TypeInfoPtr getRecurciveComplexType( TypeInfoPtr &lowestType, std::string &suffix, ULONG ptrSize ); -// -// ULONG64 m_staticOffset; -// -// bool m_constant; -// -// bool m_staticMember; -// -// bool m_virtualMember; -// -// VARIANT m_constantValue; -// -// LONG m_virtualBasePtr; -// -// ULONG m_virtualDispIndex; -// -// ULONG m_virtualDispSize; -// -// TypeInfoPtr m_virtualBaseType; -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//template -//class TypeInfoWrapper : public TypeInfo -//{ -//public: -// TypeInfoWrapper( const std::string &name ) : -// m_name(name) -// {} -// -//private: -// -// virtual std::string getName() { -// return m_name; -// } -// -// virtual ULONG getSize() { -// return sizeof(T); -// } -// -// virtual bool isBasicType() { -// return true; -// } -// -// std::string m_name; -// -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class BitFieldTypeInfo : public TypeInfo -//{ -//public: -// -// BitFieldTypeInfo( pyDia::SymbolPtr &symbol ); -// -// virtual std::string getName() { -// return m_name; -// } -// -// virtual ULONG getSize() { -// return m_size; -// } -// -// virtual bool isBitField() { -// return true; -// } -// -// virtual ULONG getBitOffset() { -// return m_bitPos; -// } -// -// virtual ULONG getBitWidth() { -// return m_bitWidth; -// } -// -//private: -// -// ULONG m_size; -// ULONG m_bitWidth; -// ULONG m_bitPos; -// std::string m_name; -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class UdtTypeInfo : public TypeInfo -//{ -//public: -// -// UdtTypeInfo ( pyDia::SymbolPtr &symbol ) : -// m_dia( symbol ), -// m_fields( symbol->getName() ) -// { -// } -// -//protected: -// -// virtual std::string getName() { -// return m_dia->getName(); -// } -// -// virtual ULONG getSize() { -// return (ULONG)m_dia->getSize(); -// } -// -// virtual TypeInfoPtr getField( const std::string &fieldName ) { -// return lookupField(fieldName).m_type; -// } -// -// virtual TypeInfoPtr getFieldByIndex( ULONG index ) { -// return lookupField(index).m_type; -// } -// -// virtual std::string getFieldNameByIndex( ULONG index ) { -// return lookupField(index).m_name; -// } -// -// virtual ULONG getFieldOffsetByNameRecirsive( const std::string &fieldName ) { -// return UdtUtils::getFiledOffsetRecirsive( shared_from_this(), fieldName ); -// } -// virtual ULONG getFieldOffsetByNameNotRecursively( const std::string &fieldName ) { -// return lookupField(fieldName).m_offset; -// } -// -// virtual ULONG getFieldOffsetByIndex( ULONG index ) { -// return lookupField(index).m_offset; -// } -// -// virtual ULONG getFieldCount(); -// -// virtual bool isUserDefined() { -// return true; -// } -// -// virtual ULONG getElementCount() { -// return getFieldCount(); -// } -// -// virtual python::tuple getElementByIndex( ULONG index ) { -// return python::make_tuple( getFieldNameByIndex(index), getFieldByIndex(index) ); -// } -// -// virtual std::string print(); -// -// pyDia::SymbolPtr m_dia; -// -// UdtUtils::FieldCollection m_fields; -// -// void getFields( -// pyDia::SymbolPtr &rootSym, -// pyDia::SymbolPtr &baseVirtualSym, -// ULONG startOffset = 0, -// LONG virtualBasePtr = 0, -// ULONG virtualDispIndex = 0, -// ULONG m_virtualDispSize = 0 ); -// -// -// void getVirtualFields(); -// -//private: -// void refreshFields(); -// -// template -// const UdtUtils::Field &lookupField( T index) { -// refreshFields(); -// return m_fields.lookup(index); -// } -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class EnumTypeInfo : public TypeInfo -//{ -//public: -// -// EnumTypeInfo ( pyDia::SymbolPtr &symbol ) : -// m_dia( symbol ) -// {} -// -//protected: -// -// virtual std::string getName() { -// return m_dia->getName(); -// } -// -// virtual ULONG getSize() { -// return (ULONG)m_dia->getSize(); -// } -// -// virtual TypeInfoPtr getFieldByIndex( ULONG index ); -// -// virtual std::string getFieldNameByIndex( ULONG index ); -// -// virtual ULONG getFieldCount(); -// -// virtual TypeInfoPtr getField( const std::string &fieldName ); -// -// virtual python::dict asMap(); -// -// virtual bool isEnum() { -// return true; -// } -// -// virtual std::string print(); -// -// pyDia::SymbolPtr m_dia; -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class PointerTypeInfo : public TypeInfo { -// -//public: -// -// PointerTypeInfo( const TypeInfoPtr ptr, ULONG ptrSize ) : -// m_size( ptrSize ), -// m_derefType( ptr ) -// {} -// -// PointerTypeInfo( pyDia::SymbolPtr &symbol ); -// -// PointerTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName ); -// -// virtual std::string getName(); -// -// virtual ULONG getSize(); -// -// virtual bool isPointer() { -// return true; -// } -// -// virtual TypeInfoPtr deref() { -// return getDerefType(); -// } -// -// TypeInfoPtr getDerefType() { -// if (!m_derefType) -// throw TypeException("", "this pointer can not be dereferenced"); -// return m_derefType; -// } -// -// bool derefPossible() const { -// return m_derefType; -// } -// -// const std::string getDerefName() const { -// if (m_derefName.empty()) -// throw TypeException("", "this pointer can not be dereferenced"); -// return m_derefName; -// } -// -//private: -// -// TypeInfoPtr m_derefType; -// ULONG m_size; -// std::string m_derefName; -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//class ArrayTypeInfo : public TypeInfo { -// -//public: -// -// ArrayTypeInfo( const TypeInfoPtr ptr, ULONG count ) : -// m_derefType( ptr ), -// m_count( count ) -// {} -// -// ArrayTypeInfo( pyDia::SymbolPtr &symbol ); -// -// ArrayTypeInfo( pyDia::SymbolPtr &symScope, const std::string &symName, ULONG count ); -// -// virtual std::string getName(); -// -// virtual ULONG getSize(); -// -// virtual bool isArray() { -// return true; -// } -// -// virtual ULONG getCount() { -// return m_count; -// } -// -// virtual TypeInfoPtr getElementType() { -// return m_derefType; -// } -// -// TypeInfoPtr getDerefType() { -// return m_derefType; -// } -// -//private: -// -// TypeInfoPtr m_derefType; -// -// ULONG m_count; -//}; -// -///////////////////////////////////////////////////////////////////////////////////// -// -//}; // namespace pykd +private: + void refreshFields(); + + template + const UdtUtils::Field &lookupField( T index) { + refreshFields(); + return m_fields.lookup(index); + } +}; + +/////////////////////////////////////////////////////////////////////////////////// + +class EnumTypeInfo : public TypeInfo +{ +public: + + EnumTypeInfo ( SymbolPtr &symbol ) : + m_dia( symbol ) + {} + +protected: + + virtual std::string getName() { + return m_dia->getName(); + } + + virtual ULONG getSize() { + return (ULONG)m_dia->getSize(); + } + + virtual TypeInfoPtr getFieldByIndex( ULONG index ); + + virtual std::string getFieldNameByIndex( ULONG index ); + + virtual ULONG getFieldCount(); + + virtual TypeInfoPtr getField( const std::string &fieldName ); + + virtual python::dict asMap(); + + virtual bool isEnum() { + return true; + } + + virtual std::string print(); + + SymbolPtr m_dia; +}; + +/////////////////////////////////////////////////////////////////////////////////// + +class PointerTypeInfo : public TypeInfo { + +public: + + PointerTypeInfo( const TypeInfoPtr ptr, ULONG ptrSize ) : + m_size( ptrSize ), + m_derefType( ptr ) + {} + + PointerTypeInfo( SymbolPtr &symbol ); + + PointerTypeInfo( SymbolPtr &symScope, const std::string &symName ); + + virtual std::string getName(); + + virtual ULONG getSize(); + + virtual bool isPointer() { + return true; + } + + virtual TypeInfoPtr deref() { + return getDerefType(); + } + + TypeInfoPtr getDerefType() { + if (!m_derefType) + throw TypeException("", "this pointer can not be dereferenced"); + return m_derefType; + } + + bool derefPossible() const { + return m_derefType; + } + + const std::string getDerefName() const { + if (m_derefName.empty()) + throw TypeException("", "this pointer can not be dereferenced"); + return m_derefName; + } + +private: + + TypeInfoPtr m_derefType; + ULONG m_size; + std::string m_derefName; +}; + +/////////////////////////////////////////////////////////////////////////////////// + +class ArrayTypeInfo : public TypeInfo { + +public: + + ArrayTypeInfo( const TypeInfoPtr ptr, ULONG count ) : + m_derefType( ptr ), + m_count( count ) + {} + + ArrayTypeInfo( SymbolPtr &symbol ); + + ArrayTypeInfo( SymbolPtr &symScope, const std::string &symName, ULONG count ); + + virtual std::string getName(); + + virtual ULONG getSize(); + + virtual bool isArray() { + return true; + } + + virtual ULONG getCount() { + return m_count; + } + + virtual TypeInfoPtr getElementType() { + return m_derefType; + } + + TypeInfoPtr getDerefType() { + return m_derefType; + } + +private: + + TypeInfoPtr m_derefType; + + ULONG m_count; +}; + +/////////////////////////////////////////////////////////////////////////////////// + +}; // namespace pykd diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index ae71c49..49b9f91 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -150,6 +150,26 @@ ULONG64 findModuleBase( ULONG64 offset ) /////////////////////////////////////////////////////////////////////////////////// +ULONG64 findModuleBySymbol( const std::string &symbolName ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG64 base; + + hres = g_dbgEng->symbols->GetSymbolModule( ( std::string("!") + symbolName ).c_str(), &base ); + if ( FAILED( hres ) ) + { + std::stringstream sstr; + sstr << "failed to find module for symbol: " << symbolName; + throw SymbolException( sstr.str() ); + } + + return base; +} + +/////////////////////////////////////////////////////////////////////////////////// + std::string getModuleName( ULONG64 baseOffset ) { PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 367b3f1..34dff38 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -16,6 +16,7 @@ import target import intbase import memtest import moduletest +import typeinfo def getTestSuite( singleName = "" ): @@ -25,7 +26,8 @@ def getTestSuite( singleName = "" ): unittest.TestLoader().loadTestsFromTestCase( target.TargetTest ), unittest.TestLoader().loadTestsFromTestCase( intbase.IntBaseTest ), unittest.TestLoader().loadTestsFromTestCase( moduletest.ModuleTest ), - unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ) + unittest.TestLoader().loadTestsFromTestCase( memtest.MemoryTest ), + unittest.TestLoader().loadTestsFromTestCase( typeinfo.TypeInfoTest ), ] ) else: return unittest.TestSuite( unittest.TestLoader().loadTestsFromName( singleName ) )