diff --git a/BurnOutSharp/Matching/MatchUtil.cs b/BurnOutSharp/Matching/MatchUtil.cs index 303cf538..da724fdc 100644 --- a/BurnOutSharp/Matching/MatchUtil.cs +++ b/BurnOutSharp/Matching/MatchUtil.cs @@ -89,10 +89,9 @@ namespace BurnOutSharp.Matching } // Otherwise, invoke the version method - // TODO: Pass all positions to the version finding method else { - string version = matcher.GetContentVersion(file, fileContent, positions[0]) ?? "Unknown Version"; + string version = matcher.GetContentVersion(file, fileContent, positions) ?? "Unknown Version"; matchedProtections.Add($"{matcher.ProtectionName ?? "Unknown Protection"} {version}" + (includePosition ? $" (Index {positionsString})" : string.Empty)); } diff --git a/BurnOutSharp/Matching/Matcher.cs b/BurnOutSharp/Matching/Matcher.cs index e062b5dd..de4c40c8 100644 --- a/BurnOutSharp/Matching/Matcher.cs +++ b/BurnOutSharp/Matching/Matcher.cs @@ -17,8 +17,7 @@ namespace BurnOutSharp.Matching /// /// Function to get a content version for this Matcher /// - /// TODO: Can this be made more generic? - public Func GetContentVersion { get; set; } + public Func, string> GetContentVersion { get; set; } /// /// Set of all path matches @@ -28,7 +27,6 @@ namespace BurnOutSharp.Matching /// /// Function to get a path version for this Matcher /// - /// TODO: Can this be made more generic? public Func, string> GetPathVersion { get; set; } /// @@ -44,10 +42,10 @@ namespace BurnOutSharp.Matching public Matcher(List needles, string protectionName) : this(needles, null, protectionName) { } - public Matcher(byte?[] needle, Func getVersion, string protectionName) + public Matcher(byte?[] needle, Func, string> getVersion, string protectionName) : this(new List { needle }, getVersion, protectionName) { } - public Matcher(List needles, Func getVersion, string protectionName) + public Matcher(List needles, Func, string> getVersion, string protectionName) : this(needles.Select(n => new ContentMatch(n)).ToList(), getVersion, protectionName) { } public Matcher(ContentMatch needle, string protectionName) @@ -56,10 +54,10 @@ namespace BurnOutSharp.Matching public Matcher(List needles, string protectionName) : this(needles, null, protectionName) { } - public Matcher(ContentMatch needle, Func getVersion, string protectionName) + public Matcher(ContentMatch needle, Func, string> getVersion, string protectionName) : this(new List() { needle }, getVersion, protectionName) { } - public Matcher(List needles, Func getVersion, string protectionName) + public Matcher(List needles, Func, string> getVersion, string protectionName) { ContentMatches = needles; GetContentVersion = getVersion; diff --git a/BurnOutSharp/PackerType/InnoSetup.cs b/BurnOutSharp/PackerType/InnoSetup.cs index f57ba1f3..17ba365c 100644 --- a/BurnOutSharp/PackerType/InnoSetup.cs +++ b/BurnOutSharp/PackerType/InnoSetup.cs @@ -46,7 +46,7 @@ namespace BurnOutSharp.PackerType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { byte[] signature = new ArraySegment(fileContent, 0x30, 12).ToArray(); diff --git a/BurnOutSharp/PackerType/NSIS.cs b/BurnOutSharp/PackerType/NSIS.cs index 00e997fd..7ae11a7e 100644 --- a/BurnOutSharp/PackerType/NSIS.cs +++ b/BurnOutSharp/PackerType/NSIS.cs @@ -32,10 +32,11 @@ namespace BurnOutSharp.PackerType return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - public static string GetVersion(string file, byte[] fileContent, int index) + public static string GetVersion(string file, byte[] fileContent, List positions) { try { + int index = positions[0]; index += 24; if (fileContent[index] != 'v') return "(Unknown Version)"; diff --git a/BurnOutSharp/PackerType/PECompact.cs b/BurnOutSharp/PackerType/PECompact.cs index 7d21e37a..799db138 100644 --- a/BurnOutSharp/PackerType/PECompact.cs +++ b/BurnOutSharp/PackerType/PECompact.cs @@ -30,9 +30,9 @@ namespace BurnOutSharp.PackerType return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { - return $"v{BitConverter.ToInt16(fileContent, position + 4)}"; + return $"v{BitConverter.ToInt16(fileContent, positions[0] + 4)}"; } } } diff --git a/BurnOutSharp/PackerType/SetupFactory.cs b/BurnOutSharp/PackerType/SetupFactory.cs index c663d127..1ae6bd7a 100644 --- a/BurnOutSharp/PackerType/SetupFactory.cs +++ b/BurnOutSharp/PackerType/SetupFactory.cs @@ -67,7 +67,7 @@ namespace BurnOutSharp.PackerType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { // Check the manifest version first string version = Utilities.GetManifestVersion(fileContent); diff --git a/BurnOutSharp/PackerType/UPX.cs b/BurnOutSharp/PackerType/UPX.cs index 6d86abde..40bc2542 100644 --- a/BurnOutSharp/PackerType/UPX.cs +++ b/BurnOutSharp/PackerType/UPX.cs @@ -45,10 +45,11 @@ namespace BurnOutSharp.PackerType return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - public static string GetVersion(string file, byte[] fileContent, int index) + public static string GetVersion(string file, byte[] fileContent, List positions) { try { + int index = positions[0]; index -= 5; string versionString = Encoding.ASCII.GetString(fileContent, index, 4); if (!char.IsNumber(versionString[0])) diff --git a/BurnOutSharp/PackerType/WinZipSFX.cs b/BurnOutSharp/PackerType/WinZipSFX.cs index 01e66b02..a7afe43d 100644 --- a/BurnOutSharp/PackerType/WinZipSFX.cs +++ b/BurnOutSharp/PackerType/WinZipSFX.cs @@ -92,7 +92,7 @@ namespace BurnOutSharp.PackerType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { // Check the manifest version first string version = Utilities.GetManifestVersion(fileContent); diff --git a/BurnOutSharp/ProtectionType/CDCops.cs b/BurnOutSharp/ProtectionType/CDCops.cs index 356f7b3e..4ea83bc1 100644 --- a/BurnOutSharp/ProtectionType/CDCops.cs +++ b/BurnOutSharp/ProtectionType/CDCops.cs @@ -57,9 +57,9 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { - char[] version = new ArraySegment(fileContent, position + 15, 4).Select(b => (char)b).ToArray(); + char[] version = new ArraySegment(fileContent, positions[0] + 15, 4).Select(b => (char)b).ToArray(); if (version[0] == 0x00) return ""; diff --git a/BurnOutSharp/ProtectionType/DVDCops.cs b/BurnOutSharp/ProtectionType/DVDCops.cs index 7118cbe8..8ea7bb03 100644 --- a/BurnOutSharp/ProtectionType/DVDCops.cs +++ b/BurnOutSharp/ProtectionType/DVDCops.cs @@ -23,9 +23,9 @@ namespace BurnOutSharp.ProtectionType return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { - char[] version = new ArraySegment(fileContent, position + 15, 4).Select(b => (char)b).ToArray(); + char[] version = new ArraySegment(fileContent, positions[0] + 15, 4).Select(b => (char)b).ToArray(); if (version[0] == 0x00) return ""; diff --git a/BurnOutSharp/ProtectionType/JoWooDXProt.cs b/BurnOutSharp/ProtectionType/JoWooDXProt.cs index 3f928713..7bf535b4 100644 --- a/BurnOutSharp/ProtectionType/JoWooDXProt.cs +++ b/BurnOutSharp/ProtectionType/JoWooDXProt.cs @@ -5,35 +5,41 @@ using BurnOutSharp.Matching; namespace BurnOutSharp.ProtectionType { - // TODO: Figure out how to use GetContentMatches here public class JoWooDXProt : IContentCheck { /// public string CheckContents(string file, byte[] fileContent, bool includePosition = false) { - // ".ext " - byte?[] check = new byte?[] { 0x2E, 0x65, 0x78, 0x74, 0x20, 0x20, 0x20, 0x20 }; - if (fileContent.FirstPosition(check, out int position)) - { - // "kernel32.dll" + (char)0x00 + (char)0x00 + (char)0x00 + "VirtualProtect" - byte?[] check2 = new byte?[] { 0x6B, 0x65, 0x72, 0x6E, 0x65, 0x6C, 0x33, 0x32, 0x2E, 0x64, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74 }; - if (fileContent.FirstPosition(check2, out int position2)) - return $"JoWooD X-Prot {GetVersion(fileContent, --position2)}" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); - else - return $"JoWooD X-Prot v1" + (includePosition ? $" (Index {position})" : string.Empty); - } - var matchers = new List { // @HC09 new Matcher(new byte?[] { 0x40, 0x48, 0x43, 0x30, 0x39, 0x20, 0x20, 0x20, 0x20 }, "JoWooD X-Prot v2"), + + new Matcher(new List + { + // .ext + new byte?[] { 0x2E, 0x65, 0x78, 0x74, 0x20, 0x20, 0x20, 0x20 }, + + // kernel32.dll + (char)0x00 + (char)0x00 + (char)0x00 + VirtualProtect + new byte?[] + { + 0x6B, 0x65, 0x72, 0x6E, 0x65, 0x6C, 0x33, 0x32, + 0x2E, 0x64, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x56, + 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C, 0x50, 0x72, + 0x6F, 0x74, 0x65, 0x63, 0x74 + }, + }, GetVersion, "JoWooD X-Prot"), + + // .ext + new Matcher(new byte?[] { 0x2E, 0x65, 0x78, 0x74, 0x20, 0x20, 0x20, 0x20 }, "JoWooD X-Prot v1"), }; return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - private static string GetVersion(byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { + int position = positions[1]--; // TODO: Verify this subtract char[] version = new ArraySegment(fileContent, position + 67, 8).Select(b => (char)b).ToArray(); return $"{version[0]}.{version[2]}.{version[4]}.{version[6]}{version[7]}"; } diff --git a/BurnOutSharp/ProtectionType/ProtectDisc.cs b/BurnOutSharp/ProtectionType/ProtectDisc.cs index 354deb37..4d22b502 100644 --- a/BurnOutSharp/ProtectionType/ProtectDisc.cs +++ b/BurnOutSharp/ProtectionType/ProtectDisc.cs @@ -25,7 +25,7 @@ namespace BurnOutSharp.ProtectionType return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - public static string GetVersion6till8(string file, byte[] fileContent, int position) + public static string GetVersion6till8(string file, byte[] fileContent, List positions) { string version = SearchProtectDiscVersion(file, fileContent); if (version.Length > 0) @@ -34,10 +34,10 @@ namespace BurnOutSharp.ProtectionType return $"{astrVersionArray[0]}.{astrVersionArray[1]}.{astrVersionArray[2]} (Build {astrVersionArray[3]})"; } - return $"{GetVersionBuild6till8(fileContent, position)}"; + return $"{GetVersionBuild6till8(fileContent, positions[0])}"; } - public static string GetVersion76till10(string file, byte[] fileContent, int position) + public static string GetVersion76till10(string file, byte[] fileContent, List positions) { string version = SearchProtectDiscVersion(file, fileContent); if (version.Length > 0) @@ -45,7 +45,7 @@ namespace BurnOutSharp.ProtectionType string[] astrVersionArray = version.Split('.'); if (astrVersionArray[0] == "9") { - if (GetVersionBuild76till10(fileContent, position, out int ibuild).Length > 0) + if (GetVersionBuild76till10(fileContent, positions[0], out int ibuild).Length > 0) return $"{astrVersionArray[0]}.{astrVersionArray[1]}{astrVersionArray[2]}.{astrVersionArray[3]} (Build {ibuild})"; } else diff --git a/BurnOutSharp/ProtectionType/SafeDisc.cs b/BurnOutSharp/ProtectionType/SafeDisc.cs index 4abb37cd..d007eafb 100644 --- a/BurnOutSharp/ProtectionType/SafeDisc.cs +++ b/BurnOutSharp/ProtectionType/SafeDisc.cs @@ -131,9 +131,18 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string Get320to4xVersion(string file, byte[] fileContent, List positions) { - int index = position + 20; // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc + string version = SearchSafeDiscVersion(file, fileContent); + if (version.Length > 0) + return version; + + return "3.20-4.xx (version removed)"; + } + + public static string GetVersion(string file, byte[] fileContent, List positions) + { + int index = positions[0] + 20; // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc int version = BitConverter.ToInt32(fileContent, index); index += 4; int subVersion = BitConverter.ToInt32(fileContent, index); @@ -143,7 +152,7 @@ namespace BurnOutSharp.ProtectionType if (version != 0) return $"{version}.{subVersion:00}.{subsubVersion:000}"; - index = position + 18 + 14; // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc + index = positions[0] + 18 + 14; // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc version = BitConverter.ToInt32(fileContent, index); index += 4; subVersion = BitConverter.ToInt32(fileContent, index); @@ -156,15 +165,6 @@ namespace BurnOutSharp.ProtectionType return $"{version}.{subVersion:00}.{subsubVersion:000}"; } - public static string Get320to4xVersion(string file, byte[] fileContent, int position) - { - string version = SearchSafeDiscVersion(file, fileContent); - if (version.Length > 0) - return version; - - return "3.20-4.xx (version removed)"; - } - private static string GetDPlayerXVersion(string file) { if (file == null || !File.Exists(file)) diff --git a/BurnOutSharp/ProtectionType/SecuROM.cs b/BurnOutSharp/ProtectionType/SecuROM.cs index 9b290ded..cfe72c42 100644 --- a/BurnOutSharp/ProtectionType/SecuROM.cs +++ b/BurnOutSharp/ProtectionType/SecuROM.cs @@ -92,9 +92,9 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetV4Version(string file, byte[] fileContent, int position) + public static string GetV4Version(string file, byte[] fileContent, List positions) { - int index = position + 8; // Begin reading after "AddD" + int index = positions[0] + 8; // Begin reading after "AddD" char version = (char)fileContent[index]; index += 2; @@ -112,9 +112,9 @@ namespace BurnOutSharp.ProtectionType return $"{version}.{subVersion}.{subSubVersion}.{subSubSubVersion}"; } - public static string GetV5Version(string file, byte[] fileContent, int position) + public static string GetV5Version(string file, byte[] fileContent, List positions) { - int index = position + 8; // Begin reading after "ÊÝݬ" + int index = positions[0] + 8; // Begin reading after "ÊÝݬ" byte version = (byte)(fileContent[index] & 0x0F); index += 2; @@ -145,7 +145,7 @@ namespace BurnOutSharp.ProtectionType return $"{version}.{subVersion[0]}{subVersion[1]}.{subSubVersion[0]}{subSubVersion[1]}.{subSubSubVersion[0]}{subSubSubVersion[1]}{subSubSubVersion[2]}{subSubSubVersion[3]}"; } - public static string GetV7Version(string file, byte[] fileContent, int position) + public static string GetV7Version(string file, byte[] fileContent, List positions) { int index = 236; byte[] bytes = new ReadOnlySpan(fileContent, index, 4).ToArray(); diff --git a/BurnOutSharp/ProtectionType/SolidShield.cs b/BurnOutSharp/ProtectionType/SolidShield.cs index 2578a9ef..e88ed3f0 100644 --- a/BurnOutSharp/ProtectionType/SolidShield.cs +++ b/BurnOutSharp/ProtectionType/SolidShield.cs @@ -7,7 +7,6 @@ using BurnOutSharp.Matching; namespace BurnOutSharp.ProtectionType { - // TODO: Figure out how to use GetContentMatches here public class SolidShield : IContentCheck, IPathCheck { /// @@ -62,7 +61,8 @@ namespace BurnOutSharp.ProtectionType // dvm.dll new Matcher(new byte?[] { 0x64, 0x76, 0x6D, 0x2E, 0x64, 0x6C, 0x6C }, "SolidShield EXE Wrapper"), - // Placeholder for the complex SolidShield + TAGES check + // (char)0xAD + (char)0xDE + (char)0xFE + (char)0xCA + new Matcher(new byte?[] { 0xAD, 0xDE, 0xFE, 0xCA }, GetVersionPlusTages, "SolidShield"), // Solidshield new Matcher(new byte?[] @@ -80,41 +80,7 @@ namespace BurnOutSharp.ProtectionType }, "SolidShield"), }; - string firstMatch = MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); - if (firstMatch != null) - return firstMatch; - - // (char)0xAD + (char)0xDE + (char)0xFE + (char)0xCA - byte?[] check = new byte?[] { 0xAD, 0xDE, 0xFE, 0xCA }; - if (fileContent.FirstPosition(check, out int position)) - { - var id1 = new ArraySegment(fileContent, position + 4, 3); - var id2 = new ArraySegment(fileContent, position + 15, 4); - - if ((fileContent[position + 3] == 0x04 || fileContent[position + 3] == 0x05) - && id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 }) - && id2.SequenceEqual(new byte[] { 0x00, 0x10, 0x00, 0x00 })) - { - return "SolidShield 2 (SolidShield v2 EXE Wrapper)" + (includePosition ? $" (Index {position})" : string.Empty); - } - else if (id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 }) - && id2.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x00 })) - { - // "T" + (char)0x00 + "a" + (char)0x00 + "g" + (char)0x00 + "e" + (char)0x00 + "s" + (char)0x00 + "S" + (char)0x00 + "e" + (char)0x00 + "t" + (char)0x00 + "u" + (char)0x00 + "p" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "0" + (char)0x00 + (char)0x8 + (char)0x00 + (char)0x1 + (char)0x0 + "F" + (char)0x00 + "i" + (char)0x00 + "l" + (char)0x00 + "e" + (char)0x00 + "V" + (char)0x00 + "e" + (char)0x00 + "r" + (char)0x00 + "s" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 - byte?[] check2 = new byte?[] { 0x54, 0x61, 0x67, 0x65, 0x73, 0x53, 0x65, 0x74, 0x75, 0x70, 0x30, 0x08, 0x01, 0x00, 0x46, 0x69, 0x6C, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x00, 0x00, 0x00, 0x00 }; - if (fileContent.FirstPosition(check2, out int position2)) - { - position2--; // TODO: Verify this subtract - return $"SolidShield 2 + Tagès {fileContent[position2 + 0x38]}.{fileContent[position2 + 0x38 + 4]}.{fileContent[position2 + 0x38 + 8]}.{fileContent[position + 0x38 + 12]}" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); - } - else - { - return "SolidShield 2 (SolidShield v2 EXE Wrapper)" + (includePosition ? $" (Index {position})" : string.Empty); - } - } - } - - return null; + return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } /// @@ -146,10 +112,10 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetExeWrapperVersion(string file, byte[] fileContent, int position) + public static string GetExeWrapperVersion(string file, byte[] fileContent, List positions) { - var id1 = new ArraySegment(fileContent, position + 5, 3); - var id2 = new ArraySegment(fileContent, position + 16, 4); + var id1 = new ArraySegment(fileContent, positions[0] + 5, 3); + var id2 = new ArraySegment(fileContent, positions[0] + 16, 4); if (id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 }) && id2.SequenceEqual(new byte[] { 0x00, 0x10, 0x00, 0x00 })) return "1 (SolidShield EXE Wrapper)"; @@ -159,7 +125,7 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetFileVersion(string file, byte[] fileContent, int position) + public static string GetFileVersion(string file, byte[] fileContent, List positions) { string companyName = string.Empty; if (file != null) @@ -171,9 +137,9 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { - int index = position + 12; // Begin reading after "Solidshield" + int index = positions[0] + 12; // Begin reading after "Solidshield" char version = (char)fileContent[index]; index++; index++; @@ -187,5 +153,36 @@ namespace BurnOutSharp.ProtectionType return $"{version}.{subVersion}.{subSubVersion}.{subSubSubVersion}"; } + + public static string GetVersionPlusTages(string file, byte[] fileContent, List positions) + { + int position = positions[0]; + var id1 = new ArraySegment(fileContent, position + 4, 3); + var id2 = new ArraySegment(fileContent, position + 15, 4); + + if ((fileContent[position + 3] == 0x04 || fileContent[position + 3] == 0x05) + && id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 }) + && id2.SequenceEqual(new byte[] { 0x00, 0x10, 0x00, 0x00 })) + { + return "2 (SolidShield v2 EXE Wrapper)"; + } + else if (id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 }) + && id2.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x00 })) + { + // "T" + (char)0x00 + "a" + (char)0x00 + "g" + (char)0x00 + "e" + (char)0x00 + "s" + (char)0x00 + "S" + (char)0x00 + "e" + (char)0x00 + "t" + (char)0x00 + "u" + (char)0x00 + "p" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "0" + (char)0x00 + (char)0x8 + (char)0x00 + (char)0x1 + (char)0x0 + "F" + (char)0x00 + "i" + (char)0x00 + "l" + (char)0x00 + "e" + (char)0x00 + "V" + (char)0x00 + "e" + (char)0x00 + "r" + (char)0x00 + "s" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + byte?[] check2 = new byte?[] { 0x54, 0x61, 0x67, 0x65, 0x73, 0x53, 0x65, 0x74, 0x75, 0x70, 0x30, 0x08, 0x01, 0x00, 0x46, 0x69, 0x6C, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x00, 0x00, 0x00, 0x00 }; + if (fileContent.FirstPosition(check2, out int position2)) + { + position2--; // TODO: Verify this subtract + return $"2 + Tagès {fileContent[position2 + 0x38]}.{fileContent[position2 + 0x38 + 4]}.{fileContent[position2 + 0x38 + 8]}.{fileContent[position + 0x38 + 12]}" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); + } + else + { + return "2 (SolidShield v2 EXE Wrapper)"; + } + } + + return null; + } } } diff --git a/BurnOutSharp/ProtectionType/StarForce.cs b/BurnOutSharp/ProtectionType/StarForce.cs index b1852b68..886e9f03 100644 --- a/BurnOutSharp/ProtectionType/StarForce.cs +++ b/BurnOutSharp/ProtectionType/StarForce.cs @@ -6,50 +6,99 @@ using BurnOutSharp.Matching; namespace BurnOutSharp.ProtectionType { - // TODO: Figure out how to use GetContentMatches here public class StarForce : IContentCheck, IPathCheck { /// public string CheckContents(string file, byte[] fileContent, bool includePosition = false) { - // "(" + (char)0x00 + "c" + (char)0x00 + ")" + (char)0x00 + " " + (char)0x00 + "P" + (char)0x00 + "r" + (char)0x00 + "o" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00 + "T" + (char)0x00 + "e" + (char)0x00 + "c" + (char)0x00 + "h" + (char)0x00 + "n" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "o" + (char)0x00 + "g" + (char)0x00 + "y" + (char)0x00 - byte?[] check = new byte?[] { 0x28, 0x00, 0x63, 0x00, 0x29, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x20, 0x00, 0x54, 0x00, 0x65, 0x00, 0x63, 0x00, 0x68, 0x00, 0x6E, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x67, 0x00, 0x79, 0x00 }; - if (fileContent.FirstPosition(check, out int position)) - { - // "PSA_GetDiscLabel" - // byte?[] check2 = new byte?[] { 0x50, 0x53, 0x41, 0x5F, 0x47, 0x65, 0x74, 0x44, 0x69, 0x73, 0x63, 0x4C, 0x61, 0x62, 0x65, 0x6C }; - - // "(c) Protection Technology" - // byte?[] check2 = new byte?[] { 0x28, 0x63, 0x29, 0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79 }; - - // "TradeName" - byte?[] check2 = new byte?[] { 0x54, 0x72, 0x61, 0x64, 0x65, 0x4E, 0x61, 0x6D, 0x65 }; - if (fileContent.FirstPosition(check2, out int position2) && position2 != 0) - return $"StarForce {Utilities.GetFileVersion(file)} ({fileContent.Skip(position2 + 22).TakeWhile(c => c != 0x00)})" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); - else - return $"StarForce {Utilities.GetFileVersion(file)}" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); - } - - // "Protection Technology, Ltd." - check = new byte?[] { 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79, 0x2C, 0x20, 0x4C, 0x74, 0x64, 0x2E }; - if (fileContent.FirstPosition(check, out position)) - { - // "PSA_GetDiscLabel" - // byte?[] check2 = new byte?[] { 0x50, 0x53, 0x41, 0x5F, 0x47, 0x65, 0x74, 0x44, 0x69, 0x73, 0x63, 0x4C, 0x61, 0x62, 0x65, 0x6C }; - - // "(c) Protection Technology" - // byte?[] check2 = new byte?[] { 0x28, 0x63, 0x29, 0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79 }; - - // "TradeName" - byte?[] check2 = new byte?[] { 0x54, 0x72, 0x61, 0x64, 0x65, 0x4E, 0x61, 0x6D, 0x65 }; - if (fileContent.FirstPosition(check2, out int position2) && position2 != 0) - return $"StarForce {Utilities.GetFileVersion(file)} ({fileContent.Skip(position2 + 22).TakeWhile(c => c != 0x00)})" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); - else - return $"StarForce {Utilities.GetFileVersion(file)}" + (includePosition ? $" (Index {position}, {position2})" : string.Empty); - } - var matchers = new List { + new Matcher(new List + { + // ( + (char)0x00 + c + (char)0x00 + ) + (char)0x00 + + (char)0x00 + P + (char)0x00 + r + (char)0x00 + o + (char)0x00 + t + (char)0x00 + e + (char)0x00 + c + (char)0x00 + t + (char)0x00 + i + (char)0x00 + o + (char)0x00 + n + (char)0x00 + + (char)0x00 + T + (char)0x00 + e + (char)0x00 + c + (char)0x00 + h + (char)0x00 + n + (char)0x00 + o + (char)0x00 + l + (char)0x00 + o + (char)0x00 + g + (char)0x00 + y + (char)0x00 + new byte?[] + { + 0x28, 0x00, 0x63, 0x00, 0x29, 0x00, 0x20, 0x00, + 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x74, 0x00, + 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, + 0x6F, 0x00, 0x6E, 0x00, 0x20, 0x00, 0x54, 0x00, + 0x65, 0x00, 0x63, 0x00, 0x68, 0x00, 0x6E, 0x00, + 0x6F, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x67, 0x00, + 0x79, 0x00 + }, + + // // PSA_GetDiscLabel + // new byte?[] + // { + // 0x50, 0x53, 0x41, 0x5F, 0x47, 0x65, 0x74, 0x44, + // 0x69, 0x73, 0x63, 0x4C, 0x61, 0x62, 0x65, 0x6C + // }, + + // (c) Protection Technology + // new byte?[] + // { + // 0x28, 0x63, 0x29, 0x20, 0x50, 0x72, 0x6F, 0x74, + // 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, + // 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, + // 0x79 + // }, + + // TradeName + new byte?[] { 0x54, 0x72, 0x61, 0x64, 0x65, 0x4E, 0x61, 0x6D, 0x65 }, + }, GetVersion, "StarForce"), + + // ( + (char)0x00 + c + (char)0x00 + ) + (char)0x00 + + (char)0x00 + P + (char)0x00 + r + (char)0x00 + o + (char)0x00 + t + (char)0x00 + e + (char)0x00 + c + (char)0x00 + t + (char)0x00 + i + (char)0x00 + o + (char)0x00 + n + (char)0x00 + + (char)0x00 + T + (char)0x00 + e + (char)0x00 + c + (char)0x00 + h + (char)0x00 + n + (char)0x00 + o + (char)0x00 + l + (char)0x00 + o + (char)0x00 + g + (char)0x00 + y + (char)0x00 + new Matcher(new byte?[] + { + 0x28, 0x00, 0x63, 0x00, 0x29, 0x00, 0x20, 0x00, + 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x74, 0x00, + 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, + 0x6F, 0x00, 0x6E, 0x00, 0x20, 0x00, 0x54, 0x00, + 0x65, 0x00, 0x63, 0x00, 0x68, 0x00, 0x6E, 0x00, + 0x6F, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x67, 0x00, + 0x79, 0x00 + }, Utilities.GetFileVersion, "StarForce"), + + new Matcher(new List + { + // Protection Technology, Ltd. + new byte?[] + { + 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, + 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, + 0x6F, 0x6C, 0x6F, 0x67, 0x79, 0x2C, 0x20, 0x4C, + 0x74, 0x64, 0x2E + }, + + // // PSA_GetDiscLabel + // new byte?[] + // { + // 0x50, 0x53, 0x41, 0x5F, 0x47, 0x65, 0x74, 0x44, + // 0x69, 0x73, 0x63, 0x4C, 0x61, 0x62, 0x65, 0x6C + // }, + + // (c) Protection Technology + // new byte?[] + // { + // 0x28, 0x63, 0x29, 0x20, 0x50, 0x72, 0x6F, 0x74, + // 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, + // 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, + // 0x79 + // }, + + // TradeName + new byte?[] { 0x54, 0x72, 0x61, 0x64, 0x65, 0x4E, 0x61, 0x6D, 0x65 }, + }, GetVersion, "StarForce"), + + // Protection Technology, Ltd. + new Matcher(new byte?[] + { + 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, + 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, + 0x6F, 0x6C, 0x6F, 0x67, 0x79, 0x2C, 0x20, 0x4C, + 0x74, 0x64, 0x2E + }, Utilities.GetFileVersion, "StarForce"), + // .sforce new Matcher(new byte?[] { 0x2E, 0x73, 0x66, 0x6F, 0x72, 0x63, 0x65 }, "StarForce 3-5"), @@ -93,5 +142,10 @@ namespace BurnOutSharp.ProtectionType return null; } + + public static string GetVersion(string file, byte[] fileContent, List positions) + { + return $"{Utilities.GetFileVersion(file)} ({fileContent.Skip(positions[1] + 22).TakeWhile(c => c != 0x00)})"; + } } } diff --git a/BurnOutSharp/ProtectionType/Sysiphus.cs b/BurnOutSharp/ProtectionType/Sysiphus.cs index 1b7418aa..e6837cc6 100644 --- a/BurnOutSharp/ProtectionType/Sysiphus.cs +++ b/BurnOutSharp/ProtectionType/Sysiphus.cs @@ -28,9 +28,9 @@ namespace BurnOutSharp.ProtectionType return MatchUtil.GetFirstContentMatch(file, fileContent, matchers, includePosition); } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { - int index = position - 3; + int index = positions[0] - 3; char subVersion = (char)fileContent[index]; index++; index++; diff --git a/BurnOutSharp/ProtectionType/Tages.cs b/BurnOutSharp/ProtectionType/Tages.cs index 090e3127..68509109 100644 --- a/BurnOutSharp/ProtectionType/Tages.cs +++ b/BurnOutSharp/ProtectionType/Tages.cs @@ -94,11 +94,11 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { // (char)0xFF + (char)0xFF + "h" - if (new ArraySegment(fileContent, --position + 8, 3).SequenceEqual(new byte[] { 0xFF, 0xFF, 0x68 })) // TODO: Verify this subtract - return GetVersion(fileContent, position); + if (new ArraySegment(fileContent, --positions[0] + 8, 3).SequenceEqual(new byte[] { 0xFF, 0xFF, 0x68 })) // TODO: Verify this subtract + return GetVersion(fileContent, positions[0]); return null; } diff --git a/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs b/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs index 04ad5fbd..cfd5f4c7 100644 --- a/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs +++ b/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs @@ -50,9 +50,9 @@ namespace BurnOutSharp.ProtectionType return null; } - public static string GetOldVersion(string file, byte[] fileContent, int position) + public static string GetOldVersion(string file, byte[] fileContent, List positions) { - position--; // TODO: Verify this subtract + int position = positions[0]--; // TODO: Verify this subtract char[] version = new ArraySegment(fileContent, position + 16, 4).Select(b => (char)b).ToArray(); // Begin reading after "VOB ProtectCD" if (char.IsNumber(version[0]) && char.IsNumber(version[2]) && char.IsNumber(version[3])) return $"{version[0]}.{version[2]}{version[3]}"; @@ -60,9 +60,9 @@ namespace BurnOutSharp.ProtectionType return "old"; } - public static string GetVersion(string file, byte[] fileContent, int position) + public static string GetVersion(string file, byte[] fileContent, List positions) { - string version = GetVersion(fileContent, --position); // TODO: Verify this subtract + string version = GetVersion(fileContent, --positions[0]); // TODO: Verify this subtract if (version.Length > 0) return version; @@ -75,7 +75,7 @@ namespace BurnOutSharp.ProtectionType return version; } - return $"5.9-6.0 {GetBuild(fileContent, position)}"; + return $"5.9-6.0 {GetBuild(fileContent, positions[0])}"; } private static string GetBuild(byte[] fileContent, int position) diff --git a/BurnOutSharp/Utilities.cs b/BurnOutSharp/Utilities.cs index 36a5ea63..2765f3c7 100644 --- a/BurnOutSharp/Utilities.cs +++ b/BurnOutSharp/Utilities.cs @@ -248,9 +248,9 @@ namespace BurnOutSharp /// /// File to check for version /// Byte array representing the file contents - /// Last matched position in the contents + /// Last matched positions in the contents /// Version string, null on error - public static string GetFileVersion(string file, byte[] fileContent, int position) + public static string GetFileVersion(string file, byte[] fileContent, List positions) { return GetFileVersion(file); }