Skip to content

fix: 修复部分游戏启动时的使用 RegOpenKeyExA 读注册表导致退出的错误 - #7

Merged
Applesaber merged 1 commit into
MuNET-OSS:mainfrom
WYH2004-MC:main
Nov 20, 2026
Merged

Applesaber merged 1 commit into
MuNET-OSS:mainfrom
WYH2004-MC:main

Conversation

@WYH2004-MC

@WYH2004-MC WYH2004-MC commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor
  • 接管 RegOpenKeyExA 并复用虚拟键逻辑,让现有的RegQueryValueExA Hook 能读到虚拟的 OSVersion。

View guided diff

Sourcery 总结

在虚拟注册表层支持以 ANSI 编码打开注册表项,以便现有的操作系统版本虚拟化功能适用于更多游戏。

错误修复:

  • 防止使用 ANSI 注册表打开 API 的游戏在访问虚拟操作系统版本数据时退出。

增强功能:

  • 扩展注册表虚拟化功能以支持 RegOpenKeyExA,同时让各注册表钩子共享键解析和后备句柄管理逻辑。
Original summary in English

Summary by Sourcery

Support ANSI registry key opening in the virtual registry layer so existing OS version virtualization works across more games.

Bug Fixes:

  • Prevent games that use the ANSI registry-opening API from exiting when accessing virtual OS version data.

Enhancements:

  • Extend registry virtualization to support RegOpenKeyExA while sharing key resolution and backing-handle management across registry hooks.

- 接管 RegOpenKeyExA 并复用虚拟键逻辑,让现有的RegQueryValueExA Hook 能读到虚拟的 OSVersion。
@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

审查者指南

实现

拦截 RegOpenKeyExA,并将其接入现有的虚拟键查找和句柄生命周期,使 ANSI 调用方能够访问虚拟注册表值。

  • packages/applechu/src/platform/reg_hook.rs L206-210, L282-312, L628-632(另有 9 处小改动)

提示和命令

与 Sourcery 互动

  • **触发新的审查:**在拉取请求中评论 @sourcery-ai review。
  • **继续讨论:**直接回复 Sourcery 的审查评论。
  • **根据审查评论创建 GitHub issue:**回复审查评论,请 Sourcery 根据该评论创建 issue。你也可以在审查评论下回复 @sourcery-ai issue 来创建 issue。
  • **生成拉取请求标题:**在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • **生成拉取请求摘要:**在拉取请求正文的任意位置写入 @sourcery-ai summary,即可在你指定的位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • **生成审查者指南:**在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审查者指南。
  • **解决所有 Sourcery 评论:**在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • **关闭所有 Sourcery 审查:**在拉取请求中评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 审查。如果你想从头开始进行新的审查,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

访问你的控制面板,以便:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implementation

