Commit graph

2255 commits

Author SHA1 Message Date
Yan
9f046651bc CFGFast: Keep a function the binary's own symbol table names
drop_bad_functions() exists to remove functions the linear scan decoded out of
data. One of its tests deletes a function whose block ends in bytes the lifter
could not decode, which is sound when the bytes are data and wrong when they are
an instruction set VEX does not implement: glibc's EVEX string routines, the
AVX-512 PLT resolvers, and MIPS III code in a 32-bit container all look like
data from there.

A function whose entry the file's own symbol table names is not something the
scan invented, so skip it. Everything the file does not name is judged exactly
as before.
2026-08-17 11:05:37 +00:00
Yan Shoshitaishvili
2c95eb92e6
CFG: Warn when the regions to analyze cover no bytes. (#6825) 2026-08-13 17:26:22 -05:00
Fish
b80f4cf2af
Outliner: Rebuild phi statements; update output phis; return only region-defined vvars. (#6831)
* Rebuild phi statements instead of mutating them in place

* Update the phis of every dispatcher target

* Return only the variables the outlined region defines
2026-08-13 13:51:21 -07:00
Fish
41a7db2f17
SLiveness: propagate to predecessors instead of re-walking the graph (#6830) 2026-08-13 12:38:23 -07:00
Yan Shoshitaishvili
2bfaa7e8f7
CFGModel: Stop aborting when tidying a data reference at an unmapped address (#6811)
Fix #6770.
2026-08-11 13:27:06 -07:00
Fish
0c293dc0de
Phoenix: Fix incorrect virtualization of orphaned edges. (#6790) 2026-08-09 02:00:48 -07:00
Fish
ede5faf162
Decompiler: Add edits layer; add more tools to MCP. (#6789) 2026-08-09 01:48:07 -07:00
Fish
bdc1321845
RustCodeGen: Add more handlers. (#6788) 2026-08-08 09:28:22 -07:00
Fish
666fadabc5
Dephication: Keep the remapped assignment destination with source is not a vvar. (#6787) 2026-08-07 23:50:03 -07:00
Fish
fdd66945ea
CFGTransformationMixin: Rebuild conditional jumps when replacing branch targets. (#6786) 2026-08-07 23:46:34 -07:00
Fish
b0e3541dfd
SwitchClusterSimplifier: Do not merge different default nodes. (#6782) 2026-08-07 19:13:10 -07:00
Fish
780a80de79
Phoenix: Correct Loop.continue_addr. (#6785) 2026-08-07 18:41:56 -07:00
Fish
08c7e48d5b
CFGFast: Mark bad blocks found by complete scanning as nodecode. (#6781) 2026-08-07 14:16:21 -07:00
Fish
0f4be85db4
Make CallSiteMaker a normal class instead of an Analysis. (#6776) 2026-08-06 08:44:29 -04:00
Fish
7d3c7c82ce
AILSimplifier: De-quadratify _unify_local_variables. (#6772) 2026-08-05 22:33:55 -04:00
Md7
1c99579f69
Fix #6744: avoid empty Or expression in memory.find (#6750) 2026-08-05 04:01:10 -07:00
Fish
3333f39fff
CFGFast: Make the smart scan nodecode ratio O(log n) (#6767) 2026-08-05 01:42:45 -07:00
Fish
7c2e3501e6
SimStruct: Remove _arch_memo to fix the cache leak. (#6757)
* SimStruct: Remove _arch_memo to fix the cache leak.

* Fix the comment

* Better typing.

* Fix RustSimTypes.

* More fixes.

* Fix caching for anonymous structs.

* SimUnion: Cache alignment.

* Convert returnty to a arch-ed returnty.

* RustSimType: Do not shadow SimType.with_arch.

* Rust: Bind an arch to types before they reach the type solver.

* RustSimType: Make it a subclass of SimType.
2026-08-05 01:12:55 -07:00
Yan Shoshitaishvili
f160178837
reaching_definitions: reject mismatched conversion widths (#6749)
* reaching_definitions: reject mismatched conversion widths

* Tests: satisfy RDA lint and type checks
2026-08-05 00:26:01 -07:00
Fish
71bf42c9b8
Decompiler: Test common C conditions. (#6762)
* Decompiler: Test common C conditions.

* Improve c-style null compatison implementation

* Make order-sensitive

---------

Co-authored-by: Kevin Phoenix <kevin@kphoenix.us>
2026-08-04 18:27:09 -07:00
Fish
551df09fc5
Decompiler: Fix duplicate struct defs for pre-defined structs. (#6756) 2026-08-03 22:12:47 -07:00
Yibo Liu
0f8e082f9a
Clinic: recover variable-length arrays (VLAs) (#6634) 2026-08-01 13:41:12 -07:00
Kevin Phoenix
49434bc3fc
Render truncations to non-C widths as masks instead of casts (#6741) 2026-07-31 17:05:47 -07:00
Quintin Kong
d46e56f891
Fix signed division and remainder in the pcode engine (#6739)
* Fix signed division and remainder in the pcode engine

OpBehaviorIntSdiv and OpBehaviorIntSrem used Claripy's `/` and `%`, which are
unsigned bit-vector operations. For negative operands they therefore produced
the same results as the unsigned INT_DIV and INT_REM behaviors.

INT_SDIV now uses claripy.SDiv (truncation toward zero). INT_SREM is defined as
in1 - SDiv(in1, in2) * in2, giving a remainder with the dividend's sign, which
matches the p-code semantics documented in the class comments.

For 64-bit -5 and 2, INT_SDIV now yields -2 (0xfffffffffffffffe) and INT_SREM
yields -1 (0xffffffffffffffff) instead of large unsigned values.

The arithmetic behavior test table enables both INT_SDIV and INT_SREM with the
matching signed reference expressions, and a new concrete test checks mixed-sign
combinations (-5/2, 5/-2, -5/-2, ...) that an unsigned implementation cannot
satisfy.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Use claripy.SMod for INT_SREM

Per review, INT_SREM uses claripy.SMod directly instead of the equivalent
in1 - claripy.SDiv(in1, in2) * in2. Verified identical to a truncated-toward-zero
reference over 100k random 64-bit pairs, including the INT_MIN / -1 corner.

* Address pcode signed arithmetic review comments

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-07-31 12:23:05 -07:00
Fish
61bac8ffd0
SimConstantVariable: Fix overflows and value out of range errors. (#6738)
* SimConstantVariable: Fix overflows and value out of range errors.

* Fix usages of SimConstantVariable.

* Mask the value.

* Fix negative values.
2026-07-29 13:58:20 -07:00
pre-commit-ci[bot]
d38cc5a019
[pre-commit.ci] pre-commit autoupdate (#6721)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.15.22 → v0.16.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.22...v0.16.0)

* Apply fixes

* Add values()

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kevin Phoenix <kevin@kphoenix.us>
2026-07-29 13:46:11 -07:00
Fish
7cedfbfa8b
Dephication: Correctly consider phi congruence classes. (#6735) 2026-07-29 01:53:02 -07:00
Fish
b9358da5da
AIL: Fix __eq__. (#6728)
* AIL: Merge likes/matches into a single mode-parameterized walk

* AIL: Make __eq__ idx-aware at every node, not just the root

* AIL: Stop hashing fields that equality does not compare

* AIL: Regression-test the hash/eq contract

* AIL: Compare bits in StringLiteral and Struct

* AIL: Replace the CMP_* constants with a CmpMode enum

* AIL: cargo fmt

* AIL: Compare and hash rounding_mode on Convert and BinaryOp

* Update comments.
2026-07-29 01:22:10 -07:00
Ati Priya
6933b065f0
Decompiler: rewrite CondBE and CondNB ccalls on amd64 (#6645)
* Decompiler: rewrite CondBE and CondNB ccalls on amd64

* Decompiler: fix inverted CondZ/CondNZ over G_CC_OP_COPY on amd64

* tests: add binary-driven regressions for CondBE/CondNB ccall recovery
2026-07-29 01:11:09 -07:00
Fish
6b2637c446
Dephication: Consider the vvar used in block-end jumps during intersection. (#6733)
* Dephication: Consider the vvar used in block-end jumps during intersection.

This is a subtlety in the Sreedhar et. al. paper.

* Fix test cases.
2026-07-29 00:42:21 -07:00
Fish
a7ae033c69
EagerEval: Fix broken expression type comparison. (#6734)
This is a bug introduced by the Rusty AIL migration.
2026-07-29 00:05:07 -07:00
Fish
659f3d7f5d
CCodeGen: Fix the display of negative offsets. (#6730)
* CCodeGen: Fix the display of negative offsets.

* Fix a test case.
2026-07-28 22:29:12 -07:00
Fish
22613f4a0a
CompleteCallingConventions: fail loudly when all workers die. (#6718) 2026-07-27 18:20:59 -07:00
Fish
2fffb71f86
state_plugins: Map the heap region lazily and grow it on demand. (#6715) 2026-07-27 18:20:07 -07:00
Fish
55f059982b
UltraPage: Make the symbolic map an actual bitmap. (#6714) 2026-07-27 17:35:52 -07:00
Fish
1a5eedf622
Decompiler: Speed up AIL block simplifications. (#6712)
- Make SPropagator, SRDA, and BlockSimplifier normal classes instead of Analysis classes.

- Share peephole optimizer instances across BlockSimplifiers.

- BlockSimplifier: Skip unnecessary peephole passes; avoid block-level comparisons for fixpoint determination.

- Add a runtime-only peephole_optimized flag to AIL statements so we skip running peephole optimizations on already optimized statements.
2026-07-27 16:34:10 -07:00
Fish
bc72b9e1a6
MCP: Protect stdio from forked workers. (#6717)
Some checks failed
CI / Rust Check (push) Failing after 6s
CI / rust_test (ubuntu-latest) (push) Failing after 9s
Test with coverage / Build (push) Failing after 8s
Test with coverage / Test (push) Has been skipped
Test with coverage / Test-1 (push) Has been skipped
Test with coverage / Test-2 (push) Has been skipped
Test with coverage / Test-3 (push) Has been skipped
Test with coverage / Test-4 (push) Has been skipped
Test with coverage / Test-5 (push) Has been skipped
Test with coverage / Test-6 (push) Has been skipped
Test with coverage / Test-7 (push) Has been skipped
Test with coverage / Test-8 (push) Has been skipped
Test with coverage / Test-9 (push) Has been skipped
Test with coverage / Test Rust packages (push) Failing after 6s
Test with coverage / Report (push) Has been skipped
CI / ci (push) Has been cancelled
CI / Test installation (macos-26, py3.12) (push) Has been cancelled
CI / Test installation (ubuntu-24.04, py3.14) (push) Has been cancelled
CI / Test installation (windows-2025, py3.12) (push) Has been cancelled
CI / rust_test (macos-latest) (push) Has been cancelled
CI / rust_test (windows-latest) (push) Has been cancelled
2026-07-27 03:01:56 -07:00
Fish
651d9cccc2
Tests: Speed up decompiler-related test cases (strike 1). (#6713) 2026-07-27 01:56:24 -07:00
Fish
787c2c7d8e
SimpleSolver: Memoize least common ancestors on type lattices. (#6707) 2026-07-26 17:17:09 -07:00
Fish
b37cca0101
VRA: Register the Reference stack variable against its atom. (#6705) 2026-07-26 07:58:06 -07:00
Fish
fc7ff8e62c
CFGFast: Linear scan heuristics for monotonic byte ramps and floats. (#6701) 2026-07-26 00:35:43 -07:00
Yan Shoshitaishvili
83d0061e12
Calling conventions: ignore stack canary comparisons as returns (#6699)
* Calling conventions: ignore stack canary comparisons as returns
2026-07-24 16:34:21 -07:00
Yan Shoshitaishvili
f74d1c5c1e
Typehoon: index subtype constraint components (#6696)
* Typehoon: index subtype constraint components

* Refactor the code to eliminate weird terminology.

* Fix test cases.

---------

Co-authored-by: Fish <fishw@asu.edu>
2026-07-24 16:26:47 -07:00
Fish
3efd1ec6db
SimLibrary/SimSyscallLibrary: Treat None prototypes as absent. (#6673) 2026-07-24 11:29:58 -07:00
Ati Priya
db21fb0fee
Rewrite the amd64 CondO/CondNO ccall (#6693)
* Rewrite the amd64 CondO/CondNO ccall family

amd64g_calculate_condition with cond CondO/CondNO had no rewrite arm at
all, so every jo/jno/seto/cmovno site leaked into the decompilation as an
uncompilable _ccall(0|1, cc_op, ...).

Add arms for the cc_op families that define OF:

  LOGIC{B,W,L,Q}  and/or/xor always clear OF -> constant 0 / 1
  ADD{B,W,L,Q}    -> __OFADD__(dep_1, dep_2)
  SUB{B,W,L,Q}    -> __OFSUB__(dep_1, dep_2)
  UMUL{B,W,L,Q}   -> __OFUMUL__(dep_1, dep_2)
  SMUL{B,W,L,Q}   -> __OFSMUL__(dep_1, dep_2)
  INC{B,W,L,Q}    result == signed minimum
  DEC{B,W,L,Q}    result == signed maximum
  COPY            test the stored OF bit

The overflow helpers follow the existing __CFADD__ arm: a named usercall
whose operands carry the operation width. CondNO reuses the same helper
and compares it against zero.

Unsigned multiply overflow is defined as "the high half of the full
2N-bit product is nonzero", i.e. the product does not fit in N unsigned
bits. Note this is NOT the threshold used by the x86 rewriter, which
compares the product against 1 << (N - 1) -- that is the signed
threshold, half the correct unsigned one, and it reports overflow for
every product in [2^(N-1), 2^N - 1] even though those fit. At 8 bits it
misclassifies 820 of 65536 operand pairs, all false positives.

pc_actions_UMUL in the VEX ccall helpers is itself wrong here: it
multiplies two N-bit values without widening, so its `>> nbits` is
always zero and its CF/OF do not agree with the hardware. The rewrite
arm follows the hardware and pc_actions_SMUL's (correct) structure
instead; fixing the helper is left alone.

Every arm was checked exhaustively at 8 bits against
pc_calculate_condition, and the ADD/SUB/UMUL/SMUL arms additionally
against real setcc results.

* Drop the synthetic CondO fixture test

The real gzip and file fixtures already cover the CondO arms; a purpose
built binary added nothing that the unit tests do not already check.

* Cover the CondNO overflow path with a real binary

tar's argp helper guards a multiply with 'mul %rbp; jno', exercising the
CondNO side of UMULQ that gzip and file do not reach. Other cc_op
families still leak a ccall in that function, so only the OF conditions
are asserted.

* Cover the CondO overflow arms with three more real binaries

coreutils cat, grep and zlib's minigzip each carry the xalloc /
__builtin_mul_overflow idiom, between them exercising CondO against
ADDQ, SMULQ and UMULQ across three separate projects. Verified symbols
and addresses are cited on each test.

* Correct the tar overflow test to CondO

The jno there is canonicalized into CondO with an inverted branch, so the
ccall reaching the rewriter carries cond 0, not cond 1. The negation seen
in the output is the structurer's, not the condition's.
2026-07-24 11:28:39 -07:00
Fish
91cc026062
AILVexLifter: Fix libVEX overread by padding in convert_from_lift. (#6686) 2026-07-24 01:43:20 -07:00
Yan Shoshitaishvili
90062a9914
Support native AIL Abs expressions in light engines (#6683)
* Fix AIL Abs unary operation dispatch

* Fix Abs regression test lint
2026-07-24 00:43:03 -07:00
Yan Shoshitaishvili
fe434a049b
Decompiler: reject float constants in string simplifiers (#6682)
* Decompiler: reject float constants in string simplifiers

* Tests: allow private simplifier coverage
2026-07-24 00:28:36 -07:00
Yan Shoshitaishvili
208ec719a6
Decompiler: disambiguate Extract condition placeholders (#6677) 2026-07-23 22:33:21 -07:00
Yan Shoshitaishvili
8b98c5ad6c
Keep eager evaluation integer-only (#6681) 2026-07-23 22:30:15 -07:00