mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[0.2.x] added: getVersion ( return tuple of the module's file version )
[0.2.x] added: queryVersion ( Return string from the module's version resources ) git-svn-id: https://pykd.svn.codeplex.com/svn@82001 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
fe32493b73
commit
20cefe3ecc
@ -45,6 +45,8 @@ ULONG getModuleSize( ULONG64 baseOffset );
|
|||||||
std::string getModuleSymbolFileName( ULONG64 baseOffset );
|
std::string getModuleSymbolFileName( ULONG64 baseOffset );
|
||||||
ULONG getModuleTimeStamp( ULONG64 baseOffset );
|
ULONG getModuleTimeStamp( ULONG64 baseOffset );
|
||||||
ULONG getModuleCheckSum( ULONG64 baseOffset );
|
ULONG getModuleCheckSum( ULONG64 baseOffset );
|
||||||
|
std::string getModuleVersionInfo( ULONG64 baseOffset, const std::string &value );
|
||||||
|
void getModuleFileVersion( ULONG64 baseOffset, USHORT &majorHigh, USHORT &majorLow, USHORT &minorHigh, USHORT &minorLow );
|
||||||
|
|
||||||
// CPU registers
|
// CPU registers
|
||||||
ULONG getRegIndexByName( const std::string ®Name );
|
ULONG getRegIndexByName( const std::string ®Name );
|
||||||
|
@ -397,4 +397,21 @@ python::list Module::enumTypes( const std::string &mask )
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string Module::queryVersion( const std::string &value) {
|
||||||
|
return getModuleVersionInfo( m_base, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::tuple Module::getVersion()
|
||||||
|
{
|
||||||
|
USHORT a1,a2,a3,a4;
|
||||||
|
getModuleFileVersion( m_base, a1,a2,a3,a4 );
|
||||||
|
|
||||||
|
return python::make_tuple(a1,a2,a3,a4);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}; // end of namespace pykd
|
}; // end of namespace pykd
|
||||||
|
@ -137,6 +137,10 @@ public:
|
|||||||
|
|
||||||
std::string print();
|
std::string print();
|
||||||
|
|
||||||
|
std::string queryVersion( const std::string &value);
|
||||||
|
|
||||||
|
python::tuple getVersion();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SymbolPtr& getSymScope();
|
SymbolPtr& getSymScope();
|
||||||
|
@ -389,6 +389,10 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" )
|
"Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" )
|
||||||
.def("timestamp",&Module::getTimeDataStamp,
|
.def("timestamp",&Module::getTimeDataStamp,
|
||||||
"Return a low 32 bits of the time stamp of the image: IMAGE_FILE_HEADER.TimeDateStamp" )
|
"Return a low 32 bits of the time stamp of the image: IMAGE_FILE_HEADER.TimeDateStamp" )
|
||||||
|
.def("queryVersion", &Module::queryVersion,
|
||||||
|
"Return string from the module's version resources" )
|
||||||
|
.def("getVersion", &Module::getVersion,
|
||||||
|
"Return tuple of the module's file version" )
|
||||||
.def("__getattr__", &Module::getSymbolOffset,
|
.def("__getattr__", &Module::getSymbolOffset,
|
||||||
"Return address of the symbol" )
|
"Return address of the symbol" )
|
||||||
.def( "__str__", &Module::print );
|
.def( "__str__", &Module::print );
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
#include <boost\algorithm\string\case_conv.hpp>
|
#include <boost\algorithm\string\case_conv.hpp>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#include "win/dbgeng.h"
|
#include "win/dbgeng.h"
|
||||||
#include "win/dbgio.h"
|
#include "win/dbgio.h"
|
||||||
@ -541,7 +542,110 @@ ULONG getModuleCheckSum( ULONG64 baseOffset )
|
|||||||
return moduleParam.Checksum;
|
return moduleParam.Checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void getModuleFileVersion( ULONG64 baseOffset, USHORT &majorHigh, USHORT &majorLow, USHORT &minorHigh, USHORT &minorLow )
|
||||||
|
{
|
||||||
|
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||||
|
|
||||||
|
VS_FIXEDFILEINFO fileInfo={};
|
||||||
|
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
hres = g_dbgEng->symbols->GetModuleVersionInformation(
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
baseOffset,
|
||||||
|
"\\",
|
||||||
|
(PVOID)&fileInfo,
|
||||||
|
sizeof(fileInfo),
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbol2::GetModuleVersionInformation failed" );
|
||||||
|
|
||||||
|
majorHigh = HIWORD(fileInfo.dwFileVersionMS);
|
||||||
|
majorLow = LOWORD(fileInfo.dwFileVersionMS);
|
||||||
|
minorHigh = HIWORD(fileInfo.dwFileVersionLS);
|
||||||
|
minorLow = LOWORD(fileInfo.dwFileVersionLS);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
std::string getModuleVersionInfo( ULONG64 baseOffset, const std::string &value )
|
||||||
|
{
|
||||||
|
struct LANGANDCODEPAGE {
|
||||||
|
WORD wLanguage;
|
||||||
|
WORD wCodePage;
|
||||||
|
};
|
||||||
|
|
||||||
|
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||||
|
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
ULONG codePagesSize = 0;
|
||||||
|
|
||||||
|
hres = g_dbgEng->symbols->GetModuleVersionInformation(
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
baseOffset,
|
||||||
|
"\\VarFileInfo\\Translation",
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&codePagesSize );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbol2::GetModuleVersionInformation failed" );
|
||||||
|
|
||||||
|
size_t codePageNum = codePagesSize / sizeof(LANGANDCODEPAGE);
|
||||||
|
|
||||||
|
std::vector<LANGANDCODEPAGE> codePages(codePageNum);
|
||||||
|
|
||||||
|
hres = g_dbgEng->symbols->GetModuleVersionInformation(
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
baseOffset,
|
||||||
|
"\\VarFileInfo\\Translation",
|
||||||
|
&codePages[0],
|
||||||
|
codePagesSize,
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbol2::GetModuleVersionInformation failed" );
|
||||||
|
|
||||||
|
ULONG productNameLength = 0;
|
||||||
|
|
||||||
|
std::stringstream sstr;
|
||||||
|
sstr << "\\StringFileInfo\\" << std::hex
|
||||||
|
<< std::setw(4) << std::setfill('0') << codePages[0].wLanguage
|
||||||
|
<< std::setw(4) << std::setfill('0') << codePages[0].wCodePage
|
||||||
|
<< "\\" << value;
|
||||||
|
|
||||||
|
ULONG valueLength;
|
||||||
|
|
||||||
|
g_dbgEng->symbols->GetModuleVersionInformation(
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
baseOffset,
|
||||||
|
sstr.str().c_str(),
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&valueLength );
|
||||||
|
|
||||||
|
std::vector<char> valueStr(valueLength);
|
||||||
|
|
||||||
|
hres = g_dbgEng->symbols->GetModuleVersionInformation(
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
baseOffset,
|
||||||
|
sstr.str().c_str(),
|
||||||
|
&valueStr[0],
|
||||||
|
valueLength,
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
if ( hres == S_OK )
|
||||||
|
return std::string( &valueStr[0] );
|
||||||
|
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ULONG ptrSize()
|
ULONG ptrSize()
|
||||||
{
|
{
|
||||||
@ -1464,6 +1568,7 @@ std::string callExtension( ULONG64 extHandle, const std::wstring command, const
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end pykd namespace
|
} // end pykd namespace
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user