Roll up Il2CppInspector.Binary and Il2CppInspector.Metadata
This commit is contained in:
@@ -12,17 +12,32 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Il2CppInspector
|
namespace Il2CppInspector
|
||||||
{
|
{
|
||||||
|
// Il2CppInspector ties together the binary and metadata files into a congruent API surface
|
||||||
public class Il2CppInspector
|
public class Il2CppInspector
|
||||||
{
|
{
|
||||||
public Il2CppBinary Binary { get; }
|
private Il2CppBinary Binary { get; }
|
||||||
public Metadata Metadata { get; }
|
private Metadata Metadata { get; }
|
||||||
|
|
||||||
// Shortcuts
|
// Shortcuts
|
||||||
|
public double Version => Metadata.Version;
|
||||||
|
|
||||||
public Dictionary<int, string> Strings => Metadata.Strings;
|
public Dictionary<int, string> Strings => Metadata.Strings;
|
||||||
public Il2CppTypeDefinition[] TypeDefinitions => Metadata.Types;
|
public Il2CppTypeDefinition[] TypeDefinitions => Metadata.Types;
|
||||||
public List<Il2CppType> TypeUsages => Binary.Types;
|
public Il2CppImageDefinition[] Images => Metadata.Images;
|
||||||
|
public Il2CppMethodDefinition[] Methods => Metadata.Methods;
|
||||||
|
public Il2CppParameterDefinition[] Params => Metadata.Params;
|
||||||
|
public Il2CppFieldDefinition[] Fields => Metadata.Fields;
|
||||||
|
public Il2CppPropertyDefinition[] Properties => Metadata.Properties;
|
||||||
|
public Il2CppEventDefinition[] Events => Metadata.Events;
|
||||||
|
public int[] InterfaceUsageIndices => Metadata.InterfaceUsageIndices;
|
||||||
public Dictionary<int, object> FieldDefaultValue { get; } = new Dictionary<int, object>();
|
public Dictionary<int, object> FieldDefaultValue { get; } = new Dictionary<int, object>();
|
||||||
public List<int> FieldOffsets { get; }
|
public List<int> FieldOffsets { get; }
|
||||||
|
public List<Il2CppType> TypeUsages => Binary.Types;
|
||||||
|
public Dictionary<string, Il2CppCodeGenModule> Modules => Binary.Modules;
|
||||||
|
public uint[] MethodPointers => Binary.MethodPointers;
|
||||||
|
|
||||||
|
// TODO: Finish all file access in the constructor and eliminate the need for this
|
||||||
|
public IFileFormatReader BinaryImage { get; }
|
||||||
|
|
||||||
public Il2CppInspector(Il2CppBinary binary, Metadata metadata) {
|
public Il2CppInspector(Il2CppBinary binary, Metadata metadata) {
|
||||||
// Store stream representations
|
// Store stream representations
|
||||||
@@ -96,10 +111,10 @@ namespace Il2CppInspector
|
|||||||
// Get all field offsets
|
// Get all field offsets
|
||||||
|
|
||||||
// Versions from 22 onwards use an array of pointers in Binary.FieldOffsetData
|
// Versions from 22 onwards use an array of pointers in Binary.FieldOffsetData
|
||||||
bool fieldOffsetsArePointers = (Metadata.Version >= 22);
|
bool fieldOffsetsArePointers = (Version >= 22);
|
||||||
|
|
||||||
// Some variants of 21 also use an array of pointers
|
// Some variants of 21 also use an array of pointers
|
||||||
if (Metadata.Version == 21) {
|
if (Version == 21) {
|
||||||
var f = Binary.FieldOffsetData;
|
var f = Binary.FieldOffsetData;
|
||||||
// We detect this by relying on the fact Module, Object, ValueType, Attribute, _Attribute and Int32
|
// We detect this by relying on the fact Module, Object, ValueType, Attribute, _Attribute and Int32
|
||||||
// are always the first six defined types, and that all but Int32 have no fields
|
// are always the first six defined types, and that all but Int32 have no fields
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -19,7 +19,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
Package = package;
|
Package = package;
|
||||||
|
|
||||||
// Create Assembly objects from Il2Cpp package
|
// Create Assembly objects from Il2Cpp package
|
||||||
for (var image = 0; image < package.Metadata.Images.Length; image++)
|
for (var image = 0; image < package.Images.Length; image++)
|
||||||
Assemblies.Add(new Assembly(this, image));
|
Assemblies.Add(new Assembly(this, image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -34,7 +34,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// Initialize from specified assembly index in package
|
// Initialize from specified assembly index in package
|
||||||
public Assembly(Il2CppReflector model, int imageIndex) {
|
public Assembly(Il2CppReflector model, int imageIndex) {
|
||||||
Model = model;
|
Model = model;
|
||||||
Definition = Model.Package.Metadata.Images[imageIndex];
|
Definition = Model.Package.Images[imageIndex];
|
||||||
Index = Definition.assemblyIndex;
|
Index = Definition.assemblyIndex;
|
||||||
FullName = Model.Package.Strings[Definition.nameIndex];
|
FullName = Model.Package.Strings[Definition.nameIndex];
|
||||||
|
|
||||||
@@ -43,8 +43,8 @@ namespace Il2CppInspector.Reflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find corresponding module (we'll need this for method pointers)
|
// Find corresponding module (we'll need this for method pointers)
|
||||||
if (Model.Package.Metadata.Version >= 24.1)
|
if (Model.Package.Version >= 24.1)
|
||||||
Module = Model.Package.Binary.Modules[FullName];
|
Module = Model.Package.Modules[FullName];
|
||||||
|
|
||||||
// Generate types in DefinedTypes from typeStart to typeStart+typeCount-1
|
// Generate types in DefinedTypes from typeStart to typeStart+typeCount-1
|
||||||
for (var t = Definition.typeStart; t < Definition.typeStart + Definition.typeCount; t++)
|
for (var t = Definition.typeStart; t < Definition.typeStart + Definition.typeCount; t++)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +33,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
public EventInfo(Il2CppInspector pkg, int eventIndex, TypeInfo declaringType) :
|
public EventInfo(Il2CppInspector pkg, int eventIndex, TypeInfo declaringType) :
|
||||||
base(declaringType) {
|
base(declaringType) {
|
||||||
Definition = pkg.Metadata.Events[eventIndex];
|
Definition = pkg.Events[eventIndex];
|
||||||
Index = eventIndex;
|
Index = eventIndex;
|
||||||
Name = pkg.Strings[Definition.nameIndex];
|
Name = pkg.Strings[Definition.nameIndex];
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -83,7 +83,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
|
|
||||||
public FieldInfo(Il2CppInspector pkg, int fieldIndex, TypeInfo declaringType) :
|
public FieldInfo(Il2CppInspector pkg, int fieldIndex, TypeInfo declaringType) :
|
||||||
base(declaringType) {
|
base(declaringType) {
|
||||||
Definition = pkg.Metadata.Fields[fieldIndex];
|
Definition = pkg.Fields[fieldIndex];
|
||||||
Index = fieldIndex;
|
Index = fieldIndex;
|
||||||
Offset = pkg.FieldOffsets[fieldIndex];
|
Offset = pkg.FieldOffsets[fieldIndex];
|
||||||
Name = pkg.Strings[Definition.nameIndex];
|
Name = pkg.Strings[Definition.nameIndex];
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
|
|
||||||
public MethodInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) :
|
public MethodInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) :
|
||||||
base(declaringType) {
|
base(declaringType) {
|
||||||
Definition = pkg.Metadata.Methods[methodIndex];
|
Definition = pkg.Methods[methodIndex];
|
||||||
Index = methodIndex;
|
Index = methodIndex;
|
||||||
Name = pkg.Strings[Definition.nameIndex];
|
Name = pkg.Strings[Definition.nameIndex];
|
||||||
|
|
||||||
@@ -39,16 +39,16 @@ namespace Il2CppInspector.Reflection
|
|||||||
if (Definition.methodIndex >= 0) {
|
if (Definition.methodIndex >= 0) {
|
||||||
|
|
||||||
// Global method pointer array
|
// Global method pointer array
|
||||||
if (pkg.Metadata.Version < 24.1) {
|
if (pkg.Version < 24.1) {
|
||||||
VirtualAddress = pkg.Binary.MethodPointers[Definition.methodIndex];
|
VirtualAddress = pkg.MethodPointers[Definition.methodIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Per-module method pointer array uses the bottom 24 bits of the method's metadata token
|
// Per-module method pointer array uses the bottom 24 bits of the method's metadata token
|
||||||
// Derived from il2cpp::vm::MetadataCache::GetMethodPointer
|
// Derived from il2cpp::vm::MetadataCache::GetMethodPointer
|
||||||
else {
|
else {
|
||||||
var method = (Definition.token & 0xffffff) - 1;
|
var method = (Definition.token & 0xffffff) - 1;
|
||||||
pkg.Binary.Image.Position = pkg.Binary.Image.MapVATR(Assembly.Module.methodPointers + method * 4);
|
pkg.BinaryImage.Position = pkg.BinaryImage.MapVATR(Assembly.Module.methodPointers + method * 4);
|
||||||
VirtualAddress = pkg.Binary.Image.ReadUInt32();
|
VirtualAddress = pkg.BinaryImage.ReadUInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove ARM Thumb marker LSB if necessary
|
// Remove ARM Thumb marker LSB if necessary
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -51,8 +51,8 @@ namespace Il2CppInspector.Reflection
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var param = pkg.Metadata.Params[paramIndex];
|
var param = pkg.Params[paramIndex];
|
||||||
Name = pkg.Metadata.Strings[param.nameIndex];
|
Name = pkg.Strings[param.nameIndex];
|
||||||
Position = paramIndex - declaringMethod.Definition.parameterStart;
|
Position = paramIndex - declaringMethod.Definition.parameterStart;
|
||||||
paramType = pkg.TypeUsages[param.typeIndex];
|
paramType = pkg.TypeUsages[param.typeIndex];
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -25,7 +25,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
|
|
||||||
public PropertyInfo(Il2CppInspector pkg, int propIndex, TypeInfo declaringType) :
|
public PropertyInfo(Il2CppInspector pkg, int propIndex, TypeInfo declaringType) :
|
||||||
base(declaringType) {
|
base(declaringType) {
|
||||||
var prop = pkg.Metadata.Properties[propIndex];
|
var prop = pkg.Properties[propIndex];
|
||||||
|
|
||||||
Name = pkg.Strings[prop.nameIndex];
|
Name = pkg.Strings[prop.nameIndex];
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2017 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
@@ -183,7 +183,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// Add all implemented interfaces
|
// Add all implemented interfaces
|
||||||
implementedInterfaces = new Il2CppType[Definition.interfaces_count];
|
implementedInterfaces = new Il2CppType[Definition.interfaces_count];
|
||||||
for (var i = 0; i < Definition.interfaces_count; i++)
|
for (var i = 0; i < Definition.interfaces_count; i++)
|
||||||
implementedInterfaces[i] = pkg.TypeUsages[pkg.Metadata.InterfaceUsageIndices[Definition.interfacesStart + i]];
|
implementedInterfaces[i] = pkg.TypeUsages[pkg.InterfaceUsageIndices[Definition.interfacesStart + i]];
|
||||||
|
|
||||||
// Add all fields
|
// Add all fields
|
||||||
for (var f = Definition.fieldStart; f < Definition.fieldStart + Definition.field_count; f++)
|
for (var f = Definition.fieldStart; f < Definition.fieldStart + Definition.field_count; f++)
|
||||||
@@ -205,7 +205,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
|
|
||||||
// Initialize type from binary usage
|
// Initialize type from binary usage
|
||||||
public TypeInfo(Il2CppReflector model, Il2CppType pType, MemberTypes memberType) : base(null) {
|
public TypeInfo(Il2CppReflector model, Il2CppType pType, MemberTypes memberType) : base(null) {
|
||||||
var image = model.Package.Binary.Image;
|
var image = model.Package.BinaryImage;
|
||||||
|
|
||||||
IsNested = true;
|
IsNested = true;
|
||||||
MemberType = memberType;
|
MemberType = memberType;
|
||||||
|
|||||||
Reference in New Issue
Block a user