mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
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:
1 parent
659772952d
commit
422cff00ab
23 files changed
+912
-330
No files matched your search
@@ -1,6 +1,10 @@
|
||||
import { statSync } from "node:fs";
|
||||
import { win32 } from "node:path";
|
||||
import { windowsPathEntries } from "../process/WindowsExecutable.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
windowsPathCandidates,
|
||||
type WindowsPathSearchFailure,
|
||||
} from "../process/executableSearch.js";
|
||||
|
||||
export interface WindowsExecutableLookup {
|
||||
/** Windows-formatted working directory; defaults to the process CWD. */
|
||||
@@ -17,43 +21,32 @@ const isRegularFile = (path: string): boolean => {
|
||||
}
|
||||
};
|
||||
|
||||
/** Resolve Windows bare command names against the captured child environment. */
|
||||
/**
|
||||
* Resolve a configured command against the captured child environment. A
|
||||
* path is resolved against `cwd`; a bare name must be found on PATH/PATHEXT,
|
||||
* and is never returned unresolved, because Windows would then also search
|
||||
* the current directory.
|
||||
*/
|
||||
export const resolveWindowsProviderExecutable = (
|
||||
executable: string,
|
||||
environment: Readonly<NodeJS.ProcessEnv>,
|
||||
lookup: WindowsExecutableLookup = {},
|
||||
): string => {
|
||||
): Result<
|
||||
string,
|
||||
{ readonly kind: "not_found" } | WindowsPathSearchFailure
|
||||
> => {
|
||||
const cwd = lookup.cwd ?? process.cwd();
|
||||
const absolute = (...paths: string[]): string => win32.resolve(cwd, ...paths);
|
||||
if (
|
||||
win32.isAbsolute(executable) ||
|
||||
executable.includes("/") ||
|
||||
executable.includes("\\") ||
|
||||
win32.parse(executable).root !== ""
|
||||
)
|
||||
return absolute(executable);
|
||||
return ok(win32.resolve(cwd, executable));
|
||||
|
||||
const pathValue = environment.PATH ?? environment.Path ?? environment.path;
|
||||
if (pathValue === undefined) return executable;
|
||||
const pathEntries = windowsPathEntries(pathValue);
|
||||
const explicitExtension = win32.extname(executable).toLowerCase();
|
||||
if (explicitExtension !== "" && ![".com", ".exe"].includes(explicitExtension))
|
||||
return executable;
|
||||
const extensions =
|
||||
explicitExtension !== ""
|
||||
? [""]
|
||||
: (environment.PATHEXT ?? environment.PathExt ?? ".COM;.EXE")
|
||||
.split(";")
|
||||
.filter((extension) =>
|
||||
[".com", ".exe"].includes(extension.toLowerCase()),
|
||||
);
|
||||
|
||||
for (const entry of pathEntries) {
|
||||
if (entry.length === 0) continue;
|
||||
for (const extension of extensions) {
|
||||
const candidate = absolute(entry, `${executable}${extension}`);
|
||||
if ((lookup.isFile ?? isRegularFile)(candidate)) return candidate;
|
||||
}
|
||||
}
|
||||
return executable;
|
||||
const candidates = windowsPathCandidates(executable, environment, { cwd });
|
||||
if (!candidates.ok) return candidates;
|
||||
for (const { path } of candidates.value)
|
||||
if ((lookup.isFile ?? isRegularFile)(path)) return ok(path);
|
||||
return err({ kind: "not_found" });
|
||||
};
|
||||
@@ -1,5 +1,10 @@
|
||||
import type { ReverseEngineeringServiceRuntimeOptions } from "../application/reverse/ReverseEngineeringService.js";
|
||||
import type { ReverseEngineeringCommandPort } from "../application/reverse/ReverseEngineeringCommandPort.js";
|
||||
import type {
|
||||
ReverseEngineeringCommandPort,
|
||||
ReverseEngineeringCommandSelection,
|
||||
ReverseEngineeringProviderCommand,
|
||||
} from "../application/reverse/ReverseEngineeringCommandPort.js";
|
||||
import { err, ok } from "../domain/result.js";
|
||||
import { ReverseEngineeringService } from "../application/reverse/ReverseEngineeringService.js";
|
||||
import { objdumpCommand } from "../objdump/ObjdumpCommand.js";
|
||||
import { OBJDUMP_PROVIDER_IDENTITY } from "../objdump/ObjdumpProviderIdentity.js";
|
||||
@@ -15,37 +20,50 @@ export const createReverseEngineeringCommandPort = (
|
||||
environment: Readonly<NodeJS.ProcessEnv>,
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
): ReverseEngineeringCommandPort => ({
|
||||
objdump: (input) => ({
|
||||
executable: providerExecutable(
|
||||
objdump: (input) =>
|
||||
selectCommand(
|
||||
environment.REA_OBJDUMP_COMMAND ?? "objdump",
|
||||
environment,
|
||||
platform,
|
||||
{
|
||||
arguments: objdumpCommand(input),
|
||||
identity: OBJDUMP_PROVIDER_IDENTITY,
|
||||
environmentOverrides: { DEBUGINFOD_URLS: "" },
|
||||
},
|
||||
),
|
||||
arguments: objdumpCommand(input),
|
||||
identity: OBJDUMP_PROVIDER_IDENTITY,
|
||||
environmentOverrides: { DEBUGINFOD_URLS: "" },
|
||||
}),
|
||||
rizin: (input) => ({
|
||||
executable: providerExecutable(
|
||||
rizin: (input) =>
|
||||
selectCommand(
|
||||
environment.REA_RIZIN_COMMAND ?? "rizin",
|
||||
environment,
|
||||
platform,
|
||||
{
|
||||
arguments: rizinCommand(input),
|
||||
limitations: rizinCommandLimitations(input),
|
||||
rejection: rizinCommandRejection,
|
||||
identity: RIZIN_PROVIDER_IDENTITY,
|
||||
},
|
||||
),
|
||||
arguments: rizinCommand(input),
|
||||
limitations: rizinCommandLimitations(input),
|
||||
rejection: rizinCommandRejection,
|
||||
identity: RIZIN_PROVIDER_IDENTITY,
|
||||
}),
|
||||
});
|
||||
|
||||
const providerExecutable = (
|
||||
executable: string,
|
||||
/** Bind the configured executable, resolving Windows bare names on PATH. */
|
||||
const selectCommand = (
|
||||
command: string,
|
||||
environment: Readonly<NodeJS.ProcessEnv>,
|
||||
platform: NodeJS.Platform,
|
||||
): string =>
|
||||
platform === "win32"
|
||||
? resolveWindowsProviderExecutable(executable, environment)
|
||||
: executable;
|
||||
profile: Omit<ReverseEngineeringProviderCommand, "executable">,
|
||||
): ReverseEngineeringCommandSelection => {
|
||||
if (platform !== "win32") return ok({ ...profile, executable: command });
|
||||
const resolved = resolveWindowsProviderExecutable(command, environment);
|
||||
if (resolved.ok) return ok({ ...profile, executable: resolved.value });
|
||||
return err({
|
||||
identity: profile.identity,
|
||||
command,
|
||||
reason:
|
||||
resolved.error.kind === "not_found"
|
||||
? { kind: "not_found" }
|
||||
: { kind: "invalid_pathext", extension: resolved.error.extension },
|
||||
});
|
||||
};
|
||||
|
||||
/** Compose BYO reverse-engineering commands without acquiring tools at import time. */
|
||||
export const createReverseEngineeringService = (
|
||||
|
||||
Reference in new issue
Block a user