给dll添加版本号

This commit is contained in:
Perfare 2021-12-10 18:39:13 +08:00
parent a9e2c98c24
commit 5146a888cc
3 changed files with 50 additions and 3 deletions

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Il2CppDumper
@ -10,6 +11,7 @@ namespace Il2CppDumper
{
public Il2CppGlobalMetadataHeader header;
public Il2CppImageDefinition[] imageDefs;
public Il2CppAssemblyDefinition[] assemblyDefs;
public Il2CppTypeDefinition[] typeDefs;
public Il2CppMethodDefinition[] methodDefs;
public Il2CppParameterDefinition[] parameterDefs;
@ -73,6 +75,7 @@ namespace Il2CppDumper
{
Version = 24.4;
}
assemblyDefs = ReadMetadataClassArray<Il2CppAssemblyDefinition>(header.assembliesOffset, header.assembliesCount);
typeDefs = ReadMetadataClassArray<Il2CppTypeDefinition>(header.typeDefinitionsOffset, header.typeDefinitionsCount);
methodDefs = ReadMetadataClassArray<Il2CppMethodDefinition>(header.methodsOffset, header.methodsCount);
parameterDefs = ReadMetadataClassArray<Il2CppParameterDefinition>(header.parametersOffset, header.parametersCount);
@ -238,6 +241,11 @@ namespace Il2CppDumper
var e = fieldType.GetField("value__").FieldType;
size += GetPrimitiveTypeSize(e.Name);
}
else if (fieldType.IsArray)
{
var arrayLengthAttribute = i.GetCustomAttribute<ArrayLengthAttribute>();
size += arrayLengthAttribute.Length;
}
else
{
size += SizeOf(fieldType);

View file

@ -52,7 +52,7 @@ namespace Il2CppDumper
public int rgctxEntriesCount;
public uint imagesOffset; // Il2CppImageDefinition
public int imagesCount;
public int assembliesOffset; // Il2CppAssemblyDefinition
public uint assembliesOffset; // Il2CppAssemblyDefinition
public int assembliesCount;
[Version(Min = 19, Max = 24.5)]
public uint metadataUsageListsOffset; // Il2CppMetadataUsageList
@ -100,6 +100,38 @@ namespace Il2CppDumper
public int exportedTypeDefinitionsCount;
}
public class Il2CppAssemblyDefinition
{
public int imageIndex;
[Version(Min = 24.1)]
public uint token;
[Version(Max = 24)]
public int customAttributeIndex;
[Version(Min = 20)]
public int referencedAssemblyStart;
[Version(Min = 20)]
public int referencedAssemblyCount;
public Il2CppAssemblyNameDefinition aname;
}
public class Il2CppAssemblyNameDefinition
{
public uint nameIndex;
public uint cultureIndex;
[Version(Max = 24.3)]
public int hashValueIndex;
public uint publicKeyIndex;
public uint hash_alg;
public int hash_len;
public uint flags;
public int major;
public int minor;
public int build;
public int revision;
[ArrayLength(Length = 8)]
public byte[] public_key_token;
}
public class Il2CppImageDefinition
{
public uint nameIndex;

View file

@ -54,8 +54,15 @@ namespace Il2CppDumper
foreach (var imageDef in metadata.imageDefs)
{
var imageName = metadata.GetStringFromIndex(imageDef.nameIndex);
var assemblyName = new AssemblyNameDefinition(imageName.Replace(".dll", ""), new Version("3.7.1.6"));
var assemblyDefinition = AssemblyDefinition.CreateAssembly(assemblyName, imageName, moduleParameters);
var aname = metadata.assemblyDefs[imageDef.assemblyIndex].aname;
var assemblyName = metadata.GetStringFromIndex(aname.nameIndex);
var assemblyNameDef = new AssemblyNameDefinition(assemblyName, new Version(aname.major, aname.minor, aname.build, aname.revision));
/*assemblyNameDef.Culture = metadata.GetStringFromIndex(aname.cultureIndex);
assemblyNameDef.PublicKey = Encoding.UTF8.GetBytes(metadata.GetStringFromIndex(aname.publicKeyIndex));
assemblyNameDef.HashAlgorithm = (AssemblyHashAlgorithm)aname.hash_alg;
assemblyNameDef.Attributes = (AssemblyAttributes)aname.flags;
assemblyNameDef.PublicKeyToken = aname.public_key_token;*/
var assemblyDefinition = AssemblyDefinition.CreateAssembly(assemblyNameDef, imageName, moduleParameters);
resolver.Register(assemblyDefinition);
Assemblies.Add(assemblyDefinition);
var moduleDefinition = assemblyDefinition.MainModule;