Add fields to script export (PrivateImplementationDetails)

This commit is contained in:
LukeFZ
2023-11-29 19:59:48 +01:00
parent e6355bb1b4
commit 2d73e28cea
3 changed files with 445 additions and 413 deletions

View File

@@ -51,6 +51,8 @@ namespace Il2CppInspector.Model
// For il2cpp < 19, the key is the string literal ordinal instead of the address
public Dictionary<ulong, string> Strings { get; } = new Dictionary<ulong, string>();
public Dictionary<ulong, string> Fields { get; } = new Dictionary<ulong, string>();
public bool StringIndexesAreOrdinals => Package.Version < 19;
// The .NET type model for the application
@@ -243,6 +245,16 @@ namespace Il2CppInspector.Model
}
Methods[method].MethodInfoPtrAddress = address;
break;
case MetadataUsageType.FieldInfo:
if (usage.SourceIndex > TypeModel.Package.Metadata.FieldRefs.Length)
break;
var fieldRef = TypeModel.Package.FieldRefs[usage.SourceIndex];
var fieldType = TypeModel.GetMetadataUsageType(usage);
var field = fieldType.DeclaredFields.First(f => f.Index == fieldType.Definition.fieldStart + fieldRef.fieldIndex);
Fields.Add(usage.VirtualAddress, $"{fieldType.Name}.{field.Name}".ToCIdentifier());
break;
}
}

View File

@@ -41,6 +41,7 @@ namespace Il2CppInspector.Outputs
writeApis();
writeExports();
writeSymbols();
writeFields();
},
"Address map of methods, internal functions, type pointers and string literals in the binary file"
);
@@ -215,6 +216,20 @@ namespace Il2CppInspector.Outputs
}, "Symbol table");
}
private void writeFields()
{
writeArray("fields", () =>
{
foreach (var field in model.Fields)
{
writeObject(() =>
{
writeName(field.Key, field.Value);
});
}
});
}
// JSON helpers
private void writeObject(Action objectWriter) => writeObject(null, objectWriter);

View File

@@ -95,6 +95,11 @@ def ProcessJSON(jsonData):
for d in jsonData['methodInfoPointers']:
DefineILMethodInfo(d)
# FieldInfo
print('Processing FieldInfo pointers')
for d in jsonData['fields']:
DefineField(d['virtualAddress'], d['name'], r"uint64_t")
# Function boundaries
print('Processing function boundaries')
functionAddresses = jsonData['functionAddresses']