Files
BinaryObjectScanner/BurnOutSharp/ProtectionType/CactusDataShield.cs

206 lines
10 KiB
C#
Raw Normal View History

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BurnOutSharp.ExecutableType.Microsoft.PE;
2022-05-01 17:41:50 -07:00
using BurnOutSharp.Interfaces;
2021-03-21 15:34:19 -07:00
using BurnOutSharp.Matching;
namespace BurnOutSharp.ProtectionType
{
/// <summary>
/// CactusDataShield was a copy protection originally developed by Midbar Technologies, which was then purchased by Macrovision in 2002 (https://variety.com/2002/digital/news/macrovision-acquires-midbar-cuts-ttr-link-1117875824/).
/// Macrovision's product page for CDS: https://web.archive.org/web/20050215235405/http://www.macrovision.com/products/cds/index.shtml
/// CDS-100 appears to function by attempting to prevent dumping/ripping the discs protected with it.
/// CDS-200+ uses a dedicated audio player to play the music "legitimately".
/// Patent relating to CDS-100: https://patents.google.com/patent/US6425098B1/
/// Known CDS versions:
/// CDS-100 ("The Loveparade Compilation 2001" by various artists (Barcode 74321 86986 2) (Likely Discogs Release Code [r155963]) and "World Of Our Own" (Limited Edition) by Westlife (Barcode 7 43218 98572 0) (Discogs Release Code [r1357706])).
/// CDS-200 (PlayJ) (("Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427])) (Confirmed to be CDS-200 from https://www.cdrinfo.com/d7/content/cactus-data-shield-200?page=2).
/// CDS200.0.4 - 3.0 build 16a (Redump entry 95036)
/// CDS200.0.4 - 3.0 build 16c ("TMF Hitzone 20" by various artists (Barcode 7 31458 37062 8)).
/// CDS200.0.4 - 4.1 build 2a ("Ich Habe Einen Traum" by Uwe Busse (Barcode 9 002723 251203)).
/// CDS200.0.4 - 4.1 build 2e ("Hallucinations" by David Usher (Barcode 7 24359 30322 2)).
/// CDS200.5.11.90 - 5.10.090 ("Finn 5 Fel!" by Gyllene Tider (Barcode 7 24357 10922 2)).
/// CDS-300
/// Further information:
/// https://www.cdrinfo.com/d7/content/cactus-data-shield-200
/// https://www.cdmediaworld.com/hardware/cdrom/cd_protections_cactus_data_shield.shtml
/// </summary>
2022-05-01 17:23:00 -07:00
public class CactusDataShield : IContentCheck, IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
2022-03-14 11:20:11 -07:00
{
// TODO: Limit these checks to Mac binaries
// TODO: Obtain a sample to find where this string is in a typical executable
if (includeDebug)
{
2022-03-14 11:52:49 -07:00
var contentMatchSets = new List<ContentMatchSet>
{
// CDSPlayer
new ContentMatchSet(new byte?[] { 0x43, 0x44, 0x53, 0x50, 0x6C, 0x61, 0x79, 0x65, 0x72 }, "Cactus Data Shield 200"),
// yucca.cds
new ContentMatchSet(new byte?[] { 0x79, 0x75, 0x63, 0x63, 0x61, 0x2E, 0x63, 0x64, 0x73 }, "Cactus Data Shield 200"),
};
2022-03-14 11:20:11 -07:00
if (contentMatchSets != null && contentMatchSets.Any())
return MatchUtil.GetFirstMatch(file, fileContent, contentMatchSets, includeDebug);
}
return null;
}
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
{
// Get the sections from the executable, if possible
var sections = pex?.SectionTable;
if (sections == null)
return null;
// Get the .data section, if it exists
if (pex.DataSectionRaw != null)
{
var matchers = new List<ContentMatchSet>
{
// \*.CDS
new ContentMatchSet(new byte?[] { 0x5C, 0x2A, 0x2E, 0x43, 0x44, 0x53 }, "Cactus Data Shield 200"),
// DATA.CDS
new ContentMatchSet(new byte?[] { 0x44, 0x41, 0x54, 0x41, 0x2E, 0x43, 0x44, 0x53 }, "Cactus Data Shield 200"),
};
string match = MatchUtil.GetFirstMatch(file, pex.DataSectionRaw, matchers, includeDebug);
if (!string.IsNullOrWhiteSpace(match))
return match;
}
// Get the .rsrc section, if it exists
var rsrcSectionRaw = pex.ReadRawSection(".rsrc", first: false);
if (rsrcSectionRaw != null)
{
var matchers = new List<ContentMatchSet>
{
// CactusPJ
// Found in "Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427]).
// Modified version of the PlayJ Music Player specificaly for CDS, as indicated by the About page present when running the executable.
new ContentMatchSet(new byte?[] { 0x43, 0x61, 0x63, 0x74, 0x75, 0x73, 0x50, 0x4A }, "PlayJ Music Player (Cactus Data Shield 200)"),
};
string match = MatchUtil.GetFirstMatch(file, rsrcSectionRaw, matchers, includeDebug);
if (!string.IsNullOrWhiteSpace(match))
return match;
}
return null;
}
2021-02-26 00:32:09 -08:00
/// <inheritdoc/>
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
{
2021-03-22 23:02:01 -07:00
// TODO: Verify if these are OR or AND
var matchers = new List<PathMatchSet>
{
// Found in "Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427]).
// Modified version of the PlayJ Music Player specificaly for CDS, as indicated by the About page present when running the executable.
// The file "DATA16.BML" is also present on this disc but the name is too generic to check for.
new PathMatchSet(new PathMatch("CACTUSPJ.exe", useEndsWith: true), "PlayJ Music Player (Cactus Data Shield 200)"),
// Found in "Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427]).
// In "Volumina! - Puur" (7 43218 63282 2), this file is composed of multiple PLJ files combined together.
// In later versions, this file is a padded dummy file. ("Ich Habe Einen Traum" by Uwe Busse (Barcode 9 002723 251203)).
new PathMatchSet(new PathMatch("YUCCA.CDS", useEndsWith: true), "Cactus Data Shield 200"),
// TODO: Find samples of the following:
new PathMatchSet(new PathMatch("CDSPlayer.app", useEndsWith: true), GetVersion, "Cactus Data Shield"),
new PathMatchSet(new PathMatch("wmmp.exe", useEndsWith: true), GetVersion, "Cactus Data Shield"),
Overhaul SafeDisc detection (#133) * Begin overhauling SafeDisc detection * A new utility method for obtaining the SHA1 hash of a file. * SHA1-based detection for drvmgt.dll, which is vastly more accurate than the existing size checks. * (Currently nonfunctional) PEX based checks for newer secdrv.sys versions. * General clean-up and minor additions. * Address PR review comments * Address further PR comments and remove some file size checks Remove file size checks that are now redundant. * Add CLCD16 hash based version detection Add support for detecting a rough version range from the hash of CLCD16.dll, as well as general cleanup. * Add CLCD32 hash based version detection Add hash based version checks for CLCD32.dll, which provides reliable detection for 1.X, much more than CLCD16.dll. * Add CLOKSPL hash based version detection Add CLOKSPL hash based version detection, which is an excellent indicator of version within 1.X. * Add detailed SafeDisc version notes, address PR reviews * Add a note that includes every known SafeDisc and SafeCast version. * General cleanup and minor detection additions. * Address PR reviews. * Various SafeDisc detection improvements * Add broad version checks for 00000001.TMP. * Add a few SafeDisc Lite specific CLCD32.DLL checks. * Remove unneeded dplayerx.dll size checks that were already covered by executable string checks. * Improve DPlayerX version size checks Improve DPlayerX existing version size checks and add new ones. Add new hash checks for previously undetected files. * Improve secdrv.sys version detection Improve secdrv.sys version detection using both file size checks and product version checks. * Fix various false positives Fix various false positives, as well as incomplete detections. * Address PR comments * Properly set check for File Description
2022-08-21 21:20:28 -06:00
// Present on CDS-300, as well as SafeDisc. This is likely due to both protections being created by Macrovision.
new PathMatchSet(new PathMatch("00000001.TMP", useEndsWith: true), Get00000001TMPVersion, "Cactus Data Shield 300 (Confirm presence of other CDS-300 files)"),
2021-03-22 23:02:01 -07:00
};
2021-03-19 15:41:49 -07:00
return MatchUtil.GetAllMatches(files, matchers, any: true);
2021-03-19 15:41:49 -07:00
}
/// <inheritdoc/>
public string CheckFilePath(string path)
{
2021-03-22 23:02:01 -07:00
var matchers = new List<PathMatchSet>
{
// Found in "Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427]).
// Modified version of the PlayJ Music Player specificaly for CDS, as indicated by the About page present when running the executable.
// The file "DATA16.BML" is also present on this disc but the name is too generic to check for.
new PathMatchSet(new PathMatch("CACTUSPJ.exe", useEndsWith: true), "PlayJ Music Player (Cactus Data Shield 200)"),
// Found in "Volumia!" by Puur (Barcode 7 43218 63282 2) (Discogs Release Code [r795427]),
// In "Volumia! - Puur", this file is composed of multiple PLJ files combined together.
// In later versions, this file is a padded dummy file. ("Ich Habe Einen Traum" by Uwe Busse (Barcode 9 002723 251203)).
new PathMatchSet(new PathMatch("YUCCA.CDS", useEndsWith: true), "Cactus Data Shield 200"),
// TODO: Find samples of the following:
2021-03-22 23:02:01 -07:00
new PathMatchSet(new PathMatch("CDSPlayer.app", useEndsWith: true), "Cactus Data Shield 200"),
new PathMatchSet(new PathMatch("wmmp.exe", useEndsWith: true), "Cactus Data Shield 200"),
Overhaul SafeDisc detection (#133) * Begin overhauling SafeDisc detection * A new utility method for obtaining the SHA1 hash of a file. * SHA1-based detection for drvmgt.dll, which is vastly more accurate than the existing size checks. * (Currently nonfunctional) PEX based checks for newer secdrv.sys versions. * General clean-up and minor additions. * Address PR review comments * Address further PR comments and remove some file size checks Remove file size checks that are now redundant. * Add CLCD16 hash based version detection Add support for detecting a rough version range from the hash of CLCD16.dll, as well as general cleanup. * Add CLCD32 hash based version detection Add hash based version checks for CLCD32.dll, which provides reliable detection for 1.X, much more than CLCD16.dll. * Add CLOKSPL hash based version detection Add CLOKSPL hash based version detection, which is an excellent indicator of version within 1.X. * Add detailed SafeDisc version notes, address PR reviews * Add a note that includes every known SafeDisc and SafeCast version. * General cleanup and minor detection additions. * Address PR reviews. * Various SafeDisc detection improvements * Add broad version checks for 00000001.TMP. * Add a few SafeDisc Lite specific CLCD32.DLL checks. * Remove unneeded dplayerx.dll size checks that were already covered by executable string checks. * Improve DPlayerX version size checks Improve DPlayerX existing version size checks and add new ones. Add new hash checks for previously undetected files. * Improve secdrv.sys version detection Improve secdrv.sys version detection using both file size checks and product version checks. * Fix various false positives Fix various false positives, as well as incomplete detections. * Address PR comments * Properly set check for File Description
2022-08-21 21:20:28 -06:00
// Present on CDS-300, as well as SafeDisc. This is likely due to both protections being created by Macrovision.
2022-08-21 20:36:37 -07:00
new PathMatchSet(new PathMatch("00000001.TMP", useEndsWith: true), Get00000001TMPVersion, "Cactus Data Shield 300"),
2021-03-22 23:02:01 -07:00
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
Overhaul SafeDisc detection (#133) * Begin overhauling SafeDisc detection * A new utility method for obtaining the SHA1 hash of a file. * SHA1-based detection for drvmgt.dll, which is vastly more accurate than the existing size checks. * (Currently nonfunctional) PEX based checks for newer secdrv.sys versions. * General clean-up and minor additions. * Address PR review comments * Address further PR comments and remove some file size checks Remove file size checks that are now redundant. * Add CLCD16 hash based version detection Add support for detecting a rough version range from the hash of CLCD16.dll, as well as general cleanup. * Add CLCD32 hash based version detection Add hash based version checks for CLCD32.dll, which provides reliable detection for 1.X, much more than CLCD16.dll. * Add CLOKSPL hash based version detection Add CLOKSPL hash based version detection, which is an excellent indicator of version within 1.X. * Add detailed SafeDisc version notes, address PR reviews * Add a note that includes every known SafeDisc and SafeCast version. * General cleanup and minor detection additions. * Address PR reviews. * Various SafeDisc detection improvements * Add broad version checks for 00000001.TMP. * Add a few SafeDisc Lite specific CLCD32.DLL checks. * Remove unneeded dplayerx.dll size checks that were already covered by executable string checks. * Improve DPlayerX version size checks Improve DPlayerX existing version size checks and add new ones. Add new hash checks for previously undetected files. * Improve secdrv.sys version detection Improve secdrv.sys version detection using both file size checks and product version checks. * Fix various false positives Fix various false positives, as well as incomplete detections. * Address PR comments * Properly set check for File Description
2022-08-21 21:20:28 -06:00
public static string Get00000001TMPVersion(string firstMatchedString, IEnumerable<string> files)
{
if (string.IsNullOrEmpty(firstMatchedString) || !File.Exists(firstMatchedString))
return string.Empty;
// This file is present on both CDS-300 and SafeDisc.
// Only one specific file size appears to be associated with CDS-300, so any files with a differing file size are discarded. If it is the correct file size, return it as valid.
FileInfo fi = new FileInfo(firstMatchedString);
switch (fi.Length)
{
case 2_048:
2022-08-21 20:36:37 -07:00
return "(Confirm presence of other CDS-300 files)";
Overhaul SafeDisc detection (#133) * Begin overhauling SafeDisc detection * A new utility method for obtaining the SHA1 hash of a file. * SHA1-based detection for drvmgt.dll, which is vastly more accurate than the existing size checks. * (Currently nonfunctional) PEX based checks for newer secdrv.sys versions. * General clean-up and minor additions. * Address PR review comments * Address further PR comments and remove some file size checks Remove file size checks that are now redundant. * Add CLCD16 hash based version detection Add support for detecting a rough version range from the hash of CLCD16.dll, as well as general cleanup. * Add CLCD32 hash based version detection Add hash based version checks for CLCD32.dll, which provides reliable detection for 1.X, much more than CLCD16.dll. * Add CLOKSPL hash based version detection Add CLOKSPL hash based version detection, which is an excellent indicator of version within 1.X. * Add detailed SafeDisc version notes, address PR reviews * Add a note that includes every known SafeDisc and SafeCast version. * General cleanup and minor detection additions. * Address PR reviews. * Various SafeDisc detection improvements * Add broad version checks for 00000001.TMP. * Add a few SafeDisc Lite specific CLCD32.DLL checks. * Remove unneeded dplayerx.dll size checks that were already covered by executable string checks. * Improve DPlayerX version size checks Improve DPlayerX existing version size checks and add new ones. Add new hash checks for previously undetected files. * Improve secdrv.sys version detection Improve secdrv.sys version detection using both file size checks and product version checks. * Fix various false positives Fix various false positives, as well as incomplete detections. * Address PR comments * Properly set check for File Description
2022-08-21 21:20:28 -06:00
default:
return null;
}
}
// TODO: Simplify version checking.
2021-03-22 23:02:01 -07:00
public static string GetVersion(string firstMatchedString, IEnumerable<string> files)
{
// Find the version.txt file first
string versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(versionPath))
{
2021-03-22 23:02:01 -07:00
string version = GetInternalVersion(versionPath);
if (!string.IsNullOrWhiteSpace(version))
return version;
}
2021-03-22 23:02:01 -07:00
return "200";
}
2020-10-27 14:37:14 -07:00
2021-03-22 23:02:01 -07:00
private static string GetInternalVersion(string path)
2020-10-27 14:37:14 -07:00
{
if (!File.Exists(path))
return null;
try
{
using (var sr = new StreamReader(path, Encoding.Default))
{
return $"{sr.ReadLine().Substring(3)} ({sr.ReadLine()})";
2020-10-27 14:37:14 -07:00
}
}
catch
{
return null;
}
}
}
}