From dbdf9e2123f28ae933fb6798a21ba28d9f14fc5d Mon Sep 17 00:00:00 2001 From: LukeFZ <17146677+LukeFZ@users.noreply.github.com> Date: Sun, 18 Jan 2026 02:46:13 +0100 Subject: [PATCH] set version, name, public key and hash alg from assembly name definition for dummy dlls --- .../IL2CPP/Il2CppInspector.cs | 1 + Il2CppInspector.Common/IL2CPP/Metadata.cs | 17 +++++++++ .../Outputs/AssemblyShims.cs | 37 ++++++++++++++++--- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs index 1fc120a..82b558a 100644 --- a/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs +++ b/Il2CppInspector.Common/IL2CPP/Il2CppInspector.cs @@ -62,6 +62,7 @@ namespace Il2CppInspector public ImmutableArray AttributeTypeIndices => Metadata.AttributeTypeIndices; public ImmutableArray VTableMethodIndices => Metadata.VTableMethodIndices; public ImmutableArray FieldRefs => Metadata.FieldRefs; + public Dictionary AssemblyPublicKeys => Metadata.AssemblyPublicKeys; public Dictionary FieldDefaultValue { get; } = new Dictionary(); public Dictionary ParameterDefaultValue { get; } = new Dictionary(); public List FieldOffsets { get; } diff --git a/Il2CppInspector.Common/IL2CPP/Metadata.cs b/Il2CppInspector.Common/IL2CPP/Metadata.cs index 96acbfe..58868bf 100644 --- a/Il2CppInspector.Common/IL2CPP/Metadata.cs +++ b/Il2CppInspector.Common/IL2CPP/Metadata.cs @@ -54,6 +54,7 @@ namespace Il2CppInspector : Header.AttributeDataOffset; public Dictionary Strings { get; private set; } = []; + public Dictionary AssemblyPublicKeys { get; private set; } = []; // Set if something in the metadata has been modified / decrypted public bool IsModified { get; private set; } = false; @@ -341,6 +342,22 @@ namespace Il2CppInspector } } + // These are stored in a special way, so we read them in advance. + if (Version == MetadataVersions.V242 || Version >= MetadataVersions.V244) + { + var stringOffset = Version >= MetadataVersions.V380 + ? Header.Strings.Offset + : Header.StringOffset; + + foreach (var assembly in Assemblies) + { + Position = stringOffset + assembly.Aname.PublicKeyIndex; + var length = ReadCompressedUInt32(); + + AssemblyPublicKeys[assembly.Aname.PublicKeyIndex] = ReadBytes((int)length).ToArray(); + } + } + // Post-processing hook IsModified |= PluginHooks.PostProcessMetadata(this).IsStreamModified; return; diff --git a/Il2CppInspector.Common/Outputs/AssemblyShims.cs b/Il2CppInspector.Common/Outputs/AssemblyShims.cs index f0af6b4..b99bee5 100644 --- a/Il2CppInspector.Common/Outputs/AssemblyShims.cs +++ b/Il2CppInspector.Common/Outputs/AssemblyShims.cs @@ -5,15 +5,14 @@ All rights reserved. */ -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; using dnlib.DotNet; using dnlib.DotNet.Emit; using Il2CppInspector.Next; +using Il2CppInspector.Next.Metadata; using Il2CppInspector.Reflection; +using AssemblyNameFlags = System.Reflection.AssemblyNameFlags; + namespace Il2CppInspector.Outputs { @@ -187,6 +186,34 @@ namespace Il2CppInspector.Outputs return module; } + private AssemblyDefUser CreateAssembly(Il2CppAssemblyNameDefinition nameDefinition) + { + var name = model.Package.Strings[nameDefinition.NameIndex]; + var version = new Version(nameDefinition.Major, nameDefinition.Minor, nameDefinition.Build, + nameDefinition.Revision); + + return new AssemblyDefUser(name, version) + { + PublicKey = new PublicKey(model.Package.AssemblyPublicKeys[nameDefinition.PublicKeyIndex]), + Culture = model.Package.Strings[nameDefinition.CultureIndex], + HashAlgorithm = (AssemblyHashAlgorithm)nameDefinition.HashAlg, + HasPublicKey = nameDefinition.Flags.HasFlag(AssemblyNameFlags.PublicKey) + }; + } + + private ModuleDefUser CreateAssembly(Assembly assembly) + { + var module = new ModuleDefUser(assembly.ShortName) + { + Kind = ModuleKind.Dll + }; + + var asm = CreateAssembly(assembly.AssemblyDefinition.Aname); + asm.Modules.Add(module); + + return module; + } + // Create a shallow type definition that only populates the type itself and its nested types. // Used for custom attributes. private TypeDefUser CreateTypeShallow(ModuleDef module, TypeInfo type) @@ -648,7 +675,7 @@ namespace Il2CppInspector.Outputs foreach (var asm in model.Assemblies) { // Create assembly and add primary module to list - var module = CreateAssembly(asm.ShortName); + var module = CreateAssembly(asm); module.Context = ctx; modules.Add(asm, module); }