From c1d9242b812e4d19795fc48f4639adf31348a6d5 Mon Sep 17 00:00:00 2001 From: EJClaw Date: Wed, 11 Nov 2026 23:04:18 +0900 Subject: [PATCH] voice-changer installer 1.0.4: refuse admin-token deploy; do not carry over the v1.0.2 uninstall log Review/arbiter REVISE on 85f5782: - If the installer is started elevated ("Run as administrator", admin terminal), ExecAsOriginalUser is elevated too, so deploy.ps1 copied into the user's folder and ran its scripts with admin rights. deploy.ps1 now checks the real token first (WindowsPrincipal.IsInRole(Administrator)) and exits 33 before touching any path; the installer explains to start it by double-click. The post-install launch only runs when deploy succeeded (Check: DeployDone). - v1.0.2 and later share AppId and uninstall dir, and the default UninstallLogMode=append kept v1.0.2's entries for files in the user's folder, which the elevated uninstaller would delete through a junction. UninstallLogMode=overwrite starts a fresh log. Since pre-existing folders are then not recorded as created, the uninstaller removes Program Files\VoiceChanger's apo\ scripts\ payload\ itself and launches a detached `rmdir` for the then-empty uninstall\ and install folder (Program Files only). Windows 11 VM, Inno 6.7.4, AppVersion 1.0.4 (final build): - A: setup started from an elevated process with /DATADIR=\VCA: deploy exit 33, the folder was never created, no shortcuts; REFUSED_BEFORE_WRITE PASS. - L: deploy.ps1 under the logged-on user's limited token (Administrators deny-only) copies the app, folder owned by the user. - C (control): v1.0.2 on Desktop -> v1.0.3, unins000.dat mentions Desktop\VC2; folder swapped for a junction to admin-only C:\vctarget, uninstall deletes the target's same-named files (FAIL, the bug). - B: v1.0.2 on Desktop -> 1.0.4: unins000.dat no longer mentions it; same swap + uninstall: target files and SDDL unchanged (PASS); Program Files\VoiceChanger fully removed. - R: fresh -> reinstall -> uninstall: Program Files\VoiceChanger fully removed; FxProperties restored. - python unittest: 16 run, 2 skipped (tkinter missing). Co-Authored-By: Claude Opus 5.5 --- voice-changer/README.md | 2 +- voice-changer/installer/VoiceChanger.iss | 31 ++++++++++++++++++++---- voice-changer/installer/deploy.ps1 | 9 ++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/voice-changer/README.md b/voice-changer/README.md index 52c9e73..974283a 100644 --- a/voice-changer/README.md +++ b/voice-changer/README.md @@ -10,7 +10,7 @@ ## 설치 — `VoiceChangerSetup.exe` 하나만 -1. `VoiceChangerSetup.exe` 를 실행합니다 (관리자 권한 확인 창이 뜹니다). +1. `VoiceChangerSetup.exe` 를 **더블클릭**해서 실행합니다 (관리자 권한 확인 창이 뜹니다). "관리자 권한으로 실행" 이나 관리자 터미널로 시작하면 앱 파일을 복사하지 않고 안내만 합니다 (고른 폴더는 내 계정 권한으로만 다루기 때문). 2. **설치할 폴더**를 고릅니다. 기본값은 `C:\VoiceChanger` 이고, 다른 드라이브(`D:\...`)나 한글 · 띄어쓰기가 들어간 경로도 됩니다. 비어 있는 폴더나 새 폴더만 됩니다 (다른 파일이 든 폴더는 거절합니다). 바탕 화면 · 문서 아래(예: `바탕 화면\VoiceChanger`)도 됩니다. OneDrive 로 동기화되는 폴더를 고르면 한 번 더 묻습니다. 앱 · Python · 엔진 · torch · 목소리 모델 · 설정 · 학습 파일 · 캐시 · 임시 파일이 **모두 이 폴더 안에만** 저장됩니다. diff --git a/voice-changer/installer/VoiceChanger.iss b/voice-changer/installer/VoiceChanger.iss index 82638dc..2564e58 100644 --- a/voice-changer/installer/VoiceChanger.iss +++ b/voice-changer/installer/VoiceChanger.iss @@ -35,6 +35,9 @@ Compression=lzma2 SolidCompression=yes WizardStyle=modern UninstallFilesDir={app}\uninstall +; 이전 제거 기록을 이어 쓰지 않는다. v1.0.2 의 기록에는 고른 폴더(바탕 화면 등)의 파일이 들어 있어서, +; 이어 쓰면 제거할 때 관리자 권한으로 그 경로의 파일을 지우게 된다 (정션으로 바꿔치면 다른 곳의 같은 이름 파일이 지워짐) +UninstallLogMode=overwrite UninstallDisplayIcon={app}\payload\VoiceChanger.exe UninstallDisplayName={#AppName} @@ -61,7 +64,7 @@ Type: files; Name: "{autoprograms}\{#AppName}.lnk" Type: files; Name: "{autodesktop}\{#AppName}.lnk" [Run] -Filename: "{code:DataDir}\VoiceChanger.exe"; Description: "음성 변환기 실행"; Flags: postinstall nowait skipifsilent unchecked runasoriginaluser +Filename: "{code:DataDir}\VoiceChanger.exe"; Description: "음성 변환기 실행"; Flags: postinstall nowait skipifsilent unchecked runasoriginaluser; Check: DeployDone [UninstallRun] Filename: "powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\scripts\mic-apo.ps1"" -Uninstall -Root ""{app}"""; Flags: runhidden waituntilterminated; RunOnceId: "MicApoUninstall" @@ -73,6 +76,7 @@ const var DataPage: TInputDirWizardPage; LegacyOld: String; + DeployOk: Boolean; UninstDataDir: String; { Program Files\VoiceChanger. 설치 폴더 상수와 같지만 그 상수는 InitializeWizard 때 아직 정해지지 않아서 따로 둔다 } @@ -81,6 +85,13 @@ begin Result := ExpandConstant('{commonpf}\VoiceChanger'); end; +{ 앱 복사가 사용자 권한으로 끝났을 때만 설치 뒤 바로 실행한다. + 설치 프로그램을 관리자 권한으로 시작하면 "원래 사용자" 도 관리자라 deploy.ps1 이 거부(33)하고, 실행도 하지 않는다 } +function DeployDone: Boolean; +begin + Result := DeployOk; +end; + function DataDir(Param: String): String; begin Result := RemoveBackslashUnlessRoot(DataPage.Values[0]); @@ -268,8 +279,12 @@ begin if not ExecAsOriginalUser(PowerShellExe, Args, ExpandConstant('{app}'), SW_SHOWNORMAL, ewWaitUntilTerminated, Code) then Code := -1; Log('deploy exit=' + IntToStr(Code)); + DeployOk := Code = 0; case Code of 0: ; + 33: SuppressibleMsgBox('설치 프로그램이 관리자 권한으로 시작되어 앱 파일을 복사하지 않았습니다.' + #13#10 + + '관리자 권한으로 실행하지 말고 VoiceChangerSetup.exe 를 그냥 더블클릭해서 다시 설치해 주세요.' + #13#10 + + '(관리자 권한 확인 창이 뜨는 것은 정상입니다)', mbError, MB_OK, IDOK); 31: SuppressibleMsgBox(DataDir('') + ' 이 다른 곳을 가리키는 링크(정션)라서 앱을 복사하지 않았습니다.' + #13#10 + '링크를 지우거나 다른 폴더를 골라 다시 설치해 주세요.', mbError, MB_OK, IDOK); 32: SuppressibleMsgBox(DataDir('') + ' 에 앱 파일을 복사하지 못했습니다 (쓰기 권한이 없는 폴더일 수 있습니다).' + #13#10 + @@ -290,6 +305,8 @@ begin end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); +var + Code: Integer; begin if CurUninstallStep = usUninstall then begin @@ -299,10 +316,14 @@ begin end; { 마이크 되돌리기([UninstallRun])와 설치 파일 지우기가 끝난 뒤 } if CurUninstallStep <> usPostUninstall then Exit; - DeleteFile(ExpandConstant('{app}\apo\mic-apo.log')); - RemoveDir(ExpandConstant('{app}\apo')); - RemoveDir(ExpandConstant('{app}\scripts')); - RemoveDir(ExpandConstant('{app}')); + { Program Files 쪽(관리자만 쓰는 곳)은 남은 기록 · 빈 폴더까지 지운다. + 제거 기록을 이어 쓰지 않아서(overwrite) 업그레이드 전부터 있던 폴더는 Inno 가 지우지 않는다. 제거 프로그램 파일은 + 이 뒤에 지워지므로, 끝난 뒤 빈 uninstall 폴더와 설치 폴더를 지우는 cmd 를 따로 띄운다 (rmdir 은 빈 폴더만 지움) } + DelTree(ExpandConstant('{app}\apo'), True, True, True); + DelTree(ExpandConstant('{app}\scripts'), True, True, True); + DelTree(ExpandConstant('{app}\payload'), True, True, True); + Exec(ExpandConstant('{cmd}'), '/c ping -n 4 127.0.0.1 >nul & rmdir "' + ExpandConstant('{app}\uninstall') + '" & rmdir "' + ExpandConstant('{app}') + '"', + '', SW_HIDE, ewNoWait, Code); { 고른 폴더는 관리자 권한으로 지우지 않는다 (정션으로 바꿔쳐 다른 곳을 지우게 만들 수 있음). 내 계정 폴더라 직접 지울 수 있다 } if (UninstDataDir <> '') and DirExists(UninstDataDir) and not UninstallSilent then MsgBox('마이크 설정을 되돌리고 프로그램을 지웠습니다.' + #13#10#13#10 + diff --git a/voice-changer/installer/deploy.ps1 b/voice-changer/installer/deploy.ps1 index 161ecb1..e48a5ff 100644 --- a/voice-changer/installer/deploy.ps1 +++ b/voice-changer/installer/deploy.ps1 @@ -7,9 +7,16 @@ # - v1.0.2: 고른 폴더가 관리자 소유로 잠겨 있으면, 상위 폴더가 내 것일 때 이름을 바꿔 비켜 두고 새로 만든다 # 2. Program Files\VoiceChanger\payload 의 앱 파일을 복사한다 # 3. scripts\install.ps1 로 Python · 엔진 · 기본 모델을 받는다 -# 종료 코드: 0 성공, 31 고른 폴더가 링크(정션), 32 폴더를 만들거나 복사하지 못함, 그 밖 = install.ps1 실패 +# 종료 코드: 0 성공, 31 고른 폴더가 링크(정션), 32 폴더를 만들거나 복사하지 못함, +# 33 관리자 권한으로 실행됨(설치 프로그램을 관리자 권한으로 시작하면 "원래 사용자" 도 관리자), 그 밖 = install.ps1 실패 param([Parameter(Mandatory)][string]$Data, [string]$From) $ErrorActionPreference = 'Stop' +# 경로를 건드리기 전에 실제 토큰을 확인한다. 관리자 권한이면 이 스크립트가 지키려는 분리가 없어지므로 아무것도 하지 않는다 +$me = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) +if ($me.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Host "[deploy] 관리자 권한으로 실행되어 중단합니다. 설치 프로그램을 그냥 더블클릭해서 실행해 주세요." + exit 33 +} [Console]::OutputEncoding = [Text.Encoding]::UTF8 $Payload = Join-Path (Split-Path -Parent $PSScriptRoot) 'payload' $DataDirs = 'models', 'training', 'datasets', 'config', 'cache', 'env', 'engine', 'tools'