-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
173 lines (149 loc) · 4.85 KB
/
main.cpp
File metadata and controls
173 lines (149 loc) · 4.85 KB
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
#include <WinSock2.h>
#include <windows.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <experimental/filesystem>
#pragma comment( lib, "Version.lib" )
#pragma comment( lib, "ws2_32.lib" )
struct Patch
{
uint32_t addr;
std::vector<uint8_t> bytes;
};
Patch patches[] = {
// Startup
{ 0x27677C, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 } }, // 0x67737C
{ 0x276789, { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 } }, // 0x677389
{ 0x276794, { 0x90 } }, // 0x677394
{ 0x2767CB, { 0x90, 0x90 } }, // 0x6773CB
// Xat
{ 0x232244, { 0xB9, 0xFF } }, // 0x632E44
{ 0x18FD9E, { 0xEB } }, // 0x59099E
// Inet
{ 0x125AF8, { 0xB8, 0x00, 0x00, 0x00, 0x00, 0x90 }}, // 0x5266F8
// End patches
{ 0x0, {} }
};
const uint8_t restoreInet[] = { 0x50, 0xE8, 0x02, 0xFE, 0xFF, 0xFF };
int main(int argc, char** argv)
{
char* exe = nullptr;
std::string ip;
// Exe path must be set as argument 1
if (argc > 1)
{
exe = argv[1];
}
else
{
printf("Drag file to this exe or pass as 1st parameter\nPress [ENTER] to exit");
getchar();
return 1;
}
// Ensure the exe exists
if (!std::experimental::filesystem::exists(exe))
{
std::cout << "Wrong path, file does not exist" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 1;
}
// Make a copy if no copy already exists (so that we can restore it)
std::string backup = std::string(exe) + ".bak";
if (!std::experimental::filesystem::exists(backup))
{
std::experimental::filesystem::copy(std::string(exe), backup);
}
// Ask for IP if not passed as 2nd argument
if (argc <= 2)
{
std::cout << "Input a IP (invalid one to restore): ";
std::cin >> ip;
getchar();
}
else
{
ip = argv[2];
}
// Convert IP (string) to hexadecimal
DWORD addr = inet_addr(ip.c_str());
if (addr != -1)
{
// No error, use that IP
patches[6].bytes[1] = (addr >> 0) & 0xFF;
patches[6].bytes[2] = (addr >> 8) & 0xFF;
patches[6].bytes[3] = (addr >> 16) & 0xFF;
patches[6].bytes[4] = (addr >> 24) & 0xFF;
}
else
{
// Else, restore the original bytes
for (int i = 0; i < sizeof(restoreInet); ++i)
{
patches[6].bytes[i] = restoreInet[i];
}
}
// Get file version size
DWORD dwHandle;
DWORD sz = GetFileVersionInfoSizeA(exe, &dwHandle);
if (sz == 0)
{
std::cout << "Try to run as Admin" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 1;
}
// Get file version
std::vector<unsigned char> buf(sz);
if (!GetFileVersionInfoA(exe, dwHandle, sz, &buf[0]))
{
std::cout << "Try to run as Admin" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 1;
}
// Query the version
VS_FIXEDFILEINFO* pvi;
sz = sizeof(VS_FIXEDFILEINFO);
if (!VerQueryValueA(&buf[0], "\\", (LPVOID*)&pvi, (unsigned int*)&sz))
{
std::cout << "Try to run as Admin" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 1;
}
// Transform to major.minor.hotfix.other
int major = (pvi->dwFileVersionMS >> 16) & 0xffff;
int minor = (pvi->dwFileVersionMS) & 0xffff;
int hotfix = (pvi->dwFileVersionLS >> 16) & 0xffff;
int other = (pvi->dwFileVersionLS) & 0xffff;
// Assert it is the same as the one it was thought to be used with
if (major != 0 || minor != 9 || hotfix != 3 || other != 3057)
{
std::cout << "Wrong version" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 1;
}
// Open file as read+write+binary, so that it overwrites instead of append
std::fstream s(exe, std::ios_base::out | std::ios_base::in | std::ios_base::binary);
if (!s.is_open())
{
std::cout << "Can not open file, wrong path, already opened or needs admin rights" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 1;
}
// Write all patches
Patch* patch = &patches[0];
while (patch->addr != 0x0)
{
// Write bytes
s.seekp(patch->addr, std::ios_base::beg);
s.write((const char*)&patch->bytes[0], patch->bytes.size());
// Next patch
++patch;
}
// Close file and save changes
s.close();
// Exit
std::cout << "DONE!" << std::endl << "Press [ENTER] to exit" << std::endl;
getchar();
return 0;
}