Skip to content

fix(windows): harden PE metadata, static TaskDialog, and screenshot helper - #1306

Merged
iruriQ merged 1 commit into
mainfrom
fix/windows-defender-pe-hygiene
Nov 27, 2026
Merged

iruriQ merged 1 commit into
mainfrom
fix/windows-defender-pe-hygiene

Conversation

@iruriQ

@iruriQ iruriQ commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Hardens Windows PE hygiene and reduces high-sensitivity static imports in the resident bin/codexhost.exe launcher to mitigate Microsoft Defender false positives while preserving all runtime contracts:

  1. Complete Windows PE VersionInfo & asInvoker manifests across all 7 self-built .exe binaries:
    • Embeds CompanyName, ProductName, FileDescription, OriginalFilename, InternalName, LegalCopyright, version metadata, and <trustInfo><requestedExecutionLevel level="asInvoker" uiAccess="false"/></trustInfo> (preserving Common-Controls 6.0, DPI awareness, and longPathAware) across codexhost.exe, codexhost-start.exe, codexhost-shim.exe, codexhost-node-repl.exe, codexhost-updater.exe, codexhost-shell.exe, and codexhost-screenshot.exe.
    • Uses per-binary cargo:rustc-link-arg-bin resource linking in multi-bin crates (crates/launcher, crates/shim) plus cargo:rustc-link-arg-tests for crates/launcher test targets, and configures apps/desktop-shell/src-tauri via tauri_build::WindowsAttributes + tauri.conf.json to avoid CVT1100 duplicate resources.
  2. Remove handwritten LoadLibraryW + GetProcAddress dynamic loading:
    • Removes manual LoadLibraryW("comctl32.dll") / GetProcAddress("TaskDialogIndirect") / FreeLibrary / transmute from crates/platform/src/windows_ui.rs.
    • Moves the Common Controls v6 prompt behind the windows-task-dialog feature in crates/platform/src/windows_task_dialog.rs using static windows::Win32::UI::Controls::TaskDialogIndirect binding (only enabled by codexhost-launcher, which embeds the Common Controls v6 manifest).
  3. Split Windows desktop screenshot capture out of codexhost.exe:
    • Adds crates/screenshot (libexec/codexhost-screenshot.exe on Windows) to isolate xcap, OpenInputDesktop, GetThreadDesktop, and HiDPI capture APIs from the resident bin/codexhost.exe binary.
    • Preserves the codexhost desktop-screenshot CLI and web-server contract verbatim (Windows delegates on demand to libexec/codexhost-screenshot.exe with CREATE_NO_WINDOW; macOS retains its existing in-process implementation to preserve Screen Recording TCC attribution).
    • Updates crates/updater/src/prepare_install.rs, scripts/release/prepare-payload.mjs, scripts/release/prepare-npm.mjs, and corresponding release tests.

Related issues

无 / N/A

UI Demo

No visual changes: changes under apps/desktop-shell/src-tauri/ only configure Windows PE metadata (publisher, copyright, OriginalFilename, InternalName) and the embedded windows.manifest (asInvoker / longPathAware / Common-Controls 6.0) without modifying any UI layout, styles, or interactive behavior.

Test plan

