Skip to content

Commit 8b6a794

Browse files
committed
fixed DarthTon#146
1 parent 76b626a commit 8b6a794

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/BlackBone/Process/ProcessModules.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,27 @@ exportData ProcessModules::GetExport( const ModuleData* hMod, const char* name_o
276276

277277
_memory.Read( hMod->baseAddress + expBase, expSize, pExpData );
278278

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*>(
280294
pExpData->AddressOfNameOrdinals + reinterpret_cast<uintptr_t>(pExpData) - expBase);
281295

282-
DWORD *pAddressOfNames = reinterpret_cast<DWORD*>(
296+
DWORD* pAddressOfNames = reinterpret_cast<DWORD*>(
283297
pExpData->AddressOfNames + reinterpret_cast<uintptr_t>(pExpData) - expBase);
284298

285-
DWORD *pAddressOfFuncs = reinterpret_cast<DWORD*>(
299+
DWORD* pAddressOfFuncs = reinterpret_cast<DWORD*>(
286300
pExpData->AddressOfFunctions + reinterpret_cast<uintptr_t>(pExpData) - expBase);
287301

288302
for (DWORD i = 0; i < pExpData->NumberOfFunctions; ++i)

0 commit comments

Comments
 (0)