2021-07-21 13:40:32 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
2022-05-01 17:41:50 -07:00
|
|
|
|
using BurnOutSharp.Interfaces;
|
2021-07-21 13:40:32 -07:00
|
|
|
|
using UnshieldSharp.Archive;
|
2022-12-15 00:13:24 -08:00
|
|
|
|
using static BurnOutSharp.Utilities.Dictionary;
|
2021-07-21 13:40:32 -07:00
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.FileType
|
|
|
|
|
|
{
|
2022-12-08 21:32:52 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// InstallShield archive v3
|
|
|
|
|
|
/// </summary>
|
2021-09-10 16:10:15 -07:00
|
|
|
|
public class InstallShieldArchiveV3 : IScannable
|
2021-07-21 13:40:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
2022-12-22 22:03:32 -08:00
|
|
|
|
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
2021-07-21 13:40:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
return Scan(scanner, fs, file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add stream opening support
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
|
|
|
|
|
|
{
|
2023-01-04 10:05:21 -08:00
|
|
|
|
// If the archive itself fails
|
|
|
|
|
|
try
|
2021-07-21 13:40:32 -07:00
|
|
|
|
{
|
2023-01-04 10:05:21 -08:00
|
|
|
|
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
|
|
|
|
|
Directory.CreateDirectory(tempPath);
|
2021-07-21 13:40:32 -07:00
|
|
|
|
|
2023-01-04 10:05:21 -08:00
|
|
|
|
UnshieldSharp.Archive.InstallShieldArchiveV3 archive = new UnshieldSharp.Archive.InstallShieldArchiveV3(file);
|
|
|
|
|
|
foreach (CompressedFile cfile in archive.Files.Select(kvp => kvp.Value))
|
|
|
|
|
|
{
|
|
|
|
|
|
// If an individual entry fails
|
|
|
|
|
|
try
|
2021-07-21 13:40:32 -07:00
|
|
|
|
{
|
2023-01-04 10:05:21 -08:00
|
|
|
|
string tempFile = Path.Combine(tempPath, cfile.FullPath);
|
|
|
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
|
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
|
2021-07-21 13:40:32 -07:00
|
|
|
|
|
2023-01-04 10:05:21 -08:00
|
|
|
|
(byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(error))
|
|
|
|
|
|
continue;
|
2021-07-21 13:40:32 -07:00
|
|
|
|
|
2023-01-04 10:05:21 -08:00
|
|
|
|
using (FileStream fs = File.OpenWrite(tempFile))
|
2022-05-15 20:58:27 -07:00
|
|
|
|
{
|
2023-01-04 10:05:21 -08:00
|
|
|
|
fs.Write(fileContents, 0, fileContents.Length);
|
2022-05-15 20:58:27 -07:00
|
|
|
|
}
|
2021-07-21 13:40:32 -07:00
|
|
|
|
}
|
2022-05-15 20:58:27 -07:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scanner.IncludeDebug) Console.WriteLine(ex);
|
|
|
|
|
|
}
|
2023-01-04 10:05:21 -08:00
|
|
|
|
}
|
2021-07-21 13:40:32 -07:00
|
|
|
|
|
2023-01-04 10:05:21 -08:00
|
|
|
|
// Collect and format all found protections
|
|
|
|
|
|
var protections = scanner.GetProtections(tempPath);
|
2021-07-21 13:40:32 -07:00
|
|
|
|
|
2023-01-04 10:05:21 -08:00
|
|
|
|
// If temp directory cleanup fails
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.Delete(tempPath, true);
|
2021-07-21 13:40:32 -07:00
|
|
|
|
}
|
2022-05-15 20:58:27 -07:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scanner.IncludeDebug) Console.WriteLine(ex);
|
|
|
|
|
|
}
|
2023-01-04 10:05:21 -08:00
|
|
|
|
|
|
|
|
|
|
// Remove temporary path references
|
|
|
|
|
|
StripFromKeys(protections, tempPath);
|
|
|
|
|
|
|
|
|
|
|
|
return protections;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scanner.IncludeDebug) Console.WriteLine(ex);
|
2021-07-21 13:40:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|