Files
MemRelay/projects/ea207d36-693c-4349-b3c8-7c40c8c889f5/Checkpoint 2026-08-20 02-41-42 UTC [8a81e51bd4].md
T

53 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Checkpoint 2026-08-20 02:41:42 UTC [8a81e51bd4]
type: checkpoint
permalink: main/projects/ea207d36-693c-4349-b3c8-7c40c8c889f5/checkpoint-2026-08-20-02-41-42-utc-8a81e51bd4
stable_id: 4163f161-0f27-476a-bf98-ba407de20919
scope: project
project_id: ea207d36-693c-4349-b3c8-7c40c8c889f5
memory_type: checkpoint
status: active
revision: 1
restored_from_commit: 6a6a895eafcca6052e81a14fca103a42635dd1c2
created_at: '2026-09-23T15:11:34.910786+00:00'
updated_at: '2026-09-23T15:11:34.910851+00:00'
---
# 安装方式变更:PowerShell 脚本 → Rust installer(2026-08-20,提交 09662c8)
## 重要:覆盖上一个检查点里关于 install.ps1 的描述
工程里已经**没有任何 .ps1 文件**。install/install.ps1、install/uninstall.ps1 已删除,install/ 目录现在只剩 provider.reg(纯注册表模板,作手动备用)。
## 变更原因(用户提出“为何非得用 ps1”)
1. 无 BOM 的 UTF-8 中文 .ps1 在 PowerShell 5.1 + 代码页 936(GBK) 下会被按 ANSI 解码,实测 install.ps1 / uninstall.ps1 分别产生 8 个 / 3 个语法错误,根本跑不起来(虽然转 UTF-8 with BOM 能修好,但仍不如 exe)。
2. .ps1 还受 ExecutionPolicy 限制。
3. exe 可以在运行时 SetConsoleOutputCP(65001) 自我修正输出编码,这是脚本做不到的。
## 本次实现
- 新增第五个 crate:crates/installer(package name = installer),产物 **winunlock-admin.exe**(≈273KB)。
- 子命令:`winunlock-admin install [-t|--unlock-time HH:MM] [-s|--source <目录>] [--skip-task]` 与 `winunlock-admin uninstall`,另有 --help。
- install 流程:IsUserAnAdmin 校验管理员 → 定位产物(本程序同目录或 target\x86_64-pc-windows-msvc\release)→ 复制 provider.dll/client.exe/setup.exe 到 %PROGRAMDATA%\WinUnLock\bin → icacls 收紧 ACL(仅 SYSTEM/Administrators)→ regsvr32 /s 注册 → schtasks /Create 建每日任务(SYSTEM + /RL HIGHEST,默认 08:30)。
- uninstall 流程:schtasks /Delete → regsvr32 /u(由 DllUnregisterServer 删两处注册表键)→ 删整个数据目录(DLL 被 LogonUI 占用时提示重启后重跑)。注意:install 不会把 winunlock-admin.exe 自己复制到 bin(避免删自己失败),卸载请从构建产物目录运行。
- setup 也加上 SetConsoleOutputCP(65001),中文提示不再需要手动 chcp。
- README 安装/卸载/工程结构/产物路径/crate 职责表/安全说明 共 7 处已全部同步,无 ps1 残留。
## 验证结果
- cargo build --release 通过;四个产物 provider.dll(573KB)、client.exe(506KB)、setup.exe(632KB)、winunlock-admin.exe(273KB)。
- cargo test --release:14 个单测全过(协议往返/拒绝错误 magic/版本/超长字段/截断、Debug 不泄露密码、账户名解析、配置往返、DPAPI 加解密实测、CLSID 格式化)。
- winunlock-admin.exe --help 与 setup.exe --help 实际运行,退出码 0,**中文输出完全正常**。
- dumpbin 确认 provider.dll 仍导出 5 个函数。
## 踩过的坑
给 setup 加 UTF-8 时一次 StrReplace 的 new_string 被截断,把 import 块和 main 函数写坏了(编译报错);已补全修复并重新编译验证通过。教训:大块替换后要立即编译验证。
## 下一步(给下个会话 / 用户 VM 测试)
1. cargo build --release
2. 管理员终端:cd target\x86_64-pc-windows-msvc\release 然后 .\winunlock-admin.exe install(可 --unlock-time 改时间)
3. 运行 %PROGRAMDATA%\WinUnLock\bin\setup.exe 设账户(.\用户名)与密码
4. Win+L 锁屏,把计划任务临时改到 1-2 分钟后,观察自动解锁
5. 看 %PROGRAMDATA%\WinUnLock\logs\{provider,client}.log
6. 卸载:从构建产物目录运行 .\winunlock-admin.exe uninstall
故障恢复不变:安全模式/WinRE 删 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{E9C67B30-B120-4838-A5A3-FBC2DE03C532} 与 HKCR\CLSID\{同} 。
## Git
当前工作区干净。提交历史:3e4d09b feat: 实现 WinUnLock 定时自动解锁工程 → 09662c8 refactor: 用 Rust installer 取代 PowerShell 安装脚本。