* feat(artifacts): read Godot PCK packs Add a Godot Engine PCK artifact reader for standalone packs and packs embedded behind an executable trailer (formats 2 and 3). Members are uncompressed byte ranges verified against their declared MD5 on read. Encrypted directories, sparse bundles, patch removal entries, unknown flags and format 1 fail closed as unavailable; encrypted members are reported without being read. inspect-artifact and extract-artifact recognize standalone packs by their GDPC magic. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(artifacts): bound Godot PCK metadata and own member streams Cap member paths at 4096 bytes and the retained directory at 64 MiB before allocation. Read members with positional chunk reads through pipeline so cancellation is typed, abandoned consumers release their source, and the shared descriptor stays reader-owned. Retain the root descriptor for godot-pck inventory, as for ZIP and universal Mach-O. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(artifacts): complete Godot PCK facts, integrity and selected views * fix(artifacts): preserve atomic-root inventory Evidence * fix(artifacts): bound aggregate PCK member expansion --------- Co-authored-by: Samucahub <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: gensokyo-dev <[email protected]>
269 lines
8.2 KiB
TypeScript
269 lines
8.2 KiB
TypeScript
import {
|
|
analysisEvidenceDeliveryOptions,
|
|
cliEvidenceDeliveryInputError,
|
|
publishCliAnalysisEvidence,
|
|
} from "./analysisEvidenceDelivery.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import { ARTIFACT_GRAPH_PROVIDER } from "../application/InvestigationProviders.js";
|
|
import { z } from "incur";
|
|
|
|
import type { DirectAnalysis } from "../composition/directAnalysis.js";
|
|
import { createArtifactExtractionDestination } from "../application/artifacts/ArtifactExtractionDestination.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import type { Logger } from "pino";
|
|
import type { CliInstance } from "./types.js";
|
|
|
|
export const registerArtifactCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
runProviderAnalysis: DirectAnalysis["runProviderAnalysis"],
|
|
): void => {
|
|
registerInspectionCommand(cli, logger, runProviderAnalysis);
|
|
registerExtractionCommand(cli, logger, runProviderAnalysis);
|
|
registerInterfaceBuilderCommand(cli, logger, runProviderAnalysis);
|
|
registerAssetCatalogCommand(cli, logger, runProviderAnalysis);
|
|
registerDylibResolutionCommand(cli, logger, runProviderAnalysis);
|
|
cli.command(CLI_COMMANDS.inspectKeyedArchive, {
|
|
description:
|
|
"Inspect a Foundation keyed archive as an object-reference graph",
|
|
args: z.object({
|
|
path: z.string().describe("Foundation plist archive or Apple app bundle"),
|
|
archive: z
|
|
.string()
|
|
.default(".")
|
|
.describe("Relative archive path when the target is a bundle"),
|
|
}),
|
|
options: z.object({
|
|
root: z.string().optional().describe("Named $top archive root"),
|
|
offset: z
|
|
.number()
|
|
.int()
|
|
.min(0)
|
|
.default(0)
|
|
.describe("First original object-table index"),
|
|
limit: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(20000)
|
|
.default(20000)
|
|
.describe("Maximum object-table entries to return"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectKeyedArchive, () =>
|
|
runProviderAnalysis(
|
|
args.path,
|
|
"inspect_keyed_archive",
|
|
{
|
|
path: args.archive,
|
|
offset: options.offset,
|
|
limit: options.limit,
|
|
...(options.root === undefined ? {} : { root: options.root }),
|
|
},
|
|
logger,
|
|
),
|
|
),
|
|
});
|
|
};
|
|
|
|
const registerDylibResolutionCommand = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
runProviderAnalysis: DirectAnalysis["runProviderAnalysis"],
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.traceDylibResolution, {
|
|
description:
|
|
"Trace dyld load-path resolution for a Mach-O or every executable in an app bundle",
|
|
args: z.object({
|
|
path: z.string().describe("Mach-O file or Apple .app bundle path"),
|
|
}),
|
|
options: z.object({
|
|
root: z
|
|
.array(z.string())
|
|
.optional()
|
|
.describe(
|
|
"Process root relative to the bundle or the Mach-O's directory (repeatable)",
|
|
),
|
|
architecture: z
|
|
.enum(["arm64", "arm64e", "x86_64"])
|
|
.optional()
|
|
.describe("Trace only this slice of each root"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
logCliCommand(logger, CLI_COMMANDS.traceDylibResolution, () =>
|
|
runProviderAnalysis(
|
|
args.path,
|
|
"trace_dylib_resolution",
|
|
{
|
|
...(options.root === undefined ? {} : { roots: options.root }),
|
|
...(options.architecture === undefined
|
|
? {}
|
|
: { architecture: options.architecture }),
|
|
},
|
|
logger,
|
|
),
|
|
),
|
|
});
|
|
};
|
|
|
|
const registerAssetCatalogCommand = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
runProviderAnalysis: DirectAnalysis["runProviderAnalysis"],
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.inspectAssetCatalog, {
|
|
description: "Inspect compiled Apple asset catalog metadata",
|
|
args: z.object({ path: z.string().describe("Apple .app bundle path") }),
|
|
options: z.object({
|
|
offset: z
|
|
.number()
|
|
.int()
|
|
.min(0)
|
|
.default(0)
|
|
.describe("First metadata record"),
|
|
limit: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(10_000)
|
|
.default(1_000)
|
|
.describe("Maximum records to return"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectAssetCatalog, () =>
|
|
runProviderAnalysis(
|
|
args.path,
|
|
"inspect_asset_catalog",
|
|
{ offset: options.offset, limit: options.limit },
|
|
logger,
|
|
),
|
|
),
|
|
});
|
|
};
|
|
|
|
const registerInterfaceBuilderCommand = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
runProviderAnalysis: DirectAnalysis["runProviderAnalysis"],
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.decodeInterfaceBuilder, {
|
|
description:
|
|
"Decode compiled storyboard and nib archives from an app bundle",
|
|
args: z.object({
|
|
path: z.string().describe("Apple .app bundle path"),
|
|
}),
|
|
options: z.object({
|
|
maxDocuments: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(64)
|
|
.default(64)
|
|
.describe("Maximum archives to decode"),
|
|
maxObjects: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(20_000)
|
|
.default(20_000)
|
|
.describe("Maximum graph objects"),
|
|
maxConnections: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(40_000)
|
|
.default(40_000)
|
|
.describe("Maximum decoded connections"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
logCliCommand(logger, "decode-interface-builder", () =>
|
|
runProviderAnalysis(
|
|
args.path,
|
|
"decode_interface_builder",
|
|
{
|
|
max_documents: options.maxDocuments,
|
|
max_objects: options.maxObjects,
|
|
max_connections: options.maxConnections,
|
|
},
|
|
logger,
|
|
),
|
|
),
|
|
});
|
|
};
|
|
|
|
const registerExtractionCommand = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
runProviderAnalysis: DirectAnalysis["runProviderAnalysis"],
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.extractArtifact, {
|
|
description: "Extract all regular artifact contents safely",
|
|
args: z.object({
|
|
path: z.string().describe("Application or package path"),
|
|
}),
|
|
options: z.object({
|
|
integrityPolicy: z
|
|
.enum(["fail", "record-and-continue"])
|
|
.default("fail")
|
|
.describe("Behavior when declared artifact integrity does not match"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
logCliCommand(logger, "extract-artifact", () =>
|
|
runProviderAnalysis(
|
|
args.path,
|
|
"extract_artifact",
|
|
{
|
|
integrity_policy: options.integrityPolicy,
|
|
output_root: createArtifactExtractionDestination(),
|
|
},
|
|
logger,
|
|
),
|
|
),
|
|
});
|
|
};
|
|
|
|
const registerInspectionCommand = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
runProviderAnalysis: DirectAnalysis["runProviderAnalysis"],
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.inspectArtifact, {
|
|
description:
|
|
"Inspect one artifact and return all available observations and next probes",
|
|
args: z.object({
|
|
path: z.string().min(1).describe("Application or package path"),
|
|
}),
|
|
options: z.object({
|
|
...analysisEvidenceDeliveryOptions,
|
|
integrityPolicy: z
|
|
.enum(["fail", "record-and-continue"])
|
|
.default("fail")
|
|
.describe("Behavior when declared artifact integrity does not match"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
logCliCommand(logger, "inspect-artifact", () =>
|
|
withCommandCancellation(async (signal) => {
|
|
const delivery = {
|
|
providerId: ARTIFACT_GRAPH_PROVIDER.id,
|
|
operation: "inspect_artifact",
|
|
signal,
|
|
detail: options.detail,
|
|
evidenceOutput: options.evidence_output,
|
|
};
|
|
const inputError = cliEvidenceDeliveryInputError(delivery);
|
|
if (inputError !== undefined) return projectAnalysisError(inputError);
|
|
const complete = await runProviderAnalysis(
|
|
args.path,
|
|
"inspect_artifact",
|
|
{ integrity_policy: options.integrityPolicy },
|
|
logger,
|
|
signal,
|
|
);
|
|
return publishCliAnalysisEvidence(complete, delivery);
|
|
}),
|
|
),
|
|
});
|
|
};
|