refactor: finish lint cleanup
This commit is contained in:
@@ -3,7 +3,7 @@ import { open } from "node:fs/promises";
|
||||
import { classifyArtifactPath } from "../ArtifactGraphConstruction.js";
|
||||
import type { ArtifactNode } from "../../domain/artifactGraph.js";
|
||||
|
||||
export const classifyContainerExtension = (
|
||||
const classifyContainerExtension = (
|
||||
path: string,
|
||||
): ArtifactNode["format"] | undefined => {
|
||||
const lower = path.toLowerCase();
|
||||
|
||||
@@ -31,10 +31,10 @@ export interface PendingIntegrityContradiction {
|
||||
readonly unpacked: boolean;
|
||||
}
|
||||
|
||||
export const UNAVAILABLE_UNPACKED_LIMITATION =
|
||||
const UNAVAILABLE_UNPACKED_LIMITATION =
|
||||
"ASAR unpacked companion bytes were unavailable; no content hash or child artifact was produced.";
|
||||
|
||||
export const emptyScan = (): {
|
||||
const emptyScan = (): {
|
||||
readonly nodes: Map<string, ArtifactNode>;
|
||||
readonly occurrences: MutableOccurrence[];
|
||||
readonly pendingContradictions: PendingIntegrityContradiction[];
|
||||
|
||||
@@ -75,6 +75,8 @@ export const runControlledReplayValidated = async (
|
||||
options.signal,
|
||||
);
|
||||
if (!prepared.ok) return prepared;
|
||||
if (isAborted(options.signal))
|
||||
return err(new AnalysisCancelledError(OPERATION));
|
||||
|
||||
if (input.mode === "plan")
|
||||
return ok(
|
||||
|
||||
+2
-111
@@ -20,6 +20,7 @@ import { AnalysisInputError, projectAnalysisError } from "./domain/errors.js";
|
||||
import type { JsonValue } from "./domain/jsonValue.js";
|
||||
import type { Logger } from "./logger.js";
|
||||
import { CLI_COMMANDS } from "./cliCommandNames.js";
|
||||
import { browserPageInspectionOptions } from "./cliObservationOptions.js";
|
||||
|
||||
const browserScopeOptions = {
|
||||
allowedOrigins: z
|
||||
@@ -112,117 +113,7 @@ const registerPageInspection = (
|
||||
endpoint: z.string().describe("Configured loopback CDP HTTP endpoint"),
|
||||
targetId: z.string().describe("Target ID from list-browser-targets"),
|
||||
}),
|
||||
options: z.object({
|
||||
...browserScopeOptions,
|
||||
observationMs: boundedCount(
|
||||
"observation duration in milliseconds",
|
||||
10_000,
|
||||
500,
|
||||
0,
|
||||
),
|
||||
includeAccessibilityText: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded accessibility text"),
|
||||
includeConsoleText: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded console message text"),
|
||||
consoleTextApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve capturing console message text"),
|
||||
includeJsonBodyShapes: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include structural shapes of JSON response bodies"),
|
||||
jsonBodySchemaApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe(
|
||||
"Approve inspecting JSON response bodies for structural shapes",
|
||||
),
|
||||
includeWebsocketShapes: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include structural shapes of WebSocket payloads"),
|
||||
websocketShapeApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe(
|
||||
"Approve inspecting WebSocket payloads for structural shapes",
|
||||
),
|
||||
includeScriptSources: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded JavaScript source text"),
|
||||
includeStorageKeys: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include storage key names without values"),
|
||||
maxFrames: boundedCount("page frames", 1_000, 200),
|
||||
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
|
||||
maxAxNodes: boundedCount("accessibility nodes", 10_000, 2_000),
|
||||
maxAxTextFieldBytes: boundedBytes(
|
||||
"one accessibility text field",
|
||||
16 * 1_024,
|
||||
1_024,
|
||||
),
|
||||
maxTotalAxTextBytes: boundedBytes(
|
||||
"total accessibility text",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxScripts: boundedCount("scripts", 1_000, 200),
|
||||
maxResources: boundedCount("resources", 10_000, 2_000),
|
||||
maxWorkers: boundedCount("workers", 5_000, 500),
|
||||
maxStorageKeys: boundedCount("storage keys", 10_000, 1_000),
|
||||
maxScriptSourceBytes: boundedBytes(
|
||||
"one script source",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalScriptSourceBytes: boundedBytes(
|
||||
"total script source",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
maxNetworkEvents: boundedCount("network events", 10_000, 1_000),
|
||||
maxConsoleEvents: boundedCount("console events", 2_000, 200),
|
||||
maxConsoleTextFieldBytes: boundedBytes(
|
||||
"one console text field",
|
||||
16 * 1_024,
|
||||
1_024,
|
||||
),
|
||||
maxTotalConsoleTextBytes: boundedBytes(
|
||||
"total console text",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxJsonBodyBytes: boundedBytes(
|
||||
"one JSON response body",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalJsonBodyBytes: boundedBytes(
|
||||
"total JSON response bodies",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
maxJsonShapeNodes: boundedCount("JSON shape nodes", 100_000, 5_000),
|
||||
maxJsonShapeDepth: boundedCount("JSON shape depth", 100, 20),
|
||||
maxWebsocketEvents: boundedCount("WebSocket events", 5_000, 500),
|
||||
maxWebsocketShapeBytes: boundedBytes(
|
||||
"one WebSocket shape",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxTotalWebsocketShapeBytes: boundedBytes(
|
||||
"total WebSocket shapes",
|
||||
16 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
}),
|
||||
options: browserPageInspectionOptions,
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-web-page", async () => {
|
||||
const context = await browserContext();
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import { z } from "incur";
|
||||
|
||||
import { loadConfiguredPermissionAuthority } from "../application/PermissionConfiguration.js";
|
||||
import { CdpBrowserProvider } from "../browser/CdpBrowserProvider.js";
|
||||
import { parseConfig } from "../config.js";
|
||||
import { projectAnalysisError } from "../domain/errors.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
|
||||
export const browserScopeOptions = {
|
||||
allowedOrigins: z
|
||||
.array(z.string().min(1))
|
||||
.optional()
|
||||
.describe(
|
||||
"Exact origins to observe; defaults to REA_BROWSER_ALLOWED_ORIGINS_JSON",
|
||||
),
|
||||
approved: z.boolean().default(false).describe("Approve passive observation"),
|
||||
};
|
||||
|
||||
export const boundedCount = (
|
||||
subject: string,
|
||||
maximum: number,
|
||||
fallback: number,
|
||||
minimum = 1,
|
||||
) =>
|
||||
z
|
||||
.number()
|
||||
.int()
|
||||
.min(minimum)
|
||||
.max(maximum)
|
||||
.default(fallback)
|
||||
.describe(`Maximum ${subject}`);
|
||||
|
||||
export const boundedBytes = (
|
||||
subject: string,
|
||||
maximum: number,
|
||||
fallback: number,
|
||||
) => boundedCount(`${subject} in bytes`, maximum, fallback);
|
||||
|
||||
export const browserContext = async () => {
|
||||
const config = parseConfig(process.env);
|
||||
if (!config.ok) return { ok: false as const, error: cliError(config.error) };
|
||||
const authority = await loadConfiguredPermissionAuthority(config.value);
|
||||
if (!authority.ok)
|
||||
return { ok: false as const, error: cliError(authority.error) };
|
||||
return {
|
||||
ok: true as const,
|
||||
authority: authority.value,
|
||||
provider: new CdpBrowserProvider(),
|
||||
allowedBrowserOrigins: config.value.browserAllowedOrigins,
|
||||
};
|
||||
};
|
||||
|
||||
export const cliError = (
|
||||
error: Parameters<typeof projectAnalysisError>[0],
|
||||
): JsonValue => ({
|
||||
error: "Browser observation failed",
|
||||
...projectAnalysisError(error),
|
||||
});
|
||||
+20
-168
@@ -20,6 +20,10 @@ import type { JsonValue } from "./domain/jsonValue.js";
|
||||
import type { Logger } from "./logger.js";
|
||||
import { CLI_COMMANDS } from "./cliCommandNames.js";
|
||||
import { parseCliJsonInput } from "./cliJsonInput.js";
|
||||
import {
|
||||
electronPageInspectionOptions,
|
||||
javascriptApplicationOptions,
|
||||
} from "./cliObservationOptions.js";
|
||||
|
||||
const scopeOptions = {
|
||||
allowedFileRoots: z
|
||||
@@ -73,6 +77,14 @@ const registerJavaScriptRuntimeReconciliationCommand = (
|
||||
const registerElectronObservationCommands = (
|
||||
cli: ReturnType<typeof Cli.create>,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
registerElectronTargetList(cli, logger);
|
||||
registerElectronPageInspection(cli, logger);
|
||||
};
|
||||
|
||||
const registerElectronTargetList = (
|
||||
cli: ReturnType<typeof Cli.create>,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
cli.command(CLI_COMMANDS.listElectronTargets, {
|
||||
description: "List root-confined file pages from Electron CDP",
|
||||
@@ -118,6 +130,12 @@ const registerElectronObservationCommands = (
|
||||
return result.ok ? result.value : cliError(result.error);
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const registerElectronPageInspection = (
|
||||
cli: ReturnType<typeof Cli.create>,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
cli.command(CLI_COMMANDS.inspectElectronPage, {
|
||||
description: "Passively inspect one root-confined Electron file page",
|
||||
args: z.object({
|
||||
@@ -126,73 +144,7 @@ const registerElectronObservationCommands = (
|
||||
.describe("Configured loopback Electron CDP endpoint"),
|
||||
targetId: z.string().describe("Target ID from list-electron-targets"),
|
||||
}),
|
||||
options: z.object({
|
||||
...scopeOptions,
|
||||
observationMs: z
|
||||
.number()
|
||||
.int()
|
||||
.min(0)
|
||||
.max(10_000)
|
||||
.default(100)
|
||||
.describe("Observation duration in milliseconds"),
|
||||
includeScriptSources: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded JavaScript source text"),
|
||||
sourceCaptureApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve capturing bounded script source text"),
|
||||
maxFrames: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(1_000)
|
||||
.default(200)
|
||||
.describe("Maximum page frames"),
|
||||
maxDomNodes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(10_000)
|
||||
.default(2_000)
|
||||
.describe("Maximum DOM nodes"),
|
||||
maxScripts: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(2_000)
|
||||
.default(500)
|
||||
.describe("Maximum scripts"),
|
||||
maxResources: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(10_000)
|
||||
.default(2_000)
|
||||
.describe("Maximum resources"),
|
||||
maxWorkers: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(5_000)
|
||||
.default(500)
|
||||
.describe("Maximum workers"),
|
||||
maxScriptSourceBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(4 * 1_024 * 1_024)
|
||||
.default(1_024 * 1_024)
|
||||
.describe("Maximum size of one captured script source"),
|
||||
maxTotalScriptSourceBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.max(16 * 1_024 * 1_024)
|
||||
.default(4 * 1_024 * 1_024)
|
||||
.describe("Maximum total captured script source size"),
|
||||
}),
|
||||
options: electronPageInspectionOptions,
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-electron-page", async () => {
|
||||
const context = await electronContext();
|
||||
@@ -237,107 +189,7 @@ const registerJavaScriptApplicationCommand = (
|
||||
args: z.object({
|
||||
path: z.string().describe("Absolute ASAR or extracted application path"),
|
||||
}),
|
||||
options: z.object({
|
||||
approved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve reading the application artifact"),
|
||||
format: z
|
||||
.enum(["auto", "asar", "directory"])
|
||||
.default("auto")
|
||||
.describe("Application artifact format"),
|
||||
sourceMapReadApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe(
|
||||
"Approve reading local source maps referenced by the application",
|
||||
),
|
||||
maxEntries: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(8_000)
|
||||
.describe("Maximum artifact entries to inspect"),
|
||||
maxTotalArtifactBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(512 * 1_024 * 1_024)
|
||||
.describe("Maximum total uncompressed artifact content to inspect"),
|
||||
maxArtifactEntryBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(128 * 1_024 * 1_024)
|
||||
.describe("Maximum uncompressed content for one artifact entry"),
|
||||
maxCompressionRatio: z
|
||||
.number()
|
||||
.min(1)
|
||||
.default(1_000)
|
||||
.describe(
|
||||
"Maximum accepted compressed-to-uncompressed expansion ratio",
|
||||
),
|
||||
maxDepth: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(64)
|
||||
.describe("Maximum artifact directory depth"),
|
||||
maxPathBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(4_096)
|
||||
.describe("Maximum encoded artifact path length"),
|
||||
maxTextFiles: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(5_000)
|
||||
.describe("Maximum text files to parse"),
|
||||
maxTotalTextBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(128 * 1_024 * 1_024)
|
||||
.describe("Maximum total text content to parse"),
|
||||
maxTextFileBytes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(8 * 1_024 * 1_024)
|
||||
.describe("Maximum size of one parsed text file"),
|
||||
maxAstNodes: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(2_000_000)
|
||||
.describe("Maximum JavaScript AST nodes to parse"),
|
||||
maxFindings: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(8_000)
|
||||
.describe("Maximum static-analysis findings to return"),
|
||||
maxModules: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(20_000)
|
||||
.describe("Maximum application modules to project"),
|
||||
maxSourceMapSources: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(5_000)
|
||||
.describe("Maximum original sources from source maps"),
|
||||
maxParseMilliseconds: z
|
||||
.number()
|
||||
.int()
|
||||
.min(1)
|
||||
.default(30_000)
|
||||
.describe("Maximum JavaScript parsing time in milliseconds"),
|
||||
}),
|
||||
options: javascriptApplicationOptions,
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(
|
||||
logger,
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import { z } from "incur";
|
||||
|
||||
const boundedCount = (
|
||||
subject: string,
|
||||
maximum: number,
|
||||
fallback: number,
|
||||
minimum = 1,
|
||||
) =>
|
||||
z
|
||||
.number()
|
||||
.int()
|
||||
.min(minimum)
|
||||
.max(maximum)
|
||||
.default(fallback)
|
||||
.describe(`Maximum ${subject}`);
|
||||
|
||||
const boundedBytes = (subject: string, maximum: number, fallback: number) =>
|
||||
boundedCount(`${subject} in bytes`, maximum, fallback);
|
||||
|
||||
const positiveCount = (subject: string, fallback: number) =>
|
||||
z.number().int().min(1).default(fallback).describe(`Maximum ${subject}`);
|
||||
|
||||
const browserScopeOptions = {
|
||||
allowedOrigins: z
|
||||
.array(z.string().min(1))
|
||||
.optional()
|
||||
.describe(
|
||||
"Exact origins to observe; defaults to REA_BROWSER_ALLOWED_ORIGINS_JSON",
|
||||
),
|
||||
approved: z.boolean().default(false).describe("Approve passive observation"),
|
||||
};
|
||||
|
||||
export const browserPageInspectionOptions = z.object({
|
||||
...browserScopeOptions,
|
||||
observationMs: boundedCount(
|
||||
"observation duration in milliseconds",
|
||||
10_000,
|
||||
500,
|
||||
0,
|
||||
),
|
||||
includeAccessibilityText: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded accessibility text"),
|
||||
includeConsoleText: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded console message text"),
|
||||
consoleTextApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve capturing console message text"),
|
||||
includeJsonBodyShapes: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include structural shapes of JSON response bodies"),
|
||||
jsonBodySchemaApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve inspecting JSON response bodies for structural shapes"),
|
||||
includeWebsocketShapes: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include structural shapes of WebSocket payloads"),
|
||||
websocketShapeApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve inspecting WebSocket payloads for structural shapes"),
|
||||
includeScriptSources: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded JavaScript source text"),
|
||||
includeStorageKeys: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include storage key names without values"),
|
||||
maxFrames: boundedCount("page frames", 1_000, 200),
|
||||
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
|
||||
maxAxNodes: boundedCount("accessibility nodes", 10_000, 2_000),
|
||||
maxAxTextFieldBytes: boundedBytes(
|
||||
"one accessibility text field",
|
||||
16 * 1_024,
|
||||
1_024,
|
||||
),
|
||||
maxTotalAxTextBytes: boundedBytes(
|
||||
"total accessibility text",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxScripts: boundedCount("scripts", 1_000, 200),
|
||||
maxResources: boundedCount("resources", 10_000, 2_000),
|
||||
maxWorkers: boundedCount("workers", 5_000, 500),
|
||||
maxStorageKeys: boundedCount("storage keys", 10_000, 1_000),
|
||||
maxScriptSourceBytes: boundedBytes(
|
||||
"one script source",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalScriptSourceBytes: boundedBytes(
|
||||
"total script source",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
maxNetworkEvents: boundedCount("network events", 10_000, 1_000),
|
||||
maxConsoleEvents: boundedCount("console events", 2_000, 200),
|
||||
maxConsoleTextFieldBytes: boundedBytes(
|
||||
"one console text field",
|
||||
16 * 1_024,
|
||||
1_024,
|
||||
),
|
||||
maxTotalConsoleTextBytes: boundedBytes(
|
||||
"total console text",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxJsonBodyBytes: boundedBytes(
|
||||
"one JSON response body",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalJsonBodyBytes: boundedBytes(
|
||||
"total JSON response bodies",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
maxJsonShapeNodes: boundedCount("JSON shape nodes", 100_000, 5_000),
|
||||
maxJsonShapeDepth: boundedCount("JSON shape depth", 100, 20),
|
||||
maxWebsocketEvents: boundedCount("WebSocket events", 5_000, 500),
|
||||
maxWebsocketShapeBytes: boundedBytes(
|
||||
"one WebSocket shape",
|
||||
1_024 * 1_024,
|
||||
64 * 1_024,
|
||||
),
|
||||
maxTotalWebsocketShapeBytes: boundedBytes(
|
||||
"total WebSocket shapes",
|
||||
16 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
});
|
||||
|
||||
const electronScopeOptions = {
|
||||
allowedFileRoots: z
|
||||
.array(z.string().min(1))
|
||||
.optional()
|
||||
.describe("Filesystem roots; defaults to REA_ELECTRON_FILE_ROOTS_JSON"),
|
||||
approved: z.boolean().default(false).describe("Approve passive observation"),
|
||||
};
|
||||
|
||||
export const electronPageInspectionOptions = z.object({
|
||||
...electronScopeOptions,
|
||||
observationMs: boundedCount(
|
||||
"observation duration in milliseconds",
|
||||
10_000,
|
||||
100,
|
||||
0,
|
||||
),
|
||||
includeScriptSources: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Include bounded JavaScript source text"),
|
||||
sourceCaptureApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve capturing bounded script source text"),
|
||||
maxFrames: boundedCount("page frames", 1_000, 200),
|
||||
maxDomNodes: boundedCount("DOM nodes", 10_000, 2_000),
|
||||
maxScripts: boundedCount("scripts", 2_000, 500),
|
||||
maxResources: boundedCount("resources", 10_000, 2_000),
|
||||
maxWorkers: boundedCount("workers", 5_000, 500),
|
||||
maxScriptSourceBytes: boundedBytes(
|
||||
"one captured script source",
|
||||
4 * 1_024 * 1_024,
|
||||
1_024 * 1_024,
|
||||
),
|
||||
maxTotalScriptSourceBytes: boundedBytes(
|
||||
"total captured script source",
|
||||
16 * 1_024 * 1_024,
|
||||
4 * 1_024 * 1_024,
|
||||
),
|
||||
});
|
||||
|
||||
export const javascriptApplicationOptions = z.object({
|
||||
approved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe("Approve reading the application artifact"),
|
||||
format: z
|
||||
.enum(["auto", "asar", "directory"])
|
||||
.default("auto")
|
||||
.describe("Application artifact format"),
|
||||
sourceMapReadApproved: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.describe(
|
||||
"Approve reading local source maps referenced by the application",
|
||||
),
|
||||
maxEntries: positiveCount("artifact entries to inspect", 8_000),
|
||||
maxTotalArtifactBytes: positiveCount(
|
||||
"total uncompressed artifact content to inspect",
|
||||
512 * 1_024 * 1_024,
|
||||
),
|
||||
maxArtifactEntryBytes: positiveCount(
|
||||
"uncompressed content for one artifact entry",
|
||||
128 * 1_024 * 1_024,
|
||||
),
|
||||
maxCompressionRatio: z
|
||||
.number()
|
||||
.min(1)
|
||||
.default(1_000)
|
||||
.describe("Maximum accepted compressed-to-uncompressed expansion ratio"),
|
||||
maxDepth: positiveCount("artifact directory depth", 64),
|
||||
maxPathBytes: positiveCount("encoded artifact path length", 4_096),
|
||||
maxTextFiles: positiveCount("text files to parse", 5_000),
|
||||
maxTotalTextBytes: positiveCount(
|
||||
"total text content to parse",
|
||||
128 * 1_024 * 1_024,
|
||||
),
|
||||
maxTextFileBytes: positiveCount(
|
||||
"size of one parsed text file",
|
||||
8 * 1_024 * 1_024,
|
||||
),
|
||||
maxAstNodes: positiveCount("JavaScript AST nodes to parse", 2_000_000),
|
||||
maxFindings: positiveCount("static-analysis findings to return", 8_000),
|
||||
maxModules: positiveCount("application modules to project", 20_000),
|
||||
maxSourceMapSources: positiveCount(
|
||||
"original sources from source maps",
|
||||
5_000,
|
||||
),
|
||||
maxParseMilliseconds: positiveCount(
|
||||
"JavaScript parsing time in milliseconds",
|
||||
30_000,
|
||||
),
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import { ConfigurationError } from "../domain/errors.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { analysisProviderSelectorSchema } from "../contracts/providerSelection.js";
|
||||
|
||||
export const environmentSchema = z
|
||||
const environmentSchema = z
|
||||
.object({
|
||||
REA_ANALYSIS_PROVIDER: analysisProviderSelectorSchema.default("auto"),
|
||||
GHIDRA_INSTALL_DIR: z
|
||||
|
||||
@@ -48,7 +48,7 @@ import {
|
||||
pageOutput,
|
||||
procedureIdentity,
|
||||
procedureInfoOutput,
|
||||
resultOf,
|
||||
evidenceResultOf as resultOf,
|
||||
searchPageOutput,
|
||||
segmentOutput,
|
||||
sessionProvider,
|
||||
|
||||
@@ -21,7 +21,7 @@ export const evidenceResultOf = (schema: z.ZodType) =>
|
||||
evidence_uri: z.string().regex(/^rea:\/\/evidence\/ev_[a-f0-9]{64}$/u),
|
||||
});
|
||||
|
||||
export const resultOf = evidenceResultOf;
|
||||
const resultOf = evidenceResultOf;
|
||||
export const lifecycleResultOf = (schema: z.ZodType) =>
|
||||
z.object({ result: schema });
|
||||
|
||||
@@ -60,7 +60,7 @@ export const targetKindSchema = z.enum([
|
||||
"artifact",
|
||||
]);
|
||||
|
||||
export const providerCapability = z.object({
|
||||
const providerCapability = z.object({
|
||||
operation: z.string(),
|
||||
available: z.boolean(),
|
||||
reason: z.string().nullable(),
|
||||
@@ -85,19 +85,19 @@ export const providerCapability = z.object({
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
export const providerIdentity = z.object({
|
||||
const providerIdentity = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
version: z.string().nullable(),
|
||||
});
|
||||
|
||||
export const providerRejectionCode: z.ZodType<ProviderRejectionCode> = z.enum(
|
||||
const providerRejectionCode: z.ZodType<ProviderRejectionCode> = z.enum(
|
||||
PROVIDER_REJECTION_CODES,
|
||||
);
|
||||
|
||||
export const providerDiagnostics = z.record(z.string(), z.json());
|
||||
const providerDiagnostics = z.record(z.string(), z.json());
|
||||
|
||||
export const providerAvailability = z.discriminatedUnion("status", [
|
||||
const providerAvailability = z.discriminatedUnion("status", [
|
||||
z.object({
|
||||
status: z.literal("available"),
|
||||
code: z.null(),
|
||||
@@ -112,7 +112,7 @@ export const providerAvailability = z.discriminatedUnion("status", [
|
||||
}),
|
||||
]);
|
||||
|
||||
export const providerTargetSupport = z.discriminatedUnion("status", [
|
||||
const providerTargetSupport = z.discriminatedUnion("status", [
|
||||
z.object({
|
||||
status: z.literal("unknown"),
|
||||
code: z.null(),
|
||||
@@ -240,9 +240,12 @@ export const sessionProvider = z.object({
|
||||
|
||||
export const nullableText = z.string().nullable();
|
||||
export const addressList = z.array(z.string());
|
||||
export const addressedEntry = z.object({ address: z.string(), name: z.string() });
|
||||
export const addressedEntry = z.object({
|
||||
address: z.string(),
|
||||
name: z.string(),
|
||||
});
|
||||
export const procedureIdentity = procedureIdentitySchema;
|
||||
export const localVariable = localVariableSchema;
|
||||
const localVariable = localVariableSchema;
|
||||
|
||||
export const containingProcedureResolution = z.discriminatedUnion("found", [
|
||||
z.object({
|
||||
@@ -258,12 +261,12 @@ export const containingProcedureResolution = z.discriminatedUnion("found", [
|
||||
}),
|
||||
]);
|
||||
|
||||
export const unavailable = z.object({
|
||||
const unavailable = z.object({
|
||||
available: z.literal(false),
|
||||
reason: z.string(),
|
||||
});
|
||||
|
||||
export const availableMemoryPermissions = z.object({
|
||||
const availableMemoryPermissions = z.object({
|
||||
available: z.literal(true),
|
||||
source: z.literal("ghidra-memory-block"),
|
||||
});
|
||||
@@ -277,7 +280,7 @@ export const bounded = (item: z.ZodType) =>
|
||||
next_offset: z.number().int().min(0).nullable(),
|
||||
});
|
||||
|
||||
export const addressedValue = z.object({
|
||||
const addressedValue = z.object({
|
||||
address: z.string(),
|
||||
value: z.string(),
|
||||
value_truncated: z.boolean().optional(),
|
||||
@@ -325,7 +328,7 @@ export const searchPageOutput = pageOutput.extend({
|
||||
),
|
||||
});
|
||||
|
||||
export const memoryRegionOutput = z.object({
|
||||
const memoryRegionOutput = z.object({
|
||||
name: z.string(),
|
||||
start: z.string(),
|
||||
end: z.string(),
|
||||
|
||||
@@ -4,7 +4,11 @@ import {
|
||||
functionComparisonResultSchema,
|
||||
type FunctionComparisonResult,
|
||||
} from "./functionComparisonSchemas.js";
|
||||
import { overallStatus, summarize, canonicalJson } from "./functionComparisonResults.js";
|
||||
import {
|
||||
overallStatus,
|
||||
summarize,
|
||||
canonicalJson,
|
||||
} from "./functionComparisonResults.js";
|
||||
import { compareDimensions } from "./functionComparisonDimensions.js";
|
||||
|
||||
export {
|
||||
|
||||
@@ -16,7 +16,10 @@ import {
|
||||
sorted,
|
||||
stringAndNameProjection,
|
||||
} from "./functionComparisonNormalization.js";
|
||||
import type { DimensionName, FunctionDimension } from "./functionComparisonSchemas.js";
|
||||
import type {
|
||||
DimensionName,
|
||||
FunctionDimension,
|
||||
} from "./functionComparisonSchemas.js";
|
||||
import {
|
||||
canonicalJson,
|
||||
dimensionResult,
|
||||
|
||||
@@ -89,7 +89,12 @@ const applyTier = (context: TierContext): void => {
|
||||
const leftGroup = leftByKey.get(key) ?? [];
|
||||
const rightGroup = rightByKey.get(key) ?? [];
|
||||
if (rightGroup.length === 0) continue;
|
||||
recordCandidates(leftGroup, rightGroup, context.leftCandidates, context.rightCandidates);
|
||||
recordCandidates(
|
||||
leftGroup,
|
||||
rightGroup,
|
||||
context.leftCandidates,
|
||||
context.rightCandidates,
|
||||
);
|
||||
if (leftGroup.length !== 1 || rightGroup.length !== 1) continue;
|
||||
const leftNode = leftGroup[0];
|
||||
const rightNode = rightGroup[0];
|
||||
|
||||
@@ -50,11 +50,23 @@ export const traverseApplicationFeature = (
|
||||
const depth = depths.get(current) ?? 0;
|
||||
for (const entry of adjacency.get(current) ?? []) {
|
||||
if (depth >= limits.max_depth) {
|
||||
recordOmission({ entry, current, omittedNodes, omittedEdges, frontier });
|
||||
recordOmission({
|
||||
entry,
|
||||
current,
|
||||
omittedNodes,
|
||||
omittedEdges,
|
||||
frontier,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (!visited.has(entry.nextNodeId) && visited.size >= limits.max_nodes) {
|
||||
recordOmission({ entry, current, omittedNodes, omittedEdges, frontier });
|
||||
recordOmission({
|
||||
entry,
|
||||
current,
|
||||
omittedNodes,
|
||||
omittedEdges,
|
||||
frontier,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
|
||||
@@ -17,9 +17,7 @@ import {
|
||||
inspectRoleProperty,
|
||||
} from "./javascriptStaticAnalysisCalls.js";
|
||||
import { inspectBundlerRegistration } from "./javascriptStaticAnalysisBundler.js";
|
||||
import {
|
||||
finalizeLocatedFindings,
|
||||
} from "./javascriptStaticAnalysisFindings.js";
|
||||
import { finalizeLocatedFindings } from "./javascriptStaticAnalysisFindings.js";
|
||||
import {
|
||||
createJavaScriptAnalysisAccumulator,
|
||||
type JavaScriptAnalysisAccumulator as AnalysisAccumulator,
|
||||
|
||||
@@ -42,7 +42,7 @@ export interface ManagedGraphProjectionOmissions {
|
||||
}
|
||||
|
||||
/** Complete application-graph fact coverage. */
|
||||
export const completeManagedGraphCoverage =
|
||||
const completeManagedGraphCoverage =
|
||||
(): ApplicationGraphEvidence["coverage"] => ({
|
||||
status: "complete",
|
||||
truncated: false,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { ParsedManagedGraphInput } from "./managedApplicationGraph.js";
|
||||
|
||||
/** Derive module coverage from the best available managed evidence source. */
|
||||
export const moduleCoverageState = (
|
||||
parsed: ParsedManagedGraphInput,
|
||||
): "complete" | "partial" | "unavailable" =>
|
||||
parsed.artifact !== null && parsed.artifact.result.module !== null
|
||||
? parsed.artifact.result.coverage.state
|
||||
: parsed.members !== null && parsed.members.result.module !== null
|
||||
? parsed.members.result.coverage.state
|
||||
: (parsed.boundaries?.result.coverage.state ?? "complete");
|
||||
@@ -1,5 +1,4 @@
|
||||
import { basename } from "node:path";
|
||||
|
||||
import {
|
||||
createJavaScriptApplicationEdge,
|
||||
createJavaScriptApplicationNode,
|
||||
@@ -15,8 +14,11 @@ import {
|
||||
type ManagedMemberInspection,
|
||||
type ManagedNativeBoundaryInspection,
|
||||
} from "./managedArtifact.js";
|
||||
import type { GraphBuildState, ParsedManagedGraphInput } from "./managedApplicationGraph.js";
|
||||
|
||||
import type {
|
||||
GraphBuildState,
|
||||
ParsedManagedGraphInput,
|
||||
} from "./managedApplicationGraph.js";
|
||||
import { moduleCoverageState } from "./managedApplicationGraphNodeCoverage.js";
|
||||
type ManagedMethod = ManagedMemberInspection["methods"]["items"][number];
|
||||
type ManagedField = ManagedMemberInspection["fields"]["items"][number];
|
||||
type ManagedType = ManagedMemberInspection["types"]["items"][number];
|
||||
@@ -204,7 +206,7 @@ export const addMemberNodes = (
|
||||
};
|
||||
|
||||
/** Build a managed type application node. */
|
||||
export const typeNode = (
|
||||
const typeNode = (
|
||||
state: GraphBuildState,
|
||||
type: ManagedType,
|
||||
coverage: ApplicationGraphEvidence["coverage"],
|
||||
@@ -233,7 +235,7 @@ export const typeNode = (
|
||||
});
|
||||
|
||||
/** Build a managed method application node. */
|
||||
export const methodNode = (
|
||||
const methodNode = (
|
||||
state: GraphBuildState,
|
||||
method: ManagedMethod,
|
||||
coverage: ApplicationGraphEvidence["coverage"],
|
||||
@@ -269,7 +271,7 @@ export const methodNode = (
|
||||
});
|
||||
|
||||
/** Build a managed field application node. */
|
||||
export const fieldNode = (
|
||||
const fieldNode = (
|
||||
state: GraphBuildState,
|
||||
field: ManagedField,
|
||||
coverage: ApplicationGraphEvidence["coverage"],
|
||||
@@ -374,7 +376,7 @@ export const addBoundaryNodes = (
|
||||
};
|
||||
|
||||
/** Build a managed P/Invoke import application node. */
|
||||
export const pinvokeNode = (
|
||||
const pinvokeNode = (
|
||||
state: GraphBuildState,
|
||||
pinvoke: PinvokeImport,
|
||||
coverage: ApplicationGraphEvidence["coverage"],
|
||||
@@ -409,7 +411,7 @@ export const pinvokeNode = (
|
||||
});
|
||||
|
||||
/** Build a managed native implementation application node. */
|
||||
export const nativeImplementationNode = (
|
||||
const nativeImplementationNode = (
|
||||
state: GraphBuildState,
|
||||
implementation: NativeImplementation,
|
||||
coverage: ApplicationGraphEvidence["coverage"],
|
||||
@@ -444,7 +446,7 @@ export const nativeImplementationNode = (
|
||||
});
|
||||
|
||||
/** Add a contains relationship edge between two nodes. */
|
||||
export const addContainsEdge = (
|
||||
const addContainsEdge = (
|
||||
state: GraphBuildState,
|
||||
source: ApplicationNode,
|
||||
target: ApplicationNode,
|
||||
@@ -466,7 +468,7 @@ export const addContainsEdge = (
|
||||
};
|
||||
|
||||
/** Build an artifact-local key identity for a managed graph entity. */
|
||||
export const artifactLocalIdentity = (
|
||||
const artifactLocalIdentity = (
|
||||
artifactSha256: string,
|
||||
namespace: string,
|
||||
key: string,
|
||||
@@ -479,10 +481,12 @@ export const artifactLocalIdentity = (
|
||||
});
|
||||
|
||||
/** Build managed static-analysis evidence for a graph observation. */
|
||||
export const managedEvidence = (
|
||||
const managedEvidence = (
|
||||
state: GraphBuildState,
|
||||
operation: string,
|
||||
coverage: ApplicationGraphEvidence["coverage"] = managedSourceCoverage("complete"),
|
||||
coverage: ApplicationGraphEvidence["coverage"] = managedSourceCoverage(
|
||||
"complete",
|
||||
),
|
||||
): ApplicationGraphEvidence => ({
|
||||
authority: "managed-static-analysis",
|
||||
state: "observed",
|
||||
@@ -516,17 +520,7 @@ export const managedEvidence = (
|
||||
});
|
||||
|
||||
/** Sanitize an artifact path into a managed graph location. */
|
||||
export const graphArtifactPath = (path: string): string => {
|
||||
const graphArtifactPath = (path: string): string => {
|
||||
const name = basename(path).replaceAll(/[^A-Za-z0-9._-]/gu, "_");
|
||||
return `managed/${name.length === 0 ? "artifact.pe" : name}`;
|
||||
};
|
||||
|
||||
/** Derive the module coverage state from the best available evidence source. */
|
||||
export const moduleCoverageState = (
|
||||
parsed: ParsedManagedGraphInput,
|
||||
): "complete" | "partial" | "unavailable" =>
|
||||
parsed.artifact !== null && parsed.artifact.result.module !== null
|
||||
? parsed.artifact.result.coverage.state
|
||||
: parsed.members !== null && parsed.members.result.module !== null
|
||||
? parsed.members.result.coverage.state
|
||||
: (parsed.boundaries?.result.coverage.state ?? "complete");
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
} from "./managedMemberComparison.js";
|
||||
import type { ManagedMemberInspection } from "./managedArtifact.js";
|
||||
|
||||
export interface PageAssessment {
|
||||
interface PageAssessment {
|
||||
readonly sourceComplete: boolean;
|
||||
readonly sourceOmittedCount: number;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ const modulePath = (
|
||||
evidence: ReturnType<typeof parseEvidence>,
|
||||
): string | null => evidence.subject?.local_path ?? null;
|
||||
|
||||
export const symbolsForEvidence = (
|
||||
const symbolsForEvidence = (
|
||||
evidence: ReturnType<typeof parseEvidence>,
|
||||
): {
|
||||
readonly supported: boolean;
|
||||
|
||||
@@ -24,12 +24,12 @@ const matchBasisSchema = z.enum([
|
||||
"unsupported-native-evidence",
|
||||
]);
|
||||
|
||||
export const nativeVerificationLimitsSchema = z.strictObject({
|
||||
const nativeVerificationLimitsSchema = z.strictObject({
|
||||
max_native_observations: z.number().int().min(1).max(50).default(20),
|
||||
max_candidates_per_import: z.number().int().min(1).max(100).default(25),
|
||||
});
|
||||
|
||||
export const nativeSymbolSchema = z.strictObject({
|
||||
const nativeSymbolSchema = z.strictObject({
|
||||
evidence_id: evidenceIdSchema,
|
||||
operation: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
|
||||
@@ -26,5 +26,10 @@ export const analyzeCapturedWebBundle = (
|
||||
const accumulator = emptyAccumulator();
|
||||
const sourceScripts = inspection.scripts.items.filter(isIncludedScript);
|
||||
for (const script of sourceScripts) analyzeScript(script, input, accumulator);
|
||||
return buildWebBundleAnalysis(inspection, sourceScripts, sourceMaps, accumulator);
|
||||
return buildWebBundleAnalysis(
|
||||
inspection,
|
||||
sourceScripts,
|
||||
sourceMaps,
|
||||
accumulator,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -334,7 +334,10 @@ const addRouteFrameworkInference = (context: RouteFrameworkContext): void => {
|
||||
value,
|
||||
confidence: "medium",
|
||||
basis: [
|
||||
{ ...basis(context.script, `call:${context.name}`), ...locationFields(context.node) },
|
||||
{
|
||||
...basis(context.script, `call:${context.name}`),
|
||||
...locationFields(context.node),
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
@@ -383,8 +386,9 @@ export const emptyAccumulator = (): AnalysisAccumulator => ({
|
||||
astLimitReached: false,
|
||||
});
|
||||
|
||||
export const isIncludedScript = (script: BrowserScript): script is IncludedScript =>
|
||||
script.source.included;
|
||||
export const isIncludedScript = (
|
||||
script: BrowserScript,
|
||||
): script is IncludedScript => script.source.included;
|
||||
|
||||
const routeCallNames = [
|
||||
"route",
|
||||
|
||||
@@ -3,7 +3,10 @@ import {
|
||||
webBundleAnalysisSchema,
|
||||
type WebBundleAnalysis,
|
||||
} from "./webBundleAnalysis.js";
|
||||
import type { AnalysisAccumulator, IncludedScript } from "./webBundleAnalyzerInspection.js";
|
||||
import type {
|
||||
AnalysisAccumulator,
|
||||
IncludedScript,
|
||||
} from "./webBundleAnalyzerInspection.js";
|
||||
|
||||
export const buildWebBundleAnalysis = (
|
||||
inspection: WebPageInspection,
|
||||
@@ -67,15 +70,13 @@ const buildCaptureObservation = (
|
||||
});
|
||||
|
||||
const sourceArtifact = (script: IncludedScript) => {
|
||||
if (!script.source.included)
|
||||
throw new TypeError("Filtered source changed");
|
||||
if (!script.source.included) throw new TypeError("Filtered source changed");
|
||||
const { text: _text, ...artifact } = script.source.artifact;
|
||||
return { ...artifact, text_available: true };
|
||||
};
|
||||
|
||||
const chunkNode = (script: IncludedScript) => {
|
||||
if (!script.source.included)
|
||||
throw new TypeError("Filtered source changed");
|
||||
if (!script.source.included) throw new TypeError("Filtered source changed");
|
||||
return {
|
||||
script_key: script.script_key,
|
||||
url: script.url,
|
||||
|
||||
@@ -364,6 +364,13 @@ const mapResources = (
|
||||
}
|
||||
};
|
||||
|
||||
const inventoryPagesComplete = (
|
||||
inventory: ReturnType<typeof readManagedMetadataInventory>,
|
||||
): boolean =>
|
||||
inventory.references.complete &&
|
||||
inventory.resources.complete &&
|
||||
inventory.attributes.complete;
|
||||
|
||||
/** Inspect PE/CLI identity directly from bounded bytes without CLR loading. */
|
||||
export const inspectManagedArtifactBytes = (
|
||||
bytes: Buffer,
|
||||
@@ -405,7 +412,13 @@ export const inspectManagedArtifactBytes = (
|
||||
} catch (cause: unknown) {
|
||||
if (!(cause instanceof ManagedReaderFailure)) throw cause;
|
||||
return managedArtifactInspectionSchema.parse(
|
||||
partialMetadataResult({ target, bytes, layout, limits, issue: cause.issue }),
|
||||
partialMetadataResult({
|
||||
target,
|
||||
bytes,
|
||||
layout,
|
||||
limits,
|
||||
issue: cause.issue,
|
||||
}),
|
||||
);
|
||||
}
|
||||
const resourceIssues: ManagedParseIssue[] = [];
|
||||
@@ -417,10 +430,7 @@ export const inspectManagedArtifactBytes = (
|
||||
resourceDirectory,
|
||||
);
|
||||
const issues = [...resourceIssues, ...inventory.issues];
|
||||
const pagesComplete =
|
||||
inventory.references.complete &&
|
||||
inventory.resources.complete &&
|
||||
inventory.attributes.complete;
|
||||
const pagesComplete = inventoryPagesComplete(inventory);
|
||||
const limitations = [
|
||||
...(pagesComplete
|
||||
? []
|
||||
|
||||
@@ -302,7 +302,7 @@ export const parseTypes = (
|
||||
return items;
|
||||
};
|
||||
|
||||
export const readCompressed = (
|
||||
const readCompressed = (
|
||||
bytes: Buffer,
|
||||
offset: number,
|
||||
): { readonly value: number; readonly next: number } => {
|
||||
|
||||
@@ -238,7 +238,10 @@ const readCoffHeader = (bytes: Buffer): CoffHeader => {
|
||||
return { coff, machine, sectionCount, optionalSize, characteristics };
|
||||
};
|
||||
|
||||
const readOptionalHeader = (bytes: Buffer, coff: CoffHeader): OptionalHeader => {
|
||||
const readOptionalHeader = (
|
||||
bytes: Buffer,
|
||||
coff: CoffHeader,
|
||||
): OptionalHeader => {
|
||||
const optionalOffset = coff.coff + 20;
|
||||
requireRange(bytes, optionalOffset, coff.optionalSize, "pe.optional-header");
|
||||
if (coff.optionalSize < 96)
|
||||
@@ -272,13 +275,12 @@ const readSections = (
|
||||
coff: CoffHeader,
|
||||
optional: OptionalHeader,
|
||||
): readonly PeSection[] => {
|
||||
const sectionOffset = add(optional.optionalOffset, coff.optionalSize, "pe.sections");
|
||||
requireRange(
|
||||
bytes,
|
||||
sectionOffset,
|
||||
coff.sectionCount * 40,
|
||||
const sectionOffset = add(
|
||||
optional.optionalOffset,
|
||||
coff.optionalSize,
|
||||
"pe.sections",
|
||||
);
|
||||
requireRange(bytes, sectionOffset, coff.sectionCount * 40, "pe.sections");
|
||||
const sections: PeSection[] = [];
|
||||
for (let index = 0; index < coff.sectionCount; index += 1) {
|
||||
const offset = sectionOffset + index * 40;
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
} from "./GhidraTransport.js";
|
||||
|
||||
/** Stable listeners attached for the lifetime of one bridge socket. */
|
||||
export interface GhidraSocketHandlers {
|
||||
interface GhidraSocketHandlers {
|
||||
readonly data: (chunk: string) => void;
|
||||
readonly error: () => void;
|
||||
readonly close: () => void;
|
||||
@@ -37,7 +37,7 @@ export interface GhidraSocketConnectOptions {
|
||||
}
|
||||
|
||||
/** Attach decoded bridge listeners and return an idempotent detach callback. */
|
||||
export const attachGhidraSocket = (
|
||||
const attachGhidraSocket = (
|
||||
socket: Socket,
|
||||
handlers: GhidraSocketHandlers,
|
||||
): (() => void) => {
|
||||
@@ -96,7 +96,7 @@ export const connectGhidraSocket = async (
|
||||
};
|
||||
|
||||
/** Open one abort-aware connection to an observed local Ghidra endpoint. */
|
||||
export const connectGhidraSocketOnce = (
|
||||
const connectGhidraSocketOnce = (
|
||||
target: GhidraConnectTarget,
|
||||
signal: AbortSignal,
|
||||
): Promise<Result<Socket, GhidraSessionError>> =>
|
||||
|
||||
@@ -26,7 +26,7 @@ export const boundedCollector = (maximum: number) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const collect = async (
|
||||
const collect = async (
|
||||
executable: string,
|
||||
arguments_: readonly string[],
|
||||
maximum: number,
|
||||
|
||||
@@ -60,7 +60,7 @@ export const functionEvidenceIds = (
|
||||
),
|
||||
);
|
||||
|
||||
export const uniqueIds = (ids: readonly string[]): string[] =>
|
||||
const uniqueIds = (ids: readonly string[]): string[] =>
|
||||
[...new Set(ids)].sort((left, right) => left.localeCompare(right));
|
||||
|
||||
export const evidenceClosure = (
|
||||
|
||||
Reference in New Issue
Block a user