From c4ca27608bb67ecfeedf15c1f3717b0b908639d1 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 26 Aug 2021 21:57:56 -0700 Subject: [PATCH] Convert Advanced Installer to section based --- BurnOutSharp/PackerType/AdvancedInstaller.cs | 57 ++++++++++++++------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/BurnOutSharp/PackerType/AdvancedInstaller.cs b/BurnOutSharp/PackerType/AdvancedInstaller.cs index eaf381a7..5e68d954 100644 --- a/BurnOutSharp/PackerType/AdvancedInstaller.cs +++ b/BurnOutSharp/PackerType/AdvancedInstaller.cs @@ -1,5 +1,9 @@ using System.Collections.Generic; +using System.Linq; +using System.Text; +using BurnOutSharp.ExecutableType.Microsoft; using BurnOutSharp.Matching; +using BurnOutSharp.Tools; namespace BurnOutSharp.PackerType { @@ -7,23 +11,42 @@ namespace BurnOutSharp.PackerType public class AdvancedInstaller : IContentCheck { /// - public List GetContentMatchSets() - { - return new List - { - // Software\Caphyon\Advanced Installer - new ContentMatchSet(new byte?[] - { - 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x5C, 0x43, 0x61, 0x70, 0x68, 0x79, 0x6F, 0x6E, - 0x5C, 0x41, 0x64, 0x76, 0x61, 0x6E, 0x63, 0x65, - 0x64, 0x20, 0x49, 0x6E, 0x73, 0x74, 0x61, 0x6C, - 0x6C, 0x65, 0x72 - }, "Caphyon Advanced Installer"), - }; - } - + public List GetContentMatchSets() => null; + /// - public string CheckContents(string file, byte[] fileContent, bool includeDebug = false) => null; + public string CheckContents(string file, byte[] fileContent, bool includeDebug = false) + { + // Get the sections from the executable, if possible + PEExecutable pex = PEExecutable.Deserialize(fileContent, 0); + var sections = pex?.SectionHeaders; + if (sections == null) + return null; + + // Get the .rdata section, if it exists + var rdataSection = sections.FirstOrDefault(s => Encoding.ASCII.GetString(s.Name).StartsWith(".rdata")); + if (rdataSection != null) + { + int sectionAddr = (int)EVORE.ConvertVirtualAddress(rdataSection.VirtualAddress, sections); + int sectionEnd = sectionAddr + (int)rdataSection.VirtualSize; + var matchers = new List + { + // Software\Caphyon\Advanced Installer + new ContentMatchSet(new ContentMatch( + new byte?[] + { + 0x53, 0x6F, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, + 0x5C, 0x43, 0x61, 0x70, 0x68, 0x79, 0x6F, 0x6E, + 0x5C, 0x41, 0x64, 0x76, 0x61, 0x6E, 0x63, 0x65, + 0x64, 0x20, 0x49, 0x6E, 0x73, 0x74, 0x61, 0x6C, + 0x6C, 0x65, 0x72 + }, start: sectionAddr, end: sectionEnd), + "Caphyon Advanced Installer"), + }; + + return MatchUtil.GetFirstMatch(file, fileContent, matchers, includeDebug); + } + + return null; + } } }