Skip to content

Commit c3959fd

Browse files
committed
Added support for files larger than 2GB
Perfare#869
1 parent cb953f9 commit c3959fd

6 files changed

Lines changed: 30 additions & 290 deletions

File tree

Il2CppDumper/IO/BinaryStream.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public BinaryStream(Stream input)
2222
{
2323
stream = input;
2424
Reader = new BinaryReader(stream, Encoding.UTF8, true);
25-
Writer = new BinaryWriter(stream, Encoding.UTF8, true);
25+
if (stream.CanWrite) {
26+
writer = new BinaryWriter(stream, Encoding.UTF8, true);
27+
}
2628
readClass = GetType().GetMethod("ReadClass", Type.EmptyTypes);
2729
readClassArray = GetType().GetMethod("ReadClassArray", new[] { typeof(long) });
2830
genericMethodCache = new Dictionary<Type, MethodInfo>();

Il2CppDumper/Outputs/Il2CppDecompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Il2CppDecompiler(Il2CppExecutor il2CppExecutor)
2424

2525
public void Decompile(Config config, string outputDir)
2626
{
27-
var writer = new StreamWriter(new FileStream(outputDir + "dump.cs", FileMode.Create), new UTF8Encoding(false));
27+
var writer = new StreamWriter(new FileStream(Path.Combine(outputDir, "dump.cs"), FileMode.Create), new UTF8Encoding(false));
2828
//dump image
2929
for (var imageIndex = 0; imageIndex < metadata.imageDefs.Length; imageIndex++)
3030
{

Il2CppDumper/Outputs/StructGenerator.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,9 @@ public void WriteScript(string outputDir, bool escapeJsonValues)
445445
{
446446
jsonOptions.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;
447447
}
448-
File.WriteAllText(
449-
outputDir + "stringliteral.json",
450-
JsonSerializer.Serialize(stringLiterals, jsonOptions),
451-
new UTF8Encoding(false));
448+
File.WriteAllText(Path.Combine(outputDir, "stringliteral.json"), JsonSerializer.Serialize(stringLiterals, jsonOptions), new UTF8Encoding(false));
452449
//写入文件
453-
using (var stream = new FileStream(outputDir + "script.json",FileMode.Create))
450+
using (var stream = new FileStream(Path.Combine(outputDir, "script.json"), FileMode.Create))
454451
{
455452
JsonSerializer.Serialize(stream, json, jsonOptions);
456453
}
@@ -517,7 +514,7 @@ public void WriteScript(string outputDir, bool escapeJsonValues)
517514
sb.Append(arrayClassHeader);
518515
sb.Append(methodInfoHeader);
519516
int bufferSize = 4096;
520-
using (StreamWriter writer = new StreamWriter(outputDir + "il2cpp.h", false, Encoding.UTF8, bufferSize))
517+
using (StreamWriter writer = new StreamWriter(Path.Combine(outputDir, "il2cpp.h"), false, Encoding.UTF8, bufferSize))
521518
{
522519
int index = 0;
523520
int length = sb.Length;

Il2CppDumper/Program.cs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ internal class Program
1313
[STAThread]
1414
private static void Main(string[] args)
1515
{
16-
config = JsonSerializer.Deserialize<Config>(
17-
File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"config.json"));
16+
config = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json")));
1817
GenerateReplaceNameMap();
1918
string il2cppPath = null;
2019
string metadataPath = null;
@@ -29,8 +28,9 @@ private static void Main(string[] args)
2928
}
3029
}
3130

32-
if (args.Length > 3)
31+
if (args.Length < 3)
3332
{
33+
Console.WriteLine("ERROR: Not enough arguments.");
3434
ShowHelp();
3535
return;
3636
}
@@ -41,8 +41,12 @@ private static void Main(string[] args)
4141
{
4242
if (File.Exists(arg))
4343
{
44-
var file = File.ReadAllBytes(arg);
45-
if (BitConverter.ToUInt32(file, 0) == 0xFAB11BAF)
44+
UInt32 magicBytes = 0;
45+
using (FileStream fileStream = File.OpenRead(arg))
46+
{
47+
magicBytes = new BinaryReader(fileStream).ReadUInt32();
48+
}
49+
if (magicBytes == 0xFAB11BAF)
4650
{
4751
metadataPath = arg;
4852
}
@@ -58,41 +62,29 @@ private static void Main(string[] args)
5862
}
5963
}
6064

61-
outputDir ??= AppDomain.CurrentDomain.BaseDirectory;
62-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
65+
if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir))
66+
{
67+
Console.WriteLine("ERROR: The specified output folder does not exist.");
68+
ShowHelp();
69+
return;
70+
}
71+
outputDir = Path.GetFullPath(outputDir) + Path.DirectorySeparatorChar;
6372
{
64-
if (il2cppPath == null)
73+
if (il2cppPath == null || metadataPath == null)
6574
{
66-
var ofd = new OpenFileDialog { Filter = "Il2Cpp binary file|*.*" };
67-
if (ofd.ShowDialog())
68-
{
69-
il2cppPath = ofd.FileName;
70-
ofd.Filter = "global-metadata|global-metadata.dat";
71-
if (ofd.ShowDialog())
72-
{
73-
metadataPath = ofd.FileName;
74-
}
75-
else
76-
{
77-
return;
78-
}
79-
}
80-
else
81-
{
82-
return;
83-
}
75+
Console.WriteLine("ERROR: Missing required input files.");
76+
ShowHelp();
77+
return;
8478
}
8579
}
86-
8780
if (il2cppPath == null)
8881
{
8982
ShowHelp();
9083
return;
9184
}
92-
9385
if (metadataPath == null)
9486
{
95-
Console.WriteLine("ERROR: Metadata file not found or encrypted.");
87+
Console.WriteLine($"ERROR: Metadata file not found or encrypted.");
9688
}
9789
else
9890
{
@@ -147,8 +139,8 @@ private static void ShowHelp()
147139
private static bool Init(string il2cppPath, string metadataPath, out Metadata metadata, out Il2Cpp il2Cpp)
148140
{
149141
Console.WriteLine("Initializing metadata...");
150-
var metadataBytes = File.ReadAllBytes(metadataPath);
151-
metadata = new Metadata(new MemoryStream(metadataBytes));
142+
var metadataStream = File.OpenRead(metadataPath);
143+
metadata = new Metadata(metadataStream);
152144
Console.WriteLine($"Metadata Version: {metadata.Version}");
153145

154146
Console.WriteLine("Initializing il2cpp file...");

Il2CppDumper/Utils/FileDialogNative.cs

Lines changed: 0 additions & 205 deletions
This file was deleted.

Il2CppDumper/Utils/OpenFileDialog.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)