fix(android): support owned JADX stdio on Windows (#1276)
Support owned JADX stdio on Windows x64, preserve protocol input errors through cancellation, and verify native stdin and Android CLI/MCP lifecycle on the real Windows host. Closes #1262
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { constants } from "node:fs";
|
||||
import { access, realpath, stat } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
||||
import { systemWindowsNativeAuthority } from "../windows/WindowsNativeLoader.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
|
||||
import type { AndroidOperation } from "../domain/android/androidAnalysis.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
@@ -116,7 +117,7 @@ const readJadxConfiguration = async (
|
||||
): Promise<JadxConfiguration> => {
|
||||
requireSupportedHost();
|
||||
const jar = await resolveJar(environment);
|
||||
const java = resolveJava(environment);
|
||||
const java = await resolveJava(environment, signal);
|
||||
await requireJavaHomeExecutable(environment.JAVA_HOME, java);
|
||||
const jvmArguments = resolveJvmArguments(environment);
|
||||
await inspectJavaRuntime(java, environment, signal);
|
||||
@@ -169,9 +170,26 @@ const requireEngineArchive = async (
|
||||
|
||||
const requireSupportedHost = (): void => {
|
||||
if (process.platform === "linux" || process.platform === "darwin") return;
|
||||
if (process.platform === "win32" && process.arch === "x64") {
|
||||
const loaded = systemWindowsNativeAuthority();
|
||||
if (loaded.available && loaded.authority.inspection.protocolStdin === true)
|
||||
return;
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
loaded.available
|
||||
? "The bundled Windows native artifact lacks owned protocol stdin; use a matching current Windows x64 REA package."
|
||||
: loaded.reason,
|
||||
{
|
||||
platform: process.platform,
|
||||
architecture: process.arch,
|
||||
phase: "process-ownership",
|
||||
owned_protocol_stdin: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
throw configurationFailure(
|
||||
"unsupported_host",
|
||||
`Android JADX subprocess ownership is unsupported on ${process.platform}; use Linux or macOS. The metadata bridge has real-provider verification on macOS arm64.`,
|
||||
`Android JADX subprocess ownership is unsupported on ${process.platform}/${process.arch}; use Linux, macOS, or Windows x64 with its bundled native controls.`,
|
||||
{ platform: process.platform },
|
||||
);
|
||||
};
|
||||
@@ -206,12 +224,52 @@ const resolveJar = async (
|
||||
}
|
||||
};
|
||||
|
||||
const resolveJava = (
|
||||
const resolveJava = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
): string => {
|
||||
if (environment.JAVA_HOME === undefined) return "java";
|
||||
signal?: AbortSignal,
|
||||
): Promise<string> => {
|
||||
const executable = process.platform === "win32" ? "java.exe" : "java";
|
||||
if (environment.JAVA_HOME === undefined) {
|
||||
if (process.platform !== "win32") return executable;
|
||||
const path =
|
||||
Object.entries(environment).find(
|
||||
([key]) => key.toLowerCase() === "path",
|
||||
)?.[1] ?? "";
|
||||
for (const directory of [process.cwd(), ...path.split(delimiter)]) {
|
||||
signal?.throwIfAborted();
|
||||
// Windows PATH commonly quotes individual entries containing spaces.
|
||||
const selected =
|
||||
directory.startsWith('"') && directory.endsWith('"')
|
||||
? directory.slice(1, -1)
|
||||
: directory;
|
||||
const candidate = resolve(selected, executable);
|
||||
try {
|
||||
await access(candidate, constants.R_OK | constants.X_OK);
|
||||
if ((await stat(candidate)).isFile()) return await realpath(candidate);
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
typeof cause === "object" &&
|
||||
cause !== null &&
|
||||
"code" in cause &&
|
||||
(cause.code === "ENOENT" || cause.code === "ENOTDIR")
|
||||
)
|
||||
continue;
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
`Cannot inspect selected Java executable ${candidate}: ${errorText(cause)}`,
|
||||
{ java_executable: candidate },
|
||||
cause,
|
||||
);
|
||||
}
|
||||
}
|
||||
throw configurationFailure(
|
||||
"runtime_missing",
|
||||
"Cannot find java.exe on the selected Windows PATH. Select a full JDK with JAVA_HOME or PATH, then verify it with java --list-modules. REA does not install Java.",
|
||||
{ java_executable: executable },
|
||||
);
|
||||
}
|
||||
if (isAbsolute(environment.JAVA_HOME))
|
||||
return join(environment.JAVA_HOME, "bin", "java");
|
||||
return join(environment.JAVA_HOME, "bin", executable);
|
||||
throw configurationFailure(
|
||||
"open_options_invalid",
|
||||
"JAVA_HOME must select an existing JDK by absolute path; omit it to use java on PATH.",
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
type Transport,
|
||||
} from "@modelcontextprotocol/client";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { finished } from "node:stream/promises";
|
||||
import type {
|
||||
OwnedProviderProcessSpawnOptions,
|
||||
SpawnedOwnedProviderProcess,
|
||||
@@ -19,7 +20,7 @@ import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
const MAX_FRAME_BYTES = 8 * 1024 * 1024;
|
||||
const MAX_OPERATION_BYTES = 32 * 1024 * 1024;
|
||||
|
||||
/** Injectable process acquisition seam; the production launcher owns a POSIX group. */
|
||||
/** Injectable acquisition seam; production owns a POSIX group or Windows job. */
|
||||
export type JadxLauncher = (
|
||||
options: OwnedProviderProcessSpawnOptions,
|
||||
) => Promise<SpawnedOwnedProviderProcess>;
|
||||
@@ -139,8 +140,19 @@ export class JadxMcpTransport implements Transport {
|
||||
process?.stderr?.off("data", this.#countStderr);
|
||||
process?.off("error", this.#error);
|
||||
process?.off("exit", this.#exit);
|
||||
process?.stdin?.off("error", this.#error);
|
||||
const input = process?.stdin;
|
||||
// A job termination can complete an in-flight pipe write asynchronously.
|
||||
// Observe its errors until the owned Writable has finished closing.
|
||||
const inputClosed =
|
||||
input === undefined || input === null
|
||||
? undefined
|
||||
: finished(input, { readable: false, cleanup: true }).catch(
|
||||
() => undefined,
|
||||
);
|
||||
const stopped = await this.#supervisor?.stop();
|
||||
input?.destroy();
|
||||
await inputClosed;
|
||||
input?.off("error", this.#error);
|
||||
this.onclose?.();
|
||||
if (stopped?.status === "incomplete")
|
||||
throw new ProviderCleanupError("jadx", [this.runId], {
|
||||
|
||||
Reference in New Issue
Block a user