Don't crash with exception if metadata file is invalid

This commit is contained in:
Katy Coe
2017-10-19 10:37:36 +02:00
parent 083d1328d6
commit fc1ff07036
2 changed files with 9 additions and 2 deletions

View File

@@ -22,7 +22,14 @@ namespace Il2CppInspector
public static Il2CppProcessor LoadFromFile(string codeFile, string metadataFile) { public static Il2CppProcessor LoadFromFile(string codeFile, string metadataFile) {
// Load the metadata file // Load the metadata file
var metadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile))); Metadata metadata;
try {
metadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile)));
}
catch (Exception ex) {
Console.Error.WriteLine(ex.Message);
return null;
}
// Load the il2cpp code file (try ELF and PE) // Load the il2cpp code file (try ELF and PE)
var memoryStream = new MemoryStream(File.ReadAllBytes(codeFile)); var memoryStream = new MemoryStream(File.ReadAllBytes(codeFile));

View File

@@ -39,7 +39,7 @@ namespace Il2CppInspector
} }
if (pMetadataHdr.version != 21 && pMetadataHdr.version != 22) if (pMetadataHdr.version != 21 && pMetadataHdr.version != 22)
{ {
throw new Exception($"ERROR: Metadata file supplied is not a supported version[{pMetadataHdr.version}]."); throw new Exception($"ERROR: Metadata file supplied is not a supported version ({pMetadataHdr.version}).");
} }
var uiImageCount = pMetadataHdr.imagesCount / MySizeOf(typeof(Il2CppImageDefinition)); var uiImageCount = pMetadataHdr.imagesCount / MySizeOf(typeof(Il2CppImageDefinition));
var uiNumTypes = pMetadataHdr.typeDefinitionsCount / MySizeOf(typeof(Il2CppTypeDefinition)); var uiNumTypes = pMetadataHdr.typeDefinitionsCount / MySizeOf(typeof(Il2CppTypeDefinition));