Skip to content

Commit

Permalink
Add a headless angr CI (#27)
Browse files Browse the repository at this point in the history
* Add a headless angr CI

* Rename tests
  • Loading branch information
mahaloz authored Jan 27, 2024
1 parent 1f83025 commit c2039e9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion libbs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.20.0"
__version__ = "0.21.0"

import logging
logging.getLogger("libbs").addHandler(logging.NullHandler())
Expand Down
7 changes: 4 additions & 3 deletions libbs/api/decompiler_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,4 @@ console_scripts =
[options.extras_require]
test =
pytest
angr-management
pytest-qt

ghidra =
ghidra_bridge
PySide6-Essentials>=6.4.2
angr
22 changes: 19 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]

0 comments on commit c2039e9

Please sign in to comment.