1
0
mirror of https://github.com/angr/angr synced 2026-06-08 13:09:39 +00:00
Files
angr-angr/tests/sim/test_state_customization.py
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

56 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
from __future__ import annotations
__package__ = __package__ or "tests.sim" # pylint:disable=redefined-builtin
import glob
import os
import unittest
import angr
from tests.common import bin_location
test_location = os.path.join(bin_location, "tests")
class TestStateCustomization(unittest.TestCase):
def test_stack_end(self):
for fn in glob.glob(os.path.join(test_location, "*", "fauxware")):
p = angr.Project(fn, auto_load_libs=False)
# normal state
s = p.factory.full_init_state()
offset = s.solver.eval(p.arch.initial_sp - s.regs.sp)
# different stack ends
for n in [0x1337000, 0xBAAAAA00, 0x100, 0xFFFFFF00, 0x13371337000, 0xBAAAAAAA0000, 0xFFFFFFFFFFFFFF00]:
if n.bit_length() > p.arch.bits:
continue
s = p.factory.full_init_state(stack_end=n)
assert s.solver.eval_one(s.regs.sp + offset == n)
def test_execstack(self):
bin_path = os.path.join(test_location, "x86_64", "fauxware")
proj = angr.Project(bin_path, auto_load_libs=False)
# manually mark the stack as executable
proj.loader.main_object.execstack = True
s = proj.factory.blank_state()
assert s.memory._stack_perms == 7
def test_brk(self):
for fn in glob.glob(os.path.join(test_location, "*", "fauxware")):
p = angr.Project(fn, auto_load_libs=False)
# different stack ends
for n in [0x1337000, 0xBAAAAA00, 0x100, 0xFFFFFF00, 0x13371337000, 0xBAAAAAAA0000, 0xFFFFFFFFFFFFFF00]:
if n.bit_length() > p.arch.bits:
continue
s = p.factory.full_init_state(brk=n)
assert s.solver.eval_one(s.posix.brk == n)
if __name__ == "__main__":
unittest.main()