Skip to content

Commit 38aa679

Browse files
committed
kinda fixed problems with symbol parser resulting in deadlock (rip in pieces Download Manager. gone but not forgotten.
1 parent 70e5774 commit 38aa679

File tree

8 files changed

+95
-187
lines changed

8 files changed

+95
-187
lines changed

GH Injector Library/Download Manager.cpp

Lines changed: 0 additions & 94 deletions
This file was deleted.

GH Injector Library/Download Manager.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

GH Injector Library/Error.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,28 +226,29 @@
226226
//Symbol errors:
227227
#define SYMBOL_ERR_SUCCESS 0x00000000
228228

229-
//Source : error description
230-
#define SYMBOL_ERR_CANT_OPEN_MODULE 0x40000001 //std::ifstream::good : can't open the specified module
231-
#define SYMBOL_ERR_FILE_SIZE_IS_NULL 0x40000002 //std::ifstream::tellg : file size of the specified module is 0
232-
#define SYMBOL_ERR_CANT_ALLOC_MEMORY_NEW 0x40000003 //operator new : can't allocate memory
233-
#define SYMBOL_ERR_INVALID_FILE_ARCHITECTURE 0x40000004 //internal error : the architecture of the specified file doesn't match AMD64 or I386
234-
#define SYMBOL_ERR_CANT_ALLOC_MEMORY 0x40000005 //VirtualAlloc : can't allocate memory
235-
#define SYMBOL_ERR_NO_PDB_DEBUG_DATA 0x40000006 //internal error : debuge directory is emtpy or wrong type
236-
#define SYMBOL_ERR_PATH_DOESNT_EXIST 0x40000007 //CreateDirectoryA : path doesn't exit and can't be created
237-
#define SYMBOL_ERR_CANT_CREATE_DIRECTORY 0x40000008 //CreateDirectoryA : path doesn't exit and can't be created (x86/x64 subdirectory)
238-
#define SYMBOL_ERR_CANT_CONVERT_PDB_GUID 0x40000008 //StringFromGUID2 : conversion of the GUID to string failed
239-
#define SYMBOL_ERR_GUID_TO_ANSI_FAILED 0x40000009 //wcstombs_s : conversion of GUID to ANSI string failed
240-
#define SYMBOL_ERR_DOWNLOAD_FAILED 0x4000000A //URLDownloadToFileA : downloading the pdb file failed
241-
#define SYMBOL_ERR_CANT_ACCESS_PDB_FILE 0x4000000B //GetFileAttributesExA : can't access the pdb file
242-
#define SYMBOL_ERR_CANT_OPEN_PDB_FILE 0x4000000C //CreateFileA : can't open the pdb file
243-
#define SYMBOL_ERR_CANT_OPEN_PROCESS 0x4000000D //OpenProcess : can't open handle to current process
244-
#define SYMBOL_ERR_SYM_INIT_FAIL 0x4000000E //SymInitialize : couldn't initialize pdb symbol stuff
245-
#define SYMBOL_ERR_SYM_LOAD_TABLE 0x4000000F //SymLoadModule64 : couldn't load symbol table
246-
#define SYMBOL_ERR_ALREADY_INITIALIZED 0x40000010 //internal error : this instance of the SYMBOL_PARSER has already been initialized
247-
#define SYMBOL_ERR_NOT_INITIALIZED 0x40000011 //internal error : this isntance of the SYMBOL_PARSER hasn't benen initialized
248-
#define SYMBOL_ERR_IVNALID_SYMBOL_NAME 0x40000012 //internal error : szSymbolName is NULL
249-
#define SYMBOL_ERR_SYMBOL_SEARCH_FAILED 0x40000013 //SymFromName : couldn't find szSymbolName in the specified pdb
250-
#define SYMBOL_CANT_OPEN_PROCESS 0x40000014 //OpenProcess : can't get PROCESS_QUERY_LIMITED_INFORMATION handle to current process
229+
//Source : error description
230+
#define SYMBOL_ERR_CANT_OPEN_MODULE 0x40000001 //std::ifstream::good : can't open the specified module
231+
#define SYMBOL_ERR_FILE_SIZE_IS_NULL 0x40000002 //std::ifstream::tellg : file size of the specified module is 0
232+
#define SYMBOL_ERR_CANT_ALLOC_MEMORY_NEW 0x40000003 //operator new : can't allocate memory
233+
#define SYMBOL_ERR_INVALID_FILE_ARCHITECTURE 0x40000004 //internal error : the architecture of the specified file doesn't match AMD64 or I386
234+
#define SYMBOL_ERR_CANT_ALLOC_MEMORY 0x40000005 //VirtualAlloc : can't allocate memory
235+
#define SYMBOL_ERR_NO_PDB_DEBUG_DATA 0x40000006 //internal error : debuge directory is emtpy or wrong type
236+
#define SYMBOL_ERR_PATH_DOESNT_EXIST 0x40000007 //CreateDirectoryA : path doesn't exit and can't be created
237+
#define SYMBOL_ERR_CANT_CREATE_DIRECTORY 0x40000008 //CreateDirectoryA : path doesn't exit and can't be created (x86/x64 subdirectory)
238+
#define SYMBOL_ERR_CANT_CONVERT_PDB_GUID 0x40000008 //StringFromGUID2 : conversion of the GUID to string failed
239+
#define SYMBOL_ERR_GUID_TO_ANSI_FAILED 0x40000009 //wcstombs_s : conversion of GUID to ANSI string failed
240+
#define SYMBOL_ERR_DOWNLOAD_FAILED 0x4000000A //URLDownloadToCacheFileA : downloading the pdb file failed
241+
#define SYMBOL_ERR_CANT_ACCESS_PDB_FILE 0x4000000B //GetFileAttributesExA : can't access the pdb file
242+
#define SYMBOL_ERR_CANT_OPEN_PDB_FILE 0x4000000C //CreateFileA : can't open the pdb file
243+
#define SYMBOL_ERR_CANT_OPEN_PROCESS 0x4000000D //OpenProcess : can't open handle to current process
244+
#define SYMBOL_ERR_SYM_INIT_FAIL 0x4000000E //SymInitialize : couldn't initialize pdb symbol stuff
245+
#define SYMBOL_ERR_SYM_LOAD_TABLE 0x4000000F //SymLoadModule64 : couldn't load symbol table
246+
#define SYMBOL_ERR_ALREADY_INITIALIZED 0x40000010 //internal error : this instance of the SYMBOL_PARSER has already been initialized
247+
#define SYMBOL_ERR_NOT_INITIALIZED 0x40000011 //internal error : this isntance of the SYMBOL_PARSER hasn't benen initialized
248+
#define SYMBOL_ERR_IVNALID_SYMBOL_NAME 0x40000012 //internal error : szSymbolName is NULL
249+
#define SYMBOL_ERR_SYMBOL_SEARCH_FAILED 0x40000013 //SymFromName : couldn't find szSymbolName in the specified pdb
250+
#define SYMBOL_CANT_OPEN_PROCESS 0x40000014 //OpenProcess : can't get PROCESS_QUERY_LIMITED_INFORMATION handle to current process
251+
#define SYMBOL_ERR_COPYFILE_FAILED 0x40000015 //CopyFileA : copying the file from the cache directory failed
251252

252253

253254

GH Injector Library/GH Injector Library.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
</Link>
165165
</ItemDefinitionGroup>
166166
<ItemGroup>
167-
<ClInclude Include="Download Manager.h" />
168167
<ClInclude Include="Eject.h" />
169168
<ClInclude Include="Error.h" />
170169
<ClInclude Include="Handle Hijacking.h" />
@@ -182,7 +181,6 @@
182181
<ClInclude Include="WOW64 Shells.h" />
183182
</ItemGroup>
184183
<ItemGroup>
185-
<ClCompile Include="Download Manager.cpp" />
186184
<ClCompile Include="Eject.cpp" />
187185
<ClCompile Include="Handle Hijacking.cpp" />
188186
<ClCompile Include="Hook Scanner WOW64.cpp" />

GH Injector Library/GH Injector Library.vcxproj.filters

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@
8181
<ClInclude Include="WOW64 Shells.h">
8282
<Filter>Quelldateien\wow64\Injection Methods</Filter>
8383
</ClInclude>
84-
<ClInclude Include="Download Manager.h">
85-
<Filter>Headerdateien</Filter>
86-
</ClInclude>
8784
</ItemGroup>
8885
<ItemGroup>
8986
<ClCompile Include="Handle Hijacking.cpp">
@@ -164,8 +161,5 @@
164161
<ClCompile Include="Injection Generic WOW64.cpp">
165162
<Filter>Quelldateien\wow64\Injection Methods</Filter>
166163
</ClCompile>
167-
<ClCompile Include="Download Manager.cpp">
168-
<Filter>Quelldateien</Filter>
169-
</ClCompile>
170164
</ItemGroup>
171165
</Project>

GH Injector Library/Symbol Parser.cpp

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
SYMBOL_PARSER::SYMBOL_PARSER()
66
{
77
m_Initialized = false;
8+
m_Ready = false;
89
m_SymbolTable = 0;
910
m_Filesize = 0;
1011
m_hPdbFile = nullptr;
@@ -15,14 +16,22 @@ SYMBOL_PARSER::~SYMBOL_PARSER()
1516
{
1617
if (m_Initialized)
1718
{
18-
SymUnloadModule64(m_hProcess, m_SymbolTable);
19+
if (m_SymbolTable)
20+
{
21+
SymUnloadModule64(m_hProcess, m_SymbolTable);
22+
}
1923

2024
SymCleanup(m_hProcess);
25+
}
2126

27+
if (m_hProcess)
28+
{
2229
CloseHandle(m_hProcess);
23-
CloseHandle(m_hPdbFile);
30+
}
2431

25-
m_Initialized = false;
32+
if (m_hPdbFile)
33+
{
34+
CloseHandle(m_hPdbFile);
2635
}
2736
}
2837

@@ -125,7 +134,7 @@ bool SYMBOL_PARSER::VerifyExistingPdb(const GUID & guid)
125134

126135
DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::string path, std::string * pdb_path_out, bool Redownload, bool WaitForConnection)
127136
{
128-
if (m_Initialized)
137+
if (m_Ready)
129138
{
130139
return SYMBOL_ERR_ALREADY_INITIALIZED;
131140
}
@@ -328,26 +337,27 @@ DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::strin
328337
while (InternetCheckConnectionA("https://msdl.microsoft.com", FLAG_ICC_FORCE_CONNECTION, NULL) == FALSE)
329338
{
330339
Sleep(10);
340+
}
341+
}
331342

332-
if (WaitForSingleObject(DownloadManager::hInterrupEvent, 0) == WAIT_OBJECT_0)
333-
{
334-
VirtualFree(pLocalImageBase, 0, MEM_RELEASE);
343+
char szCacheFile[MAX_PATH]{ 0 };
335344

336-
delete[] pRawData;
345+
if (FAILED(URLDownloadToCacheFileA(nullptr, url.c_str(), szCacheFile, MAX_PATH , NULL, nullptr)))
346+
{
347+
VirtualFree(pLocalImageBase, 0, MEM_RELEASE);
337348

338-
return SYMBOL_ERR_DOWNLOAD_FAILED;
339-
}
340-
}
349+
delete[] pRawData;
350+
351+
return SYMBOL_ERR_DOWNLOAD_FAILED;
341352
}
342353

343-
DownloadManager dm;
344-
if (FAILED(URLDownloadToFileA(nullptr, url.c_str(), m_szPdbPath.c_str(), NULL, &dm)))
354+
if (!CopyFileA(szCacheFile, m_szPdbPath.c_str(), FALSE))
345355
{
346356
VirtualFree(pLocalImageBase, 0, MEM_RELEASE);
347357

348358
delete[] pRawData;
349359

350-
return SYMBOL_ERR_DOWNLOAD_FAILED;
360+
return SYMBOL_ERR_COPYFILE_FAILED;
351361
}
352362
}
353363

@@ -365,24 +375,24 @@ DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::strin
365375
Filesize = file_attr_data.nFileSizeLow;
366376
}
367377

368-
HANDLE hPdbFile = CreateFileA(m_szPdbPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, NULL, nullptr);
369-
if (hPdbFile == INVALID_HANDLE_VALUE)
378+
m_hPdbFile = CreateFileA(m_szPdbPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, NULL, nullptr);
379+
if (m_hPdbFile == INVALID_HANDLE_VALUE)
370380
{
371381
return SYMBOL_ERR_CANT_OPEN_PDB_FILE;
372382
}
373383

374384
m_hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, GetCurrentProcessId());
375385
if (!m_hProcess)
376386
{
377-
CloseHandle(hPdbFile);
387+
CloseHandle(m_hPdbFile);
378388

379389
return SYMBOL_ERR_CANT_OPEN_PROCESS;
380390
}
381391

382392
if (!SymInitialize(m_hProcess, m_szPdbPath.c_str(), FALSE))
383393
{
384394
CloseHandle(m_hProcess);
385-
CloseHandle(hPdbFile);
395+
CloseHandle(m_hPdbFile);
386396

387397
return SYMBOL_ERR_SYM_INIT_FAIL;
388398
}
@@ -395,7 +405,7 @@ DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::strin
395405
SymCleanup(m_hProcess);
396406

397407
CloseHandle(m_hProcess);
398-
CloseHandle(hPdbFile);
408+
CloseHandle(m_hPdbFile);
399409

400410
return SYMBOL_ERR_SYM_LOAD_TABLE;
401411
}
@@ -405,14 +415,14 @@ DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::strin
405415
*pdb_path_out = m_szPdbPath;
406416
}
407417

408-
m_Initialized = true;
418+
m_Ready = true;
409419

410420
return SYMBOL_ERR_SUCCESS;
411421
}
412422

413423
DWORD SYMBOL_PARSER::GetSymbolAddress(const char * szSymbolName, DWORD & RvaOut)
414424
{
415-
if (!m_Initialized)
425+
if (!m_Ready)
416426
{
417427
return SYMBOL_ERR_NOT_INITIALIZED;
418428
}
@@ -432,4 +442,34 @@ DWORD SYMBOL_PARSER::GetSymbolAddress(const char * szSymbolName, DWORD & RvaOut)
432442
RvaOut = (DWORD)(si.Address - si.ModBase);
433443

434444
return SYMBOL_ERR_SUCCESS;
445+
}
446+
447+
void SYMBOL_PARSER::InterruptCleanup()
448+
{
449+
if (m_Initialized)
450+
{
451+
if (m_SymbolTable)
452+
{
453+
SymUnloadModule64(m_hProcess, m_SymbolTable);
454+
}
455+
456+
SymCleanup(m_hProcess);
457+
}
458+
459+
if (m_hProcess)
460+
{
461+
CloseHandle(m_hProcess);
462+
}
463+
464+
if (m_hPdbFile)
465+
{
466+
CloseHandle(m_hPdbFile);
467+
}
468+
469+
m_Initialized = false;
470+
m_Ready = false;
471+
m_SymbolTable = 0;
472+
m_Filesize = 0;
473+
m_hPdbFile = nullptr;
474+
m_hProcess = nullptr;
435475
}

0 commit comments

Comments
 (0)