Pass-thru scanner, better return types

This commit is contained in:
Matt Nadareski
2020-10-31 14:00:31 -07:00
parent df90583f73
commit 81f0400790
20 changed files with 829 additions and 892 deletions

View File

@@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the BFPK file itself fails
try
@@ -25,14 +25,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
br.ReadBytes(4); // Skip magic number
@@ -101,7 +93,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the 7-zip file itself fails
try
@@ -25,14 +25,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (BZip2Stream bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true))
{
// If an individual entry fails
@@ -48,7 +40,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -41,7 +41,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static List<string> Scan(Stream stream, string file = null, bool includePosition = false)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream, string file = null)
{
// Load the current file content
byte[] fileContent = null;
@@ -55,191 +55,191 @@ namespace BurnOutSharp.FileType
stream.Seek(0, SeekOrigin.Begin);
// Files can be protected in multiple ways
List<string> protections = new List<string>();
List<string> subProtections = new List<string>();
var protections = new Dictionary<string, List<string>>();
var subProtections = new Dictionary<string, List<string>>();
string protection;
#region Protections
// 3PLock
protection = ThreePLock.CheckContents(fileContent, includePosition);
protection = ThreePLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// 321Studios Online Activation
protection = ThreeTwoOneStudios.CheckContents(fileContent, includePosition);
protection = ThreeTwoOneStudios.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// ActiveMARK
protection = ActiveMARK.CheckContents(fileContent, includePosition);
protection = ActiveMARK.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Alpha-ROM
protection = AlphaROM.CheckContents(fileContent, includePosition);
protection = AlphaROM.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Cactus Data Shield
protection = CactusDataShield.CheckContents(fileContent, includePosition);
protection = CactusDataShield.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// CD-Cops
protection = CDCops.CheckContents(fileContent, includePosition);
protection = CDCops.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// CD-Lock
protection = CDLock.CheckContents(fileContent, includePosition);
protection = CDLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// CDSHiELD SE
protection = CDSHiELDSE.CheckContents(fileContent, includePosition);
protection = CDSHiELDSE.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// CD Check
protection = CDCheck.CheckContents(fileContent, includePosition);
protection = CDCheck.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Cenega ProtectDVD
protection = CengaProtectDVD.CheckContents(fileContent, includePosition);
protection = CengaProtectDVD.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Code Lock
protection = CodeLock.CheckContents(fileContent, includePosition);
protection = CodeLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// CopyKiller
protection = CopyKiller.CheckContents(fileContent, includePosition);
protection = CopyKiller.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// DVD-Cops
protection = DVDCops.CheckContents(fileContent, includePosition);
protection = DVDCops.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// EA Protections
protection = ElectronicArts.CheckContents(file, fileContent, includePosition);
protection = ElectronicArts.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Games for Windows - Live
protection = GFWL.CheckContents(fileContent, includePosition);
protection = GFWL.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Impulse Reactor
protection = ImpulseReactor.CheckContents(file, fileContent, includePosition);
protection = ImpulseReactor.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Inno Setup
protection = InnoSetup.CheckContents(fileContent, includePosition);
protection = InnoSetup.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// JoWooD X-Prot
protection = JoWooDXProt.CheckContents(fileContent, includePosition);
protection = JoWooDXProt.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Key-Lock (Dongle)
protection = KeyLock.CheckContents(fileContent, includePosition);
protection = KeyLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// LaserLock
protection = LaserLock.CheckContents(file, fileContent, includePosition);
protection = LaserLock.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// ProtectDisc
protection = ProtectDisc.CheckContents(file, fileContent, includePosition);
protection = ProtectDisc.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Ring PROTECH
protection = RingPROTECH.CheckContents(fileContent, includePosition);
protection = RingPROTECH.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// SafeDisc / SafeCast
protection = SafeDisc.CheckContents(file, fileContent, includePosition);
protection = SafeDisc.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// SafeLock
protection = SafeLock.CheckContents(fileContent, includePosition);
protection = SafeLock.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// SecuROM
protection = SecuROM.CheckContents(file, fileContent, includePosition);
protection = SecuROM.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// SmartE
protection = SmartE.CheckContents(fileContent, includePosition);
protection = SmartE.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// SolidShield
protection = SolidShield.CheckContents(file, fileContent, includePosition);
protection = SolidShield.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// StarForce
protection = StarForce.CheckContents(file, fileContent, includePosition);
protection = StarForce.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// SVK Protector
protection = SVKProtector.CheckContents(fileContent, includePosition);
protection = SVKProtector.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Sysiphus / Sysiphus DVD
protection = Sysiphus.CheckContents(fileContent, includePosition);
protection = Sysiphus.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// TAGES
protection = Tages.CheckContents(file, fileContent, includePosition);
protection = Tages.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// VOB ProtectCD/DVD
protection = VOBProtectCDDVD.CheckContents(file, fileContent, includePosition);
protection = VOBProtectCDDVD.CheckContents(file, fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Wise Installer
subProtections = WiseInstaller.CheckContents(file, fileContent, includePosition);
subProtections = WiseInstaller.CheckContents(scanner, file, fileContent);
if (subProtections != null && subProtections.Count > 0)
protections.AddRange(subProtections);
Utilities.AppendToDictionary(protections, subProtections);
// WTM CD Protect
protection = WTMCDProtect.CheckContents(fileContent, includePosition);
protection = WTMCDProtect.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// XCP 1/2
protection = XCP.CheckContents(fileContent, includePosition);
protection = XCP.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// Xtreme-Protector
protection = XtremeProtector.CheckContents(fileContent, includePosition);
protection = XtremeProtector.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
#endregion
@@ -247,34 +247,34 @@ namespace BurnOutSharp.FileType
#region Packers
// Armadillo
protection = Armadillo.CheckContents(fileContent, includePosition);
protection = Armadillo.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// dotFuscator
protection = dotFuscator.CheckContents(fileContent, includePosition);
protection = dotFuscator.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// EXE Stealth
protection = EXEStealth.CheckContents(fileContent, includePosition);
protection = EXEStealth.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// NSIS
protection = NSIS.CheckContents(fileContent, includePosition);
protection = NSIS.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// PE Compact
protection = PECompact.CheckContents(fileContent, includePosition);
protection = PECompact.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
// UPX
protection = UPX.CheckContents(fileContent, includePosition);
protection = UPX.CheckContents(fileContent, scanner.IncludePosition);
if (!string.IsNullOrWhiteSpace(protection))
protections.Add(protection);
Utilities.AppendToDictionary(protections, file, protection);
#endregion

View File

@@ -16,7 +16,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the gzip file itself fails
try
@@ -24,14 +24,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (GZipArchive zipFile = GZipArchive.Open(stream))
{
foreach (var entry in zipFile.Entries)
@@ -51,7 +43,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -17,7 +17,7 @@ namespace BurnOutSharp.FileType
}
// TODO: Add stream opening support
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
public static Dictionary<string, List<string>> Scan(Scanner scanner, string file)
{
// Get the name of the first cabinet file or header
string directory = Path.GetDirectoryName(file);
@@ -39,14 +39,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
UnshieldCabinet cabfile = UnshieldCabinet.Open(file);
for (int i = 0; i < cabfile.FileCount; i++)
{
@@ -60,7 +52,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -16,7 +16,7 @@ namespace BurnOutSharp.FileType
}
// TODO: Add stream opening support
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
public static Dictionary<string, List<string>> Scan(Scanner scanner, string file)
{
// If the mpq file itself fails
try
@@ -24,14 +24,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read))
{
string listfile = null;
@@ -59,7 +51,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -16,7 +16,7 @@ namespace BurnOutSharp.FileType
}
// TODO: Add stream opening support
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
public static Dictionary<string, List<string>> Scan(Scanner scanner, string file)
{
// If the MSI file itself fails
try
@@ -24,21 +24,13 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (Database msidb = new Database(file, DatabaseOpenMode.ReadOnly))
{
msidb.ExportAll(tempPath);
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -16,7 +16,7 @@ namespace BurnOutSharp.FileType
}
// TODO: Add stream opening support
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
public static Dictionary<string, List<string>> Scan(Scanner scanner, string file)
{
// If the cab file itself fails
try
@@ -24,14 +24,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (MSCabinet cabfile = new MSCabinet(file))
{
foreach (var sub in cabfile.GetFiles())
@@ -47,7 +39,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -25,7 +25,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the zip file itself fails
try
@@ -33,14 +33,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (ZipArchive zipFile = ZipArchive.Open(stream))
{
foreach (var entry in zipFile.Entries)
@@ -60,7 +52,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
@@ -22,7 +21,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the rar file itself fails
try
@@ -30,14 +29,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (RarArchive zipFile = RarArchive.Open(stream))
{
foreach (var entry in zipFile.Entries)
@@ -57,7 +48,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -16,7 +16,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the 7-zip file itself fails
try
@@ -24,14 +24,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream))
{
foreach (var entry in sevenZipFile.Entries)
@@ -50,7 +42,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -19,7 +19,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the tar file itself fails
try
@@ -27,14 +27,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (TarArchive tarFile = TarArchive.Open(stream))
{
foreach (var entry in tarFile.Entries)
@@ -54,7 +46,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -32,7 +32,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static List<string> Scan(Stream stream, bool includePosition = false)
public static List<string> Scan(Stream stream)
{
List<string> protections = new List<string>();

View File

@@ -33,19 +33,11 @@ namespace BurnOutSharp.FileType
}
// TODO: Add stream opening support
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
public static Dictionary<string, List<string>> Scan(Scanner scanner, string file)
{
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
string[] args = new string[]
{
"-p", file,
@@ -58,7 +50,7 @@ namespace BurnOutSharp.FileType
HLExtractProgram.Process(args);
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

View File

@@ -15,7 +15,7 @@ namespace BurnOutSharp.FileType
return false;
}
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
public static Dictionary<string, List<string>> Scan(Scanner scanner, Stream stream)
{
// If the xz file itself fails
try
@@ -23,14 +23,6 @@ namespace BurnOutSharp.FileType
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create a new scanner for the new temp path
Scanner subScanner = new Scanner(parentScanner.FileProgress)
{
IncludePosition = parentScanner.IncludePosition,
ScanAllFiles = parentScanner.ScanAllFiles,
ScanArchives = parentScanner.ScanArchives,
};
using (XZStream xzFile = new XZStream(stream))
{
// If an individual entry fails
@@ -46,7 +38,7 @@ namespace BurnOutSharp.FileType
}
// Collect and format all found protections
var protections = subScanner.GetProtections(tempPath);
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Wise = WiseUnpacker.WiseUnpacker;
namespace BurnOutSharp.ProtectionType
{
public class WiseInstaller
{
public static List<string> CheckContents(string file, byte[] fileContent, bool includePosition = false)
public static Dictionary<string, List<string>> CheckContents(Scanner scanner, string file, byte[] fileContent)
{
// "WiseMain"
// WiseMain
byte[] check = new byte[] { 0x57, 0x69, 0x73, 0x65, 0x4D, 0x61, 0x69, 0x6E };
if (fileContent.Contains(check, out int position))
{
List<string> protections = new List<string> { "Wise Installation Wizard Module" + (includePosition ? $" (Index {position})" : string.Empty) };
if (!File.Exists(file))
Dictionary<string, List<string>> protections = new Dictionary<string, List<string>>
{
[file ?? "NO FILENAME"] = new List<string> { "Wise Installation Wizard Module" + (scanner.IncludePosition ? $" (Index {position})" : string.Empty) },
};
if (file == null || !File.Exists(file))
return protections;
protections.AddRange(WiseInstaller.Scan(file, includePosition));
var subProtections = Scan(scanner, file);
Utilities.AppendToDictionary(protections, subProtections);
return protections;
}
@@ -26,10 +30,8 @@ namespace BurnOutSharp.ProtectionType
return null;
}
public static List<string> Scan(string file, bool includePosition = false)
public static Dictionary<string, List<string>> Scan(Scanner scanner, string file)
{
List<string> protections = new List<string>();
// If the installer file itself fails
try
{
@@ -40,7 +42,7 @@ namespace BurnOutSharp.ProtectionType
unpacker.ExtractTo(file, tempPath);
// Collect and format all found protections
var protections = subScanner.GetProtections();
var protections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try
@@ -48,10 +50,12 @@ namespace BurnOutSharp.ProtectionType
Directory.Delete(tempPath, true);
}
catch { }
return protections;
}
catch { }
return protections;
return null;
}
}

View File

@@ -8,7 +8,6 @@ using BurnOutSharp.ProtectionType;
namespace BurnOutSharp
{
// TODO: Use the file progress everywhere
// TODO: Re-enable direct stream scanning
// TODO: Should FileTypes be exposed directly as well so the scans can be exposed easier?
public class Scanner
{
@@ -61,6 +60,13 @@ namespace BurnOutSharp
if (paths == null || !paths.Any())
return null;
// Checkpoint
FileProgress?.Report(new FileProtection(null, 0, null));
// Temp variables for reporting
string tempFilePath = Path.GetTempPath();
string tempFilePathWithGuid = Path.Combine(tempFilePath, Guid.NewGuid().ToString());
// Loop through each path and get the returned values
var protections = new Dictionary<string, List<string>>();
foreach (string path in paths)
@@ -73,32 +79,25 @@ namespace BurnOutSharp
// Scan for path-detectable protections
var directoryPathProtections = GetPathProtections(path, files);
if (directoryPathProtections != null && directoryPathProtections.Any())
{
foreach (string key in directoryPathProtections.Keys)
{
if (!protections.ContainsKey(key))
protections[key] = new List<string>();
protections[key].AddRange(directoryPathProtections[key]);
}
}
Utilities.AppendToDictionary(protections, directoryPathProtections);
// Scan each file in directory separately
foreach (string file in files)
for (int i = 0; i < files.Count(); i++)
{
// Get the current file
string file = files.ElementAt(i);
// Get the reportable file name
string reportableFileName = file;
if (reportableFileName.StartsWith(tempFilePath))
reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length);
// Checkpoint
FileProgress?.Report(new FileProtection(reportableFileName, i / (float)files.Count(), "Checking file" + (file != reportableFileName ? " from archive" : string.Empty)));
// Scan for path-detectable protections
var filePathProtections = GetPathProtections(file);
if (filePathProtections != null && filePathProtections.Any())
{
foreach (string key in filePathProtections.Keys)
{
if (!protections.ContainsKey(key))
protections[key] = new List<string>();
protections[key].AddRange(filePathProtections[key]);
}
}
Utilities.AppendToDictionary(protections, filePathProtections);
// Scan for content-detectable protections
var fileProtections = GetInternalProtections(file);
@@ -112,24 +111,28 @@ namespace BurnOutSharp
protections[key].AddRange(fileProtections[key]);
}
}
}
// Checkpoint
protections.TryGetValue(file, out List<string> fullProtectionList);
string fullProtection = (fullProtectionList != null && fullProtectionList.Any() ? string.Join(", ", fullProtectionList) : null);
FileProgress?.Report(new FileProtection(reportableFileName, (i + 1) / (float)files.Count(), fullProtection ?? string.Empty));
}
}
// Scan a single file by itself
else if (File.Exists(path))
{
// Get the reportable file name
string reportableFileName = path;
if (reportableFileName.StartsWith(tempFilePath))
reportableFileName = reportableFileName.Substring(tempFilePathWithGuid.Length);
// Checkpoint
FileProgress?.Report(new FileProtection(reportableFileName, 0, "Checking file" + (path != reportableFileName ? " from archive" : string.Empty)));
// Scan for path-detectable protections
var filePathProtections = GetPathProtections(path);
if (filePathProtections != null && filePathProtections.Any())
{
foreach (string key in filePathProtections.Keys)
{
if (!protections.ContainsKey(key))
protections[key] = new List<string>();
protections[key].AddRange(filePathProtections[key]);
}
}
Utilities.AppendToDictionary(protections, filePathProtections);
// Scan for content-detectable protections
var fileProtections = GetInternalProtections(path);
@@ -143,12 +146,17 @@ namespace BurnOutSharp
protections[key].AddRange(fileProtections[key]);
}
}
// Checkpoint
protections.TryGetValue(path, out List<string> fullProtectionList);
string fullProtection = (fullProtectionList != null && fullProtectionList.Any() ? string.Join(", ", fullProtectionList) : null);
FileProgress?.Report(new FileProtection(reportableFileName, 1, fullProtection ?? string.Empty));
}
// Throw on an invalid path
else
{
throw new FileNotFoundException($"{path} is not a directory or file, skipping...");
// throw new FileNotFoundException($"{path} is not a directory or file, skipping...");
}
}
@@ -428,21 +436,15 @@ namespace BurnOutSharp
// Executable
if (ScanAllFiles || Executable.ShouldScan(magic))
{
var subProtections = Executable.Scan(fs, file, IncludePosition);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
var subProtections = Executable.Scan(this, fs, file);
Utilities.AppendToDictionary(protections, subProtections);
}
// Text-based files
if (ScanAllFiles || Textfile.ShouldScan(magic, extension))
{
var subProtections = Executable.Scan(fs, file, IncludePosition);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
var subProtections = Textfile.Scan(fs);
Utilities.AppendToDictionary(protections, file, subProtections);
}
#endregion
@@ -457,130 +459,91 @@ namespace BurnOutSharp
if (SevenZip.ShouldScan(magic))
{
var subProtections = SevenZip.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// BFPK archive
if (BFPK.ShouldScan(magic))
{
var subProtections = BFPK.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// BZip2
if (BZip2.ShouldScan(magic))
{
var subProtections = BZip2.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// GZIP
if (GZIP.ShouldScan(magic))
{
var subProtections = GZIP.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// InstallShield Cabinet
if (file != null && InstallShieldCAB.ShouldScan(magic))
{
var subProtections = InstallShieldCAB.Scan(this, file);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// Microsoft Cabinet
if (file != null && MicrosoftCAB.ShouldScan(magic))
{
var subProtections = MicrosoftCAB.Scan(this, file);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// MSI
if (file != null && MSI.ShouldScan(magic))
{
var subProtections = MSI.Scan(this, file);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// MPQ archive
if (file != null && MPQ.ShouldScan(magic))
{
var subProtections = MPQ.Scan(this, file);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// PKZIP archive (and derivatives)
if (PKZIP.ShouldScan(magic))
{
var subProtections = PKZIP.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// RAR archive
if (RAR.ShouldScan(magic))
{
var subProtections = RAR.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// Tape Archive
if (TapeArchive.ShouldScan(magic))
{
var subProtections = TapeArchive.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// Valve archive formats
if (file != null && Valve.ShouldScan(magic))
{
var subProtections = Valve.Scan(this, file);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
// XZ
if (XZ.ShouldScan(magic))
{
var subProtections = XZ.Scan(this, fs);
if (!protections.ContainsKey(file))
protections[file] = new List<string>();
protections[file] = subProtections;
Utilities.AppendToDictionary(protections, subProtections);
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
@@ -7,7 +8,7 @@ using System.Threading;
namespace BurnOutSharp
{
public static class Utilities
internal static class Utilities
{
/// <summary>
/// Search for a byte array in another array
@@ -109,6 +110,60 @@ namespace BurnOutSharp
return fsName;
}
/// <summary>
/// Append one result to a results dictionary
/// </summary>
/// <param name="original">Dictionary to append to</param>
/// <param name="key">Key to add information to</param>
/// <param name="value">String value to add</param>
public static void AppendToDictionary(Dictionary<string, List<string>> original, string key, string value)
{
AppendToDictionary(original, key, new List<string> { value });
}
/// <summary>
/// Append one result to a results dictionary
/// </summary>
/// <param name="original">Dictionary to append to</param>
/// <param name="key">Key to add information to</param>
/// <param name="value">String value to add</param>
public static void AppendToDictionary(Dictionary<string, List<string>> original, string key, List<string> values)
{
// If the dictionary is null, just return
if (original == null)
return;
// Use a placeholder value if the key is null
key = key ?? "NO FILENAME";
// Add the key if needed and then append the lists
if (!original.ContainsKey(key))
original[key] = new List<string>();
original[key].AddRange(values);
}
/// <summary>
/// Append one results dictionary to another
/// </summary>
/// <param name="original">Dictionary to append to</param>
/// <param name="addition">Dictionary to pull from</param>
public static void AppendToDictionary(Dictionary<string, List<string>> original, Dictionary<string, List<string>> addition)
{
// If either dictionary is missing, just return
if (original == null || addition == null)
return;
// Loop through each of the addition keys and add accordingly
foreach (string key in addition.Keys)
{
if (!original.ContainsKey(key))
original[key] = new List<string>();
original[key].AddRange(addition[key]);
}
}
#region P/Invoke
// https://stackoverflow.com/questions/8819188/c-sharp-classes-to-undelete-files/8820157#8820157

View File

@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Linq;
using BurnOutSharp;
namespace Test
@@ -9,15 +8,36 @@ namespace Test
{
static void Main(string[] args)
{
// Create progress indicator
var p = new Progress<FileProtection>();
p.ProgressChanged += Changed;
// Create scanner to be shared
var scanner = new Scanner(p)
{
IncludePosition = true,
ScanAllFiles = false,
ScanArchives = true,
};
foreach (string arg in args)
{
string protections = string.Join("\r\n", ProtectionFind.Scan(arg, true, p).Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
Console.WriteLine(protections);
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
var protections = scanner.GetProtections(arg);
if (protections != null)
{
sw.WriteLine(protections);
using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
{
foreach (string key in protections.Keys)
{
string line = $"{key}: {string.Join(", ", protections[key])}";
Console.WriteLine(line);
sw.WriteLine(line);
}
}
}
else
{
Console.WriteLine($"No protections found for {arg}");
}
}