set version, name, public key and hash alg from assembly name definition for dummy dlls

This commit is contained in:
LukeFZ
2026-01-18 02:46:13 +01:00
parent 0a66441bf0
commit dbdf9e2123
3 changed files with 50 additions and 5 deletions

View File

@@ -62,6 +62,7 @@ namespace Il2CppInspector
public ImmutableArray<int> AttributeTypeIndices => Metadata.AttributeTypeIndices;
public ImmutableArray<uint> VTableMethodIndices => Metadata.VTableMethodIndices;
public ImmutableArray<Il2CppFieldRef> FieldRefs => Metadata.FieldRefs;
public Dictionary<int, byte[]> AssemblyPublicKeys => Metadata.AssemblyPublicKeys;
public Dictionary<int, (ulong, object)> FieldDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
public Dictionary<int, (ulong, object)> ParameterDefaultValue { get; } = new Dictionary<int, (ulong, object)>();
public List<long> FieldOffsets { get; }

View File

@@ -54,6 +54,7 @@ namespace Il2CppInspector
: Header.AttributeDataOffset;
public Dictionary<int, string> Strings { get; private set; } = [];
public Dictionary<int, byte[]> 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;

View File

@@ -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);
}