Tidy up error handling slightly

This commit is contained in:
Katy Coe
2020-06-16 23:08:15 +02:00
parent d16db6f1f5
commit 0f2fff6e70
2 changed files with 13 additions and 7 deletions

View File

@@ -308,9 +308,15 @@ namespace Il2CppInspector
Console.WriteLine("Detected metadata version " + metadata.Version);
// Load the il2cpp code file (try all available file formats)
IFileFormatReader stream = FileFormatReader.Load(codeFile);
if (stream == null) {
Console.Error.WriteLine("Unsupported executable file format");
IFileFormatReader stream;
try {
stream = FileFormatReader.Load(codeFile);
if (stream == null)
throw new InvalidOperationException("Unsupported executable file format");
}
catch (Exception ex) {
Console.Error.WriteLine(ex.Message);
return null;
}

View File

@@ -52,7 +52,7 @@ namespace Il2CppInspector
{
// Read magic bytes
if (ReadUInt32() != 0xFAB11BAF) {
throw new InvalidOperationException("ERROR: Metadata file supplied is not valid metadata file.");
throw new InvalidOperationException("The supplied metadata file is not valid.");
}
// Set object versioning for Bin2Object from metadata version
@@ -62,7 +62,7 @@ namespace Il2CppInspector
Header = ReadObject<Il2CppGlobalMetadataHeader>(0);
if (Version < 16 || Version > 24)
{
throw new InvalidOperationException($"ERROR: Metadata file supplied is not a supported version ({Header.version}).");
throw new InvalidOperationException($"The supplied metadata file is not of a supported version ({Header.version}).");
}
// Sanity checking
@@ -84,7 +84,7 @@ namespace Il2CppInspector
}
if (realHeaderLength != Sizeof(typeof(Il2CppGlobalMetadataHeader))) {
throw new InvalidOperationException("ERROR: Could not verify the integrity of the metadata file or accurately identify the metadata sub-version");
throw new InvalidOperationException("Could not verify the integrity of the metadata file or accurately identify the metadata sub-version");
}
// Load all the relevant metadata using offsets provided in the header
@@ -103,7 +103,7 @@ namespace Il2CppInspector
Images = ReadArray<Il2CppImageDefinition>(Header.imagesOffset, Header.imagesCount / Sizeof(typeof(Il2CppImageDefinition)));
if (Images.Any(x => x.token != 1))
throw new InvalidOperationException("ERROR: Could not verify the integrity of the metadata file image list");
throw new InvalidOperationException("Could not verify the integrity of the metadata file image list");
}
Types = ReadArray<Il2CppTypeDefinition>(Header.typeDefinitionsOffset, Header.typeDefinitionsCount / Sizeof(typeof(Il2CppTypeDefinition)));