Files
EJClaw 85f5782876 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>
2026-11-11 22:51:52 +09:00

85 lines
5.7 KiB
PowerShell

# v1.0.0 · v1.0.1 이 설치한 폴더 정리 (설치 프로그램이 관리자 권한으로 {tmp} 에서 실행).
# 그 버전은 고른 폴더를 관리자 소유로 잠그고 그 안에 실행 파일 · 제거 프로그램 · 마이크 모듈을 두었다.
# 이제 앱 파일은 사용자 권한으로 복사하므로(deploy.ps1), 관리자 권한으로 하는 일은 이것뿐이다:
# 이전 실행 부분을 이름을 지정해 지우고, 마이크 백업을 Program Files 쪽으로 옮기고, 폴더 이름을 -Old 로 바꾼다.
# 남은 데이터 폴더(models · config · env 등, 일반 사용자가 쓸 수 있음)는 deploy.ps1 이 사용자 권한으로 새 폴더에 옮긴다.
# 관리자가 아닌 누구도 이 폴더나 그 위 폴더를 지우거나 이름을 바꿀 수 없을 때만 한다 (소유자 · ACL 로 확인).
# 그래야 일반 사용자가 이 작업 도중에 경로를 다른 곳을 가리키는 정션으로 바꿔칠 수 없다. ACL 은 관리자만 바꿀 수 있어서
# 확인한 뒤에도 그대로다. v1.0.0 · v1.0.1 은 상위가 관리자 소유인 곳에만 설치했고 폴더를 이렇게 잠갔다.
# -App <고른 폴더> -Sys <Program Files\VoiceChanger> -Old <새 이름 전체 경로>
# 종료 코드: 0 = 이전 버전 폴더 아님(할 일 없음), 1 = 정리하고 -Old 로 옮김,
# 20 = 이전 버전 폴더지만 안전하게 다룰 수 없음, 22 = -Old 가 이미 있음, 12 = 실패
param([Parameter(Mandatory)][string]$App, [Parameter(Mandatory)][string]$Sys, [Parameter(Mandatory)][string]$Old)
$ErrorActionPreference = 'Stop'
$SY = 'S-1-5-18'; $BA = 'S-1-5-32-544'
$TI = 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464'
$Sid = [System.Security.Principal.SecurityIdentifier]
$App = [IO.Path]::GetFullPath($App).TrimEnd('\')
function Say($m) { Write-Host "[legacy] $m" }
function Is-Link([string]$p) { ([IO.File]::GetAttributes($p) -band [IO.FileAttributes]::ReparsePoint) -ne 0 }
function Owner-Sid([string]$p) { (Get-Acl -LiteralPath $p).GetOwner($Sid).Value }
# 관리자가 아닌 사람이 $p 를 지우거나 이름을 바꿀 수 있는지: 소유자가 관리자가 아니거나,
# $p 에 DELETE · WRITE_DAC · WRITE_OWNER · GENERIC_ALL, 또는 상위 폴더에 DELETE_CHILD · WRITE_DAC · WRITE_OWNER · GENERIC_ALL 을 주는 항목이 있으면 그렇다
$Admins = @($SY, $BA, $TI)
function Grants([string]$p, [int]$bits) {
$acl = Get-Acl -LiteralPath $p
@($acl.GetAccessRules($true, $true, $Sid) | Where-Object { $_.AccessControlType -eq 'Allow' -and
($_.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 -and
$_.IdentityReference.Value -notin $Admins -and ([int]$_.FileSystemRights -band $bits) }).Count -gt 0
}
function Swappable([string]$p) {
$parent = Split-Path -Parent $p
if (-not $parent) { return $false } # 드라이브 루트는 지우거나 이름을 바꿀 수 없음
if ((Owner-Sid $p) -notin $Admins) { return $true }
if (Grants $p (0x10000 -bor 0x40000 -bor 0x80000 -bor 0x10000000)) { return $true }
if (Grants $parent (0x40 -bor 0x40000 -bor 0x80000 -bor 0x10000000)) { return $true }
return $false
}
try {
if (-not (Test-Path -LiteralPath (Join-Path $App 'uninstall\unins000.exe'))) { exit 0 }
$p = $App
while ($p) {
if ((Is-Link $p) -or (Swappable $p)) { Say "안전하게 다룰 수 없음: $p (link=$(Is-Link $p) owner=$(Owner-Sid $p))"; exit 20 }
$p = Split-Path -Parent $p
}
if (Test-Path -LiteralPath $Old) { Say "이미 있음: $Old"; exit 22 }
# 이전 배포의 실행 부분만 이름을 지정해 지운다. 목록에 없는 파일은 남겨 두고 폴더째 -Old 로 옮긴다.
$known = [ordered]@{
'.' = @('VoiceChanger.exe', 'install.bat', 'train.bat', 'examples.bat', 'README.md')
'scripts' = @('install.ps1', 'mic-apo.ps1')
'app' = @('common.py', 'examples.py', 'mic_bridge.py', 'models.py', 'record_servers.py', 'setup_engine.py', 'train.py', 'voice_changer.py')
'launcher' = @('launcher.c')
'apo' = @('VoiceChangerAPO.dll', 'vcapo.cpp', 'vccore.h', 'vcapo.def', 'mic-apo.json', 'mic-apo.log')
'uninstall' = @('unins*.exe', 'unins*.dat', 'unins*.msg')
'app\__pycache__' = @('*.pyc')
}
$n = 0
foreach ($d in $known.Keys) {
$dir = if ($d -eq '.') { $App } else { Join-Path $App $d }
if (-not (Test-Path -LiteralPath $dir -PathType Container)) { continue }
foreach ($pat in $known[$d]) {
Get-ChildItem -LiteralPath $dir -Force -File -Filter $pat | ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force; $n++ }
}
}
# 마이크 설정 백업 (apo\ 는 관리자만 쓰던 폴더). mic-apo.ps1 이 Program Files 쪽에서 읽고 값을 다시 검증한다
$bk = Join-Path $App 'apo\mic-apo-backup.json'
$sysBk = Join-Path $Sys 'apo\mic-apo-backup.json'
if ((Test-Path -LiteralPath $bk) -and -not (Test-Path -LiteralPath $sysBk)) {
New-Item -ItemType Directory -Force -Path (Split-Path $sysBk) | Out-Null
Move-Item -LiteralPath $bk -Destination $sysBk
Say "마이크 백업을 옮김: $sysBk"
}
foreach ($d in 'app\__pycache__', 'app', 'scripts', 'launcher', 'uninstall', 'apo') { # 비었을 때만
$dir = Join-Path $App $d
if ((Test-Path -LiteralPath $dir) -and -not [IO.Directory]::EnumerateFileSystemEntries($dir).GetEnumerator().MoveNext()) { Remove-Item -LiteralPath $dir -Force }
}
Rename-Item -LiteralPath $App -NewName (Split-Path -Leaf $Old)
Say "이전 배포 파일 $n 개를 지우고 $Old 로 옮김"
exit 1
} catch {
Say "실패: $($_.Exception.Message)"
exit 12
}