IL2CPP: Add silent mode to loader
This commit is contained in:
@@ -301,7 +301,7 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// Finds and extracts the metadata and IL2CPP binary from an APK or IPA file into MemoryStreams
|
// Finds and extracts the metadata and IL2CPP binary from an APK or IPA file into MemoryStreams
|
||||||
// Returns null if package not recognized or does not contain an IL2CPP application
|
// Returns null if package not recognized or does not contain an IL2CPP application
|
||||||
public static (MemoryStream Metadata, MemoryStream Binary)? GetStreamsFromPackage(string packageFile) {
|
public static (MemoryStream Metadata, MemoryStream Binary)? GetStreamsFromPackage(string packageFile, bool silent = false) {
|
||||||
try {
|
try {
|
||||||
// Check if it's a zip file first because ZipFile.OpenRead is extremely slow if it isn't
|
// Check if it's a zip file first because ZipFile.OpenRead is extremely slow if it isn't
|
||||||
using (BinaryReader zipTest = new BinaryReader(File.Open(packageFile, FileMode.Open))) {
|
using (BinaryReader zipTest = new BinaryReader(File.Open(packageFile, FileMode.Open))) {
|
||||||
@@ -328,12 +328,13 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// This package doesn't contain an IL2CPP application
|
// This package doesn't contain an IL2CPP application
|
||||||
if (metadataFile == null || !binaryFiles.Any()) {
|
if (metadataFile == null || !binaryFiles.Any()) {
|
||||||
Console.WriteLine($"Package {packageFile} does not contain an IL2CPP application");
|
Console.Error.WriteLine($"Package {packageFile} does not contain an IL2CPP application");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the metadata file to memory
|
// Extract the metadata file to memory
|
||||||
Console.WriteLine($"Extracting metadata from {packageFile}{Path.DirectorySeparatorChar}{metadataFile.FullName}");
|
if (!silent)
|
||||||
|
Console.WriteLine($"Extracting metadata from {packageFile}{Path.DirectorySeparatorChar}{metadataFile.FullName}");
|
||||||
|
|
||||||
var metadataMemoryStream = new MemoryStream();
|
var metadataMemoryStream = new MemoryStream();
|
||||||
metadataStream = metadataFile.Open();
|
metadataStream = metadataFile.Open();
|
||||||
@@ -345,7 +346,8 @@ namespace Il2CppInspector
|
|||||||
|
|
||||||
// IPAs will only have one binary (which may or may not be a UB covering multiple architectures)
|
// IPAs will only have one binary (which may or may not be a UB covering multiple architectures)
|
||||||
if (ipaBinaryFolder != null) {
|
if (ipaBinaryFolder != null) {
|
||||||
Console.WriteLine($"Extracting binary from {packageFile}{Path.DirectorySeparatorChar}{binaryFiles.First().FullName}");
|
if (!silent)
|
||||||
|
Console.WriteLine($"Extracting binary from {packageFile}{Path.DirectorySeparatorChar}{binaryFiles.First().FullName}");
|
||||||
|
|
||||||
binaryStream = binaryFiles.First().Open();
|
binaryStream = binaryFiles.First().Open();
|
||||||
binaryStream.CopyTo(binaryMemoryStream);
|
binaryStream.CopyTo(binaryMemoryStream);
|
||||||
@@ -368,21 +370,27 @@ namespace Il2CppInspector
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load from an APK or IPA file
|
// Load from an APK or IPA file
|
||||||
public static List<Il2CppInspector> LoadFromPackage(string packageFile) {
|
public static List<Il2CppInspector> LoadFromPackage(string packageFile, bool silent = false) {
|
||||||
var streams = GetStreamsFromPackage(packageFile);
|
var streams = GetStreamsFromPackage(packageFile, silent);
|
||||||
if (!streams.HasValue)
|
if (!streams.HasValue)
|
||||||
return null;
|
return null;
|
||||||
return LoadFromStream(streams.Value.Binary, streams.Value.Metadata);
|
return LoadFromStream(streams.Value.Binary, streams.Value.Metadata, silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from a binary file and metadata file
|
// Load from a binary file and metadata file
|
||||||
public static List<Il2CppInspector> LoadFromFile(string binaryFile, string metadataFile)
|
public static List<Il2CppInspector> LoadFromFile(string binaryFile, string metadataFile, bool silent = false)
|
||||||
=> LoadFromStream(new FileStream(binaryFile, FileMode.Open, FileAccess.Read),
|
=> LoadFromStream(new FileStream(binaryFile, FileMode.Open, FileAccess.Read),
|
||||||
new MemoryStream(File.ReadAllBytes(metadataFile)));
|
new MemoryStream(File.ReadAllBytes(metadataFile)),
|
||||||
|
silent);
|
||||||
|
|
||||||
// Load from a binary stream and metadata stream
|
// Load from a binary stream and metadata stream
|
||||||
// Must be a seekable stream otherwise we catch a System.IO.NotSupportedException
|
// Must be a seekable stream otherwise we catch a System.IO.NotSupportedException
|
||||||
public static List<Il2CppInspector> LoadFromStream(Stream binaryStream, Stream metadataStream) {
|
public static List<Il2CppInspector> LoadFromStream(Stream binaryStream, Stream metadataStream, bool silent = false) {
|
||||||
|
|
||||||
|
// Silent operation if requested
|
||||||
|
var stdout = Console.Out;
|
||||||
|
if (silent)
|
||||||
|
Console.SetOut(new StreamWriter(Stream.Null));
|
||||||
|
|
||||||
// Load the metadata file
|
// Load the metadata file
|
||||||
Metadata metadata;
|
Metadata metadata;
|
||||||
@@ -391,6 +399,7 @@ namespace Il2CppInspector
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Console.Error.WriteLine(ex.Message);
|
Console.Error.WriteLine(ex.Message);
|
||||||
|
Console.SetOut(stdout);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +415,7 @@ namespace Il2CppInspector
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Console.Error.WriteLine(ex.Message);
|
Console.Error.WriteLine(ex.Message);
|
||||||
|
Console.SetOut(stdout);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,6 +445,8 @@ namespace Il2CppInspector
|
|||||||
Console.Error.WriteLine(ex.Message);
|
Console.Error.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.SetOut(stdout);
|
||||||
return processors;
|
return processors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user