This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloader.cc
240 lines (219 loc) · 6.44 KB
/
loader.cc
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
#include "jaakkos.h"
// fork or die
pid_t try_fork() {
pid_t forkpid = fork();
if(forkpid == -1) {
perror("fork()");
exit(1);
}
return forkpid;
}
// Called after Sage's config is read
void inject_my_starsign(void) {
uint32_t INJECT_STARSIGN = 0, STAROFF = 0;
int adom_version = get_version();
/*
INJECT_* is the address in memory to overwrite with the location of our function.
See http://www.adom.de/forums/showthread.php/1134-Choosing-star-sign?p=72882#post72882
for information on finding these offsets.
*/
if (adom_version == 111) {
INJECT_STARSIGN = 0x813ee0a;
}
else if (adom_version == 100) {
INJECT_STARSIGN = 0x813ac6a;
}
else if (adom_version == 1203) {
INJECT_STARSIGN = 0x081387ba;
}
else if (adom_version == 1204) {
INJECT_STARSIGN = 0x0813a09a;
}
else if (adom_version == 1205) {
INJECT_STARSIGN = 0x0813a94a;
}
else if (adom_version == 1206) {
INJECT_STARSIGN = 0x0813c05a;
}
else if (adom_version == 1207) {
INJECT_STARSIGN = 0x814068a;
}
else if (adom_version == 1208) {
INJECT_STARSIGN = 0x81419da;
}
else if (adom_version == 1209) {
INJECT_STARSIGN = 0x814598a;
}
else if (adom_version == 12010) {
INJECT_STARSIGN = 0x814586a;
}
else if (adom_version == 12011) {
INJECT_STARSIGN = 0x81449fa;
}
else if (adom_version == 12012) {
INJECT_STARSIGN = 0x814470a;
}
else if (adom_version == 12013) {
INJECT_STARSIGN = 0x814477a;
}
else if (adom_version == 12014) {
INJECT_STARSIGN = 0x814595a;
}
else if (adom_version == 12016) {
INJECT_STARSIGN = 0x814917a;
}
else if (adom_version == 12017) {
INJECT_STARSIGN = 0x814a8aa;
}
else if (adom_version == 12018) {
INJECT_STARSIGN = 0x814a12a;
}
else if (adom_version == 12020) {
INJECT_STARSIGN = 0x0814a49a;
}
else if (adom_version == 12021) {
INJECT_STARSIGN = 0x8156cda;
}
else if (adom_version == 12022) {
INJECT_STARSIGN = 0x81584fa;
}
else if (adom_version == 12023) {
INJECT_STARSIGN = 0x08158d3a;
}
else if (adom_version == 12048) {
INJECT_STARSIGN = 0x08165aca;
}
else if (adom_version == 12049) {
INJECT_STARSIGN = 0x0816653a;
}
else if (adom_version == 12051) {
INJECT_STARSIGN = 0x08171b2c;
}
else if (adom_version == 12055) {
INJECT_STARSIGN = 0x081723cc;
}
else if (adom_version == 12059) {
INJECT_STARSIGN = 0x0817844c;
}
if (INJECT_STARSIGN == 0) {
printf("Don't know where to inject a function to. Unknown ADOM version %i ?\n", adom_version);
return;
}
STAROFF = INJECT_STARSIGN + 4;
if(
mprotect(PAGEBOUND(INJECT_STARSIGN), getpagesize(), RWX_PROT) /* starsign */
) {
perror("mprotect()");
exit(1);
}
// inject starsign selector
*((char**)INJECT_STARSIGN) = ((char*)(&starsign_select)) - STAROFF;
}
void inject_autosaver(void) {
uint32_t COMMAND_ADDR = 0, SAVE_ADDR = 0;
int adom_version = get_version();
if (adom_version == 111) {
COMMAND_ADDR = 0x0808F990;
SAVE_ADDR = 0x08090735;
}
else if (adom_version == 12018) {
COMMAND_ADDR = 0x0808A6FE;
SAVE_ADDR = 0x0808AEA8;
}
else if (adom_version == 12020) {
COMMAND_ADDR = 0x0808a77e;
SAVE_ADDR = 0x0808af28;
}
else if (adom_version == 12021) {
COMMAND_ADDR = 0x0808e1c0;
SAVE_ADDR = 0x0808e9b5;
}
else if (adom_version == 12022) {
COMMAND_ADDR = 0x0808ea28;
SAVE_ADDR = 0x0808f21b;
}
else if (adom_version == 12023) {
COMMAND_ADDR = 0x0808ecf8;
SAVE_ADDR = 0x0808f4eb;
}
else if (adom_version == 12048) {
COMMAND_ADDR = 0x080931a0;
SAVE_ADDR = 0x08093be4;
}
else if (adom_version == 12049) {
COMMAND_ADDR = 0x0809331d;
SAVE_ADDR = 0x08093d64;
}
else if (adom_version == 12051) {
COMMAND_ADDR = 0x0809B70E;
SAVE_ADDR = 0x0809CD90;
}
else {
printf("Don't know where to inject autosaver. Unknown ADOM version %i ?\n", adom_version);
return;
}
if(
mprotect(PAGEBOUND(COMMAND_ADDR), getpagesize(), RWX_PROT) || /* autosave command_hook */
mprotect(PAGEBOUND(SAVE_ADDR), getpagesize(), RWX_PROT) /* autosave save_hook */
) {
perror("mprotect()");
exit(1);
}
// inject autosaver - every 1000 turn
*((char**)COMMAND_ADDR) = ((char*)(&command_hook)) - COMMAND_ADDR - 4;
// inject autosaver - on 'S' command
*((char**)SAVE_ADDR) = ((char*)(&save_hook)) - SAVE_ADDR - 4;
}
void inject_roller(void) {
uint32_t ROLL_ADDR = 0;
int adom_version = get_version();
if (adom_version == 111) {
ROLL_ADDR = 0x080756C4;
}
else if (adom_version == 12018) {
ROLL_ADDR = 0x0807DB03;
}
else if (adom_version == 12020) {
ROLL_ADDR = 0x0807db83;
}
else if (adom_version == 12021) {
ROLL_ADDR = 0x080800e5;
}
else if (adom_version == 12022) {
ROLL_ADDR = 0x0808052d;
}
else if (adom_version == 12023) {
ROLL_ADDR = 0x080806cd;
}
else if (adom_version == 12048) {
ROLL_ADDR = 0x08082ced;
}
else if (adom_version == 12049) {
ROLL_ADDR = 0x08082e07;
}
else if (adom_version == 12051) {
ROLL_ADDR = 0x0808ab1b;
}
else if (adom_version == 12055) {
ROLL_ADDR = 0x0808afcb;
}
else if (adom_version == 12059) {
ROLL_ADDR = 0x0808d7aa;
}
else {
printf("Don't know where to inject roller. Unknown ADOM version %i ?\n", adom_version);
return;
}
// try to load user's saved requirements
load_requirements();
// roller's item list
load_item_list();
if(
mprotect(PAGEBOUND(ROLL_ADDR), getpagesize(), RWX_PROT) /* roller */
) {
perror("mprotect()");
exit(1);
}
// inject stat roller
*((char**)ROLL_ADDR) = ((char*)(&roll_start)) - ROLL_ADDR - 4;
}