Skip to content

Commit

Permalink
Fix various archive formats not extracting folders (#323)
Browse files Browse the repository at this point in the history
Fixes folder extraction for 7z, RAR, and WinRAR SFX. Applied same fix to tar, but more is needed for it to work properly.
  • Loading branch information
TheRogueArchivist authored Sep 26, 2024
1 parent 54cb996 commit 28ebc14
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions BinaryObjectScanner/FileType/RAR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public class RAR : IExtractable
if (entry.Key == null)
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)
Expand Down
7 changes: 7 additions & 0 deletions BinaryObjectScanner/FileType/SevenZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public class SevenZip : IExtractable
if (entry.Key == null)
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)
Expand Down
8 changes: 8 additions & 0 deletions BinaryObjectScanner/FileType/TapeArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ public class TapeArchive : IExtractable
if (entry.Key == null)
continue;

// If we have a partial entry due to an incomplete multi-part archive, skip it
if (!entry.IsComplete)
continue;

// TODO: Fix bug with extracting folders from tar.
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)
Expand Down
13 changes: 10 additions & 3 deletions BinaryObjectScanner/Packer/WinRARSFX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public class WinRARSFX : IExtractablePortableExecutable, IPortableExecutableChec
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 zipFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true }))
using (RarArchive rarFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true }))
{
if (!zipFile.IsComplete)
if (!rarFile.IsComplete)
return null;

string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);

foreach (var entry in zipFile.Entries)
foreach (var entry in rarFile.Entries)
{
try
{
Expand All @@ -59,7 +59,14 @@ public class WinRARSFX : IExtractablePortableExecutable, IPortableExecutableChec
if (entry.Key == null)
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)
Expand Down

0 comments on commit 28ebc14

Please sign in to comment.