Files
BinaryObjectScanner/BinaryObjectScanner.FileType/Textfile.cs

126 lines
5.2 KiB
C#
Raw Normal View History

using System;
2023-03-13 16:17:21 -04:00
using System.Collections.Generic;
using System.IO;
using System.Text;
2023-03-13 16:17:21 -04:00
using BinaryObjectScanner.Interfaces;
2023-03-13 16:17:21 -04:00
namespace BinaryObjectScanner.FileType
{
/// <summary>
/// Various generic textfile formats
/// </summary>
2023-03-13 16:17:21 -04:00
public class Textfile : IDetectable
{
2021-02-26 09:26:23 -08:00
/// <inheritdoc/>
2023-03-13 16:17:21 -04:00
public string Detect(string file, bool includeDebug)
2021-02-26 09:26:23 -08:00
{
if (!File.Exists(file))
return null;
2022-12-22 22:03:32 -08:00
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
2021-02-26 09:26:23 -08:00
{
2023-03-13 16:17:21 -04:00
return Detect(fs, file, includeDebug);
2021-02-26 09:26:23 -08:00
}
}
/// <inheritdoc/>
2023-03-13 16:17:21 -04:00
public string Detect(Stream stream, string file, bool includeDebug)
{
2021-02-26 09:26:23 -08:00
// Files can be protected in multiple ways
2023-03-13 16:17:21 -04:00
var protections = new List<string>();
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))
{
fileContent = sr.ReadToEnd();
}
// AegiSoft License Manager
// Found in "setup.ins" (Redump entry 73521/IA item "Nova_HoyleCasino99USA").
if (fileContent.Contains("Failed to load the AegiSoft License Manager install program."))
2023-03-13 16:17:21 -04:00
protections.Add("AegiSoft License Manager");
// CD-Key
2020-11-03 14:41:05 -08:00
if (fileContent.Contains("a valid serial number is required"))
2023-03-13 16:17:21 -04:00
protections.Add("CD-Key / Serial");
2020-11-03 14:41:05 -08:00
else if (fileContent.Contains("serial number is located"))
2023-03-13 16:17:21 -04:00
protections.Add("CD-Key / Serial");
// Found in "Setup.Ins" ("Word Point 2002" in IA item "advantage-language-french-beginner-langmaster-2005").
else if (fileContent.Contains("Please enter a valid registration number"))
2023-03-13 16:17:21 -04:00
protections.Add("CD-Key / Serial");
// Freelock
// Found in "FILE_ID.DIZ" distributed with Freelock.
if (fileContent.Contains("FREELOCK 1.0"))
2023-03-13 16:17:21 -04:00
protections.Add("Freelock 1.0");
else if (fileContent.Contains("FREELOCK 1.2"))
2023-03-13 16:17:21 -04:00
protections.Add("Freelock 1.2");
else if (fileContent.Contains("FREELOCK 1.2a"))
2023-03-13 16:17:21 -04:00
protections.Add("Freelock 1.2a");
else if (fileContent.Contains("FREELOCK 1.3"))
2023-03-13 16:17:21 -04:00
protections.Add("Freelock 1.3");
else if (fileContent.Contains("FREELOCK"))
2023-03-13 16:17:21 -04:00
protections.Add("Freelock");
2020-11-03 14:41:05 -08:00
// MediaCloQ
if (fileContent.Contains("SunnComm MediaCloQ"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaCloQ");
else if (fileContent.Contains("http://download.mediacloq.com/"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaCloQ");
else if (fileContent.Contains("http://www.sunncomm.com/mediacloq/"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaCloQ");
2020-11-03 14:41:05 -08:00
// MediaMax
if (fileContent.Contains("MediaMax technology"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaMax CD-3");
else if (fileContent.Contains("exclusive Cd3 technology"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaMax CD-3");
else if (fileContent.Contains("<PROTECTION-VENDOR>MediaMAX</PROTECTION-VENDOR>"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaMax CD-3");
else if (fileContent.Contains("MediaMax(tm)"))
2023-03-13 16:17:21 -04:00
protections.Add("MediaMax CD-3");
// phenoProtect
if (fileContent.Contains("phenoProtect"))
2023-03-13 16:17:21 -04:00
protections.Add("phenoProtect");
// Rainbow Sentinel
// Found in "SENTW95.HLP" and "SENTINEL.HLP" in BA entry "Autodesk AutoCAD LT 98 (1998) (CD) [English] [Dutch]".
if (fileContent.Contains("Rainbow Sentinel Driver Help"))
2023-03-13 16:17:21 -04:00
protections.Add("Rainbow Sentinel");
// Found in "OEMSETUP.INF" in BA entry "Autodesk AutoCAD LT 98 (1998) (CD) [English] [Dutch]".
if (fileContent.Contains("Sentinel Driver Disk"))
2023-03-13 16:17:21 -04:00
protections.Add("Rainbow Sentinel");
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"))
2023-03-13 16:17:21 -04:00
protections.Add("SecuROM");
2022-03-14 09:03:43 -07:00
// Steam
if (fileContent.Contains("All use of the Program is governed by the terms of the Steam Agreement as described below."))
2023-03-13 16:17:21 -04:00
protections.Add("Steam");
// XCP
if (fileContent.Contains("http://cp.sonybmg.com/xcp/"))
2023-03-13 16:17:21 -04:00
protections.Add("XCP");
}
2022-05-15 20:58:27 -07:00
catch (Exception ex)
{
2023-03-13 16:17:21 -04:00
if (includeDebug) Console.WriteLine(ex);
}
2023-03-13 16:17:21 -04:00
return string.Join(";", protections);
}
}
}