GUI: Load binary file
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Il2CppInspector;
|
||||
using Inspector = Il2CppInspector.Il2CppInspector;
|
||||
|
||||
namespace Il2CppInspectorGUI
|
||||
{
|
||||
@@ -15,7 +16,9 @@ namespace Il2CppInspectorGUI
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
public Metadata CurrentMetadata { get; private set; }
|
||||
private Metadata metadata;
|
||||
|
||||
public List<Inspector> Il2CppImages { get; } = new List<Inspector>();
|
||||
|
||||
public Exception LastException { get; private set; }
|
||||
|
||||
@@ -23,7 +26,43 @@ namespace Il2CppInspectorGUI
|
||||
public Task<bool> LoadMetadataAsync(string metadataFile) =>
|
||||
Task.Run(() => {
|
||||
try {
|
||||
CurrentMetadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile)));
|
||||
metadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile)));
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LastException = ex;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
public Task<bool> LoadBinaryAsync(string binaryFile) =>
|
||||
Task.Run(() => {
|
||||
try {
|
||||
// This may throw other exceptions from the individual loaders as well
|
||||
IFileFormatReader stream = FileFormatReader.Load(binaryFile);
|
||||
if (stream == null) {
|
||||
throw new InvalidOperationException("Could not determine the binary file format");
|
||||
}
|
||||
if (!stream.Images.Any()) {
|
||||
throw new InvalidOperationException("Could not find any binary images in the file");
|
||||
}
|
||||
|
||||
// Multi-image binaries may contain more than one Il2Cpp image
|
||||
Il2CppImages.Clear();
|
||||
foreach (var image in stream.Images) {
|
||||
// Architecture-agnostic load attempt
|
||||
try {
|
||||
// If we can't load the IL2CPP data here, it's probably packed or obfuscated; ignore it
|
||||
if (Il2CppBinary.Load(image, metadata.Version) is Il2CppBinary binary) {
|
||||
Il2CppImages.Add(new Inspector(binary, metadata));
|
||||
}
|
||||
}
|
||||
// Unsupported architecture; ignore it
|
||||
catch (NotImplementedException) { }
|
||||
}
|
||||
if (!Il2CppImages.Any()) {
|
||||
throw new InvalidOperationException("Could not auto-detect any IL2CPP binary images in the file");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
Reference in New Issue
Block a user