Skip to content

Commit af43748

Browse files
Improve detection for cd/dvd-cops version string (#368)
* Improve detection for cd/dvd-cops version string * I forgot to include the regex compensation for comma version number cases * Pasted comment wrong previously * Implemented Sabre's review fixes, also added check for Codefree
1 parent d28d8b5 commit af43748

File tree

2 files changed

+80
-41
lines changed

2 files changed

+80
-41
lines changed

BinaryObjectScanner.Test/Protection/CDDVDCopsTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ namespace BinaryObjectScanner.Test.Protection
77
{
88
public class CDDVDCopsTests
99
{
10-
[Fact]
11-
public void CheckContentsTest()
12-
{
13-
string file = "filename";
14-
byte[] fileContent = [0x01, 0x02, 0x03, 0x04];
15-
16-
var checker = new CDDVDCops();
17-
string? actual = checker.CheckContents(file, fileContent, includeDebug: true);
18-
Assert.Null(actual);
19-
}
20-
2110
[Fact]
2211
public void CheckNewExecutableTest()
2312
{

BinaryObjectScanner/Protection/CDDVDCops.cs

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
#endif
66
using System.Text;
7+
using System.Text.RegularExpressions;
78
using BinaryObjectScanner.Interfaces;
89
using SabreTools.Matching;
910
using SabreTools.Matching.Content;
@@ -64,35 +65,12 @@ namespace BinaryObjectScanner.Protection
6465
///
6566
/// List of applications that have CD/DVD/WEB-Cops relating to a Windows update: https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/924867
6667
/// </summary>
67-
68-
public class CDDVDCops : IContentCheck, IExecutableCheck<NewExecutable>, IExecutableCheck<PortableExecutable>, IPathCheck
68+
// TODO: Investigate reference to "CD32COPS.DLL" in "WETFLIPP.QZ_" in IA item "Triada_Russian_DVD_Complete_Collection_of_Erotic_Games".
69+
// TODO: Investigate cdcode.key for redump ID 108167, may be key-less cd-cops?
70+
// TODO: Document update 12 for redump ID 108167 bumping version, adding key, adding vista(?) support
71+
72+
public class CDDVDCops : IExecutableCheck<NewExecutable>, IExecutableCheck<PortableExecutable>, IPathCheck
6973
{
70-
// TODO: Investigate reference to "CD32COPS.DLL" in "WETFLIPP.QZ_" in IA item "Triada_Russian_DVD_Complete_Collection_of_Erotic_Games".
71-
/// <inheritdoc/>
72-
public string? CheckContents(string file, byte[] fileContent, bool includeDebug)
73-
{
74-
// TODO: Obtain a sample to find where this string is in a typical executable
75-
var contentMatchSets = new List<ContentMatchSet>
76-
{
77-
// TODO: Remove from here once it's confirmed that no PE executables contain this string
78-
// CD-Cops, ver.
79-
new(new byte?[]
80-
{
81-
0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C,
82-
0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
83-
}, GetVersion, "CD-Cops (Unconfirmed - Please report to us on Github)"),
84-
85-
// // DVD-Cops, ver.
86-
new(new byte?[]
87-
{
88-
0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73,
89-
0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
90-
}, GetVersion, "DVD-Cops (Unconfirmed - Please report to us on Github)"),
91-
};
92-
93-
return MatchUtil.GetFirstMatch(file, fileContent, contentMatchSets, includeDebug);
94-
}
95-
9674
/// <inheritdoc/>
9775
public string? CheckExecutable(string file, NewExecutable nex, bool includeDebug)
9876
{
@@ -104,13 +82,39 @@ public class CDDVDCops : IContentCheck, IExecutableCheck<NewExecutable>, IExecut
10482
// TODO: Figure out what NE section this lives in
10583
var neMatchSets = new List<ContentMatchSet>
10684
{
107-
// CD-Cops, ver.
85+
// Checking for variants with one or two spaces, just in case; the Brockhaus DVDs only had one
86+
new(new byte?[]
87+
{
88+
0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C,
89+
0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
90+
}, GetVersion, "CD-Cops"),
91+
// CD-Cops, ver.
92+
10893
// Found in "h3blade.exe" in Redump entry 85077.
10994
new(new byte?[]
11095
{
11196
0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C,
11297
0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
11398
}, GetVersion, "CD-Cops"),
99+
// CD-Cops, ver.
100+
101+
// Found in IA entries "der-brockhaus-multimedial-2002-premium" and "der-brockhaus-multimedial-2003-premium"
102+
// TODO: 2002 returns DVD-Cops 2.01, 2003 returns DVD-Cops 1,60. CD-Cops version numbers seem to "reset"
103+
// after some point in time in existing redump entries- perhaps the command instead of the period may have
104+
// some significance?
105+
new(new byte?[]
106+
{
107+
0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73,
108+
0x2C, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
109+
}, GetVersion, "DVD-Cops"),
110+
// DVD-Cops, ver.
111+
112+
new(new byte?[]
113+
{
114+
0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73,
115+
0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
116+
}, GetVersion, "DVD-Cops"),
117+
// DVD-Cops, ver.
114118
};
115119

116120
var match = MatchUtil.GetFirstMatch(file, data, neMatchSets, includeDebug);
@@ -186,7 +190,22 @@ public class CDDVDCops : IContentCheck, IExecutableCheck<NewExecutable>, IExecut
186190
// Found in "FGP.exe" in IA item "flaklypa-grand-prix-dvd"/Redump entry 108169.
187191
if (pex.ContainsSection("UNICops", exact: true))
188192
return "UNI-Cops";
189-
193+
194+
// Get the DATA section, if it exists
195+
// Found in "bib.dll" in IA item "https://archive.org/details/cover_202501"
196+
// This contains the version section that the Content Check looked for. There are likely other sections
197+
// that may contain it. Update when more are found.
198+
var strs = pex.GetFirstSectionStrings("DATA");
199+
if (strs != null)
200+
{
201+
var match = strs.Find(s => s.Contains(" ver. ") && (s.Contains("CD-Cops, ") || s.Contains("DVD-Cops, ")));
202+
if (match != null)
203+
if (match.Contains("CD-Cops"))
204+
return $"CD-Cops {GetVersionString(match)}";
205+
else if (match.Contains("DVD-Cops"))
206+
return $"DVD-Cops {GetVersionString(match)}";
207+
}
208+
190209
return null;
191210
}
192211

@@ -206,6 +225,16 @@ public List<string> CheckDirectoryPath(string path, List<string>? files)
206225

207226
new(new PathMatch(".GZ_", matchCase: true, useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
208227
new(new PathMatch(".Qz", matchCase: true, useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
228+
229+
// Found in Redump entries 84517, 108167, 119435, 119436, and 119437. This is the official
230+
// name from their website https://www.linkdatasecurity.com/index.htm#/protection-products/cd-dvd-usb-copy-protection/cdcops
231+
// I can't find this specific filename documented anywhere, but, all of these
232+
// games do not require a key to be input
233+
new(new FilePathMatch("cdcode.key"), "CD-Cops Codefree"),
234+
235+
// DVD-Cops Codefree does exist https://www.linkdatasecurity.com/index.htm#/protection-products/cd-dvd-usb-copy-protection/dvdvers
236+
// but we currently have no samples. Presumably this is what the file would be called?
237+
new(new FilePathMatch("dvdcode.key"), "DVD-Cops Codefree (Unconfirmed - Please report to us on Github)"),
209238
};
210239

211240
return MatchUtil.GetAllMatches(files, matchers, any: true);
@@ -226,6 +255,15 @@ public List<string> CheckDirectoryPath(string path, List<string>? files)
226255

227256
new(new PathMatch(".GZ_", matchCase: true, useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
228257
new(new PathMatch(".Qz", matchCase: true, useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
258+
// Found in Redump entries 84517, 108167, 119435, 119436, and 119437. This is the official
259+
// name from their website https://www.linkdatasecurity.com/index.htm#/protection-products/cd-dvd-usb-copy-protection/cdcops
260+
// I can't find this specific filename documented anywhere, but, all of these
261+
// games do not require a key to be input
262+
new(new FilePathMatch("cdcode.key"), "CD-Cops Codefree"),
263+
264+
// DVD-Cops Codefree does exist https://www.linkdatasecurity.com/index.htm#/protection-products/cd-dvd-usb-copy-protection/dvdvers
265+
// but we currently have no samples. Presumably this is what the file would be called?
266+
new(new FilePathMatch("dvdcode.key"), "DVD-Cops Codefree (Unconfirmed - Please report to us on Github)"),
229267
};
230268

231269
return MatchUtil.GetFirstMatch(path, matchers, any: true);
@@ -243,5 +281,17 @@ public List<string> CheckDirectoryPath(string path, List<string>? files)
243281

244282
return version;
245283
}
284+
285+
private static string GetVersionString(string match)
286+
{
287+
// Full string ends with # (i.e. "CD-Cops, ver. 1.72, #"), use that to compensate for comma in version
288+
// number cases (don't change the comma, see earlier to-do) like "DVD-Cops, ver. 1,60, #"
289+
// TODO: improve regex via the starting "N" character? Possibly unnecessary?
290+
var versionMatch = Regex.Match(match, @"(?<=D-Cops,\s{1,}ver. )(.*?)(?=,\s{1,}#)");
291+
if (versionMatch.Success)
292+
return versionMatch.Value;
293+
294+
return "(Unknown Version - Please report to us on GitHub)";
295+
}
246296
}
247297
}

0 commit comments

Comments
 (0)