Sync IExtractable*Executable implementations

This commit is contained in:
Matt Nadareski
2024-11-04 21:14:06 -05:00
parent 5ec90b290a
commit 92097222b0
34 changed files with 217 additions and 243 deletions

View File

@@ -33,6 +33,9 @@ namespace BinaryObjectScanner.FileType
try
{
using RarArchive rarFile = RarArchive.Open(stream);
if (!rarFile.IsComplete)
return false;
foreach (var entry in rarFile.Entries)
{
try

View File

@@ -32,8 +32,8 @@ namespace BinaryObjectScanner.FileType
#if NET462_OR_GREATER || NETCOREAPP
try
{
using var sevenZipFile = SevenZipArchive.Open(stream);
foreach (var entry in sevenZipFile.Entries)
using var sevenZip = SevenZipArchive.Open(stream);
foreach (var entry in sevenZip.Entries)
{
try
{

View File

@@ -140,17 +140,19 @@ namespace BinaryObjectScanner
try
{
// Extract and get the output path
var tempPath = impl.Extract(fileName, mz, scanner.IncludeDebug);
if (tempPath == null)
return null;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
bool extracted = impl.Extract(fileName, mz, tempPath, scanner.IncludeDebug);
// Collect and format all found protections
var subProtections = scanner.GetProtections(tempPath);
ProtectionDictionary? subProtections = null;
if (extracted)
subProtections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try
{
Directory.Delete(tempPath, true);
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
}
catch (Exception ex)
{
@@ -184,17 +186,19 @@ namespace BinaryObjectScanner
try
{
// Extract and get the output path
var tempPath = impl.Extract(fileName, lex, scanner.IncludeDebug);
if (tempPath == null)
return null;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
bool extracted = impl.Extract(fileName, lex, tempPath, scanner.IncludeDebug);
// Collect and format all found protections
var subProtections = scanner.GetProtections(tempPath);
ProtectionDictionary? subProtections = null;
if (extracted)
subProtections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try
{
Directory.Delete(tempPath, true);
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
}
catch (Exception ex)
{
@@ -228,17 +232,19 @@ namespace BinaryObjectScanner
try
{
// Extract and get the output path
var tempPath = impl.Extract(fileName, nex, scanner.IncludeDebug);
if (tempPath == null)
return null;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
bool extracted = impl.Extract(fileName, nex, tempPath, scanner.IncludeDebug);
// Collect and format all found protections
var subProtections = scanner.GetProtections(tempPath);
ProtectionDictionary? subProtections = null;
if (extracted)
subProtections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try
{
Directory.Delete(tempPath, true);
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
}
catch (Exception ex)
{
@@ -272,17 +278,19 @@ namespace BinaryObjectScanner
try
{
// Extract and get the output path
var tempPath = impl.Extract(fileName, pex, scanner.IncludeDebug);
if (tempPath == null)
return null;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
bool extracted = impl.Extract(fileName, pex, tempPath, scanner.IncludeDebug);
// Collect and format all found protections
var subProtections = scanner.GetProtections(tempPath);
ProtectionDictionary? subProtections = null;
if (extracted)
subProtections = scanner.GetProtections(tempPath);
// If temp directory cleanup fails
try
{
Directory.Delete(tempPath, true);
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
}
catch (Exception ex)
{

View File

@@ -12,8 +12,9 @@ namespace BinaryObjectScanner.Interfaces
/// </summary>
/// <param name="file">Path to the input file</param>
/// <param name="lex">LinearExecutable representing the read-in file</param>
/// <param name="outDir">Path to the output directory</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Path to extracted files, null on error</returns>
string? Extract(string file, LinearExecutable lex, bool includeDebug);
bool Extract(string file, LinearExecutable lex, string outDir, bool includeDebug);
}
}

View File

@@ -12,8 +12,9 @@ namespace BinaryObjectScanner.Interfaces
/// </summary>
/// <param name="file">Path to the input file</param>
/// <param name="mz">MSDOS representing the read-in file</param>
/// <param name="outDir">Path to the output directory</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Path to extracted files, null on error</returns>
string? Extract(string file, MSDOS mz, bool includeDebug);
bool Extract(string file, MSDOS mz, string outDir, bool includeDebug);
}
}

View File

@@ -12,8 +12,9 @@ namespace BinaryObjectScanner.Interfaces
/// </summary>
/// <param name="file">Path to the input file</param>
/// <param name="nex">NewExecutable representing the read-in file</param>
/// <param name="outDir">Path to the output directory</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Path to extracted files, null on error</returns>
string? Extract(string file, NewExecutable nex, bool includeDebug);
bool Extract(string file, NewExecutable nex, string outDir, bool includeDebug);
}
}

View File

@@ -12,8 +12,9 @@ namespace BinaryObjectScanner.Interfaces
/// </summary>
/// <param name="file">Path to the input file</param>
/// <param name="pex">PortableExecutable representing the read-in file</param>
/// <param name="outDir">Path to the output directory</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>Path to extracted files, null on error</returns>
string? Extract(string file, PortableExecutable pex, bool includeDebug);
bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug);
}
}

View File

@@ -51,9 +51,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
/// <summary>

View File

@@ -28,9 +28,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -33,9 +33,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
private string GetVersion(PortableExecutable pex)

View File

@@ -51,14 +51,14 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
try
{
// Get the first resource of type 99 with index 2
var payload = pex.FindResourceByNamedType("99, 2").FirstOrDefault();
if (payload == null || payload.Length == 0)
return null;
return false;
// Determine which compression was used
bool zlib = pex.FindResourceByNamedType("99, 1").Any();
@@ -125,27 +125,25 @@ namespace BinaryObjectScanner.Packer
// If we have no data
if (data == null)
return null;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
return false;
// Create the temp filename
string tempFile = string.IsNullOrEmpty(file) ? "temp.sxe" : $"{Path.GetFileNameWithoutExtension(file)}.sxe";
tempFile = Path.Combine(tempPath, tempFile);
tempFile = Path.Combine(outDir, tempFile);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
// Write the file data to a temp file
using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
tempStream.Write(data, 0, data.Length);
}
var tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
tempStream.Write(data, 0, data.Length);
return tempPath;
return true;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
}
}

View File

@@ -27,9 +27,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -97,10 +97,10 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
// TODO: Add extraction
return null;
return false;
}
}
}