Executed locally on macOS (arm64):

  • cargo fmt --all --check — passed
  • cargo clippy --workspace --all-targets --locked --features codexhost-shim/test-utils,codexhost-gate-a-native/gate-tools -- -D warnings — passed
  • cargo test --workspace --locked --features codexhost-shim/test-utils,codexhost-gate-a-native/gate-tools — passed (including new codexhost-screenshot tests)
  • cargo check --manifest-path apps/desktop-shell/src-tauri/Cargo.toml --locked — passed
  • cargo check --target x86_64-pc-windows-msvc --locked -p codexhost-platform --all-targets (default and --features windows-task-dialog) — passed
  • cargo clippy --target x86_64-pc-windows-msvc --workspace --all-targets --locked --features codexhost-shim/test-utils,codexhost-gate-a-native/gate-tools -- -D warnings (with mock RC_PATH verifying generated .rc files contain no external #include headers) — passed
  • cargo check --target x86_64-pc-windows-msvc --locked -p codexhost-launcher -p codexhost-screenshot --all-targets -v — confirmed each bin/test target links exactly one .res without duplication
  • cargo tree --locked --target x86_64-pc-windows-msvc -p codexhost-launcher — confirmed zero xcap, Win32_System_StationsAndDesktops, or Win32_UI_HiDpi dependencies in Windows codexhost.exe
  • npx vitest run --config tests/vitest.config.js tests/release/payload.test.mjs tests/release/npm-package.test.mjs — 85 passed, 1 Windows-only skipped
  • node --import tsx --test packages/web-server/test/desktop-screenshot.test.ts — 6 passed

Not executed locally (deferred to Windows CI / Windows machine):

  • Native Windows MSVC rc.exe + link.exe resource compilation and linking across all 7 .exe targets (including tauri_build)
  • Native Windows cargo test --workspace runtime check verifying TaskDialogIndirect static import works without STATUS_ENTRYPOINT_NOT_FOUND
  • Windows PE IAT/VersionInfo/Manifest inspection and end-to-end codexhost desktop-screenshot + installer/npm packaging run

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 新功能
    • Windows 版现支持桌面截图,截图结果可供相关功能使用。
  • 改进
    • Windows 安装包现包含截图支持组件;应用的 Windows 标识及兼容性配置也已更新。

新增 Windows 桌面截图辅助程序,并接入启动器、构建和发布流程。Windows 程序新增应用清单和资源配置。运行中桌面提示移至受功能门控的 Task Dialog 模块。

Changes: 截图辅助程序与发布

Layer / File(s) Summary
截图程序与平台捕获接口
Cargo.toml, AGENTS.md, crates/screenshot/*, crates/platform/Cargo.toml, crates/platform/src/desktop_screenshot.rs, crates/platform/src/lib.rs
新增 codexhost-screenshot。Windows 实现检查桌面会话、捕获主显示器并将受限大小的 PNG 写入标准输出;非 Windows 返回 Unsupported。平台 crate 导出截图尺寸检查和受限图像缓冲器。
启动器发现并执行截图程序
crates/launcher/src/installation_layout.rs, crates/launcher/src/main.rs
安装布局增加 Windows 截图助手路径。启动器查找并监督执行助手;非 Windows 保留进程内截图逻辑。
Windows 程序资源与应用清单
apps/desktop-shell/src-tauri/*, crates/launcher/build.rs, crates/launcher/windows.manifest, crates/shim/*, crates/updater/*
为多个 Windows 程序新增应用清单和资源元数据。启动器和 shim 的构建脚本按 Windows 目标环境调用资源编译器,并链接生成的资源。
截图程序的 Windows 发布集成
crates/updater/src/prepare_install.rs, package.json, scripts/release/prepare-npm.mjs, scripts/release/prepare-payload.mjs, tests/release/*
Windows 构建和发布负载新增截图程序;npm 包和发布负载将其复制到 libexec。测试新增对应构建参数和路径断言。

Windows Task Dialog 提示

Layer / File(s) Summary
Task Dialog 提示及功能门控
crates/platform/Cargo.toml, crates/platform/src/lib.rs, crates/platform/src/windows_task_dialog.rs, crates/platform/src/windows_ui.rs, crates/launcher/Cargo.toml
新增区域文案选择、Task Dialog 按钮结果映射和失败回退。RunningDesktopChoice 与 prompt_running_desktop 改为仅在 Windows 且启用 windows-task-dialog 时导出;启动器启用该 feature。

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Launcher as 启动器
  participant ScreenshotHelper as 截图辅助程序
  participant WindowsDesktop as Windows 桌面
  participant StandardOutput as 标准输出
  Launcher->>ScreenshotHelper: 启动并继承标准输出
  ScreenshotHelper->>WindowsDesktop: 检查会话并捕获主显示器
  WindowsDesktop-->>ScreenshotHelper: 返回显示器图像
  ScreenshotHelper->>StandardOutput: 写入 PNG 数据
Loading

Possibly related issues

  • BytePioneer-AI/codex-host issue 1291:该问题报告 updater 缺少 manifest;本次为 updater 增加 Windows manifest,并声明 asInvoker 执行级别。

Suggested reviewers: bytepioneer-ai, omsd512-w

Merge Risk: Minimal · up to a4e37 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(windows): harden PE metadata, static TaskDialog, and screenshot helper”描述了本次变更的三个主要部分:PE 版本元数据与 asInvoker 清单、静态 TaskDialogIndirect 绑定、截图辅助程序拆分。标题与变更集相关,且准确概括了主要内容。标题较长,但不影响判断。
Description check Passed 描述详细说明了 Windows PE 元数据与 asInvoker 清单、移除手写 LoadLibraryW/GetProcAddress 动态加载、拆分截图能力到 codexhost-screenshot.exe,并列出测试计划和发布脚本变更。描述与变更集直接相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 625d5d5 and a4e37f0.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 33

  • AGENTS.md
  • Cargo.toml
  • apps/desktop-shell/src-tauri/Cargo.toml
  • apps/desktop-shell/src-tauri/build.rs
  • apps/desktop-shell/src-tauri/tauri.conf.json
  • apps/desktop-shell/src-tauri/windows.manifest
  • crates/launcher/Cargo.toml
  • crates/launcher/build.rs
  • crates/launcher/src/installation_layout.rs
  • crates/launcher/src/main.rs
  • crates/launcher/tests/cli.rs
  • crates/launcher/windows.manifest
  • crates/platform/Cargo.toml
  • crates/platform/src/desktop_screenshot.rs
  • crates/platform/src/lib.rs
  • crates/platform/src/windows_task_dialog.rs
  • crates/platform/src/windows_ui.rs
  • crates/screenshot/Cargo.toml
  • crates/screenshot/build.rs
  • crates/screenshot/src/main.rs
  • crates/screenshot/windows.manifest
  • crates/shim/Cargo.toml
  • crates/shim/build.rs
  • crates/shim/windows.manifest
  • crates/updater/Cargo.toml
  • crates/updater/build.rs
  • crates/updater/src/prepare_install.rs
  • crates/updater/windows.manifest
  • package.json
  • scripts/release/prepare-npm.mjs
  • scripts/release/prepare-payload.mjs
  • tests/release/npm-package.test.mjs
  • tests/release/payload.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: CodeRabbit
  • GitHub Check: Static checks
  • GitHub Check: Check macos-26
  • GitHub Check: Vitest
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Check windows-latest
  • GitHub Check: Web Host tests
Additional context used

Code guidelines: 1

CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: Rust owns native launch, process management, update installation, and platform integration.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • crates/launcher/Cargo.toml
  • crates/launcher/build.rs
  • crates/launcher/src/installation_layout.rs
  • crates/launcher/src/main.rs
  • crates/launcher/tests/cli.rs
  • crates/launcher/windows.manifest
  • crates/platform/Cargo.toml
  • crates/platform/src/desktop_screenshot.rs
  • crates/platform/src/lib.rs
  • crates/platform/src/windows_task_dialog.rs
  • crates/platform/src/windows_ui.rs
  • crates/screenshot/Cargo.toml
  • crates/screenshot/build.rs
  • crates/screenshot/src/main.rs
  • crates/screenshot/windows.manifest
  • crates/shim/Cargo.toml
  • crates/shim/build.rs
  • crates/shim/windows.manifest
  • crates/updater/Cargo.toml
  • crates/updater/build.rs
  • crates/updater/src/prepare_install.rs
  • crates/updater/windows.manifest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants