feat: native launcher ported to Rust (anyxboxx-native-launcher) #249

Merged
LooperSalty merged 27 commits from upstream-pr/249 into rust/full 2026-11-25 22:37:27 +00:00
LooperSalty commented 2026-11-25 21:23:01 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-25T21:23:01Z.


Change

Port of runtime/launcher/launcher.cpp (the native mode launcher) to Rust, as part of the rust/full migration (docs/rust-full-status.md, decision D4). Written by OpenAI Codex at the maintainer's request, in small commits on top of rust/full 754d1e0f.

  • Package manifest parsing, PE section mapping and relocations, image allocation, import table decoding and binding (missing symbols reported), Win32 loader hooks and local DLL import hooks, TLS installation and callbacks, exception registration and first-exception report, entry point call, command line identical to the C++ launcher.
  • CMake integration next to the other Rust runtime pieces; the C++ launcher stays in the tree as the parity oracle for now.
  • Parity tests against the C++ launcher (tests/test_native_*).

Verification (local, Windows)

  • cargo build --release --workspace, cargo test --release --workspace, cargo clippy (crate, -D warnings), cargo fmt --check: pass.
  • Runtime built with CMake/Ninja; native pytest: 39 passed, 6 skipped (cases needing the TomBox DLLs).
  • No game or game file was run or used.

Follow-ups

  • Check the 6 skipped cases once the TomBox DLLs are built.
  • Remove the C++ launcher after a release cycle with the Rust one as default.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LwHrL4bPjrVJiDKC8BDYfz

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6614025275 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/249). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-25T21:23:01Z. --- ## Change Port of `runtime/launcher/launcher.cpp` (the native mode launcher) to Rust, as part of the `rust/full` migration (docs/rust-full-status.md, decision D4). Written by OpenAI Codex at the maintainer's request, in small commits on top of `rust/full` 754d1e0f. - Package manifest parsing, PE section mapping and relocations, image allocation, import table decoding and binding (missing symbols reported), Win32 loader hooks and local DLL import hooks, TLS installation and callbacks, exception registration and first-exception report, entry point call, command line identical to the C++ launcher. - CMake integration next to the other Rust runtime pieces; the C++ launcher stays in the tree as the parity oracle for now. - Parity tests against the C++ launcher (`tests/test_native_*`). ## Verification (local, Windows) - `cargo build --release --workspace`, `cargo test --release --workspace`, `cargo clippy` (crate, `-D warnings`), `cargo fmt --check`: pass. - Runtime built with CMake/Ninja; native pytest: 39 passed, 6 skipped (cases needing the TomBox DLLs). - No game or game file was run or used. ## Follow-ups - Check the 6 skipped cases once the TomBox DLLs are built. - Remove the C++ launcher after a release cycle with the Rust one as default. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01LwHrL4bPjrVJiDKC8BDYfz
chatgpt-codex-connector[bot] commented 2026-11-25 21:23:17 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T21:23:17Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T21:25:00.329157Z 7a1bb9e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7175008622 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/249#issuecomment-7175008622). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-25T21:23:17Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7a1bb9efcc66fb66dc1a56a8b49a6f112e66c1b5","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T21:25:00.329157Z">2026-11-25T21:25:00.329157Z</relative-time> | `7a1bb9e` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot] commented 2026-11-25 21:24:58 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T21:24:58Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a1bb9efcc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:LooperSalty/AnyXboxX:review:6065188625 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/249#pullrequestreview-6065188625). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-25T21:24:58Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `7a1bb9efcc` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot] commented 2026-11-25 21:24:58 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T21:24:58Z.

Code review location: crates/anyxboxx-native-launcher/src/image.rs; line 83

