Files
BinaryObjectScanner/BurnOutSharp/ProtectionType/CDDVDCops.cs

163 lines
6.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
2022-12-05 17:05:41 -08:00
using System.Text;
2022-05-01 17:41:50 -07:00
using BurnOutSharp.Interfaces;
2021-03-21 22:19:38 -07:00
using BurnOutSharp.Matching;
using BurnOutSharp.Wrappers;
namespace BurnOutSharp.ProtectionType
{
// TODO: Investigate "Cops Copylock II" (https://www.cbmstuff.com/forum/showthread.php?tid=488).
2022-12-06 22:31:46 -08:00
// `AgentHugo.exe`
// Embedded PE executable in one of the NE sections
// `AgentHugo.exe` / `NE.EXE` (1.46) / `NETINST.EXE` (1.48) / `NETINST.QZ_`
// Embedded PKZIP archive that may contain the CD-Cops files
// `CDCOPS.DLL` (1.46) / `CDCOPS.DLL` (1.48)
// `WINCOPS.INI`
2022-05-01 17:23:00 -07:00
public class CDDVDCops : IContentCheck, INewExecutableCheck, IPathCheck, IPortableExecutableCheck
{
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckContents(string file, byte[] fileContent, bool includeDebug)
{
// TODO: Obtain a sample to find where this string is in a typical executable
if (includeDebug)
{
var contentMatchSets = new List<ContentMatchSet>
{
// TODO: Remove from here once it's confirmed that no PE executables contain this string
// CD-Cops, ver.
new ContentMatchSet(new byte?[]
{
0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C,
0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
}, GetVersion, "CD-Cops (Unconfirmed - Please report to us on Github)"),
// // 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 (Unconfirmed - Please report to us on Github)"),
};
return MatchUtil.GetFirstMatch(file, fileContent, contentMatchSets, includeDebug);
}
return null;
}
2022-03-14 11:20:11 -07:00
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckNewExecutable(string file, NewExecutable nex, bool includeDebug)
2022-03-14 11:20:11 -07:00
{
// Check we have a valid executable
if (nex == null)
2022-03-14 11:20:11 -07:00
return null;
2022-03-15 11:18:53 -07:00
// TODO: Don't read entire file
var data = nex.ReadArbitraryRange();
if (data == null)
return null;
2022-03-14 11:20:11 -07:00
// TODO: Figure out what NE section this lives in
var neMatchSets = new List<ContentMatchSet>
{
// CD-Cops, ver.
// Found in "h3blade.exe" in Redump entry 85077.
2022-03-14 11:20:11 -07:00
new ContentMatchSet(new byte?[]
{
0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C,
0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20
}, GetVersion, "CD-Cops"),
2022-03-14 11:20:11 -07:00
};
2022-12-05 17:05:41 -08:00
string match = MatchUtil.GetFirstMatch(file, data, neMatchSets, includeDebug);
if (!string.IsNullOrEmpty(match))
return match;
// Check the imported-name table
// Found in "h3blade.exe" in Redump entry 85077.
2022-12-06 21:04:08 -08:00
bool importedNameTableEntries = nex.ImportedNameTable?
.Select(kvp => kvp.Value)
.Where(inte => inte.NameString != null)
2022-12-05 17:05:41 -08:00
.Select(inte => Encoding.ASCII.GetString(inte.NameString))
2022-12-06 21:04:08 -08:00
.Any(s => s.Contains("CDCOPS")) ?? false;
2022-12-05 17:05:41 -08:00
if (importedNameTableEntries)
return "CD-Cops";
// Check the nonresident-name table
// Found in "CDCOPS.DLL" in Redump entry 85077.
2022-12-06 21:04:08 -08:00
bool nonresidentNameTableEntries = nex.NonResidentNameTable?
.Where(nrnte => nrnte.NameString != null)
2022-12-05 17:05:41 -08:00
.Select(nrnte => Encoding.ASCII.GetString(nrnte.NameString))
2022-12-06 21:04:08 -08:00
.Any(s => s.Contains("CDcops assembly-language DLL")) ?? false;
2022-12-05 17:05:41 -08:00
if (nonresidentNameTableEntries)
return "CD-Cops";
return null;
2022-03-14 11:20:11 -07:00
}
/// <inheritdoc/>
2022-05-01 17:17:15 -07:00
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
2022-03-14 11:20:11 -07:00
{
// Get the sections from the executable, if possible
var sections = pex?.SectionTable;
if (sections == null)
return null;
// Get the .grand section, if it exists -- TODO: Confirm is this is in DVD-Cops as well
// Found in "AGENTHUG.QZ_" in Redump entry 84517 and "h3blade.QZ_" in Redump entry 85077.
2022-03-14 11:20:11 -07:00
bool grandSection = pex.ContainsSection(".grand", exact: true);
if (grandSection)
return "CD-Cops";
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: Original had "CDCOPS.DLL" required and all the rest in a combined OR
var matchers = new List<PathMatchSet>
{
// Found in Redump entry 84517
2021-03-22 23:02:01 -07:00
new PathMatchSet(new PathMatch("CDCOPS.DLL", useEndsWith: true), "CD-Cops"),
new PathMatchSet(new PathMatch(".W_X", useEndsWith: true), "CD-Cops"),
new PathMatchSet(new PathMatch(".QZ_", useEndsWith: true), "CD-Cops"),
new PathMatchSet(new PathMatch(".GZ_", useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
new PathMatchSet(new PathMatch(".Qz", useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
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 Redump entry 84517
2021-03-22 23:02:01 -07:00
new PathMatchSet(new PathMatch("CDCOPS.DLL", useEndsWith: true), "CD-Cops"),
new PathMatchSet(new PathMatch(".W_X", useEndsWith: true), "CD-Cops"),
new PathMatchSet(new PathMatch(".QZ_", useEndsWith: true), "CD-Cops"),
new PathMatchSet(new PathMatch(".GZ_", useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
new PathMatchSet(new PathMatch(".Qz", useEndsWith: true), "CD-Cops (Unconfirmed - Please report to us on Github)"),
2021-03-22 23:02:01 -07:00
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);
}
public static string GetVersion(string file, byte[] fileContent, List<int> positions)
{
char[] version = new ArraySegment<byte>(fileContent, positions[0] + 15, 4).Select(b => (char)b).ToArray();
if (version[0] == 0x00)
2021-03-22 16:25:40 -07:00
return string.Empty;
2019-09-30 11:08:44 -07:00
return new string(version);
}
}
}