Skip to content

Commit 477109a

Browse files
committed
More error checking, fixed readme (updated this one by accident lmao), proper unicode implementation of setwindowhookex injection, GH Injector SM is also a unicode project now
1 parent 390faa4 commit 477109a

File tree

14 files changed

+46
-29
lines changed

14 files changed

+46
-29
lines changed

GH Injector Library/Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
#define HOOK_SCAN_ERR_CREATE_PROCESS_FAILED 0x50000008 //CreateProcessW : win32 error
283283
#define HOOK_SCAN_ERR_WAIT_FAILED 0x50000009 //WaitForSingleObject : win32 error
284284
#define HOOK_SCAN_ERR_WAIT_TIMEOUT 0x5000000A //WaitForSingleObject : waiting timed out
285+
#define HOOK_SCAN_ERR_BUFFER_TOO_SMALL 0x5000000B //internal error : the buffer passed to ValidateInjectionFunctions is too small
285286

286287

287288

GH Injector Library/Handle Hijacking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NTSTATUS EnumHandles(char * pBuffer, ULONG Size, ULONG * SizeOut, UINT & Count)
1111

1212
if (NT_FAIL(ntRet))
1313
{
14-
LOG("Failed to grab handle list\n");
14+
LOG("Failed to grab handle list: %08X\n", ntRet);
1515

1616
return ntRet;
1717
}

GH Injector Library/Hook Scanner.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ bool __stdcall ValidateInjectionFunctions(DWORD dwTargetProcessId, DWORD & Error
326326
{
327327
LOG("Provided buffer too small\n");
328328

329+
ErrorCode = HOOK_SCAN_ERR_BUFFER_TOO_SMALL;
330+
329331
return false;
330332
}
331333

@@ -381,10 +383,10 @@ bool __stdcall RestoreInjectionFunctions(DWORD dwTargetProcessId, DWORD & ErrorC
381383
*CountOut = SuccessCount;
382384
}
383385

384-
LOG("%d of %d hook(s) restored\n", SuccessCount, Count);
385-
386386
CloseHandle(hTargetProc);
387387

388+
LOG("%d of %d hook(s) restored\n", SuccessCount, Count);
389+
388390
return true;
389391
}
390392

