fix(evb): PEセクションによるEVB判定の厳格化と誤検知の防止
- 誤検知の要因となっていたバイナリ文字列探索(ContainsEvbContentMarker)を廃止 - PEセクションテーブル(.enigma1, .enigma2)の検出のみで確実に判定するよう見直し
This commit is contained in:
1 parent
8f67ab1864
commit
908dc443eb
1 file changed
+8
-74
@@ -10,34 +10,21 @@ namespace GameLauncher.Engines.Evb
|
||||
/// that ordinary (unpacked) games are never misclassified.
|
||||
///
|
||||
/// Detection strategy:
|
||||
/// 1. Parse the PE header and inspect the section table for the packer's sections
|
||||
/// (".enigma1" / ".enigma2"). A present section is a decisive match.
|
||||
/// 2. When sections are inconclusive, scan bounded windows of the file for the
|
||||
/// "Enigma Virtual Box" marker string embedded by the packer.
|
||||
/// Parse the PE header and inspect the section table for the packer's sections
|
||||
/// (".enigma1" / ".enigma2"). A present section is a decisive match; anything else
|
||||
/// is treated as "not EVB" so plain (unpacked) games are never misclassified.
|
||||
///
|
||||
/// This class is engine-local and has no side effects.
|
||||
/// </summary>
|
||||
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>
|
||||
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>
|
||||
/// <remarks>
|
||||
/// Step 1 reads the PE section table for the packer's section names.
|
||||
/// Step 2 falls back to a bounded content scan for the packer marker.
|
||||
/// Any IO/format error yields false (treated as "not confidently EVB").
|
||||
/// Reads the PE section table for the packer's section names. Any IO/format error
|
||||
/// yields false (treated as "not confidently EVB").
|
||||
/// </remarks>
|
||||
public static bool IsEvbPacked(string exePath)
|
||||
{
|
||||
@@ -48,24 +35,12 @@ namespace GameLauncher.Engines.Evb
|
||||
|
||||
try
|
||||
{
|
||||
// Step 1: decisive PE section check.
|
||||
if (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);
|
||||
// Decisive: the packer's own PE sections are the only reliable signal.
|
||||
return HasEnigmaSection(exePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Unparseable executable -> never claim EVB.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -188,46 +163,5 @@ namespace GameLauncher.Engines.Evb
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user