From c0f8e0eb178fb5fd1f0555d2fbc6dd6b4f98e339 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 12 Dec 2020 20:14:48 +0100 Subject: [PATCH] GUI: Add load options dialog with ELF image base option --- .../FileFormatReaders/LoadOptions.cs | 2 +- Il2CppInspector.GUI/App.xaml | 63 ++++++++++++++- Il2CppInspector.GUI/App.xaml.cs | 20 +++-- .../HexStringValueConverter.cs | 34 ++++++++ Il2CppInspector.GUI/LoadOptionsDialog.xaml | 76 ++++++++++++++++++ Il2CppInspector.GUI/LoadOptionsDialog.xaml.cs | 39 ++++++++++ Il2CppInspector.GUI/MainWindow.xaml | 77 +++---------------- Il2CppInspector.GUI/MainWindow.xaml.cs | 32 +++++--- 8 files changed, 256 insertions(+), 87 deletions(-) create mode 100644 Il2CppInspector.GUI/HexStringValueConverter.cs create mode 100644 Il2CppInspector.GUI/LoadOptionsDialog.xaml create mode 100644 Il2CppInspector.GUI/LoadOptionsDialog.xaml.cs diff --git a/Il2CppInspector.Common/FileFormatReaders/LoadOptions.cs b/Il2CppInspector.Common/FileFormatReaders/LoadOptions.cs index 06283b9..ee0e716 100644 --- a/Il2CppInspector.Common/FileFormatReaders/LoadOptions.cs +++ b/Il2CppInspector.Common/FileFormatReaders/LoadOptions.cs @@ -10,6 +10,6 @@ namespace Il2CppInspector public class LoadOptions { // For dumped ELF files, the virtual address to which we should rebase - ignored for other file types - public ulong? ImageBase; + public ulong? ImageBase { get; set; } } } \ No newline at end of file diff --git a/Il2CppInspector.GUI/App.xaml b/Il2CppInspector.GUI/App.xaml index 378a7a7..b3e015d 100644 --- a/Il2CppInspector.GUI/App.xaml +++ b/Il2CppInspector.GUI/App.xaml @@ -3,6 +3,67 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> - + + + + + + + + + + + + + + + + + diff --git a/Il2CppInspector.GUI/App.xaml.cs b/Il2CppInspector.GUI/App.xaml.cs index d879a4a..1feed87 100644 --- a/Il2CppInspector.GUI/App.xaml.cs +++ b/Il2CppInspector.GUI/App.xaml.cs @@ -34,6 +34,8 @@ namespace Il2CppInspectorGUI } } + public LoadOptions LoadOptions { get; private set; } = null; + public List AppModels { get; } = new List(); public Exception LastException { get; private set; } @@ -43,8 +45,14 @@ namespace Il2CppInspectorGUI private void StatusUpdate(object sender, string status) => OnStatusUpdate?.Invoke(sender, status); + public void ResetLoadOptions() { + LoadOptions = new LoadOptions { + ImageBase = 0ul + }; + } + // Attempt to load an IL2CPP application package (APK or IPA) - public async Task LoadPackageAsync(IEnumerable packageFiles, LoadOptions loadOptions) { + public async Task LoadPackageAsync(IEnumerable packageFiles) { IsExtractedFromPackage = false; try { @@ -54,7 +62,7 @@ namespace Il2CppInspectorGUI if (streams == null) throw new InvalidOperationException("The supplied package is not an APK or IPA file, or does not contain a complete IL2CPP application"); - IsExtractedFromPackage = await LoadMetadataAsync(streams.Value.Metadata) && await LoadBinaryAsync(streams.Value.Binary, loadOptions); + IsExtractedFromPackage = await LoadMetadataAsync(streams.Value.Metadata) && await LoadBinaryAsync(streams.Value.Binary); return IsExtractedFromPackage; } catch (Exception ex) { @@ -85,18 +93,18 @@ namespace Il2CppInspectorGUI }); // Attempt to load an IL2CPP binary file - public async Task LoadBinaryAsync(string binaryFile, LoadOptions loadOptions) { + public async Task LoadBinaryAsync(string binaryFile) { var stream = new MemoryStream(await File.ReadAllBytesAsync(binaryFile)); - return await LoadBinaryAsync(stream, loadOptions); + return await LoadBinaryAsync(stream); } - public Task LoadBinaryAsync(Stream binaryStream, LoadOptions loadOptions) => + public Task LoadBinaryAsync(Stream binaryStream) => Task.Run(() => { try { OnStatusUpdate?.Invoke(this, "Processing binary"); // This may throw other exceptions from the individual loaders as well - IFileFormatReader stream = FileFormatReader.Load(binaryStream, loadOptions, StatusUpdate); + IFileFormatReader stream = FileFormatReader.Load(binaryStream, LoadOptions, StatusUpdate); if (stream == null) { throw new InvalidOperationException("Could not determine the binary file format"); } diff --git a/Il2CppInspector.GUI/HexStringValueConverter.cs b/Il2CppInspector.GUI/HexStringValueConverter.cs new file mode 100644 index 0000000..e97ef58 --- /dev/null +++ b/Il2CppInspector.GUI/HexStringValueConverter.cs @@ -0,0 +1,34 @@ +// Copyright (c) 2020 Katy Coe - https://www.djkaty.com - https://github.com/djkaty +// All rights reserved + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Windows; +using System.Windows.Data; + +namespace Il2CppInspector.GUI +{ + internal class HexStringValueConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + if (value == null || targetType != typeof(string)) + return DependencyProperty.UnsetValue; + + return ((ulong) value).ToString("x16"); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + if (value == null || targetType != typeof(ulong?)) + return DependencyProperty.UnsetValue; + + try { + return System.Convert.ToUInt64((string) value, 16); + } + catch { + return DependencyProperty.UnsetValue; + } + } + } +} diff --git a/Il2CppInspector.GUI/LoadOptionsDialog.xaml b/Il2CppInspector.GUI/LoadOptionsDialog.xaml new file mode 100644 index 0000000..83378b4 --- /dev/null +++ b/Il2CppInspector.GUI/LoadOptionsDialog.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + For ELF binaries that have been dumped from memory, specify the base address of the dumpIgnored for normal ELF binaries + + + + + + + + + + + + + diff --git a/Il2CppInspector.GUI/LoadOptionsDialog.xaml.cs b/Il2CppInspector.GUI/LoadOptionsDialog.xaml.cs new file mode 100644 index 0000000..1e31969 --- /dev/null +++ b/Il2CppInspector.GUI/LoadOptionsDialog.xaml.cs @@ -0,0 +1,39 @@ +// Copyright (c) 2020 Katy Coe - https://www.djkaty.com - https://github.com/djkaty +// All rights reserved + +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; +using Il2CppInspectorGUI; + +namespace Il2CppInspector.GUI +{ + /// + /// Interaction logic for LoadOptionsDialog.xaml + /// + public partial class LoadOptionsDialog : Window + { + public LoadOptionsDialog() { + InitializeComponent(); + + var app = (App) Application.Current; + if (app.LoadOptions == null) + app.ResetLoadOptions(); + + DataContext = app.LoadOptions; + } + + private void okButton_Click(object sender, RoutedEventArgs e) { + // Closes dialog box automatically + DialogResult = true; + } + } +} diff --git a/Il2CppInspector.GUI/MainWindow.xaml b/Il2CppInspector.GUI/MainWindow.xaml index feecb5d..ede0350 100644 --- a/Il2CppInspector.GUI/MainWindow.xaml +++ b/Il2CppInspector.GUI/MainWindow.xaml @@ -6,74 +6,11 @@ xmlns:local="clr-namespace:Il2CppInspectorGUI" xmlns:gif="https://github.com/XamlAnimatedGif/XamlAnimatedGif" mc:Ignorable="d" - Title="Il2CppInspector" Height="850" Width="1080" Background="White" + Title="Il2CppInspector" Height="850" Width="1100" Background="White" WindowStartupLocation="CenterScreen" ContentRendered="MainWindow_OnContentRendered" Drop="MainWindow_OnDrop"> - - - - - - - - - - - - - - - - - - @@ -116,7 +53,7 @@ - + @@ -475,9 +412,10 @@ + - - + + + -