Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to control whether json values are escaped #816

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Il2CppDumper/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class Config
public double ForceVersion { get; set; } = 24.3;
public bool ForceDump { get; set; } = false;
public bool NoRedirectedPointer { get; set; } = false;
public bool EscapeJsonValues { get; set; } = false;
}
}
6 changes: 5 additions & 1 deletion Il2CppDumper/Outputs/StructGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public StructGenerator(Il2CppExecutor il2CppExecutor)
il2Cpp = il2CppExecutor.il2Cpp;
}

public void WriteScript(string outputDir)
public void WriteScript(string outputDir, bool escapeJsonValues)
{
var json = new ScriptJson();
// 生成唯一名称
Expand Down Expand Up @@ -373,6 +373,10 @@ public void WriteScript(string outputDir)
address = $"0x{x.Address:X}"
}).ToArray();
var jsonOptions = new JsonSerializerOptions() { WriteIndented = true, IncludeFields = true };
if (!escapeJsonValues)
{
jsonOptions.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
}
File.WriteAllText(outputDir + "stringliteral.json", JsonSerializer.Serialize(stringLiterals, jsonOptions), new UTF8Encoding(false));
//写入文件
File.WriteAllText(outputDir + "script.json", JsonSerializer.Serialize(json, jsonOptions));
Expand Down
2 changes: 1 addition & 1 deletion Il2CppDumper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private static void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
{
Console.WriteLine("Generate struct...");
var scriptGenerator = new StructGenerator(executor);
scriptGenerator.WriteScript(outputDir);
scriptGenerator.WriteScript(outputDir, config.EscapeJsonValues);
Console.WriteLine("Done!");
}
if (config.GenerateDummyDll)
Expand Down
3 changes: 2 additions & 1 deletion Il2CppDumper/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"ForceIl2CppVersion": false,
"ForceVersion": 16,
"ForceDump": false,
"NoRedirectedPointer": false
"NoRedirectedPointer": false,
"EscapeJsonValues": true
}