From e01cdd967e961cc0cc9c8b0f4a33002e2e9e44f3 Mon Sep 17 00:00:00 2001 From: Dusk-92 Date: Fri, 28 Aug 2026 18:08:35 +0200 Subject: [PATCH] fix: support spaces in elevated DEP script paths --- setup_tool.py | 8 +++---- tests/test_safety.py | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/setup_tool.py b/setup_tool.py index 5174f68..42e0e71 100644 --- a/setup_tool.py +++ b/setup_tool.py @@ -1792,12 +1792,12 @@ class WowSetupTool: escaped_script = script_path.replace("'", "''") launcher = ( "$ErrorActionPreference='Stop'; " + f"$scriptPath = '{escaped_script}'; " + "$argumentLine = '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File \"' " + "+ $scriptPath + '\"'; " "try { " "$p = Start-Process -FilePath 'powershell.exe' -Verb RunAs " - "-Wait -PassThru -ArgumentList @(" - "'-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass'," - f"'-File','{escaped_script}'" - "); " + "-Wait -PassThru -ArgumentList $argumentLine; " "exit $p.ExitCode " "} catch { Write-Error $_; exit 1 }" ) diff --git a/tests/test_safety.py b/tests/test_safety.py index 9cc284d..6cc2305 100644 --- a/tests/test_safety.py +++ b/tests/test_safety.py @@ -468,6 +468,59 @@ class AutoLoginEncryptionTests(unittest.TestCase): os.environ["WOW_ENCRYPTION_KEY"] = original +class DepElevationTests(unittest.TestCase): + def test_quotes_script_path_when_game_folder_contains_spaces(self): + tool = WowSetupTool.__new__(WowSetupTool) + + with tempfile.TemporaryDirectory(prefix="01 OctoWoW ") as root: + captured = {} + + def fake_run(args, **kwargs): + captured["args"] = args + script_path = os.path.join( + root, + ".modernization_tool", + "process_mitigation.ps1", + ) + self.assertIn(" ", script_path) + self.assertTrue(os.path.isfile(script_path)) + return mock.Mock(returncode=0, stdout="", stderr="") + + with mock.patch("setup_tool.subprocess.run", side_effect=fake_run): + tool._run_elevated_powershell( + root, + "Set-ProcessMitigation -Name 'WoW_Modernized.exe' " + "-Disable DEP, EmulateAtlThunks", + "Disabling DEP for WoW_Modernized.exe", + ) + + launcher = captured["args"][-1] + escaped_script = os.path.join( + root, + ".modernization_tool", + "process_mitigation.ps1", + ).replace("'", "''") + + self.assertIn( + f"$scriptPath = '{escaped_script}';", + launcher, + ) + self.assertIn( + "'-NoProfile -NonInteractive -ExecutionPolicy Bypass -File \"' " + "+ $scriptPath + '\"'", + launcher, + ) + self.assertFalse( + os.path.exists( + os.path.join( + root, + ".modernization_tool", + "process_mitigation.ps1", + ) + ) + ) + + class PeValidationTests(unittest.TestCase): def write_minimal_x86_pe(self, path): data = bytearray(2048)