Intercept RegOpenKeyExA and connect it to the existing virtual-key lookup and handle lifecycle so ANSI callers can access virtual registry values.

  • packages/applechu/src/platform/reg_hook.rs L206-210, L282-312, L628-632 (+9 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

View guided diff | Re-trigger cubic

@WYH2004-MC

Copy link
Copy Markdown
Contributor Author

fix this issues #6

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我发现了 5 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="206" />
<code_context>
 fn install_hooks(api: &Api) {
     unsafe {
         let symbols = [
+            HookSymbol {
+                name: "RegOpenKeyExA",
+                patch: hooked_reg_open_key_ex_a as *const (),
</code_context>
<issue_to_address>
**Virtual keys fail during startup**

When another game thread calls `RegOpenKeyExA` after the hook is installed but before `init` registers the virtual keys, `hooked_reg_open_key_ex_a` cannot find the virtual key and forwards the request to the real registry, which returns an error, so the caller's open fails.

Register the virtual keys before installing the hook, or otherwise prevent calls from reaching it until registration completes.

Also at `packages/applechu/src/platform/reg_hook.rs:207`.
</issue_to_address>

### Comment 2
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="293" />
<code_context>
+        return ERROR_INVALID_PARAMETER;
+    }
+    let name = winapi::cstr_to_string(subkey).unwrap_or_default();
+    if let Some(key_id) = resolve_named_key_id(parent, &name) {
+        return open_virtual_key(key_id, out);
+    }
</code_context>
<issue_to_address>
**Nested opens miss virtual keys**

When a caller opens `HKLM\SYSTEM` first and then opens `SEGA` or a deeper virtual subkey relative to that returned handle, `resolve_named_key_id` cannot resolve `SEGA` from the real handle returned for `HKLM\SYSTEM`, and `key_for_handle` has no entry for that handle. The hook falls through to the real registry, so callers opening the virtual path one component at a time fail to reach it.

Track the registry path for ordinary handles opened by the A hook and use it to resolve virtual descendants, or otherwise support resolving virtual paths from real ancestor handles.
</issue_to_address>

### Comment 3
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="206-210" />
<code_context>
 fn install_hooks(api: &Api) {
     unsafe {
         let symbols = [
+            HookSymbol {
+                name: "RegOpenKeyExA",
+                patch: hooked_reg_open_key_ex_a as *const (),
+                original: ptr::addr_of_mut!(ORIG_OPEN_KEY_EX_A_PTR),
+            },
             HookSymbol {
                 name: "RegOpenKeyExW",
</code_context>
<issue_to_address>
**Partial hook returns wrong values**

When the caller's RegOpenKeyExA IAT entry is patched but its RegQueryValueExA entry is not, `hooked_reg_open_key_ex_a` returns a mapped handle backed by the real SOFTWARE key, but the caller's native `RegQueryValueExA` bypasses `hooked_reg_query_value_ex_a` and reads the real registry instead of virtual OSVersion.

Treat the open and query hooks as a required pair: roll back or disable virtual opens for callers whose query entry could not be patched.
</issue_to_address>

### Comment 4
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="294" />
<code_context>
+    }
+    let name = winapi::cstr_to_string(subkey).unwrap_or_default();
+    if let Some(key_id) = resolve_named_key_id(parent, &name) {
+        return open_virtual_key(key_id, out);
+    }
+    if key_for_handle(parent).is_some() {
</code_context>
<issue_to_address>
**Write access is falsely granted**

When an ANSI caller opens a virtual key requesting write access, `hooked_reg_open_key_ex_a` ignores the requested `access` and `open_virtual_key` opens the backing key with `KEY_READ`; callers requesting write access therefore receive success but cannot perform the writes that success promises.

Validate the requested access rights and return an appropriate error when the virtual key cannot honor them.

Also at `packages/applechu/src/platform/reg_hook.rs:539`.
</issue_to_address>

### Comment 5
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="296-297" />
<code_context>
+    if let Some(key_id) = resolve_named_key_id(parent, &name) {
+        return open_virtual_key(key_id, out);
+    }
+    if key_for_handle(parent).is_some() {
+        return winapi::ERROR_FILE_NOT_FOUND;
+    }
+    let original_addr = ORIG_OPEN_KEY_EX_A.load(Ordering::SeqCst);
</code_context>
<issue_to_address>
**ANSI child keys stop resolving**

When a game opens a virtual key and then requests a child key not registered in `KEYS`, the hook returns `ERROR_FILE_NOT_FOUND` as soon as `key_for_handle(parent)` recognizes a virtual parent, without trying the original `RegOpenKeyExA`; callers therefore cannot open an otherwise valid child key beneath that handle.

Preserve the original registry lookup for unresolved child keys, using a backing handle rooted at the virtual key’s actual registry path.
</issue_to_address>

Sourcery 评估

待批准。 请先处理 5 项发现。

阻塞性发现:packages/applechu/src/platform/reg_hook.rs:206、packages/applechu/src/platform/reg_hook.rs:293、packages/applechu/src/platform/reg_hook.rs:210、packages/applechu/src/platform/reg_hook.rs:294、packages/applechu/src/platform/reg_hook.rs:297


Sourcery 对开源项目免费使用——如果您喜欢我们的审查,欢迎分享 ✨
Original comment in English

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="206" />
<code_context>
 fn install_hooks(api: &Api) {
     unsafe {
         let symbols = [
+            HookSymbol {
+                name: "RegOpenKeyExA",
+                patch: hooked_reg_open_key_ex_a as *const (),
</code_context>
<issue_to_address>
**Virtual keys fail during startup**

When another game thread calls `RegOpenKeyExA` after the hook is installed but before `init` registers the virtual keys, `hooked_reg_open_key_ex_a` cannot find the virtual key and forwards the request to the real registry, which returns an error, so the caller's open fails.

Register the virtual keys before installing the hook, or otherwise prevent calls from reaching it until registration completes.

Also at `packages/applechu/src/platform/reg_hook.rs:207`.
</issue_to_address>

### Comment 2
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="293" />
<code_context>
+        return ERROR_INVALID_PARAMETER;
+    }
+    let name = winapi::cstr_to_string(subkey).unwrap_or_default();
+    if let Some(key_id) = resolve_named_key_id(parent, &name) {
+        return open_virtual_key(key_id, out);
+    }
</code_context>
<issue_to_address>
**Nested opens miss virtual keys**

When a caller opens `HKLM\SYSTEM` first and then opens `SEGA` or a deeper virtual subkey relative to that returned handle, `resolve_named_key_id` cannot resolve `SEGA` from the real handle returned for `HKLM\SYSTEM`, and `key_for_handle` has no entry for that handle. The hook falls through to the real registry, so callers opening the virtual path one component at a time fail to reach it.

Track the registry path for ordinary handles opened by the A hook and use it to resolve virtual descendants, or otherwise support resolving virtual paths from real ancestor handles.
</issue_to_address>

### Comment 3
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="206-210" />
<code_context>
 fn install_hooks(api: &Api) {
     unsafe {
         let symbols = [
+            HookSymbol {
+                name: "RegOpenKeyExA",
+                patch: hooked_reg_open_key_ex_a as *const (),
+                original: ptr::addr_of_mut!(ORIG_OPEN_KEY_EX_A_PTR),
+            },
             HookSymbol {
                 name: "RegOpenKeyExW",
</code_context>
<issue_to_address>
**Partial hook returns wrong values**

When the caller's RegOpenKeyExA IAT entry is patched but its RegQueryValueExA entry is not, `hooked_reg_open_key_ex_a` returns a mapped handle backed by the real SOFTWARE key, but the caller's native `RegQueryValueExA` bypasses `hooked_reg_query_value_ex_a` and reads the real registry instead of virtual OSVersion.

Treat the open and query hooks as a required pair: roll back or disable virtual opens for callers whose query entry could not be patched.
</issue_to_address>

### Comment 4
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="294" />
<code_context>
+    }
+    let name = winapi::cstr_to_string(subkey).unwrap_or_default();
+    if let Some(key_id) = resolve_named_key_id(parent, &name) {
+        return open_virtual_key(key_id, out);
+    }
+    if key_for_handle(parent).is_some() {
</code_context>
<issue_to_address>
**Write access is falsely granted**

When an ANSI caller opens a virtual key requesting write access, `hooked_reg_open_key_ex_a` ignores the requested `access` and `open_virtual_key` opens the backing key with `KEY_READ`; callers requesting write access therefore receive success but cannot perform the writes that success promises.

Validate the requested access rights and return an appropriate error when the virtual key cannot honor them.

Also at `packages/applechu/src/platform/reg_hook.rs:539`.
</issue_to_address>

### Comment 5
<location path="packages/applechu/src/platform/reg_hook.rs" line_range="296-297" />
<code_context>
+    if let Some(key_id) = resolve_named_key_id(parent, &name) {
+        return open_virtual_key(key_id, out);
+    }
+    if key_for_handle(parent).is_some() {
+        return winapi::ERROR_FILE_NOT_FOUND;
+    }
+    let original_addr = ORIG_OPEN_KEY_EX_A.load(Ordering::SeqCst);
</code_context>
<issue_to_address>
**ANSI child keys stop resolving**

When a game opens a virtual key and then requests a child key not registered in `KEYS`, the hook returns `ERROR_FILE_NOT_FOUND` as soon as `key_for_handle(parent)` recognizes a virtual parent, without trying the original `RegOpenKeyExA`; callers therefore cannot open an otherwise valid child key beneath that handle.

Preserve the original registry lookup for unresolved child keys, using a backing handle rooted at the virtual key’s actual registry path.
</issue_to_address>

Sourcery assessment

Approval pending. 5 findings to address first.

Blocking findings: packages/applechu/src/platform/reg_hook.rs:206, packages/applechu/src/platform/reg_hook.rs:293, packages/applechu/src/platform/reg_hook.rs:210, packages/applechu/src/platform/reg_hook.rs:294, packages/applechu/src/platform/reg_hook.rs:297


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

fn install_hooks(api: &Api) {
unsafe {
let symbols = [
HookSymbol {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · 虚拟键在启动期间无法使用

如果其他游戏线程在钩子安装后、但在 init 注册虚拟键之前调用 RegOpenKeyExA,hooked_reg_open_key_ex_a 将无法找到该虚拟键,并会将请求转发给真实注册表;真实注册表会返回错误,因此调用方无法打开该键。

请在安装钩子之前注册虚拟键,或者采取其他措施,确保注册完成前不会有调用进入该钩子。

另请参见 packages/applechu/src/platform/reg_hook.rs:207。

提供给 AI 代理的提示
在 `packages/applechu/src/platform/reg_hook.rs` 第 206 行:

**虚拟键在启动期间无法使用**

如果其他游戏线程在钩子安装后、但在 `init` 注册虚拟键之前调用 `RegOpenKeyExA`,`hooked_reg_open_key_ex_a` 将无法找到该虚拟键,并会将请求转发给真实注册表;真实注册表会返回错误,因此调用方无法打开该键。

请在安装钩子之前注册虚拟键,或者采取其他措施,确保注册完成前不会有调用进入该钩子。

另请参见 `packages/applechu/src/platform/reg_hook.rs:207`。
Original comment in English

🟡 Medium · Virtual keys fail during startup

When another game thread calls RegOpenKeyExA after the hook is installed but before init registers the virtual keys, hooked_reg_open_key_ex_a cannot find the virtual key and forwards the request to the real registry, which returns an error, so the caller's open fails.

Register the virtual keys before installing the hook, or otherwise prevent calls from reaching it until registration completes.

Also at packages/applechu/src/platform/reg_hook.rs:207.

Prompt for AI agents
In `packages/applechu/src/platform/reg_hook.rs` at line 206:

**Virtual keys fail during startup**

When another game thread calls `RegOpenKeyExA` after the hook is installed but before `init` registers the virtual keys, `hooked_reg_open_key_ex_a` cannot find the virtual key and forwards the request to the real registry, which returns an error, so the caller's open fails.

Register the virtual keys before installing the hook, or otherwise prevent calls from reaching it until registration completes.

Also at `packages/applechu/src/platform/reg_hook.rs:207`.

return ERROR_INVALID_PARAMETER;
}
let name = winapi::cstr_to_string(subkey).unwrap_or_default();
if let Some(key_id) = resolve_named_key_id(parent, &name) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · 嵌套打开操作无法找到虚拟键

当调用方先打开 HKLM\SYSTEM,然后相对于返回的句柄打开 SEGA 或更深层的虚拟子键时,resolve_named_key_id 无法从 HKLM\SYSTEM 返回的真实句柄解析 SEGA,而 key_for_handle 中也没有该句柄的条目。钩子会回退到真实注册表,因此,逐级打开虚拟路径的调用方无法访问该虚拟路径。

请跟踪由 A 钩子打开的普通句柄对应的注册表路径,并用它解析虚拟后代键;或者以其他方式支持从真实的祖先句柄解析虚拟路径。

提供给 AI 代理的提示
在 `packages/applechu/src/platform/reg_hook.rs` 第 293 行:

**嵌套打开操作无法找到虚拟键**

当调用方先打开 `HKLM\SYSTEM`,然后相对于返回的句柄打开 `SEGA` 或更深层的虚拟子键时,`resolve_named_key_id` 无法从 `HKLM\SYSTEM` 返回的真实句柄解析 `SEGA`,而 `key_for_handle` 中也没有该句柄的条目。钩子会回退到真实注册表,因此,逐级打开虚拟路径的调用方无法访问该虚拟路径。

请跟踪由 A 钩子打开的普通句柄对应的注册表路径,并用它解析虚拟后代键;或者以其他方式支持从真实的祖先句柄解析虚拟路径。
Original comment in English

🟡 Medium · Nested opens miss virtual keys

When a caller opens HKLM\SYSTEM first and then opens SEGA or a deeper virtual subkey relative to that returned handle, resolve_named_key_id cannot resolve SEGA from the real handle returned for HKLM\SYSTEM, and key_for_handle has no entry for that handle. The hook falls through to the real registry, so callers opening the virtual path one component at a time fail to reach it.

Track the registry path for ordinary handles opened by the A hook and use it to resolve virtual descendants, or otherwise support resolving virtual paths from real ancestor handles.

Prompt for AI agents
In `packages/applechu/src/platform/reg_hook.rs` at line 293:

**Nested opens miss virtual keys**

When a caller opens `HKLM\SYSTEM` first and then opens `SEGA` or a deeper virtual subkey relative to that returned handle, `resolve_named_key_id` cannot resolve `SEGA` from the real handle returned for `HKLM\SYSTEM`, and `key_for_handle` has no entry for that handle. The hook falls through to the real registry, so callers opening the virtual path one component at a time fail to reach it.

Track the registry path for ordinary handles opened by the A hook and use it to resolve virtual descendants, or otherwise support resolving virtual paths from real ancestor handles.

Comment on lines +206 to +210
HookSymbol {
name: "RegOpenKeyExA",
patch: hooked_reg_open_key_ex_a as *const (),
original: ptr::addr_of_mut!(ORIG_OPEN_KEY_EX_A_PTR),
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · 部分安装钩子时返回错误的值

当调用方的 RegOpenKeyExA IAT 条目已被修补,但 RegQueryValueExA 条目未被修补时,hooked_reg_open_key_ex_a 会返回一个映射句柄,该句柄由真实的 SOFTWARE 键提供支持;但调用方原生的 RegQueryValueExA 会绕过 hooked_reg_query_value_ex_a,转而读取真实注册表,而不是虚拟的 OSVersion。

请将打开和查询钩子视为必须成对安装的钩子:对于查询条目无法修补的调用方,应回滚修补,或禁用虚拟键打开功能。

提供给 AI 代理的提示
在 `packages/applechu/src/platform/reg_hook.rs` 第 206–210 行:

**部分安装钩子时返回错误的值**

当调用方的 RegOpenKeyExA IAT 条目已被修补,但 RegQueryValueExA 条目未被修补时,`hooked_reg_open_key_ex_a` 会返回一个映射句柄,该句柄由真实的 SOFTWARE 键提供支持;但调用方原生的 `RegQueryValueExA` 会绕过 `hooked_reg_query_value_ex_a`,转而读取真实注册表,而不是虚拟的 OSVersion。

请将打开和查询钩子视为必须成对安装的钩子:对于查询条目无法修补的调用方,应回滚修补,或禁用虚拟键打开功能。
Original comment in English

🟡 Medium · Partial hook returns wrong values

When the caller's RegOpenKeyExA IAT entry is patched but its RegQueryValueExA entry is not, hooked_reg_open_key_ex_a returns a mapped handle backed by the real SOFTWARE key, but the caller's native RegQueryValueExA bypasses hooked_reg_query_value_ex_a and reads the real registry instead of virtual OSVersion.

Treat the open and query hooks as a required pair: roll back or disable virtual opens for callers whose query entry could not be patched.

Prompt for AI agents
In `packages/applechu/src/platform/reg_hook.rs` at lines 206-210:

**Partial hook returns wrong values**

When the caller's RegOpenKeyExA IAT entry is patched but its RegQueryValueExA entry is not, `hooked_reg_open_key_ex_a` returns a mapped handle backed by the real SOFTWARE key, but the caller's native `RegQueryValueExA` bypasses `hooked_reg_query_value_ex_a` and reads the real registry instead of virtual OSVersion.

Treat the open and query hooks as a required pair: roll back or disable virtual opens for callers whose query entry could not be patched.

}
let name = winapi::cstr_to_string(subkey).unwrap_or_default();
if let Some(key_id) = resolve_named_key_id(parent, &name) {
return open_virtual_key(key_id, out);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · 错误地授予了写入权限

当 ANSI 调用方请求写入权限来打开虚拟键时,hooked_reg_open_key_ex_a 会忽略请求的 access,而 open_virtual_key 会以 KEY_READ 权限打开后备键;因此,请求写入权限的调用方虽然收到成功结果,却无法执行该成功结果所承诺允许的写入操作。

请验证请求的访问权限;如果虚拟键无法满足这些权限,请返回适当的错误。

另请参见 packages/applechu/src/platform/reg_hook.rs:539。

提供给 AI 代理的提示
在 `packages/applechu/src/platform/reg_hook.rs` 第 294 行:

**错误地授予了写入权限**

当 ANSI 调用方请求写入权限来打开虚拟键时,`hooked_reg_open_key_ex_a` 会忽略请求的 `access`,而 `open_virtual_key` 会以 `KEY_READ` 权限打开后备键;因此,请求写入权限的调用方虽然收到成功结果,却无法执行该成功结果所承诺允许的写入操作。

请验证请求的访问权限;如果虚拟键无法满足这些权限,请返回适当的错误。

另请参见 `packages/applechu/src/platform/reg_hook.rs:539`。
Original comment in English

🟡 Medium · Write access is falsely granted

When an ANSI caller opens a virtual key requesting write access, hooked_reg_open_key_ex_a ignores the requested access and open_virtual_key opens the backing key with KEY_READ; callers requesting write access therefore receive success but cannot perform the writes that success promises.

Validate the requested access rights and return an appropriate error when the virtual key cannot honor them.

Also at packages/applechu/src/platform/reg_hook.rs:539.

Prompt for AI agents
In `packages/applechu/src/platform/reg_hook.rs` at line 294:

**Write access is falsely granted**

When an ANSI caller opens a virtual key requesting write access, `hooked_reg_open_key_ex_a` ignores the requested `access` and `open_virtual_key` opens the backing key with `KEY_READ`; callers requesting write access therefore receive success but cannot perform the writes that success promises.

Validate the requested access rights and return an appropriate error when the virtual key cannot honor them.

Also at `packages/applechu/src/platform/reg_hook.rs:539`.

Comment on lines +296 to +297
if key_for_handle(parent).is_some() {
return winapi::ERROR_FILE_NOT_FOUND;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中 · ANSI 子键无法继续解析

当游戏打开一个虚拟键,随后请求一个未在 KEYS 中注册的子键时,只要 key_for_handle(parent) 识别出该父键是虚拟键,钩子就会返回 ERROR_FILE_NOT_FOUND,而不会尝试调用原始的 RegOpenKeyExA;因此,调用方无法打开该句柄下其他本来有效的子键。

对于无法解析的子键,请保留原始注册表查询行为,并使用一个以该虚拟键实际注册表路径为根的后备句柄。

提供给 AI 代理的提示
在 `packages/applechu/src/platform/reg_hook.rs` 第 296–297 行:

**ANSI 子键无法继续解析**

当游戏打开一个虚拟键,随后请求一个未在 `KEYS` 中注册的子键时,只要 `key_for_handle(parent)` 识别出该父键是虚拟键,钩子就会返回 `ERROR_FILE_NOT_FOUND`,而不会尝试调用原始的 `RegOpenKeyExA`;因此,调用方无法打开该句柄下其他本来有效的子键。

对于无法解析的子键,请保留原始注册表查询行为,并使用一个以该虚拟键实际注册表路径为根的后备句柄。
Original comment in English

🟡 Medium · ANSI child keys stop resolving

When a game opens a virtual key and then requests a child key not registered in KEYS, the hook returns ERROR_FILE_NOT_FOUND as soon as key_for_handle(parent) recognizes a virtual parent, without trying the original RegOpenKeyExA; callers therefore cannot open an otherwise valid child key beneath that handle.

Preserve the original registry lookup for unresolved child keys, using a backing handle rooted at the virtual key’s actual registry path.

Prompt for AI agents
In `packages/applechu/src/platform/reg_hook.rs` at lines 296-297:

**ANSI child keys stop resolving**

When a game opens a virtual key and then requests a child key not registered in `KEYS`, the hook returns `ERROR_FILE_NOT_FOUND` as soon as `key_for_handle(parent)` recognizes a virtual parent, without trying the original `RegOpenKeyExA`; callers therefore cannot open an otherwise valid child key beneath that handle.

Preserve the original registry lookup for unresolved child keys, using a backing handle rooted at the virtual key’s actual registry path.

@Applesaber Applesaber changed the title fix: 修复 部分游戏启动时的使用RegOpenKeyExA读注册表导致退出的错误 fix: 修复部分游戏启动时的使用 RegOpenKeyExA 读注册表导致退出的错误 Nov 20, 2026
@Applesaber
Applesaber merged commit 868fd3f into MuNET-OSS:main Nov 20, 2026
5 checks passed
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