View File

@@ -75,9 +75,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -29,13 +29,13 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
try
{
// If there are no resources
if (pex.ResourceData == null)
return null;
return false;
// Get the resources that have an executable signature
var resources = pex.ResourceData
@@ -44,9 +44,6 @@ namespace BinaryObjectScanner.Packer
.Where(b => b != null && b.StartsWith(SabreTools.Models.MSDOS.Constants.SignatureBytes))
.ToList();
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
for (int i = 0; i < resources.Count; i++)
{
try
@@ -58,7 +55,10 @@ namespace BinaryObjectScanner.Packer
// Create the temp filename
string tempFile = $"embedded_resource_{i}.bin";
tempFile = Path.Combine(tempPath, tempFile);
tempFile = Path.Combine(outDir, tempFile);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
// Write the resource data to a temp file
using var tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
@@ -70,12 +70,12 @@ namespace BinaryObjectScanner.Packer
}
}
return tempPath;
return true;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
}
}

View File

@@ -31,9 +31,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -31,9 +31,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -54,9 +54,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
private static string GetOldVersion(string file, NewExecutable nex)

View File

@@ -28,9 +28,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
private string GetVersion(PortableExecutable pex)

View File

@@ -29,9 +29,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -33,9 +33,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -47,9 +47,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
private string GetVersion(PortableExecutable pex)

View File

