diff --git a/Il2CppInspector.GUI/App.xaml.cs b/Il2CppInspector.GUI/App.xaml.cs index 1a3e7d2..768a577 100644 --- a/Il2CppInspector.GUI/App.xaml.cs +++ b/Il2CppInspector.GUI/App.xaml.cs @@ -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 /// public partial class App : Application { - public Metadata CurrentMetadata { get; private set; } + private Metadata metadata; + + public List Il2CppImages { get; } = new List(); public Exception LastException { get; private set; } @@ -23,7 +26,43 @@ namespace Il2CppInspectorGUI public Task 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 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) { diff --git a/Il2CppInspector.GUI/MainWindow.xaml b/Il2CppInspector.GUI/MainWindow.xaml index 5341763..46c4cfc 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml +++ b/Il2CppInspector.GUI/MainWindow.xaml @@ -71,7 +71,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -92,6 +92,6 @@ - + diff --git a/Il2CppInspector.GUI/MainWindow.xaml.cs b/Il2CppInspector.GUI/MainWindow.xaml.cs index e78a7fa..1817b68 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml.cs +++ b/Il2CppInspector.GUI/MainWindow.xaml.cs @@ -45,7 +45,6 @@ namespace Il2CppInspectorGUI // Load the metadata file if (await app.LoadMetadataAsync(openFileDialog.FileName)) { // Metadata loaded successfully - lblMetadataVersion.DataContext = app.CurrentMetadata; btnSelectBinaryFile.Visibility = Visibility.Visible; btnBack.Visibility = Visibility.Visible; } @@ -75,11 +74,22 @@ namespace Il2CppInspectorGUI if (openFileDialog.ShowDialog() == true) { // Load the binary file + if (await app.LoadBinaryAsync(openFileDialog.FileName)) { + // Binary loaded successfully + // TODO: Set DataContext + // TODO: Format, Endianness, Bits, Arch, GlobalOffset, symbol table size, relocations size, CodeReg, MetaReg + rectModalLightBoxBackground.Visibility = Visibility.Hidden; + } + else { + MessageBox.Show(this, app.LastException.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + btnSelectBinaryFile.Visibility = Visibility.Visible; + } } else { btnSelectBinaryFile.Visibility = Visibility.Visible; - btnBack.IsEnabled = true; } + + btnBack.IsEnabled = true; } /// @@ -90,7 +100,8 @@ namespace Il2CppInspectorGUI private void BtnBack_OnClick(object sender, RoutedEventArgs e) { var app = (App) Application.Current; - lblMetadataVersion.DataContext = null; + rectModalLightBoxBackground.Visibility = Visibility.Visible; + gridImageDetails.DataContext = null; btnSelectBinaryFile.Visibility = Visibility.Hidden; btnBack.Visibility = Visibility.Hidden; btnSelectMetadataFile.Visibility = Visibility.Visible;