From b61ac0b10a1c38c337a1227f2a837b34b207c25e Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 24 Jan 2011 14:13:02 +0000 Subject: [PATCH] [~] updated : __str__ method for typedVar class git-svn-id: https://pykd.svn.codeplex.com/svn@60649 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgmem.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgmem.h | 6 ++++ pykd/dbgtype.cpp | 33 ++++++++++++++++++++-- pykd/dbgtype.h | 5 ++++ 4 files changed, 112 insertions(+), 3 deletions(-) diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index b927527..e05ad05 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -339,6 +339,76 @@ loadAnsiStr( ULONG64 address ) return boost::python::object( "" ); } +/////////////////////////////////////////////////////////////////////////////////// + +bool +loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen ) +{ + address = addr64( address ); + + try { + + HRESULT hres = + dbgExt->dataSpaces4->ReadMultiByteStringVirtual( + address, + bufferLen, + buffer, + bufferLen/sizeof(CHAR), + NULL ); + + if ( FAILED( hres ) ) + return false; + + return true; + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + return false; +} + +/////////////////////////////////////////////////////////////////////////////////// + +bool +loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen ) +{ + address = addr64( address ); + + try { + + HRESULT hres = + dbgExt->dataSpaces4->ReadUnicodeStringVirtualWide( + address, + bufferLen, + buffer, + bufferLen/sizeof(WCHAR), + NULL ); + + if ( FAILED( hres ) ) + return false; + + return true; + + } + catch( std::exception &e ) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); + } + catch(...) + { + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + return false; +} + + /////////////////////////////////////////////////////////////////////////////////// boost::python::object @@ -423,6 +493,7 @@ loadWStr( ULONG64 address ) return strObj; } + /////////////////////////////////////////////////////////////////////////////////// boost::python::object diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index a696029..0d617ce 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -68,9 +68,15 @@ loadAnsiStr( ULONG64 address ); boost::python::object loadCStr( ULONG64 address ); +bool +loadCStrToBuffer( ULONG64 address, PCHAR buffer, ULONG bufferLen ); + boost::python::object loadWStr( ULONG64 address ); +bool +loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen ); + bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE ); diff --git a/pykd/dbgtype.cpp b/pykd/dbgtype.cpp index d00dc88..8c21fa0 100644 --- a/pykd/dbgtype.cpp +++ b/pykd/dbgtype.cpp @@ -431,7 +431,7 @@ typedVarClass::print() const { sstr << "\t" << hex << "+" << field->offset << " " << field->name << " "; - if ( field->type.isComplex() ) + if ( field->type.isComplex() && !field->type.isPtr()) sstr << field->type.name(); else { @@ -447,8 +447,35 @@ typedVarClass::print() const { unsigned __int64 val = boost::python::extract( attr ); - sstr << hex << "0x" << val << dec << " ( " << val << " )"; - } + sstr << hex << "0x" << val; + + if ( field->type.name() == "char*" ) + { + char buf[0x100]; + if ( loadCStrToBuffer( val, buf, sizeof(buf) ) ) + sstr << " (" << buf << " )"; + else + sstr << " ( read string error )"; + } + else if ( field->type.name() == "unsigned short*" ) + { + wchar_t wbuf[0x100]; + if ( loadWStrToBuffer( val, wbuf, sizeof(wbuf) ) ) + { + char mbBuf[0x100] = { 0 }; + + WideCharToMultiByte( CP_ACP, 0, wbuf, wcslen(wbuf)+1, mbBuf, sizeof(mbBuf), NULL, NULL ); + + sstr << " (" << mbBuf << " )"; + } + else + sstr << " ( read string error )"; + } + else + { + sstr << dec << " ( " << val << " )"; + } + } } else { diff --git a/pykd/dbgtype.h b/pykd/dbgtype.h index 22c863c..cc1a3d5 100644 --- a/pykd/dbgtype.h +++ b/pykd/dbgtype.h @@ -106,6 +106,11 @@ public: return !m_baseType; } + bool + isPtr() const { + return m_pointer; + } + private: static TypeInfoMap g_typeInfoCache;