Repository navigation
feat(ghidra): recover signed AArch64 relative jump tables - #1592
Conversation
Generalise the AArch64 relative-table matcher to signed byte/halfword entries, UXTW indexes, byte or LSL morluto#2 offsets, B.CS/B.HS bounds and a CBZ route for zero entries. Cross-check it against Ghidra's own load table when one exists, and add a fixture modelled on the RenderScript blend kernel. Refs morluto#487
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: On Linux the new signed-table check passes. All five cases map to the right code, including case 3 (the ResultsI tested head On this box the Ghidra lanes do not reach the PR's code as shipped. GCC here is 16.2.1, and the
The PR adds no unit tests. The five test files are existing ones that sit near the Ghidra code. On the PR, the cross-format failure goes away when only Case 3, checked by hand. I built the fixture with the lane's Entry alias (#1597). The check passes on Linux, and it ran unmodified. My added changes touch only the two verifier scripts and One thing stays unknown. The default path (selector 5 and up, through Not run
Thanks, RishTheFish21, for a fixture that carries its own answers in the source, and for filing #1597. ConflictsGitHub marks the PR as conflicting. I did not merge, because the mirror is read-only here. Since A plain
Git's own merge may disagree with What I added to both trees
Commands# trees: git archive <sha> | tar -x, then on Node 24.18.0
npm ci && npm run build
# one Ghidra lane at a time, GHIDRA_INSTALL_DIR and JAVA_HOME set
npm run verify:ghidra:aarch64-jump-table
npm run verify:ghidra:cross-format
# Node 22, 24 and 26
npm run test:focused -- tests/boundary/providers/ghidra/ghidraLauncher.test.ts \
tests/boundary/providers/ghidra/ghidraClient.test.ts \
tests/boundary/mcp/ghidraNativeApiMcp.test.ts \
src/ghidra/GhidraFunctionValues.test.ts \
src/application/native/NativeApiInspection.test.ts
# check:fast needs a git checkout, so it ran in a clone at 8ab1453e5
npm run check:fast
# by hand
clang --target=aarch64-linux-gnu -c tests/conformance/ghidra/relative-switch-signed.S -o rs.o
nm -n rs.o; readelf -r rs.o; readelf -x .rodata rs.o
gdb --batch -ex 'set architecture aarch64' -ex 'file rs.o' -ex 'disassemble /r 0x0,0x54'The case-3 numbers on both trees came from a short MCP script: Raw output: the new table on the PRBase, same Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Welcome, @RishTheFish21! Thank you for the signed AArch64 jump-table work. The zero-entry |
Summary
Part of #487. REA's AArch64 relative jump-table matcher only recognised one shape: unsigned
ldrb/ldrhentries,lsl #2offsets and ab.hibound. Hand-written code like the RenderScript blend kernel from the issue thread usesldrsh, auxtwindex, plain byte offsets, ab.csbound and acbzthat skips zero entries. This PR extends the matcher to those forms, still only when the bound, registers and table bytes check out exactly.Problem and expected behavior
On the new fixture (same instruction shape as
rsdIntrinsicBlend_K),mainmaps cases 0, 1, 2 and 4 from Ghidra's typed case labels. Case 3 is a zero entry that thecbzsends to its own path. Ghidra doesn't model thecbz, so it decodes that entry as a branch to the table's base address, which thebrcan never reach. REA then reported the base as a target with an unknown case, and case 3's real destination was missing.Expected: every case maps to the code it actually reaches, with evidence, and anything REA can't prove stays unknown.
Change and scope
uxtwindexes, byte orlsl #2offsets,b.hiorb.cs/b.hsbounds, and an optionalcbzon the loaded entry. It still requires one straight-line path with no other branches into it, and an index bounded by the compare.cbzmap to thecbztarget. The base address Ghidra decodes for them is no longer listed as an unknown target; a limitation explains why it's unreachable.tests/conformance/ghidra/relative-switch-signed.S, wired into theaarch64-jump-tablelane as ELF, plus Mach-O on arm64 hosts.Not included: reporting computed branches Ghidra can't resolve, and returning a partial dossier when the decompiler fails. Both are planned as a follow-up.
Contract and boundary impact
ReaGhidraBridge.java), jump-table inference.Evidence and regression coverage
verifyRelativeSignedSwitch, which checks every case target against the immediate written in the source.mainbehavior when Ghidra exposes a load table), the new check fails withSigned relative switch case 3 was not verified, and0x100030is reported as an unlabelled target.inspect_native_apinow reports case 3 → thecbztarget with high confidence, plus a limitation naming the unreachable base address.For evidence-bearing changes:
Validation performed
npm run verify:ghidra:aarch64-jump-tableon an Apple Silicon Mac (Ghidra 12.1.4, JDK 21, decompiler built withbuildNatives): passed.relative-signedwas verified for ELF and Mach-O; the existingrelative-1/relative-2fixtures and the cross-format AArch64 fixture still pass.npm run check:I ran the lane with the entry-alias boundary check skipped locally (not part of this PR). That check already fails on macOS arm64 on
main: the fixture's interior label lands on the function entry, and even when moved, the Mach-O linker records it as a function start, so Ghidra makes it a function. I'll open a separate issue. Because of the skip, theimported_entry_alias_selection: truein the report is not evidence. Not run against the reallibrenderscript-toolkit.so, only against a fixture with the same shape. Not run on Linux.Compatibility, safety, and release
Review checklist
type(scope): outcome.