Skip to content

Commit

Permalink
DummyDll:添加选项控制token输出
Browse files Browse the repository at this point in the history
  • Loading branch information
Perfare committed Feb 13, 2021
1 parent e4cc43f commit 25b5c22
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions Il2CppDumper/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Config
public bool DumpTypeDefIndex = true;
public bool GenerateDummyDll = true;
public bool GenerateStruct = true;
public bool DummyDllAddToken = true;
public bool RequireAnyKey = true;
public bool ForceIl2CppVersion = false;
public float ForceVersion = 24.3f;
Expand Down
4 changes: 2 additions & 2 deletions Il2CppDumper/Outputs/DummyAssemblyExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Il2CppDumper
{
public static class DummyAssemblyExporter
{
public static void Export(Il2CppExecutor il2CppExecutor, string outputDir)
public static void Export(Il2CppExecutor il2CppExecutor, string outputDir, bool addToken)
{
Directory.SetCurrentDirectory(outputDir);
if (Directory.Exists("DummyDll"))
Directory.Delete("DummyDll", true);
Directory.CreateDirectory("DummyDll");
Directory.SetCurrentDirectory("DummyDll");
var dummy = new DummyAssemblyGenerator(il2CppExecutor);
var dummy = new DummyAssemblyGenerator(il2CppExecutor, addToken);
foreach (var assembly in dummy.Assemblies)
{
using (var stream = new MemoryStream())
Expand Down
2 changes: 1 addition & 1 deletion Il2CppDumper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private static void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
if (config.GenerateDummyDll)
{
Console.WriteLine("Generate dummy dll...");
DummyAssemblyExporter.Export(executor, outputDir);
DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
Console.WriteLine("Done!");
}
}
Expand Down
56 changes: 35 additions & 21 deletions Il2CppDumper/Utils/DummyAssemblyGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Il2CppDumper
{
Expand All @@ -21,7 +20,7 @@ public class DummyAssemblyGenerator
private TypeReference stringType;
private Dictionary<string, MethodDefinition> knownAttributes = new Dictionary<string, MethodDefinition>();

public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor, bool addToken)
{
executor = il2CppExecutor;
metadata = il2CppExecutor.metadata;
Expand Down Expand Up @@ -95,9 +94,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
var typeDef = metadata.typeDefs[index];
var typeDefinition = typeDefinitionDic[typeDef];

var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{typeDef.token:X}")));
typeDefinition.CustomAttributes.Add(customTokenAttribute);
if (addToken)
{
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{typeDef.token:X}")));
typeDefinition.CustomAttributes.Add(customTokenAttribute);
}

//genericParameter
if (typeDef.genericContainerIndex >= 0)
Expand Down Expand Up @@ -150,9 +152,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
typeDefinition.Fields.Add(fieldDefinition);
fieldDefinitionDic.Add(i, fieldDefinition);

var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{fieldDef.token:X}")));
fieldDefinition.CustomAttributes.Add(customTokenAttribute);
if (addToken)
{
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{fieldDef.token:X}")));
fieldDefinition.CustomAttributes.Add(customTokenAttribute);
}

//fieldDefault
if (metadata.GetFieldDefaultValueFromIndex(i, out var fieldDefault) && fieldDefault.dataIndex != -1)
Expand Down Expand Up @@ -207,9 +212,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
var returnType = GetTypeReferenceWithByRef(methodDefinition, methodReturnType);
methodDefinition.ReturnType = returnType;

var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{methodDef.token:X}")));
methodDefinition.CustomAttributes.Add(customTokenAttribute);
if (addToken)
{
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{methodDef.token:X}")));
methodDefinition.CustomAttributes.Add(customTokenAttribute);
}

if (methodDefinition.HasBody && typeDefinition.BaseType?.FullName != "System.MulticastDelegate")
{
Expand Down Expand Up @@ -308,9 +316,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
typeDefinition.Properties.Add(propertyDefinition);
propertyDefinitionDic.Add(i, propertyDefinition);

var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{propertyDef.token:X}")));
propertyDefinition.CustomAttributes.Add(customTokenAttribute);
if (addToken)
{
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{propertyDef.token:X}")));
propertyDefinition.CustomAttributes.Add(customTokenAttribute);
}
}
//event
var eventEnd = typeDef.eventStart + typeDef.event_count;
Expand All @@ -330,9 +341,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
typeDefinition.Events.Add(eventDefinition);
eventDefinitionDic.Add(i, eventDefinition);

var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{eventDef.token:X}")));
eventDefinition.CustomAttributes.Add(customTokenAttribute);
if (addToken)
{
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{eventDef.token:X}")));
eventDefinition.CustomAttributes.Add(customTokenAttribute);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Il2CppDumper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"DumpTypeDefIndex": true,
"GenerateDummyDll": true,
"GenerateStruct": true,
"DummyDllAddToken": true,
"RequireAnyKey": true,
"ForceIl2CppVersion": false,
"ForceVersion": 16
Expand Down

0 comments on commit 25b5c22

Please sign in to comment.