Commit graph

26 commits

Author SHA1 Message Date
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
Kevin Phoenix
f939c5b88c
Enable ruff isort rule (#6452)
* Enable ruff isort rule

* [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-06-02 14:48:07 -07:00
Matt Borgerson
6029bb193c pcode: Update riscv test language id 2026-05-21 14:57:35 -07:00
huyi51462
a7ca0201ba
fix(engines): use Ijk_FakeRet instead of Ijk_Ret in CALLLESS mode (#6365)
When CALLLESS option is enabled, the engine skips function calls by
converting Ijk_Call successors to simulate an immediate return. Previously
this was done by setting jumpkind to Ijk_Ret, which caused
CFGEmulated._update_function_transition_graph to treat it as a real
cross-function return, invoking _add_return_from instead of _add_fakeret_to.

As a result, em_ret.graph remained correct (since _graph_add_edge is
jumpkind-agnostic), but function.graph was broken: call blocks had no
predecessors or successors, making function.graph inconsistent with
em_ret.graph.

Fix by changing the jumpkind from Ijk_Ret to Ijk_FakeRet in both
heavy.py and engine.py. This matches the true semantic intent of
CALLLESS — "assume the function returns, continue after the call site"
— and causes _update_function_transition_graph to invoke _add_fakeret_to,
correctly building intra-function edges in function.graph.

Affected files:
  - angr/engines/vex/heavy/heavy.py
  - angr/engines/engine.py
2026-04-24 09:08:31 -07:00
Fish
78799acd95
CFGModel: Spilling CFG nodes to RtDb. (#6092)
* Preliminary implementation of a spilling CFG graph.

* Fix some test cases.

* Fix another test case.

* Fixes.

* Lint code.

* Implement InEdgeView and OutEdgeView.

* Implement InDegreeView and OutDegreeView.

* Fixes.

* Use (Node.addr, Node.size) as key.

* Fix test cases.

* More fixes.

* Fix CFGENode support.

* Fix the remaining issues.

* Get rid of SpillingCFGGraph.reverse().

* Some refactoring.

* Oops

* Fix perf issue.

* Fix set size change error during key iteration.

* Fix db_batch_size assignment. Fix some test cases.

* SpillingCFGNodeDict.__setstate__: Initialize self._all_keys.

* Getting rid of the nodes dictionary.

* Fix logic in cfg_emulated.py

* Multiple fixes.

* Type annotation fix.

* Fix missing edges after merging CFGNodes.

* Fix more logic.

* Add Soot CFGNodes to the CFG model.

* Lint and type check.

* Add USE_SPILLING_CFGNODE_DICT and CFGNode.dirty.

* Oops

* Lint code.

* No more pickling of CFGNodes.

* Fix no_ret being None.

* Lint code.

* Some refactor; Destroy the fallback mechanism.

* Fix node dirty bug after deserialization.
2026-02-24 09:40:02 -07:00
Kevin Phoenix
86ca60014a
Remove conditional imports for hard dependencies in tests (#6077)
* Remove conditional imports for hard dependencies in tests

* Improve lint
2026-01-30 14:55:19 -07:00
pre-commit-ci[bot]
563fb5f862
[pre-commit.ci] pre-commit autoupdate (#6025)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.14.11 → v0.14.13](https://github.com/astral-sh/ruff-pre-commit/compare/v0.14.11...v0.14.13)
- [github.com/psf/black-pre-commit-mirror: 25.12.0 → 26.1.0](https://github.com/psf/black-pre-commit-mirror/compare/25.12.0...26.1.0)

* [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-01-19 13:37:06 -07:00
Christoph Jung
cc291cf169
pcode engine: zero extend in OpBehaviorIntRight (#5741)
* zero extend in OpBehaviorIntRight

* [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>
2025-10-22 10:35:53 -07:00
Kevin Phoenix
e55cefabdc
Make pypcode required (#5471)
* Make pypcode required

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

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

* whoops

* Double whoops

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-19 09:38:17 -04:00
pre-commit-ci[bot]
efecbf7255
[pre-commit.ci] pre-commit autoupdate (#5242)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.3 → v0.9.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.3...v0.9.4)
- [github.com/psf/black: 24.10.0 → 25.1.0](https://github.com/psf/black/compare/24.10.0...25.1.0)

* [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>
2025-02-03 11:41:49 -07:00
aheinric
6e7d1aa978
Allow pcode syscalls (#5176)
* Altered pcode emulator to take fallthrough jumpkind from IRSB

Previously, this assumed the jumpkind would be "Ijk_Boring";
a good assumption, since that's what pcode always generates.

However, this made it impossible for analyses
to rewrite an IRSB to introduce behavior not modeled by pcode;
for example, syscalls.

* Made it possible to syscall without ip_at_syscall

Pcode-based architectures don't have an ip_at_syscall register,
so existing code would raise an exception if you tried to force one.

Altered code just warns that you may run into problems
on such an architecture.  Test your syscall handlers
before your rely on them.

* Added missing field to Pcode test mock

* Fixed linter errors

* Fixed whitespace
2025-01-13 11:03:41 -07:00
Audrey Dutcher
2f61708d4a
Typecheck more things (#5061)
All engines that angr decompiler uses are now type checked.

---------

Co-authored-by: Fish <fishw@asu.edu>
2024-12-12 01:06:30 -07:00
Kevin Phoenix
0972e6b5c9
Remove backend references in test cases (#4825)
* Remove backend references in test cases

* Call eval first before checking is_true

* Improve lint
2024-09-08 14:10:15 -07:00
Kevin Phoenix
feda6f6909
Apply ruff SIM lints (#4793)
* Apply SIM lints

* Fix some failing tests

* Fix more bugs
2024-08-29 16:56:53 -07:00
Kevin Phoenix
ee464d0338
Adopt from __future__ import annotations (#4790) 2024-08-28 18:31:43 -07:00
Matt Borgerson
537aeaafed pcode: Implement new lzcount op 2024-05-08 14:36:11 -07:00
mborgerson
40ee68b637
Bump min Python to 3.10 (#4621)
* Bump min Python to 3.10

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

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

* Remove broken docs run

* Satisfy ruff

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kevin Phoenix <kevin@kphoenix.us>
2024-05-07 20:55:00 -07:00
Kevin Phoenix
3233d7e8af
Fix pcode test_emulate erroring if pcode is not installed (#4415) 2024-01-11 18:31:11 -07:00
Matt Borgerson
dbdfcc3b84 pcode: Update to new pypcode API 2024-01-10 15:19:12 -07:00
Matt Borgerson
883f08fcd8 tests: Fixup shebangs, main functions, and mark tests executable 2023-09-07 18:46:00 -07:00
Matt Borgerson
0b5742d507 pcode: Update test_pcode.py ArchPcode generation 2023-01-25 18:43:07 -07:00
Matt Borgerson
454da0a608 pcode: Migrate ArchPcode generation to archinfo 2023-01-25 18:43:07 -07:00
zwimer
346b2d883d black 2023-01-12 16:43:51 -07:00
Zachary Wimer
415508a997
Skip tests if a dependency is missing rather than failing them (#3568)
* Skip tests if a dependency is missing rather than failing them

* Linter fixes

* Fix typo

* Revert do_trace but raise unittest.SkipTest instead of generic exception

Co-authored-by: Kevin Phoenix <kevin@kphoenix.us>
2022-10-14 16:11:21 -07:00
mborgerson
cfafb919fe
tests: Add missing __init__.py files for test discovery (#3498)
* tests: Add missing __init__.py files

* Environment::merge: Add back other environment type check

* TestEnvironment: Fix merge() rval unpacking

* TestLiveDefinitons: Fix merge() rval unpacking

* LiveDefinitions::get_sp: Don't filter out 0 values
2022-08-29 23:10:42 -07:00
Matt Borgerson
4f5802ae09 pcode: Add a couple sanity check test cases 2022-03-29 22:53:50 -07:00