846 Commits
Author SHA1 Message Date
pancake edc6310be8 Build zlib before the Sleigh compiler objects 2026-11-07 14:21:04 +01:00
pancake f30f21c13f Respect visible read-only IO map boundaries 2026-11-07 14:21:04 +01:00
pancake 21e49ad932 Clarify read-only propagation modes 2026-11-07 14:21:04 +01:00
pancake de31254948 Stop throwing on name conflicts 2026-11-07 12:24:44 +01:00
pancake 7d27888017 Refresh ESIL goldens and initialize AArch64 before emulation 2026-11-07 11:12:48 +01:00
pancake af24454ff0 Rewrite P-code to ESIL translation with deferred writes and expressions
Inline P-code temporaries as expressions, compute everything from the
pre-instruction state and emit register/memory/pc writes in program order.
Conditional branches guard the following pcodes with the negated condition.
Track the register-space location of operands to handle partial register
overlaps, and compare wide values at 64 bits.
2026-11-06 21:40:18 +01:00
pancake ab2d3b9b48 Update ghidra-native to 0.7.3
* Implement the new Scope::findSymbolBefore/After by asking the cache
* Look up join records through AddrSpace::findJoin
* Iterate main ops now that INDIRECTs live in their own container
* Follow the new size argument of pushUnnamedLocation
* Refresh test expectations for the new decompiler and sleigh output
2026-11-06 00:44:50 +01:00
pancake 5f5e607bb9 Release 6.2.6 6.2.6 2026-11-05 23:51:22 +01:00
pancake 505623d336 Update global variable tests for r2 6.2.6 automatic globals 2026-11-05 23:38:41 +01:00
pancake 718e67cbc3 Fix compiler warnings and silence ghidra-native ones in meson builds 2026-11-05 23:24:06 +01:00
pancake 44275663a3 Fix meson build against r2 6.2.6 sigaction in r_core_priv.h 2026-11-05 23:12:14 +01:00
pancake b4e4246127 Use r2-6.2.6 in the ci 2026-11-05 23:07:46 +01:00
pancake 727ab6eb9e Skip r2ghidra_inline tests on radare2 older than ABI 163 2026-11-05 13:20:34 +01:00
pancake 5d04dc6ced Fix build after r_cons_gprintf removal 2026-11-05 12:53:41 +01:00
pancake 8e0b04edac Fix build with radare2 ABI 168 basic block vectors 2026-10-30 18:55:17 +01:00
pancake d6a283c5cf Add r2ghidra.inline to combine inline functions 2026-10-27 23:10:51 +01:00
pancake af847a9396 Preserve console filtering for timeout worker output 2026-10-18 07:08:21 +02:00
pancake 9b7969e190 Export removed p-code metadata with deadcode enabled
Capture lifted operations before analysis and preserve their native dead state before clearing analysis. Export eliminated_ops in pdgj and pdgx, then rerun with unused computations preserved for display under r2ghidra.deadcode.

Document that p-code retirement does not prove instructions can be NOPed. Cover real dead records, toggling, full addresses and timeout workers.

Validation: 59 focused regression tests; AddressSanitizer with a forced analysis restart and preserved-code rerun.
2026-10-16 00:27:27 +02:00
pancake ab2f721a58 Add r2ghidra.deadcode and add is_dead fields in pdgj 2026-10-16 00:01:44 +02:00
pancake 5353b890dc Export native p-code dead state in pdgx XML 2026-10-15 21:45:33 +02:00
pancake 911d82d214 Consume ghidra-native 0.7.2 and refresh subprojects in place
Use the upstream Meson dependency, shared source manifest, and Sleigh compilation helper instead of maintaining local copies. Check pinned subprojects before Make and XPS builds, cache fetched revisions for offline reuse, and save local ghidra-native changes in a named stash before updating.
2026-10-15 21:32:18 +02:00
pancake aeede61eea Reference ghidra-native 0.7.0 2026-10-12 19:21:18 +02:00
Kirby Kuehl 06db2a163c ccode: honor r2ghidra.casts instead of forcing casts off
ccode mode called setNoCastPrinting(true) after applying r2ghidra.casts, so
`e r2ghidra.casts=true` was silently overridden and semantically necessary
truncations disappeared. For

  long cast_test(long x) { return (long)(int)x + 0x100000000L; }

the output was `arg1 + 0x100000000`, which evaluates to 0xffffffff at
0xffffffff instead of the 0x1ffffffff the binary produces.

Let r2ghidra.casts decide: ccode keeps only the identifier cleanup and the
hidden implied ZEXT/SEXT extensions and no-convention prototype style. With
ccode=true,casts=true the printer now emits
`(int64_t)(int)arg1 + 0x100000000`; with casts=false it stays cast-free as the
option documents, and ccode=false output is unchanged.

Regression in test/db/extras/r2ghidra_ccode with the compiled fixture.
2026-10-12 19:18:42 +02:00
Kirby Kuehl c2c66513e1 ccode: keep whole import names instead of splitting at the first underscore
sanitizeCName() assumed every flag tail was `<lib>_<fn>`, which corrupted
names in actual output:

- ELF imports lost their prefix: sym.imp.pthread_mutex_lock became mutex_lock
  (and sym.imp.__libc_init lost a leading underscore).
- Windows API-set DLL names stopped at the first underscore inside the
  library name, leaving a dot and naming the wrong symbol:
  sub.api_ms_win_crt_stdio_l1_1_0.dll__set_fmode became
  ms_win_crt_stdio_l1_1_0.dll__set_fmode.

Only strip a real PE `.dll_` separator (case-insensitive); keep the whole tail
for ELF imports, handle loc.imp. like sym.imp./imp., and use the same rule for
sub. stubs. Normalize the result to a legal C identifier: keep leading
underscores, map dots/@/other illegal characters to _, never return empty
(a leading digit gets an underscore prefixed).

Prefer import metadata when it actually improves the name: registerFunction()
now uses a flag realname that differs from the raw flag name (rsym. flags carry
their own namespaced name as realname). This matches what registerFunctionFlag
and registerFlag already do for ccode output and also fixes those names for
e asm.flags.real=true.

Regressions in test/db/extras/r2ghidra_ccode:
- radare2-testbins/pe/ConsoleApplication1.exe, the reviewer's
  sub.api_ms_win_crt_stdio_l1_1_0.dll__set_fmode fixture -> _set_fmode
- a small ELF .so importing pthread_mutex_lock -> pthread_mutex_lock
- hello-arm's sym.imp.__libc_init -> __libc_init
2026-10-12 19:18:42 +02:00
Kirby Kuehl 70f4428e29 subprojects: track radareorg/ghidra-native at bcfd3fa and apply its patches
The wrap pointed at a fork revision with the patches baked into src, and the
generated dependency Makefile still applied a private copy of the patches that
this PR deletes, so clean builds failed on the missing 0100-CHAR-windows.patch
and ghidra-native.patch.

Pin both the wrap and subprojects/ghidra-native.mk to radareorg's merged
revision bcfd3fa and apply upstream's own patch stack once:

- acr Makefile: after checkout and the packagefiles overlay, run upstream's
  `make patch`, which applies patches/*.patch in order and fails on the first
  error (patch.done marks completion).
- meson overlay: at configure time apply the same top-level patches once with
  `git apply` (git is guaranteed for wrap-git builds, so Windows needs no GNU
  patch), enumerated from `git ls-files patches` filtered to patches/*.patch,
  which is the same order as upstream's `ls patches/*.patch | sort -n`.
  Dirty trees and trees carrying upstream's patch.done are skipped, and a
  checkout at any other revision fails configure, so the stack is never
  applied twice.

A `make dist` archive stays the release path: it ships pre-patched and carries
patch.done but neither patches/ nor .git, so the meson step is a no-op.

Verified from a clean tree: `make -C subprojects ghidra-native` exits 0 and
leaves a tree whose diff is byte-identical to upstream's own `make patch`
flow; a fresh meson fetch logged "applied 18 upstream patches" and produced
the same tree; re-running configure skipped patching (hash unchanged) and the
MSVC build completed.
2026-10-12 19:18:42 +02:00
Kirby Kuehl f6a5cf8b4b Consume ghidra-native's own patches instead of a private copy
Point the ghidra-native wrap at the fork (feature/r2ghidra-patches, which
ships the patches/ and the patched src/) and drop the private
subprojects/packagefiles/ghidra-native/patches copy plus the diff_files list.
The decompiler now builds from ghidra-native's patched source directly.

Note: the wrap url/revision point at the kkuehl fork until the ghidra-native
PR merges to radareorg/ghidra-native; then re-point at the upstream commit.
2026-10-12 19:18:42 +02:00
Kirby Kuehl a47158ce76 ccode: name unknown globals instead of raw address literals
When ccode is on, disable rawptr so unknown globals render as named symbols
(iRam... / pcRam... / piRam...) instead of *0x... address literals.
2026-10-12 19:18:42 +02:00
Kirby Kuehl 29400ddf78 ccode: prefer radare2's realname when emitting clean identifiers
When e r2ghidra.ccode is enabled, resolve flags to their realname (the
clean import or demangled name radare2 already derives from the binary)
instead of the sym.imp.<lib>_<fn> or mangled flag name. sanitizeCName stays
as the fallback for names with no realname, such as anonymous functions.
2026-10-12 19:18:42 +02:00
Kirby Kuehl 4138f27e3b ccode: deindirect PE import calls to read as direct calls
On Windows PE, imports are reached through the IAT: `call qword
[sym.imp.KERNEL32.dll_WriteFile]`. Pcode renders that as an indirect
dereference `(*_WriteFile)(...)`, which is not a direct call expression.
The existing fixupResolvedIndirectCalls only deindirects register-indirect
calls.

Add fixupImportCallDeindirection: for every CALL/CODE ref whose target is
an import flag, insert a deindirect override so the decompiler prints a
direct call. Gated by e r2ghidra.ccode so default output is unchanged.
2026-10-12 19:18:42 +02:00
Kirby Kuehl 713c07d9df ccode: strip radare2's <lib>.dll_ prefix from import symbols
radare2 6.2 names imports `sym.imp.<lib>_<fn>` (e.g.
`sym.imp.KERNEL32.dll_WriteFile`) rather than the older `sym.imp.<fn>`.
The previous sanitizer only dropped `sym.imp.`, leaving the `.dll`-bearing
library name in the output (`KERNEL32.dll_WriteFile`), which is still not a
valid C identifier. Drop everything through the first `_` so the bare
`WriteFile` remains, and switch `sub.` to `find('_')` too so names with a
leading underscore (`_snprintf`) survive.
2026-10-12 19:18:42 +02:00
Kirby Kuehl 6f25345c15 ccode: also emit CCODE-style PrintC options (no casts, hide implied exts)
When e r2ghidra.ccode=true, additionally set NoCastPrinting, HideImpliedExts
and disable the calling convention on the prototype, so the output reads more
like Ghidra's toggleCCode and parses as clean C with less ZEXT/SEXT noise.
2026-10-12 19:18:42 +02:00
Kirby Kuehl e0fea58b19 Add e r2ghidra.ccode: emit clean C identifiers
radare2 labels import stubs sub.<lib>_<fn>, anonymous functions fcn.ADDR and
imports sym.imp.fn / imp.fn - none of which are valid C identifiers, so the
decompiled output uses names that are not legal C.

New opt-in eval var, e r2ghidra.ccode=true, sanitizes names in R2Scope:
- sub.<lib>_<fn> -> <fn> (import stubs -> bare symbol, e.g. memcpy)
- sym.imp.<fn> / imp.<fn> -> <fn> (import flags)
- dotted names (fcn.ADDR, sym.lib.fn) -> underscores

Applied in registerFunction, registerFunctionFlag and registerFlag; default
stays false so existing output is unchanged.
2026-10-12 19:18:42 +02:00
Kirby Kuehl 704e5546ec Fix ghidra-native patches against resynced decompiler sources (483ae94)
Commit 20d6ae1 bumped ghidra-native to 483ae94 but only regenerated a few
patches, leaving four stale ones that no longer apply and break the meson
build:

- 0002-make-sleigharch-public (sleigh_arch.hh reorganized, getDescriptions
  present, collectSpecFiles still in protected section)
- 0020-Fix-double-free (xml.hh moved from 'using namespace std' to
  per-symbol using declarations)
- 0091-decompiler-xml-packer (setOutputStream moved below setPackedOutput)
- 0092-badvar-segfault (SymbolEntry::getSizedType renamed to
  MapEntry::getSizedType and the off computation folded to one line)

Regenerate all four against 483ae94 so the wrap applies cleanly. Also add
the missing trailing newline to 0001-space-after-comma.patch, which newer
git releases otherwise reject as a corrupt patch.
2026-10-12 19:18:42 +02:00
phix33 d690abdbfd Preserve recovered pdgw types without changing ABI or stack writes 2026-10-07 04:21:01 +02:00
pancake c1287ccb54 Fix r2 cc clobber sets in prototype models 6.2.4 2026-10-05 23:01:53 +02:00
pancake 817db5d3fa Release 6.2.4 with msvc workaround for r_cmd.h 2026-10-05 22:24:29 +02:00
pancake 8b3f878b71 Release 6.2.4 2026-10-05 21:57:41 +02:00
pancake 9fe5eb84df Update to base ci image to Ubuntu 24.04 2026-10-05 20:36:35 +02:00
pancake ff0b1d6cc7 Add linux-arm ci builds and improve for r2pm-b 2026-10-05 20:36:32 +02:00
pancake 763477467d Simplify Sleigh ID resolution and be case insensitive 2026-09-22 17:50:09 +08:00
pancake a271227ca9 Ignore endian when building sleighid for single endian archs 2026-09-22 16:33:40 +08:00
pancake 11a688481d Fix default Sleigh discovery on Windows 2026-09-22 13:10:59 +08:00
phix33 ebd12d2536 Read prototype arg counts through one version-compat helper 2026-09-16 14:20:18 +08:00
phix33 5884d67ca0 Accept any spelling of a zero prototype argument count 2026-09-16 14:20:18 +08:00
phix33 a59c4ecbc1 Lock noreturn inputs only for known empty prototypes 2026-09-16 14:20:18 +08:00
phix33 9e36cfd88e Stop pdg decompiling past noreturn calls to relocated imports 2026-09-16 14:20:18 +08:00
phix33 ce32d30a8f Stop shipping an arm64 copy as the x86-64 varargs fixture 2026-09-16 11:32:09 +08:00
pancake 0166ba412c Support the RFlag vector API 2026-09-12 14:31:52 +08:00
pancake 1b5cba403c Release 6.2.2 6.2.2 2026-09-06 20:51:13 +02:00
phix33 20d6ae1924 Update ghidra-native to the resynced decompiler sources 2026-08-23 13:27:35 +02:00