mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-08 13:49:47 +00:00
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System.IO;
|
|
using System.Linq;
|
|
using BinaryObjectScanner.Interfaces;
|
|
using BinaryObjectScanner.Wrappers;
|
|
|
|
namespace BinaryObjectScanner.Packer
|
|
{
|
|
// TODO: Add extraction
|
|
public class SevenZipSFX : IExtractable, IPortableExecutableCheck
|
|
{
|
|
/// <inheritdoc/>
|
|
public string CheckPortableExecutable(string file, PortableExecutable pex, bool includeDebug)
|
|
{
|
|
// Get the sections from the executable, if possible
|
|
var sections = pex?.SectionTable;
|
|
if (sections == null)
|
|
return null;
|
|
|
|
// 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";
|
|
if (pex.FileDescription?.Equals("7z Self-Extract Setup") == true)
|
|
return "7-Zip SFX";
|
|
|
|
// Get the original filename, if it exists
|
|
if (pex.OriginalFilename?.Equals("7z.sfx.exe") == true)
|
|
return "7-Zip SFX";
|
|
else if (pex.OriginalFilename?.Equals("7zS.sfx") == true)
|
|
return "7-Zip SFX";
|
|
|
|
// Get the internal name, if it exists
|
|
if (pex.InternalName?.Equals("7z.sfx") == true)
|
|
return "7-Zip SFX";
|
|
else if (pex.InternalName?.Equals("7zS.sfx") == true)
|
|
return "7-Zip SFX";
|
|
|
|
// If any dialog boxes match
|
|
if (pex.FindDialogByTitle("7-Zip self-extracting archive").Any())
|
|
return "7-Zip SFX";
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public string Extract(string file, bool includeDebug)
|
|
{
|
|
if (!File.Exists(file))
|
|
return null;
|
|
|
|
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
{
|
|
return Extract(fs, file, includeDebug);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public string Extract(Stream stream, string file, bool includeDebug)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|