fix(evb): PEセクションによるEVB判定の厳格化と誤検知の防止

- 誤検知の要因となっていたバイナリ文字列探索(ContainsEvbContentMarker)を廃止
- PEセクションテーブル(.enigma1, .enigma2)の検出のみで確実に判定するよう見直し
This commit is contained in:
armonica committed 2026-10-14 09:57:33 +09:00
1 parent 8f67ab1864
commit 908dc443eb
1 file changed
+8 -74
+8 -74
View File
@@ -10,34 +10,21 @@ namespace GameLauncher.Engines.Evb
/// that ordinary (unpacked) games are never misclassified. /// that ordinary (unpacked) games are never misclassified.
/// ///
/// Detection strategy: /// Detection strategy:
/// 1. Parse the PE header and inspect the section table for the packer's sections /// Parse the PE header and inspect the section table for the packer's sections
/// (".enigma1" / ".enigma2"). A present section is a decisive match. /// (".enigma1" / ".enigma2"). A present section is a decisive match; anything else
/// 2. When sections are inconclusive, scan bounded windows of the file for the /// is treated as "not EVB" so plain (unpacked) games are never misclassified.
/// "Enigma Virtual Box" marker string embedded by the packer.
/// ///
/// This class is engine-local and has no side effects. /// This class is engine-local and has no side effects.
/// </summary> /// </summary>
public static class EvbDetectionHelper public static class EvbDetectionHelper
{ {
/// <summary>Marker string embedded by the Enigma Virtual Box packer.</summary>
private const string EnigmaMarker = "Enigma Virtual Box";
/// <summary>Section names produced by the packer.</summary> /// <summary>Section names produced by the packer.</summary>
private static readonly string[] EnigmaSections = { ".enigma1", ".enigma2" }; private static readonly string[] EnigmaSections = { ".enigma1", ".enigma2" };
/// <summary>Additional loader identifiers checked during the content scan.</summary>
private static readonly string[] EvbContentMarkers =
{
EnigmaMarker,
"evb.dll",
"EnigmaVB",
};
/// <summary>Returns true when the given executable is packed with EVB.</summary> /// <summary>Returns true when the given executable is packed with EVB.</summary>
/// <remarks> /// <remarks>
/// Step 1 reads the PE section table for the packer's section names. /// Reads the PE section table for the packer's section names. Any IO/format error
/// Step 2 falls back to a bounded content scan for the packer marker. /// yields false (treated as "not confidently EVB").
/// Any IO/format error yields false (treated as "not confidently EVB").
/// </remarks> /// </remarks>
public static bool IsEvbPacked(string exePath) public static bool IsEvbPacked(string exePath)
{ {
@@ -48,24 +35,12 @@ namespace GameLauncher.Engines.Evb
try try
{ {
// Step 1: decisive PE section check. // Decisive: the packer's own PE sections are the only reliable signal.
if (HasEnigmaSection(exePath)) return HasEnigmaSection(exePath);
{
return true;
}
}
catch
{
// Fall through to the content scan on any parse failure.
}
try
{
// Step 2: content marker scan over bounded windows.
return ContainsEvbContentMarker(exePath);
} }
catch catch
{ {
// Unparseable executable -> never claim EVB.
return false; return false;
} }
} }
@@ -188,46 +163,5 @@ namespace GameLauncher.Engines.Evb
return false; return false;
} }
/// <summary>
/// Scans bounded windows of the executable for EVB loader markers.
/// EVB metadata typically sits near the end of the PE (overlay).
/// </summary>
private static bool ContainsEvbContentMarker(string exePath)
{
const int windowSize = 2 * 1024 * 1024;
using var fs = new FileStream(exePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
long size = fs.Length;
if (size < 1024)
{
return false;
}
double[] fractions = { 0.5, 0.8, 0.9, 0.97 };
foreach (var frac in fractions)
{
long start = (long)(size * frac);
int readLen = (int)Math.Min(windowSize, size - start);
if (readLen <= 0)
{
continue;
}
var buf = new byte[readLen];
fs.Seek(start, SeekOrigin.Begin);
int read = fs.Read(buf, 0, buf.Length);
var text = System.Text.Encoding.ASCII.GetString(buf, 0, read);
foreach (var marker in EvbContentMarkers)
{
if (text.IndexOf(marker, StringComparison.OrdinalIgnoreCase) >= 0)
{
return true;
}
}
}
return false;
}
} }
} }