diff --git a/pykd/eventhandler.cpp b/pykd/eventhandler.cpp index cef87ac..ae6d55d 100644 --- a/pykd/eventhandler.cpp +++ b/pykd/eventhandler.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "eventhandler.h" +#include "module.h" namespace pykd { @@ -56,6 +57,15 @@ DEBUG_CALLBACK_RESULT EventHandlerImpl::OnBreakpoint( ULONG bpId ) /////////////////////////////////////////////////////////////////////////////// +DEBUG_CALLBACK_RESULT EventHandlerImpl::OnModuleUnload( ULONG64 offset, const std::string &name ) +{ + Module::onUnloadModule( offset ); + + return DebugCallbackNoChange; +} + +/////////////////////////////////////////////////////////////////////////////// + }; // namespace pykd diff --git a/pykd/eventhandler.h b/pykd/eventhandler.h index c09d454..13f6230 100644 --- a/pykd/eventhandler.h +++ b/pykd/eventhandler.h @@ -132,6 +132,8 @@ private: virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ); + virtual DEBUG_CALLBACK_RESULT OnModuleUnload( ULONG64 offset, const std::string &name ); + private: typedef std::map BpMap; diff --git a/pykd/module.cpp b/pykd/module.cpp index 0c9bad4..d5f0af4 100644 --- a/pykd/module.cpp +++ b/pykd/module.cpp @@ -8,12 +8,58 @@ namespace pykd { /////////////////////////////////////////////////////////////////////////////////// -ModulePtr Module::loadModuleByName( const std::string &moduleName ) { - return ModulePtr( new Module( moduleName ) ); +Module::ModuleList Module::m_moduleList; + +/////////////////////////////////////////////////////////////////////////////////// + +ModulePtr Module::loadModuleByName( const std::string &moduleName ) +{ + + ModuleList::iterator it; + for ( it = m_moduleList.begin(); it != m_moduleList.end(); ++it ) + { + if ( (*it)->m_name == moduleName ) + return *it; + } + + ModulePtr modPtr = ModulePtr( new Module( moduleName ) ); + + m_moduleList.push_back( modPtr ); + + return modPtr; }; -ModulePtr Module::loadModuleByOffset( ULONG64 offset ) { - return ModulePtr( new Module( offset ) ); +///////////////////////////////////////////////////////////////////////////////////// + +ModulePtr Module::loadModuleByOffset( ULONG64 offset ) +{ + ModuleList::iterator it; + for ( it = m_moduleList.begin(); it != m_moduleList.end(); ++it ) + { + if ( (*it)->m_base <= offset && offset < (*it)->m_base + (*it)->m_size ) + return *it; + } + + ModulePtr modPtr = ModulePtr( new Module( offset ) ); + + m_moduleList.push_back( modPtr ); + + return modPtr; +} + +///////////////////////////////////////////////////////////////////////////////////// + +void Module::onUnloadModule( ULONG64 offset ) +{ + ModuleList::iterator it; + for ( it = m_moduleList.begin(); it != m_moduleList.end(); ++it ) + { + if ( (*it)->m_base == offset ) + { + m_moduleList.erase( it ); + return; + } + } } ///////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/module.h b/pykd/module.h index 645fc6b..46c5b4e 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -24,6 +24,14 @@ public: static ModulePtr loadModuleByOffset( ULONG64 offset ); + static + void onUnloadModule( ULONG64 offset ); + +private: + + typedef std::list ModuleList; + static ModuleList m_moduleList; + public: Module(const std::string &name );