From 4ab71d8594eedee7da81e5783cd76d79661c6e4e Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Wed, 25 Oct 2017 05:53:34 +0200 Subject: [PATCH] Implement Reflection.Assembly --- Il2CppInspector/Il2CppReflector.cs | 13 ++---- Il2CppInspector/Reflection/Assembly.cs | 40 +++++++++++++++++++ .../Reflection/ReflectionClasses.cs | 19 --------- 3 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 Il2CppInspector/Reflection/Assembly.cs diff --git a/Il2CppInspector/Il2CppReflector.cs b/Il2CppInspector/Il2CppReflector.cs index 601b6d4..aeb22b1 100644 --- a/Il2CppInspector/Il2CppReflector.cs +++ b/Il2CppInspector/Il2CppReflector.cs @@ -7,15 +7,10 @@ namespace Il2CppInspector.Reflection { public List Assemblies { get; } = new List(); - // Factory instantiation via Il2CppReflector.Parse only - private Il2CppReflector() { } - - public static Il2CppReflector Parse(Il2CppInspector package) { - var r = new Il2CppReflector(); - - // TODO: Populate reflection classes - - return r; + public Il2CppReflector(Il2CppInspector package) { + // Create Assembly objects from Il2Cpp package + for (var image = 0; image < package.Metadata.Images.Length; image++) + Assemblies.Add(new Assembly(package, image)); } // Get the assembly in which a type is defined diff --git a/Il2CppInspector/Reflection/Assembly.cs b/Il2CppInspector/Reflection/Assembly.cs new file mode 100644 index 0000000..554f0a1 --- /dev/null +++ b/Il2CppInspector/Reflection/Assembly.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; + +namespace Il2CppInspector.Reflection { + public class Assembly + { + // IL2CPP-specific data + public Il2CppImageDefinition Definition { get; } + public int Index { get; } + + // TODO: CustomAttributes + + // Name of the assembly + public string FullName { get; } + + // Entry point method for the assembly + public MethodInfo EntryPoint { get; } + + // List of types defined in the assembly + public List DefinedTypes { get; } = new List(); + + // Get a type from its string name + public Type GetType(string typeName) { + throw new NotImplementedException(); + } + + // Initialize from specified assembly index in package + public Assembly(Il2CppInspector pkg, int imageIndex) { + Definition = pkg.Metadata.Images[imageIndex]; + Index = Definition.assemblyIndex; + FullName = pkg.Metadata.Strings[Definition.nameIndex]; + + if (Definition.entryPointIndex != -1) { + // TODO: Generate EntryPoint method from entryPointIndex + } + + // TODO: Generate types in DefinedTypes from typeStart to typeStart+typeCount-1 + } + } +} \ No newline at end of file diff --git a/Il2CppInspector/Reflection/ReflectionClasses.cs b/Il2CppInspector/Reflection/ReflectionClasses.cs index 0361c82..f5b30ff 100644 --- a/Il2CppInspector/Reflection/ReflectionClasses.cs +++ b/Il2CppInspector/Reflection/ReflectionClasses.cs @@ -4,25 +4,6 @@ using System.Reflection; namespace Il2CppInspector.Reflection { - public class Assembly - { - // TODO: CustomAttributes - - // Name of the assembly - public string FullName { get; set; } - - // Entry point method for the assembly - public MethodInfo EntryPoint { get; set; } - - // List of types defined in the assembly - public List DefinedTypes { get; } = new List(); - - // Get a type from its string name - public Type GetType(string typeName) { - throw new NotImplementedException(); - } - } - public abstract class MemberInfo { // Assembly that this member is defined in