From 103ffc70bdb630af1e99b30895d00e3633e0d38e Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 13 Dec 2024 14:07:08 -0500 Subject: [PATCH] Enable bz2 and gzip on all platforms --- BinaryObjectScanner/FileType/BZip2.cs | 11 ++------ BinaryObjectScanner/FileType/GZIP.cs | 40 ++++++--------------------- 2 files changed, 11 insertions(+), 40 deletions(-) diff --git a/BinaryObjectScanner/FileType/BZip2.cs b/BinaryObjectScanner/FileType/BZip2.cs index 3975fe0a..916c905c 100644 --- a/BinaryObjectScanner/FileType/BZip2.cs +++ b/BinaryObjectScanner/FileType/BZip2.cs @@ -1,10 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER || NETCOREAPP -using SharpCompress.Compressors; -using SharpCompress.Compressors.BZip2; -#endif +using SabreTools.Compression.BZip2; namespace BinaryObjectScanner.FileType { @@ -29,11 +26,10 @@ namespace BinaryObjectScanner.FileType if (stream == null || !stream.CanRead) return false; -#if NET462_OR_GREATER || NETCOREAPP try { // Try opening the stream - using var bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true); + using var bz2File = new BZip2InputStream(stream, true); // Create the output file path Directory.CreateDirectory(outDir); @@ -50,9 +46,6 @@ namespace BinaryObjectScanner.FileType if (includeDebug) Console.WriteLine(ex); return false; } -#else - return false; -#endif } } } diff --git a/BinaryObjectScanner/FileType/GZIP.cs b/BinaryObjectScanner/FileType/GZIP.cs index 1c2dbb05..c7047f04 100644 --- a/BinaryObjectScanner/FileType/GZIP.cs +++ b/BinaryObjectScanner/FileType/GZIP.cs @@ -1,10 +1,7 @@ using System; using System.IO; using BinaryObjectScanner.Interfaces; -#if NET462_OR_GREATER || NETCOREAPP -using SharpCompress.Archives; -using SharpCompress.Archives.GZip; -#endif +using SabreTools.Compression.Deflate; namespace BinaryObjectScanner.FileType { @@ -29,34 +26,18 @@ namespace BinaryObjectScanner.FileType if (stream == null || !stream.CanRead) return false; -#if NET462_OR_GREATER || NETCOREAPP try { - using var zipFile = GZipArchive.Open(stream); - foreach (var entry in zipFile.Entries) - { - try - { - // If the entry is a directory - if (entry.IsDirectory) - continue; + // Try opening the stream + using var gzipFile = new GZipStream(stream, CompressionMode.Decompress, true); - // If the entry has an invalid key - if (entry.Key == null) - continue; + // Create the output file path + Directory.CreateDirectory(outDir); + string tempFile = Path.Combine(outDir, Guid.NewGuid().ToString()); - string tempFile = Path.Combine(outDir, entry.Key); - var directoryName = Path.GetDirectoryName(tempFile); - if (directoryName != null && !Directory.Exists(directoryName)) - Directory.CreateDirectory(directoryName); - - entry.WriteToFile(tempFile); - } - catch (Exception ex) - { - if (includeDebug) Console.WriteLine(ex); - } - } + // Extract the file + using FileStream fs = File.OpenWrite(tempFile); + gzipFile.CopyTo(fs); return true; } @@ -65,9 +46,6 @@ namespace BinaryObjectScanner.FileType if (includeDebug) Console.WriteLine(ex); return false; } -#else - return false; -#endif } } }