-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
72 lines (54 loc) · 1.5 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Author: Broihon
* Copyright: Guided Hacking™ © 2012-2023 Guided Hacking LLC
*/
#include <Windows.h>
#include <string>
#define INJ_86 TEXT("GH Injector - x86.exe")
#define INJ_64 TEXT("GH Injector - x64.exe")
int main()
{
BOOL WoW64 = FALSE;
IsWow64Process(GetCurrentProcess(), &WoW64);
const TCHAR * szExe = WoW64 ? INJ_64 : INJ_86;
if (GetFileAttributes(szExe) == INVALID_FILE_ATTRIBUTES && WoW64)
{
szExe = INJ_86;
}
if (GetFileAttributes(szExe) == INVALID_FILE_ATTRIBUTES)
{
MessageBoxA(NULL, "GH Injector executables are missing. Make sure all files are in the correct directory.", "Error", MB_ICONERROR);
return ERROR_FILE_NOT_FOUND;
}
PROCESS_INFORMATION pi{ 0 };
STARTUPINFO si{ 0 };
si.cb = sizeof(si);
auto bRet = CreateProcess(szExe, nullptr, nullptr, nullptr, FALSE, NULL, nullptr, nullptr, &si, &pi);
if (!bRet)
{
DWORD dwRet = GetLastError();
char error_code[9]{ 0 };
_ultoa_s(dwRet, error_code, 0x10);
std::string msg;
msg += "Failed to launch GH Injector. CreateProcess returned error code 0x";
msg += error_code;
MessageBoxA(NULL, msg.c_str(), "Error", MB_ICONERROR);
return dwRet;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
TCHAR OldPath[MAX_PATH]{ 0 };
GetFullPathName(TEXT("OLD.exe"), MAX_PATH, OldPath, nullptr);
if (GetFileAttributes(OldPath) != INVALID_FILE_ATTRIBUTES)
{
while (!DeleteFile(OldPath))
{
if (GetLastError() != ERROR_ACCESS_DENIED)
{
break;
}
Sleep(10);
}
}
return ERROR_SUCCESS;
}