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:
EJClaw
2026-11-11 18:00:20 +09:00
parent 21b4278b77
commit ffc553851a
5 changed files with 248 additions and 36 deletions

View File

@@ -1,7 +1,8 @@
# 마이크 APO 등록 · 해제 (관리자 권한). 설치 프로그램과 앱의 "마이크 다시 연결" 버튼이 실행한다.
# mic-apo.ps1 -Install [-Root <설치 폴더>] 마이크마다 APO 를 붙이고 오디오 서비스를 다시 시작
# mic-apo.ps1 -Uninstall [-Root <설치 폴더>] 원래 설정으로 되돌림
# 바꾼 레지스트리 값의 원래 값은 <설치 폴더>\config\mic-apo-backup.json 에 남겨 두고 해제할 때 되돌린다.
# 바꾼 레지스트리 값의 원래 값은 <설치 폴더>\apo\mic-apo-backup.json 에 남겨 두고 해제할 때 되돌린다.
# apo\ 는 관리자만 쓸 수 있는 폴더다 (일반 사용자가 백업을 바꿔 관리자 권한으로 레지스트리를 쓰게 만들 수 없게).
param([switch]$Install, [switch]$Uninstall, [string]$Root)
$ErrorActionPreference = 'Stop'
if (-not $Root) { $Root = Split-Path -Parent $PSScriptRoot }
@@ -10,15 +11,30 @@ $Root = (Resolve-Path $Root).Path
# apo/vcapo.cpp 의 CLSID_VoiceChangerAPO 와 같아야 한다
$Clsid = '{6F1C5E2A-3B7D-4C41-9A0E-5D2B8F61C437}'
$Dll = Join-Path $Root 'apo\VoiceChangerAPO.dll'
$Config = Join-Path $Root 'config'
$Config = Join-Path $Root 'apo'
$BackupFile = Join-Path $Config 'mic-apo-backup.json'
$ListFile = Join-Path $Config 'mic-apo.json'
$ListFile = Join-Path $Config 'mic-apo.json' # 앱이 읽는 "모듈을 붙인 마이크" 목록
# 실행 기록은 관리자만 쓸 수 있는 apo\mic-apo.log 에 남긴다 (앱이 실패 이유를 보여 줄 때 읽음)
$LogFile = Join-Path $Config 'mic-apo.log'
function Write-RunLog($m) { try { Add-Content -Path $LogFile -Value "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] $m" -Encoding UTF8 } catch {} }
trap { Write-RunLog ("실패: " + ($_ | Out-String).Trim()); Write-Host "[mic-apo] 실패: $($_.Exception.Message)"; exit 1 }
# 관리자 권한으로 도는 스크립트라 임시 파일(Add-Type 컴파일 결과 등)은 관리자만 쓰는 Windows 임시 폴더에 둔다.
# 앱이 물려준 TEMP(설치 폴더의 cache\temp)는 일반 사용자도 쓸 수 있는 곳이라 쓰지 않는다.
$env:TEMP = Join-Path $env:SystemRoot 'Temp'; $env:TMP = $env:TEMP
Write-RunLog ("시작: " + $(if ($Install) { '-Install' } elseif ($Uninstall) { '-Uninstall' } else { '(없음)' }))
$Capture = 'SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Capture'
$FX = '{d04e05a6-594b-4fb6-a80d-01af5eed7d1d}'
$SFX = "$FX,5" # PKEY_FX_StreamEffectClsid
$SFX_COMPOSITE = "$FX,13" # PKEY_CompositeFX_StreamEffectClsid (여러 개를 차례로)
$SFX_MODES = '{d3993a3f-99c2-4402-b5ec-a92a0367664b},5' # SFX 가 맡는 처리 모드 (없으면 기본 모드를 넣음)
$DEFAULT_MODE = '{C18E2F7E-933D-4965-B7D1-1EEF228D2AF3}'
$SFX_MODES = '{d3993a3f-99c2-4402-b5ec-a92a0367664b},5' # SFX 가 맡는 처리 모드 (없을 때만 아래 목록을 넣음)
# 녹음 쪽 처리 모드 (ksmedia.h AUDIO_SIGNALPROCESSINGMODE_*): 기본 · 통화(디스코드 등 VoIP) · 음성 · 미디어.
# RAW 는 "처리 없이" 를 요청한 스트림이라 넣지 않는다.
$CAPTURE_MODES = @(
'{C18E2F7E-933D-4965-B7D1-1EEF228D2AF3}', # DEFAULT
'{98951333-B9CD-48B1-A0A3-FF40682D73F7}', # COMMUNICATIONS
'{FC1CFC9B-B9D6-4CFA-B5E0-4BB2166878B2}', # SPEECH
'{4780004E-7133-41D8-8C74-660DADD2C0EE}' # MEDIA
)
$DISABLE_SYSFX = '{1da5d803-d492-4edd-8c23-e0c0ffee7f0e},5' # "오디오 향상 끔" (FxProperties 에 있음)
$DESC = '{a45c254e-df1c-4efd-8020-67d146a850e0},2'
$IFACE = '{b3f8fa53-0004-438e-9003-51a46e139bfc},6'
@@ -45,7 +61,7 @@ $Admins = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544'
$RW = [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree
$Rights = [System.Security.AccessControl.RegistryRights]
function Log($m) { Write-Host "[mic-apo] $m" }
function Log($m) { Write-Host "[mic-apo] $m"; Write-RunLog $m }
# MMDevices 의 마이크 키에서 관리자는 값 읽기 · 쓰기만 되고 하위 키는 못 만든다.
# 그래서 값은 그 권한으로만 바꾼다. FxProperties 키가 아예 없는 마이크에서만 잠깐 소유권을 가져와
@@ -172,7 +188,8 @@ function Install-Apo {
} else {
$fx.SetValue($SFX, $Clsid, 'String')
}
if (-not ($fx.GetValueNames() -contains $SFX_MODES)) { $fx.SetValue($SFX_MODES, [string[]]@($DEFAULT_MODE), 'MultiString') }
# 드라이버가 이미 모드 목록을 갖고 있으면 그대로 둔다 (드라이버 효과가 지원하지 않는 모드를 억지로 켜지 않게)
if (-not ($fx.GetValueNames() -contains $SFX_MODES)) { $fx.SetValue($SFX_MODES, [string[]]$CAPTURE_MODES, 'MultiString') }
# 사용자가 "오디오 향상" 을 꺼 두면 APO 가 통째로 빠지므로 켠다 (해제할 때 되돌림)
if ($fx.GetValueNames() -contains $DISABLE_SYSFX) { $fx.DeleteValue($DISABLE_SYSFX) }
$fx.Close()
@@ -212,4 +229,12 @@ function Uninstall-Apo {
Restart-Audio
}
if ($Install) { Install-Apo } elseif ($Uninstall) { Uninstall-Apo } else { throw '-Install 또는 -Uninstall 을 주세요' }
try {
if ($Install) { Install-Apo } elseif ($Uninstall) { Uninstall-Apo } else { throw '-Install 또는 -Uninstall 을 주세요' }
Write-RunLog '끝: 성공'
exit 0
} catch {
Write-RunLog ("실패: " + ($_ | Out-String).Trim())
Write-Host "[mic-apo] 실패: $($_.Exception.Message)"
exit 1
}