Fix a problem with LoadDll.hFile and committing gigabytes of memory on attach

This commit is contained in:
Duncan Ogilvie 2017-10-24 00:04:56 +02:00
parent 5d1e43bb69
commit 587183f984
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
1 changed files with 6 additions and 3 deletions

View File

@ -165,7 +165,8 @@ __declspec(dllexport) void TITCALL DebugLoop()
myCustomHandler(&DBGEvent.u.CreateProcessInfo); myCustomHandler(&DBGEvent.u.CreateProcessInfo);
} }
EngineCloseHandle(DBGFileHandle); //close file handle if(DBGFileHandle)
EngineCloseHandle(DBGFileHandle); //close file handle
} }
break; break;
@ -258,7 +259,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
memset(&NewLibraryData, 0, sizeof(LIBRARY_ITEM_DATAW)); memset(&NewLibraryData, 0, sizeof(LIBRARY_ITEM_DATAW));
NewLibraryData.hFile = DBGEvent.u.LoadDll.hFile; NewLibraryData.hFile = DBGEvent.u.LoadDll.hFile;
NewLibraryData.BaseOfDll = DBGEvent.u.LoadDll.lpBaseOfDll; NewLibraryData.BaseOfDll = DBGEvent.u.LoadDll.lpBaseOfDll;
hFileMapping = CreateFileMappingA(DBGEvent.u.LoadDll.hFile, NULL, PAGE_READONLY, NULL, GetFileSize(DBGEvent.u.LoadDll.hFile, NULL), NULL); hFileMapping = DBGEvent.u.LoadDll.hFile ? CreateFileMappingA(DBGEvent.u.LoadDll.hFile, NULL, PAGE_READONLY, 0, 0, NULL) : NULL;
if(hFileMapping != NULL) if(hFileMapping != NULL)
{ {
hFileMappingView = MapViewOfFile(hFileMapping, FILE_MAP_READ, NULL, NULL, NULL); hFileMappingView = MapViewOfFile(hFileMapping, FILE_MAP_READ, NULL, NULL, NULL);
@ -331,6 +332,9 @@ __declspec(dllexport) void TITCALL DebugLoop()
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chLoadDll); myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chLoadDll);
myCustomHandler(&DBGEvent.u.LoadDll); myCustomHandler(&DBGEvent.u.LoadDll);
} }
if(DBGEvent.u.LoadDll.hFile)
EngineCloseHandle(DBGEvent.u.LoadDll.hFile); //close file handle
} }
break; break;
@ -379,7 +383,6 @@ __declspec(dllexport) void TITCALL DebugLoop()
UnmapViewOfFile(hListLibrary.at(i).hFileMappingView); UnmapViewOfFile(hListLibrary.at(i).hFileMappingView);
EngineCloseHandle(hListLibrary.at(i).hFileMapping); EngineCloseHandle(hListLibrary.at(i).hFileMapping);
} }
EngineCloseHandle(hListLibrary.at(i).hFile);
hListLibrary.erase(hListLibrary.begin() + i); hListLibrary.erase(hListLibrary.begin() + i);
break; break;
} }