fix: support spaces in elevated DEP script paths

This commit is contained in:
Dusk-92
2026-08-28 18:08:35 +02:00
parent 4bc60a3a6a
commit e01cdd967e
2 changed files with 57 additions and 4 deletions
+4 -4
View File
@@ -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 }"
)
+53
View File
@@ -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)