Files
BinaryObjectScanner/BurnOutSharp/PackerType/InnoSetup.cs

103 lines
3.6 KiB
C#
Raw Normal View History

2022-12-09 14:58:12 -08:00
using System.Collections.Concurrent;
2021-02-26 09:32:41 -08:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
2022-05-01 17:41:50 -07:00
using BurnOutSharp.Interfaces;
2021-03-21 15:24:23 -07:00
using BurnOutSharp.Matching;
using BurnOutSharp.Wrappers;
2021-02-26 09:34:07 -08:00
namespace BurnOutSharp.PackerType
{
2022-05-01 21:02:59 -07:00
// TODO: Add extraction - https://github.com/dscharrer/InnoExtract
2022-07-13 12:50:36 -07:00
// https://raw.githubusercontent.com/wolfram77web/app-peid/master/userdb.txt
2022-05-01 17:17:15 -07:00
public class InnoSetup : INewExecutableCheck, IPortableExecutableCheck, IScannable
{
2021-08-26 23:07:04 -07:00
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
{
// Check we have a valid executable
if (nex == null)
2022-03-14 11:00:17 -07:00
return null;
// Check for "Inno" in the reserved words
if (nex.Stub_Reserved2[4] == 0x6E49 && nex.Stub_Reserved2[5] == 0x6F6E)
{
2022-03-15 11:11:22 -07:00
string version = GetOldVersion(file, nex);
2022-03-14 11:00:17 -07:00
if (!string.IsNullOrWhiteSpace(version))
return $"Inno Setup {version}";
2021-09-11 22:40:01 -07:00
2022-03-14 11:00:17 -07:00
return "Inno Setup (Unknown Version)";
}
2021-09-11 22:40:01 -07:00
2022-03-14 11:00:17 -07:00
return null;
}
2021-09-11 22:40:01 -07:00
2022-03-14 11:00:17 -07:00
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
2022-03-14 11:00:17 -07:00
{
2022-03-14 11:20:11 -07:00
// Get the sections from the executable, if possible
2022-03-14 11:00:17 -07:00
var sections = pex?.SectionTable;
if (sections == null)
return null;
2022-12-05 10:47:17 -08:00
2022-12-09 14:58:12 -08:00
// Get the .data section strings, if they exist
List<string> strs = pex.GetFirstSectionStrings(".data") ?? pex.GetFirstSectionStrings("DATA");
if (strs != null)
2022-03-14 11:00:17 -07:00
{
2022-12-09 14:58:12 -08:00
string str = strs.FirstOrDefault(s => s.StartsWith("Inno Setup Setup Data"));
if (str != null)
2021-09-11 22:40:01 -07:00
{
2022-12-09 14:58:12 -08:00
return str.Replace("Inno Setup Setup Data", "Inno Setup")
.Replace("(u)", "[Unicode]")
.Replace("(", string.Empty)
.Replace(")", string.Empty)
.Replace("[Unicode]", "(Unicode)");
}
2021-08-26 23:07:04 -07:00
}
2021-08-26 23:07:04 -07:00
return null;
}
2021-02-26 09:32:41 -08:00
/// <inheritdoc/>
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
2021-02-26 09:32:41 -08:00
{
if (!File.Exists(file))
return null;
using (var fs = File.OpenRead(file))
{
return Scan(scanner, fs, file);
}
}
/// <inheritdoc/>
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
2021-02-26 09:32:41 -08:00
{
return null;
}
2022-03-15 11:11:22 -07:00
private static string GetOldVersion(string file, NewExecutable nex)
{
2022-12-05 20:44:34 -08:00
// Notes:
// Look into `SETUPLDR` in the resident-name table
// Look into `SETUPLDR.EXE` in the nonresident-name table
2022-03-15 11:18:53 -07:00
// TODO: Don't read entire file
2022-03-15 11:11:22 -07:00
// TODO: Only 64 bytes at the end of the file is needed
var data = nex.ReadArbitraryRange();
if (data != null)
{
2022-03-15 11:11:22 -07:00
var matchers = new List<ContentMatchSet>
{
// "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"),
};
2022-03-15 11:11:22 -07:00
return MatchUtil.GetFirstMatch(file, data, matchers, false) ?? "Unknown 1.X";
}
return "Unknown 1.X";
}
}
}