mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-17 13:55:36 +00:00
Make archives use full scan, not just content
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
@@ -88,7 +89,9 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
}
|
||||
|
||||
string protection = ProtectionFind.ScanContent(tempFile, includePosition);
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.Compressors.BZip2;
|
||||
|
||||
@@ -31,18 +32,20 @@ namespace BurnOutSharp.FileType
|
||||
// If an individual entry fails
|
||||
try
|
||||
{
|
||||
string tempfile = Path.Combine(tempPath, Guid.NewGuid().ToString());
|
||||
using (FileStream fs = File.OpenWrite(tempfile))
|
||||
string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
|
||||
using (FileStream fs = File.OpenWrite(tempFile))
|
||||
{
|
||||
bz2File.CopyTo(fs);
|
||||
}
|
||||
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.GZip;
|
||||
|
||||
@@ -37,14 +38,17 @@ namespace BurnOutSharp.FileType
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
string tempfile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnshieldSharp;
|
||||
|
||||
@@ -50,7 +51,9 @@ namespace BurnOutSharp.FileType
|
||||
string tempFile = Path.Combine(tempPath, cabfile.FileName(i));
|
||||
if (cabfile.FileSave(i, tempFile))
|
||||
{
|
||||
string protection = ProtectionFind.ScanContent(tempFile, includePosition);
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using StormLibSharp;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -44,15 +45,18 @@ namespace BurnOutSharp.FileType
|
||||
// If an individual entry fails
|
||||
try
|
||||
{
|
||||
string tempfile = Path.Combine(tempPath, sub);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(tempfile));
|
||||
mpqArchive.ExtractFile(sub, tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, sub);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
|
||||
mpqArchive.ExtractFile(sub, tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LibMSPackN;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -33,14 +34,17 @@ namespace BurnOutSharp.FileType
|
||||
// If an individual entry fails
|
||||
try
|
||||
{
|
||||
string tempfile = Path.Combine(tempPath, sub.Filename);
|
||||
sub.ExtractTo(tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, sub.Filename);
|
||||
sub.ExtractTo(tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Zip;
|
||||
|
||||
@@ -46,14 +47,17 @@ namespace BurnOutSharp.FileType
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
string tempfile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Rar;
|
||||
|
||||
@@ -42,14 +43,17 @@ namespace BurnOutSharp.FileType
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
string tempfile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.SevenZip;
|
||||
|
||||
@@ -37,14 +38,17 @@ namespace BurnOutSharp.FileType
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
string tempfile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Tar;
|
||||
|
||||
@@ -40,14 +41,17 @@ namespace BurnOutSharp.FileType
|
||||
if (entry.IsDirectory)
|
||||
continue;
|
||||
|
||||
string tempfile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempfile);
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
string tempFile = Path.Combine(tempPath, entry.Key);
|
||||
entry.WriteToFile(tempFile);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using HLExtract.Net;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -55,7 +56,9 @@ namespace BurnOutSharp.FileType
|
||||
{
|
||||
foreach (string tempFile in Directory.EnumerateFiles(tempPath, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
string protection = ProtectionFind.ScanContent(tempFile, includePosition);
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Compressors.Xz;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -30,18 +31,20 @@ namespace BurnOutSharp.FileType
|
||||
// If an individual entry fails
|
||||
try
|
||||
{
|
||||
string tempfile = Path.Combine(tempPath, Guid.NewGuid().ToString());
|
||||
using (FileStream fs = File.OpenWrite(tempfile))
|
||||
string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString());
|
||||
using (FileStream fs = File.OpenWrite(tempFile))
|
||||
{
|
||||
xzFile.CopyTo(fs);
|
||||
}
|
||||
|
||||
string protection = ProtectionFind.ScanContent(tempfile, includePosition);
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempfile);
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace BurnOutSharp
|
||||
{
|
||||
public static class ProtectionFind
|
||||
{
|
||||
/// <summary>
|
||||
/// Progress indicator
|
||||
/// </summary>
|
||||
private static IProgress<FileProtection> FileProgress = null;
|
||||
|
||||
/// <summary>
|
||||
/// Scan a path to find any known copy protection(s)
|
||||
/// </summary>
|
||||
@@ -35,12 +40,18 @@ namespace BurnOutSharp
|
||||
/// <param name="includePosition">True to include scanned copy protection position, false otherwise (default)</param>
|
||||
/// <param name="progress">Optional progress indicator that will return a float in the range from 0 to 1</param>
|
||||
/// <returns>Dictionary of filename to protection mappings, if possible</returns>
|
||||
/// TODO: For all of the archives that use this, ensure that they scan the temp extraction directory, if applicable
|
||||
public static Dictionary<string, string> Scan(string path, bool includePosition = false, IProgress<FileProtection> progress = null)
|
||||
{
|
||||
// Set the progress indicator, if it's not set already
|
||||
if (FileProgress == null)
|
||||
FileProgress = progress;
|
||||
|
||||
// Initialize the protections dictionary
|
||||
var protections = new Dictionary<string, string>();
|
||||
|
||||
// Checkpoint
|
||||
progress?.Report(new FileProtection(null, 0, null));
|
||||
FileProgress?.Report(new FileProtection(null, 0, null));
|
||||
|
||||
// If we have a file
|
||||
if (File.Exists(path))
|
||||
@@ -61,7 +72,7 @@ namespace BurnOutSharp
|
||||
}
|
||||
|
||||
// Checkpoint
|
||||
progress?.Report(new FileProtection(path, 1, contentProtection));
|
||||
FileProgress?.Report(new FileProtection(path, 1, contentProtection));
|
||||
}
|
||||
// If we have a directory
|
||||
else if (Directory.Exists(path))
|
||||
@@ -96,7 +107,7 @@ namespace BurnOutSharp
|
||||
}
|
||||
|
||||
// Checkpoint
|
||||
progress?.Report(new FileProtection(file, i / (float)files.Count(), contentProtection));
|
||||
FileProgress?.Report(new FileProtection(file, i / (float)files.Count(), contentProtection));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Wise = WiseUnpacker.WiseUnpacker;
|
||||
|
||||
namespace BurnOutSharp.ProtectionType
|
||||
@@ -40,7 +41,9 @@ namespace BurnOutSharp.ProtectionType
|
||||
|
||||
foreach (string tempFile in Directory.EnumerateFiles(tempPath, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
string protection = ProtectionFind.ScanContent(tempFile, includePosition);
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Test
|
||||
p.ProgressChanged += Changed;
|
||||
foreach (string arg in args)
|
||||
{
|
||||
string protections = String.Join("\r\n", ProtectionFind.Scan(arg, true, p).Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
|
||||
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")))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user