@@ -31,9 +31,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -36,9 +36,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -41,9 +41,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -24,9 +24,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -38,9 +38,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
private string GetVersion(PortableExecutable pex)

View File

@@ -24,7 +24,7 @@ namespace BinaryObjectScanner.Packer
// Get the assembly description, if possible
if (pex.AssemblyDescription?.StartsWith("7-Zip Self-extracting Archive") == true)
return $"7-Zip SFX {pex.AssemblyDescription.Substring("7-Zip Self-extracting Archive ".Length)}";
// Get the file description, if it exists
if (pex.FileDescription?.Equals("7z SFX") == true)
return "7-Zip SFX";
@@ -51,58 +51,53 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
if (!File.Exists(file))
return null;
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
// Create a temp output directory
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(file, new ReaderOptions() { LookForHeader = true }))
using var sevenZip = SevenZipArchive.Open(file, new ReaderOptions() { LookForHeader = true });
foreach (var entry in sevenZip.Entries)
{
foreach (var entry in sevenZipFile.Entries)
try
{
try
{
// If the entry is a directory
if (entry.IsDirectory)
continue;
// If the entry is a directory
if (entry.IsDirectory)
continue;
// If the entry has an invalid key
if (entry.Key == null)
continue;
// If the entry has an invalid key
if (entry.Key == null)
continue;
// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
string tempFile = Path.Combine(tempPath, entry.Key);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
string tempFile = Path.Combine(outDir, entry.Key);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
}
return tempPath;
return true;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
#else
return null;
return false;
#endif
}
}

View File

@@ -25,9 +25,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}

View File

@@ -63,9 +63,9 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
public static string GetVersion(string file, byte[] fileContent, List<int> positions)

View File

@@ -33,58 +33,57 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
if (!File.Exists(file))
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
// Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file.
using (RarArchive rarFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true }))
using var rarFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true });
if (!rarFile.IsComplete)
return false;
foreach (var entry in rarFile.Entries)
{
if (!rarFile.IsComplete)
return null;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
foreach (var entry in rarFile.Entries)
try
{
try
{
// If the entry is a directory
if (entry.IsDirectory)
continue;
// If the entry is a directory
if (entry.IsDirectory)
continue;
// If the entry has an invalid key
if (entry.Key == null)
continue;
// If the entry has an invalid key
if (entry.Key == null)
continue;
// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
string tempFile = Path.Combine(tempPath, entry.Key);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
string tempFile = Path.Combine(outDir, entry.Key);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
return tempPath;
}
return true;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
#else
return null;
return false;
#endif
}
}

View File

