From 50afc2f9b204a330f1367e2bf2c6efdd7df901fa Mon Sep 17 00:00:00 2001 From: colton-gabertan Date: Fri, 26 May 2023 17:51:48 -0700 Subject: [PATCH] colton: developing ghidra backend tests --- capa/main.py | 1 + tests/test_ghidra_features.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/test_ghidra_features.py diff --git a/capa/main.py b/capa/main.py index 39a2632a..6d270fc1 100644 --- a/capa/main.py +++ b/capa/main.py @@ -1333,6 +1333,7 @@ def ghidra_main(): globl_features: List[Tuple[Feature, Address]] = [] globl_features.extend(capa.features.extractors.ghidra.global_.extract_os()) + globl_features.extend(capa.features.extractors.ghidra.global_.extract_arch()) print(globl_features) diff --git a/tests/test_ghidra_features.py b/tests/test_ghidra_features.py new file mode 100644 index 00000000..a4a9a748 --- /dev/null +++ b/tests/test_ghidra_features.py @@ -0,0 +1,25 @@ +import logging + +import fixtures +from fixtures import * + +import capa.main + +logger = logging.getLogger(__file__) + +# We need to skip the ghidra test if we cannot import ghidra modules, e.g., in GitHub CI. +ghidra_present: bool = False +try: + import ghidra.program.flatapi as flatapi + ghidraapi = flatapi.FlatProgramAPI(currentProgram) + + try: + current_program_test = ghidraapi.getCurrentProgram() + except RuntimeError as e: + logger.warning("Ghidra runtime not detected") + else: + ghidra_present = True +except ImportError: + pass + +