mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-08 18:06:34 +00:00
Scanner shouldn't include path intrinsically
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SharpCompress.Compressors;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
@@ -18,10 +17,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the BFPK file itself fails
|
||||
try
|
||||
{
|
||||
@@ -29,7 +26,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -104,8 +101,7 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
@@ -113,10 +109,12 @@ namespace BurnOutSharp.FileType
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the 7-zip file itself fails
|
||||
try
|
||||
{
|
||||
@@ -28,7 +26,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -45,34 +43,25 @@ namespace BurnOutSharp.FileType
|
||||
{
|
||||
bz2File.CopyTo(fs);
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (!string.IsNullOrEmpty(protection))
|
||||
protections.Add($"\r\n{protection}");
|
||||
}
|
||||
catch { }
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.GZip;
|
||||
|
||||
@@ -17,10 +16,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the gzip file itself fails
|
||||
try
|
||||
{
|
||||
@@ -28,7 +25,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -48,35 +45,26 @@ namespace BurnOutSharp.FileType
|
||||
|
||||
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.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (!string.IsNullOrEmpty(protection))
|
||||
protections.Add($"\r\n{entry.Key} - {protection}");
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnshieldSharp;
|
||||
|
||||
@@ -18,10 +17,8 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// TODO: Add stream opening support
|
||||
public static List<string> Scan(Scanner parentScanner, string file, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// Get the name of the first cabinet file or header
|
||||
string directory = Path.GetDirectoryName(file);
|
||||
string noExtension = Path.GetFileNameWithoutExtension(file);
|
||||
@@ -43,7 +40,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -63,8 +60,7 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
@@ -72,11 +68,13 @@ namespace BurnOutSharp.FileType
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using StormLibSharp;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -17,10 +16,8 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// TODO: Add stream opening support
|
||||
public static List<string> Scan(Scanner parentScanner, string file, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the mpq file itself fails
|
||||
try
|
||||
{
|
||||
@@ -28,7 +25,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -59,22 +56,23 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LibMSPackN;
|
||||
using Microsoft.Deployment.WindowsInstaller;
|
||||
using Microsoft.Deployment.WindowsInstaller.Package;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
{
|
||||
@@ -21,10 +16,8 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// TODO: Add stream opening support
|
||||
public static List<string> Scan(Scanner parentScanner, string file, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the MSI file itself fails
|
||||
try
|
||||
{
|
||||
@@ -32,7 +25,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -45,8 +38,7 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
@@ -54,10 +46,12 @@ namespace BurnOutSharp.FileType
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LibMSPackN;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -17,10 +16,8 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// TODO: Add stream opening support
|
||||
public static List<string> Scan(Scanner parentScanner, string file, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the cab file itself fails
|
||||
try
|
||||
{
|
||||
@@ -28,7 +25,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -50,8 +47,7 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
@@ -59,10 +55,12 @@ namespace BurnOutSharp.FileType
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Zip;
|
||||
|
||||
@@ -26,10 +25,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the zip file itself fails
|
||||
try
|
||||
{
|
||||
@@ -37,7 +34,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -60,22 +57,23 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the rar file itself fails
|
||||
try
|
||||
{
|
||||
@@ -33,7 +31,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -56,22 +54,23 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.SevenZip;
|
||||
|
||||
@@ -17,10 +16,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the 7-zip file itself fails
|
||||
try
|
||||
{
|
||||
@@ -28,7 +25,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -53,8 +50,7 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
@@ -62,11 +58,13 @@ namespace BurnOutSharp.FileType
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Tar;
|
||||
|
||||
@@ -20,10 +19,8 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the tar file itself fails
|
||||
try
|
||||
{
|
||||
@@ -31,7 +28,7 @@ namespace BurnOutSharp.FileType
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create a new scanner for the new temp path
|
||||
Scanner subScanner = new Scanner(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -54,22 +51,23 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using HLExtract.Net;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -34,15 +33,13 @@ namespace BurnOutSharp.FileType
|
||||
}
|
||||
|
||||
// TODO: Add stream opening support
|
||||
public static List<string> Scan(Scanner parentScanner, string file, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, string file)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
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(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -61,8 +58,7 @@ namespace BurnOutSharp.FileType
|
||||
HLExtractProgram.Process(args);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Compressors.Xz;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
@@ -16,18 +15,16 @@ namespace BurnOutSharp.FileType
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<string> Scan(Scanner parentScanner, Stream stream, bool includePosition = false)
|
||||
public static Dictionary<string, List<string>> Scan(Scanner parentScanner, Stream stream)
|
||||
{
|
||||
List<string> protections = new List<string>();
|
||||
|
||||
// If the 7-zip file itself fails
|
||||
// If the xz file itself fails
|
||||
try
|
||||
{
|
||||
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(tempPath, parentScanner.FileProgress)
|
||||
Scanner subScanner = new Scanner(parentScanner.FileProgress)
|
||||
{
|
||||
IncludePosition = parentScanner.IncludePosition,
|
||||
ScanAllFiles = parentScanner.ScanAllFiles,
|
||||
@@ -44,34 +41,25 @@ namespace BurnOutSharp.FileType
|
||||
{
|
||||
xzFile.CopyTo(fs);
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempFile, includePosition);
|
||||
string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()));
|
||||
|
||||
// If tempfile cleanup fails
|
||||
try
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (!string.IsNullOrEmpty(protection))
|
||||
protections.Add($"\r\n{protection}");
|
||||
}
|
||||
catch { }
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = subScanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return protections;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ namespace BurnOutSharp.ProtectionType
|
||||
unpacker.ExtractTo(file, tempPath);
|
||||
|
||||
// Collect and format all found protections
|
||||
var fileProtections = ProtectionFind.Scan(tempPath, includePosition);
|
||||
protections = fileProtections.Select(kvp => kvp.Key.Substring(tempPath.Length) + ": " + kvp.Value.TrimEnd()).ToList();
|
||||
var protections = subScanner.GetProtections();
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
|
||||
@@ -17,11 +17,6 @@ namespace BurnOutSharp
|
||||
/// </summary>
|
||||
public IProgress<FileProtection> FileProgress { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// List of paths that will be scanned with this object
|
||||
/// </summary>
|
||||
public List<string> Paths { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the byte position of found protection is included or not
|
||||
/// </summary>
|
||||
@@ -40,39 +35,35 @@ namespace BurnOutSharp
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="path">Path to create a scanner for</param>
|
||||
/// <param name="fileProgress">Optional progress callback</param>
|
||||
public Scanner(string path, IProgress<FileProtection> fileProgress = null)
|
||||
public Scanner(IProgress<FileProtection> fileProgress = null)
|
||||
{
|
||||
Paths = new List<string> { path };
|
||||
FileProgress = fileProgress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// Scan a single path and get all found protections
|
||||
/// </summary>
|
||||
/// <param name="paths">Paths to create a scanner for</param>
|
||||
/// <param name="fileProgress">Optional progress callback</param>
|
||||
public Scanner(List<string> paths, IProgress<FileProtection> fileProgress = null)
|
||||
/// <param name="path">Path to scan</param>
|
||||
/// <returns>Dictionary of list of strings representing the found protections</returns>
|
||||
public Dictionary<string, List<string>> GetProtections(string path)
|
||||
{
|
||||
Paths = paths;
|
||||
FileProgress = fileProgress;
|
||||
return GetProtections(new List<string> { path });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scan the list of paths and get all found protections
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of list of strings representing the found protections</returns>
|
||||
/// TODO: Should this populate an internal field instead of returning?
|
||||
public Dictionary<string, List<string>> GetProtections()
|
||||
public Dictionary<string, List<string>> GetProtections(List<string> paths)
|
||||
{
|
||||
// If we have no paths, we can't scan
|
||||
if (Paths == null || !Paths.Any())
|
||||
if (paths == null || !paths.Any())
|
||||
return null;
|
||||
|
||||
// Loop through each path and get the returned values
|
||||
var protections = new Dictionary<string, List<string>>();
|
||||
foreach (string path in Paths)
|
||||
foreach (string path in paths)
|
||||
{
|
||||
// Directories scan each internal file individually
|
||||
if (Directory.Exists(path))
|
||||
@@ -459,13 +450,13 @@ namespace BurnOutSharp
|
||||
#region Archive File Types
|
||||
|
||||
// If we're scanning archives, we have a few to try out
|
||||
// TODO: All archives should return a dictionary instead of a list
|
||||
// TODO: All archives should prefix internal paths properly
|
||||
if (ScanArchives)
|
||||
{
|
||||
// 7-Zip archive
|
||||
if (SevenZip.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = SevenZip.Scan(this, fs, IncludePosition);
|
||||
var subProtections = SevenZip.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -475,7 +466,7 @@ namespace BurnOutSharp
|
||||
// BFPK archive
|
||||
if (BFPK.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = BFPK.Scan(this, fs, IncludePosition);
|
||||
var subProtections = BFPK.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -485,7 +476,7 @@ namespace BurnOutSharp
|
||||
// BZip2
|
||||
if (BZip2.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = BZip2.Scan(this, fs, IncludePosition);
|
||||
var subProtections = BZip2.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -495,7 +486,7 @@ namespace BurnOutSharp
|
||||
// GZIP
|
||||
if (GZIP.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = GZIP.Scan(this, fs, IncludePosition);
|
||||
var subProtections = GZIP.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -505,7 +496,7 @@ namespace BurnOutSharp
|
||||
// InstallShield Cabinet
|
||||
if (file != null && InstallShieldCAB.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = InstallShieldCAB.Scan(this, file, IncludePosition);
|
||||
var subProtections = InstallShieldCAB.Scan(this, file);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -515,7 +506,7 @@ namespace BurnOutSharp
|
||||
// Microsoft Cabinet
|
||||
if (file != null && MicrosoftCAB.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = MicrosoftCAB.Scan(this, file, IncludePosition);
|
||||
var subProtections = MicrosoftCAB.Scan(this, file);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -525,7 +516,7 @@ namespace BurnOutSharp
|
||||
// MSI
|
||||
if (file != null && MSI.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = MSI.Scan(this, file, IncludePosition);
|
||||
var subProtections = MSI.Scan(this, file);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -535,7 +526,7 @@ namespace BurnOutSharp
|
||||
// MPQ archive
|
||||
if (file != null && MPQ.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = MPQ.Scan(this, file, IncludePosition);
|
||||
var subProtections = MPQ.Scan(this, file);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -545,7 +536,7 @@ namespace BurnOutSharp
|
||||
// PKZIP archive (and derivatives)
|
||||
if (PKZIP.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = PKZIP.Scan(this, fs, IncludePosition);
|
||||
var subProtections = PKZIP.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -555,7 +546,7 @@ namespace BurnOutSharp
|
||||
// RAR archive
|
||||
if (RAR.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = RAR.Scan(this, fs, IncludePosition);
|
||||
var subProtections = RAR.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -565,7 +556,7 @@ namespace BurnOutSharp
|
||||
// Tape Archive
|
||||
if (TapeArchive.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = TapeArchive.Scan(this, fs, IncludePosition);
|
||||
var subProtections = TapeArchive.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -575,7 +566,7 @@ namespace BurnOutSharp
|
||||
// Valve archive formats
|
||||
if (file != null && Valve.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = Valve.Scan(this, file, IncludePosition);
|
||||
var subProtections = Valve.Scan(this, file);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
@@ -585,7 +576,7 @@ namespace BurnOutSharp
|
||||
// XZ
|
||||
if (XZ.ShouldScan(magic))
|
||||
{
|
||||
var subProtections = XZ.Scan(this, fs, IncludePosition);
|
||||
var subProtections = XZ.Scan(this, fs);
|
||||
if (!protections.ContainsKey(file))
|
||||
protections[file] = new List<string>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user