Skip to content

Commit dd64958

Browse files
committed
v3.4 beta
1 parent 477109a commit dd64958

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2906
-906
lines changed

GH Injector Library/Download Manager.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ DownloadManager::DownloadManager()
66
{
77
m_hInterruptEvent = nullptr;
88
m_fProgress = 0.0f;
9+
m_fOldProgress = 0.0f;
910
}
1011

1112
DownloadManager::~DownloadManager()
@@ -39,20 +40,26 @@ HRESULT __stdcall DownloadManager::OnStartBinding(DWORD dwReserved, IBinding * p
3940
UNREFERENCED_PARAMETER(dwReserved);
4041
UNREFERENCED_PARAMETER(pib);
4142

43+
LOG(" DownloadManager: OnStartBinding\n");
44+
4245
return S_OK;
4346
}
4447

4548
HRESULT __stdcall DownloadManager::GetPriority(LONG * pnPriority)
4649
{
4750
UNREFERENCED_PARAMETER(pnPriority);
4851

52+
LOG(" DownloadManager: GetPriority\n");
53+
4954
return S_OK;
5055
}
5156

5257
HRESULT __stdcall DownloadManager::OnLowResource(DWORD reserved)
5358
{
5459
UNREFERENCED_PARAMETER(reserved);
5560

61+
LOG(" DownloadManager: OnLowResource\n");
62+
5663
return S_OK;
5764
}
5865

@@ -61,14 +68,18 @@ HRESULT __stdcall DownloadManager::OnStopBinding(HRESULT hresult, LPCWSTR szErro
6168
UNREFERENCED_PARAMETER(hresult);
6269
UNREFERENCED_PARAMETER(szError);
6370

71+
LOG(" DownloadManager: OnStopBinding\n");
72+
6473
return S_OK;
6574
}
6675

67-
HRESULT __stdcall DownloadManager::GetBindInfo(DWORD * grfBINDF, BINDINFO *pbindinfo)
76+
HRESULT __stdcall DownloadManager::GetBindInfo(DWORD * grfBINDF, BINDINFO * pbindinfo)
6877
{
6978
UNREFERENCED_PARAMETER(grfBINDF);
7079
UNREFERENCED_PARAMETER(pbindinfo);
7180

81+
LOG(" DownloadManager: GetBindInfo\n");
82+
7283
return S_OK;
7384
}
7485

@@ -79,6 +90,8 @@ HRESULT __stdcall DownloadManager::OnDataAvailable(DWORD grfBSCF, DWORD dwSize,
7990
UNREFERENCED_PARAMETER(pformatetc);
8091
UNREFERENCED_PARAMETER(pstgmed);
8192

93+
LOG(" DownloadManager: OnDataAvailable\n");
94+
8295
return S_OK;
8396
}
8497

@@ -87,6 +100,8 @@ HRESULT __stdcall DownloadManager::OnObjectAvailable(const IID & riid, IUnknown
87100
UNREFERENCED_PARAMETER(riid);
88101
UNREFERENCED_PARAMETER(punk);
89102

103+
LOG(" DownloadManager: OnObjectAvailable\n");
104+
90105
return S_OK;
91106
}
92107

@@ -97,12 +112,20 @@ HRESULT __stdcall DownloadManager::OnProgress(ULONG ulProgress, ULONG ulProgress
97112

98113
if (m_hInterruptEvent && WaitForSingleObject(m_hInterruptEvent, 0) == WAIT_OBJECT_0)
99114
{
115+
LOG(" DownloadManager: Interrupting download\n");
116+
100117
return E_ABORT;
101118
}
102119

103120
if (ulProgressMax)
104121
{
105122
m_fProgress = (float)ulProgress / ulProgressMax;
123+
124+
if (m_fProgress - m_fOldProgress >= 0.1f)
125+
{
126+
LOG(" DownloadManager: %2.0f%%\n", m_fProgress * 100.0f);
127+
m_fOldProgress = m_fProgress;
128+
}
106129
}
107130

108131
return S_OK;
@@ -115,12 +138,12 @@ BOOL DownloadManager::SetInterruptEvent(HANDLE hInterrupt)
115138
CloseHandle(m_hInterruptEvent);
116139
}
117140