@@ -66,65 +66,63 @@ namespace BinaryObjectScanner.Packer
// TODO: Find a way to generically detect 2.X versions and improve exact version detection for SFX PE versions bundled with WinZip 11+
/// <inheritdoc/>
public string? Extract(string file, NewExecutable nex, bool includeDebug)
=> Extract(file, includeDebug);
public bool Extract(string file, NewExecutable nex, string outDir, bool includeDebug)
=> Extract(file, outDir, includeDebug);
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
=> Extract(file, includeDebug);
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
=> Extract(file, outDir, includeDebug);
/// <summary>
/// Handle common extraction between executable types
/// </summary>
public static string? Extract(string file, bool includeDebug)
public static bool Extract(string file, string outDir, bool includeDebug)
{
if (!File.Exists(file))
return false;
#if NET462_OR_GREATER || NETCOREAPP
try
{
// Create a temp output directory
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
using (ZipArchive zipFile = ZipArchive.Open(file))
using var zipFile = ZipArchive.Open(file);
foreach (var entry in zipFile.Entries)
{
foreach (var entry in zipFile.Entries)
try
{
try
{
// If the entry is a directory
if (entry.IsDirectory)
continue;
// If the entry is a directory
if (entry.IsDirectory)
continue;
// If the entry has an invalid key
if (entry.Key == null)
continue;
// If the entry has an invalid key
if (entry.Key == null)
continue;
// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;
string tempFile = Path.Combine(tempPath, entry.Key);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
string tempFile = Path.Combine(outDir, entry.Key);
var directoryName = Path.GetDirectoryName(tempFile);
if (directoryName != null && !Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
entry.WriteToFile(tempFile);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
}
return tempPath;
return true;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
#else
return null;
return false;
#endif
}
@@ -796,14 +794,14 @@ namespace BinaryObjectScanner.Packer
"WZIPSE32.exe" => "Unknown Version (32-bit)",// TODO: Find starting version
"SI32LPG.SFX" => "Unknown Version (32-bit)",// TODO: Find starting version
"ST32E.WZE" => "Unknown Version (32-bit)",// TODO: Find starting version
// Personal Edition
"VW95LE.SFX" => "Unknown Version before Personal Edition Build 1285 (32-bit)",
"PE32E.SFX" => "Unknown Version after Personal Edition Build 1285 (32-bit)",
"wzsepe32.exe" => "Unknown Version Personal Edition (32-bit)",// TODO: Find starting version
"SI32PE.SFX" => "Unknown Version Personal Edition (32-bit)",// TODO: Find starting version
"SI32LPE.SFX" => "Unknown Version Personal Edition (32-bit)",// TODO: Find starting version
// Software Installation
"VW95SRE.SFX" => "Unknown Version before Software Installation 2.1 (32-bit)",
"SI32E.SFX" => "Unknown Version after Software Installation 2.1 (32-bit)",

View File

@@ -75,52 +75,36 @@ namespace BinaryObjectScanner.Packer
}
/// <inheritdoc/>
public string? Extract(string file, NewExecutable nex, bool includeDebug)
public bool Extract(string file, NewExecutable nex, string outDir, bool includeDebug)
{
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
Directory.CreateDirectory(outDir);
try
{
// TODO: Try to find where the file data lives and how to get it
if (!Extractor.ExtractTo(file, tempPath))
{
try
{
Directory.Delete(tempPath, true);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
return null;
}
return Extractor.ExtractTo(file, outDir);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
return tempPath;
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
try
{
// Get the matching PE format
var format = GetPEFormat(pex);
if (format == null)
return null;
return false;
// Get the overlay data for easier reading
int overlayOffset = 0, dataStart = 0;
var overlayData = pex.OverlayData;
if (overlayData == null)
return null;
return false;
// Skip over the additional DLL name, if we expect it
if (format.Dll)
@@ -175,43 +159,28 @@ namespace BinaryObjectScanner.Packer
var magic = overlayData.ReadBytes(ref overlayOffset, 4); overlayOffset -= 4;
bool pkzip = magic?.StartsWith(new byte?[] { (byte)'P', (byte)'K' }) ?? false;
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create the output directory
Directory.CreateDirectory(outDir);
// If we have PKZIP
if (pkzip)
{
string tempFile = Path.Combine(tempPath, "WISEDATA.zip");
using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
tempStream.Write(overlayData, overlayOffset, overlayData.Length - overlayOffset);
}
string tempFile = Path.Combine(outDir, "WISEDATA.zip");
using Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
tempStream.Write(overlayData, overlayOffset, overlayData.Length - overlayOffset);
return true;
}
// If we have DEFLATE -- TODO: Port implementation here or use DeflateStream
else
{
if (!Extractor.ExtractTo(file, tempPath))
{
try
{
Directory.Delete(tempPath, true);
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
}
return null;
}
return Extractor.ExtractTo(file, outDir);
}
return tempPath;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
return false;
}
}

View File

@@ -52,9 +52,9 @@ namespace BinaryObjectScanner.Protection
}
/// <inheritdoc/>
public string? Extract(string file, PortableExecutable pex, bool includeDebug)
public bool Extract(string file, PortableExecutable pex, string outDir, bool includeDebug)
{
return null;
return false;
}
}
}