harden macOS networking port
This commit is contained in:
@@ -24,6 +24,7 @@ import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import winreg
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@@ -143,6 +144,13 @@ def _clear_mru_key(path: str, rep: WipeReport) -> None:
|
||||
|
||||
|
||||
def _clear_clipboard(rep: WipeReport) -> None:
|
||||
if sys.platform == "darwin":
|
||||
try:
|
||||
subprocess.run(["pbcopy"], input="", text=True, timeout=5)
|
||||
rep.clipboard_cleared = True
|
||||
except Exception as e:
|
||||
rep.errors.append(f"clipboard: {e}")
|
||||
return
|
||||
try:
|
||||
user32 = ctypes.windll.user32 # type: ignore[attr-defined]
|
||||
if user32.OpenClipboard(None):
|
||||
@@ -157,6 +165,27 @@ def _clear_clipboard(rep: WipeReport) -> None:
|
||||
|
||||
def wipe_artifacts(include_prefetch: bool = True) -> WipeReport:
|
||||
rep = WipeReport()
|
||||
if sys.platform == "darwin":
|
||||
import tempfile
|
||||
temp = Path(tempfile.gettempdir())
|
||||
_purge_dir(temp, rep, keep_root=True)
|
||||
for path in (
|
||||
Path.home() / "Library" / "Caches" / "ProxyChainManager",
|
||||
Path.home() / "Library" / "Logs" / "ProxyGod.out.log",
|
||||
Path.home() / "Library" / "Logs" / "ProxyGod.err.log",
|
||||
):
|
||||
try:
|
||||
if path.is_dir():
|
||||
_purge_dir(path, rep, keep_root=False)
|
||||
elif path.is_file():
|
||||
sz = path.stat().st_size
|
||||
path.unlink(missing_ok=True)
|
||||
rep.files_deleted += 1
|
||||
rep.bytes_freed += sz
|
||||
except OSError as exc:
|
||||
rep.errors.append(f"{path.name}: {exc}")
|
||||
_clear_clipboard(rep)
|
||||
return rep
|
||||
appdata = Path(os.environ.get("APPDATA", "")) if os.environ.get("APPDATA") else None
|
||||
temp = Path(os.environ.get("TEMP", "")) if os.environ.get("TEMP") else None
|
||||
sysroot = Path(os.environ.get("SystemRoot", r"C:\Windows"))
|
||||
|
||||
Reference in New Issue
Block a user