Skip to content

Commit

Permalink
Handle some warnings and messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Apr 24, 2024
1 parent 2f2cf76 commit 90223e6
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 14 deletions.
6 changes: 5 additions & 1 deletion BinaryObjectScanner/FileType/GZIP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ public class GZIP : IExtractable
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If the entry has an invalid key
if (entry.Key == null)
continue;

string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
Expand Down
8 changes: 6 additions & 2 deletions BinaryObjectScanner/FileType/PKZIP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ public class PKZIP : IExtractable
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If we have a partial entry due to an incomplete multi-part archive, skip it
// If the entry has an invalid key
if (entry.Key == null)
continue;

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

Expand Down
6 changes: 5 additions & 1 deletion BinaryObjectScanner/FileType/RAR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ public class RAR : IExtractable
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If the entry has an invalid key
if (entry.Key == null)
continue;

string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
Expand Down
9 changes: 8 additions & 1 deletion BinaryObjectScanner/FileType/SevenZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class SevenZip : IExtractable
/// <inheritdoc/>
public string? Extract(Stream? stream, string file, bool includeDebug)
{
if (stream == null)
return null;

#if NET462_OR_GREATER || NETCOREAPP
try
{
Expand All @@ -39,10 +42,14 @@ public class SevenZip : IExtractable
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If the entry has an invalid key
if (entry.Key == null)
continue;

string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
Expand Down
6 changes: 5 additions & 1 deletion BinaryObjectScanner/FileType/TapeArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ public class TapeArchive : IExtractable
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If the entry has an invalid key
if (entry.Key == null)
continue;

string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
Expand Down
11 changes: 6 additions & 5 deletions BinaryObjectScanner/Packer/EmbeddedExecutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class EmbeddedExecutable : IExtractablePortableExecutable, IPortableExecu
{
try
{
// If there are no resources
if (pex.ResourceData == null)
return null;

// Get the resources that have an executable signature
var resources = pex.ResourceData
.Where(kvp => kvp.Value != null && kvp.Value is byte[])
Expand All @@ -57,11 +61,8 @@ public class EmbeddedExecutable : IExtractablePortableExecutable, IPortableExecu
tempFile = Path.Combine(tempPath, tempFile);

// Write the resource data to a temp file
using (var tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
if (tempStream != null)
tempStream.Write(data, 0, data.Length);
}
using var tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
tempStream?.Write(data, 0, data.Length);
}
catch (Exception ex)
{
Expand Down
6 changes: 5 additions & 1 deletion BinaryObjectScanner/Packer/WinRARSFX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ public class WinRARSFX : IExtractablePortableExecutable, IPortableExecutableChec
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If the entry has an invalid key
if (entry.Key == null)
continue;

string tempFile = Path.Combine(tempPath, entry.Key);
entry.WriteToFile(tempFile);
}
Expand Down
8 changes: 6 additions & 2 deletions BinaryObjectScanner/Packer/WinZipSFX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class WinZipSFX : IExtractableNewExecutable, IExtractablePortableExecutab
/// Handle common extraction between executable types
/// </summary>
/// <inheritdoc/>
public string? Extract(string file, bool includeDebug)
public static string? Extract(string file, bool includeDebug)
{
#if NET462_OR_GREATER || NETCOREAPP
try
Expand All @@ -89,10 +89,14 @@ public class WinZipSFX : IExtractableNewExecutable, IExtractablePortableExecutab
{
try
{
// If we have a directory, skip it
// If the entry is a directory
if (entry.IsDirectory)
continue;

// If the entry has an invalid key
if (entry.Key == null)
continue;

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

0 comments on commit 90223e6

Please sign in to comment.