Make it easier to support new file types

This commit is contained in:
Matt Nadareski
2022-12-08 21:32:52 -08:00
parent 3b4929a368
commit 39f2dd88aa
22 changed files with 718 additions and 49 deletions

100
BurnOutSharp/Enums.cs Normal file
View File

@@ -0,0 +1,100 @@
namespace BurnOutSharp
{
public enum FileTypes
{
/// <summary>
/// Unknown or unsupported
/// </summary>
UNKNOWN,
/// <summary>
/// BFPK custom archive
/// </summary>
BFPK,
/// <summary>
/// bzip2 archive
/// </summary>
BZip2,
/// <summary>
/// Executable or library
/// </summary>
Executable,
/// <summary>
/// gzip archive
/// </summary>
GZIP,
/// <summary>
/// Key-value pair INI file
/// </summary>
IniFile,
/// <summary>
/// InstallShield archive v3
/// </summary>
InstallShieldArchiveV3,
/// <summary>
/// InstallShield cabinet file
/// </summary>
InstallShieldCAB,
/// <summary>
/// Microsoft cabinet file
/// </summary>
MicrosoftCAB,
/// <summary>
/// MPQ game data archive
/// </summary>
MPQ,
/// <summary>
/// Microsoft installation package
/// </summary>
MSI,
/// <summary>
/// PKWARE ZIP archive and derivatives
/// </summary>
PKZIP,
/// <summary>
/// PlayJ audio file
/// </summary>
PLJ,
/// <summary>
/// RAR archive
/// </summary>
RAR,
/// <summary>
/// 7-zip archive
/// </summary>
SevenZip,
/// <summary>
/// Tape archive
/// </summary>
TapeArchive,
/// <summary>
/// Various generic textfile formats
/// </summary>
Textfile,
/// <summary>
/// Various Valve archive formats
/// </summary>
Valve,
/// <summary>
/// xz archive
/// </summary>
XZ,
}
}

View File

