refactor(process): give POSIX PATH search order one owner (#10891)

* refactor(process): give POSIX PATH search order one owner

Program lookup, the packet-tool locator and Jadx's Java lookup each split
PATH and resolved empty and relative entries themselves. They now take the
candidates from posixPathCandidates in src/process/executableSearch and keep
only their own probe and failure reporting. A counted architecture guard
keeps new PATH splits from returning; the remaining Windows and Ghidra
searches are baselined.

* refactor(process): move the colon-split PATH searches onto the search owner

REA's launcher-alias lookup and Ghidra's macOS Java lookup split PATH on
":" and skipped relative entries themselves; they now use
posixPathCandidates with relativeEntries: "skip", and the guard counts
colon splits of PATH as well.

* fix(process): produce PATH candidates lazily so an unused entry cannot fail an earlier match

* refactor(process): give Windows PATH/PATHEXT search order the executable search owner (#10916)

* refactor(process): give Windows PATH/PATHEXT search order the executable search owner

* fix(process): keep later PATH entries searchable after a stray quote or a removed working directory

* fix(reverse): refuse a Windows objdump or Rizin command that PATH does not find (#10953)

* fix(reverse): refuse an objdump or Rizin command Windows PATH does not find instead of launching the bare name

* fix(reverse): report a Windows lookup refusal after cancellation and to capability discovery

* fix(desktop): search a Windows host's PATH as Windows does when doctor looks up a program

programOnPath sent every host through the POSIX PATH search, so on Windows a
relative PATH entry reached absoluteCallerPath with platform linux and the
Windows working directory, which resolved against itself until the stack
overflowed. programOnPath now searches PATH and PATHEXT through
windowsPathCandidates on a Windows host, and absoluteCallerPath refuses a
non-POSIX working directory with a TypeError instead of recursing.
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 18:24:04 +08:00
1 parent 659772952d
commit 422cff00ab
23 files changed
+912 -330

No files matched your search

+20 -19
View File
@@ -17,7 +17,12 @@ import {
} from "./JadxInterruption.js";
import { constants } from "node:fs";
import { access, realpath, stat } from "node:fs/promises";
import { delimiter, isAbsolute, resolve } from "node:path";
import { isAbsolute } from "node:path";
import {
posixPathCandidates,
windowsPathCandidates,
type PathSearchCandidate,
} from "../process/executableSearch.js";
import { inspectWindowsNativeReadiness } from "../process/WindowsAuthority.js";
import { systemWindowsNativeAuthority } from "../windows/WindowsNativeLoader.js";
import { providerStartupTimeoutSchema } from "../config/providerStartupTimeout.js";
@@ -592,27 +597,23 @@ const resolveJava = async (
const executable = process.platform === "win32" ? "java.exe" : "java";
if (environment.JAVA_HOME === undefined) {
const windows = process.platform === "win32";
const path = windows
? (Object.entries(environment).find(
([key]) => key.toLowerCase() === "path",
)?.[1] ?? "")
: (environment.PATH ?? "/usr/bin:/bin");
// Resolve in the caller's directory once. The module probe and the engine
// run in different directories, and the selected executable also owns the
// retained session's cache identity. Empty POSIX PATH components select cwd.
const directories = path.split(delimiter);
for (const directory of windows
? directories.filter((entry) => entry !== "")
: directories) {
// retained session's cache identity. Empty POSIX PATH components select
// cwd. `java.exe` names its extension, so PATHEXT never fails the search.
const windowsSearch = windows
? windowsPathCandidates(executable, environment)
: undefined;
const candidates: Iterable<PathSearchCandidate> =
windowsSearch === undefined
? posixPathCandidates(executable, environment.PATH ?? "/usr/bin:/bin", {
relativeEntries: "resolve",
})
: windowsSearch.ok
? windowsSearch.value
: [];
for (const { path: candidate } of candidates) {
throwIfJadxInterrupted(signal);
// Windows PATH commonly quotes individual entries containing spaces.
const selected =
windows && directory.startsWith('"') && directory.endsWith('"')
? directory.slice(1, -1)
: directory;
const candidate = windows
? resolve(selected, executable)
: absoluteCallerPath(appendCallerPath(selected, executable));
try {
await access(
candidate,