Model: Add GetMethodBody() to CustomAttributeData and MethodInvoker
This commit is contained in:
@@ -34,6 +34,9 @@ namespace Il2CppInspector.Reflection
|
||||
|
||||
public override string ToString() => "[" + AttributeType.FullName + "]";
|
||||
|
||||
// Get the machine code of the C++ function
|
||||
public byte[] GetMethodBody() => Model.Package.BinaryImage.ReadMappedBytes(VirtualAddress.Start, (int) (VirtualAddress.End - VirtualAddress.Start));
|
||||
|
||||
// Get all the custom attributes for a given assembly, type, member or parameter
|
||||
private static IEnumerable<CustomAttributeData> getCustomAttributes(Assembly asm, int customAttributeIndex) {
|
||||
if (customAttributeIndex < 0)
|
||||
|
||||
@@ -89,8 +89,7 @@ namespace Il2CppInspector.Reflection
|
||||
return null;
|
||||
|
||||
var image = Assembly.Model.Package.BinaryImage;
|
||||
image.Position = image.MapVATR(VirtualAddress.Value.Start);
|
||||
return image.ReadBytes((int) (VirtualAddress.Value.End - VirtualAddress.Value.Start));
|
||||
return image.ReadMappedBytes(VirtualAddress.Value.Start, (int) (VirtualAddress.Value.End - VirtualAddress.Value.Start));
|
||||
}
|
||||
|
||||
public string CSharpName =>
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace Il2CppInspector.Reflection
|
||||
// IL2CPP invoker index
|
||||
public int Index { get; }
|
||||
|
||||
// IL2CPP package
|
||||
public Il2CppInspector Package { get; }
|
||||
|
||||
// Virtual address of the invoker function
|
||||
public (ulong Start, ulong End) VirtualAddress { get; }
|
||||
|
||||
@@ -35,7 +38,7 @@ namespace Il2CppInspector.Reflection
|
||||
// Find the correct method invoker for a method with a specific signature
|
||||
public MethodInvoker(MethodBase exampleMethod, int index) {
|
||||
var model = exampleMethod.Assembly.Model;
|
||||
var package = exampleMethod.Assembly.Model.Package;
|
||||
Package = exampleMethod.Assembly.Model.Package;
|
||||
|
||||
Index = index;
|
||||
IsStatic = exampleMethod.IsStatic;
|
||||
@@ -43,8 +46,8 @@ namespace Il2CppInspector.Reflection
|
||||
ReturnType = exampleMethod.IsConstructor ? model.TypesByFullName["System.Void"] : mapParameterType(model, ((MethodInfo) exampleMethod).ReturnType);
|
||||
ParameterTypes = exampleMethod.DeclaredParameters.Select(p => mapParameterType(model, p.ParameterType)).ToArray();
|
||||
|
||||
var start = package.MethodInvokePointers[Index];
|
||||
VirtualAddress = (start & 0xffff_ffff_ffff_fffe, package.FunctionAddresses[start]);
|
||||
var start = Package.MethodInvokePointers[Index];
|
||||
VirtualAddress = (start & 0xffff_ffff_ffff_fffe, Package.FunctionAddresses[start]);
|
||||
}
|
||||
|
||||
// The invokers use Object for all reference types, and SByte for booleans
|
||||
@@ -54,6 +57,9 @@ namespace Il2CppInspector.Reflection
|
||||
_ => type
|
||||
};
|
||||
|
||||
// Get the machine code of the C++ function
|
||||
public byte[] GetMethodBody() => Package.BinaryImage.ReadMappedBytes(VirtualAddress.Start, (int) (VirtualAddress.End - VirtualAddress.Start));
|
||||
|
||||
public string Name => $"RuntimeInvoker_{!IsStatic}{ReturnType.BaseName.ToCIdentifier()}_" + string.Join("_", ParameterTypes.Select(p => p.BaseName.ToCIdentifier()));
|
||||
|
||||
// Display as a C++ method signature; MethodInfo* is the same as RuntimeMethod* (see codegen/il2cpp-codegen-metadata.h)
|
||||
|
||||
Reference in New Issue
Block a user