From e48c1813f322bffac47da30f683b5e7509ab10df Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Thu, 28 Nov 2019 04:44:27 +0100 Subject: [PATCH] Model and Output: Retrieve fully qualified assembly names --- Il2CppDumper/Il2CppCSharpDumper.cs | 4 ++-- Il2CppInspector/Il2CppModel.cs | 4 ++-- Il2CppInspector/MetadataClasses.cs | 8 ++++---- Il2CppInspector/Reflection/Assembly.cs | 22 +++++++++++++++++++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Il2CppDumper/Il2CppCSharpDumper.cs b/Il2CppDumper/Il2CppCSharpDumper.cs index c49e9d3..6af3f89 100644 --- a/Il2CppDumper/Il2CppCSharpDumper.cs +++ b/Il2CppDumper/Il2CppCSharpDumper.cs @@ -51,7 +51,7 @@ namespace Il2CppInspector public void WriteFilesByAssembly(string outPath, Func orderBy) { foreach (var asm in model.Assemblies) { // Sort namespaces into alphabetical order, then sort types within the namespaces by the specified sort function - writeFile($"{outPath}\\{asm.FullName}.cs", asm.DefinedTypes.OrderBy(t => t.Namespace).ThenBy(orderBy)); + writeFile($"{outPath}\\{asm.ShortName}.cs", asm.DefinedTypes.OrderBy(t => t.Namespace).ThenBy(orderBy)); } } @@ -179,7 +179,7 @@ namespace Il2CppInspector var text = new StringBuilder(); foreach (var asm in assemblies) { - text.Append($"// Image {asm.Index}: {asm.FullName} - {asm.ImageDefinition.typeStart}-{asm.ImageDefinition.typeStart + asm.ImageDefinition.typeCount - 1}\n"); + text.Append($"// Image {asm.Index}: {asm.ShortName} - Assembly: {asm.FullName} - Types {asm.ImageDefinition.typeStart}-{asm.ImageDefinition.typeStart + asm.ImageDefinition.typeCount - 1}\n"); // Assembly-level attributes text.Append(asm.CustomAttributes.Where(a => a.AttributeType.FullName != ExtAttribute) diff --git a/Il2CppInspector/Il2CppModel.cs b/Il2CppInspector/Il2CppModel.cs index 8d887e1..f285efd 100644 --- a/Il2CppInspector/Il2CppModel.cs +++ b/Il2CppInspector/Il2CppModel.cs @@ -48,8 +48,8 @@ namespace Il2CppInspector.Reflection Assemblies.Add(new Assembly(this, image)); } - // Get an assembly by its name - public Assembly GetAssembly(string name) => Assemblies.FirstOrDefault(a => a.FullName == name); + // Get an assembly by its image name + public Assembly GetAssembly(string name) => Assemblies.FirstOrDefault(a => a.ShortName == name); private TypeInfo getNewTypeUsage(Il2CppType usage, MemberTypes memberType) { switch (usage.type) { diff --git a/Il2CppInspector/MetadataClasses.cs b/Il2CppInspector/MetadataClasses.cs index 3b1af5a..8a82f78 100644 --- a/Il2CppInspector/MetadataClasses.cs +++ b/Il2CppInspector/MetadataClasses.cs @@ -203,10 +203,10 @@ namespace Il2CppInspector // They moved the position of publicKeyToken in v16 from the middle to the bottom of the struct public byte[] publicKeyToken => publicKeyToken_post16; - public uint nameIndex; - public uint cultureIndex; - public uint hashValueIndex; - public uint publicKeyIndex; + public int nameIndex; + public int cultureIndex; + public int hashValueIndex; + public int publicKeyIndex; [Version(Max = 15), ArrayLength(FixedSize = 8)] public byte[] publicKeyToken_pre16; public uint hash_alg; diff --git a/Il2CppInspector/Reflection/Assembly.cs b/Il2CppInspector/Reflection/Assembly.cs index 5b1c431..2afb698 100644 --- a/Il2CppInspector/Reflection/Assembly.cs +++ b/Il2CppInspector/Reflection/Assembly.cs @@ -21,9 +21,12 @@ namespace Il2CppInspector.Reflection { // Custom attributes for this assembly public IEnumerable CustomAttributes => CustomAttributeData.GetCustomAttributes(this); - // Name of the assembly + // Fully qualified name of the assembly public string FullName { get; } + // Display name of the assembly + public string ShortName { get; } + // Entry point method for the assembly public MethodInfo EntryPoint => throw new NotImplementedException(); @@ -43,14 +46,27 @@ namespace Il2CppInspector.Reflection { throw new InvalidOperationException("Assembly/image index mismatch"); Index = ImageDefinition.assemblyIndex; - FullName = Model.Package.Strings[ImageDefinition.nameIndex]; + ShortName = Model.Package.Strings[ImageDefinition.nameIndex]; + + // Get full assembly name + var nameDef = AssemblyDefinition.aname; + var name = Model.Package.Strings[nameDef.nameIndex]; + var culture = Model.Package.Strings[nameDef.cultureIndex]; + if (string.IsNullOrEmpty(culture)) + culture = "neutral"; + var pkt = BitConverter.ToString(nameDef.publicKeyToken).Replace("-", ""); + if (pkt == "0000000000000000") + pkt = "null"; + var version = string.Format($"{nameDef.major}.{nameDef.minor}.{nameDef.build}.{nameDef.revision}"); + + FullName = string.Format($"{name}, Version={version}, Culture={culture}, PublicKeyToken={pkt.ToLower()}"); if (ImageDefinition.entryPointIndex != -1) { // TODO: Generate EntryPoint method from entryPointIndex } // Find corresponding module (we'll need this for method pointers) - ModuleDefinition = Model.Package.Modules?[FullName]; + ModuleDefinition = Model.Package.Modules?[ShortName]; // Generate types in DefinedTypes from typeStart to typeStart+typeCount-1 for (var t = ImageDefinition.typeStart; t < ImageDefinition.typeStart + ImageDefinition.typeCount; t++) {