From 7195ed3587c1abb58aadab9cfeef0e7f20965ef0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 11 Sep 2021 16:49:54 -0700 Subject: [PATCH] Combine CD-Cops and DVD-Cops --- .../Microsoft/PortableExecutable.cs | 2 +- .../{CDCops.cs => CDDVDCops.cs} | 19 +++++++- BurnOutSharp/ProtectionType/DVDCops.cs | 47 ------------------- 3 files changed, 18 insertions(+), 50 deletions(-) rename BurnOutSharp/ProtectionType/{CDCops.cs => CDDVDCops.cs} (85%) delete mode 100644 BurnOutSharp/ProtectionType/DVDCops.cs diff --git a/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs b/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs index e9fef5a4..58efb340 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs @@ -93,7 +93,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft // // Here is a list of non-standard sections whose contents are read by various protections: // - CODE *1 protection WTM CD Protect - // - .grand 2 protections? CD-Cops / DVD-Cops(?) + // - .grand *1 protection CD-Cops / DVD-Cops // - .init *1 protection SolidShield // - .NOS0 *1 protection UPX (NOS Variant) // - .NOS1 *1 protection UPX (NOS Variant) diff --git a/BurnOutSharp/ProtectionType/CDCops.cs b/BurnOutSharp/ProtectionType/CDDVDCops.cs similarity index 85% rename from BurnOutSharp/ProtectionType/CDCops.cs rename to BurnOutSharp/ProtectionType/CDDVDCops.cs index ffdcf6e1..602482d7 100644 --- a/BurnOutSharp/ProtectionType/CDCops.cs +++ b/BurnOutSharp/ProtectionType/CDDVDCops.cs @@ -8,8 +8,7 @@ using BurnOutSharp.Matching; namespace BurnOutSharp.ProtectionType { - // TODO: Can this be combined with DVD-Cops? - public class CDCops : IContentCheck, IPathCheck + public class CDDVDCops : IContentCheck, IPathCheck { /// private List GetContentMatchSets() @@ -23,6 +22,13 @@ namespace BurnOutSharp.ProtectionType 0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 }, GetVersion, "CD-Cops"), + + // DVD-Cops, ver. + new ContentMatchSet(new byte?[] + { + 0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, + 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 + }, GetVersion, "DVD-Cops"), }; } @@ -50,6 +56,15 @@ namespace BurnOutSharp.ProtectionType 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 }, start: sectionAddr, end: sectionEnd), GetVersion, "CD-Cops"), + + // DVD-Cops, ver. + new ContentMatchSet( + new ContentMatch(new byte?[] + { + 0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, + 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 + }, start: sectionAddr, end: sectionEnd), + GetVersion, "DVD-Cops"), }; string match = MatchUtil.GetFirstMatch(file, fileContent, matchers, includeDebug); diff --git a/BurnOutSharp/ProtectionType/DVDCops.cs b/BurnOutSharp/ProtectionType/DVDCops.cs deleted file mode 100644 index 4a6740ec..00000000 --- a/BurnOutSharp/ProtectionType/DVDCops.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using BurnOutSharp.ExecutableType.Microsoft; -using BurnOutSharp.Matching; - -namespace BurnOutSharp.ProtectionType -{ - // TODO: Can this be combined with CD-Cops? - public class DVDCops : IContentCheck - { - /// - private List GetContentMatchSets() - { - // TODO: Obtain a sample to find where this string is in a typical executable - return new List - { - // DVD-Cops, ver. - new ContentMatchSet(new byte?[] - { - 0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, - 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 - }, GetVersion, "DVD-Cops"), - }; - } - - /// TODO: Does this look for the `.grand` section like CD-Cops? - /// - public string CheckContents(string file, byte[] fileContent, bool includeDebug, PortableExecutable pex, NewExecutable nex) - { - var contentMatchSets = GetContentMatchSets(); - if (contentMatchSets != null && contentMatchSets.Any()) - return MatchUtil.GetFirstMatch(file, fileContent, contentMatchSets, includeDebug); - - return null; - } - - public static string GetVersion(string file, byte[] fileContent, List positions) - { - char[] version = new ArraySegment(fileContent, positions[0] + 15, 4).Select(b => (char)b).ToArray(); - if (version[0] == 0x00) - return string.Empty; - - return new string(version); - } - } -}