From c2039e9b48f9675f242ceb6bfc66d493e9728f14 Mon Sep 17 00:00:00 2001 From: Zion Leonahenahe Basque Date: Sat, 27 Jan 2024 15:45:40 -0700 Subject: [PATCH] Add a headless angr CI (#27) * Add a headless angr CI * Rename tests --- .github/workflows/python-app.yml | 6 ++---- libbs/__init__.py | 2 +- libbs/api/decompiler_interface.py | 7 ++++--- setup.cfg | 7 +------ tests/tests.py | 22 +++++++++++++++++++--- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 7fdf14f5..62df6d4d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Core Tests +name: Headless Dec Tests on: push: @@ -21,9 +21,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest - pip install psutil - pip install . + pip install .[test] - name: Set up Java 17 uses: actions/setup-java@v4 with: diff --git a/libbs/__init__.py b/libbs/__init__.py index 632cc9d9..83f85771 100644 --- a/libbs/__init__.py +++ b/libbs/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.20.0" +__version__ = "0.21.0" import logging logging.getLogger("libbs").addHandler(logging.NullHandler()) diff --git a/libbs/api/decompiler_interface.py b/libbs/api/decompiler_interface.py index dc388189..0ebfc6a5 100644 --- a/libbs/api/decompiler_interface.py +++ b/libbs/api/decompiler_interface.py @@ -583,7 +583,7 @@ def _find_global_in_call_frames(global_name, max_frames=10): return None @staticmethod - def find_current_decompiler() -> Optional[str]: + def find_current_decompiler(forced=False) -> Optional[str]: """ Finds the name of the current decompiler that this function is running inside of. Note, this function does not create an interface, but instead finds the name of the decompiler that is currently running. @@ -625,7 +625,8 @@ def find_current_decompiler() -> Optional[str]: except ImportError: pass - _l.warning("LibBS does not know the current decompiler you are running in... it may not be supported!") + if not forced: + _l.warning("LibBS does not know the current decompiler you are running in... it may not be supported!") return None @staticmethod @@ -645,7 +646,7 @@ def discover( if force_decompiler and force_decompiler not in SUPPORTED_DECOMPILERS: raise ValueError(f"Unsupported decompiler {force_decompiler}") - current_decompiler = DecompilerInterface.find_current_decompiler() + current_decompiler = DecompilerInterface.find_current_decompiler(forced=bool(force_decompiler)) if force_decompiler == IDA_DECOMPILER or current_decompiler == IDA_DECOMPILER: from libbs.decompilers.ida.interface import IDAInterface deci_class = IDAInterface diff --git a/setup.cfg b/setup.cfg index bc8dd4bb..90261f49 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,9 +33,4 @@ console_scripts = [options.extras_require] test = pytest - angr-management - pytest-qt - -ghidra = - ghidra_bridge - PySide6-Essentials>=6.4.2 + angr diff --git a/tests/tests.py b/tests/tests.py index e8a75c34..b27e50be 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -9,7 +9,7 @@ class TestHeadlessInterfaces(unittest.TestCase): - def test_ghidra_interface(self): + def test_ghidra(self): fauxware_path = TEST_BINARY_DIR / "fauxware" deci = DecompilerInterface.discover( force_decompiler="ghidra", @@ -18,7 +18,23 @@ def test_ghidra_interface(self): binary_path=fauxware_path ) main = deci.functions[0x400664] - main.name = "main" + main.name = "binsync_main" deci.functions[0x400664] = main - assert deci.functions[0x400664].name == "main" + assert deci.functions[0x400664].name == "binsync_main" deci.shutdown() + + def test_angr(self): + fauxware_path = TEST_BINARY_DIR / "fauxware" + deci = DecompilerInterface.discover( + force_decompiler="angr", + headless=True, + binary_path=fauxware_path + ) + func_addr = deci.art_lifter.lift_addr(0x400664) + new_name = "binsync_main" + main = deci.functions[func_addr] + main.name = new_name + deci.functions[func_addr] = main + assert deci.functions[func_addr].name == new_name + # good redudancy: verify internal angr sees the change + assert deci.main_instance.project.kb.functions[new_name]