Move method pointer logic from Model to Inspector
This commit is contained in:
@@ -35,7 +35,6 @@ namespace Il2CppInspector
|
|||||||
public List<long> FieldOffsets { get; }
|
public List<long> FieldOffsets { get; }
|
||||||
public List<Il2CppType> TypeUsages => Binary.Types;
|
public List<Il2CppType> TypeUsages => Binary.Types;
|
||||||
public Dictionary<string, Il2CppCodeGenModule> Modules => Binary.Modules;
|
public Dictionary<string, Il2CppCodeGenModule> Modules => Binary.Modules;
|
||||||
public ulong[] GlobalMethodPointers => Binary.GlobalMethodPointers; // <=v24.1 only
|
|
||||||
|
|
||||||
// TODO: Finish all file access in the constructor and eliminate the need for this
|
// TODO: Finish all file access in the constructor and eliminate the need for this
|
||||||
public IFileFormatReader BinaryImage => Binary.Image;
|
public IFileFormatReader BinaryImage => Binary.Image;
|
||||||
@@ -141,6 +140,35 @@ namespace Il2CppInspector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ulong GetMethodPointer(Il2CppCodeGenModule module, Il2CppMethodDefinition methodDef) {
|
||||||
|
// Find method pointer
|
||||||
|
if (methodDef.methodIndex < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Global method pointer array
|
||||||
|
if (Version <= 24.1) {
|
||||||
|
return Binary.GlobalMethodPointers[methodDef.methodIndex] & 0xffff_ffff_ffff_fffe;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Per-module method pointer array uses the bottom 24 bits of the method's metadata token
|
||||||
|
// Derived from il2cpp::vm::MetadataCache::GetMethodPointer
|
||||||
|
var method = (methodDef.token & 0xffffff);
|
||||||
|
if (method == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// In the event of an exception, the method pointer is not set in the file
|
||||||
|
// This probably means it has been optimized away by the compiler, or is an unused generic method
|
||||||
|
try {
|
||||||
|
BinaryImage.Position = BinaryImage.MapVATR(module.methodPointers + (ulong)((method - 1) * (BinaryImage.Bits / 8)));
|
||||||
|
|
||||||
|
// Remove ARM Thumb marker LSB if necessary
|
||||||
|
return (ulong) BinaryImage.ReadWord() & 0xffff_ffff_ffff_fffe;
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Il2CppInspector> LoadFromFile(string codeFile, string metadataFile) {
|
public static List<Il2CppInspector> LoadFromFile(string codeFile, string metadataFile) {
|
||||||
// Load the metadata file
|
// Load the metadata file
|
||||||
Metadata metadata;
|
Metadata metadata;
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ 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.Version >= 24.2)
|
Module = Model.Package.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++) {
|
||||||
|
|||||||
@@ -52,32 +52,9 @@ namespace Il2CppInspector.Reflection
|
|||||||
Name = pkg.Strings[Definition.nameIndex];
|
Name = pkg.Strings[Definition.nameIndex];
|
||||||
|
|
||||||
// Find method pointer
|
// Find method pointer
|
||||||
if (Definition.methodIndex >= 0) {
|
VirtualAddress = pkg.GetMethodPointer(Assembly.Module, Definition);
|
||||||
|
|
||||||
// Global method pointer array
|
|
||||||
if (pkg.Version <= 24.1) {
|
|
||||||
VirtualAddress = pkg.GlobalMethodPointers[Definition.methodIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Per-module method pointer array uses the bottom 24 bits of the method's metadata token
|
|
||||||
// Derived from il2cpp::vm::MetadataCache::GetMethodPointer
|
|
||||||
else {
|
|
||||||
var method = (Definition.token & 0xffffff);
|
|
||||||
if (method != 0) {
|
|
||||||
// In the event of an exception, the method pointer is not set in the file
|
|
||||||
// This probably means it has been optimized away by the compiler, or is an unused generic method
|
|
||||||
try {
|
|
||||||
pkg.BinaryImage.Position = pkg.BinaryImage.MapVATR(Assembly.Module.methodPointers + (ulong)((method - 1) * (pkg.BinaryImage.Bits / 8)));
|
|
||||||
VirtualAddress = (ulong)pkg.BinaryImage.ReadWord();
|
|
||||||
}
|
|
||||||
catch (Exception) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove ARM Thumb marker LSB if necessary
|
|
||||||
VirtualAddress &= 0xffff_ffff_ffff_fffe;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Set method attributes
|
||||||
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PRIVATE)
|
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PRIVATE)
|
||||||
Attributes |= MethodAttributes.Private;
|
Attributes |= MethodAttributes.Private;
|
||||||
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PUBLIC)
|
if ((Definition.flags & Il2CppConstants.METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == Il2CppConstants.METHOD_ATTRIBUTE_PUBLIC)
|
||||||
|
|||||||
Reference in New Issue
Block a user