Skip to content

Commit 9421249

Browse files
committed
Support ancient .NET
1 parent e823cba commit 9421249

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+512
-148
lines changed

BinaryObjectScanner/BinaryObjectScanner.csproj

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<!-- Assembly Properties -->
5-
<TargetFrameworks>net48;net6.0;net7.0</TargetFrameworks>
5+
<TargetFrameworks>net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
66
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<LangVersion>latest</LangVersion>
@@ -32,15 +32,15 @@
3232
</PropertyGroup>
3333

3434
<!-- Exclude all external modules for .NET Core and modern .NET -->
35-
<PropertyGroup Condition="!$(TargetFramework.StartsWith(`net4`))">
35+
<PropertyGroup Condition="!$(TargetFramework.StartsWith(`net4`)) OR $(TargetFramework.StartsWith(`net40`))">
3636
<DefaultItemExcludes>
3737
$(DefaultItemExcludes);
3838
_EXTERNAL\**;
3939
</DefaultItemExcludes>
4040
</PropertyGroup>
4141

4242
<!-- These are needed for dealing with native Windows DLLs -->
43-
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`))">
43+
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`)) AND !$(TargetFramework.StartsWith(`net40`))">
4444
<Content Include="*.dll">
4545
<Pack>true</Pack>
4646
<PackagePath>contentFiles;content</PackagePath>
@@ -55,19 +55,22 @@
5555

5656
<ItemGroup>
5757
<PackageReference Include="OpenMcdf" Version="2.3.0" />
58-
<PackageReference Include="SabreTools.Compression" Version="0.1.1" />
59-
<PackageReference Include="SabreTools.IO" Version="1.1.1" />
60-
<PackageReference Include="SabreTools.Matching" Version="1.1.1" />
61-
<PackageReference Include="SabreTools.Models" Version="1.1.5" />
62-
<PackageReference Include="SabreTools.Serialization" Version="1.1.7" />
58+
<PackageReference Include="SabreTools.Compression" Version="0.2.0" />
59+
<PackageReference Include="SabreTools.IO" Version="1.2.0" />
60+
<PackageReference Include="SabreTools.Matching" Version="1.2.0" />
61+
<PackageReference Include="SabreTools.Models" Version="1.2.0" />
62+
<PackageReference Include="SabreTools.Serialization" Version="1.2.0" />
63+
<PackageReference Include="UnshieldSharp" Version="1.7.0" />
64+
<PackageReference Include="WiseUnpacker" Version="1.2.0" />
65+
</ItemGroup>
66+
67+
<ItemGroup Condition="!$(TargetFramework.StartsWith(`net40`)) AND !$(TargetFramework.StartsWith(`net452`))">
6368
<PackageReference Include="SharpCompress" Version="0.34.1" />
6469
<PackageReference Include="SharpZipLib" Version="1.4.2" />
6570
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
66-
<PackageReference Include="UnshieldSharp" Version="1.6.9" />
67-
<PackageReference Include="WiseUnpacker" Version="1.0.4" />
6871
</ItemGroup>
6972

