Skip to content

feat(rizin): select the decoder and map address for one-shot commands - #8991

Merged
morluto merged 9 commits into
morluto:mainfrom
Entrpi:feat-rizin-decoder-inputs
Nov 6, 2026
Merged

morluto merged 9 commits into
morluto:mainfrom
Entrpi:feat-rizin-decoder-inputs

Conversation

@Entrpi

@Entrpi Entrpi commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #7955. execute_rizin_command could not open a raw firmware image at its load address: -n is a startup option, so no command can set it, and a Rizin format loader can claim a raw image and give wrong reads with no error. This PR adds four optional inputs that select the decoder and the map, and states what REA does not confirm about them.

Problem and expected behavior

An analyst with a Cortex-M or ESP32 flash dump needs the bytes decoded with the right arch at the right address. Rizin 0.9.1's AVR loader can claim such an image and turn io.va off, so every read at the mapped address returns 0xff. The BIOS loader maps the file at another address. With these inputs the same call reads the file at the caller's address, and Evidence records the choice.

Change and scope

  • asm_arch, asm_bits, asm_cpu and base_address become -a, -b, -e asm.cpu= and -n -m, on MCP and the CLI (--asm-arch, --asm-bits, --asm-cpu, --base-address). Rizin 0.9.1 refuses -e asm.arch= at startup, so REA uses -a and -b.
  • REA checks only the spelling. Rizin owns the arch and CPU names, and its builds differ.
  • Results state what REA does not confirm: that Rizin applied the asm_* values, and the map. -n also keeps Rizin's default arch, bits and byte order unless the call selects them.
  • The tool description carries the raw-loading warning, because the compact catalog drops property descriptions.
  • Independent of feat(rizin)!: record which tool and version answered execute_rizin_command #7487, which [Roadmap] Embedded firmware: make REA work on the devices around us #7955 lists first. The two share one import line in src/composition/reverseEngineering.ts, which the PR that lands second takes. Until feat(rizin)!: record which tool and version answered execute_rizin_command #7487 lands, Evidence for these calls has no Rizin version.
  • Not included: byte-order input (e cfg.bigendian=true in the command does this), a rebase of a format-loaded file, and a Rizin session mode.

Contract and boundary impact

  • Semantic owner and earliest changed stage: rizinInputSchema in src/domain/reverseEngineering.ts owns the inputs. src/rizin/RizinCommand.ts owns the arguments and limitations, and the application port carries limitations generically.
  • Contribution scope fit and linked maintainer decision: not applicable; these are optional inputs on an existing tool, with no new target execution.
  • CLI and MCP/tool-catalog contract: four optional inputs on one tool. Existing calls keep their arguments and results. Output schemas do not change.
  • Provider, bridge, target-format, or platform compatibility: Rizin 0.9.1 and 0.7.4 accept -a, -b, -n and -m. Arch and CPU availability depends on the build.
  • Evidence, artifact, provenance, or reconstruction contract: parameters records each input and the complete command_arguments. Limitations are added only when an input is set.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none changed.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none beyond the regenerated tool catalog.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: RizinDecoderInputs.test.ts, a real-provider gate through MCP, covers the arguments' effect on raw images, reads around the map, images that the AVR and BIOS loaders claim, an arch and bits value Rizin lacks, asm_cpu changing a decode (msr primask, r0 with cortexm, invalid without), and a base_address-only call whose command removes the map. CLI, MCP and composition tests cover the arguments, parameters, limitations and refusal of a value such as cortexm; q.
  • Base reproduction or other evidence: executed; see the gate above and docs/testing-lanes.md.
  • User-visible CLI/MCP output (if applicable):
$ rea execute-rizin-command flash.bin "e asm.arch; e asm.bits; e asm.cpu; oml; pi 2 @ 0x08000008" --asm-arch arm --asm-bits 16 --asm-cpu cortexm --base-address 0x08000000
raw_result:
  stdout: "arm\n16\ncortexm\n 1 fd: 3 +0x00000000 0x08000000 * 0x0800000d r-x \nmsr primask, r0\nbx lr\n"
  • Remaining proof gaps: no test covers format loading being skipped for a real ELF, the documented ESP om recipe, or Linux host defaults. Homebrew's Rizin has no xtensa or riscv plugin. .github/workflows does not mention Rizin, so the gate presumably skips in CI (inferred, not observed).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

On the head 30120e099, which changes only test files after ed30d26df:

  • npm run check:fast, format:check, docs:check, knip — passed.
  • The 4 test files this PR changes — 44 passed, including the 6 real-provider tests on Rizin 0.9.1 (Homebrew, macOS arm64).
  • npm run test:focused -- tests/boundary/providers/RizinDecoderInputs.test.ts — 6 passed on Rizin 0.7.4 (official static build, Linux x86_64).
  • CI passed on this head.

On 1fb5a7435, which contains main 71f680d7c (ed30d26df after it changes docs/testing-lanes.md only, and format:check and docs:check passed there):

  • npm run test:focused -- tests/boundary/providers/RizinDecoderInputs.test.ts — 6 passed on Rizin 0.9.1 (Homebrew, macOS arm64) and 6 passed on Rizin 0.7.4 (official static build, Linux x86_64).
  • npm run check:fast, format:check, docs:check, knip — passed.
  • The 4 test files this PR changes, src/contracts and toolSchemaValidity — 28 files, 286 passed, 3 skipped.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real Rizin on macOS arm64 and Linux x86_64. No Ghidra or Hopper involvement.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: names are limited to letters, digits, _, ., + and -, start with a letter or digit, and reach Rizin as separate arguments, so a value cannot become a flag or a command. The tool's existing warning about Rizin commands and plugins still applies.

Author readiness

Human owner: @Entrpi

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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).
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.
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.
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.
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.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-05T08:37:07.794467Z
We couldn’t complete this review. Comment @codex review to try again.
ed30d26 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge; no new blocking issue remains in the reviewed changes.

Summary

Adds optional decoder and raw-map inputs to one-shot Rizin commands through CLI and MCP. Evidence keeps the selected inputs, arguments, and limits of what REA confirms.

  • Callers can choose Rizin's decoder and map a raw file at a chosen address.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Input["CLI or MCP inputs"] --> Schema["rizinInputSchema"]
  Schema --> Args["RizinCommand"]
  Args --> Decoder["-a, -b, asm.cpu"]
  Args --> Map["base_address → -n -m"]
  Decoder --> Rizin["Rizin command"]
  Map --> Rizin
  Rizin --> Evidence["Output, arguments, and limitations"]
Loading

Reviews (2) · Last reviewed commit: "test(rizin): follow the test guide in th..." · Reviewed by Greptile

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.
@morluto
morluto merged commit 81f9f71 into morluto:main Nov 6, 2026
47 checks passed
Entrpi added a commit to Entrpi/rea that referenced this pull request Nov 7, 2026
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added area: cli CLI adapter and one-shot commands enhancement New feature or request provider: rizin Analysis provider / engine: rizin labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands enhancement New feature or request provider: rizin Analysis provider / engine: rizin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants