跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

publish-windows-component-manifest.ps1

53 行 · 3.4 KB历史下载
1# Records only the files verified in this fixed guest after installation.
2param([guid]$VMId,[string]$GUIUserSID,[string]$ManifestJSON)
3$ErrorActionPreference='Stop'
4if ([guid](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').VirtualMachineId -ne $VMId -or
5 $GUIUserSID -notmatch '^S-1-5-21-\d+-\d+-\d+-\d+$' -or [Text.Encoding]::UTF8.GetByteCount($ManifestJSON) -gt 4MB) {
6 throw '组件版本记录与客机身份不一致。'
7}
8$manifest=$ManifestJSON|ConvertFrom-Json
9if ($manifest.protocol -ne 1 -or $manifest.system -cne 'windows-11' -or $manifest.revision -notmatch '^[a-f0-9]{64}$' -or
10 @($manifest.files).Count -lt 1 -or @($manifest.files).Count -gt 10000) { throw '组件版本清单无效。' }
11$roots=@{bridge=(Join-Path $env:ProgramFiles ('Cage Guest Bridge\'+$VMId));network=(Join-Path $env:ProgramFiles ('Cage Guest Network\'+$VMId))}
12$seen=@{}
13foreach ($entry in $manifest.files) {
14 if (!$entry.target) { continue }
15 if ($entry.target -notmatch '^(bridge|network)/[^:\\]+$' -or $entry.target -match '(^|/)\.\.?(/|$)' -or
16 $entry.installed_sha256 -notmatch '^[a-f0-9]{64}$' -or $seen.ContainsKey($entry.target)) { throw '组件文件记录无效。' }
17 $seen[$entry.target]=$true
18 $parts=$entry.target -split '/',2
19 $file=Join-Path $roots[$parts[0]] $parts[1]
20 $item=Get-Item -LiteralPath $file -Force
21 if ($item -isnot [IO.FileInfo]) { throw '安装的组件文件缺失,请继续同步环境组件。' }
22 for ($parent=$item; $parent; $parent=if($parent -is [IO.FileInfo]){$parent.Directory}else{$parent.Parent}) {
23 if ($parent.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw '组件安装目录包含文件链接。' }
24 }
25 if ((Get-FileHash -LiteralPath $file).Hash -ne $entry.installed_sha256) { throw '安装的组件与当前应用版本不匹配,请继续同步环境组件。' }
26}
27if (!$seen.Count) { throw '组件清单缺少安装文件。' }
28$target=Join-Path $roots.bridge 'native-components.json'
29if (Test-Path -LiteralPath $target) {
30 $old=Get-Item -LiteralPath $target -Force
31 if ($old -isnot [IO.FileInfo] -or $old.Attributes -band [IO.FileAttributes]::ReparsePoint) { throw '现有组件记录无法安全更新。' }
32}
33$temporary=Join-Path $roots.bridge ('native-components.'+[guid]::NewGuid().ToString('N')+'.json')
34try {
35 $file=[IO.File]::Open($temporary,'CreateNew','Write','None')
36 try {
37 $bytes=[Text.UTF8Encoding]::new($false).GetBytes($ManifestJSON)
38 $file.Write($bytes,0,$bytes.Length)
39 $file.Flush($true)
40 } finally { $file.Dispose() }
41 $acl=[Security.AccessControl.FileSecurity]::new()
42 $acl.SetAccessRuleProtection($true,$false)
43 $acl.SetOwner([Security.Principal.SecurityIdentifier]::new('S-1-5-32-544'))
44 foreach ($sid in @('S-1-5-18','S-1-5-32-544')) {
45 $acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new([Security.Principal.SecurityIdentifier]::new($sid),'FullControl','Allow'))
46 }
47 $acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new([Security.Principal.SecurityIdentifier]::new($GUIUserSID),'ReadAndExecute','Allow'))
48 Set-Acl -LiteralPath $temporary -AclObject $acl
49 if (Test-Path -LiteralPath $target) { [IO.File]::Replace($temporary,$target,[Management.Automation.Language.NullString]::Value) }
50 else { [IO.File]::Move($temporary,$target) }
51} finally {
52 if ([IO.File]::Exists($temporary)) { [IO.File]::Delete($temporary) }
53}