Skip to content

Commit

Permalink
Add a generic tester for all dec CI (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz authored Jan 27, 2024
1 parent c2039e9 commit 033f570
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@
import os

from libbs.api import DecompilerInterface
from libbs.decompilers import IDA_DECOMPILER, ANGR_DECOMPILER, BINJA_DECOMPILER, GHIDRA_DECOMPILER

GHIDRA_HEADLESS_PATH = Path(os.environ.get('GHIDRA_HEADLESS_PATH'))
GHIDRA_HEADLESS_PATH = Path(os.environ.get('GHIDRA_HEADLESS_PATH', ""))
IDA_HEADLESS_PATH = Path(os.environ.get('IDA_HEADLESS_PATH', ""))
TEST_BINARY_DIR = Path(__file__).parent / "binaries"
DEC_TO_HEADLESS = {
IDA_DECOMPILER: IDA_HEADLESS_PATH,
GHIDRA_DECOMPILER: GHIDRA_HEADLESS_PATH,
ANGR_DECOMPILER: None,
BINJA_DECOMPILER: None,
}


class TestHeadlessInterfaces(unittest.TestCase):
def test_ghidra(self):
fauxware_path = TEST_BINARY_DIR / "fauxware"
deci = DecompilerInterface.discover(
force_decompiler="ghidra",
headless=True,
headless_dec_path=GHIDRA_HEADLESS_PATH,
binary_path=fauxware_path
)
main = deci.functions[0x400664]
main.name = "binsync_main"
deci.functions[0x400664] = main
assert deci.functions[0x400664].name == "binsync_main"
deci.shutdown()
def setUp(self):
self._generic_renamed_name = "binsync_main"

def test_angr(self):
def _generic_decompiler_test(self, decompiler):
fauxware_path = TEST_BINARY_DIR / "fauxware"
deci = DecompilerInterface.discover(
force_decompiler="angr",
force_decompiler=decompiler,
headless=True,
headless_dec_path=DEC_TO_HEADLESS[decompiler],
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
main.name = self._generic_renamed_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]
assert deci.functions[func_addr].name == self._generic_renamed_name

return deci

def test_ghidra(self):
deci = self._generic_decompiler_test(decompiler=GHIDRA_DECOMPILER)
deci.shutdown()

def test_angr(self):
deci = self._generic_decompiler_test(decompiler=ANGR_DECOMPILER)
assert self._generic_renamed_name in deci.main_instance.project.kb.functions

0 comments on commit 033f570

Please sign in to comment.