Add support for metadata version 29.2 and 31

This commit is contained in:
LukeFZ
2024-06-24 18:41:14 +02:00
parent 98edac1aea
commit 87766f6f96
7 changed files with 4871 additions and 10 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -88,7 +88,7 @@ namespace Il2CppInspector
// Set object versioning for Bin2Object from metadata version // Set object versioning for Bin2Object from metadata version
Version = Header.version; Version = Header.version;
if (Version < 16 || Version > 29.1) { if (Version < 16 || Version > 31) {
throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version})."); throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version}).");
} }

View File

@@ -314,6 +314,10 @@ namespace Il2CppInspector
public int declaringType; public int declaringType;
public int returnType; public int returnType;
[Version(Min = 31)]
public int returnParameterToken;
public int parameterStart; public int parameterStart;
[Version(Max = 24.0)] [Version(Max = 24.0)]
@@ -337,6 +341,9 @@ namespace Il2CppInspector
public ushort iflags; public ushort iflags;
public ushort slot; public ushort slot;
public ushort parameterCount; public ushort parameterCount;
[Version(Min = 29.2, Max = 31)]
public bool isUnmanagedCallersOnly;
} }
public class Il2CppParameterDefinition public class Il2CppParameterDefinition

View File

@@ -383,6 +383,15 @@ namespace Il2CppInspector.Outputs
mMethod.ParamDefs.Add(p); mMethod.ParamDefs.Add(p);
} }
if (method is MethodInfo { ReturnParameter: not null } methodInfo && methodInfo.ReturnParameter.MetadataToken != 0)
{
mMethod.Parameters.ReturnParameter.CreateParamDef();
var returnParam = mMethod.Parameters.ReturnParameter.ParamDef;
foreach (var ca in methodInfo.ReturnParameter.CustomAttributes)
AddCustomAttribute(module, returnParam, ca);
}
// Everything that's not extern, abstract or a delegate type should have a method body // Everything that's not extern, abstract or a delegate type should have a method body
if ((method.Attributes & System.Reflection.MethodAttributes.PinvokeImpl) == 0 if ((method.Attributes & System.Reflection.MethodAttributes.PinvokeImpl) == 0
&& method.DeclaringType.BaseType?.FullName != "System.MulticastDelegate" && method.DeclaringType.BaseType?.FullName != "System.MulticastDelegate"

View File

@@ -139,16 +139,16 @@ namespace Il2CppInspector.Reflection
} }
} }
private static IList<CustomAttributeData> getCustomAttributes(Assembly asm, int token, int customAttributeIndex) => public static IList<CustomAttributeData> GetCustomAttributes(Assembly asm, int token, int customAttributeIndex) =>
getCustomAttributes(asm, asm.Model.GetCustomAttributeIndex(asm, token, customAttributeIndex)).ToList(); getCustomAttributes(asm, asm.Model.GetCustomAttributeIndex(asm, token, customAttributeIndex)).ToList();
public static IList<CustomAttributeData> GetCustomAttributes(Assembly asm) => getCustomAttributes(asm, asm.MetadataToken, asm.AssemblyDefinition.customAttributeIndex); public static IList<CustomAttributeData> GetCustomAttributes(Assembly asm) => GetCustomAttributes(asm, asm.MetadataToken, asm.AssemblyDefinition.customAttributeIndex);
public static IList<CustomAttributeData> GetCustomAttributes(EventInfo evt) => getCustomAttributes(evt.Assembly, evt.MetadataToken, evt.Definition.customAttributeIndex); public static IList<CustomAttributeData> GetCustomAttributes(EventInfo evt) => GetCustomAttributes(evt.Assembly, evt.MetadataToken, evt.Definition.customAttributeIndex);
public static IList<CustomAttributeData> GetCustomAttributes(FieldInfo field) => getCustomAttributes(field.Assembly, field.MetadataToken, field.Definition.customAttributeIndex); public static IList<CustomAttributeData> GetCustomAttributes(FieldInfo field) => GetCustomAttributes(field.Assembly, field.MetadataToken, field.Definition.customAttributeIndex);
public static IList<CustomAttributeData> GetCustomAttributes(MethodBase method) => getCustomAttributes(method.Assembly, method.MetadataToken, method.Definition.customAttributeIndex); public static IList<CustomAttributeData> GetCustomAttributes(MethodBase method) => GetCustomAttributes(method.Assembly, method.MetadataToken, method.Definition.customAttributeIndex);
public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo param) => getCustomAttributes(param.DeclaringMethod.Assembly, param.MetadataToken, param.Definition.customAttributeIndex); public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo param) => GetCustomAttributes(param.DeclaringMethod.Assembly, param.MetadataToken, param.Definition.customAttributeIndex);
public static IList<CustomAttributeData> GetCustomAttributes(PropertyInfo prop) public static IList<CustomAttributeData> GetCustomAttributes(PropertyInfo prop)
=> prop.Definition != null ? getCustomAttributes(prop.Assembly, prop.MetadataToken, prop.Definition.customAttributeIndex) : new List<CustomAttributeData>(); => prop.Definition != null ? GetCustomAttributes(prop.Assembly, prop.MetadataToken, prop.Definition.customAttributeIndex) : new List<CustomAttributeData>();
public static IList<CustomAttributeData> GetCustomAttributes(TypeInfo type) => type.Definition != null? getCustomAttributes(type.Assembly, type.MetadataToken, type.Definition.customAttributeIndex) : new List<CustomAttributeData>(); public static IList<CustomAttributeData> GetCustomAttributes(TypeInfo type) => type.Definition != null? GetCustomAttributes(type.Assembly, type.MetadataToken, type.Definition.customAttributeIndex) : new List<CustomAttributeData>();
} }
} }

View File

@@ -25,7 +25,9 @@ namespace Il2CppInspector.Reflection
public ParameterAttributes Attributes { get; } public ParameterAttributes Attributes { get; }
// Custom attributes for this parameter // Custom attributes for this parameter
public IEnumerable<CustomAttributeData> CustomAttributes => CustomAttributeData.GetCustomAttributes(rootDefinition); public IEnumerable<CustomAttributeData> CustomAttributes => Position == -1 /* Return type */
? CustomAttributeData.GetCustomAttributes(DeclaringMethod.Assembly, MetadataToken, 0)
: CustomAttributeData.GetCustomAttributes(rootDefinition);
// True if the parameter has a default value // True if the parameter has a default value
public bool HasDefaultValue => (Attributes & ParameterAttributes.HasDefault) != 0; public bool HasDefaultValue => (Attributes & ParameterAttributes.HasDefault) != 0;
@@ -63,6 +65,7 @@ namespace Il2CppInspector.Reflection
if (paramIndex == -1) { if (paramIndex == -1) {
Position = -1; Position = -1;
paramTypeReference = TypeRef.FromReferenceIndex(declaringMethod.Assembly.Model, declaringMethod.Definition.returnType); paramTypeReference = TypeRef.FromReferenceIndex(declaringMethod.Assembly.Model, declaringMethod.Definition.returnType);
MetadataToken = declaringMethod.Definition.returnParameterToken;
Attributes |= ParameterAttributes.Retval; Attributes |= ParameterAttributes.Retval;
return; return;
} }