From 1aef137cb21901f75693154c1878f5f5c1d9df25 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 9 Dec 2022 14:58:12 -0800 Subject: [PATCH] Convert Inno Setup to string finding --- BurnOutSharp/PackerType/InnoSetup.cs | 56 ++++++---------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/BurnOutSharp/PackerType/InnoSetup.cs b/BurnOutSharp/PackerType/InnoSetup.cs index b7d0b63f..b1902b4b 100644 --- a/BurnOutSharp/PackerType/InnoSetup.cs +++ b/BurnOutSharp/PackerType/InnoSetup.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using BurnOutSharp.Interfaces; using BurnOutSharp.Matching; using BurnOutSharp.Wrappers; @@ -42,24 +40,19 @@ namespace BurnOutSharp.PackerType if (sections == null) return null; - // Get the .data/DATA section, if it exists - var dataSectionRaw = pex.GetFirstSectionData(".data") ?? pex.GetFirstSectionData("DATA"); - if (dataSectionRaw != null) + // Get the .data section strings, if they exist + List strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA"); + if (strs != null) { - var matchers = new List + string str = strs.FirstOrDefault(s => s.StartsWith("Inno Setup Setup Data")); + if (str != null) { - // 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"), - }; - - string match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) - return match; + return str.Replace("Inno Setup Setup Data", "Inno Setup") + .Replace("(u)", "[Unicode]") + .Replace("(", string.Empty) + .Replace(")", string.Empty) + .Replace("[Unicode]", "(Unicode)"); + } } return null; @@ -83,31 +76,6 @@ namespace BurnOutSharp.PackerType return null; } - public static string GetVersion(string file, byte[] fileContent, List positions) - { - try - { - int index = positions[0]; - index += 23; - - var versionBytes = new ReadOnlySpan(fileContent, index, 16).ToArray(); - var onlyVersion = versionBytes.TakeWhile(b => b != ')').ToArray(); - - index += onlyVersion.Length + 2; - var unicodeBytes = new ReadOnlySpan(fileContent, index, 3).ToArray(); - string version = Encoding.ASCII.GetString(onlyVersion); - - if (unicodeBytes.SequenceEqual(new byte[] { 0x28, 0x75, 0x29 })) - return version + " (Unicode)"; - - return version; - } - catch - { - return "(Unknown Version)"; - } - } - private static string GetOldVersion(string file, NewExecutable nex) { // Notes: