forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata_class.py
More file actions
325 lines (264 loc) · 9.91 KB
/
Copy pathmetadata_class.py
File metadata and controls
325 lines (264 loc) · 9.91 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
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
from .helper import *
class Il2CppGlobalMetadataHeader(MetaDataClass):
sanity: uint
version: int
stringLiteralOffset: uint # string data for managed code
stringLiteralCount: int
stringLiteralDataOffset: uint
stringLiteralDataCount: int
stringOffset: uint # string data for metadata
stringCount: int
eventsOffset: uint # Il2CppEventDefinition
eventsCount: int
propertiesOffset: uint # Il2CppPropertyDefinition
propertiesCount: int
methodsOffset: uint # Il2CppMethodDefinition
methodsCount: int
parameterDefaultValuesOffset: uint # Il2CppParameterDefaultValue
parameterDefaultValuesCount: int
fieldDefaultValuesOffset: uint # Il2CppFieldDefaultValue
fieldDefaultValuesCount: int
fieldAndParameterDefaultValueDataOffset: uint # uint8_t
fieldAndParameterDefaultValueDataCount: int
fieldMarshaledSizesOffset: int # Il2CppFieldMarshaledSize
fieldMarshaledSizesCount: int
parametersOffset: uint # Il2CppParameterDefinition
parametersCount: int
fieldsOffset: uint # Il2CppFieldDefinition
fieldsCount: int
genericParametersOffset: uint # Il2CppGenericParameter
genericParametersCount: int
genericParameterConstraintsOffset: uint # TypeIndex
genericParameterConstraintsCount: int
genericContainersOffset: uint # Il2CppGenericContainer
genericContainersCount: int
nestedTypesOffset: uint # TypeDefinitionIndex
nestedTypesCount: int
interfacesOffset: uint # TypeIndex
interfacesCount: int
vtableMethodsOffset: uint # EncodedMethodIndex
vtableMethodsCount: int
interfaceOffsetsOffset: int # Il2CppInterfaceOffsetPair
interfaceOffsetsCount: int
typeDefinitionsOffset: uint # Il2CppTypeDefinition
typeDefinitionsCount: int
rgctxEntriesOffset: Union[uint, Version(Max=24.1)] # Il2CppRGCTXDefinition
rgctxEntriesCount: Union[int, Version(Max=24.1)]
imagesOffset: uint # Il2CppImageDefinition
imagesCount: int
assembliesOffset: int # Il2CppAssemblyDefinition
assembliesCount: int
metadataUsageListsOffset: Union[
uint, Version(Min=19, Max=24.4)
] # Il2CppMetadataUsageList
metadataUsageListsCount: Union[int, Version(Min=19, Max=24.4)]
metadataUsagePairsOffset: Union[
uint, Version(Min=19, Max=24.4)
] # Il2CppMetadataUsagePair
metadataUsagePairsCount: Union[int, Version(Min=19, Max=24.4)]
fieldRefsOffset: Union[uint, Version(Min=19)] # Il2CppFieldRef
fieldRefsCount: Union[int, Version(Min=19)]
referencedAssembliesOffset: Union[int, Version(Min=20)] # int32_t
referencedAssembliesCount: Union[int, Version(Min=20)]
attributesInfoOffset: Union[uint, Version(Min=21)] # Il2CppCustomAttributeTypeRange
attributesInfoCount: Union[int, Version(Min=21)]
attributeTypesOffset: Union[uint, Version(Min=21)] # TypeIndex
attributeTypesCount: Union[int, Version(Min=21)]
unresolvedVirtualCallParameterTypesOffset: Union[int, Version(Min=22)] # TypeIndex
unresolvedVirtualCallParameterTypesCount: Union[int, Version(Min=22)]
unresolvedVirtualCallParameterRangesOffset: Union[
int, Version(Min=22)
] # Il2CppRange
unresolvedVirtualCallParameterRangesCount: Union[int, Version(Min=22)]
windowsRuntimeTypeNamesOffset: Union[
int, Version(Min=23)
] # Il2CppWindowsRuntimeTypeNamePair
windowsRuntimeTypeNamesSize: Union[int, Version(Min=23)]
windowsRuntimeStringsOffset: Union[int, Version(Min=27)] # const char*
windowsRuntimeStringsSize: Union[int, Version(Min=27)]
exportedTypeDefinitionsOffset: Union[int, Version(Min=24)] # TypeDefinitionIndex
exportedTypeDefinitionsCount: Union[int, Version(Min=24)]
class Il2CppImageDefinition(MetaDataClass):
nameIndex: uint
assemblyIndex: int
typeStart: int
typeCount: uint
exportedTypeStart: Union[int, Version(Min=24)]
exportedTypeCount: Union[uint, Version(Min=24)]
entryPointIndex: int
token: Union[uint, Version(Min=19)]
customAttributeStart: Union[int, Version(Min=24.1)]
customAttributeCount: Union[uint, Version(Min=24.1)]
class Il2CppTypeDefinition(MetaDataClass):
nameIndex: uint
namespaceIndex: uint
customAttributeIndex: Union[int, Version(Max=24)]
byvalTypeIndex: int
byrefTypeIndex: Union[int, Version(Max=24.4)]
declaringTypeIndex: int
parentIndex: int
elementTypeIndex: int # we can probably remove this one. Only used for enums
rgctxStartIndex: Union[int, Version(Max=24.1)]
rgctxCount: Union[int, Version(Max=24.1)]
genericContainerIndex: int
delegateWrapperFromManagedToNativeIndex: Union[int, Version(Max=22)]
marshalingFunctionsIndex: Union[int, Version(Max=22)]
ccwFunctionIndex: Union[int, Version(Min=21, Max=22)]
guidIndex: Union[int, Version(Min=21, Max=22)]
flags: uint
fieldStart: int
methodStart: int
eventStart: int
propertyStart: int
nestedTypesStart: int
interfacesStart: int
vtableStart: int
interfaceOffsetsStart: int
method_count: ushort
property_count: ushort
field_count: ushort
event_count: ushort
nested_type_count: ushort
vtable_count: ushort
interfaces_count: ushort
interface_offsets_count: ushort
# bitfield to portably encode boolean values as single bits
# 01 - valuetype;
# 02 - enumtype;
# 03 - has_finalize;
# 04 - has_cctor;
# 05 - is_blittable;
# 06 - is_import_or_windows_runtime;
# 07-10 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128)
# 11 - PackingSize is default
# 12 - ClassSize is default
# 13-16 - One of nine possible PackingSize values (0, 1, 2, 4, 8, 16, 32, 64, or 128) - the specified packing size (even for explicit layouts)
bitfield: uint
token: Union[uint, Version(Min=19)]
@property
def IsValueType(self) -> bool:
return (self.bitfield & 0x1) == 1
@property
def IsEnum(self) -> bool:
return ((self.bitfield >> 1) & 0x1) == 1
class Il2CppMethodDefinition(MetaDataClass):
nameIndex: uint
declaringType: int
returnType: int
parameterStart: int
customAttributeIndex: Union[int, Version(Max=24)]
genericContainerIndex: int
methodIndex: Union[int, Version(Max=24.1)]
invokerIndex: Union[int, Version(Max=24.1)]
delegateWrapperIndex: Union[int, Version(Max=24.1)]
rgctxStartIndex: Union[int, Version(Max=24.1)]
rgctxCount: Union[int, Version(Max=24.1)]
token: uint
flags: ushort
iflags: ushort
slot: ushort
parameterCount: ushort
class Il2CppParameterDefinition(MetaDataClass):
nameIndex: uint
token: uint
customAttributeIndex: Union[int, Version(Max=24)]
typeIndex: int
class Il2CppFieldDefinition(MetaDataClass):
nameIndex: uint
typeIndex: int
customAttributeIndex: Union[int, Version(Max=24)]
token: Union[uint, Version(Min=19)]
class Il2CppFieldDefaultValue(MetaDataClass):
fieldIndex: int
typeIndex: int
dataIndex: int
class Il2CppPropertyDefinition(MetaDataClass):
nameIndex: uint
get: int
set: int
attrs: uint
customAttributeIndex: Union[int, Version(Max=24)]
token: Union[uint, Version(Min=19)]
class Il2CppCustomAttributeTypeRange(MetaDataClass):
token: Union[uint, Version(Min=24.1)]
start: int
count: int
class Il2CppMetadataUsageList(MetaDataClass):
start: uint
count: uint
class Il2CppMetadataUsagePair(MetaDataClass):
destinationIndex: uint
encodedSourceIndex: uint
class Il2CppStringLiteral(MetaDataClass):
length: uint
dataIndex: int
class Il2CppParameterDefaultValue(MetaDataClass):
parameterIndex: int
typeIndex: int
dataIndex: int
class Il2CppEventDefinition(MetaDataClass):
nameIndex: uint
typeIndex: int
add: int
remove: int
rais: int
customAttributeIndex: Union[int, Version(Max=24)]
token: Union[uint, Version(Min=19)]
class Il2CppGenericContainer(MetaDataClass):
# index of the generic type definition or the generic method definition corresponding to this container
ownerIndex: int # either index into Il2CppClass metadata array or Il2CppMethodDefinition array
type_argc: int
# If true, we're a generic method, otherwise a generic type definition.
is_method: int
# Our type parameters.
genericParameterStart: int
class Il2CppFieldRef(MetaDataClass):
typeIndex: int
fieldIndex: int # local offset into type fields
class Il2CppGenericParameter(MetaDataClass):
ownerIndex: int # Type or method this parameter was defined in.
nameIndex: uint
constraintsStart: short
constraintsCount: short
num: ushort
flags: ushort
class Il2CppRGCTXDataType(uint, Enum):
IL2CPP_RGCTX_DATA_INVALID = 0
IL2CPP_RGCTX_DATA_TYPE = 1
IL2CPP_RGCTX_DATA_CLASS = 2
IL2CPP_RGCTX_DATA_METHOD = 3
IL2CPP_RGCTX_DATA_ARRAY = 4
class Il2CppRGCTXDefinitionData(MetaDataClass):
rgctxDataDummy: int
@property
def methodIndex(self) -> int:
return self.rgctxDataDummy
@property
def typeIndex(self) -> int:
return self.rgctxDataDummy
class Il2CppRGCTXDefinition:
type: Il2CppRGCTXDataType
data: Il2CppRGCTXDefinitionData
version: float
size: int
parseString: str
def __init__(self, reader: BinaryIO = None) -> None:
if not (self.version):
raise NotImplementedError(
"Using an unversioned MetaDataClass isn't possible."
)
if reader:
self.read_from(reader)
def read_from(self, reader: BytesIO):
self.type = Il2CppRGCTXDataType.read_from(reader)
self.data = Il2CppRGCTXDefinitionData.generate_versioned_subclass(self.version)(
reader
)
def write_to(self, writer: BytesIO):
self.type = self.data.write_to(writer)
self.data.write_to(writer)
@classmethod
def generate_versioned_subclass(cls, version: float):
cls.version = version
cls.size = 8 # TODO if data changes
return cls