From 222515e19165e076f4e763dfb778a8986722139b Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Fri, 24 Jan 2014 13:28:24 +0000 Subject: [PATCH] [0.2.x] added: VS_FIXEDFILEINFO structure for a module git-svn-id: https://pykd.svn.codeplex.com/svn@87133 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgengine.h | 29 +++++++++++++++++++++++++++++ pykd/module.cpp | 6 ++++++ pykd/module.h | 2 ++ pykd/python/pymod.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- pykd/win/dbgmod.cpp | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 2 deletions(-) diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index 94a67f6..78d1f27 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -70,6 +70,35 @@ bool isModuleUserMode( ULONG64 baseOffset ); std::string getModuleVersionInfo( ULONG64 baseOffset, const std::string &value ); void getModuleFileVersion( ULONG64 baseOffset, USHORT &majorHigh, USHORT &majorLow, USHORT &minorHigh, USHORT &minorLow ); +struct FixedFileInfo : protected boost::noncopyable { + DWORD Signature; + DWORD StrucVersion; + DWORD FileVersionMS; + DWORD FileVersionLS; + DWORD ProductVersionMS; + DWORD ProductVersionLS; + DWORD FileFlagsMask; + DWORD FileFlags; + DWORD FileOS; + DWORD FileType; + DWORD FileSubtype; + DWORD FileDateMS; + DWORD FileDateLS; + + FixedFileInfo(ULONG64 baseOffset); +}; +typedef boost::shared_ptr< FixedFileInfo > FixedFileInfoPtr; + +enum FileFlag +{ + FileFlagDebug = 0x00000001, + FileFlagPreRelease = 0x00000002, + FileFlagPatched = 0x00000004, + FileFlagPrivateBuild = 0x00000008, + FileFlagInfoInferred = 0x00000010, + FileFlagSpecialBuild = 0x00000020, +}; + // CPU registers ULONG getRegIndexByName( const std::string ®Name ); std::string getRegNameByIndex( ULONG index ); diff --git a/pykd/module.cpp b/pykd/module.cpp index c984496..1c84fc8 100644 --- a/pykd/module.cpp +++ b/pykd/module.cpp @@ -431,4 +431,10 @@ python::tuple Module::getVersion() /////////////////////////////////////////////////////////////////////////////////// +FixedFileInfoPtr Module::getFixedFileInfo() { + return FixedFileInfoPtr( new FixedFileInfo(m_base) ); +} + +/////////////////////////////////////////////////////////////////////////////////// + }; // end of namespace pykd diff --git a/pykd/module.h b/pykd/module.h index f0e4eac..03e3a1e 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -128,6 +128,8 @@ public: python::tuple getVersion(); + boost::shared_ptr< struct FixedFileInfo > getFixedFileInfo(); + private: void completeConstruct(); // call from ctor diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index 7c3af0b..4eb7fa4 100644 --- a/pykd/python/pymod.cpp +++ b/pykd/python/pymod.cpp @@ -380,6 +380,44 @@ BOOST_PYTHON_MODULE( pykd ) python::implicitly_convertible(); python::implicitly_convertible(); + python::class_( "FixedFileInfo", + "Version information for a file", python::no_init ) + .def_readonly( "Signature", &FixedFileInfo::Signature, + "Contains the value 0xFEEF04BD" ) + .def_readonly( "StrucVersion", &FixedFileInfo::StrucVersion, + "The binary version number of this structure" ) + .def_readonly( "FileVersionMS", &FixedFileInfo::FileVersionMS, + "The most significant 32 bits of the file's binary version number" ) + .def_readonly( "FileVersionLS", &FixedFileInfo::FileVersionLS, + "The least significant 32 bits of the file's binary version number" ) + .def_readonly( "ProductVersionMS", &FixedFileInfo::ProductVersionMS, + "The most significant 32 bits of the binary version number of the product with which this file was distributed" ) + .def_readonly( "ProductVersionLS", &FixedFileInfo::ProductVersionLS, + "The least significant 32 bits of the binary version number of the product with which this file was distributed" ) + .def_readonly( "FileFlagsMask", &FixedFileInfo::FileFlagsMask, + "Contains a bitmask that specifies the valid bits in FileFlags" ) + .def_readonly( "FileFlags", &FixedFileInfo::FileFlags, + "Contains a bitmask that specifies the Boolean attributes of the file: FileFlag" ) + .def_readonly( "FileOS", &FixedFileInfo::FileOS, + "The operating system for which this file was designed" ) + .def_readonly( "FileType", &FixedFileInfo::FileType, + "The general type of file" ) + .def_readonly( "FileSubtype", &FixedFileInfo::FileSubtype, + "The function of the file. The possible values depend on the value of FileType" ) + .def_readonly( "FileDateMS", &FixedFileInfo::FileDateMS, + "The most significant 32 bits of the file's 64-bit binary creation date and time stamp" ) + .def_readonly( "FileDateLS", &FixedFileInfo::FileDateLS, + "The least significant 32 bits of the file's 64-bit binary creation date and time stamp" ); + + python::enum_("FileFlag", "Attributes of the file") + .value("Debug", FileFlagDebug) + .value("PreRelease", FileFlagPreRelease) + .value("Patched", FileFlagPatched) + .value("PrivateBuild", FileFlagPrivateBuild) + .value("InfoInferred", FileFlagInfoInferred) + .value("SpecialBuild", FileFlagSpecialBuild) + .export_values(); + python::class_ >("module", "Class representing executable module", python::no_init ) .def("__init__", python::make_constructor(Module::loadModuleByName) ) .def("__init__", python::make_constructor(Module::loadModuleByOffset) ) @@ -440,6 +478,8 @@ BOOST_PYTHON_MODULE( pykd ) "Return string from the module's version resources" ) .def("getVersion", &Module::getVersion, "Return tuple of the module's file version" ) + .def("getFixedFileInfo", &Module::getFixedFileInfo, + "Return FixedFileInfo" ) .def("__getattr__", &Module::getSymbolOffset, "Return address of the symbol" ) .def( "__str__", &Module::print ); @@ -592,8 +632,6 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__str__", &ExceptionInfo::print, "Return object as a string"); - - python::enum_("eventType", "Type of debug event") .value("Breakpoint", EventTypeBreakpoint) .value("Exception", EventTypeException) diff --git a/pykd/win/dbgmod.cpp b/pykd/win/dbgmod.cpp index 0cdd0b9..aff6e02 100644 --- a/pykd/win/dbgmod.cpp +++ b/pykd/win/dbgmod.cpp @@ -410,6 +410,39 @@ std::string getModuleVersionInfo( ULONG64 baseOffset, const std::string &value ) /////////////////////////////////////////////////////////////////////////////// +FixedFileInfo::FixedFileInfo(ULONG64 baseOffset) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + VS_FIXEDFILEINFO Pod; + HRESULT hres = + g_dbgEng->symbols->GetModuleVersionInformation( + DEBUG_ANY_ID, + baseOffset, + "\\", + &Pod, + sizeof(Pod), + NULL ); + if ( hres != S_OK ) + throw DbgException("IDebugSymbols::GetModuleVersionInformation", hres); + + Signature = Pod.dwSignature; + StrucVersion = Pod.dwStrucVersion; + FileVersionMS = Pod.dwFileVersionMS; + FileVersionLS = Pod.dwFileVersionLS; + ProductVersionMS = Pod.dwProductVersionMS; + ProductVersionLS = Pod.dwProductVersionLS; + FileFlagsMask = Pod.dwFileFlagsMask; + FileFlags = Pod.dwFileFlags; + FileOS = Pod.dwFileOS; + FileType = Pod.dwFileType; + FileSubtype = Pod.dwFileSubtype; + FileDateMS = Pod.dwFileDateMS; + FileDateLS = Pod.dwFileDateLS; +} + +/////////////////////////////////////////////////////////////////////////////// + } // namespace pykd ///////////////////////////////////////////////////////////////////////////////