Skip to content

Commit 25b5c22

Browse files
committed
DummyDll:添加选项控制token输出
1 parent e4cc43f commit 25b5c22

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

Il2CppDumper/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Config
1111
public bool DumpTypeDefIndex = true;
1212
public bool GenerateDummyDll = true;
1313
public bool GenerateStruct = true;
14+
public bool DummyDllAddToken = true;
1415
public bool RequireAnyKey = true;
1516
public bool ForceIl2CppVersion = false;
1617
public float ForceVersion = 24.3f;

Il2CppDumper/Outputs/DummyAssemblyExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace Il2CppDumper
99
{
1010
public static class DummyAssemblyExporter
1111
{
12-
public static void Export(Il2CppExecutor il2CppExecutor, string outputDir)
12+
public static void Export(Il2CppExecutor il2CppExecutor, string outputDir, bool addToken)
1313
{
1414
Directory.SetCurrentDirectory(outputDir);
1515
if (Directory.Exists("DummyDll"))
1616
Directory.Delete("DummyDll", true);
1717
Directory.CreateDirectory("DummyDll");
1818
Directory.SetCurrentDirectory("DummyDll");
19-
var dummy = new DummyAssemblyGenerator(il2CppExecutor);
19+
var dummy = new DummyAssemblyGenerator(il2CppExecutor, addToken);
2020
foreach (var assembly in dummy.Assemblies)
2121
{
2222
using (var stream = new MemoryStream())

Il2CppDumper/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private static void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
243243
if (config.GenerateDummyDll)
244244
{
245245
Console.WriteLine("Generate dummy dll...");
246-
DummyAssemblyExporter.Export(executor, outputDir);
246+
DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
247247
Console.WriteLine("Done!");
248248
}
249249
}

Il2CppDumper/Utils/DummyAssemblyGenerator.cs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using Mono.Cecil;
1+
using Mono.Cecil;
62
using Mono.Cecil.Cil;
73
using Mono.Collections.Generic;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
87

98
namespace Il2CppDumper
109
{
@@ -21,7 +20,7 @@ public class DummyAssemblyGenerator
2120
private TypeReference stringType;
2221
private Dictionary<string, MethodDefinition> knownAttributes = new Dictionary<string, MethodDefinition>();
2322

24-
public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
23+
public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor, bool addToken)
2524
{
2625
executor = il2CppExecutor;
2726
metadata = il2CppExecutor.metadata;
@@ -95,9 +94,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
9594
var typeDef = metadata.typeDefs[index];
9695
var typeDefinition = typeDefinitionDic[typeDef];
9796

98-
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
99-
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{typeDef.token:X}")));
100-
typeDefinition.CustomAttributes.Add(customTokenAttribute);
97+
if (addToken)
98+
{
99+
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
100+
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{typeDef.token:X}")));
101+
typeDefinition.CustomAttributes.Add(customTokenAttribute);
102+
}
101103

102104
//genericParameter
103105
if (typeDef.genericContainerIndex >= 0)
@@ -150,9 +152,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
150152
typeDefinition.Fields.Add(fieldDefinition);
151153
fieldDefinitionDic.Add(i, fieldDefinition);
152154

153-
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
154-
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{fieldDef.token:X}")));
155-
fieldDefinition.CustomAttributes.Add(customTokenAttribute);
155+
if (addToken)
156+
{
157+
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
158+
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{fieldDef.token:X}")));
159+
fieldDefinition.CustomAttributes.Add(customTokenAttribute);
160+
}
156161

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

210-
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
211-
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{methodDef.token:X}")));
212-
methodDefinition.CustomAttributes.Add(customTokenAttribute);
215+
if (addToken)
216+
{
217+
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
218+
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{methodDef.token:X}")));
219+
methodDefinition.CustomAttributes.Add(customTokenAttribute);
220+
}
213221

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

311-
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
312-
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{propertyDef.token:X}")));
313-
propertyDefinition.CustomAttributes.Add(customTokenAttribute);
319+
if (addToken)
320+
{
321+
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
322+
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{propertyDef.token:X}")));
323+
propertyDefinition.CustomAttributes.Add(customTokenAttribute);
324+
}
314325
}
315326
//event
316327
var eventEnd = typeDef.eventStart + typeDef.event_count;
@@ -330,9 +341,12 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor)
330341
typeDefinition.Events.Add(eventDefinition);
331342
eventDefinitionDic.Add(i, eventDefinition);
332343

333-
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
334-
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{eventDef.token:X}")));
335-
eventDefinition.CustomAttributes.Add(customTokenAttribute);
344+
if (addToken)
345+
{
346+
var customTokenAttribute = new CustomAttribute(typeDefinition.Module.ImportReference(tokenAttribute));
347+
customTokenAttribute.Fields.Add(new CustomAttributeNamedArgument("Token", new CustomAttributeArgument(stringType, $"0x{eventDef.token:X}")));
348+
eventDefinition.CustomAttributes.Add(customTokenAttribute);
349+
}
336350
}
337351
}
338352
}

Il2CppDumper/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"DumpTypeDefIndex": true,
99
"GenerateDummyDll": true,
1010
"GenerateStruct": true,
11+
"DummyDllAddToken": true,
1112
"RequireAnyKey": true,
1213
"ForceIl2CppVersion": false,
1314
"ForceVersion": 16

0 commit comments

Comments
 (0)