@@ -276,13 +276,27 @@ exportData ProcessModules::GetExport( const ModuleData* hMod, const char* name_o
276
276
277
277
_memory.Read ( hMod->baseAddress + expBase, expSize, pExpData );
278
278
279
- WORD *pAddressOfOrds = reinterpret_cast <WORD*> (
279
+ // Fix invalid directory size
280
+ if (expSize <= sizeof ( IMAGE_EXPORT_DIRECTORY ))
281
+ {
282
+ // New size should take care of max number of present names (max name length is assumed to be 255 chars)
283
+ expSize = static_cast <DWORD>(
284
+ pExpData->AddressOfNameOrdinals - expBase
285
+ + max ( pExpData->NumberOfFunctions , pExpData->NumberOfNames ) * 255
286
+ );
287
+
288
+ expData.reset ( reinterpret_cast <IMAGE_EXPORT_DIRECTORY*>(malloc ( expSize )) );
289
+ pExpData = expData.get ();
290
+ _memory.Read ( hMod->baseAddress + expBase, expSize, pExpData );
291
+ }
292
+
293
+ WORD* pAddressOfOrds = reinterpret_cast <WORD*>(
280
294
pExpData->AddressOfNameOrdinals + reinterpret_cast <uintptr_t >(pExpData) - expBase);
281
295
282
- DWORD * pAddressOfNames = reinterpret_cast <DWORD*>(
296
+ DWORD* pAddressOfNames = reinterpret_cast <DWORD*>(
283
297
pExpData->AddressOfNames + reinterpret_cast <uintptr_t >(pExpData) - expBase);
284
298
285
- DWORD * pAddressOfFuncs = reinterpret_cast <DWORD*>(
299
+ DWORD* pAddressOfFuncs = reinterpret_cast <DWORD*>(
286
300
pExpData->AddressOfFunctions + reinterpret_cast <uintptr_t >(pExpData) - expBase);
287
301
288
302
for (DWORD i = 0 ; i < pExpData->NumberOfFunctions ; ++i)
0 commit comments