voice-changer: fix review findings (install-folder ACL, scoped uninstall delete, comm-mode APO, reconnect)
- installer: lock the install folder (admins/SYSTEM full, Users read) and grant Users modify only on data dirs (models/training/datasets/config/cache/env/engine/tools); download the engine as the original (non-elevated) user; refuse non-empty folders; uninstall deletes only app-managed dirs - mic-apo.ps1: backup/list/log moved to admin-only apo\; register SFX for DEFAULT, COMMUNICATIONS, SPEECH and MEDIA when the endpoint has no mode list; admin TEMP for Add-Type; run log + trap - app: '마이크 다시 연결' launches one elevated PowerShell via ShellExecuteExW(runas) with double-quoted -File args and waits for its exit code; shows apo\mic-apo.log on failure - tests: reconnect argument splitting (Korean/space/quote/drive root) Verified on the Windows 11 VM: basic-user token gets ERROR_ACCESS_DENIED on scripts/apo/exe/ uninstall/app and write access only on data dirs; Communications-category capture receives the converted signal (440 Hz); reconnect exits 0 from a Korean+space install path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,14 +7,13 @@
|
||||
import json
|
||||
import multiprocessing as mp
|
||||
import queue
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox, ttk
|
||||
|
||||
from common import CONFIG, ROOT, SETTINGS, load_json, save_json, use_engine
|
||||
from common import ROOT, SETTINGS, load_json, save_json, use_engine
|
||||
from models import GENDERS, auto_pitch, list_models
|
||||
|
||||
LATENCY = {"낮음 (약 0.15초, GPU 여유 필요)": 128, "보통 (약 0.25초)": 250, "안정 (약 0.4초)": 400}
|
||||
@@ -32,9 +31,9 @@ def list_devices():
|
||||
|
||||
|
||||
def hooked_mics() -> list:
|
||||
"""설치할 때 마이크 모듈을 붙인 마이크들 (scripts/mic-apo.ps1 이 남긴 목록)."""
|
||||
"""설치할 때 마이크 모듈을 붙인 마이크들 (scripts/mic-apo.ps1 이 apo\\ 에 남긴 목록)."""
|
||||
try:
|
||||
items = json.loads((CONFIG / "mic-apo.json").read_text(encoding="utf-8-sig"))
|
||||
items = json.loads((ROOT / "apo" / "mic-apo.json").read_text(encoding="utf-8-sig"))
|
||||
except (OSError, ValueError):
|
||||
return []
|
||||
items = items if isinstance(items, list) else [items]
|
||||
@@ -45,13 +44,54 @@ def is_hooked(name: str, hooked: list) -> bool:
|
||||
return any(d and d in name and (not f or f in name) for d, f in hooked)
|
||||
|
||||
|
||||
def reconnect_params(root=None) -> str:
|
||||
"""관리자 PowerShell 에 넘길 인자. Windows 경로에는 " 가 들어갈 수 없어서 큰따옴표로만 감싸면 공백 · 한글 경로도 안전하다."""
|
||||
root = ROOT if root is None else root
|
||||
script, r = str(root / "scripts" / "mic-apo.ps1"), str(root)
|
||||
if r.endswith("\\"): # "D:\" 처럼 \ 로 끝나면 닫는 따옴표가 이스케이프되므로 "D:\." 로
|
||||
r += "."
|
||||
return f'-NoProfile -ExecutionPolicy Bypass -File "{script}" -Install -Root "{r}"'
|
||||
|
||||
|
||||
def mic_apo_log_tail(lines: int = 8) -> str:
|
||||
"""scripts/mic-apo.ps1 이 apo\\mic-apo.log 에 남긴 마지막 기록."""
|
||||
try:
|
||||
text = (ROOT / "apo" / "mic-apo.log").read_text(encoding="utf-8-sig", errors="replace")
|
||||
except OSError:
|
||||
return "(기록 없음)"
|
||||
return "\n".join(text.strip().splitlines()[-lines:])
|
||||
|
||||
|
||||
def reconnect_mics() -> int:
|
||||
"""관리자 권한으로 마이크 모듈을 다시 붙인다 (UAC 확인 창이 뜸). 종료 코드를 돌려준다."""
|
||||
script = ROOT / "scripts" / "mic-apo.ps1"
|
||||
inner = f"-NoProfile -ExecutionPolicy Bypass -File '{script}' -Install -Root '{ROOT}'"
|
||||
cmd = ["powershell", "-NoProfile", "-Command",
|
||||
f"$p = Start-Process powershell -Verb RunAs -Wait -PassThru -WindowStyle Hidden -ArgumentList \"{inner}\"; exit $p.ExitCode"]
|
||||
return subprocess.run(cmd, creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0)).returncode
|
||||
"""관리자 권한으로 mic-apo.ps1 -Install 을 돌린다 (UAC 확인 창이 뜸). 스크립트의 종료 코드를 돌려준다.
|
||||
ShellExecuteExW("runas") 로 PowerShell 하나만 띄우고 끝날 때까지 기다린다. -1223 = 사용자가 UAC 를 취소함."""
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
|
||||
class SHELLEXECUTEINFOW(ctypes.Structure):
|
||||
_fields_ = [("cbSize", wintypes.DWORD), ("fMask", wintypes.ULONG), ("hwnd", wintypes.HWND),
|
||||
("lpVerb", wintypes.LPCWSTR), ("lpFile", wintypes.LPCWSTR), ("lpParameters", wintypes.LPCWSTR),
|
||||
("lpDirectory", wintypes.LPCWSTR), ("nShow", ctypes.c_int), ("hInstApp", wintypes.HINSTANCE),
|
||||
("lpIDList", ctypes.c_void_p), ("lpClass", wintypes.LPCWSTR), ("hkeyClass", wintypes.HKEY),
|
||||
("dwHotKey", wintypes.DWORD), ("hIconOrMonitor", wintypes.HANDLE), ("hProcess", wintypes.HANDLE)]
|
||||
|
||||
shell32 = ctypes.WinDLL("shell32", use_last_error=True)
|
||||
k32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
||||
k32.WaitForSingleObject.argtypes = [wintypes.HANDLE, wintypes.DWORD]
|
||||
k32.GetExitCodeProcess.argtypes = [wintypes.HANDLE, ctypes.POINTER(wintypes.DWORD)]
|
||||
k32.CloseHandle.argtypes = [wintypes.HANDLE]
|
||||
sei = SHELLEXECUTEINFOW(cbSize=ctypes.sizeof(SHELLEXECUTEINFOW), fMask=0x40, # SEE_MASK_NOCLOSEPROCESS
|
||||
lpVerb="runas", lpFile="powershell.exe", lpParameters=reconnect_params(),
|
||||
lpDirectory=str(ROOT), nShow=0)
|
||||
if not shell32.ShellExecuteExW(ctypes.byref(sei)):
|
||||
return -ctypes.get_last_error()
|
||||
try:
|
||||
k32.WaitForSingleObject(sei.hProcess, 0xFFFFFFFF)
|
||||
code = wintypes.DWORD()
|
||||
k32.GetExitCodeProcess(sei.hProcess, ctypes.byref(code))
|
||||
return int(code.value)
|
||||
finally:
|
||||
k32.CloseHandle(sei.hProcess)
|
||||
|
||||
|
||||
class Converter:
|
||||
@@ -144,9 +184,7 @@ class Converter:
|
||||
f"'{mic_name}' 에 마이크 모듈이 붙어 있지 않습니다 (모듈이 붙은 마이크: {seen}).\n"
|
||||
"'마이크 다시 연결' 을 누르고, 윈도우 소리 설정에서 이 마이크의 '오디오 향상' 이 켜져 있는지 확인해 주세요."
|
||||
)
|
||||
if monitor_id is not None:
|
||||
from rvc.realtime.audio import queue_latest # noqa: F401 (엔진과 같은 모니터 큐)
|
||||
|
||||
if monitor_id is not None: # 엔진의 모니터 큐(cb.audio.mon_queue)를 헤드셋으로
|
||||
dev = sd.query_devices(monitor_id)
|
||||
api = sd.query_hostapis(dev["hostapi"])["name"]
|
||||
mon = sd.OutputStream(
|
||||
@@ -432,7 +470,12 @@ class App:
|
||||
elif kind == "reconnected":
|
||||
self.reconnect_btn.config(state="normal")
|
||||
self.load_devices()
|
||||
self.status.config(text="마이크를 다시 연결했습니다." if val == 0 else f"마이크를 연결하지 못했습니다 (코드 {val}).")
|
||||
if val == 0:
|
||||
self.status.config(text="마이크를 다시 연결했습니다.")
|
||||
else:
|
||||
self.status.config(text="마이크 연결을 취소했습니다." if val == -1223 else f"마이크를 연결하지 못했습니다 (코드 {val}).")
|
||||
if val != -1223:
|
||||
messagebox.showerror("음성 변환기", f"마이크를 연결하지 못했습니다 (코드 {val}).\n\n{mic_apo_log_tail()}")
|
||||
if self.conv.running and str(self.stop_btn["state"]) == "normal":
|
||||
if self.conv.error is not None:
|
||||
err, self.conv.error = self.conv.error, None
|
||||
|
||||
Reference in New Issue
Block a user