Model: Make assembly definitions available

This commit is contained in:
Katy Coe
2019-11-11 01:37:51 +01:00
parent e923a51fc0
commit 734e88a07b
5 changed files with 18 additions and 11 deletions

View File

@@ -33,7 +33,7 @@ namespace Il2CppInspector
public void WriteFile(string outFile) {
using (writer = new StreamWriter(new FileStream(outFile, FileMode.Create), Encoding.UTF8)) {
foreach (var asm in model.Assemblies) {
writer.Write($"// Image {asm.Index}: {asm.FullName} - {asm.Definition.typeStart}\n");
writer.Write($"// Image {asm.Index}: {asm.FullName} - {asm.ImageDefinition.typeStart}\n");
// Assembly-level attributes
writer.Write(asm.CustomAttributes.ToString(attributePrefix: "assembly: "));

View File

@@ -24,6 +24,7 @@ namespace Il2CppInspector
public Dictionary<int, string> Strings => Metadata.Strings;
public Il2CppTypeDefinition[] TypeDefinitions => Metadata.Types;
public Il2CppAssemblyDefinition[] Assemblies => Metadata.Assemblies;
public Il2CppImageDefinition[] Images => Metadata.Images;
public Il2CppMethodDefinition[] Methods => Metadata.Methods;
public Il2CppParameterDefinition[] Params => Metadata.Params;

View File

@@ -113,7 +113,7 @@ namespace Il2CppInspector.Reflection
if (Package.Version <= 24.0)
return customAttributeIndex;
var image = asm.Definition;
var image = asm.ImageDefinition;
var imageRange = image.customAttributeStart..(int)(image.customAttributeStart + image.customAttributeCount);
// From v24.1 onwards, token was added to Il2CppCustomAttributeTypeRange and each Il2CppImageDefinition noted the CustomAttributeTypeRanges for the image

View File

@@ -13,8 +13,9 @@ namespace Il2CppInspector.Reflection {
{
// IL2CPP-specific data
public Il2CppModel Model { get; }
public Il2CppImageDefinition Definition { get; }
public Il2CppCodeGenModule Module { get; }
public Il2CppImageDefinition ImageDefinition { get; }
public Il2CppAssemblyDefinition AssemblyDefinition { get; }
public Il2CppCodeGenModule ModuleDefinition { get; }
public int Index { get; }
// Custom attributes for this assembly
@@ -35,19 +36,24 @@ namespace Il2CppInspector.Reflection {
// Initialize from specified assembly index in package
public Assembly(Il2CppModel model, int imageIndex) {
Model = model;
Definition = Model.Package.Images[imageIndex];
Index = Definition.assemblyIndex;
FullName = Model.Package.Strings[Definition.nameIndex];
ImageDefinition = Model.Package.Images[imageIndex];
AssemblyDefinition = Model.Package.Assemblies[ImageDefinition.assemblyIndex];
if (Definition.entryPointIndex != -1) {
if (AssemblyDefinition.imageIndex != imageIndex)
throw new InvalidOperationException("Assembly/image index mismatch");
Index = ImageDefinition.assemblyIndex;
FullName = Model.Package.Strings[ImageDefinition.nameIndex];
if (ImageDefinition.entryPointIndex != -1) {
// TODO: Generate EntryPoint method from entryPointIndex
}
// Find corresponding module (we'll need this for method pointers)
Module = Model.Package.Modules?[FullName];
ModuleDefinition = Model.Package.Modules?[FullName];
// Generate types in DefinedTypes from typeStart to typeStart+typeCount-1
for (var t = Definition.typeStart; t < Definition.typeStart + Definition.typeCount; t++) {
for (var t = ImageDefinition.typeStart; t < ImageDefinition.typeStart + ImageDefinition.typeCount; t++) {
var type = new TypeInfo(t, this);
// Don't add empty module definitions

View File

@@ -61,7 +61,7 @@ namespace Il2CppInspector.Reflection
Name = pkg.Strings[Definition.nameIndex];
// Find method pointer
VirtualAddress = pkg.GetMethodPointer(Assembly.Module, Definition);
VirtualAddress = pkg.GetMethodPointer(Assembly.ModuleDefinition, Definition);
// Add to global method definition list
Assembly.Model.MethodsByDefinitionIndex[Index] = this;