mirror of
https://github.com/morluto/rea.git
synced 2026-11-09 16:26:36 +00:00
* feat(rizin): select the decoder and map address for one-shot commands execute_rizin_command and rea execute-rizin-command accept optional asm_arch, asm_bits, asm_cpu and base_address (CLI --asm-arch, --asm-bits, --asm-cpu and --base-address). REA passes them to Rizin before the artifact path as -a, -b, -e asm.cpu= and -m. Rizin 0.9.1 refuses -e asm.arch= and -e asm.bits= at startup, while -a and -b work in 0.7.4 and 0.9.1. Rizin applies -e settings after -a and -b. base_address is the address of file offset 0, as in REA's raw-binary inputs. REA checks only the spelling, because Rizin owns the arch and CPU vocabulary and its builds differ. The Homebrew build of Rizin 0.9.1 has no xtensa or riscv plugin; the official static Linux build of 0.7.4 has both. Evidence records each input and the complete argument list. When any input is set, Evidence also states that REA does not confirm the decoder or map that Rizin used: Rizin uses another value for one it cannot apply and exits 0. Rizin 0.9.1 keeps its default and reports the value on stderr, and Rizin 0.7.4 turned -b 8 for arm into 16 without a message. Calls without these inputs keep their argument list and Evidence. The real-provider gate tests/boundary/providers/RizinDecoderInputs.test.ts checks the effect of each flag through MCP with Rizin's own e asm.*, omlj and byte reads. It skips when no Rizin is on PATH. It passes with Rizin 0.9.1 (Homebrew, macOS arm64) and 0.7.4 (official static build, Linux x86_64). * docs(rizin): map multi-segment ESP32 images with om An ESP32-family app or bootloader image holds several segments, each loaded at its own address, so one base_address cannot map it. The recipe removes the default map with om-* and adds one om map per segment, using the segment offsets from the image format or from esptool image-info. It does not depend on an ESP image reader in REA. The offsets were checked against esptool 4.12.0 image_info on a synthetic two-segment ESP32 image. Rizin 0.9.1 and 0.7.4 mapped its segments at their load addresses. Rizin 0.7.4, whose static Linux build has the xtensa plugin, decoded the IRAM segment as nop.n, nop.n, ret.n and nop.n. * fix(rizin): read the file at base_address when a loader would claim it On Rizin 0.9.1, base_address could read 0xff at the mapped address with exit 0. -m maps the file, but Rizin still runs its format loaders, and a loose one can claim a raw image. Rizin 0.9.1's AVR loader matches when bytes 1 and 3 look like rjmp and turns io.va off, so reads use file offsets. The BIOS loader, in 0.7.4 and 0.9.1, matches a 64 KiB file with a jmp 16 bytes from its end and maps it at another address. An acceptance run on a raw ESP32-S3 segment hit the first case. With base_address, REA now passes -n together with -m. Rizin then skips the loaders and maps the whole file at the address: rizin.c calls rz_io_map_new at the -m address and leaves io.va at its default. The input therefore means a raw image, and Rizin loads no sections, symbols or entry point, even from an ELF file. Evidence states this in its own limitation, and the decoder limitation no longer covers the map. The real-provider gate adds an AVR-like and a BIOS-like image and reads below the base, at it, at the end of the image and past it. Without -n it fails on Rizin 0.9.1. It passes with Rizin 0.9.1 (Homebrew, macOS arm64) and 0.7.4 (official static build, Linux x86_64). The ESP om recipe now starts with e io.va=true, because reads use the maps only while io.va is on. * fix(rizin): advertise name patterns that compile in v mode The asm_arch and asm_cpu pattern ended its character class with an unescaped '-', which JavaScript's v (unicodeSets) mode rejects, so clients compiling advertised patterns in that mode could not use execute_rizin_command's schema. Escaping it keeps the same names valid in every mode, as main's own patterns write it. * fix(rizin): state what the decoder and map inputs leave unconfirmed The base_address limitation reported a map REA never observes and left out that -n keeps Rizin's default arch, bits and byte order. The asm_* limitation implied Rizin replaces a bad CPU, but e asm.cpu echoes any value. Compact schemas drop property descriptions, so the tool description now carries the raw-loading warning. The real-provider gate checks that asm_cpu changes a decode, and a base_address-only call. * docs(rizin): record the gate's full run on Rizin 0.7.4 * test(rizin): follow the test guide in the decoder input tests Focused tests resolve execute_rizin_command from its contract family, the harness owns the temporary directory before setup can fail, and guidance is compared with its owner, not with sentences from it.
134 lines
4.6 KiB
TypeScript
134 lines
4.6 KiB
TypeScript
import { z } from "zod";
|
|
import { commandEvidenceDetailSchema } from "./commandObservation.js";
|
|
import { localPathStringSchema } from "./localPath.js";
|
|
import { RAW_BINARY_ENTRY_POINT } from "./rawBinary.js";
|
|
|
|
/** Omitted one-shot objdump/rizin wall clock. Preflight shares it; the command gets it again. */
|
|
export const DEFAULT_REVERSE_COMMAND_TIMEOUT_MS = 120_000;
|
|
/** Node timer ceiling. Larger deadlines would be clamped instead of honored. */
|
|
export const MAX_REVERSE_COMMAND_TIMEOUT_MS = 2_147_483_647;
|
|
|
|
/** Per-call deadline for one-shot objdump and rizin commands. */
|
|
export const reverseCommandTimeoutSchema = z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(MAX_REVERSE_COMMAND_TIMEOUT_MS)
|
|
.exactOptional()
|
|
.describe(
|
|
"Wall-clock budget in milliseconds. Target preflight shares one budget across stat and digest, and the one-shot command receives that budget again (default 120000 each). Omitted means 120000. Applies on the next call. Does not raise the 16 MiB combined output cap, Ghidra or Hopper startup deadlines, or debugger session deadlines.",
|
|
);
|
|
|
|
const commandTimeoutMsField = {
|
|
command_timeout_ms: reverseCommandTimeoutSchema,
|
|
};
|
|
|
|
export const OBJDUMP_ARTIFACT_OPERATIONS = [
|
|
"file_headers",
|
|
"section_headers",
|
|
"symbols",
|
|
"relocations",
|
|
"dwarf",
|
|
"disassemble",
|
|
"disassemble_all",
|
|
] as const;
|
|
|
|
const objdumpArtifactInputSchema = z
|
|
.object({
|
|
path: localPathStringSchema,
|
|
operation: z.enum(OBJDUMP_ARTIFACT_OPERATIONS).exclude(["disassemble"]),
|
|
follow_debug_links: z.boolean().default(false),
|
|
...commandTimeoutMsField,
|
|
})
|
|
.strict();
|
|
|
|
const objdumpDisassemblyInputSchema = objdumpArtifactInputSchema.extend({
|
|
operation: z.literal("disassemble"),
|
|
symbol: z
|
|
.string()
|
|
.min(1)
|
|
.regex(/^[^\x00]*$/u)
|
|
// Keep UTF-16 checks out of patterns consumed by scalar Unicode engines.
|
|
.refine(
|
|
(symbol) => !/[\uD800-\uDFFF]/u.test(symbol),
|
|
"Symbol must be well-formed Unicode.",
|
|
)
|
|
.describe(
|
|
"Native symbol to disassemble, expressed as well-formed Unicode. Matching and symbol boundaries follow the selected executable; omitted means all code sections.",
|
|
)
|
|
.optional(),
|
|
});
|
|
|
|
const objdumpArchitecturesInputSchema = z.strictObject({
|
|
operation: z.literal("architectures"),
|
|
...commandTimeoutMsField,
|
|
});
|
|
|
|
/** Caller-selected native selection and independent Evidence delivery. */
|
|
export const objdumpInputSchema = z.discriminatedUnion("operation", [
|
|
objdumpArtifactInputSchema.extend({ detail: commandEvidenceDetailSchema }),
|
|
objdumpDisassemblyInputSchema.extend({ detail: commandEvidenceDetailSchema }),
|
|
objdumpArchitecturesInputSchema.extend({
|
|
detail: commandEvidenceDetailSchema,
|
|
}),
|
|
]);
|
|
|
|
// Rizin owns its arch and CPU vocabulary, and the plugins differ between
|
|
// builds, so REA checks only the spelling. Rizin sets no length limit.
|
|
const rizinNameSchema = z
|
|
.string()
|
|
.regex(
|
|
/^[A-Za-z0-9][A-Za-z0-9_.+\-]*$/u,
|
|
"must be a Rizin name: letters, digits, '_', '.', '+' or '-', starting with a letter or digit",
|
|
);
|
|
|
|
/** Caller-selected Rizin command against one local artifact. */
|
|
export const rizinInputSchema = z
|
|
.object({
|
|
path: localPathStringSchema,
|
|
command: z
|
|
.string()
|
|
.min(1)
|
|
.refine(
|
|
(value) => !/[\r\n\u0000]/u.test(value),
|
|
"A single command line is required",
|
|
),
|
|
asm_arch: rizinNameSchema
|
|
.exactOptional()
|
|
.describe(
|
|
"Rizin arch plugin, passed as -a, such as arm. Plugins differ between builds; e asm.arch=? lists them.",
|
|
),
|
|
// Rizin's widest decoders are 64-bit.
|
|
asm_bits: z
|
|
.number()
|
|
.int()
|
|
.min(1)
|
|
.max(64)
|
|
.exactOptional()
|
|
.describe(
|
|
"Rizin asm.bits, passed as -b, such as 16 for Thumb. Omitted, Rizin's default applies.",
|
|
),
|
|
asm_cpu: rizinNameSchema
|
|
.exactOptional()
|
|
.describe(
|
|
"Rizin asm.cpu, passed as -e asm.cpu=, such as cortexm; e asm.cpu=? lists those of the selected arch.",
|
|
),
|
|
base_address: z
|
|
.string()
|
|
.regex(RAW_BINARY_ENTRY_POINT, {
|
|
message: "base_address must be a hexadecimal address of the form 0x…",
|
|
})
|
|
.exactOptional()
|
|
.describe(
|
|
"Address of file offset 0. REA passes -n and -m, so Rizin maps the file there as a raw image, reads no format headers, and keeps its default decoder unless asm_arch and asm_bits select one.",
|
|
),
|
|
...commandTimeoutMsField,
|
|
})
|
|
.strict();
|
|
|
|
export type ObjdumpSelection =
|
|
| z.input<typeof objdumpArtifactInputSchema>
|
|
| z.input<typeof objdumpDisassemblyInputSchema>
|
|
| z.input<typeof objdumpArchitecturesInputSchema>;
|
|
export type RizinInput = z.output<typeof rizinInputSchema>;
|