Skip to content

Commit 8d2d0b7

Browse files
committed
Added exported function to check pdb download state, downloading functions now wait until a connection has been established
1 parent d86a3e2 commit 8d2d0b7

File tree

10 files changed

+58
-8
lines changed

10 files changed

+58
-8
lines changed

GH Injector Library/Import Handler WOW64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ DWORD ResolveImports_WOW64(ERROR_DATA & error_data)
112112
return INJ_ERR_WOW64_NTDLL_MISSING;
113113
}
114114

115-
if (sym_ntdll_wow64_ret.wait_for(std::chrono::milliseconds(100)) != std::future_status::ready)
115+
if (sym_ntdll_wow64_ret.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready)
116116
{
117117
INIT_ERROR_DATA(error_data, INJ_ERR_ADVANCED_NOT_DEFINED);
118118

GH Injector Library/Import Handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ DWORD ResolveImports(ERROR_DATA & error_data)
3131
WIN32_FUNC_INIT(GetLastError, hK32);
3232
if (!NATIVE::pLoadLibraryExW || !NATIVE::pGetLastError) return INJ_ERR_GET_PROC_ADDRESS_FAIL;
3333

34-
if (sym_ntdll_native_ret.wait_for(std::chrono::milliseconds(100)) != std::future_status::ready)
34+
if (sym_ntdll_native_ret.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready)
3535
{
3636
INIT_ERROR_DATA(error_data, INJ_ERR_ADVANCED_NOT_DEFINED);
3737

GH Injector Library/Injection.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,35 @@ HRESULT __stdcall GetVersionW(wchar_t * out, size_t cb_size)
531531
}
532532

533533
return StringCbCopyW(out, cb_size, GH_INJ_VERSIONW);
534+
}
535+
536+
DWORD __stdcall GetSymbolState()
537+
{
538+
#pragma EXPORT_FUNCTION(__FUNCTION__, __FUNCDNAME__)
539+
540+
if (sym_ntdll_native_ret.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready)
541+
{
542+
return INJ_ERR_SYMBOL_INIT_NOT_DONE;
543+
}
544+
545+
DWORD sym_ret = sym_ntdll_native_ret.get();
546+
if (sym_ret != SYMBOL_ERR_SUCCESS)
547+
{
548+
return sym_ret;
549+
}
550+
551+
#ifdef _WIN64
552+
if (sym_ntdll_wow64_ret.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready)
553+
{
554+
return INJ_ERR_SYMBOL_INIT_NOT_DONE;
555+
}
556+
557+
sym_ret = sym_ntdll_wow64_ret.get();
558+
if (sym_ret != SYMBOL_ERR_SUCCESS)
559+
{
560+
return sym_ret;
561+
}
562+
#endif
563+
564+
return SYMBOL_ERR_SUCCESS;
534565
}

GH Injector Library/Injection.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,8 @@ DWORD __stdcall InjectW(INJECTIONDATAW * pData);
8181

8282
//Returns the version string of the current instance
8383
HRESULT __stdcall GetVersionA(char * out, size_t cb_size);
84-
HRESULT __stdcall GetVersionW(wchar_t * out, size_t cb_size);
84+
HRESULT __stdcall GetVersionW(wchar_t * out, size_t cb_size);
85+
86+
//Returns the state of the symbol download threads
87+
//If finished SYMBOL_ERR_SUCCESS (0) is returned
88+
DWORD __stdcall GetSymbolState();

GH Injector Library/Symbol Parser.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bool SYMBOL_PARSER::VerifyExistingPdb(const GUID & guid)
124124
return (guid_eq == 0);
125125
}
126126

