-
Notifications
You must be signed in to change notification settings - Fork 4
/
Unity.h
389 lines (300 loc) · 10.1 KB
/
Unity.h
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
#include <mach-o/dyld.h>
#define ASLR_BIAS _dyld_get_image_vmaddr_slide
uint64_t getRealOffset(uint64_t offset){
return ASLR_BIAS + offset;
}
/*
This struct can hold a native C# array. Credits to caoyin.
Think of it like a wrapper for a C array. For example, if you had Player[] players in a dump,
the resulting monoArray definition would be monoArray<void **> *players;
To get the C array, call getPointer.
To get the length, call getLength.
*/
template <typename T>
struct monoArray
{
void* klass;
void* monitor;
void* bounds;
int max_length;
void* vector [1];
int getLength()
{
return max_length;
}
T getPointer()
{
return (T)vector;
}
};
/*
This struct represents a C# string. Credits to caoyin.
It is pretty straight forward. If you have this in a dump,
public class Player {
public string username; // 0xC8
}
getting that string would look like this: monoString *username = *(monoString **)((uint64_t)player + 0xc8);
C# strings are UTF-16. This means each character is two bytes instead of one.
To get the length of a monoString, call getLength.
To get a NSString from a monoString, call toNSString.
To get a std::string from a monoString, call toCPPString.
To get a C string from a monoString, call toCString.
*/
typedef struct _monoString
{
void* klass;
void* monitor;
int length;
char chars[1];
int getLength()
{
return length;
}
char* getChars()
{
return chars;
}
NSString* toNSString()
{
return [[NSString alloc] initWithBytes:(const void *)(chars)
length:(NSUInteger)(length * 2)
encoding:(NSStringEncoding)NSUTF16LittleEndianStringEncoding];
}
char* toCString()
{
NSString* v1 = toNSString();
return (char*)([v1 UTF8String]);
}
std::string toCPPString()
{
return std::string(toCString());
}
}monoString;
/*
This struct represents a List. In the dump, a List is declared as List`1.
Deep down, this simply wraps a C array around a C# list. For example, if you had this in a dump,
public class Player {
List`1<int> perks; // 0xDC
}
getting that list would look like this: monoList<int *> *perks = *(monoList<int *> **)((uint64_t)player + 0xdc);
You can also get lists that hold objects, but you need to use void ** because we don't have implementation for the Weapon class.
public class Player {
List`1<Weapon> weapons; // 0xDC
}
getting that list would look like this: monoList<void **> *weapons = *(monoList<void **> **)((uint64_t)player + 0xdc);
If you need a list of strings, use monoString **.
To get the C array, call getItems.
To get the size of a monoList, call getSize.
*/
template <typename T>
struct monoList {
void *unk0;
void *unk1;
monoArray<T> *items;
int size;
int version;
T getItems(){
return items->getPointer();
}
int getSize(){
return size;
}
int getVersion(){
return version;
}
};
/*
This struct represents a Dictionary. In the dump, a Dictionary is defined as Dictionary`1.
You could think of this as a Map in Java or C++. Keys correspond with values. This wraps the C arrays for keys and values.
If you had this in a dump,
public class GameManager {
public Dictionary`1<int, Player> players; // 0xB0
public Dictionary`1<Weapon, Player> playerWeapons; // 0xB8
public Dictionary`1<Player, string> playerNames; // 0xBC
}
to get players, it would look like this: monoDictionary<int *, void **> *players = *(monoDictionary<int *, void **> **)((uint64_t)player + 0xb0);
to get playerWeapons, it would look like this: monoDictionary<void **, void **> *playerWeapons = *(monoDictionary<void **, void **> **)((uint64_t)player + 0xb8);
to get playerNames, it would look like this: monoDictionary<void **, monoString **> *playerNames = *(monoDictionary<void **, monoString **> **)((uint64_t)player + 0xbc);
To get the C array of keys, call getKeys.
To get the C array of values, call getValues.
To get the number of keys, call getNumKeys.
To get the number of values, call getNumValues.
*/
template <typename K, typename V>
struct monoDictionary {
void *unk0;
void *unk1;
monoArray<int **> *table;
monoArray<void **> *linkSlots;
monoArray<K> *keys;
monoArray<V> *values;
int touchedSlots;
int emptySlot;
int size;
K getKeys(){
return keys->getPointer();
}
V getValues(){
return values->getPointer();
}
int getNumKeys(){
return keys->getLength();
}
int getNumValues(){
return values->getLength();
}
int getSize(){
return size;
}
};
/*
Turn a C string into a C# string!
This function is included in Unity's string class. There are two versions of this function in the dump, you want the one the comes FIRST.
The method signature is:
private string CreateString(PTR value);
Again, you want the FIRST one, not the second.
*/
monoString *U3DStr(const char *str){
monoString *(*String_CreateString)(void *_this, const char *str) = (monoString *(*)(void *, const char *))getRealOffset(/*LOCATION HERE*/);
return String_CreateString(NULL, str);
}
/*
Create a native C# array with a starting length.
This one is kind of tricky to complete. I'm currently looking for an easier way to implement this.
The offsets you need are both found at String::Split(char separator[], int count). Go to that function in IDA and scroll down until you find something like this:
TBNZ W20, #0x1F, loc_101153944
CMP W20, #1
B.EQ loc_1011538B0
CBNZ W20, loc_101153924
ADRP X8, #qword_1026E0F20@PAGE
NOP
LDR X19, [X8,#qword_1026E0F20@PAGEOFF]
MOV X0, X19
BL sub_101DD8AF8
MOV X0, X19
MOV W1, #0
LDP X29, X30, [SP,#0x30+var_10]
LDP X20, X19, [SP,#0x30+var_20]
LDP X22, X21, [SP+0x30+var_30],#0x30
B sub_101DD74E8
I filled in the locations here:
TBNZ W20, #0x1F, loc_101153944
CMP W20, #1
B.EQ loc_1011538B0
CBNZ W20, loc_101153924
ADRP X8, #qword_1026E0F20@PAGE
NOP
LDR X19, [X8,#qword_1026E0F20@PAGEOFF] <-------- Whatever 1026E0F20 is in your game is your second location
MOV X0, X19
BL sub_101DD8AF8
MOV X0, X19
MOV W1, #0
LDP X29, X30, [SP,#0x30+var_10]
LDP X20, X19, [SP,#0x30+var_20]
LDP X22, X21, [SP+0x30+var_30],#0x30
B sub_101DD74E8 <-------- Whatever 101DD74E8 is in your game is your first location
For example, if you wanted an array of 10 ints, you would do this: monoArray<int *> *integers = CreateNativeCSharpArray<int *>(10);
You can use any type with this!
*/
template<typename T>
monoArray<T> *CreateNativeCSharpArray(int startingLength){
monoArray<T> *(*IL2CPPArray_Create)(void *klass, int startingLength) = (monoArray<T> *(*)(void *, int))getRealOffset(/*FIRST LOCATION HERE*/);
void *unkptr0 = *(void **)(ASLR_BIAS + /*SECOND LOCATION HERE*/);
void *klass = *(void **)((uint64_t)unkptr0);
monoArray<T> *arr = IL2CPPArray_Create(klass, startingLength);
return arr;
}
/*
Here are some functions to safely get/set values for types from Anti Cheat Toolkit (https://assetstore.unity.com/packages/tools/utilities/anti-cheat-toolkit-10395)
I will add more to this as I go along.
*/
union intfloat {
int i;
float f;
};
/*
Get the real value of an ObscuredInt.
Parameters:
- location: the location of the ObscuredInt
*/
int GetObscuredIntValue(uint64_t location){
int cryptoKey = *(int *)location;
int obfuscatedValue = *(int *)(location + 0x4);
return obfuscatedValue ^ cryptoKey;
}
/*
Set the real value of an ObscuredInt.
Parameters:
- location: the location of the ObscuredInt
- value: the value we're setting the ObscuredInt to
*/
void SetObscuredIntValue(uint64_t location, int value){
int cryptoKey = *(int *)location;
*(int *)(location + 0x4) = value ^ cryptoKey;
}
/*
Get the real value of an ObscuredFloat.
Parameters:
- location: the location of the ObscuredFloat
*/
float GetObscuredFloatValue(uint64_t location){
int cryptoKey = *(int *)location;
int obfuscatedValue = *(int *)(location + 0x4);
/* use this intfloat to set the integer representation of our parameter value, which will also set the float value */
intfloat IF;
IF.i = obfuscatedValue ^ cryptoKey;
return IF.f;
}
/*
Set the real value of an ObscuredFloat.
Parameters:
- location: the location of the ObscuredFloat
- value: the value we're setting the ObscuredFloat to
*/
void SetObscuredFloatValue(uint64_t location, float value){
int cryptoKey = *(int *)location;
/* use this intfloat to get the integer representation of our parameter value */
intfloat IF;
IF.f = value;
/* use this intfloat to generate our hacked ObscuredFloat */
intfloat IF2;
IF2.i = IF.i ^ cryptoKey;
*(float *)(location + 0x4) = IF2.f;
}
/*
Get the real value of an ObscuredVector3.
Parameters:
- location: the location of the ObscuredVector3
*/
Vector3 GetObscuredVector3Value(uint64_t location){
int cryptoKey = *(int *)location;
Vector3 ret;
intfloat IF;
IF.i = *(int *)(location + 0x4) ^ cryptoKey;
ret.x = IF.f;
IF.i = *(int *)(location + 0x8) ^ cryptoKey;
ret.y = IF.f;
IF.i = *(int *)(location + 0xc) ^ cryptoKey;
ret.z = IF.f;
return ret;
}
/*
Set the real value of an ObscuredVector3.
Parameters:
- location: the location of the ObscuredVector3
- value: the value we're setting the ObscuredVector3 to
*/
void SetObscuredVector3Value(uint64_t location, Vector3 value){
int cryptoKey = *(int *)location;
intfloat IF;
IF.f = value.x;
intfloat IF2;
IF2.i = IF.i ^ cryptoKey;
*(float *)(location + 0x4) = IF2.f;
IF.f = value.y;
IF2.i = IF.i ^ cryptoKey;
*(float *)(location + 0x8) = IF2.f;
IF.f = value.z;
IF2.i = IF.i ^ cryptoKey;
*(float *)(location + 0xc) = IF2.f;
}