@@ -0,0 +1,182 @@
+//! PE32+ image layout and base relocations for the native launcher.
+//!
+//! This module prepares bytes only; it does not allocate executable memory or call an entry point.
+
+use std::fmt;
+
+const DOS_HEADER_SIZE: usize = 64;
+const NT_HEADERS_SIZE: usize = 264;
+const SECTION_SIZE: usize = 40;
+const RELOCATION_DIRECTORY: usize = 5;
+const DIR64: u16 = 10;
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum ImageError {
+    InvalidPe,
+    NotPe32Plus,
+    SectionOutsideImage,
+    MissingRelocations,
+    InvalidRelocations,
+}
+
+impl fmt::Display for ImageError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.write_str(match self {
+            Self::InvalidPe => "fichier PE invalide",
+            Self::NotPe32Plus => "seul le format PE32+ x86-64 est accepté",
+            Self::SectionOutsideImage => "section hors de l'image",
+            Self::MissingRelocations => "base préférée occupée et aucune table de relocation",
+            Self::InvalidRelocations => "table de relocation invalide",
+        })
+    }
+}
+
+impl std::error::Error for ImageError {}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Section {
+    pub address: u32,
+    pub virtual_size: u32,
+    pub raw_size: u32,
+    pub characteristics: u32,
+}
+
+/// Image data and the fields needed for allocation and section protection.
+pub struct Image {
+    pub bytes: Vec<u8>,
+    pub preferred_base: u64,
+    pub entry_rva: u32,
+    pub headers_size: u32,
+    pub sections: Vec<Section>,
+    directories: [(u32, u32); 16],
+}
+
+fn u16_at(data: &[u8], offset: usize) -> Option<u16> {
+    Some(u16::from_le_bytes(
+        data.get(offset..offset.checked_add(2)?)?.try_into().ok()?,
+    ))
+}
+
+fn u32_at(data: &[u8], offset: usize) -> Option<u32> {
+    Some(u32::from_le_bytes(
+        data.get(offset..offset.checked_add(4)?)?.try_into().ok()?,
+    ))
+}
+
+fn u64_at(data: &[u8], offset: usize) -> Option<u64> {
+    Some(u64::from_le_bytes(
+        data.get(offset..offset.checked_add(8)?)?.try_into().ok()?,
+    ))
+}
+
+fn range(offset: usize, size: usize, limit: usize) -> Option<std::ops::Range<usize>> {
+    let end = offset.checked_add(size)?;
+    (end <= limit).then_some(offset..end)
+}
+
+impl Image {
+    pub fn parse(file: &[u8]) -> Result<Self, ImageError> {
+        if file.len() < DOS_HEADER_SIZE || u16_at(file, 0) != Some(0x5a4d) {
+            return Err(ImageError::InvalidPe);
+        }
+        let nt = u32_at(file, 60).ok_or(ImageError::InvalidPe)? as usize;
+        range(nt, NT_HEADERS_SIZE, file.len()).ok_or(ImageError::InvalidPe)?;

P1 Badge Reuse the existing VIctory PE parser

This introduces another handwritten PE parser, with a separate import-table decoder in imports.rs, although victory_pe::ImageInfo::parse already provides PE headers, sections and imports and is reused by crates/anyxboxx-pe. Maintaining independent decoding paths means format fixes and validation changes must now be duplicated across launchers. AGENTS.md explicitly requires new Rust code to reuse VIctory's and TomBox's crates instead of reimplementing them. Build the native-specific mapping and binding logic on the existing parser rather than introducing a separate implementation.

AGENTS.md reference: AGENTS.md:L44-L44

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:review-comment:4701047042 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/249#discussion_r4701047042). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-25T21:24:58Z. **Code review location:** `crates/anyxboxx-native-launcher/src/image.rs`; line 83 ~~~~diff @@ -0,0 +1,182 @@ +//! PE32+ image layout and base relocations for the native launcher. +//! +//! This module prepares bytes only; it does not allocate executable memory or call an entry point. + +use std::fmt; + +const DOS_HEADER_SIZE: usize = 64; +const NT_HEADERS_SIZE: usize = 264; +const SECTION_SIZE: usize = 40; +const RELOCATION_DIRECTORY: usize = 5; +const DIR64: u16 = 10; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ImageError { + InvalidPe, + NotPe32Plus, + SectionOutsideImage, + MissingRelocations, + InvalidRelocations, +} + +impl fmt::Display for ImageError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + Self::InvalidPe => "fichier PE invalide", + Self::NotPe32Plus => "seul le format PE32+ x86-64 est accepté", + Self::SectionOutsideImage => "section hors de l'image", + Self::MissingRelocations => "base préférée occupée et aucune table de relocation", + Self::InvalidRelocations => "table de relocation invalide", + }) + } +} + +impl std::error::Error for ImageError {} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Section { + pub address: u32, + pub virtual_size: u32, + pub raw_size: u32, + pub characteristics: u32, +} + +/// Image data and the fields needed for allocation and section protection. +pub struct Image { + pub bytes: Vec<u8>, + pub preferred_base: u64, + pub entry_rva: u32, + pub headers_size: u32, + pub sections: Vec<Section>, + directories: [(u32, u32); 16], +} + +fn u16_at(data: &[u8], offset: usize) -> Option<u16> { + Some(u16::from_le_bytes( + data.get(offset..offset.checked_add(2)?)?.try_into().ok()?, + )) +} + +fn u32_at(data: &[u8], offset: usize) -> Option<u32> { + Some(u32::from_le_bytes( + data.get(offset..offset.checked_add(4)?)?.try_into().ok()?, + )) +} + +fn u64_at(data: &[u8], offset: usize) -> Option<u64> { + Some(u64::from_le_bytes( + data.get(offset..offset.checked_add(8)?)?.try_into().ok()?, + )) +} + +fn range(offset: usize, size: usize, limit: usize) -> Option<std::ops::Range<usize>> { + let end = offset.checked_add(size)?; + (end <= limit).then_some(offset..end) +} + +impl Image { + pub fn parse(file: &[u8]) -> Result<Self, ImageError> { + if file.len() < DOS_HEADER_SIZE || u16_at(file, 0) != Some(0x5a4d) { + return Err(ImageError::InvalidPe); + } + let nt = u32_at(file, 60).ok_or(ImageError::InvalidPe)? as usize; + range(nt, NT_HEADERS_SIZE, file.len()).ok_or(ImageError::InvalidPe)?; ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Reuse the existing VIctory PE parser** This introduces another handwritten PE parser, with a separate import-table decoder in `imports.rs`, although `victory_pe::ImageInfo::parse` already provides PE headers, sections and imports and is reused by `crates/anyxboxx-pe`. Maintaining independent decoding paths means format fixes and validation changes must now be duplicated across launchers. `AGENTS.md` explicitly requires new Rust code to reuse VIctory's and TomBox's crates instead of reimplementing them. Build the native-specific mapping and binding logic on the existing parser rather than introducing a separate implementation. AGENTS.md reference: [AGENTS.md:L44-L44](https://github.com/LooperSalty/AnyXboxX/blob/7a1bb9efcc66fb66dc1a56a8b49a6f112e66c1b5/AGENTS.md#L44-L44) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!249
No description provided.