70-
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`))">
73+
<ItemGroup Condition="$(TargetFramework.StartsWith(`net4`)) AND !$(TargetFramework.StartsWith(`net40`))">
7174
<PackageReference Include="System.Memory" Version="4.5.5" />
7275
</ItemGroup>
7376

BinaryObjectScanner/FileType/BFPK.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4+
#if NET462_OR_GREATER
45
using SharpCompress.Compressors;
56
using SharpCompress.Compressors.Deflate;
7+
#endif
68

79
namespace BinaryObjectScanner.FileType
810
{
@@ -48,7 +50,7 @@ public class BFPK : IExtractable
4850
return null;
4951
}
5052
}
51-
53+
5254
/// <summary>
5355
/// Extract all files from the BFPK to an output directory
5456
/// </summary>
@@ -121,12 +123,14 @@ public static bool ExtractFile(SabreTools.Serialization.Wrappers.BFPK item, int
121123
{
122124
fs.Write(data, 0, compressedSize);
123125
}
126+
#if NET462_OR_GREATER
124127
else
125128
{
126129
MemoryStream ms = new MemoryStream(data);
127130
ZlibStream zs = new ZlibStream(ms, CompressionMode.Decompress);
128131
zs.CopyTo(fs);
129132
}
133+
#endif
130134
}
131135

132136
return true;

BinaryObjectScanner/FileType/BZip2.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4+
#if NET462_OR_GREATER
45
using SharpCompress.Compressors;
56
using SharpCompress.Compressors.BZip2;
7+
#endif
68

79
namespace BinaryObjectScanner.FileType
810
{
@@ -29,6 +31,7 @@ public class BZip2 : IExtractable
2931
if (stream == null)
3032
return null;
3133

34+
#if NET462_OR_GREATER
3235
try
3336
{
3437
// Create a temp output directory
@@ -51,6 +54,9 @@ public class BZip2 : IExtractable
5154
if (includeDebug) Console.WriteLine(ex);
5255
return null;
5356
}
57+
#else
58+
return null;
59+
#endif
5460
}
5561
}
5662
}

BinaryObjectScanner/FileType/Executable.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ public static IEnumerable<IPortableExecutableCheck> PortableExecutableCheckClass
214214
byte[] fileContent = new byte[0];
215215
try
216216
{
217+
#if NET40
218+
using (BinaryReader br = new BinaryReader(stream, Encoding.Default))
219+
#else
217220
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
221+
#endif
218222
{
219223
fileContent = br.ReadBytes((int)stream.Length);
220224
if (fileContent == null)
@@ -408,10 +412,14 @@ public ConcurrentDictionary<IPortableExecutableCheck, string> RunPortableExecuta
408412
return assembly.GetTypes()?
409413
.Where(t => t.IsClass && t.GetInterface(typeof(T).Name) != null)?
410414
.Select(t => (T?)Activator.CreateInstance(t))
415+
#if NET40 || NET452
416+
.Cast<T>() ?? [];
417+
#else
411418
.Cast<T>() ?? Array.Empty<T>();
419+
#endif
412420
}
413421

414-
#endregion
422+
#endregion
415423

416424
#region Helpers
417425

BinaryObjectScanner/FileType/GZIP.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4+
#if NET462_OR_GREATER
45
using SharpCompress.Archives;
56
using SharpCompress.Archives.GZip;
7+
#endif
68

79
namespace BinaryObjectScanner.FileType
810
{
@@ -29,6 +31,7 @@ public class GZIP : IExtractable
2931
if (stream == null)
3032
return null;
3133

34+
#if NET462_OR_GREATER
3235
try
3336
{
3437
// Create a temp output directory
@@ -62,6 +65,9 @@ public class GZIP : IExtractable
6265
if (includeDebug) Console.WriteLine(ex);
6366
return null;
6467
}
68+
#else
69+
return null;
70+
#endif
6571
}
6672
}
6773
}

BinaryObjectScanner/FileType/InstallShieldArchiveV3.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class InstallShieldArchiveV3 : IExtractable
3737
{
3838
try
3939
{
40-
string tempFile = Path.Combine(tempPath, cfile.FullPath);
40+
string tempFile = Path.Combine(tempPath, cfile.FullPath!);
4141
var directoryName = Path.GetDirectoryName(tempFile);
4242
if (directoryName != null && !Directory.Exists(directoryName))
4343
Directory.CreateDirectory(directoryName);
4444

45-
(byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
46-
if (!string.IsNullOrWhiteSpace(error))
45+
(byte[]? fileContents, string? error) = archive.Extract(cfile.FullPath!);
46+
if (fileContents == null || !string.IsNullOrWhiteSpace(error))
4747
continue;
4848

4949
using (FileStream fs = File.OpenWrite(tempFile))

BinaryObjectScanner/FileType/InstallShieldCAB.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ public class InstallShieldCAB : IExtractable
6060
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
6161
Directory.CreateDirectory(tempPath);
6262

63-
InstallShieldCabinet cabfile = InstallShieldCabinet.Open(file);
63+
var cabfile = InstallShieldCabinet.Open(file);
64+
if (cabfile == null)
65+
return null;
66+
6467
for (int i = 0; i < cabfile.FileCount; i++)
6568
{
6669
try
@@ -72,8 +75,8 @@ public class InstallShieldCAB : IExtractable
7275
string tempFile;
7376
try
7477
{
75-
string filename = cabfile.FileName(i);
76-
tempFile = Path.Combine(tempPath, filename);
78+
string? filename = cabfile.FileName(i);
79+
tempFile = Path.Combine(tempPath, filename ?? string.Empty);
7780
}
7881
catch
7982
{

BinaryObjectScanner/FileType/MPQ.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4-
#if NET48
4+
#if NETFRAMEWORK && !NET40
55
using StormLibSharp;
66
#endif
77

@@ -28,7 +28,7 @@ public class MPQ : IExtractable
2828
/// <inheritdoc/>
2929
public string? Extract(Stream? stream, string file, bool includeDebug)
3030
{
31-
#if NETCOREAPP || NET5_0_OR_GREATER
31+
#if NET40 || NETCOREAPP || NET5_0_OR_GREATER
3232
// Not supported for .NET Core and modern .NET due to Windows DLL requirements
3333
return null;
3434
#else

BinaryObjectScanner/FileType/PKZIP.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4+
#if NET462_OR_GREATER
45
using SharpCompress.Archives;
56
using SharpCompress.Archives.Zip;
7+
#endif
68

79
namespace BinaryObjectScanner.FileType
810
{
@@ -29,6 +31,7 @@ public class PKZIP : IExtractable
2931
if (stream == null)
3032
return null;
3133

34+
#if NET462_OR_GREATER
3235
try
3336
{
3437
// Create a temp output directory
@@ -65,6 +68,9 @@ public class PKZIP : IExtractable
6568
if (includeDebug) Console.WriteLine(ex);
6669
return null;
6770
}
71+
#else
72+
return null;
73+
#endif
6874
}
6975
}
7076
}

BinaryObjectScanner/FileType/RAR.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4+
#if NET462_OR_GREATER
45
using SharpCompress.Archives;
56
using SharpCompress.Archives.Rar;
7+
#endif
68

79
namespace BinaryObjectScanner.FileType
810
{
@@ -29,6 +31,7 @@ public class RAR : IExtractable
2931
if (stream == null)
3032
return null;
3133

34+
#if NET462_OR_GREATER
3235
try
3336
{
3437
// Create a temp output directory
@@ -62,6 +65,9 @@ public class RAR : IExtractable
6265
if (includeDebug) Console.WriteLine(ex);
6366
return null;
6467
}
68+
#else
69+
return null;
70+
#endif
6571
}
6672
}
6773
}

0 commit comments

Comments
 (0)