Skip to content

Commit

Permalink
[LIBGEN] Fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed May 26, 2024
1 parent 1105cee commit 6e1a13c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tools/libgen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,12 @@ void DestroySymbolList(SYMBOL_INFO *pSymbolList)
}
}

HANDLE MappingHandle;

FILE_INFO* CreateMappedFile(char *pFileName, DWORD MaxSize)
{
FILE_INFO *pFileInfo;
HANDLE MappingHandle;
//HANDLE MappingHandle;
DWORD FileNameLength;

pFileInfo = (FILE_INFO*)malloc(sizeof(FILE_INFO));
Expand All @@ -629,13 +631,15 @@ FILE_INFO* CreateMappedFile(char *pFileName, DWORD MaxSize)

MappingHandle = CreateFileMappingW(pFileInfo->Handle, NULL, 4, 0, MaxSize, NULL);

pFileInfo->pAddress = (UCHAR*)VirtualAlloc(NULL, MaxSize, 0x102000, 4);
//pFileInfo->pAddress = (UCHAR*)VirtualAlloc(NULL, MaxSize, 0x102000, 4);

VirtualFree(pFileInfo->pAddress, 0, 0x8000);
//VirtualFree(pFileInfo->pAddress, 0, 0x8000);

MapViewOfFileEx(MappingHandle, 0xF001F, 0, 0, MaxSize, pFileInfo->pAddress);
//MapViewOfFileEx(MappingHandle, 0xF001F, 0, 0, MaxSize, pFileInfo->pAddress);

CloseHandle(MappingHandle);
pFileInfo->pAddress = (UCHAR *)MapViewOfFileEx(MappingHandle, 0xF001F, 0, 0, MaxSize, 0);

//CloseHandle(MappingHandle);

pFileInfo->MaxSize = MaxSize;
pFileInfo->Offset = 0;
Expand All @@ -647,6 +651,8 @@ void DestroyMappedFile(FILE_INFO *pFileInfo)
{
UnmapViewOfFile(pFileInfo->pAddress);

CloseHandle(MappingHandle);

SetFilePointer(pFileInfo->Handle, pFileInfo->Offset, NULL, 0);

SetEndOfFile(pFileInfo->Handle);
Expand Down Expand Up @@ -1552,6 +1558,7 @@ int main(int argc, char* argv[])
//AddFunction(pSymbolList, "fibonacci_index", 0, 0, CALLING_CONVENTION_STDCALL, IMPORT_BY_DECORATED_NAME);

WriteImportLibrary(fileName, pName, ".dll", pSymbolList);
printf("");
fflush(0);

//DestroySymbolList(pSymbolList);
Expand Down

0 comments on commit 6e1a13c

Please sign in to comment.