GH Injector Library/Injection Generic WOW64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ DWORD InjectDLL_WOW64(const wchar_t * szDllFile, HANDLE hTargetProc, INJECTION_M
109109

110110
LOG("Shell written to memory\n");
111111

112-
LOG("Enterting StartRoutine_WOW64\n");
112+
LOG("Entering StartRoutine_WOW64\n");
113113

114114
DWORD remote_ret = 0;
115115
DWORD dwRet = StartRoutine_WOW64(hTargetProc, (f_Routine_WOW64)(MDWD(pShell)), MDWD(pArg), Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/Injection Generic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ DWORD InjectDLL(const wchar_t * szDllFile, HANDLE hTargetProc, INJECTION_MODE Mo
9696

9797
LOG("Shell written to memory\n");
9898

99-
LOG("Enterting StartRoutine\n");
99+
LOG("Entering StartRoutine\n");
100100

101101
DWORD remote_ret = 0;
102102
DWORD dwRet = StartRoutine(hTargetProc, ReCa<f_Routine>(pShell), pArg, Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/Injection.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,19 @@ DWORD HijackHandle(INJECTIONDATAW * pData, ERROR_DATA & error_data)
488488
LastErrCode = INJ_ERR_CANT_OPEN_PROCESS;
489489
INIT_ERROR_DATA(error_data, GetLastError());
490490

491+
LOG("Failed to attach to process %06X\n", i.OwnerPID);
492+
491493
continue;
492494
}
495+
496+
LOG("Attached to process %06X\n", i.OwnerPID);
493497

494498
if (!IsElevatedProcess(hHijackProc) || !IsNativeProcess(hHijackProc))
495499
{
496500
LastErrCode = INJ_ERR_HIJACK_NO_NATIVE_HANDLE;
497501
INIT_ERROR_DATA(error_data, INJ_ERR_ADVANCED_NOT_DEFINED);
498502

499-
LOG("Can't open process %06X\n", i.OwnerPID);
503+
LOG("Process isn't elevated or native\n");
500504

501505
CloseHandle(hHijackProc);
502506

@@ -518,7 +522,7 @@ DWORD HijackHandle(INJECTIONDATAW * pData, ERROR_DATA & error_data)
518522
continue;
519523
}
520524

521-
LOG("Injection module loaded\n");
525+
LOG("Injection module loaded into hijack process\n");
522526

523527
HINSTANCE hInjectionModuleEx = hijack_data.hDllOut;
524528
f_Routine pRemoteInjectW = ReCa<f_Routine>(ReCa<UINT_PTR>(InjectW) - ReCa<UINT_PTR>(g_hInjMod) + ReCa<UINT_PTR>(hInjectionModuleEx));
@@ -554,6 +558,8 @@ DWORD HijackHandle(INJECTIONDATAW * pData, ERROR_DATA & error_data)
554558
continue;
555559
}
556560

561+
LOG("Handle value: %04X\n", i.hValue);
562+
557563
pData->hHandleValue = 0;
558564

559565
LOG("Injection data written to hijack process\n");

GH Injector Library/Manual Mapping WOW64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ DWORD MMAP_WOW64::ManualMap_WOW64(const wchar_t * szDllFile, HANDLE hTargetProc,
120120

121121
LOG("Shell written to memory\n");
122122

123-
LOG("Enterting StartRoutine_WOW64\n");
123+
LOG("Entering StartRoutine_WOW64\n");
124124

125125
DWORD remote_ret = 0;
126126
DWORD dwRet = StartRoutine_WOW64(hTargetProc, (f_Routine_WOW64)(MDWD(pShell)), MDWD(pArg), Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/Manual Mapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ DWORD MMAP_NATIVE::ManualMap(const wchar_t * szDllFile, HANDLE hTargetProc, LAUN
128128

129129
LOG("Shell written to memory\n");
130130

131-
LOG("Enterting StartRoutine\n");
131+
LOG("Entering StartRoutine\n");
132132

133133
DWORD remote_ret = 0;
134134
DWORD dwRet = StartRoutine(hTargetProc, ReCa<f_Routine>(pShell), pArg, Method, (Flags & INJ_THREAD_CREATE_CLOAKED) != 0, remote_ret, Timeout, error_data);

GH Injector Library/SetWindowsHookEx WOW64.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ DWORD SR_SetWindowsHookEx_WOW64(HANDLE hTargetProc, f_Routine_WOW64 pRoutine, DW
9898
std::wstring smPath = g_RootPathW;
9999
smPath += SM_EXE_FILENAME86;
100100

101-
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME86 "\"";
101+
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME86 "\" 0";
102102

103103
PROCESS_INFORMATION pi{ 0 };
104104
STARTUPINFOW si{ 0 };
@@ -156,6 +156,8 @@ DWORD SR_SetWindowsHookEx_WOW64(HANDLE hTargetProc, f_Routine_WOW64 pRoutine, DW
156156

157157
LOG("Token prepared\n");
158158

159+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME86, cmdLine);
160+
159161
if (!CreateProcessAsUserW(hAdminToken, smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
160162
{
161163
INIT_ERROR_DATA(error_data, GetLastError());
@@ -178,6 +180,8 @@ DWORD SR_SetWindowsHookEx_WOW64(HANDLE hTargetProc, f_Routine_WOW64 pRoutine, DW
178180
}
179181
else
180182
{
183+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME86, cmdLine);
184+
181185
if (!CreateProcessW(smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
182186
{
183187
INIT_ERROR_DATA(error_data, GetLastError());

GH Injector Library/SetWindowsHookEx.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ DWORD SR_SetWindowsHookEx(HANDLE hTargetProc, f_Routine pRoutine, void * pArg, U
138138
std::wstring smPath = g_RootPathW;
139139
smPath += SM_EXE_FILENAME;
140140

141-
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME "\"";
141+
wchar_t cmdLine[] = L"\"" SM_EXE_FILENAME "\" 0";
142142

143143
PROCESS_INFORMATION pi{ 0 };
144144
STARTUPINFOW si{ 0 };
@@ -199,6 +199,8 @@ DWORD SR_SetWindowsHookEx(HANDLE hTargetProc, f_Routine pRoutine, void * pArg, U
199199

200200
LOG("Token prepared\n");
201201

202+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME, cmdLine);
203+
202204
if (!CreateProcessAsUserW(hAdminToken, smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
203205
{
204206
INIT_ERROR_DATA(error_data, GetLastError());
@@ -221,7 +223,9 @@ DWORD SR_SetWindowsHookEx(HANDLE hTargetProc, f_Routine pRoutine, void * pArg, U
221223
CloseHandle(hUserToken);
222224
}
223225
else
224-
{
226+
{
227+
LOG("Launching %ls:\n %ls\n", SM_EXE_FILENAME, cmdLine);
228+
225229
if (!CreateProcessW(smPath.c_str(), cmdLine, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi))
226230
{
227231
INIT_ERROR_DATA(error_data, GetLastError());

0 commit comments

Comments
 (0)