* fix(contracts): reject OS-invalid local paths in binary and artifact tools Enforce localPathStringSchema across inspect_pe_resources, inspect_binary_layout, inspect_recorded_crash, inspect_wasm_artifact, and inspect_evm_interface input schemas to reject embedded NUL bytes at the contract boundary instead of failing later during filesystem operations. Add corresponding acceptance test cases to the advertised MCP contracts matrix in localToolContracts.test.ts. Signed-off-by: Vinícius DS Andrade <95101505+viniciusdsandrade@users.noreply.github.com> * style(contracts): wrap pe resources path description under print width Wrap the inspectPeResourcesInputSchema path property description to keep lines within the 80-column oxfmt limit. Signed-off-by: Vinícius DS Andrade <95101505+viniciusdsandrade@users.noreply.github.com> --------- Signed-off-by: Vinícius DS Andrade <95101505+viniciusdsandrade@users.noreply.github.com>
123 lines
3.4 KiB
TypeScript
123 lines
3.4 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { localPathStringSchema } from "../localPath.js";
|
|
|
|
const uint = z.number().int().min(0).max(0xffffffff);
|
|
const range = z.strictObject({ offset: uint, bytes: uint });
|
|
const identity = z.discriminatedUnion("kind", [
|
|
z.strictObject({ kind: z.literal("id"), id: uint }),
|
|
z.strictObject({
|
|
kind: z.literal("name"),
|
|
name: z.string(),
|
|
utf16le_hex: z.string().regex(/^(?:[0-9a-f]{4})*$/),
|
|
location: range,
|
|
}),
|
|
]);
|
|
|
|
/** Complete bounded inspection of a caller-selected PE image, without execution. */
|
|
export const inspectPeResourcesInputSchema = z.strictObject({
|
|
path: localPathStringSchema.describe(
|
|
"Absolute filesystem path to a PE image",
|
|
),
|
|
max_file_bytes: z
|
|
.number()
|
|
.int()
|
|
.min(64)
|
|
.max(536870912)
|
|
.default(67108864)
|
|
.describe("Maximum stable artifact bytes to read (default 64 MiB)"),
|
|
// Windows resource images carry thousands of entries: Windows 11 25H2
|
|
// SystemResources measures imageres.dll.mun at 6476 examined entries,
|
|
// shell32.dll.mun at 5903 and wmploc.DLL.mun at 5440. The default admits
|
|
// those stock images with headroom; the independent 8 MiB metadata budget
|
|
// still bounds allocation.
|
|
max_entries: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(65536)
|
|
.default(16384)
|
|
.describe(
|
|
"Maximum resource directory entries to examine; exceeding the budget fails without partial success",
|
|
),
|
|
});
|
|
|
|
/** Original file/RVA locations and resource identities; icon edges are static relationships. */
|
|
export const peResourcesSchema = z.strictObject({
|
|
artifact: z.strictObject({
|
|
path: z.string().min(1),
|
|
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
bytes: uint,
|
|
}),
|
|
format: z.enum(["pe32", "pe32-plus"]),
|
|
machine: uint,
|
|
directory: z
|
|
.strictObject({
|
|
rva: uint,
|
|
location: range,
|
|
data_directory_location: range,
|
|
})
|
|
.nullable(),
|
|
directories: z.array(
|
|
z.strictObject({
|
|
location: range,
|
|
characteristics: uint,
|
|
timestamp: uint,
|
|
major_version: uint,
|
|
minor_version: uint,
|
|
named_entries: uint,
|
|
id_entries: uint,
|
|
}),
|
|
),
|
|
resources: z.array(
|
|
z.strictObject({
|
|
index: uint,
|
|
type: identity,
|
|
name: identity,
|
|
language: identity,
|
|
entry_locations: z.array(range).length(3),
|
|
data_entry_location: range,
|
|
code_page: uint,
|
|
reserved: uint,
|
|
payload: z.strictObject({
|
|
rva: uint,
|
|
location: range,
|
|
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
}),
|
|
}),
|
|
),
|
|
icon_groups: z.array(
|
|
z.strictObject({
|
|
resource_index: uint,
|
|
images: z.array(
|
|
z.strictObject({
|
|
location: range,
|
|
width: uint,
|
|
height: uint,
|
|
color_count: uint,
|
|
reserved: uint,
|
|
planes: uint,
|
|
bit_count: uint,
|
|
declared_bytes: uint,
|
|
resource_id: uint,
|
|
candidate_resource_indices: z.array(uint),
|
|
same_language_resource_index: uint.nullable(),
|
|
size_matches: z.boolean().nullable(),
|
|
}),
|
|
),
|
|
}),
|
|
),
|
|
coverage: z.strictObject({
|
|
status: z.literal("complete"),
|
|
examined_entries: uint,
|
|
resources: uint,
|
|
}),
|
|
limitations: z.array(z.string()),
|
|
});
|
|
|
|
export type PeResources = z.infer<typeof peResourcesSchema>;
|
|
export type InspectPeResourcesInput = z.infer<
|
|
typeof inspectPeResourcesInputSchema
|
|
>;
|
|
export type PeResourceIdentity = PeResources["resources"][number]["type"];
|