diff --git a/BurnOutSharp/ExecutableType/Microsoft/PE/Headers/SectionHeader.cs b/BurnOutSharp/ExecutableType/Microsoft/PE/Headers/SectionHeader.cs index 5d0f2b25..d4d9beb5 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/PE/Headers/SectionHeader.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/PE/Headers/SectionHeader.cs @@ -21,6 +21,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE.Headers /// Executable images do not use a string table and do not support section names longer than 8 characters. /// Long names in object files are truncated if they are emitted to an executable file. /// + /// TODO: Add AsString method for this public byte[] Name; /// diff --git a/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs b/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs index 8132bc40..cae5eeff 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/PE/PortableExecutable.cs @@ -24,6 +24,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.PE /// /// Source array that the executable was parsed from /// + /// TODO: Find every place this is used and try to remove usage public byte[] SourceArray { get; } = null; /// diff --git a/BurnOutSharp/ProtectionType/ProtectDisc.cs b/BurnOutSharp/ProtectionType/ProtectDisc.cs index e77637fc..a8139725 100644 --- a/BurnOutSharp/ProtectionType/ProtectDisc.cs +++ b/BurnOutSharp/ProtectionType/ProtectDisc.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using BurnOutSharp.ExecutableType.Microsoft.PE; using BurnOutSharp.Matching; @@ -21,19 +22,19 @@ namespace BurnOutSharp.ProtectionType var fourthSection = sections.Length < 4 ? null : sections[3]; if (fourthSection != null) { - int sectionAddr = (int)fourthSection.PointerToRawData; - int sectionEnd = sectionAddr + (int)fourthSection.VirtualSize; - var matchers = new List + var fourthSectionData = pex.ReadRawSection(Encoding.ASCII.GetString(fourthSection.Name).Trim('\0'), first: true); + if (fourthSectionData != null) { - // ACE-PCD - new ContentMatchSet( - new ContentMatch(new byte?[] { 0x41, 0x43, 0x45, 0x2D, 0x50, 0x43, 0x44 }, start: sectionAddr, end: sectionEnd), - GetVersion6till8, "ProtectDISC"), - }; + var matchers = new List + { + // ACE-PCD + new ContentMatchSet(new byte?[] { 0x41, 0x43, 0x45, 0x2D, 0x50, 0x43, 0x44 }, GetVersion6till8, "ProtectDISC"), + }; - string match = MatchUtil.GetFirstMatch(file, pex.SourceArray, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) - return match; + string match = MatchUtil.GetFirstMatch(file, fourthSectionData, matchers, includeDebug); + if (!string.IsNullOrWhiteSpace(match)) + return match; + } } // Get the .data section, if it exists @@ -54,47 +55,48 @@ namespace BurnOutSharp.ProtectionType var secondToLastSection = sections.Length > 1 ? sections[sections.Length - 2] : null; if (secondToLastSection != null) { - int sectionAddr = (int)secondToLastSection.PointerToRawData; - int sectionEnd = sectionAddr + (int)secondToLastSection.VirtualSize; - var matchers = new List + var secondToLastSectionData = pex.ReadRawSection(Encoding.ASCII.GetString(secondToLastSection.Name).Trim('\0'), first: true); + if (secondToLastSectionData != null) { - // VOB ProtectCD - new ContentMatchSet( - new ContentMatch(new byte?[] - { - 0x56, 0x4F, 0x42, 0x20, 0x50, 0x72, 0x6F, 0x74, - 0x65, 0x63, 0x74, 0x43, 0x44 - }, start: sectionAddr, end: sectionEnd), - GetOldVersion, "VOB ProtectCD/DVD"), - }; + var matchers = new List + { + // VOB ProtectCD + new ContentMatchSet( + new byte?[] + { + 0x56, 0x4F, 0x42, 0x20, 0x50, 0x72, 0x6F, 0x74, + 0x65, 0x63, 0x74, 0x43, 0x44 + }, + GetOldVersion, + "VOB ProtectCD/DVD"), + }; - string match = MatchUtil.GetFirstMatch(file, pex.SourceArray, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) - return match; + string match = MatchUtil.GetFirstMatch(file, secondToLastSectionData, matchers, includeDebug); + if (!string.IsNullOrWhiteSpace(match)) + return match; + } } // Get the last section (example names: ACE5, akxpxgcv, and piofinqb) var lastSection = sections.LastOrDefault(); if (lastSection != null) { - int sectionAddr = (int)lastSection.PointerToRawData; - int sectionEnd = sectionAddr + (int)lastSection.VirtualSize; - var matchers = new List + var lastSectionData = pex.ReadRawSection(Encoding.ASCII.GetString(lastSection.Name).Trim('\0'), first: true); + if (lastSectionData != null) { - // HúMETINF - new ContentMatchSet( - new ContentMatch(new byte?[] { 0x48, 0xFA, 0x4D, 0x45, 0x54, 0x49, 0x4E, 0x46 }, start: sectionAddr, end: sectionEnd), - GetVersion76till10, "ProtectDISC"), + var matchers = new List + { + // HúMETINF + new ContentMatchSet(new byte?[] { 0x48, 0xFA, 0x4D, 0x45, 0x54, 0x49, 0x4E, 0x46 }, GetVersion76till10, "ProtectDISC"), - // DCP-BOV + (char)0x00 + (char)0x00 - new ContentMatchSet( - new ContentMatch(new byte?[] { 0x44, 0x43, 0x50, 0x2D, 0x42, 0x4F, 0x56, 0x00, 0x00 }, start: sectionAddr, end: sectionEnd), - GetVersion3till6, "VOB ProtectCD/DVD"), - }; + // DCP-BOV + (char)0x00 + (char)0x00 + new ContentMatchSet(new byte?[] { 0x44, 0x43, 0x50, 0x2D, 0x42, 0x4F, 0x56, 0x00, 0x00 }, GetVersion3till6, "VOB ProtectCD/DVD"), + }; - string match = MatchUtil.GetFirstMatch(file, pex.SourceArray, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) - return match; + string match = MatchUtil.GetFirstMatch(file, lastSectionData, matchers, includeDebug); + if (!string.IsNullOrWhiteSpace(match)) + return match; + } } // Get the .vob.pcd section, if it exists diff --git a/BurnOutSharp/ProtectionType/SafeDisc.cs b/BurnOutSharp/ProtectionType/SafeDisc.cs index ff436004..24f0671a 100644 --- a/BurnOutSharp/ProtectionType/SafeDisc.cs +++ b/BurnOutSharp/ProtectionType/SafeDisc.cs @@ -59,22 +59,22 @@ namespace BurnOutSharp.ProtectionType return $"SafeCast"; // Get the .text section, if it exists - string match = CheckSectionForProtection(file, pex.SourceArray, includeDebug, pex, ".text"); + string match = CheckSectionForProtection(file, includeDebug, pex, ".text"); if (!string.IsNullOrWhiteSpace(match)) return match; // Get the .txt2 section, if it exists - match = CheckSectionForProtection(file, pex.SourceArray, includeDebug, pex, ".txt2"); + match = CheckSectionForProtection(file, includeDebug, pex, ".txt2"); if (!string.IsNullOrWhiteSpace(match)) return match; // Get the CODE section, if it exists - match = CheckSectionForProtection(file, pex.SourceArray, includeDebug, pex, "CODE"); + match = CheckSectionForProtection(file, includeDebug, pex, "CODE"); if (!string.IsNullOrWhiteSpace(match)) return match; // Get the .data section, if it exists - match = CheckSectionForProtection(file, pex.SourceArray, includeDebug, pex, ".data"); + match = CheckSectionForProtection(file, includeDebug, pex, ".data"); if (!string.IsNullOrWhiteSpace(match)) return match; @@ -82,7 +82,7 @@ namespace BurnOutSharp.ProtectionType bool stxt371Section = pex.ContainsSection("stxt371", exact: true); bool stxt774Section = pex.ContainsSection("stxt774", exact: true); if (stxt371Section || stxt774Section) - return $"SafeDisc {Get320to4xVersion(file, pex.SourceArray, null)}"; + return $"SafeDisc {Get320to4xVersion(null, null, null)}"; return null; } @@ -269,7 +269,7 @@ namespace BurnOutSharp.ProtectionType return "1-4"; } - private string CheckSectionForProtection(string file, byte[] fileContent, bool includeDebug, PortableExecutable pex, string sectionName) + private string CheckSectionForProtection(string file, bool includeDebug, PortableExecutable pex, string sectionName) { // This subtract is needed because BoG_ starts before the section var sectionRaw = pex.ReadRawSection(sectionName, first: true, offset: -64); diff --git a/BurnOutSharp/ProtectionType/SecuROM.cs b/BurnOutSharp/ProtectionType/SecuROM.cs index c9a61b24..dd86834d 100644 --- a/BurnOutSharp/ProtectionType/SecuROM.cs +++ b/BurnOutSharp/ProtectionType/SecuROM.cs @@ -53,19 +53,19 @@ namespace BurnOutSharp.ProtectionType string nthSectionName = Encoding.ASCII.GetString(nthSection.Name).Trim('\0'); if (nthSection != null && nthSectionName != ".idata" && nthSectionName != ".rsrc") { - int sectionAddr = (int)nthSection.PointerToRawData; - int sectionEnd = sectionAddr + (int)nthSection.VirtualSize; - var matchers = new List + var nthSectionData = pex.ReadRawSection(Encoding.ASCII.GetString(nthSection.Name).Trim('\0'), first: true); + if (nthSectionData != null) { - // (char)0xCA + (char)0xDD + (char)0xDD + (char)0xAC + (char)0x03 - new ContentMatchSet( - new ContentMatch(new byte?[] { 0xCA, 0xDD, 0xDD, 0xAC, 0x03 }, start: sectionAddr, end: sectionEnd), - GetV5Version, "SecuROM"), - }; + var matchers = new List + { + // (char)0xCA + (char)0xDD + (char)0xDD + (char)0xAC + (char)0x03 + new ContentMatchSet(new byte?[] { 0xCA, 0xDD, 0xDD, 0xAC, 0x03 }, GetV5Version, "SecuROM"), + }; - string match = MatchUtil.GetFirstMatch(file, pex.SourceArray, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) - return match; + string match = MatchUtil.GetFirstMatch(file, nthSectionData, matchers, includeDebug); + if (!string.IsNullOrWhiteSpace(match)) + return match; + } } } diff --git a/BurnOutSharp/ProtectionType/StarForce.cs b/BurnOutSharp/ProtectionType/StarForce.cs index 15f44a2c..9706ccec 100644 --- a/BurnOutSharp/ProtectionType/StarForce.cs +++ b/BurnOutSharp/ProtectionType/StarForce.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Text; using BurnOutSharp.ExecutableType.Microsoft.PE; using BurnOutSharp.Matching; using BurnOutSharp.Tools; @@ -37,25 +38,27 @@ namespace BurnOutSharp.ProtectionType var rsrcSection = pex.GetLastSection(".rsrc", exact: true); if (rsrcSection != null) { - int sectionAddr = (int)rsrcSection.PointerToRawData; - int sectionEnd = sectionAddr + (int)rsrcSection.VirtualSize; - var matchers = new List + var rsrcSectionData = pex.ReadRawSection(Encoding.ASCII.GetString(rsrcSection.Name).Trim('\0'), first: true); + if (rsrcSectionData != null) { - // P + (char)0x00 + r + (char)0x00 + o + (char)0x00 + t + (char)0x00 + e + (char)0x00 + c + (char)0x00 + t + (char)0x00 + e + (char)0x00 + d + (char)0x00 + + (char)0x00 + M + (char)0x00 + o + (char)0x00 + d + (char)0x00 + u + (char)0x00 + l + (char)0x00 + e + (char)0x00 - new ContentMatchSet( - new ContentMatch(new byte?[] - { - 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x74, 0x00, - 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x65, 0x00, - 0x64, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x6f, 0x00, - 0x64, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x65, 0x00 - }, start: sectionAddr, end: sectionEnd), - "StarForce 5 [Protected Module]"), - }; + var matchers = new List + { + // P + (char)0x00 + r + (char)0x00 + o + (char)0x00 + t + (char)0x00 + e + (char)0x00 + c + (char)0x00 + t + (char)0x00 + e + (char)0x00 + d + (char)0x00 + + (char)0x00 + M + (char)0x00 + o + (char)0x00 + d + (char)0x00 + u + (char)0x00 + l + (char)0x00 + e + (char)0x00 + new ContentMatchSet( + new byte?[] + { + 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x74, 0x00, + 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x65, 0x00, + 0x64, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x6f, 0x00, + 0x64, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x65, 0x00 + }, + "StarForce 5 [Protected Module]"), + }; - string match = MatchUtil.GetFirstMatch(file, pex.SourceArray, matchers, includeDebug); - if (!string.IsNullOrWhiteSpace(match)) - return match; + string match = MatchUtil.GetFirstMatch(file, rsrcSectionData, matchers, includeDebug); + if (!string.IsNullOrWhiteSpace(match)) + return match; + } } // Get the .brick section, if it exists