Files

67 lines
2.3 KiB
C#
Raw Permalink Normal View History

2022-12-18 14:18:35 -08:00
using System.IO;
using System.Linq;
using BinaryObjectScanner.Interfaces;
2023-03-07 16:59:14 -05:00
using BinaryObjectScanner.Wrappers;
2022-12-18 14:18:35 -08:00
2023-03-09 23:52:58 -05:00
namespace BinaryObjectScanner.Packer
2022-12-18 14:18:35 -08:00
{
// TODO: Add extraction
2023-03-09 16:02:51 -05:00
public class SevenZipSFX : IExtractable, IPortableExecutableCheck
2022-12-18 14:18:35 -08:00
{
/// <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/>
2023-03-09 17:16:39 -05:00
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))
{
2023-03-09 17:16:39 -05:00
return Extract(fs, file, includeDebug);
}
}
/// <inheritdoc/>
2023-03-09 17:16:39 -05:00
public string Extract(Stream stream, string file, bool includeDebug)
{
return null;
}
2022-12-18 14:18:35 -08:00
}
}