Introduce OptionalEndsWith

This commit is contained in:
Matt Nadareski
2025-09-20 18:03:09 -04:00
parent 4afea551ba
commit 981a5bb7b5
2 changed files with 19 additions and 9 deletions

View File

@@ -68,6 +68,19 @@ namespace BinaryObjectScanner
#endif
}
/// <inheritdoc cref="string.EndsWith(string)"/>
public static bool OptionalEndsWith(this string? self, string value)
=> OptionalEndsWith(self, value, StringComparison.Ordinal);
/// <inheritdoc cref="string.EndsWith(string, StringComparison)"/>
public static bool OptionalEndsWith(this string? self, string value, StringComparison comparisonType)
{
if (self == null)
return false;
return self.EndsWith(value, comparisonType);
}
/// <inheritdoc cref="string.Equals(string)"/>
public static bool OptionalEquals(this string? self, string value)
=> OptionalEquals(self, value, StringComparison.Ordinal);

View File

@@ -28,17 +28,14 @@ namespace BinaryObjectScanner.Protection
return "Armadillo";
// Loop through all "extension" sections -- usually .data1 or .text1
if (exe.SectionNames != null)
foreach (var sectionName in Array.FindAll(exe.SectionNames, s => s.OptionalEndsWith("1")))
{
foreach (var sectionName in Array.FindAll(exe.SectionNames ?? [], s => s != null && s.EndsWith("1")))
// Get the section strings, if they exist
var strs = exe.GetFirstSectionStrings(sectionName);
if (strs != null)
{
// Get the section strings, if they exist
var strs = exe.GetFirstSectionStrings(sectionName);
if (strs != null)
{
if (strs.Exists(s => s.Contains("ARMDEBUG")))
return "Armadillo";
}
if (strs.Exists(s => s.Contains("ARMDEBUG")))
return "Armadillo";
}
}