-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
572 lines (484 loc) · 15.9 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#ifdef _DEBUG
#define LOGGING
#endif
#define MINIMUM_SAFEDISC_SUBVERSION 70
#define SECDRVDLL_NAME "secdrvemu_v1.1.dll"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <tlhelp32.h>
#include "resource.h"
#include "secdrvemu/CStringPort.h"
#include "secdrvemu/Utils.h"
#ifdef _DEBUG
BOOL AlwaysCreateDLLs = TRUE;
#else
BOOL AlwaysCreateDLLs = FALSE;
#endif
BOOL bMovedDrvMgt = FALSE;
char szSystemDrvMgtPath[MAX_PATH];
void PutBackSafeDiscShim()
{
if (bMovedDrvMgt)
{
char szSrcPath[MAX_PATH];
sprintf(szSrcPath, "%s%s", szSystemDrvMgtPath, ".disable");
if (!MoveFile(szSrcPath, szSystemDrvMgtPath))
log("Unable to put back SafeDiscShim!\r\n");
bMovedDrvMgt = FALSE;
}
}
void exitlog(const char* fmt, ...)
{
va_list va;
va_start(va, fmt);
#ifdef _DEBUG
vfprintf(stdout, fmt, va);
#else
char buf[1000];
vsprintf(buf, fmt, va);
::MessageBox(NULL, buf, "SafeDiscLoader", MB_ICONERROR);
#endif
va_end(va);
#ifdef _DEBUG
getch();
#endif
PutBackSafeDiscShim();
exit(-1);
}
void LoadResource(DWORD ResID, BYTE **pBuf, DWORD *pSize)
{
HRSRC myResource = FindResource(NULL, MAKEINTRESOURCE(ResID), "DATA");
if (myResource == NULL)
exitlog("Could not LoadResource");
HGLOBAL myResourceData = ::LoadResource(NULL, myResource);
*pSize = SizeofResource(NULL, myResource);
*pBuf = (BYTE *)LockResource(myResourceData);
}
void InjectDrvMgt(DWORD pid)
{
HANDLE hProcess;
char szSecDrvEmuDLLPath[MAX_PATH];
GetTempPath(MAX_PATH, szSecDrvEmuDLLPath);
strcat(szSecDrvEmuDLLPath, SECDRVDLL_NAME);
if (AlwaysCreateDLLs || GetFileAttributes(szSecDrvEmuDLLPath) == -1L)
{
BYTE *pBuf;
DWORD dwSize;
LoadResource(IDR_SECDRVEMUDLL1, &pBuf, &dwSize);
FILE *fout = fopen(szSecDrvEmuDLLPath, "wb");
if (!fout)
{
exitlog("Could not write SecDrvEmu.dll\n");
}
fwrite(pBuf, 1, dwSize, fout);
fclose(fout);
}
// Open Process
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProcess == NULL) // Not INVALID_HANDLE_VALUE...Strangely
{
exitlog("Process found, but cannot open handle\n");
}
// Get the address of our LoadLibraryA function. This is assuming our address for LoadLibrary will be the same as our target processes
LPVOID loadLibraryAddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
// Get full path name of the target dll
char szPath[MAX_PATH];
GetFullPathNameA(szSecDrvEmuDLLPath, MAX_PATH, szPath, NULL);
// Create Memory in Target Process to hold the DLL's filename
LPVOID newMemory = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(szPath)+1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (newMemory == NULL)
{
exitlog("Could not allocate memory inside the target process\n");
}
// Write the fullpath filename into the target process
BOOL bWritten = WriteProcessMemory(hProcess, newMemory, szPath, strlen(szPath)+1, NULL);
if (bWritten == 0)
{
exitlog("There were no bytes written to the process's address space.\n");
}
// Create Remote Thread to run LoadLibrary with our fullpath
HANDLE hNewThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)loadLibraryAddr, newMemory, NULL, NULL);
if (hNewThread == NULL)
{
exitlog("Could not create remote thread in target process\n");
}
// Wait for it to run
WaitForSingleObject(hNewThread, INFINITE);
// Clean up
CloseHandle(hNewThread);
CloseHandle(hProcess);
}
void InjectAndHope(const char *lpApplicationName, bool bShowPopUp = true)
{
if (!bShowPopUp || MessageBox(NULL, "This does not appear to be a SafeDisc 2.7 or higher executable!\r\n\r\nInject SecDrvEmu.dll Emulation and hope for the best anyway?", "SafeDiscLoader", MB_ICONQUESTION | MB_YESNOCANCEL) == IDYES)
{
STARTUPINFO StartupInfo = { 0 };
PROCESS_INFORMATION pi = { 0 };
StartupInfo.cb = sizeof(STARTUPINFO);
log("lpApplicationName: %s\n", lpApplicationName);
BOOL bSuccess = CreateProcessA(NULL, (char*)lpApplicationName, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &StartupInfo, &pi);
if (!bSuccess)
exitlog("Failed to CreateProcess: %s\r\n(ErrCode: %d)\n", lpApplicationName, GetLastError());
InjectDrvMgt(pi.dwProcessId);
ResumeThread(pi.hThread);
PutBackSafeDiscShim();
exit(0);
}
else
exit(-1);
}
HANDLE hProcess;
BYTE byte_402000[155] = { 0xEB, 0x00, 0x60, 0x9C, 0xE8, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x58, 0xC6, 0x40, 0x85,
0xFE, 0x83, 0xC0, 0x1B, 0xFF, 0x34, 0x24, 0x89, 0x44, 0x24, 0x04, 0xFF, 0x10, 0x5B, 0x89, 0x03,
0x9D, 0x61, 0xE9, 0x69, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00 };
BYTE *byte_402009;
DWORD *dword_4029AC;
DWORD dword_4021BC = 187;
DWORD dword_4029B4;
void sub_401026(BYTE a1, BYTE a2, BYTE a3, BYTE a4, BYTE a5)
{
BYTE *v5; // ebx
void *v6; // [esp-34h] [ebp-34h]
v5 = (((BYTE*)dword_4029AC) + *((DWORD *)dword_4029AC + 15)) - 8;
v5[5] = a5;
v5[4] = a4;
v5[3] = a3;
v5[2] = a2;
v5[1] = a1;
*v5 = 0xCC;
v6 = (void *)(dword_4029B4 + v5 - ((BYTE *)dword_4029AC));
DWORD flOldProtect;
VirtualProtectEx(hProcess, v6, 8, 0x40, &flOldProtect);
DWORD dwWritten;
WriteProcessMemory(hProcess, v6, v5, 8, &dwWritten);
}
void sub_401000()
{
char szSDLoaderDLLPath[MAX_PATH];
GetTempPath(MAX_PATH, szSDLoaderDLLPath);
strcat(szSDLoaderDLLPath, "SDLoader.dll");
if (AlwaysCreateDLLs || GetFileAttributes(szSDLoaderDLLPath) == -1L)
{
BYTE *pBuf;
DWORD dwSize;
LoadResource(IDR_SDLOADERDLL1, &pBuf, &dwSize);
FILE *fout = fopen(szSDLoaderDLLPath, "wb");
if (!fout)
{
exitlog("Could not write SDLoader.dll\n");
}
fwrite(pBuf, 1, dwSize, fout);
fclose(fout);
}
wsprintfA((char*)byte_402009, szSDLoaderDLLPath);
}
char *GetDirectoryFromPath(const char *szPath)
{
char *szRet = strdup(szPath);
if (strrchr(szRet, '\\'))
*strrchr(szRet, '\\') = 0;
else
szRet = strdup(".");
return szRet;
}
void SetCurrentDirectoryFromPath(const char *szPath)
{
char *szDirPath = GetDirectoryFromPath(szPath);
SetCurrentDirectory(szDirPath);
free(szDirPath);
}
int main(int argc, char *argv[])
{
BOOL bSuccess = TRUE;
// Check for SafeDiscShim
if (GetSystemDirectory(szSystemDrvMgtPath, MAX_PATH))
{
log("System Directory: %s\n", szSystemDrvMgtPath);
strcat(szSystemDrvMgtPath, "\\drvmgt.dll");
if (GetFileAttributes(szSystemDrvMgtPath) != -1L)
{
// Screw asking - gets annoying
// if (::MessageBox(NULL, "SafeDiscShim Detected!\r\nPlease remove or disable before continuing.\r\n\r\nWould you like to temporarily disable SafeDiscShim?", "SafeDiscLoader", MB_ICONERROR | MB_YESNOCANCEL) == IDYES)
{
char szDestPath[MAX_PATH];
sprintf(szDestPath, "%s%s", szSystemDrvMgtPath, ".disable");
if (!MoveFile(szSystemDrvMgtPath, szDestPath))
exitlog("Unable to disable SafeDiscShim!\r\n");
else
bMovedDrvMgt = TRUE;
}
//else
// exit(-1);
}
}
byte_402009 = byte_402000 + 9;
sub_401000();
#ifdef _DEBUG
//char *szPath = "C:\\Program Files (x86)\\EA GAMES\\The Sims 2\\TSBin\\Sims2.exe -w";
//char *szPath = "C:\\Games\\Football Manager 2005\\fm2005.exe";
//char *szPath = "C:\\Games\\Call of Duty 4 - Modern Warfare\\iw3sp.exe";
//char *szPath = "C:\\Games\\BF1942\\BF1942.exe";
//char *szPath = "C:\\Games\\HPCOS\\System\\Game.Exe";
//char *szPath = "C:\\Games\\FIFA 2003\\fifa2003.Exe";
//char *szPath = "C:\\Games\\Nightfire\\Bond.exe";
//char *szPath = "C:\\Games\\Mafia\\Game.exe";
//char *szPath = "C:\\Games\\Need For Speed Underground\\Speed_Orig.exe";
//char *szPath = "C:\\Games\\Need For Speed Underground\\Speed.exe";
//char *szPath = "F:\\Games\\Harry Potter and the Chamber of Secrets\\system\\Game.exe";
//char *szPath = "C:\\Games\\Madden NFL 2003\\mainapp.exe";
//char *szPath = "C:\\Games\\Kohan\\Kohan.exe";
char *szPath = "C:\\Games\\Kohan\\kohan_NoCD_Loader.exe";
//char *szPath = "C:\\Games\\Kohan\\Kohan_Deviance1.exe";
//char *szPath = "C:\\Games\\Hitman - Codename 47\\Hitman.exe";
//char *szPath = "C:\\Games\\Combat Flight Simulator 3\\cfs3.exe";
#else
char szPathBuffer[MAX_PATH];
char *szPath = NULL;
ZeroMemory(szPathBuffer, MAX_PATH);
if (argc < 2)
{
FILE *fini = fopen("SafeDiscLoader.ini", "rt");
if (fini)
{
fgets(szPathBuffer, MAX_PATH, fini);
fclose(fini);
if (strlen(szPathBuffer) != 0)
{
if (strstr(szPathBuffer, "\r"))
*strstr(szPathBuffer, "\r") = 0;
if (strstr(szPathBuffer, "\n"))
*strstr(szPathBuffer, "\n") = 0;
szPath = szPathBuffer;
}
}
if (szPath == NULL)
{
OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szPathBuffer;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "Executables (*.exe)\0*.exe\0All\0*.*\0\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == TRUE)
{
szPath = szPathBuffer;
}
}
}
else
{
for (int i = 1; i < argc; i++)
{
if (strstr(argv[i], " "))
{
strcat(szPathBuffer, "\"");
strcat(szPathBuffer, argv[i]);
strcat(szPathBuffer, "\"");
}
else
strcat(szPathBuffer, argv[i]);
if (i != argc-1)
strcat(szPathBuffer, " ");
}
szPath = szPathBuffer;
}
#endif
log("szPath: %s\n", szPath);
char *szExePath = szPath;
CStringPort szExePart = szExePath;
int exe_idx = szExePart.MakeLower().Find(".exe");
if (exe_idx != -1)
{
// duplicate cut off after the .exe part (so any params etc are removed
// soit's just a path to the exe
szExePath = strdup(szExePath);
szExePath[exe_idx+4] = 0;
// Cut off any quotation marks
if (szExePath[0] == '\"')
szExePath++;
if (szExePath[strlen(szExePath)-1] == '\"')
szExePath[strlen(szExePath)-1] = 0;
}
SetCurrentDirectoryFromPath(szPath);
char szCurDir[MAX_PATH];
if (GetCurrentDirectory(MAX_PATH, szCurDir))
log("Current Directory: %s\n", szCurDir);
const char *lpApplicationName = szPath;
HANDLE hFile = CreateFile(szExePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
log("szExePath: %s\n", szExePath);
if (hFile == INVALID_HANDLE_VALUE)
{
exitlog("Could not open file: %s\r\n(ErrCode: %d)\n", szExePath, GetLastError());
}
DWORD nNumberOfBytesToRead = GetFileSize(hFile, 0);
DWORD dwSize = (nNumberOfBytesToRead + 0x10000) & 0x3FFF0000;
void *v2 = VirtualAlloc(0, (nNumberOfBytesToRead + 0x10000) & 0x3FFF0000, 0x1000u, 4u);
dword_4029AC = (DWORD*) v2;
if (!v2)
{
exitlog("Cannot allocate memory\n");
}
DWORD NumberOfBytesRead;
ReadFile(hFile, v2, nNumberOfBytesToRead, &NumberOfBytesRead, 0);
CloseHandle(hFile);
if ( NumberOfBytesRead != nNumberOfBytesToRead )
{
exitlog("Could not read entire file\n");
}
DWORD SafeDiscVersion, SafeDiscSubVersion, SafeDiscRevision;
if (GetSafeDiscVersionFromBuffer((BYTE*)v2, NumberOfBytesRead, &SafeDiscVersion, &SafeDiscSubVersion, &SafeDiscRevision))
{
if (SafeDiscVersion == 2 && SafeDiscSubVersion < 90 && SafeDiscSubVersion >= MINIMUM_SAFEDISC_SUBVERSION)
{
log("SafeDisc Version 2.7 or 2.8! Doing our own loader!\n");
InjectAndHope(lpApplicationName, false);
}
}
DWORD *esi = dword_4029AC;
DWORD *ebx = esi;
ebx += nNumberOfBytesToRead;
ebx -= 4;
if (*(WORD*)esi != 23117)
{
InjectAndHope(lpApplicationName);
}
esi = (DWORD*)(((BYTE*)esi) + esi[15]);
if (esi > ebx)
{
InjectAndHope(lpApplicationName);
}
if (*esi != 17744)
{
InjectAndHope(lpApplicationName);
}
DWORD *v3 = esi;
dword_4029B4 = v3[13];
void *lpAddress = (LPVOID)(v3[10] + dword_4029B4); // Original OEP
STARTUPINFO StartupInfo = { 0 };
PROCESS_INFORMATION pi = { 0 };
StartupInfo.cb = sizeof(STARTUPINFO);
log("lpApplicationName: %s\n", lpApplicationName);
bSuccess = CreateProcessA(NULL, (char*)lpApplicationName, 0, 0, 0, CREATE_SUSPENDED, 0, 0, &StartupInfo, &pi);
if (!bSuccess)
exitlog("Failed to CreateProcess: %s\r\n(ErrCode: %d)\n", lpApplicationName, GetLastError());
hProcess = pi.hProcess;
DWORD dword_402253;
ReadProcessMemory(hProcess, (char *)lpAddress - 4, &dword_402253, 4, 0);
if ( dword_402253 != 1887007348 )
{
TerminateProcess(hProcess, -1);
InjectAndHope(lpApplicationName);
}
ReadProcessMemory(hProcess, (char *)lpAddress + 187, &dword_402253, 4, 0);
if ( *((BYTE*)&dword_402253) != 0xE9 )
{
if ( *(((BYTE*)&dword_402253)+2) != 0xE9 )
{
TerminateProcess(hProcess, -1);
InjectAndHope(lpApplicationName);
}
dword_4021BC = 189;
}
/*
Hook JMP-OEP: disabled
Logging: enabled
CD-Check function skip: enabled
Alternative Key Finding: enabled
*/
#ifdef _DEBUG
BOOL LOG_SD_LOADER = TRUE;
#else
BOOL LOG_SD_LOADER = FALSE;
#endif
sub_401026((BYTE)dword_4021BC, 0, LOG_SD_LOADER, 1, 1); /// This sets the modes for SDLoader.dll - all 1s is debug stop at OEP. Normal is 0,0,1,1
*(DWORD*)(byte_402000 + 0x97) = (DWORD)LoadLibraryA;
void *lpBaseAddress = lpAddress;
DWORD flOldProtect;
BYTE unk_40209B[0x9b] = { 0 }; // 0x9b = 155
InjectDrvMgt(pi.dwProcessId);
InjectDCEAPIHook(pi.dwProcessId);
bSuccess = VirtualProtectEx(pi.hProcess, lpAddress, 0x9B, 0x40, &flOldProtect);
bSuccess = ReadProcessMemory(pi.hProcess, lpAddress, &unk_40209B, 0x9B, 0);
bSuccess = WriteProcessMemory(pi.hProcess, lpAddress, &byte_402000, 0x9B, 0);
if (!bSuccess)
exitlog("Unable to write to process memory\n");
bSuccess = ResumeThread(pi.hThread);
if (!bSuccess)
exitlog("Unable to resume exe\n");
CONTEXT stru_402447 = { 0 };
stru_402447.ContextFlags = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \
CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | \
CONTEXT_EXTENDED_REGISTERS);
while ( 1 )
{
if ( !GetThreadContext(pi.hThread, &stru_402447))
{
exitlog("Could not GetThreadContext 1\n");
}
DWORD dword_402550 = stru_402447.Eip;
if ( (LPVOID)dword_402550 == lpBaseAddress )
break;
Sleep(0x10u);
}
DWORD dword_4029BC;
SuspendThread(pi.hThread);
ReadProcessMemory(pi.hProcess, ((BYTE*)lpAddress) + 151, &dword_4029BC, 4, 0);
bSuccess = FALSE;
if (dword_4029BC)
{
WriteProcessMemory(hProcess, lpAddress, &unk_40209B, 0x9B, 0);
lpBaseAddress = (BYTE*)lpAddress + dword_4021BC;
BYTE *v9 = (BYTE*)lpAddress + dword_4021BC;
DWORD unk_4023ED;
BYTE unk_4023EB[2] = { 0xEB, 0xFE };
ReadProcessMemory(hProcess, v9, &unk_4023ED, 2u, 0);
WriteProcessMemory(hProcess, v9, &unk_4023EB, 2u, 0); // <--- PUT EB FE in the start
ResumeThread(pi.hThread);
for ( DWORD dword_4029C0 = 0; dword_4029C0 != 30; ++dword_4029C0 )
{
CONTEXT stru_402447_2 = { 0 };
stru_402447_2.ContextFlags = (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \
CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | \
CONTEXT_EXTENDED_REGISTERS);
GetThreadContext(pi.hThread, &stru_402447_2);
if ( ((LPVOID)stru_402447_2.Eip) == lpBaseAddress ) // Should be 0x012c1159
{
SuspendThread(pi.hThread);
WriteProcessMemory(pi.hProcess, lpBaseAddress, &unk_4023ED, 2u, 0);
bSuccess = ResumeThread(pi.hThread);
break;
}
Sleep(0x64u);
}
}
if (!bSuccess)
exitlog("Failed to start at OEP!\n");
PutBackSafeDiscShim();
return 0;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE /*hPrevInst*/, LPSTR cmd_line, int showmode)
{
#ifdef LOGGING
AllocConsole();
freopen("CONOUT$", "w", stdout);
#endif
int ret = main(__argc, __argv);
#ifdef LOGGING
FreeConsole();
#endif
return 0;
}