@@ -9,6 +9,9 @@ using SharpCompress.Compressors.Deflate;
namespace BurnOutSharp.FileType
{
/// <summary>
/// BFPK custom archive format
/// </summary>
public class BFPK : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using SharpCompress.Compressors.BZip2;
namespace BurnOutSharp.FileType
{
/// <summary>
/// bzip2 archive
/// </summary>
public class BZip2 : IScannable
{
/// <inheritdoc/>

View File

@@ -9,6 +9,9 @@ using BurnOutSharp.Wrappers;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Executable or library
/// </summary>
public class Executable : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using SharpCompress.Archives.GZip;
namespace BurnOutSharp.FileType
{
/// <summary>
/// gzip archive
/// </summary>
public class GZIP : IScannable
{
/// <inheritdoc/>

View File

@@ -6,6 +6,9 @@ using System.Linq;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Key-value pair INI file
/// </summary>
public class IniFile : IDictionary<string, string>
{
private Dictionary<string, string> _keyValuePairs = new Dictionary<string, string>();

View File

@@ -9,6 +9,9 @@ using UnshieldSharp.Archive;
namespace BurnOutSharp.FileType
{
/// <summary>
/// InstallShield archive v3
/// </summary>
public class InstallShieldArchiveV3 : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using UnshieldSharp.Cabinet;
namespace BurnOutSharp.FileType
{
/// <summary>
/// InstallShield cabinet file
/// </summary>
public class InstallShieldCAB : IScannable
{
/// <inheritdoc/>

View File

@@ -7,6 +7,9 @@ using StormLibSharp;
namespace BurnOutSharp.FileType
{
/// <summary>
/// MPQ game data archive
/// </summary>
public class MPQ : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using OpenMcdf;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Microsoft installation package
/// </summary>
public class MSI : IScannable
{
/// <inheritdoc/>

View File

@@ -13,7 +13,10 @@ using WixToolset.Dtf.Compression.Cab;
namespace BurnOutSharp.FileType
{
// Specification available at http://download.microsoft.com/download/5/0/1/501ED102-E53F-4CE0-AA6B-B0F93629DDC6/Exchange/%5BMS-CAB%5D.pdf
/// <summary>
/// Microsoft cabinet file
/// </summary>
/// <remarks>Specification available at <see href="http://download.microsoft.com/download/5/0/1/501ED102-E53F-4CE0-AA6B-B0F93629DDC6/Exchange/%5BMS-CAB%5D.pdf"/></remarks>
public class MicrosoftCAB : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using SharpCompress.Archives.Zip;
namespace BurnOutSharp.FileType
{
/// <summary>
/// PKWARE ZIP archive and derivatives
/// </summary>
public class PKZIP : IScannable
{
/// <inheritdoc/>

View File

@@ -1,12 +1,14 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Tools;
namespace BurnOutSharp.FileType
{
/// <summary>
/// PlayJ audio file
/// </summary>
public class PLJ : IScannable
{
/// <inheritdoc/>
@@ -40,7 +42,7 @@ namespace BurnOutSharp.FileType
byte[] magic = new byte[16];
stream.Read(magic, 0, 16);
if (ShouldScan(magic))
if (Utilities.GetFileType(magic) == FileTypes.PLJ)
{
Utilities.AppendToDictionary(protections, file, "PlayJ Audio File");
return protections;

View File

@@ -8,6 +8,9 @@ using SharpCompress.Archives.Rar;
namespace BurnOutSharp.FileType
{
/// <summary>
/// RAR archive
/// </summary>
public class RAR : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using SharpCompress.Archives.SevenZip;
namespace BurnOutSharp.FileType
{
/// <summary>
/// 7-zip archive
/// </summary>
public class SevenZip : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using SharpCompress.Archives.Tar;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Tape archive
/// </summary>
public class TapeArchive : IScannable
{
/// <inheritdoc/>

View File

@@ -7,6 +7,9 @@ using BurnOutSharp.Tools;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Various generic textfile formats
/// </summary>
public class Textfile : IScannable
{
/// <inheritdoc/>

View File

@@ -8,6 +8,9 @@ using HLLib.Packages;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Various Valve archive formats
/// </summary>
public class Valve : IScannable
{
/// <inheritdoc/>

View File

@@ -7,6 +7,9 @@ using SharpCompress.Compressors.Xz;
namespace BurnOutSharp.FileType
{
/// <summary>
/// xz archive
/// </summary>
public class XZ : IScannable
{
/// <inheritdoc/>

View File

@@ -46,12 +46,12 @@ namespace BurnOutSharp.ProtectionType
{
0x45, 0x52, 0x65, 0x67, 0x20, 0x43, 0x6F, 0x6E,
0x66, 0x69, 0x67, 0x20, 0x46, 0x6F, 0x72, 0x6D
}, Utilities.GetInternalVersion, "EA CdKey Registration Module"),
}, "EA CdKey Registration Module"),
};
string match = MatchUtil.GetFirstMatch(file, dataSectionRaw, matchers, includeDebug);
if (!string.IsNullOrWhiteSpace(match))
return match;
return $"{match} {Utilities.GetInternalVersion(pex)}";
}
// Get the .rdata section, if it exists

View File

@@ -309,26 +309,40 @@ namespace BurnOutSharp
return null;
}
// Get the file type either from magic number or extension
FileTypes fileType = Utilities.GetFileType(magic);
if (fileType == FileTypes.UNKNOWN)
fileType = Utilities.GetFileType(extension);
// If we still got unknown, just return null
if (fileType == FileTypes.UNKNOWN)
return null;
// Create a scannable for the given file type
var scannable = Utilities.CreateScannable(fileType);
if (scannable == null)
return null;
#region Non-Archive File Types
// Executable
if (new Executable().ShouldScan(magic))
if (scannable is Executable)
{
var subProtections = new Executable().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// PLJ
if (new PLJ().ShouldScan(magic))
if (scannable is PLJ)
{
var subProtections = new PLJ().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// Text-based files
if (new Textfile().ShouldScan(magic, extension))
if (scannable is Textfile)
{
var subProtections = new Textfile().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -340,113 +354,113 @@ namespace BurnOutSharp
if (ScanArchives)
{
// 7-Zip archive
if (new SevenZip().ShouldScan(magic))
if (scannable is SevenZip)
{
var subProtections = new SevenZip().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// BFPK archive
if (new BFPK().ShouldScan(magic))
if (scannable is BFPK)
{
var subProtections = new BFPK().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// BZip2
if (new BZip2().ShouldScan(magic))
if (scannable is BZip2)
{
var subProtections = new BZip2().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// GZIP
if (new GZIP().ShouldScan(magic))
if (scannable is GZIP)
{
var subProtections = new GZIP().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// InstallShield Archive V3 (Z)
if (fileName != null && new InstallShieldArchiveV3().ShouldScan(magic))
if (fileName != null && scannable is InstallShieldArchiveV3)
{
var subProtections = new InstallShieldArchiveV3().Scan(this, fileName);
var subProtections = scannable.Scan(this, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// InstallShield Cabinet
if (fileName != null && new InstallShieldCAB().ShouldScan(magic))
if (fileName != null && scannable is InstallShieldCAB)
{
var subProtections = new InstallShieldCAB().Scan(this, fileName);
var subProtections = scannable.Scan(this, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// Microsoft Cabinet
if (fileName != null && new MicrosoftCAB().ShouldScan(magic))
if (fileName != null && scannable is MicrosoftCAB)
{
var subProtections = new MicrosoftCAB().Scan(this, fileName);
var subProtections = scannable.Scan(this, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// MSI
if (fileName != null && new MSI().ShouldScan(magic))
if (fileName != null && scannable is MSI)
{
var subProtections = new MSI().Scan(this, fileName);
var subProtections = scannable.Scan(this, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// MPQ archive
if (fileName != null && new MPQ().ShouldScan(magic))
if (fileName != null && scannable is MPQ)
{
var subProtections = new MPQ().Scan(this, fileName);
var subProtections = scannable.Scan(this, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// PKZIP archive (and derivatives)
if (new PKZIP().ShouldScan(magic))
if (scannable is PKZIP)
{
var subProtections = new PKZIP().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// RAR archive
if (new RAR().ShouldScan(magic))
if (scannable is RAR)
{
var subProtections = new RAR().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// Tape Archive
if (new TapeArchive().ShouldScan(magic))
if (scannable is TapeArchive)
{
var subProtections = new TapeArchive().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// Valve archive formats
if (fileName != null && new Valve().ShouldScan(magic))
if (fileName != null && scannable is Valve)
{
var subProtections = new Valve().Scan(this, fileName);
var subProtections = scannable.Scan(this, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}
// XZ
if (new XZ().ShouldScan(magic))
if (scannable is XZ)
{
var subProtections = new XZ().Scan(this, stream, fileName);
var subProtections = scannable.Scan(this, stream, fileName);
Utilities.PrependToKeys(subProtections, fileName);
Utilities.AppendToDictionary(protections, subProtections);
}

View File

@@ -5,7 +5,9 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using BurnOutSharp.Interfaces;
using BurnOutSharp.Wrappers;
using psxt001z;
namespace BurnOutSharp.Tools
{
@@ -137,7 +139,7 @@ namespace BurnOutSharp.Tools
// Get a list of all of the keys
var keys = original.Keys.ToList();
// Iterate and reset keys
for (int i = 0; i < keys.Count; i++)
{
@@ -177,6 +179,515 @@ namespace BurnOutSharp.Tools
#endregion
#region File Types
/// <summary>
/// Get the supported file type for a magic string
/// </summary>
/// <remarks>Recommend sending in 16 bytes to check</remarks>
public static FileTypes GetFileType(byte[] magic)
{
// If we have an invalid magic byte array
if (magic == null || magic.Length == 0)
return FileTypes.UNKNOWN;
#region BFPK
if (magic.StartsWith(new byte?[] { 0x42, 0x46, 0x50, 0x4b }))
return FileTypes.BFPK;
#endregion
#region BZip2
if (magic.StartsWith(new byte?[] { 0x42, 0x52, 0x68 }))
return FileTypes.BZip2;
#endregion
#region Executable
// DOS MZ executable file format (and descendants)
if (magic.StartsWith(new byte?[] { 0x4d, 0x5a }))
return FileTypes.Executable;
/*
// None of the following are supported in scans yet
// Executable and Linkable Format
if (magic.StartsWith(new byte?[] { 0x7f, 0x45, 0x4c, 0x46 }))
return FileTypes.Executable;
// Mach-O binary (32-bit)
if (magic.StartsWith(new byte?[] { 0xfe, 0xed, 0xfa, 0xce }))
return FileTypes.Executable;
// Mach-O binary (32-bit, reverse byte ordering scheme)
if (magic.StartsWith(new byte?[] { 0xce, 0xfa, 0xed, 0xfe }))
return FileTypes.Executable;
// Mach-O binary (64-bit)
if (magic.StartsWith(new byte?[] { 0xfe, 0xed, 0xfa, 0xcf }))
return FileTypes.Executable;
// Mach-O binary (64-bit, reverse byte ordering scheme)
if (magic.StartsWith(new byte?[] { 0xcf, 0xfa, 0xed, 0xfe }))
return FileTypes.Executable;
// Prefrred Executable File Format
if (magic.StartsWith(new byte?[] { 0x4a, 0x6f, 0x79, 0x21, 0x70, 0x65, 0x66, 0x66 }))
return FileTypes.Executable;
*/
#endregion
#region GZIP
if (magic.StartsWith(new byte?[] { 0x1f, 0x8b }))
return FileTypes.GZIP;
#endregion
#region IniFile
// No magic checks for IniFile
#endregion
#region InstallShieldArchiveV3
if (magic.StartsWith(new byte?[] { 0x13, 0x5D, 0x65, 0x8C }))
return FileTypes.InstallShieldArchiveV3;
#endregion
#region InstallShieldCAB
if (magic.StartsWith(new byte?[] { 0x49, 0x53, 0x63 }))
return FileTypes.InstallShieldCAB;
#endregion
#region MicrosoftCAB
if (magic.StartsWith(new byte?[] { 0x4d, 0x53, 0x43, 0x46 }))
return FileTypes.MicrosoftCAB;
#endregion
#region MPQ
if (magic.StartsWith(new byte?[] { 0x4d, 0x50, 0x51, 0x1a }))
return FileTypes.MPQ;
#endregion
#region MSI
if (magic.StartsWith(new byte?[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 }))
return FileTypes.MSI;
#endregion
#region PKZIP
// PKZIP (Unknown)
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x00, 0x00 }))
return FileTypes.PKZIP;
// PKZIP
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x03, 0x04 }))
return FileTypes.PKZIP;
// PKZIP (Empty Archive)
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x05, 0x06 }))
return FileTypes.PKZIP;
// PKZIP (Spanned Archive)
if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x07, 0x08 }))
return FileTypes.PKZIP;
#endregion
#region PLJ
// https://www.iana.org/assignments/media-types/audio/vnd.everad.plj
if (magic.StartsWith(new byte?[] { 0xFF, 0x9D, 0x53, 0x4B }))
return FileTypes.PLJ;
#endregion
#region RAR
// RAR archive version 1.50 onwards
if (magic.StartsWith(new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 }))
return FileTypes.RAR;
// RAR archive version 5.0 onwards
if (magic.StartsWith(new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00 }))
return FileTypes.RAR;
#endregion
#region SevenZip
if (magic.StartsWith(new byte?[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c }))
return FileTypes.SevenZip;
#endregion
#region TapeArchive
if (magic.StartsWith(new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30 }))
return FileTypes.TapeArchive;
if (magic.StartsWith(new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00 }))
return FileTypes.TapeArchive;
#endregion
#region Textfile
// Not all textfiles can be determined through magic number
// HTML
if (magic.StartsWith(new byte?[] { 0x3c, 0x68, 0x74, 0x6d, 0x6c }))
return FileTypes.Textfile;
// HTML and XML
if (magic.StartsWith(new byte?[] { 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45 }))
return FileTypes.Textfile;
// InstallShield Compiled Rules
if (magic.StartsWith(new byte?[] { 0x61, 0x4C, 0x75, 0x5A }))
return FileTypes.Textfile;
// Microsoft Office File (old)
if (magic.StartsWith(new byte?[] { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 }))
return FileTypes.Textfile;
// Rich Text File
if (magic.StartsWith(new byte?[] { 0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31 }))
return FileTypes.Textfile;
// Windows Help File
if (magic.StartsWith(new byte?[] { 0x3F, 0x5F, 0x03, 0x00 }))
return FileTypes.Textfile;
#endregion
#region Valve
if (HLLib.Packages.Package.GetPackageType(magic) != HLLib.Packages.PackageType.HL_PACKAGE_NONE)
return FileTypes.Valve;
#endregion
#region XZ
if (magic.StartsWith(new byte?[] { 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00 }))
return FileTypes.XZ;
#endregion
// We couldn't find a supported match
return FileTypes.UNKNOWN;
}
/// <summary>
/// Get the supported file type for an extension
/// </summary>
/// <remarks>This is less accurate than a magic string match</remarks>
public static FileTypes GetFileType(string extension)
{
// If we have an invalid extension
if (string.IsNullOrWhiteSpace(extension))
return FileTypes.UNKNOWN;
// Normalize the extension
extension = extension.TrimStart('.').Trim();
#region BFPK
// No extensions registered for BFPK
#endregion
#region BZip2
if (extension.Equals("bz2", StringComparison.OrdinalIgnoreCase))
return FileTypes.BZip2;
#endregion
#region Executable
// DOS MZ executable file format (and descendants)
if (extension.Equals("exe", StringComparison.OrdinalIgnoreCase))
return FileTypes.Executable;
// DOS MZ library file format (and descendants)
if (extension.Equals("dll", StringComparison.OrdinalIgnoreCase))
return FileTypes.Executable;
#endregion
#region GZIP
if (extension.Equals("gz", StringComparison.OrdinalIgnoreCase))
return FileTypes.GZIP;
#endregion
#region IniFile
if (extension.Equals("ini", StringComparison.OrdinalIgnoreCase))
return FileTypes.IniFile;
#endregion
#region InstallShieldArchiveV3
if (extension.Equals("z", StringComparison.OrdinalIgnoreCase))
return FileTypes.InstallShieldArchiveV3;
#endregion
#region InstallShieldCAB
// No extensions registered for InstallShieldCAB
// Both InstallShieldCAB and MicrosoftCAB share the same extension
#endregion
#region MicrosoftCAB
// No extensions registered for InstallShieldCAB
// Both InstallShieldCAB and MicrosoftCAB share the same extension
#endregion
#region MPQ
if (extension.Equals("mpq", StringComparison.OrdinalIgnoreCase))
return FileTypes.MPQ;
#endregion
#region MSI
if (extension.Equals("msi", StringComparison.OrdinalIgnoreCase))
return FileTypes.MSI;
#endregion
#region PKZIP
// PKZIP
if (extension.Equals("zip", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Android package
if (extension.Equals("apk", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Java archive
if (extension.Equals("jar", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Google Earth saved working session file
if (extension.Equals("kmz", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// KWord document
if (extension.Equals("kwd", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Microsoft Office Open XML Format (OOXML) Document
if (extension.Equals("docx", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Microsoft Office Open XML Format (OOXML) Presentation
if (extension.Equals("pptx", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Microsoft Office Open XML Format (OOXML) Spreadsheet
if (extension.Equals("xlsx", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenDocument text document
if (extension.Equals("odt", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenDocument presentation
if (extension.Equals("odp", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenDocument text document template
if (extension.Equals("ott", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Microsoft Open XML paper specification file
if (extension.Equals("oxps", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenOffice spreadsheet
if (extension.Equals("sxc", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenOffice drawing
if (extension.Equals("sxd", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenOffice presentation
if (extension.Equals("sxi", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// OpenOffice word processing
if (extension.Equals("sxw", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// StarOffice spreadsheet
if (extension.Equals("sxc", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Windows Media compressed skin file
if (extension.Equals("wmz", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// Mozilla Browser Archive
if (extension.Equals("xpi", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// XML paper specification file
if (extension.Equals("xps", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
// eXact Packager Models
if (extension.Equals("xpt", StringComparison.OrdinalIgnoreCase))
return FileTypes.PKZIP;
#endregion
#region PLJ
// https://www.iana.org/assignments/media-types/audio/vnd.everad.plj
if (extension.Equals("plj", StringComparison.OrdinalIgnoreCase))
return FileTypes.PLJ;
#endregion
#region RAR
if (extension.Equals("rar", StringComparison.OrdinalIgnoreCase))
return FileTypes.RAR;
#endregion
#region SevenZip
if (extension.Equals("7z", StringComparison.OrdinalIgnoreCase))
return FileTypes.SevenZip;
#endregion
#region TapeArchive
if (extension.Equals("tar", StringComparison.OrdinalIgnoreCase))
return FileTypes.SevenZip;
#endregion
#region Textfile
// "Description in Zip"
if (extension.Equals("diz", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// Generic textfile (no header)
if (extension.Equals("txt", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// HTML
if (extension.Equals("htm", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
if (extension.Equals("html", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// InstallShield Script
if (extension.Equals("ins", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// Microsoft Office File (old)
if (extension.Equals("doc", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// Rich Text File
if (extension.Equals("rtf", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// Setup information
if (extension.Equals("inf", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// Windows Help File
if (extension.Equals("hlp", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
// XML
if (extension.Equals("xml", StringComparison.OrdinalIgnoreCase))
return FileTypes.Textfile;
#endregion
#region Valve
// No extensions registered for Valve
#endregion
#region XZ
if (extension.Equals("xz", StringComparison.OrdinalIgnoreCase))
return FileTypes.XZ;
#endregion
// We couldn't find a supported match
return FileTypes.UNKNOWN;
}
/// <summary>
/// Create an instance of a scannable based on file type
/// </summary>
public static IScannable CreateScannable(FileTypes fileType)
{
switch (fileType)
{
case FileTypes.BFPK: return new FileType.BFPK();
case FileTypes.BZip2: return new FileType.BZip2();
case FileTypes.Executable: return new FileType.Executable();
case FileTypes.GZIP: return new FileType.GZIP();
//case FileTypes.IniFile: return new FileType.IniFile();
case FileTypes.InstallShieldArchiveV3: return new FileType.InstallShieldArchiveV3();
case FileTypes.InstallShieldCAB: return new FileType.InstallShieldCAB();
case FileTypes.MicrosoftCAB: return new FileType.MicrosoftCAB();
case FileTypes.MPQ: return new FileType.MPQ();
case FileTypes.MSI: return new FileType.MSI();
case FileTypes.PKZIP: return new FileType.PKZIP();
case FileTypes.PLJ: return new FileType.PLJ();
case FileTypes.RAR: return new FileType.RAR();
case FileTypes.SevenZip: return new FileType.SevenZip();
case FileTypes.TapeArchive: return new FileType.TapeArchive();
case FileTypes.Textfile: return new FileType.Textfile();
case FileTypes.Valve: return new FileType.Valve();
case FileTypes.XZ: return new FileType.XZ();
default: return null;
}
}
#endregion
#region Processed Executable Information
/// <summary>
@@ -286,15 +797,6 @@ namespace BurnOutSharp.Tools
#region Wrappers for Matchers
/// <summary>
/// Wrapper for GetInternalVersion for use in content matching
/// </summary>
/// <param name="file">File to check for version</param>
/// <param name="fileContent">Byte array representing the file contents</param>
/// <param name="positions">Last matched positions in the contents</param>
/// <returns>Version string, null on error</returns>
public static string GetInternalVersion(string file, byte[] fileContent, List<int> positions) => GetInternalVersion(file);
/// <summary>
/// Wrapper for GetInternalVersion for use in path matching
/// </summary>