Skip to content

Commit cc76275

Browse files
committed
Add support of IS-Z archives
1 parent 7065436 commit cc76275

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text.RegularExpressions;
6+
using UnshieldSharp.Archive;
7+
8+
namespace BurnOutSharp.FileType
9+
{
10+
internal class InstallShieldArchiveV3 : IScannable
11+
{
12+
/// <inheritdoc/>
13+
public bool ShouldScan(byte[] magic)
14+
{
15+
if (magic.StartsWith(new byte?[] { 0x13, 0x5D, 0x65, 0x8C }))
16+
return true;
17+
18+
return false;
19+
}
20+
21+
/// <inheritdoc/>
22+
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
23+
{
24+
if (!File.Exists(file))
25+
return null;
26+
27+
using (var fs = File.OpenRead(file))
28+
{
29+
return Scan(scanner, fs, file);
30+
}
31+
}
32+
33+
// TODO: Add stream opening support
34+
/// <inheritdoc/>
35+
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
36+
{
37+
// Get the name of the first cabinet file or header
38+
string directory = Path.GetDirectoryName(file);
39+
string noExtension = Path.GetFileNameWithoutExtension(file);
40+
string filenamePattern = Path.Combine(directory, noExtension);
41+
filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
42+
43+
bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
44+
bool shouldScanCabinet = cabinetHeaderExists
45+
? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
46+
: file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
47+
48+
// If we have the first file
49+
if (shouldScanCabinet)
50+
{
51+
// If the cab file itself fails
52+
try
53+
{
54+
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
55+
Directory.CreateDirectory(tempPath);
56+
57+
UnshieldSharp.Archive.InstallShieldArchiveV3 archive = new UnshieldSharp.Archive.InstallShieldArchiveV3(file);
58+
foreach (CompressedFile cfile in archive.Files.Select(kvp => kvp.Value))
59+
{
60+
// If an individual entry fails
61+
try
62+
{
63+
string tempFile = Path.Combine(tempPath, cfile.FullPath);
64+
if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
65+
Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
66+
67+
(byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
68+
if (!string.IsNullOrWhiteSpace(error))
69+
continue;
70+
71+
using (FileStream fs = File.OpenWrite(tempFile))
72+
{
73+
fs.Write(fileContents, 0, fileContents.Length);
74+
}
75+
}
76+
catch { }
77+
}
78+
79+
// Collect and format all found protections
80+
var protections = scanner.GetProtections(tempPath);
81+
82+
// If temp directory cleanup fails
83+
try
84+
{
85+
Directory.Delete(tempPath, true);
86+
}
87+
catch { }
88+
89+
// Remove temporary path references
90+
Utilities.StripFromKeys(protections, tempPath);
91+
92+
return protections;
93+
}
94+
catch { }
95+
}
96+
97+
return null;
98+
}
99+
}
100+
}

BurnOutSharp/FileType/InstallShieldCAB.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Concurrent;
3-
using System.Collections.Generic;
43
using System.IO;
54
using System.Text.RegularExpressions;
65
using UnshieldSharp.Cabinet;

BurnOutSharp/Scanner.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ private ConcurrentDictionary<string, ConcurrentQueue<string>> GetInternalProtect
320320
Utilities.AppendToDictionary(protections, subProtections);
321321
}
322322

323+
// InstallShield Archive V3 (Z)
324+
if (file != null && new InstallShieldArchiveV3().ShouldScan(magic))
325+
{
326+
var subProtections = new InstallShieldArchiveV3().Scan(this, file);
327+
Utilities.PrependToKeys(subProtections, file);
328+
Utilities.AppendToDictionary(protections, subProtections);
329+
}
330+
323331
// InstallShield Cabinet
324332
if (file != null && new InstallShieldCAB().ShouldScan(magic))
325333
{

0 commit comments

Comments
 (0)