-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
executable file
·88 lines (70 loc) · 2.02 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
// Credits to @Wunkolo (https://twitter.com/Wunkolo/status/843387447656435712)
#include <windows.h>
#include <tlhelp32.h>
#include <cstdint>
#include <stdio.h>
DWORD GetPidByName (const char *name)
{
DWORD pid = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnapshot, &pe32)) {
return 0;
}
while (Process32Next(hSnapshot, &pe32))
{
if (!stricmp(name, pe32.szExeFile))
{
pid = pe32.th32ProcessID;
break;
}
}
CloseHandle(hSnapshot);
return pid;
}
HANDLE GetHandleFromPid (DWORD pid)
{
HANDLE hProc;
while ((hProc = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid)) == INVALID_HANDLE_VALUE) {
Sleep(1);
}
return hProc;
}
HANDLE GetHandleFromName (const char *name)
{
return GetHandleFromPid(GetPidByName(name));
}
int main (int argc, char **argv)
{
HANDLE hNier = GetHandleFromName ("NieRAutomata.exe");
// Check patch state
LPVOID address = (void *) 0x141415B90;
std::uint64_t data;
SIZE_T bytes_read;
if (!(ReadProcessMemory (hNier, address, (void *) &data, sizeof(data), &bytes_read))) {
printf ("Cannot read process memory.");
return -1;
}
std::uint64_t new_data;
switch (data) {
case 0:
// Unpatched
MessageBox(NULL, "Free camera is enabled!", "NieR:Automata", 0);
new_data = 0x80000000;
break;
default:
MessageBox(NULL, "Free camera is disabled!", "NieR:Automata", 0);
// Patch, back to normal
new_data = 0;
break;
}
if (!(WriteProcessMemory (hNier, address, (void *) &new_data, sizeof(new_data), &bytes_read))) {
printf ("Cannot write process memory.");
return -1;
}
return 0;
}