127-
DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::string path, std::string * pdb_path_out, bool Redownload)
127+
DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::string path, std::string * pdb_path_out, bool Redownload, bool WaitForConnection)
128128
{
129129
if (m_Initialized)
130130
{
@@ -325,8 +325,17 @@ DWORD SYMBOL_PARSER::Initialize(const std::string szModulePath, const std::strin
325325
url += '/';
326326
url += pdb_info->PdbFileName;
327327

328+
if (WaitForConnection)
329+
{
330+
while (InternetCheckConnectionA("https://msdl.microsoft.com", FLAG_ICC_FORCE_CONNECTION, NULL) == FALSE)
331+
{
332+
Sleep(25);
333+
}
334+
}
335+
328336
if (FAILED(URLDownloadToFileA(nullptr, url.c_str(), m_szPdbPath.c_str(), NULL, nullptr)))
329337
{
338+
MessageBoxA(0, "Feels bad man", 0, 0);
330339
VirtualFree(pLocalImageBase, 0, MEM_RELEASE);
331340

332341
delete[] pRawData;

GH Injector Library/Symbol Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SYMBOL_PARSER
2424
SYMBOL_PARSER();
2525
~SYMBOL_PARSER();
2626

27-
DWORD Initialize(const std::string szModulePath, const std::string path, std::string * pdb_path_out, bool Redownload);
27+
DWORD Initialize(const std::string szModulePath, const std::string path, std::string * pdb_path_out, bool Redownload, bool WaitForConnection = false);
2828
DWORD GetSymbolAddress(const char * szSymbolName, DWORD & RvaOut);
2929
};
3030

GH Injector Library/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ BOOL WINAPI DllMain(HINSTANCE hDll, DWORD dwReason, void * pReserved)
6060
std::string szNtDllWOW64 = szWindowsDir;
6161
szNtDllWOW64 += "\\SysWOW64\\ntdll.dll";
6262

63-
sym_ntdll_wow64_ret = std::async(std::launch::async, &SYMBOL_PARSER::Initialize, &sym_ntdll_wow64, szNtDllWOW64, g_RootPathA, nullptr, false);
63+
sym_ntdll_wow64_ret = std::async(std::launch::async, &SYMBOL_PARSER::Initialize, &sym_ntdll_wow64, szNtDllWOW64, g_RootPathA, nullptr, false, true);
6464
#endif
6565

6666
std::string szNtDllNative = szWindowsDir;
6767
szNtDllNative += "\\System32\\ntdll.dll";
6868

69-
sym_ntdll_native_ret = std::async(std::launch::async, &SYMBOL_PARSER::Initialize, &sym_ntdll_native, szNtDllNative, g_RootPathA, nullptr, false);
69+
sym_ntdll_native_ret = std::async(std::launch::async, &SYMBOL_PARSER::Initialize, &sym_ntdll_native, szNtDllNative, g_RootPathA, nullptr, false, true);
7070

7171
delete[] szWindowsDir;
7272
}

GH Injector Library/pch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma comment(lib, "wtsapi32.lib")
44
#pragma comment(lib, "DbgHelp.lib")
55
#pragma comment(lib, "Urlmon.lib")
6+
#pragma comment(lib, "WinInet.lib")
67

78
#if (PSAPI_VERSION == 1)
89
#pragma comment(lib, "Psapi.lib")

GH Injector Library/pch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <urlmon.h>
2828
#include <future>
2929

30+
//internet shit
31+
#include <WinInet.h>
32+
3033
//warning shit
3134
#pragma warning(disable: 4201) //unnamed union
3235
#pragma warning(disable: 4324) //structure member alignment resulting in additional bytes being added as padding

Injection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,6 @@ using f_ValidateInjectionFunctions = bool(__stdcall*)(DWORD dwTargetProcessId, D
141141
using f_RestoreInjectionFunctions = bool(__stdcall*)(DWORD dwTargetProcessId, DWORD & ErrorCode, DWORD & LastWin32Error, HookInfo * HookDataIn, UINT Count, UINT * CountOut);
142142

143143
using f_GetVersionA = HRESULT(__stdcall *)(char * out, size_t cb_size);
144-
using f_GetVersionW = HRESULT(__stdcall *)(wchar_t * out, size_t cb_size);
144+
using f_GetVersionW = HRESULT(__stdcall *)(wchar_t * out, size_t cb_size);
145+
146+
using f_GetSymbolState = DWORD(__stdcall *)();

0 commit comments

Comments
 (0)