mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-08 18:06:34 +00:00
Version gate remaining Linq statements
This commit is contained in:
@@ -69,7 +69,6 @@
|
||||
|
||||
<!-- Support for old .NET versions -->
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith(`net2`))">
|
||||
<PackageReference Include="Net30.LinqBridge" Version="1.3.0" />
|
||||
<PackageReference Include="Net35.Actions" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="!$(TargetFramework.StartsWith(`net2`)) AND !$(TargetFramework.StartsWith(`net3`))">
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using BinaryObjectScanner.Data;
|
||||
using BinaryObjectScanner.Interfaces;
|
||||
using SabreTools.IO.Extensions;
|
||||
@@ -267,9 +269,20 @@ namespace BinaryObjectScanner.FileType
|
||||
return protections;
|
||||
|
||||
// If we have any extractable packers
|
||||
#if NET20
|
||||
var extractables = new List<IExtractableExecutable<T>>();
|
||||
foreach (var check in checks)
|
||||
{
|
||||
if (check == null || check is not IExtractableExecutable<T> extractable)
|
||||
continue;
|
||||
|
||||
extractables.Add(extractable);
|
||||
}
|
||||
#else
|
||||
var extractables = checks
|
||||
.Where(c => c is IExtractableExecutable<T>)
|
||||
.Select(c => c as IExtractableExecutable<T>);
|
||||
#endif
|
||||
extractables.IterateWithAction(extractable =>
|
||||
{
|
||||
var subProtections = PerformExtractableCheck(extractable!, file, exe, getProtections, includeDebug);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
using BinaryObjectScanner.Interfaces;
|
||||
using SabreTools.Matching;
|
||||
@@ -125,9 +127,28 @@ namespace BinaryObjectScanner.Protection
|
||||
|
||||
// Check the imported-name table
|
||||
// Found in "h3blade.exe" in Redump entry 85077.
|
||||
#if NET20
|
||||
bool intMatch = false;
|
||||
if (nex.Model.ImportedNameTable?.Values != null)
|
||||
{
|
||||
foreach (var inte in nex.Model.ImportedNameTable.Values)
|
||||
{
|
||||
if (inte?.NameString == null || inte.NameString.Length == 0)
|
||||
continue;
|
||||
|
||||
string ns = Encoding.ASCII.GetString(inte.NameString);
|
||||
if (ns.Contains("CDCOPS"))
|
||||
{
|
||||
intMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
bool intMatch = nex.Model.ImportedNameTable?.Values?
|
||||
.Select(inte => inte?.NameString == null ? string.Empty : Encoding.ASCII.GetString(inte.NameString))
|
||||
.Any(s => s.Contains("CDCOPS")) ?? false;
|
||||
#endif
|
||||
if (intMatch)
|
||||
return "CD-Cops";
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Text;
|
||||
using SabreTools.Matching;
|
||||
using SabreTools.Matching.Paths;
|
||||
@@ -121,10 +123,22 @@ namespace BinaryObjectScanner.Protection
|
||||
return string.Empty;
|
||||
|
||||
// Find the version.txt file first
|
||||
#if NET20
|
||||
string? versionPath = null;
|
||||
foreach (string file in files)
|
||||
{
|
||||
if (Path.GetFileName(file).Equals("version.txt", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
versionPath = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
var versionPath = files.FirstOrDefault(f => Path.GetFileName(f).Equals("version.txt", StringComparison.OrdinalIgnoreCase));
|
||||
#endif
|
||||
if (!string.IsNullOrEmpty(versionPath))
|
||||
{
|
||||
var version = GetCactusDataShieldInternalVersion(versionPath);
|
||||
var version = GetCactusDataShieldInternalVersion(versionPath!);
|
||||
if (!string.IsNullOrEmpty(version))
|
||||
return version!;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using BinaryObjectScanner.Interfaces;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Matching;
|
||||
@@ -631,7 +633,19 @@ namespace BinaryObjectScanner.Protection
|
||||
}
|
||||
|
||||
// Get distinct and order
|
||||
#if NET20
|
||||
var distinct = new List<string>();
|
||||
foreach (string result in resultsList)
|
||||
{
|
||||
if (!distinct.Contains(result))
|
||||
distinct.Add(result);
|
||||
}
|
||||
|
||||
distinct.Sort();
|
||||
return distinct;
|
||||
#else
|
||||
return [.. resultsList.Distinct().OrderBy(s => s)];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
#if NET35_OR_GREATER || NETCOREAPP
|
||||
using System.Linq;
|
||||
#endif
|
||||
using BinaryObjectScanner;
|
||||
|
||||
namespace ProtectionScan
|
||||
@@ -85,13 +87,26 @@ namespace ProtectionScan
|
||||
}
|
||||
|
||||
using var sw = new StreamWriter(File.OpenWrite($"protection-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt"));
|
||||
#if NET20
|
||||
var keysArr = new string[protections.Keys.Count];
|
||||
protections.Keys.CopyTo(keysArr, 0);
|
||||
Array.Sort(keysArr);
|
||||
foreach (string key in keysArr)
|
||||
#else
|
||||
foreach (string key in protections.Keys.OrderBy(k => k))
|
||||
#endif
|
||||
{
|
||||
// Skip over files with no protection
|
||||
if (protections[key] == null || protections[key].Count == 0)
|
||||
continue;
|
||||
|
||||
string line = $"{key}: {string.Join(", ", [.. protections[key].OrderBy(p => p)])}";
|
||||
#if NET20
|
||||
string[] fileProtections = [.. protections[key]];
|
||||
Array.Sort(fileProtections);
|
||||
#else
|
||||
string[] fileProtections = [.. protections[key].OrderBy(p => p)];
|
||||
#endif
|
||||
string line = $"{key}: {string.Join(", ", fileProtections)}";
|
||||
Console.WriteLine(line);
|
||||
sw.WriteLine(line);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user