From fc1ff07036710997c6a05ba7f769f60d997a971c Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Thu, 19 Oct 2017 10:37:36 +0200 Subject: [PATCH] Don't crash with exception if metadata file is invalid --- Il2CppInspector/Il2CppProcessor.cs | 9 ++++++++- Il2CppInspector/Metadata.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Il2CppInspector/Il2CppProcessor.cs b/Il2CppInspector/Il2CppProcessor.cs index eab48f4..fde5119 100644 --- a/Il2CppInspector/Il2CppProcessor.cs +++ b/Il2CppInspector/Il2CppProcessor.cs @@ -22,7 +22,14 @@ namespace Il2CppInspector public static Il2CppProcessor LoadFromFile(string codeFile, string metadataFile) { // 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) var memoryStream = new MemoryStream(File.ReadAllBytes(codeFile)); diff --git a/Il2CppInspector/Metadata.cs b/Il2CppInspector/Metadata.cs index 2c81591..d04b9a4 100644 --- a/Il2CppInspector/Metadata.cs +++ b/Il2CppInspector/Metadata.cs @@ -39,7 +39,7 @@ namespace Il2CppInspector } 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 uiNumTypes = pMetadataHdr.typeDefinitionsCount / MySizeOf(typeof(Il2CppTypeDefinition));