CModule: light cleanup

Remove the option to disable dynamic init, it was broken anyways as the string was getting constructed, and therefore, dynamic memory could be allocated if string exceeds a certain size where it has to be moved from stack to heap. The only functions we were interested in, while not allocating anything have been made static instead in the last refactor round.
This commit is contained in:
Kawe Mazidjatari 2023-07-08 03:01:54 +02:00
parent ca423c0dcf
commit b4cd72034e
2 changed files with 42 additions and 21 deletions

View File

@ -19,10 +19,10 @@ public:
typedef unordered_map<string, ModuleSections_t> ModuleSectionsMap_t;
CModule(void) = default;
CModule(const char* szModuleName, const bool bDynamicInit = true);
CModule(const char* szModuleName, const QWORD nModuleBase, const bool bDynamicInit = true);
CModule(const char* szModuleName);
CModule(const QWORD nModuleBase);
void Init(const bool bInitSections);
void Init();
void LoadSections();
CMemory FindPatternSIMD(const char* szPattern, const ModuleSections_t* moduleSection = nullptr) const;

View File

@ -9,39 +9,60 @@
//-----------------------------------------------------------------------------
// Purpose: constructor
// Input : *szModuleName -
// bDynamicInit - set this to false if there is no memory allocator
//-----------------------------------------------------------------------------
CModule::CModule(const char* szModuleName, const bool bDynamicInit)
: m_ModuleName(szModuleName)
CModule::CModule(const char* szModuleName)
{
m_pModuleBase = reinterpret_cast<QWORD>(GetModuleHandleA(szModuleName));
Init(bDynamicInit);
if (!m_pModuleBase)
{
Assert(0);
return;
}
m_ModuleName = szModuleName;
Init();
}
//-----------------------------------------------------------------------------
// Purpose: constructor
// Input : *szModuleName -
// nModuleBase -
// Input : *nModuleBase -
//-----------------------------------------------------------------------------
CModule::CModule(const char* szModuleName, const QWORD nModuleBase,
const bool bDynamicInit)
: m_ModuleName(szModuleName)
, m_pModuleBase(nModuleBase)
CModule::CModule(const QWORD nModuleBase)
{
Init(bDynamicInit);
m_pModuleBase = nModuleBase;
if(!m_pModuleBase)
{
Assert(0);
return;
}
Init();
CHAR szModuleName[MAX_FILEPATH];
DWORD m = GetModuleFileNameA(reinterpret_cast<HMODULE>(nModuleBase),
szModuleName, sizeof(szModuleName));
if ((m - 1) > (sizeof(szModuleName) - 2)) // Too small for buffer.
{
snprintf(szModuleName, sizeof(szModuleName),
"module@%p", (void*)nModuleBase);
m_ModuleName = szModuleName;
}
else
{
m_ModuleName = strrchr(szModuleName, '\\') + 1;
}
}
//-----------------------------------------------------------------------------
// Purpose: initializes module descriptors
//-----------------------------------------------------------------------------
void CModule::Init(const bool bInitSections)
void CModule::Init()
{
m_nModuleSize = static_cast<size_t>(GetNTHeaders()->OptionalHeader.SizeOfImage);
if (bInitSections)
{
LoadSections();
}
m_nModuleSize = GetNTHeaders()->OptionalHeader.SizeOfImage;
LoadSections();
}
//-----------------------------------------------------------------------------