2019-09-27 23:52:24 -07:00
|
|
|
|
using System;
|
2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2019-10-24 16:09:43 -04:00
|
|
|
|
using System.Text;
|
2021-08-29 21:07:26 -07:00
|
|
|
|
using BurnOutSharp.ExecutableType.Microsoft;
|
2021-03-21 15:34:19 -07:00
|
|
|
|
using BurnOutSharp.Matching;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.ProtectionType
|
|
|
|
|
|
{
|
2021-02-26 01:26:49 -08:00
|
|
|
|
public class CactusDataShield : IContentCheck, IPathCheck
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-07-17 23:40:16 -07:00
|
|
|
|
/// <inheritdoc/>
|
2021-09-10 15:32:37 -07:00
|
|
|
|
private List<ContentMatchSet> GetContentMatchSets()
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-08-29 21:07:26 -07:00
|
|
|
|
// TODO: Both of these are found in Mac binaries
|
2021-08-25 19:37:32 -07:00
|
|
|
|
return new List<ContentMatchSet>
|
2021-07-17 23:40:16 -07:00
|
|
|
|
{
|
|
|
|
|
|
// CDSPlayer
|
|
|
|
|
|
new ContentMatchSet(new byte?[] { 0x43, 0x44, 0x53, 0x50, 0x6C, 0x61, 0x79, 0x65, 0x72 }, "Cactus Data Shield 200"),
|
2021-08-29 21:07:26 -07:00
|
|
|
|
|
|
|
|
|
|
// yucca.cds
|
|
|
|
|
|
new ContentMatchSet(new byte?[] { 0x79, 0x75, 0x63, 0x63, 0x61, 0x2E, 0x63, 0x64, 0x73 }, "Cactus Data Shield 200"),
|
2021-07-17 23:40:16 -07:00
|
|
|
|
};
|
2021-08-25 19:37:32 -07:00
|
|
|
|
}
|
2020-10-27 17:01:33 -07:00
|
|
|
|
|
2021-08-25 19:37:32 -07:00
|
|
|
|
/// <inheritdoc/>
|
2021-09-10 16:10:15 -07:00
|
|
|
|
public string CheckContents(string file, byte[] fileContent, bool includeDebug, PortableExecutable pex, NewExecutable nex)
|
2021-08-29 21:07:26 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Get the sections from the executable, if possible
|
|
|
|
|
|
var sections = pex?.SectionTable;
|
|
|
|
|
|
if (sections == null)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the .data section, if it exists
|
|
|
|
|
|
var dataSection = sections.FirstOrDefault(s => Encoding.ASCII.GetString(s.Name).StartsWith(".data"));
|
|
|
|
|
|
if (dataSection != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int sectionAddr = (int)dataSection.PointerToRawData;
|
|
|
|
|
|
int sectionEnd = sectionAddr + (int)dataSection.VirtualSize;
|
|
|
|
|
|
var matchers = new List<ContentMatchSet>
|
|
|
|
|
|
{
|
|
|
|
|
|
// \*.CDS
|
|
|
|
|
|
new ContentMatchSet(
|
|
|
|
|
|
new ContentMatch(new byte?[] { 0x5C, 0x2A, 0x2E, 0x43, 0x44, 0x53 }, start: sectionAddr, end: sectionEnd),
|
|
|
|
|
|
"Cactus Data Shield 200"),
|
|
|
|
|
|
|
|
|
|
|
|
// DATA.CDS
|
|
|
|
|
|
new ContentMatchSet(
|
|
|
|
|
|
new ContentMatch(new byte?[] { 0x44, 0x41, 0x54, 0x41, 0x2E, 0x43, 0x44, 0x53 }, start: sectionAddr, end: sectionEnd),
|
|
|
|
|
|
"Cactus Data Shield 200"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
string match = MatchUtil.GetFirstMatch(file, fileContent, matchers, includeDebug);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(match))
|
|
|
|
|
|
return match;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-10 15:32:37 -07:00
|
|
|
|
var contentMatchSets = GetContentMatchSets();
|
|
|
|
|
|
if (contentMatchSets != null && contentMatchSets.Any())
|
|
|
|
|
|
return MatchUtil.GetFirstMatch(file, fileContent, contentMatchSets, includeDebug);
|
|
|
|
|
|
|
2021-08-29 21:07:26 -07:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2021-02-26 00:32:09 -08:00
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentQueue<string> CheckDirectoryPath(string path, IEnumerable<string> files)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-22 23:02:01 -07:00
|
|
|
|
// TODO: Verify if these are OR or AND
|
|
|
|
|
|
var matchers = new List<PathMatchSet>
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-22 23:02:01 -07:00
|
|
|
|
new PathMatchSet(new PathMatch("CACTUSPJ.exe", useEndsWith: true), GetVersion, "Cactus Data Shield"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("CDSPlayer.app", useEndsWith: true), GetVersion, "Cactus Data Shield"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("PJSTREAM.DLL", useEndsWith: true), GetVersion, "Cactus Data Shield"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("wmmp.exe", useEndsWith: true), GetVersion, "Cactus Data Shield"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch(".cds", useEndsWith: true), GetVersion, "Cactus Data Shield"),
|
|
|
|
|
|
};
|
2021-03-19 15:41:49 -07:00
|
|
|
|
|
2021-03-23 13:35:12 -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>
|
|
|
|
|
|
{
|
|
|
|
|
|
new PathMatchSet(new PathMatch("CACTUSPJ.exe", useEndsWith: true), "Cactus Data Shield 200"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("CDSPlayer.app", useEndsWith: true), "Cactus Data Shield 200"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("PJSTREAM.DLL", useEndsWith: true), "Cactus Data Shield 200"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch("wmmp.exe", useEndsWith: true), "Cactus Data Shield 200"),
|
|
|
|
|
|
new PathMatchSet(new PathMatch(".cds", useEndsWith: true), "Cactus Data Shield 200"),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return MatchUtil.GetFirstMatch(path, matchers, any: true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2021-03-22 23:02:01 -07:00
|
|
|
|
string version = GetInternalVersion(versionPath);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(version))
|
|
|
|
|
|
return version;
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
2021-03-22 23:02:01 -07:00
|
|
|
|
|
|
|
|
|
|
return "200";
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
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))
|
|
|
|
|
|
{
|
2020-10-27 17:01:33 -07:00
|
|
|
|
return $"{sr.ReadLine().Substring(3)} ({sr.ReadLine()})";
|
2020-10-27 14:37:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|