* fix(javascript): preserve Electron runtime entrypoint paths * fix(javascript): resolve runtime entrypoints before modules * fix(javascript): preserve Electron runtime path semantics * fix(javascript): resolve Electron renderers exactly * fix(javascript): retain runtime package aliases * fix(javascript): retain missing renderer URL paths * fix(javascript): resolve Electron URL and utility entries correctly * fix(javascript): reject suffix-only worker URLs * fix(javascript): respect Electron URL and utility path semantics * fix(javascript): separate Node runtime entrypoints from source imports * fix(comparison): recheck historical calls-only changes (#2223) * fix(comparison): preserve incomplete function call evidence Keep missing, unknown, partial and unresolved call relationships unknown in function comparisons and reconstruction claims. Aggregate IDA caller and callee coverage without overwriting uncertainty. Validate with 144 focused tests, typecheck/lint, docs checks and test discovery. Real providers were not verified; the full headless IDA session suite requires unavailable Windows native controls. * fix(comparison): recheck historical calls-only changes --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> (cherry picked from commit688defca0f) * fix(ci): isolate Linux Hopper process fixture inventory (cherry picked from commit8cac51e121) * fix(android): make DEX descriptor pattern portable (cherry picked from commit1335bcddc5) * fix: repair the static-check failures on the default branch (#2895) * fix: repair the static-check failures on the default branch The default branch fails its own required `Static checks` job three ways, so every pull request reports that job as failed regardless of its own change. - `npm run format:check` reports `src/domain/functionComparison.test.ts` and `src/ida/IdaOperationRunner.ts`. - `npm run lint` reports a duplicate `import { join } from "node:path"` in `tests/boundary/mcp/ghidraInventoryMcp.test.ts` (lines 4 and 17). - `npm run typecheck` reports `format: "devin"` missing from the client format union in `src/application/SupportedClients.ts`, and an unchecked index in `tests/boundary/cli/clientProfileLifecycle.test.ts`, whose pair array is inferred as `string[][]`. Apply the pinned formatter, drop the duplicate import, list the `"devin"` format that its own definition already uses, and mark the pair array `as const`. Validation: `npm run check:fast` and `npm run format:check` pass. * fix(setup): keep Devin on the JSON configuration dialect --------- Co-authored-by: 吴佳浩 <wujiahao@supremind.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> (cherry picked from commitdf3d96da80) --------- Co-authored-by: morluto <morluto@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Lucien <164857476+dakjdakd@users.noreply.github.com> Co-authored-by: 吴佳浩Alben <35291372+XiaoBinGan@users.noreply.github.com> Co-authored-by: 吴佳浩 <wujiahao@supremind.com>
237 lines
8.6 KiB
TypeScript
237 lines
8.6 KiB
TypeScript
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
|
|
import type { ElectronIpcFinding } from "../../domain/javascript/electronStaticAnalysisTypes.js";
|
|
import type { ElectronBoundarySummary } from "../../domain/javascript/javascriptApplicationAnalysis.js";
|
|
import type { JavaScriptModuleArtifactAnalysis } from "./JavaScriptArtifactAnalysisTypes.js";
|
|
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
|
import {
|
|
resolveArtifactPathByContext,
|
|
type ResolveArtifactPathInput,
|
|
} from "./JavaScriptArtifactPathResolution.js";
|
|
|
|
/** One IPC fact retaining its exact owning artifact for graph projection. */
|
|
export interface ElectronIpcRecord {
|
|
readonly key: string;
|
|
readonly file: JavaScriptArtifactFile;
|
|
readonly finding: ElectronIpcFinding;
|
|
}
|
|
|
|
/** An unambiguous literal renderer-to-main static pairing. */
|
|
export interface ElectronIpcPairing {
|
|
readonly transmission: ElectronIpcRecord;
|
|
readonly handler: ElectronIpcRecord;
|
|
}
|
|
|
|
/** Pairing state for one renderer transmission without overclaiming ambiguity. */
|
|
export interface ElectronIpcPairingState {
|
|
readonly transmission: ElectronIpcRecord;
|
|
readonly candidates: readonly ElectronIpcRecord[];
|
|
readonly status: "paired" | "ambiguous" | "unpaired";
|
|
}
|
|
|
|
/** Flatten all per-file IPC facts into deterministic application records. */
|
|
export const collectElectronIpcRecords = (
|
|
analysis: JavaScriptModuleArtifactAnalysis,
|
|
): readonly ElectronIpcRecord[] =>
|
|
analysis.files
|
|
.flatMap(({ file, javascript }) =>
|
|
(javascript?.electron.ipc ?? []).map((finding) => ({
|
|
key: ipcRecordKey(file.path, finding),
|
|
file,
|
|
finding,
|
|
})),
|
|
)
|
|
.sort((left, right) => compareUnicodeCodePoints(left.key, right.key));
|
|
|
|
/** Match only exact literal channels and retain ambiguous matches separately. */
|
|
export const classifyElectronIpcPairings = (
|
|
records: readonly ElectronIpcRecord[],
|
|
): readonly ElectronIpcPairingState[] => {
|
|
const handlers = records.filter(isMainHandler);
|
|
return records.filter(isPairableRendererTransmission).map((transmission) => {
|
|
const candidates =
|
|
transmission.finding.channel === null
|
|
? []
|
|
: handlers.filter(
|
|
(handler) =>
|
|
handler.finding.channel === transmission.finding.channel &&
|
|
compatibleIpcModes(transmission.finding, handler.finding),
|
|
);
|
|
return {
|
|
transmission,
|
|
candidates,
|
|
status:
|
|
candidates.length === 1
|
|
? "paired"
|
|
: candidates.length > 1
|
|
? "ambiguous"
|
|
: "unpaired",
|
|
};
|
|
});
|
|
};
|
|
|
|
/** Return only pairings supported by one unique literal main handler. */
|
|
export const unambiguousElectronIpcPairings = (
|
|
records: readonly ElectronIpcRecord[],
|
|
): readonly ElectronIpcPairing[] =>
|
|
classifyElectronIpcPairings(records).flatMap((state) => {
|
|
const handler = state.candidates[0];
|
|
return state.status === "paired" && handler !== undefined
|
|
? [{ transmission: state.transmission, handler }]
|
|
: [];
|
|
});
|
|
|
|
/** Summarize static Electron findings without treating gaps as absence. */
|
|
export const summarizeElectronBoundaries = (
|
|
analysis: JavaScriptModuleArtifactAnalysis,
|
|
): ElectronBoundarySummary => {
|
|
const files = new Map(analysis.files.map(({ file }) => [file.path, file]));
|
|
const javascript = analysis.files.flatMap(({ javascript: value }) =>
|
|
value === null ? [] : [value],
|
|
);
|
|
const windows = javascript.flatMap(
|
|
({ electron }) => electron.browser_windows,
|
|
);
|
|
const bridges = javascript.flatMap(
|
|
({ electron }) => electron.context_bridge_apis,
|
|
);
|
|
const validations = javascript.flatMap(
|
|
({ electron }) => electron.sender_validations,
|
|
);
|
|
const utilities = analysis.files.flatMap(({ file, javascript: value }) =>
|
|
(value?.electron.utility_processes ?? []).map((finding) => ({
|
|
file,
|
|
finding,
|
|
})),
|
|
);
|
|
const nativeBindings = analysis.files.flatMap(({ file, javascript: value }) =>
|
|
(value?.electron.native_addon_bindings ?? []).map((finding) => ({
|
|
file,
|
|
finding,
|
|
})),
|
|
);
|
|
const ipc = collectElectronIpcRecords(analysis);
|
|
const pairing = classifyElectronIpcPairings(ipc);
|
|
const literalChannels = new Set(
|
|
ipc.flatMap(({ finding }) =>
|
|
finding.channel === null ? [] : [finding.channel],
|
|
),
|
|
);
|
|
return {
|
|
browser_windows: windows.length,
|
|
explicit_web_preferences: windows.reduce(
|
|
(count, window) => count + window.web_preferences.length,
|
|
0,
|
|
),
|
|
preload_entrypoints: windows.filter(
|
|
({ preload_path: path }) => path !== null,
|
|
).length,
|
|
context_bridge_apis: bridges.length,
|
|
exposed_api_members: bridges.reduce(
|
|
(count, bridge) => count + bridge.members.length,
|
|
0,
|
|
),
|
|
ipc: {
|
|
operations: ipc.length,
|
|
literal_channels: literalChannels.size,
|
|
dynamic_channel_operations: ipc.filter(
|
|
({ finding }) => finding.channel === null,
|
|
).length,
|
|
renderer_transmissions: ipc.filter(isRendererTransmission).length,
|
|
renderer_listeners: ipc.filter(
|
|
({ finding }) =>
|
|
finding.side === "renderer" && finding.mode === "listen",
|
|
).length,
|
|
main_handlers: ipc.filter(isMainHandler).length,
|
|
paired_renderer_transmissions: pairing.filter(
|
|
({ status }) => status === "paired",
|
|
).length,
|
|
ambiguous_renderer_transmissions: pairing.filter(
|
|
({ status }) => status === "ambiguous",
|
|
).length,
|
|
unpaired_literal_renderer_transmissions: pairing.filter(
|
|
({ status, transmission }) =>
|
|
status === "unpaired" && transmission.finding.channel !== null,
|
|
).length,
|
|
},
|
|
sender_validation_observations: validations.length,
|
|
utility_processes: utilities.length,
|
|
resolved_utility_entrypoints: utilities.filter(
|
|
({ file, finding }) =>
|
|
finding.module_path !== null &&
|
|
resolvesToFile({
|
|
file,
|
|
specifier: finding.module_path,
|
|
context: finding.module_resolution_context,
|
|
files,
|
|
runtimePathKind: "node-entrypoint",
|
|
}),
|
|
).length,
|
|
native_addon_bindings: nativeBindings.length,
|
|
resolved_native_addon_bindings: nativeBindings.filter(({ file, finding }) =>
|
|
resolvesToFile({
|
|
file,
|
|
specifier: finding.specifier,
|
|
context: "module-specifier",
|
|
files,
|
|
kind: "native-addon",
|
|
moduleKind: finding.module_kind,
|
|
}),
|
|
).length,
|
|
};
|
|
};
|
|
|
|
const compatibleIpcModes = (
|
|
transmission: ElectronIpcFinding,
|
|
handler: ElectronIpcFinding,
|
|
): boolean =>
|
|
transmission.mode === "invoke"
|
|
? handler.mode === "handle"
|
|
: transmission.operation === "send-to-host"
|
|
? false
|
|
: transmission.mode === "send" && handler.mode === "listen";
|
|
|
|
const isRendererTransmission = ({ finding }: ElectronIpcRecord): boolean =>
|
|
finding.side === "renderer" &&
|
|
(finding.mode === "send" || finding.mode === "invoke");
|
|
|
|
const isPairableRendererTransmission = (record: ElectronIpcRecord): boolean =>
|
|
isRendererTransmission(record) && record.finding.operation !== "send-to-host";
|
|
|
|
const isMainHandler = ({ finding }: ElectronIpcRecord): boolean =>
|
|
finding.side === "main" &&
|
|
(finding.mode === "listen" || finding.mode === "handle");
|
|
|
|
interface ResolveToFileInput {
|
|
readonly file: JavaScriptArtifactFile;
|
|
readonly specifier: string;
|
|
readonly context: "module-specifier" | "filesystem-expression";
|
|
readonly files: ReadonlyMap<string, JavaScriptArtifactFile>;
|
|
readonly kind?: JavaScriptArtifactFile["kind"];
|
|
readonly moduleKind?: "import" | "require";
|
|
readonly runtimePathKind?: ResolveArtifactPathInput["runtimePathKind"];
|
|
}
|
|
|
|
const resolvesToFile = (input: ResolveToFileInput): boolean => {
|
|
const resolved = resolveArtifactPathByContext({
|
|
declaredPath: input.specifier,
|
|
sourcePath: input.file.path,
|
|
context: input.context,
|
|
files: input.files,
|
|
...(input.runtimePathKind === undefined
|
|
? {}
|
|
: { runtimePathKind: input.runtimePathKind }),
|
|
...(input.moduleKind === undefined ? {} : { moduleKind: input.moduleKind }),
|
|
}).resolved_path;
|
|
return (
|
|
resolved !== null &&
|
|
(input.kind === undefined || input.files.get(resolved)?.kind === input.kind)
|
|
);
|
|
};
|
|
|
|
const ipcRecordKey = (path: string, finding: ElectronIpcFinding): string => {
|
|
const identity = `${path}\0${String(finding.location.start.line)}:${String(finding.location.start.column)}\0${finding.side}\0${finding.operation}\0${finding.channel ?? finding.channel_expression}\0${JSON.stringify(finding.handler_location)}`;
|
|
return finding.invocation_location === undefined
|
|
? identity
|
|
: `${identity}\0${String(finding.invocation_location.start.line)}:${String(finding.invocation_location.start.column)}`;
|
|
};
|