2023-03-09 16:02:51 -05:00
|
|
|
|
using System.Collections.Generic;
|
2021-02-26 09:32:41 -08:00
|
|
|
|
using System.IO;
|
2020-09-10 21:10:32 -07:00
|
|
|
|
using System.Linq;
|
2023-03-09 11:52:28 -05:00
|
|
|
|
using BinaryObjectScanner.Interfaces;
|
2023-03-07 16:59:14 -05:00
|
|
|
|
using BinaryObjectScanner.Matching;
|
|
|
|
|
|
using BinaryObjectScanner.Wrappers;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2023-03-09 23:52:58 -05:00
|
|
|
|
namespace BinaryObjectScanner.Packer
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
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
|
2023-03-09 16:02:51 -05:00
|
|
|
|
public class InnoSetup : IExtractable, INewExecutableCheck, IPortableExecutableCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
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)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2022-12-03 22:17:48 -08:00
|
|
|
|
// 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
|
2022-12-03 22:17:48 -08:00
|
|
|
|
if (nex.Stub_Reserved2[4] == 0x6E49 && nex.Stub_Reserved2[5] == 0x6F6E)
|
2021-07-17 23:40:16 -07:00
|
|
|
|
{
|
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-20 11:52:50 -08:00
|
|
|
|
// Get the .data/DATA section strings, if they exist
|
2022-12-09 14:58:12 -08:00
|
|
|
|
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-07-17 23:40:16 -07:00
|
|
|
|
|
2021-08-26 23:07:04 -07:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2023-03-09 15:33:21 -05:00
|
|
|
|
/// <inheritdoc/>
|
2023-03-09 17:16:39 -05:00
|
|
|
|
public string Extract(string file, bool includeDebug)
|
2023-03-09 15:33:21 -05:00
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
|
|
|
{
|
2023-03-09 17:16:39 -05:00
|
|
|
|
return Extract(fs, file, includeDebug);
|
2023-03-09 15:33:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2023-03-09 17:16:39 -05:00
|
|
|
|
public string Extract(Stream stream, string file, bool includeDebug)
|
2023-03-09 15:33:21 -05:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 11:11:22 -07:00
|
|
|
|
private static string GetOldVersion(string file, NewExecutable nex)
|
2021-09-11 16:47:25 -07:00
|
|
|
|
{
|
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)
|
2021-09-11 16:47:25 -07:00
|
|
|
|
{
|
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"),
|
|
|
|
|
|
};
|
2021-09-11 16:47:25 -07:00
|
|
|
|
|
2022-03-15 11:11:22 -07:00
|
|
|
|
return MatchUtil.GetFirstMatch(file, data, matchers, false) ?? "Unknown 1.X";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "Unknown 1.X";
|
2021-09-11 16:47:25 -07:00
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|