API: Allow passing of load options to binary loaders

This commit is contained in:
Katy Coe
2020-12-11 22:44:48 +01:00
parent 95db3ad19b
commit 08c1559222
9 changed files with 59 additions and 39 deletions

View File

@@ -44,7 +44,7 @@ namespace Il2CppInspectorGUI
private void StatusUpdate(object sender, string status) => OnStatusUpdate?.Invoke(sender, status);
// Attempt to load an IL2CPP application package (APK or IPA)
public async Task<bool> LoadPackageAsync(IEnumerable<string> packageFiles) {
public async Task<bool> LoadPackageAsync(IEnumerable<string> packageFiles, LoadOptions loadOptions) {
IsExtractedFromPackage = false;
try {
@@ -54,7 +54,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);
IsExtractedFromPackage = await LoadMetadataAsync(streams.Value.Metadata) && await LoadBinaryAsync(streams.Value.Binary, loadOptions);
return IsExtractedFromPackage;
}
catch (Exception ex) {
@@ -85,18 +85,18 @@ namespace Il2CppInspectorGUI
});
// Attempt to load an IL2CPP binary file
public async Task<bool> LoadBinaryAsync(string binaryFile) {
public async Task<bool> LoadBinaryAsync(string binaryFile, LoadOptions loadOptions) {
var stream = new MemoryStream(await File.ReadAllBytesAsync(binaryFile));
return await LoadBinaryAsync(stream);
return await LoadBinaryAsync(stream, loadOptions);
}
public Task<bool> LoadBinaryAsync(Stream binaryStream) =>
public Task<bool> LoadBinaryAsync(Stream binaryStream, LoadOptions loadOptions) =>
Task.Run(() => {
try {
OnStatusUpdate?.Invoke(this, "Processing binary");
// This may throw other exceptions from the individual loaders as well
IFileFormatReader stream = FileFormatReader.Load(binaryStream, StatusUpdate);
IFileFormatReader stream = FileFormatReader.Load(binaryStream, loadOptions, StatusUpdate);
if (stream == null) {
throw new InvalidOperationException("Could not determine the binary file format");
}

View File

@@ -114,19 +114,19 @@ namespace Il2CppInspectorGUI
};
if (openFileDialog.ShowDialog() == true) {
await LoadBinaryAsync(openFileDialog.FileName);
await LoadBinaryAsync(openFileDialog.FileName, null); // TODO: loadOptions
}
}
// Load the binary file
private async Task LoadBinaryAsync(string filename) {
private async Task LoadBinaryAsync(string filename, LoadOptions loadOptions) {
var app = (App) Application.Current;
areaBusyIndicator.Visibility = Visibility.Visible;
btnSelectBinaryFile.Visibility = Visibility.Hidden;
// Load the binary file
if (await app.LoadBinaryAsync(filename)) {
if (await app.LoadBinaryAsync(filename, loadOptions)) {
// Binary loaded successfully
areaBusyIndicator.Visibility = Visibility.Hidden;
@@ -151,20 +151,20 @@ namespace Il2CppInspectorGUI
};
if (openFileDialog.ShowDialog() == true) {
await LoadPackageAsync(openFileDialog.FileNames);
await LoadPackageAsync(openFileDialog.FileNames, null); // TODO: loadOptions
}
}
// Load the package file
private async Task LoadPackageAsync(string filename) => await LoadPackageAsync(new[] { filename });
private async Task LoadPackageAsync(IEnumerable<string> filenames) {
private async Task LoadPackageAsync(string filename, LoadOptions loadOptions) => await LoadPackageAsync(new[] { filename }, loadOptions);
private async Task LoadPackageAsync(IEnumerable<string> filenames, LoadOptions loadOptions) {
var app = (App) Application.Current;
areaBusyIndicator.Visibility = Visibility.Visible;
grdFirstPage.Visibility = Visibility.Hidden;
// Load the package
if (await app.LoadPackageAsync(filenames)) {
if (await app.LoadPackageAsync(filenames, loadOptions)) {
// Package loaded successfully
areaBusyIndicator.Visibility = Visibility.Hidden;
@@ -594,7 +594,7 @@ namespace Il2CppInspectorGUI
break;
case var s when s.EndsWith(".apk") || s.EndsWith(".aab") || s.EndsWith(".ipa") || s.EndsWith(".xapk") || s.EndsWith(".zip"):
await LoadPackageAsync(s);
await LoadPackageAsync(s, null); // TODO: loadOptions
break;
}
}
@@ -607,17 +607,17 @@ namespace Il2CppInspectorGUI
// Only load binary if metadata was successful
if (btnSelectBinaryFile.Visibility == Visibility.Visible)
await LoadBinaryAsync(files[binaryIndex]);
await LoadBinaryAsync(files[binaryIndex], null); // TODO: loadOptions
}
// Split APK (files.Length >= 2)
else {
await LoadPackageAsync(files);
await LoadPackageAsync(files, null); // TODO: loadOptions
}
}
// Binary (on 2nd page)
else if (btnSelectBinaryFile.Visibility == Visibility.Visible)
if (files.Length == 1)
await LoadBinaryAsync(files[0]);
await LoadBinaryAsync(files[0], null); // TODO: loadOptions
}
}