Convert Inno Setup to string finding

This commit is contained in:
Matt Nadareski
2022-12-09 14:58:12 -08:00
parent 86707b28c0
commit 1aef137cb2

View File

@@ -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<string> strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA");
if (strs != null)
{
var matchers = new List<ContentMatchSet>
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<int> positions)
{
try
{
int index = positions[0];
index += 23;
var versionBytes = new ReadOnlySpan<byte>(fileContent, index, 16).ToArray();
var onlyVersion = versionBytes.TakeWhile(b => b != ')').ToArray();
index += onlyVersion.Length + 2;
var unicodeBytes = new ReadOnlySpan<byte>(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: