voice-changer installer: never touch the chosen folder with admin rights (1.0.3)

Review of c24cd1f: with a user-owned parent (Desktop), the user could swap the chosen folder for a junction
to a protected folder after secure-dir Prepare, and the elevated Finish would grant Users modify on the
target's config\ etc. Any elevated path operation on a user-controlled path has this race, so the elevated
installer now only works in Program Files.

- VoiceChanger.iss: {app} is always {commonpf}\VoiceChanger (apo\, scripts\mic-apo.ps1, scripts\deploy.ps1,
  uninstall\, payload\). The user's folder comes from a custom page (/DATADIR=, previous DataDir, or the
  v1.0.x App Path) and is only read for checks. deploy.ps1 runs with ExecAsOriginalUser: copies payload,
  moves data folders of an older install, runs install.ps1. Shortcuts are created after the copy
  (CreateShellLink; [Icons] made empty-target links) and the postinstall launch runs as the original user.
  Uninstall restores the mic settings and removes Program Files only; the user's folder is left (message).
- legacy.ps1 (replaces secure-dir.ps1): for a v1.0.0/1.0.1 folder (admin-locked, uninstall\ inside) deletes the
  old executable parts by name, moves the mic backup to Program Files and renames the folder to <dir>.old,
  only if no non-admin principal can delete/rename the folder or any ancestor (owner + ACL check; ACLs can
  only be changed by admins, so the check stays valid during the operation). Otherwise refuses (exit 20).
- deploy.ps1 (user level): refuses a junction; a v1.0.2 admin-locked folder under a user-owned parent is
  renamed aside by the user and its data folders moved into a fresh folder.
- mic-apo.ps1: back to its pre-c24cd1f logic (no -From); header documents the Program Files root.

Windows 11 VM, Inno 6.7.4, AppVersion 1.0.3:
- J: chosen folder = junction to admin-owned C:\vctarget (config\keep.txt, protected ACL): setup exit 0,
  legacy exit 0, deploy exit 31; target files + SDDL unchanged after setup, after limited-token deploy
  (exit 31), after limited-token write/icacls/rename attempts (all denied), and after uninstall.
- J2: same target with uninstall\unins000.exe: legacy exit 20, setup aborted (exit 7), target unchanged.
- U1: v1.0.1 at C:\VoiceChanger -> 1.0.3 with the default folder: legacy exit 1, backup moved byte-equal,
  models\mine.txt kept, C:\VoiceChanger.old removed, APO from Program Files; uninstall restores FxProperties.
- U2: v1.0.2 on Desktop -> limited-token deploy renamed it aside, moved models, new folder owned by the user;
  1.0.3 setup on it exit 0; uninstall restores FxProperties, folder and models kept.
- D: fresh Desktop install with full engine download: deploy exit 0, admin_root = Program Files,
  audiodg loads the Program Files DLL, APO 440 Hz + Communications PASS, Start menu/desktop shortcuts point
  at <Desktop>\VoiceChanger\VoiceChanger.exe and are removed on uninstall.
- python unittest: 16 run, 2 skipped (tkinter missing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-11 22:51:52 +09:00
parent c24cd1f9c0
commit 85f5782876
6 changed files with 326 additions and 295 deletions

View File

@@ -1,11 +1,11 @@
# 마이크 APO 등록 · 해제 (관리자 권한). 설치 프로그램과 앱의 "마이크 다시 연결" 버튼이 실행한다.
# mic-apo.ps1 -Install [-Root <폴더>] [-From <이전 설치 폴더>] 마이크마다 APO 를 붙이고 오디오 서비스를 다시 시작
# mic-apo.ps1 -Uninstall [-Root <폴더>] 원래 설정으로 되돌림
# mic-apo.ps1 -Install [-Root <폴더>] 마이크마다 APO 를 붙이고 오디오 서비스를 다시 시작
# mic-apo.ps1 -Uninstall [-Root <폴더>] 원래 설정으로 되돌림
# <폴더> 는 apo\ 가 있는 곳이다. 설치 프로그램은 Program Files\VoiceChanger, zip 으로 풀어 쓰면 그 폴더.
# 바꾼 레지스트리 값의 원래 값은 <폴더>\apo\mic-apo-backup.json 에 남겨 두고 해제할 때 되돌린다.
# (v1.0.1 까지 고른 폴더의 apo\ 에 있던 백업은 설치 프로그램의 legacy.ps1 이 이 자리로 옮긴다)
# apo\ 는 관리자만 쓸 수 있는 폴더다 (일반 사용자가 백업을 바꿔 관리자 권한으로 레지스트리를 쓰게 만들 수 없게).
# -From: 이전 버전이 백업을 둔 앱 폴더 (21b4278 은 config\, v1.0.1 까지는 앱 폴더의 apo\). 값을 검증한 뒤 옮긴다.
param([switch]$Install, [switch]$Uninstall, [string]$Root, [string]$From)
param([switch]$Install, [switch]$Uninstall, [string]$Root)
$ErrorActionPreference = 'Stop'
if (-not $Root) { $Root = Split-Path -Parent $PSScriptRoot }
$Root = (Resolve-Path $Root).Path
@@ -16,8 +16,7 @@ $Dll = Join-Path $Root 'apo\VoiceChangerAPO.dll'
$Config = Join-Path $Root 'apo'
$BackupFile = Join-Path $Config 'mic-apo-backup.json'
$ListFile = Join-Path $Config 'mic-apo.json' # 앱이 읽는 "모듈을 붙인 마이크" 목록
$OldDirs = @($Root) + @(if ($From -and (Test-Path -LiteralPath $From)) { (Resolve-Path -LiteralPath $From).Path })
$OldListFiles = @($OldDirs | ForEach-Object { Join-Path $_ 'config\mic-apo.json' }) # 이전 버전(21b4278)의 목록 위치 (설치 · 제거 때 지움)
$OldListFile = Join-Path $Root 'config\mic-apo.json' # 이전 버전(21b4278)의 목록 위치 (설치 · 제거 때 지움)
# 실행 기록은 관리자만 쓸 수 있는 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 {} }
@@ -163,11 +162,8 @@ function Current-Original([string]$sub) {
function Load-Backup {
$b = @{}
$src = $BackupFile
if (-not (Test-Path -LiteralPath $src)) {
$old = @(foreach ($d in $OldDirs) { Join-Path $d 'apo\mic-apo-backup.json'; Join-Path $d 'config\mic-apo-backup.json' }) |
Where-Object { $_ -ne $BackupFile -and (Test-Path -LiteralPath $_) } | Select-Object -First 1
if ($old) { $src = $old; Log "이전 백업을 옮김: $old" }
}
$old = Join-Path $Root 'config\mic-apo-backup.json' # 이전 버전(21b4278)의 위치
if (-not (Test-Path $src) -and (Test-Path $old)) { $src = $old; Log "이전 백업을 옮김: $old" }
if (Test-Path $src) {
try { $j = Get-Content $src -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $j = $null; Log "백업을 읽지 못함: $src" }
if ($j) {
@@ -185,11 +181,9 @@ function Load-Backup {
}
}
}
if ($src -ne $BackupFile) {
if ($src -eq $old) {
Save-Backup $b
Remove-Item -LiteralPath $src -Force -ErrorAction SilentlyContinue
$d = Split-Path $src # v1.0.1 까지의 앱 폴더 apo\ 는 비었으면 지운다
if ((Split-Path -Leaf $d) -eq 'apo' -and -not (Get-ChildItem -LiteralPath $d -Force)) { Remove-Item -LiteralPath $d -Force }
Remove-Item -Force $old -ErrorAction SilentlyContinue
}
return $b
}
@@ -276,7 +270,7 @@ function Install-Apo {
}
New-Item -ItemType Directory -Force $Config | Out-Null
ConvertTo-Json -InputObject @($done) -Depth 3 | Set-Content $ListFile -Encoding UTF8
Remove-Item -Force $OldListFiles -ErrorAction SilentlyContinue
Remove-Item -Force $OldListFile -ErrorAction SilentlyContinue
Restart-Audio
if ($done.Count -eq 0) { throw '마이크를 하나도 연결하지 못했습니다' }
}
@@ -301,7 +295,7 @@ function Uninstall-Apo {
foreach ($sub in @("SOFTWARE\Classes\AudioEngine\AudioProcessingObjects\$Clsid", "SOFTWARE\Classes\CLSID\$Clsid")) {
if ($HKLM.OpenSubKey($sub)) { $HKLM.DeleteSubKeyTree($sub) }
}
Remove-Item -Force (@($BackupFile, $ListFile) + $OldListFiles) -ErrorAction SilentlyContinue
Remove-Item -Force $BackupFile, $ListFile, $OldListFile -ErrorAction SilentlyContinue
Restart-Audio
}