voice-changer: lock install folder ownership, migrate old mic backup, refresh comm modes on upgrade
- installer/secure-dir.ps1 (run elevated from tmp): CheckParent: refuse folders whose nearest existing parent is not a drive root or owned by Administrators/SYSTEM/TrustedInstaller. Prepare (before files are copied): owner Administrators + protected DACL (SY/BA full, Users RX), verify, abort setup on failure; refuse links pointing outside the folder; on upgrade delete the old executable parts (scripts/app/launcher/uninstall/root files) that21b4278left user-writable. Finish: Users modify only on data dirs; verify every admin-run file is admin-owned and not user-writable, otherwise skip APO registration and engine download. - mic-apo.ps1: migrate config\mic-apo-backup.json to apo\ with value validation (CLSID/mode GUID/ DWORD only, own CLSID stripped), never record our own APO as the original value, upgrade the DEFAULT-only mode list written by21b4278to DEFAULT/COMMUNICATIONS/SPEECH/MEDIA, remove the old config\mic-apo.json. Windows 11 VM: user-precreated folder -> owner BA, basic-user WRITE_DAC/WRITE_OWNER/grant/icacls/ write/rename all ERROR_ACCESS_DENIED; user-owned parent refused (CheckParent exit 20);21b4278install -> upgrade: backup migrated, modes refreshed, Communications capture 440 Hz, uninstall restores FxProperties to the pre-install state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,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' # 앱이 읽는 "모듈을 붙인 마이크" 목록
|
||||
$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 {} }
|
||||
@@ -104,18 +105,84 @@ function Set-Val($key, [string]$name, $v) {
|
||||
$key.SetValue($name, $data, [Microsoft.Win32.RegistryValueKind]$v.kind)
|
||||
}
|
||||
|
||||
# 백업 값 검증. 이전 버전 백업(config\, 일반 사용자 쓰기 폴더)은 그대로 믿지 않는다.
|
||||
# 허용: null, CLSID 문자열, CLSID 목록, 알려진 처리 모드 GUID 목록, DISABLE_SYSFX(0/1). 이 APO 자신의 CLSID 는 "원래 값" 에서 뺀다.
|
||||
$GuidRe = '^\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\}$'
|
||||
$KNOWN_MODES = $CAPTURE_MODES + @(
|
||||
'{9E90EA20-B493-4FD1-A1A8-7E1361A956CF}', # RAW
|
||||
'{B26FEB0D-EC94-477C-9494-D1AB8E753F6E}', # MOVIE
|
||||
'{9CF2A70B-F377-403B-BD6B-360863E0355C}' # NOTIFICATION
|
||||
)
|
||||
function Clean-Val([string]$field, $v) {
|
||||
if ($null -eq $v) { return @{ ok = $true; v = $null } }
|
||||
$kind = [string]$v.kind; $data = $v.data
|
||||
switch ($field) {
|
||||
'sfx' {
|
||||
if ($kind -ne 'String' -or [string]$data -notmatch $GuidRe) { break }
|
||||
if ([string]$data -eq $Clsid) { return @{ ok = $true; v = $null } }
|
||||
return @{ ok = $true; v = @{ kind = 'String'; data = [string]$data } }
|
||||
}
|
||||
'sfx_composite' {
|
||||
$list = @($data | ForEach-Object { [string]$_ })
|
||||
if ($kind -ne 'MultiString' -or @($list | Where-Object { $_ -notmatch $GuidRe }).Count) { break }
|
||||
$list = @($list | Where-Object { $_ -ne $Clsid })
|
||||
if ($list.Count -eq 0) { return @{ ok = $true; v = $null } }
|
||||
return @{ ok = $true; v = @{ kind = 'MultiString'; data = [string[]]$list } }
|
||||
}
|
||||
'sfx_modes' {
|
||||
$list = @($data | ForEach-Object { [string]$_ })
|
||||
if ($kind -ne 'MultiString' -or $list.Count -eq 0 -or @($list | Where-Object { $KNOWN_MODES -notcontains $_ }).Count) { break }
|
||||
return @{ ok = $true; v = @{ kind = 'MultiString'; data = [string[]]$list } }
|
||||
}
|
||||
'disable_sysfx' {
|
||||
if ($kind -ne 'DWord' -or ($data -ne 0 -and $data -ne 1)) { break }
|
||||
return @{ ok = $true; v = @{ kind = 'DWord'; data = [int]$data } }
|
||||
}
|
||||
}
|
||||
return @{ ok = $false; v = $null }
|
||||
}
|
||||
|
||||
# 지금 레지스트리 값을 "원래 값" 으로 남길 때. 이전 설치가 넣은 이 APO 흔적은 뺀다.
|
||||
function Current-Original([string]$sub) {
|
||||
$fx = $HKLM.OpenSubKey("$sub\FxProperties")
|
||||
$e = @{}
|
||||
foreach ($f in @(@('sfx', $SFX), @('sfx_composite', $SFX_COMPOSITE), @('sfx_modes', $SFX_MODES), @('disable_sysfx', $DISABLE_SYSFX))) {
|
||||
$r = Clean-Val $f[0] (Get-Val $fx $f[1])
|
||||
$e[$f[0]] = $r.v
|
||||
}
|
||||
$cur = Get-Val $fx $SFX
|
||||
$modes = Get-Val $fx $SFX_MODES
|
||||
# SFX 가 이 APO 이고 모드가 기본 하나뿐이면 이전 버전이 만든 목록이다
|
||||
if ($cur -and $cur.data -eq $Clsid -and $modes -and @($modes.data).Count -eq 1 -and @($modes.data)[0] -eq $CAPTURE_MODES[0]) { $e.sfx_modes = $null }
|
||||
return $e
|
||||
}
|
||||
|
||||
function Load-Backup {
|
||||
$b = @{}
|
||||
if (Test-Path $BackupFile) {
|
||||
$j = Get-Content $BackupFile -Raw -Encoding UTF8 | ConvertFrom-Json
|
||||
foreach ($p in $j.PSObject.Properties) {
|
||||
$e = @{}
|
||||
foreach ($q in $p.Value.PSObject.Properties) {
|
||||
$e[$q.Name] = if ($null -eq $q.Value) { $null } else { @{ kind = $q.Value.kind; data = $q.Value.data } }
|
||||
$src = $BackupFile
|
||||
$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) {
|
||||
foreach ($p in $j.PSObject.Properties) {
|
||||
if ($p.Name -notmatch $GuidRe -or -not $HKLM.OpenSubKey("$Capture\$($p.Name)")) { Log "백업 항목 무시: $($p.Name)"; continue }
|
||||
$fallback = Current-Original "$Capture\$($p.Name)"
|
||||
$e = @{}
|
||||
foreach ($f in 'sfx', 'sfx_composite', 'sfx_modes', 'disable_sysfx') {
|
||||
$raw = $p.Value.$f
|
||||
$in = if ($null -eq $raw) { $null } else { @{ kind = $raw.kind; data = $raw.data } }
|
||||
$r = Clean-Val $f $in
|
||||
if ($r.ok) { $e[$f] = $r.v } else { $e[$f] = $fallback[$f]; Log "백업 값 거부($f): $($p.Name)" }
|
||||
}
|
||||
$b[$p.Name] = $e
|
||||
}
|
||||
$b[$p.Name] = $e
|
||||
}
|
||||
}
|
||||
if ($src -eq $old) {
|
||||
Save-Backup $b
|
||||
Remove-Item -Force $old -ErrorAction SilentlyContinue
|
||||
}
|
||||
return $b
|
||||
}
|
||||
|
||||
@@ -167,12 +234,7 @@ function Install-Apo {
|
||||
$sub = "$Capture\$($ep.guid)"
|
||||
try {
|
||||
if (-not $bk.ContainsKey($ep.guid)) { # 처음 붙일 때의 값만 남긴다 (다시 실행해도 덮어쓰지 않음)
|
||||
$bk[$ep.guid] = @{
|
||||
sfx = Get-Val $HKLM.OpenSubKey("$sub\FxProperties") $SFX
|
||||
sfx_composite = Get-Val $HKLM.OpenSubKey("$sub\FxProperties") $SFX_COMPOSITE
|
||||
sfx_modes = Get-Val $HKLM.OpenSubKey("$sub\FxProperties") $SFX_MODES
|
||||
disable_sysfx = Get-Val $HKLM.OpenSubKey("$sub\FxProperties") $DISABLE_SYSFX
|
||||
}
|
||||
$bk[$ep.guid] = Current-Original $sub
|
||||
Save-Backup $bk
|
||||
}
|
||||
if (-not $HKLM.OpenSubKey("$sub\FxProperties")) { New-FxKey $sub }
|
||||
@@ -188,8 +250,13 @@ function Install-Apo {
|
||||
} else {
|
||||
$fx.SetValue($SFX, $Clsid, 'String')
|
||||
}
|
||||
# 드라이버가 이미 모드 목록을 갖고 있으면 그대로 둔다 (드라이버 효과가 지원하지 않는 모드를 억지로 켜지 않게)
|
||||
if (-not ($fx.GetValueNames() -contains $SFX_MODES)) { $fx.SetValue($SFX_MODES, [string[]]$CAPTURE_MODES, 'MultiString') }
|
||||
# 드라이버가 원래 갖고 있던 모드 목록은 그대로 둔다 (드라이버 효과가 지원하지 않는 모드를 억지로 켜지 않게).
|
||||
# 원래 목록이 없었으면(백업이 null) 이 앱이 만든 목록이므로 통화 · 음성 · 미디어 모드까지 넣는다.
|
||||
# 이전 버전이 넣은 "기본 모드 하나" 목록도 여기서 갱신된다.
|
||||
$modes = Get-Val $fx $SFX_MODES
|
||||
if ($null -eq $bk[$ep.guid].sfx_modes -and (-not $modes -or (Compare-Object @($modes.data) $CAPTURE_MODES))) {
|
||||
$fx.SetValue($SFX_MODES, [string[]]$CAPTURE_MODES, 'MultiString')
|
||||
}
|
||||
# 사용자가 "오디오 향상" 을 꺼 두면 APO 가 통째로 빠지므로 켠다 (해제할 때 되돌림)
|
||||
if ($fx.GetValueNames() -contains $DISABLE_SYSFX) { $fx.DeleteValue($DISABLE_SYSFX) }
|
||||
$fx.Close()
|
||||
@@ -201,6 +268,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 $OldListFile -ErrorAction SilentlyContinue
|
||||
Restart-Audio
|
||||
if ($done.Count -eq 0) { throw '마이크를 하나도 연결하지 못했습니다' }
|
||||
}
|
||||
@@ -225,7 +293,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 -ErrorAction SilentlyContinue
|
||||
Remove-Item -Force $BackupFile, $ListFile, $OldListFile -ErrorAction SilentlyContinue
|
||||
Restart-Audio
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user