From 908dc443eb70df8d41b7daf97c3a208e50b90765 Mon Sep 17 00:00:00 2001 From: uduki Date: Wed, 14 Oct 2026 09:57:33 +0900 Subject: [PATCH] =?UTF-8?q?fix(evb):=20PE=E3=82=BB=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=AB=E3=82=88=E3=82=8BEVB=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E3=81=AE=E5=8E=B3=E6=A0=BC=E5=8C=96=E3=81=A8=E8=AA=A4?= =?UTF-8?q?=E6=A4=9C=E7=9F=A5=E3=81=AE=E9=98=B2=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 誤検知の要因となっていたバイナリ文字列探索(ContainsEvbContentMarker)を廃止 - PEセクションテーブル(.enigma1, .enigma2)の検出のみで確実に判定するよう見直し --- Engines/Evb/EvbDetectionHelper.cs | 82 +++---------------------------- 1 file changed, 8 insertions(+), 74 deletions(-) diff --git a/Engines/Evb/EvbDetectionHelper.cs b/Engines/Evb/EvbDetectionHelper.cs index 39bf941..953b03e 100644 --- a/Engines/Evb/EvbDetectionHelper.cs +++ b/Engines/Evb/EvbDetectionHelper.cs @@ -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. /// public static class EvbDetectionHelper { - /// Marker string embedded by the Enigma Virtual Box packer. - private const string EnigmaMarker = "Enigma Virtual Box"; - /// Section names produced by the packer. private static readonly string[] EnigmaSections = { ".enigma1", ".enigma2" }; - /// Additional loader identifiers checked during the content scan. - private static readonly string[] EvbContentMarkers = - { - EnigmaMarker, - "evb.dll", - "EnigmaVB", - }; - /// Returns true when the given executable is packed with EVB. /// - /// 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"). /// 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; } - - /// - /// Scans bounded windows of the executable for EVB loader markers. - /// EVB metadata typically sits near the end of the PE (overlay). - /// - 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; - } } }