From 1ea6e9d29f343ca40a90b078733ed543bcec4b14 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 8 Mar 2024 16:21:31 +0000 Subject: [PATCH] feat: add loopback exemption check in Windows bootstrap --- .../src/endstone/_internal/bootstrap/windows.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/src/endstone/_internal/bootstrap/windows.py b/python/src/endstone/_internal/bootstrap/windows.py index 05b0b77ec..35eccb859 100644 --- a/python/src/endstone/_internal/bootstrap/windows.py +++ b/python/src/endstone/_internal/bootstrap/windows.py @@ -1,4 +1,5 @@ import ctypes +import subprocess from ctypes import get_last_error from ctypes.wintypes import ( BOOL, @@ -87,7 +88,22 @@ def executable_filename(self) -> str: def _endstone_runtime_filename(self) -> str: return "endstone_runtime.dll" + def _add_loopback_exemption(self) -> bool: + sid = "S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436" + ret = subprocess.run( + ["CheckNetIsolation", "LoopbackExempt", "-s", f"-p={sid}"], check=True, capture_output=True + ) + if sid not in ret.stdout.decode(): + ret = ctypes.windll.shell32.ShellExecuteW( + None, "runas", "CheckNetIsolation", " ".join(["LoopbackExempt", "-a", f"-p={sid}"]), None, 1 + ) + return ret > 32 + else: + return True + def _create_process(self, *args, **kwargs) -> None: + self._add_loopback_exemption() + # Create the process is a suspended state super()._create_process(creationflags=CREATE_SUSPENDED) handle_proc = int(self._process._handle)