Repository navigation
fix(windows): load native controls in Node-API hosts not named node.exe - #1531
Merged
Merged
Conversation
Delay-load the Node-API import library and bind "node.exe" to the running process, matching node-gyp's win_delay_load_hook. The addon now loads under any Node-API host (Node.js, Bun) regardless of its executable file name.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
10 tasks done
Owner
|
@xeropresence, thanks for finding the hardcoded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The bundled Windows addon (
rea-windows-x64.node) imports its Node-API functions from a module named exactlynode.exe. When REA runs in any other Node-API host, Windows can't resolve that import and the addon fails toload. I hit this with Bun 1.4.2 on Windows x64. REA then reports Windows native controls as unavailable. That breaks private runtime roots (including the headless IDA provider's private workspace), owned processes, and
the JADX runtime check.
This PR delay-loads the Node-API imports and points
node.exeat the running executable. node-gyp addons use the same approach (win_delay_load_hook.cc).I didn't open an issue first. The reproduction is below.
Problem and expected behavior
Trigger: run REA on Windows in a host whose executable isn't
node.exe. For example, a Bun global install runsrea.mjswithbun.exewhen nonodeis on PATH.rea doctor --provider ida→ida-private_workspace:REA Windows native controls are unavailable: LoadLibrary failed: The specified module could not be found.open_binarywith a headless IDA registration →provider_unavailable.Expected: the addon loads in whatever process loads it, as long as that process exports the required Node-API functions.
bun.exeexports everynapi_*function the addon imports.Cause:
scripts/build-windows-native.mjswritesLIBRARY node.exeinto the.deffile and builds a normal import library withdlltool -l. That putsnode.exein the addon's PE import directory. This build has nodelay-load hook, which node-gyp builds use to avoid the problem.
Change and scope
scripts/build-windows-native.mjs:dlltool -l→-y(--output-delaylib), which builds a delay-import library for the same symbol list.native/windows/src/addon.cc: sets__pfnDliNotifyHook2. When thedliNotePreLoadLibrarynotification is fornode.exe, the hook returnsGetModuleHandleW(nullptr)(the host executable). For everything else itreturns
nullptr, so the default MinGW delay-load helper handles it.No changes to TypeScript, the manifest schema, the ABI version, or the Node-API version. This PR doesn't claim Bun as a supported runtime and doesn't change
engines.Contract and boundary impact
build:windows-native) and addon import resolution.node.exeresolves to the same module as before. Linux and macOS never load this artifact.node.exe.rea-windows-x64.nodeand theartifactSha256inmanifest.jsonchange. Nothing else in the package changes.Evidence and regression coverage
fedfd4ce…), Bun 1.4.2, Windows x64. The doctor andopen_binaryfailures are quoted above.node.exe,ADVAPI32.dll,bcrypt.dll,KERNEL32.dll,msvcrt.dllandntdll.dll. The patched artifact imports only the five system DLLs; its Node-API calls gothrough
__delayLoadHelper2.node.exesaved under a different file name and callinspect. That would fail on the baserevision and pass here. Happy to add it. Bun on Windows is the only non-Node host I tested.
Not evidence-bearing; the evidence checklist doesn't apply.
Validation performed
Fork CI run: https://github.com/xeropresence/rea/actions/runs/38042302533. It tested the PR merged into
mainat46c9cba0, one commit behind the currentmain. That newer commit doesn't touch the native code or itsbuild scripts, and the branch merges cleanly.
Build bundled Windows x64 native controls(npm run build:windows-native,npm run verify:windows-native:artifact) — passedWindows capability and package lane(npm run verify:windows-nativeunder Node onwindows-latest) — passedStatic checks,Build package,Native package baseline(linux x64, linux arm64, darwin arm64), test shards 1, 2 and 4 — passedjavascriptSemanticAnalysis.member_mutations.test.ts:645,expected 2573.855838999996 to be less than 2000.Test (coverage + timing)alsofailed; I didn't investigate it separately.
Local test on Windows x64: REA 6.3.0 with the CI-built artifact installed, run with
bun.exe1.4.2:rea doctor --provider ida— healthy:Private workspace authority is available (native-authority).open_binary(providerida, headlessidalib-mcpfrom current ida-pro-mcpmain) →analyze_function wmain→close_binaryon a copy ofC:\Windows\System32\whoami.exe— all succeeded, and the privateworkspace was removed.
Compatibility, safety, and release
verify:ghidra:windows.node.exe, and it returns the host module that is already loaded; it never loads a file from disk. One behavior change: if a host is missing aNode-API function, the error now happens the first time that function is called, as a delay-load exception, not when
LoadLibraryloads the addon. Node.js exports every function the addon uses, so Node behavior isunchanged. If failing at load time matters, module initialization could force all delay imports to resolve up front.
Review checklist
type(scope): outcome.