-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwin_authority.cpp
206 lines (156 loc) · 4.81 KB
/
win_authority.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
#include "shared.h"
#include "Commctrl.h"
#include "ShlObj.h"
#include "Shellapi.h"
void up_privilege() {
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
LookupPrivilegeValueA(NULL, "SeDebugPrivileges", &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
}
int Sys_IsAdmin() {
int b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if (b)
{
if (!CheckTokenMembership(NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
extern char sys_cmdline[MAX_STRING_CHARS];
#define ERROR_MSG(x) do \
MessageBox(0, va("Call of Duty caught an error whilst trying to do something.\nFile: %s, Line: %d\nErrorcode: %d (0x%x)\nError: %s" \
"Please report this error at the forums.",__FILE__,__LINE__,x,x,GetLastErrorAsString().c_str()), __TITLE, MB_ICONERROR | MB_OK); \
while(0)
void Sys_ElevateProgram() {
if (Sys_IsAdmin())
return; //we already are admin
char *fn;
Sys_GetModulePathInfo(NULL, NULL, &fn, NULL);
char *arg = va("allowdupe %s", sys_cmdline);
DWORD err = ERROR_SUCCESS;
ShellExecuteA(NULL, "runas", fn, arg, ".", SW_SHOWNORMAL | SW_SHOW);
if ((err = GetLastError()) != ERROR_SUCCESS)
if (err != ERROR_CANCELLED)
ERROR_MSG(err);
Com_Quit_f();
}
void Sys_RestartProgram(bool bAsAdmin) {
char *fn;
Sys_GetModulePathInfo(NULL, NULL, &fn, NULL);
char *arg = va("allowdupe %s", sys_cmdline);
DWORD err = ERROR_SUCCESS;
ShellExecuteA(NULL, bAsAdmin ? "runas" : "open", fn, arg, ".", SW_SHOWNORMAL | SW_SHOW);
if ((err = GetLastError()) != ERROR_SUCCESS)
if (err != ERROR_CANCELLED)
ERROR_MSG(err);
quit:
Com_Quit_f();
}
typedef struct {
int ver;
char *md5;
} cod_v_pair;
cod_v_pair cod_v_info[] = {
{ COD_1, "7b54e0259b24d32c16467ac454228418" }, // Modified, proper entry points, loads cod1x.dll instead of mss32.dll. f19da0d804bb20231572ee17225af339 - polish 7b54e0259b24d32c16467ac454228418 - md5 of english .exe
{ COD_1_SP, "9fa83933bbf659050a2f213c217b624c" },
//{ COD_1, "766345d1ceaf79caf7fe88a214b2f3ec" }, //from spect (different codmp entry points RVA import)
{ CODUO_51, "928dd08dc169bd85fdd12d2db28def70" },
{ COD_5_SP_STEAM, "acdf185fe7767d711fc99cb57df46044" },
{ COD_5_STEAM, "4f4596b1cdb21f9eb62e6683ecf48dc6" },
{ COD_5, "4bdf293d8e6fb32208d1b0942a1ba6bc" },
{ COD_UNKNOWN, NULL }
};
int WINAPI WinMain_upd(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
char *tempFileName = va("codmp_%u.download", rand());
bool simple_download(const char *url, const char *local);
if (!simple_download("http://cod1.eu/bin/codmp_1.bin", tempFileName)) {
MessageBoxA(NULL, "Failed to download patch CoDMP.exe! Run the program as Administrator!\n", __TITLE, MB_ICONERROR | MB_OK);
ExitProcess(0);
}
#if 1
char cur_fn[MAX_PATH + 1];
GetModuleFileNameA(NULL, cur_fn, MAX_PATH);
MoveFile(cur_fn, "cod_tmp_del_file");
DeleteFileA("cod_tmp_del_file");
MoveFileA(tempFileName, cur_fn);
Sys_RestartProgram(true);
ExitProcess(0);
#endif
}
bool determine_cod_version() {
FILE *fp = NULL;
char szFileName[MAX_PATH + 1];
GetModuleFileName(NULL, szFileName, MAX_PATH);
if (GetLastError() != ERROR_SUCCESS) {
MessageBoxA(NULL, "Too long filepath/name", "", 0);
return false;
}
char *fn;
Sys_GetModulePathInfo(NULL, NULL, &fn, NULL);
fp = fopen(fn, "rb");
if (!fp) {
MessageBoxA(NULL, va("Error reading '%s'\nRun Call of Duty as Administrator.", fn), __TITLE, MB_OK);
return false;
}
BYTE *buf = NULL;
size_t fs = 0;
fseek(fp, 0, SEEK_END);
fs = ftell(fp);
rewind(fp);
buf = new BYTE[fs];
if (fread(buf, 1, fs, fp) != fs) {
MessageBox(NULL, va("Reading error '%s'\n", fn), __TITLE, MB_OK | MB_ICONERROR);
delete[] buf;
fclose(fp);
return false;
}
std::string hash = GetHashText(buf, fs, HashMd5);
delete[] buf;
fclose(fp);
fp = NULL;
for (int i = 0; cod_v_info[i].md5 != NULL; i++) {
if (!strncmp(cod_v_info[i].md5, hash.c_str(), 32)) {
codversion = cod_v_info[i].ver;
break;
} else if (!strncmp(hash.c_str(), "766345d1ceaf79caf7fe88a214b2f3ec", 32)) { // If hash != [that] update DLL?
__call(0x528B38, (int)WinMain_upd);
break;
}
}
return (codversion != COD_UNKNOWN);
}
bool find_cod_version() {
if (!is_addr_safe(0x566C18))
return false;
char *l_1 = (char*)0x566C18;
if (!l_1)
return false;
if (!strcmp(l_1, "1.1")) {
codversion = COD_1;
return true;
}
return false;
}
bool has_authority() {
up_privilege();
if (Sys_IsAdmin())
return true;
Sys_ElevateProgram();
return false;
}