Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(electron): classify dropped preload configuration at the hook
morluto02aea22f88fe
diff --git a/scripts/electron-active-hook.cjs b/scripts/electron-active-hook.cjsindex 022acd30a..133aa2ebb 100644--- a/scripts/electron-active-hook.cjs+++ b/scripts/electron-active-hook.cjs@@ -91,7 +91,10 @@ const jsonScalarBytes = (value) => {};const eventFamily = (kind, processTypeValue) => {- if (kind === "preload" && processTypeValue === "main")+ if (+ kind === "preload" &&+ (processTypeValue === "main" || processTypeValue === "browser")+ )return "preload-configuration";if (kind.startsWith("ipc-renderer"))return processTypeValue === "renderer" ? "renderer-ipc" : "ipc";diff --git a/src/browser/PlaywrightElectronActiveProjection.test.ts b/src/browser/PlaywrightElectronActiveProjection.test.tsindex 09a5b6910..080e8185b 100644--- a/src/browser/PlaywrightElectronActiveProjection.test.ts+++ b/src/browser/PlaywrightElectronActiveProjection.test.ts@@ -41,8 +41,8 @@ it("projects hook retention and dropped event families through the result schemaevent_serialized_byte_upper_bound: 512,retained: 1,dropped: 2,- dropped_ipc: 0,- dropped_runtime: 2,+ dropped_ipc: 1,+ dropped_runtime: 1,dropped_event_families: [{ family: "renderer-ipc", count: 1 },{ family: "preload-configuration", count: 1 },@@ -68,7 +68,7 @@ it("projects hook retention and dropped event families through the result schema],dropped_event_roles: [{ role: "renderer", count: 1 }],});- expect(result.ipc).toMatchObject({ observed: 1, dropped: 0 });+ expect(result.ipc).toMatchObject({ observed: 1, dropped: 1 });expect(result.timeline).toMatchObject({ observed: 3, dropped: 2 });expect(result.coverage.observed_event_families).toContain("renderer-ipc");expect(result.coverage.unavailable_event_families).not.toContain(@@ -141,3 +141,56 @@ it("keeps renderer coverage unavailable when only the main process was observed"expect(result.coverage.observed_roles).not.toContain("renderer");expect(result.coverage.unavailable_event_families).toContain("renderer-ipc");});++it("does not correlate legacy dropped families and roles", () => {+ const result = projectElectronActiveCapture(+ {+ executable: "/opt/electron",+ application: "/opt/app/main.js",+ },+ [],+ {+ windows: [],+ metrics: [],+ electronVersion: "test-electron",+ hookSnapshot: {+ events: [],+ retention_budget_bytes: 16 * 1024 * 1024,+ estimated_retained_bytes: 0,+ event_serialized_byte_upper_bound: 0,+ retained: 0,+ dropped: 2,+ dropped_ipc: 1,+ dropped_runtime: 1,+ dropped_event_families: [+ { family: "preload", count: 1 },+ { family: "renderer-ipc", count: 1 },+ ],+ dropped_event_roles: [+ { role: "browser", count: 1 },+ { role: "renderer", count: 1 },+ ],+ observed: 2,+ observed_ipc: 1,+ observed_runtime: 1,+ hook_error: false,+ },+ },+ );++ expect(result.coverage.observed_event_families).toContain("preload");+ expect(result.coverage.observed_event_families).not.toContain(+ "preload-configuration",+ );+ expect(result.coverage.unavailable_event_families).toContain(+ "preload-configuration",+ );+ expect(result.coverage.observed_roles).toEqual(["browser", "renderer"]);+ expect(result.retention.dropped_event_families).toEqual([+ { family: "preload", count: 1 },+ { family: "renderer-ipc", count: 1 },+ ]);+ expect(result.limitations).toContain(+ "Dropped preload-family events were not attributed to preload configuration; independently aggregated event families and roles cannot establish that relationship.",+ );+});diff --git a/src/browser/PlaywrightElectronActiveProjection.ts b/src/browser/PlaywrightElectronActiveProjection.tsindex 71f5581b2..d527d3bba 100644--- a/src/browser/PlaywrightElectronActiveProjection.ts+++ b/src/browser/PlaywrightElectronActiveProjection.ts@@ -68,8 +68,8 @@ const eventFamily = (return ipcEventKinds.has(kind) ? "ipc" : kind;};-const createCoverage = (hookSnapshot: ElectronHookSnapshot) => {- const observedEventFamilies: string[] = [+const normalizeObservations = (hookSnapshot: ElectronHookSnapshot) => {+ const observedEventFamilies = [...new Set([...hookSnapshot.events.map(({ kind, process_type }) =>eventFamily(kind, process_type),@@ -77,11 +77,6 @@ const createCoverage = (hookSnapshot: ElectronHookSnapshot) => {...hookSnapshot.dropped_event_families.map(({ family }) => family),]),].sort();- const unavailableEventFamilies = new Set<string>(- observableEventFamilies.filter(- (family) => !observedEventFamilies.includes(family),- ),- );const observedRoles = [...new Set([...hookSnapshot.events.flatMap(({ process_type, kind }) => [@@ -100,6 +95,19 @@ const createCoverage = (hookSnapshot: ElectronHookSnapshot) => {...hookSnapshot.dropped_event_roles.map(({ role }) => role),]),].sort();+ return { observedEventFamilies, observedRoles };+};++const createCoverage = (+ hookSnapshot: ElectronHookSnapshot,+ observations: ReturnType<typeof normalizeObservations>,+) => {+ const { observedEventFamilies, observedRoles } = observations;+ const unavailableEventFamilies = new Set<string>(+ observableEventFamilies.filter(+ (family) => !observedEventFamilies.includes(family),+ ),+ );if (!observedRoles.includes("preload"))unavailableEventFamilies.add("preload");if (!observedRoles.includes("renderer"))@@ -113,18 +121,18 @@ const createCoverage = (hookSnapshot: ElectronHookSnapshot) => {} as const;};-const hasObservedPreloadConfiguration = (+const hasUnattributedDroppedPreloadFamily = (hookSnapshot: ElectronHookSnapshot,): boolean =>- hookSnapshot.events.some(- ({ kind, process_type }) =>- kind === "preload" &&- (process_type === "main" || process_type === "browser"),- ) ||hookSnapshot.dropped_event_families.some(- ({ family, count }) => family === "preload-configuration" && count > 0,+ ({ family, count }) => family === "preload" && count > 0,);+const hasObservedPreloadConfiguration = (+ observations: ReturnType<typeof normalizeObservations>,+): boolean =>+ observations.observedEventFamilies.includes("preload-configuration");+/** Project one provider hook snapshot into the canonical public result. */export const projectElectronActiveCapture = (paths: ElectronCapturePaths,@@ -132,6 +140,7 @@ export const projectElectronActiveCapture = (state: ElectronCaptureState,): ElectronActiveObservationResult => {const { hookSnapshot } = state;+ const observations = normalizeObservations(hookSnapshot);const ipcEvents = hookSnapshot.events.filter(({ kind }) =>ipcEventKinds.has(kind),);@@ -172,17 +181,22 @@ export const projectElectronActiveCapture = (observed_runtime: hookSnapshot.observed_runtime,dropped_runtime: hookSnapshot.dropped_runtime,},- coverage: createCoverage(hookSnapshot),+ coverage: createCoverage(hookSnapshot, observations),limitations: ["IPC payloads are represented by value shapes; payload values are never retained.","IPC direction and sender/receiver identifiers are observed only where Electron exposes them at the hooked boundary.","The runtime timeline records lifecycle, navigation, shell, permission, popup, download, protocol, preload, native-addon, process, and IPC events; activity before hook installation is unavailable.","The preload and renderer process contexts are not instrumented by the main-process -r hook; preload configuration and contextBridge API-shape events are main-boundary observations, not proof of renderer-side execution.",- ...(!hasObservedPreloadConfiguration(hookSnapshot)+ ...(!hasObservedPreloadConfiguration(observations)? ["Preload configuration was not exposed by the observed Electron window metadata. Preload paths and execution remain unavailable.",]: []),+ ...(hasUnattributedDroppedPreloadFamily(hookSnapshot)+ ? [+ "Dropped preload-family events were not attributed to preload configuration; independently aggregated event families and roles cannot establish that relationship.",+ ]+ : []),"Process metrics are an Electron API snapshot and do not prove hostile-local-user isolation.",...(hookSnapshot.dropped > 0? [diff --git a/tests/boundary/browser/electronActiveHook.test.ts b/tests/boundary/browser/electronActiveHook.test.tsindex 99d4a0a3d..63f21dfa6 100644--- a/tests/boundary/browser/electronActiveHook.test.ts+++ b/tests/boundary/browser/electronActiveHook.test.ts@@ -218,6 +218,47 @@ it("retains active hook evidence within its event-retention budget", async () =>);});+it("classifies a dropped browser preload as preload configuration at capture", async () => {+ const root = await createTestTempDirectory(+ "rea-electron-hook-browser-preload-",+ );+ temporary.push(root);+ await writeFile(join(root, "electron.js"), electronModuleSource);+ const script = join(root, "browser-preload.cjs");+ await writeFile(+ script,+ `Object.defineProperty(process, "type", { value: "browser" });+const electron = require("electron");+new electron.BrowserWindow({ webPreferences: { preload: "p".repeat(6 * 1024 * 1024) } });+const snapshot = globalThis.__reaElectronActiveSnapshot();+process.stdout.write(JSON.stringify(snapshot) + "\\n");+`,+ );+ const hook = join(process.cwd(), "scripts/electron-active-hook.cjs");+ const execution = await runNode(hook, script, root, root);+ expect(execution.code, execution.stderr).toBe(0);+ const snapshot = JSON.parse(+ execution.stdout.trim().split("\n").at(-1) ?? "null",+ ) as {+ readonly dropped_event_families: readonly {+ readonly family: string;+ readonly count: number;+ }[];+ readonly dropped_event_roles: readonly {+ readonly role: string;+ readonly count: number;+ }[];+ };+ expect(snapshot.dropped_event_families).toContainEqual({+ family: "preload-configuration",+ count: 1,+ });+ expect(snapshot.dropped_event_roles).toContainEqual({+ role: "browser",+ count: 1,+ });+});+it("preserves fatal process termination after recording uncaught exceptions", async () => {const root = await createTestTempDirectory("rea-electron-hook-fatal-");temporary.push(root);