Files
reverse-engineering-anything/src/native/pwntools/PwntoolsLayoutProvider.ts
T
gensokyo-dev e18594b247 refactor(composition): unify capability bindings and cleanup ownership (#8441)
Bind typed service creation, observed availability and retryable cleanup in one composition owner. Reuse selected CLI/MCP factories and canonical contract groups without copying provider operation inventories.

Closes #8429. Refs #740.

Validated paired real application workflows, actual local Codex CLI Terra/high use, complete Evidence and Unknown checkpoint parity, compiler-backed import boundaries, SDK schemas and final real mixed routing. Automated review findings were fixed at their producing owners. Existing exact-base CodeQL alerts are documented on the PR under the owner-authorized unrelated-check exception; no global alerts or security rules were changed.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
2026-11-01 13:30:21 +08:00

75 lines
2.7 KiB
TypeScript

import {
binaryLayoutPayloadSchema,
binaryLayoutSchema,
type BinaryLayout,
type InspectBinaryLayoutInput,
} from "../../domain/native/binaryLayout.js";
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
import { PwntoolsDecoder, type PwntoolsLauncher } from "./PwntoolsDecoder.js";
import { PWNTOOLS_PROVIDER_IDENTITY } from "./PwntoolsProviderIdentity.js";
import { PrivateRuntimeRoot } from "../../process/PrivateRuntimeRoot.js";
import type { BinaryLayoutPort } from "../../application/binaryDiagnostics/BinaryLayoutPort.js";
import type { z } from "zod";
/** ELF-specific projection around the shared owned pwntools decoder boundary. */
export class PwntoolsLayoutProvider
extends PwntoolsDecoder<
InspectBinaryLayoutInput,
z.output<typeof binaryLayoutPayloadSchema>,
BinaryLayout
>
implements BinaryLayoutPort
{
constructor(
environment: Readonly<NodeJS.ProcessEnv>,
launcher?: PwntoolsLauncher,
createRuntime: () => Promise<
Pick<PrivateRuntimeRoot, "path" | "close">
> = () => PrivateRuntimeRoot.create({ prefix: "rea-elf-layout-" }),
) {
super(
{
identity: PWNTOOLS_PROVIDER_IDENTITY,
operation: "inspect_binary_layout",
bridge: new URL("../../../bridge/pwntools/layout.py", import.meta.url),
payloadSchema: binaryLayoutPayloadSchema,
project: ({ input, payload, snapshot, diagnostics }) => {
const value = binaryLayoutSchema.safeParse({
...payload,
artifact: {
path: input.path,
sha256: snapshot.sha256,
bytes: snapshot.bytes.length,
},
diagnostics,
});
if (!value.success)
throw new AnalysisOutputError(
"inspect_binary_layout",
`ELF reply contains invalid source ranges or value meanings: ${value.error.issues[0]?.message ?? "schema mismatch"}`,
{ capturedOutput: diagnostics },
);
for (const table of value.data.packed_relative_relocations) {
const start = Number(BigInt(table.location.offset));
const length = Number(BigInt(table.location.bytes));
if (
!Buffer.from(table.encoded_bytes_base64, "base64").equals(
snapshot.bytes.subarray(start, start + length),
)
)
throw new AnalysisOutputError(
"inspect_binary_layout",
"Reported packed relocation bytes differ from the selected snapshot at their original file range.",
{ capturedOutput: diagnostics },
);
}
return value.data;
},
},
environment,
launcher,
createRuntime,
);
}
}