118-
LOG("New interrupt event specified\n");
141+
LOG(" DownloadManager: New interrupt event specified\n");
119142

120143
return DuplicateHandle(GetCurrentProcess(), hInterrupt, GetCurrentProcess(), &m_hInterruptEvent, NULL, FALSE, DUPLICATE_SAME_ACCESS);
121144
}
122145

123146
float DownloadManager::GetDownloadProgress()
124147
{
125148
return m_fProgress;
126-
}
149+
}

GH Injector Library/Download Manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DownloadManager : public IBindStatusCallback
1010
{
1111
HANDLE m_hInterruptEvent;
1212
float m_fProgress;
13+
float m_fOldProgress;
1314

1415
public:
1516

GH Injector Library/Eject.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,50 @@
22

33
#include "Eject.h"
44

5-
//gonna make this better eventually, forgot it existed
6-
7-
void EjectDll(HANDLE hTargetProc, HINSTANCE hModBase)
5+
bool EjectDll(HANDLE hTargetProc, HINSTANCE hModule)
86
{
9-
LOG("Ejecting injection library from hijack process\n");
7+
LOG(" EjectDll called\n");
8+
LOG(" PID = %08X\n", GetProcessId(hTargetProc));
9+
LOG(" hModule = %p\n", hModule);
1010

1111
HANDLE hThread = nullptr;
12-
if (FAILED(NATIVE::NtCreateThreadEx(&hThread, THREAD_ALL_ACCESS, nullptr, hTargetProc, FreeLibrary, ReCa<void*>(hModBase), NULL, 0, 0, 0, nullptr)))
12+
auto ntRet = NATIVE::NtCreateThreadEx(&hThread, THREAD_ALL_ACCESS, nullptr, hTargetProc, NATIVE::LdrUnloadDll, ReCa<void *>(hModule), NULL, 0, 0, 0, nullptr);
13+
if (FAILED(ntRet))
1314
{
14-
LOG("Failed to eject library\n");
15+
LOG(" NtCreateThreadEx failed: %08X\n", ntRet);
1516

16-
return;
17+
return false;
1718
}
1819

19-
WaitForSingleObject(hThread, 500);
20+
if (WaitForSingleObject(hThread, 500) != WAIT_OBJECT_0)
21+
{
22+
LOG(" Ejection thread timed out\n");
23+
24+
TerminateThread(hThread, 0);
25+
CloseHandle(hThread);
26+
27+
return false;
28+
}
29+
30+
if (!GetExitCodeThread(hThread, ReCa<DWORD *>(&ntRet)))
31+
{
32+
LOG(" GetExitCodeThread failed: %08X\n", GetLastError());
33+
34+
CloseHandle(hThread);
35+
36+
return false;
37+
}
2038

2139
CloseHandle(hThread);
2240

23-
LOG("Library ejected\n");
41+
if (NT_FAIL(ntRet))
42+
{
43+
LOG(" LdrUnloadDll failed: %08X\n", ntRet);
44+
45+
return false;
46+
}
47+
48+
LOG(" Dll ejected successfully\n");
49+
50+
return true;
2451
}

GH Injector Library/Eject.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "Import Handler.h"
44

5-
void EjectDll(HANDLE hTargetProc, HINSTANCE hModBase);
6-
//Unloads a Dll using FreeLibrary by creating a thread in the target process using NtCreateThreadEx (native only).
5+
bool EjectDll(HANDLE hTargetProc, HINSTANCE hModule);
6+
//Unloads a dll using LdrUnloadDll by creating a thread in the target process using NtCreateThreadEx (native only).
77
//
88
//Arguments:
99
// hTargetProc (HANDLE):
@@ -13,8 +13,9 @@ void EjectDll(HANDLE hTargetProc, HINSTANCE hModBase);
1313
/// PROCESS_VM_OPERATION
1414
/// PROCESS_VM_WRITE
1515
/// PROCESS_VM_READ
16-
// hModBase (HINSTANCE):
16+
// hModule (HINSTANCE):
1717
/// The baseaddress of the module to unload.
1818
//
19-
//Returnvalue:
20-
/// void
19+
//Returnvalue (bool):
20+
/// true: the module was unloaded successfully.
21+
/// false: something went wrong, see logs

GH Injector Library/Error.h

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#define INJ_ERR_INVALID_PID 0x00000006 //internal error : - : provided process id is 0
2828
#define INJ_ERR_CANT_OPEN_PROCESS 0x00000007 //OpenProcess : win32 error : opening the specified target process failed
2929
#define INJ_ERR_INVALID_PROC_HANDLE 0x00000008 //GetHandleInformation : win32 error : the provided handle value is not a valid handle
30-
#define INJ_ERR_CANT_GET_EXE_FILENAME 0x00000009 //(K32)GetModuleBaseNameW : win32 error : failed to resolve the file name of the target process
30+
#define INJ_ERR_CANT_GET_EXE_FILENAME 0x00000009 //QueryFullProcessImageNameW : win32 error : failed to resolve the file name of the target process
3131
#define INJ_ERR_PLATFORM_MISMATCH 0x0000000A //internal error : file error : the provided file can't be injected (file error 0x20000001 - 0x20000003)
3232
#define INJ_ERR_CANT_GET_TEMP_DIR 0x0000000B //GetTempPathW : win32 error : unable to retrieve the path to the current users temp directory
3333
#define INJ_ERR_CANT_COPY_FILE 0x0000000C //CopyFileW : win32 error : unable to create a copy of the specified dll file
@@ -65,12 +65,18 @@
6565
#define INJ_ERR_CANT_GET_PEB 0x0000002C //__readgsqword or __readfsdword : - : reading the linear address of the PEB failed
6666
#define INJ_ERR_INVALID_PEB_DATA 0x0000002D //internal error : - : peb data required to erase/fake header or unlike the module from the peb wasn't findable
6767
#define INJ_ERR_UPDATE_PROTECTION_FAILED 0x0000002E //NtProtectVirtualMemory : NTSTATUS : updating the page protection of the pe header failed
68-
#define INJ_ERR_WOW64_NTDLL_MISSING 0x0000002F //internal error : - : can't resolve address of the wow64 ntdll
68+
#define INJ_ERR_WOW64_NTDLL_MISSING 0x0000002F //internal error : - : can't resolve address of the wow64 ntdll.dll
6969
#define INJ_ERR_INVALID_PATH_SEPERATOR 0x00000030 //internal error : - : can't find '\' in a path. '/' as seperators aren't supported
7070
#define INJ_ERR_LDRP_PREPROCESS_FAILED 0x00000031 //LdrpPreprocessDllName : NTSTATUS : preprocessing the dll name for LdrpLoadDll(Internal) failed
7171
#define INJ_ERR_INVALID_POINTER 0x00000032 //internal error : - : an invalid funtion pointer was passed to SetRawPrintCallback
7272
#define INJ_ERR_NOT_IMPLEMENTED 0x00000033 //internal error : - : the module was compiled without DEBUG_INFO being defined, check pch.h for more information if you want to redirect debug output
7373
#define INJ_ERR_KERNEL32_MISSING 0x00000034 //internal error : - : failed to resolve address of kernel32.dll (native)
74+
#define INJ_ERR_WOW64_KERNEL32_MISSING 0x00000035 //internal error : - : can't resolve address of the wow64 kernel32.dll
75+
#define INJ_ERR_OPEN_WOW64_PROCESS 0x00000036 //OpenProcess : win32 error : failed to attach to wow64 process to resolve addresses
76+
#define INJ_ERR_IMPORT_HANDLER_NOT_DONE 0x00000037 //internal error : - : import handler isn't finished resolving all required functions or is waiting for symbol parser thread(s) to finish
77+
#define INJ_ERR_WCSRCHR_FAILED 0x00000038 //wcsrchr : - : wcsrchr failed to find a character in a string (usually '\\' in a path)
78+
#define INJ_ERR_TARGET_EXE_NAME_IS_NULL 0x00000039 //internal error : - : the length of the name of the specified process is 0
79+
#define INJ_ERR_LDR_ENTRY_IS_NULL 0x0000003A //internal error : - : LdrpLoadDll(Internal) didn't return a valid LDR_DATA_TABLE_ENTRY pointer
7480

7581

7682
///////////////////
@@ -89,9 +95,10 @@
8995
#define INJ_MM_ERR_IMPORT_FAIL 0x0040000A //internal error : NTSTATUS : one module couldn't be loaded or an import couldn't be resolved, if ntRet is STATUS_HEAP_CORRUPTION, memory allocation failed
9096
#define INJ_MM_ERR_DELAY_IMPORT_FAIL 0x0040000B //internal error : NTSTATUS : one module couldn't be loaded or an import couldn't be resolved, if ntRet is STATUS_HEAP_CORRUPTION, memory allocation failed
9197
#define INJ_MM_ERR_ENABLING_SEH_FAILED 0x0040000C //RtlInsertInvertedFunctionTable : NTSTATUS : enabling exception handling by calling RtlInsertInvertedFunctionTable failed
92-
#define INJ_MM_ERR_INVALID_HEAP_HANDLE 0x0040000D //internal error : - : the provided pointer to the LdrpHeap is invalid
93-
#define INJ_MM_ERR_CANT_GET_PEB 0x0040000E //__readgsqword or __readfsdword : - : reading the linear address of the PEB failed
94-
#define INJ_MM_ERR_INVALID_PEB_DATA 0x0040000F //internal error : - : peb data required to fake header wasn't findable
98+
#define INJ_MM_ERR_NOT_IN_LDRP_SEH_TABLE 0x0040000D //internal error : - : RtlInsertInvertedFunctionTable didn't insert data into LdrpInvertedFunctionTable, manual insertion currently not supported
99+
#define INJ_MM_ERR_INVALID_HEAP_HANDLE 0x0040000E //internal error : - : the provided pointer to the LdrpHeap is invalid
100+
#define INJ_MM_ERR_CANT_GET_PEB 0x0040000F //__readgsqword or __readfsdword : - : reading the linear address of the PEB failed
101+
#define INJ_MM_ERR_INVALID_PEB_DATA 0x00400010 //internal error : - : peb data required to fake header wasn't findable
95102

96103

97104

@@ -159,7 +166,7 @@
159166
#define SR_SWHEX_ERR_GET_ADMIN_TOKEN_FAIL 0x10300006 //GetTokenInformation : win32 error : failed to retrieve information from the token handle
160167
#define SR_SWHEX_ERR_CANT_CREATE_PROCESS 0x10300007 //CreateProcessAsUserW : win32 error : failed to launch SM_EXE_FILENAME.exe to execute shellcode
161168
//CreateProcessW : win32 error : failed to launch SM_EXE_FILENAME.exe to execute shellcode
162-
#define SR_SWHEX_ERR_SWHEX_TIMEOUT 0x10300008 //WaitForSingleObject : win32 error :
169+
#define SR_SWHEX_ERR_SWHEX_TIMEOUT 0x10300008 //WaitForSingleObject : win32 error : SM_EXE_FILENAME.exe execution time exceeded
163170
#define SR_SWHEX_ERR_REMOTE_TIMEOUT 0x10300009 //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT
164171
#define SR_SWHEX_ERR_RPM_FAIL 0x1030000A //ReadProcessMemory : win32 error : reading the results of the shellcode failed
165172

@@ -177,6 +184,27 @@
177184
#define SR_QUAPC_ERR_REMOTE_TIMEOUT 0x10400006 //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT
178185
#define SR_QUAPC_ERR_RPM_FAIL 0x10400007 //WriteProcessMemory : win32 error : reading the results of the shellcode failed
179186

187+
///////////////
188+
///KernelCallback
189+
//Source : advanced error type : error description
190+
191+
#define SR_KC_ERR_CANT_OPEN_INFO_TXT 0x10500001 //internal error : - : can't open kc info file
192+
#define SR_KC_ERR_PROC_INFO_FAIL 0x10500002 //internal error : - : can't grab process information
193+
#define SR_KC_ERR_CANT_GET_PEB 0x10500003 //internal error : - : failed to retrieve pointer to the (wow64) peb
194+
#define SR_KC_ERR_RPM_FAIL 0x10500004 //ReadProcessMemory : win32 error : failed to read memory from the target process
195+
#define SR_KC_ERR_NO_INITIALIZED 0x10500005 //internal error : - : the kernel callback table is not initialized
196+
#define SR_KC_ERR_CANT_ALLOC_MEM 0x10500006 //VirtualAllocEx : win32 error : memory allocation for the shellcode/table failed
197+
#define SR_KC_ERR_WPM_FAIL 0x10500007 //WriteProcessMemory : win32 error : writing the shellcode/table into the target process' memory failed
198+
#define SR_KC_ERR_WTSQUERY_FAIL 0x10500008 //WTSQueryUserToken : win32 error : failed to query the token for the target process user session
199+
#define SR_KC_ERR_DUP_TOKEN_FAIL 0x10500009 //DuplicateTokenEx : win32 error : failed to duplicate the token for the target process user session
200+
#define SR_KC_ERR_GET_ADMIN_TOKEN_FAIL 0x1050000A //GetTokenInformation : win32 error : failed to retrieve information from the token handle
201+
#define SR_KC_ERR_CANT_CREATE_PROCESS 0x1050000B //CreateProcessAsUserW : win32 error : failed to launch SM_EXE_FILENAME.exe to execute shellcode
202+
//CreateProcessW : win32 error : failed to launch SM_EXE_FILENAME.exe to execute shellcode
203+
#define SR_KC_ERR_KC_TIMEOUT 0x1050000C //WaitForSingleObject : win32 error : SM_EXE_FILENAME.exe execution time exceeded
204+
#define SR_KC_ERR_REMOTE_TIMEOUT 0x1050000D //internal error : - : execution time exceeded SR_REMOTE_TIMEOUT
205+
206+
#define SR_KC_ERR_KC_EXT_ERROR 0x1050000E //SM_EXE_FILENAME.exe : "GH Injector SM - XX.exe" error code, 0x50100001 - 0x50100006 (see below) or win32 exception
207+
180208

181209

182210
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -210,9 +238,10 @@
210238
#define SM_ERR_INVALID_ARGV 0x30000002 //main : GH Injector SM - XX.exe was called with invalid arguments
211239

212240
////////////////////////////////////////////////////////////
213-
///GH Injector SM - XX.exe - SetWindowsHookEx specific erros:
214-
#define SWHEX_ERR_SUCCESS 0x00000000
241+
//GH Injector SM - XX.exe specific errors:
215242

243+
///SetWindowHookEx:
244+
#define SWHEX_ERR_SUCCESS 0x00000000
216245
//Source : error description
217246

218247
#define SWHEX_ERR_INVALID_PATH 0x30100001 //StringCchLengthW : path exceeds MAX_PATH * 2 chars
@@ -222,6 +251,17 @@
222251
#define SWHEX_ERR_ENUM_WINDOWS_FAIL 0x30100005 //EnumWindows : API fail
223252
#define SWHEX_ERR_NO_WINDOWS 0x30100006 //internal error : no compatible window found
224253

254+
///KernelCallbackTable
255+
#define KC_ERR_SUCCESS 0x00000000
256+
//Source : error description
257+
258+
#define KC_ERR_INVALID_PATH 0x50100001 //StringCchLengthW : path exceeds MAX_PATH * 2 chars
259+
#define KC_ERR_CANT_OPEN_FILE 0x50100002 //std::ifstream::good : openening the SMXX.txt failed
260+
#define KC_ERR_EMPTY_FILE 0x50100003 //internal error : SMXX.txt is empty
261+
#define KC_ERR_INVALID_INFO 0x50100004 //internal error : provided info is wrong / invalid
262+
#define KC_ERR_ENUM_WINDOWS_FAIL 0x50100005 //EnumWindows : API fail
263+
#define KC_ERR_NO_WINDOWS 0x50100006 //internal error : no compatible window found
264+
225265

226266

227267
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2.76 KB
Binary file not shown.

0 commit comments

Comments
 (0)