refactor(tools): return complete analysis results inline

This commit is contained in:
morluto
2026-09-29 14:53:50 +08:00
parent c34efca4cd
commit 2a6eb41147
156 changed files with 2529 additions and 1891 deletions
+5 -19
View File
@@ -5,9 +5,7 @@ const {
} = require("./electron-active-hook-boundaries.cjs");
const MAX_EVENT_NAME_LENGTH = 128;
const MAX_CHANNEL_LENGTH = 1_024;
const MAX_IDENTIFIER_LENGTH = 256;
const MAX_ARGUMENT_SHAPES = 32;
const ipcEventKinds = new Set([
"main-handler-invocation",
"main-event-invocation",
@@ -101,14 +99,12 @@ const record = (event) => {
event: null,
phase: "observed",
channel: null,
channel_truncated: false,
direction: null,
sender: null,
receiver: null,
frame: null,
target: null,
argument_shapes: [],
argument_shapes_truncated: false,
result_shape: null,
process_type: processType(),
source: "electron-active-hook",
@@ -125,21 +121,14 @@ const record = (event) => {
...raw,
correlation_id: boundedString(raw.correlation_id, MAX_IDENTIFIER_LENGTH),
event: boundedString(raw.event, MAX_EVENT_NAME_LENGTH),
channel: boundedString(raw.channel, MAX_CHANNEL_LENGTH),
channel_truncated:
raw.channel_truncated === true ||
(typeof raw.channel === "string" &&
raw.channel.length > MAX_CHANNEL_LENGTH),
channel: typeof raw.channel === "string" ? raw.channel : null,
sender: boundedString(raw.sender, MAX_IDENTIFIER_LENGTH),
receiver: boundedString(raw.receiver, MAX_IDENTIFIER_LENGTH),
frame: boundedString(raw.frame, MAX_IDENTIFIER_LENGTH),
target: boundedString(raw.target, MAX_IDENTIFIER_LENGTH),
argument_shapes: argumentShapes
.slice(0, MAX_ARGUMENT_SHAPES)
.map((value) => boundedString(value, 64) ?? "unknown"),
argument_shapes_truncated:
raw.argument_shapes_truncated === true ||
argumentShapes.length > MAX_ARGUMENT_SHAPES,
argument_shapes: argumentShapes.map(
(value) => boundedString(value, 64) ?? "unknown",
),
result_shape: boundedString(raw.result_shape, 64),
process_type: boundedString(raw.process_type, MAX_IDENTIFIER_LENGTH),
artifact_path: boundedString(raw.artifact_path, 16_384),
@@ -157,10 +146,7 @@ const recordIpc = (kind, channel, args, details = {}) =>
return record({
kind,
channel: typeof channel === "string" ? channel : null,
argument_shapes: values
.slice(0, MAX_ARGUMENT_SHAPES)
.map((value) => shape(value)),
argument_shapes_truncated: values.length > MAX_ARGUMENT_SHAPES,
argument_shapes: values.map((value) => shape(value)),
...details,
});
})();
+2 -11
View File
@@ -88,12 +88,7 @@ const verifyPackagedElectronApplication = async ({
const applicationAnalysis = json(
await run(
cli,
[
"analyze-javascript-application",
applicationRoot,
"--approved",
"--json",
],
["analyze-javascript-application", applicationRoot, "--json"],
environment,
),
);
@@ -106,11 +101,7 @@ const verifyPackagedElectronApplication = async ({
)
throw new Error("packaged JavaScript application analysis CLI failed");
const routedApplicationAnalysis = json(
await run(
cli,
["analyze", applicationRoot, "--approved", "--json"],
environment,
),
await run(cli, ["analyze", applicationRoot, "--json"], environment),
);
assertRoutedApplicationAnalysis(routedApplicationAnalysis);
};
+21 -9
View File
@@ -7,7 +7,7 @@ const exec = promisify(execFile);
const packedHopperBridge = "package/bridge/hopper_bridge.py";
const packedGhidraBridge = "package/bridge/ghidra/ReaGhidraBridge.java";
/** Verify that the packed production bridge rejects a catastrophic regex. */
/** Verify regex search through the packaged production bridge. */
export async function verifyPackedBridge({
root,
workspace,
@@ -38,20 +38,32 @@ export async function verifyPackedBridge({
join(root, "tests/fixtures/bridgeSearchProbe.py"),
join(workspace, packedHopperBridge),
JSON.stringify({
action: "match",
pattern: "(a|aa){1,35}b",
value: "a".repeat(35),
case_sensitive: true,
action: "search",
items: [
["0x1000", "REA_GHIDRA_INVENTORY_ENTRY"],
["0x2000", "unrelated"],
["0x3000", "REA_GHIDRA_LEAF_VALUE"],
],
params: {
pattern: "^REA_GHIDRA_(?:INVENTORY_ENTRY|LEAF_VALUE)$",
mode: "regex",
case_sensitive: true,
},
}),
])
).stdout,
);
const matches = probe.result;
if (
probe.ok !== false ||
probe.diagnostic_type !== "invalid_request" ||
probe.message !== "Regex exceeds the 10000-path backtracking budget"
probe.ok !== true ||
!Array.isArray(matches) ||
matches.length !== 2 ||
matches[0]?.address !== "0x1000" ||
matches[0]?.value !== "REA_GHIDRA_INVENTORY_ENTRY" ||
matches[1]?.address !== "0x3000" ||
matches[1]?.value !== "REA_GHIDRA_LEAF_VALUE"
)
throw new Error(
`packaged Hopper bridge omitted regex bounds: ${JSON.stringify(probe)}`,
`packaged Hopper bridge regex search drifted: ${JSON.stringify(probe)}`,
);
}
+1 -14
View File
@@ -73,19 +73,6 @@ async function verifyBridgeRejections(client) {
{ document: null, procedure: 17 },
"invalid_request",
),
unboundedRegex: await expectRemoteFailure(
client,
"search_strings",
{
pattern: "a+",
mode: "regex",
case_sensitive: true,
offset: 0,
limit: 100,
document: null,
},
"invalid_request",
),
undeclaredMutation: await expectRemoteFailure(
client,
"set_comment",
@@ -122,7 +109,7 @@ export async function verifyInventoryOperations({
document: null,
});
if (stringSearch.total !== 2 || stringSearch.items.length !== 2)
throw new Error("Ghidra bounded regex string search drifted");
throw new Error("Ghidra regex string search drifted");
const stringItem = strings.find(
(item) => item.value === "REA_GHIDRA_INVENTORY_ENTRY",
);