From b76d09aa203be40c349f5eecec4173faaf315129 Mon Sep 17 00:00:00 2001 From: SilasLaspada Date: Sat, 5 Jun 2021 12:46:04 -0600 Subject: [PATCH] Improve Inno Setup detection (#37) * Improve Inno Setup detection * Split "GetVersion" * Remove unneeded check * Make version detection more robust * Add Unicode version detection * Address review comments --- BurnOutSharp/PackerType/InnoSetup.cs | 67 ++++++++++++++++------------ 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/BurnOutSharp/PackerType/InnoSetup.cs b/BurnOutSharp/PackerType/InnoSetup.cs index 493b06ff..0c5b4abd 100644 --- a/BurnOutSharp/PackerType/InnoSetup.cs +++ b/BurnOutSharp/PackerType/InnoSetup.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using BurnOutSharp.Matching; namespace BurnOutSharp.PackerType @@ -13,10 +14,18 @@ namespace BurnOutSharp.PackerType /// private static readonly List contentMatchers = new List { + // Inno Setup Setup Data ( + new ContentMatchSet(new byte?[] + { + 0x49, 0x6E, 0x6E, 0x6F, 0x20, 0x53, 0x65, 0x74, + 0x75, 0x70, 0x20, 0x53, 0x65, 0x74, 0x75, 0x70, + 0x20, 0x44, 0x61, 0x74, 0x61, 0x20, 0x28 + }, GetVersion, "Inno Setup"), + // Inno new ContentMatchSet( new ContentMatch(new byte?[] { 0x49, 0x6E, 0x6E, 0x6F }, start: 0x30, end: 0x31), - GetVersion, + GetOldVersion, "Inno Setup"), }; @@ -49,39 +58,41 @@ namespace BurnOutSharp.PackerType return null; } + public static string GetOldVersion(string file, byte[] fileContent, List positions) + { + var matchers = new List + { + // "rDlPtS02" + (char)0x87 + "eVx" + new ContentMatchSet(new byte?[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x32, 0x87, 0x65, 0x56, 0x78 }, "1.2.16 or earlier"), + }; + + string match = MatchUtil.GetFirstMatch(file, fileContent, matchers, false); + return match ?? "Unknown 1.X"; + } + public static string GetVersion(string file, byte[] fileContent, List positions) { - byte[] signature = new ArraySegment(fileContent, 0x30, 12).ToArray(); + try + { + int index = positions[0]; + index += 23; - // "rDlPtS02" + (char)0x87 + "eVx" - if (signature.SequenceEqual( new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x32, 0x87, 0x65, 0x56, 0x78 })) - return "1.2.10"; + var versionBytes = new ReadOnlySpan(fileContent, index, 16).ToArray(); + var onlyVersion = versionBytes.TakeWhile(b => b != ')').ToArray(); - // "rDlPtS04" + (char)0x87 + "eVx" - else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x34, 0x87, 0x65, 0x56, 0x78 })) - return "4.0.0"; + index += onlyVersion.Length + 2; + var unicodeBytes = new ReadOnlySpan(fileContent, index, 3).ToArray(); + string version = Encoding.ASCII.GetString(onlyVersion); - // "rDlPtS05" + (char)0x87 + "eVx" - else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x35, 0x87, 0x65, 0x56, 0x78 })) - return "4.0.3"; + if (unicodeBytes.SequenceEqual(new byte[] { 0x28, 0x75, 0x29 })) + return (version + " (Unicode)"); - // "rDlPtS06" + (char)0x87 + "eVx" - else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x36, 0x87, 0x65, 0x56, 0x78 })) - return "4.0.10"; - - // "rDlPtS07" + (char)0x87 + "eVx" - else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x37, 0x87, 0x65, 0x56, 0x78 })) - return "4.1.6"; - - // "rDlPtS" + (char)0xcd + (char)0xe6 + (char)0xd7 + "{" + (char)0x0b + "*" - else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0xCD, 0xE6, 0xD7, 0x7B, 0x0b, 0x2A })) - return "5.1.5"; - - // "nS5W7dT" + (char)0x83 + (char)0xaa + (char)0x1b + (char)0x0f + "j" - else if (signature.SequenceEqual(new byte[] { 0x6E, 0x53, 0x35, 0x57, 0x37, 0x64, 0x54, 0x83, 0xAA, 0x1B, 0x0F, 0x6A })) - return "5.1.5"; - - return string.Empty; + return version; + } + catch + { + return "(Unknown Version)"; + } } } }