2020-09-10 21:10:32 -07:00
|
|
|
|
using System;
|
2021-07-18 09:44:23 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
2020-09-10 21:10:32 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
2022-05-01 17:41:50 -07:00
|
|
|
|
using BurnOutSharp.Interfaces;
|
2021-08-25 15:09:42 -07:00
|
|
|
|
using BurnOutSharp.Tools;
|
2020-09-10 21:10:32 -07:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.FileType
|
|
|
|
|
|
{
|
2021-09-10 16:10:15 -07:00
|
|
|
|
public class Textfile : IScannable
|
2020-09-10 21:10:32 -07:00
|
|
|
|
{
|
2021-02-26 09:26:23 -08:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public bool ShouldScan(byte[] magic)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ShouldScan(magic, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determine if a file signature or extension matches one of the expected values
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="magic">Byte array representing the file header</param>
|
|
|
|
|
|
/// <param name="extension">Extension for the file being checked</param>
|
|
|
|
|
|
/// <returns>True if the signature is valid, false otherwise</returns>
|
|
|
|
|
|
public bool ShouldScan(byte[] magic, string extension)
|
2020-09-10 21:10:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Rich Text File
|
2021-03-20 20:47:56 -07:00
|
|
|
|
if (magic.StartsWith(new byte?[] { 0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31 }))
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// HTML
|
2021-03-20 20:47:56 -07:00
|
|
|
|
if (magic.StartsWith(new byte?[] { 0x3c, 0x68, 0x74, 0x6d, 0x6c }))
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// HTML and XML
|
2021-03-20 20:47:56 -07:00
|
|
|
|
if (magic.StartsWith(new byte?[] { 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45 }))
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// Microsoft Office File (old)
|
2021-03-20 20:47:56 -07:00
|
|
|
|
if (magic.StartsWith(new byte?[] { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 }))
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
|
2022-06-16 23:13:02 -06:00
|
|
|
|
// InstallShield Compiled Rules
|
|
|
|
|
|
if (magic.StartsWith(new byte?[] { 0x61, 0x4C, 0x75, 0x5A }))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2020-09-10 21:10:32 -07:00
|
|
|
|
// Generic textfile (no header)
|
2021-02-26 09:26:23 -08:00
|
|
|
|
if (string.Equals(extension?.TrimStart('.'), "txt", StringComparison.OrdinalIgnoreCase))
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
|
2022-06-29 15:28:46 -06:00
|
|
|
|
// XML (multiple headers possible)
|
|
|
|
|
|
if (string.Equals(extension?.TrimStart('.'), "xml", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-26 09:26:23 -08:00
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
|
2021-02-26 09:26:23 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
using (var fs = File.OpenRead(file))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Scan(scanner, fs, file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2021-07-18 09:44:23 -07:00
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
|
2020-09-10 21:10:32 -07:00
|
|
|
|
{
|
2021-02-26 09:26:23 -08:00
|
|
|
|
// Files can be protected in multiple ways
|
2021-07-18 09:44:23 -07:00
|
|
|
|
var protections = new ConcurrentDictionary<string, ConcurrentQueue<string>>();
|
2020-09-10 21:10:32 -07:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
// Load the current file content
|
|
|
|
|
|
string fileContent = null;
|
2020-11-03 14:57:23 -08:00
|
|
|
|
using (var sr = new StreamReader(stream, Encoding.Default, true, 1024 * 1024, true))
|
2020-09-10 21:10:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
fileContent = sr.ReadToEnd();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CD-Key
|
2020-11-03 14:41:05 -08:00
|
|
|
|
if (fileContent.Contains("a valid serial number is required"))
|
2021-02-26 09:26:23 -08:00
|
|
|
|
Utilities.AppendToDictionary(protections, file, "CD-Key / Serial");
|
2020-11-03 14:41:05 -08:00
|
|
|
|
else if (fileContent.Contains("serial number is located"))
|
2021-02-26 09:26:23 -08:00
|
|
|
|
Utilities.AppendToDictionary(protections, file, "CD-Key / Serial");
|
2020-11-03 14:41:05 -08:00
|
|
|
|
|
|
|
|
|
|
// MediaMax
|
|
|
|
|
|
if (fileContent.Contains("MediaMax technology"))
|
2021-02-26 09:26:23 -08:00
|
|
|
|
Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
|
2022-06-29 15:28:46 -06:00
|
|
|
|
else if (fileContent.Contains("exclusive Cd3 technology"))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
|
|
|
|
|
|
else if (fileContent.Contains("<PROTECTION-VENDOR>MediaMAX</PROTECTION-VENDOR>"))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
|
|
|
|
|
|
else if (fileContent.Contains("MediaMax(tm)"))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "MediaMax CD-3");
|
2021-07-01 21:51:40 -06:00
|
|
|
|
|
2022-06-16 23:13:02 -06:00
|
|
|
|
// phenoProtect
|
|
|
|
|
|
if (fileContent.Contains("phenoProtect"))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "phenoProtect");
|
|
|
|
|
|
|
2022-03-14 09:03:43 -07:00
|
|
|
|
// The full line from a sample is as follows:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The files securom_v7_01.dat and securom_v7_01.bak have been created during the installation of a SecuROM protected application.
|
|
|
|
|
|
//
|
|
|
|
|
|
// TODO: Use the filenames in this line to get the version out of it
|
|
|
|
|
|
|
|
|
|
|
|
// SecuROM
|
|
|
|
|
|
if (fileContent.Contains("SecuROM protected application"))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "SecuROM");
|
|
|
|
|
|
|
2022-06-30 17:18:12 -06:00
|
|
|
|
// Steam
|
|
|
|
|
|
if (fileContent.Contains("All use of the Program is governed by the terms of the Steam Agreement as described below."))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "Steam");
|
|
|
|
|
|
|
2021-07-01 21:51:40 -06:00
|
|
|
|
// XCP
|
|
|
|
|
|
if (fileContent.Contains("http://cp.sonybmg.com/xcp/"))
|
|
|
|
|
|
Utilities.AppendToDictionary(protections, file, "XCP");
|
2020-09-10 21:10:32 -07:00
|
|
|
|
}
|
2022-05-15 20:58:27 -07:00
|
|
|
|
catch (Exception ex)
|
2020-09-10 21:10:32 -07:00
|
|
|
|
{
|
2022-05-15 20:58:27 -07:00
|
|
|
|
if (scanner.IncludeDebug) Console.WriteLine(ex);
|
2020-09-10 21:10:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return protections;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|