C++: Re-factor custom attribute generator signature handling
This commit is contained in:
@@ -53,9 +53,6 @@ namespace Il2CppInspector.Model
|
||||
// For il2cpp < 19, the key is the string literal ordinal instead of the address
|
||||
public Dictionary<ulong, string> Strings = new Dictionary<ulong, string>();
|
||||
|
||||
// All of the custom attribute generator functions in the library
|
||||
public Dictionary<CustomAttributeData, AppMethod> CustomAttributeGenerators = new Dictionary<CustomAttributeData, AppMethod>();
|
||||
|
||||
public bool StringIndexesAreOrdinals => Package.MetadataUsages == null;
|
||||
|
||||
// The .NET type model for the application
|
||||
@@ -222,17 +219,6 @@ namespace Il2CppInspector.Model
|
||||
}
|
||||
}
|
||||
|
||||
// Add custom attribute generators to the model
|
||||
foreach (var cppMethod in ILModel.AttributesByIndices.Values.Where(m => m.VirtualAddress.HasValue)) {
|
||||
var cppMethodName = declarationGenerator.TypeNamer.GetName(cppMethod.AttributeType) + "_CustomAttributesCacheGenerator";
|
||||
var fnPtrType = CppFnPtrType.FromSignature(CppTypeCollection, $"void (*{cppMethodName})(CustomAttributesCache *)");
|
||||
fnPtrType.Name = cppMethodName;
|
||||
fnPtrType.Group = "custom_attribute_generators";
|
||||
|
||||
var appMethod = new AppMethod(null, fnPtrType, cppMethod.VirtualAddress.Value.Start) {Group = fnPtrType.Group};
|
||||
CustomAttributeGenerators.Add(cppMethod, appMethod);
|
||||
}
|
||||
|
||||
// This is to allow this method to be chained after a new expression
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -104,11 +104,13 @@ typedef __int64 int64_t;
|
||||
writeMethods(model.GetMethodGroup("types_from_generic_methods"));
|
||||
|
||||
writeSectionHeader("Custom attributes generators");
|
||||
writeMethods(model.CustomAttributeGenerators.Values, asRefs: true);
|
||||
foreach (var method in model.ILModel.AttributesByIndices.Values) {
|
||||
writeTypedName(method.VirtualAddress.Value.Start, method.Signature, method.Name);
|
||||
}
|
||||
|
||||
writeSectionHeader("Method.Invoke thunks");
|
||||
foreach (var method in model.ILModel.MethodInvokers.Where(m => m != null)) {
|
||||
writeTypedName(method.VirtualAddress.Start, method.ToString(), method.Name);
|
||||
writeTypedName(method.VirtualAddress.Start, method.Signature, method.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,14 +119,10 @@ typedef __int64 int64_t;
|
||||
writeDecls(type.ToString());
|
||||
}
|
||||
|
||||
private void writeMethods(IEnumerable<AppMethod> methods, bool asRefs = false) {
|
||||
private void writeMethods(IEnumerable<AppMethod> methods) {
|
||||
foreach (var method in methods) {
|
||||
var address = asRefs? method.MethodInfoPtrAddress : method.MethodCodeAddress;
|
||||
writeTypedName(address, method.CppFnPtrType.ToSignatureString(), method.CppFnPtrType.Name);
|
||||
|
||||
// C++-only methods won't have an IL equivalent, eg. invokers and custom attribute generators
|
||||
if (method.Method != null)
|
||||
writeComment(address, method.Method);
|
||||
writeTypedName(method.MethodCodeAddress, method.CppFnPtrType.ToSignatureString(), method.CppFnPtrType.Name);
|
||||
writeComment(method.MethodCodeAddress, method.Method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,13 @@ namespace Il2CppInspector.Reflection
|
||||
// The last one will be wrong but there is no way to calculate it
|
||||
(Model.Package.CustomAttributeGenerators[Index], Model.Package.FunctionAddresses[Model.Package.CustomAttributeGenerators[Index]]);
|
||||
|
||||
// C++ method names
|
||||
// TODO: Known issue here where we should be using CppDeclarationGenerator.TypeNamer to ensure uniqueness
|
||||
public string Name => $"{AttributeType.Name.ToCIdentifier()}_CustomAttributesCacheGenerator";
|
||||
|
||||
// C++ method signature
|
||||
public string Signature => $"void {Name}(CustomAttributesCache *)";
|
||||
|
||||
public override string ToString() => "[" + AttributeType.FullName + "]";
|
||||
|
||||
// Get all the custom attributes for a given assembly, type, member or parameter
|
||||
|
||||
Reference in New Issue
Block a user