Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binja: fix up analysis for the al-khaser_x64.exe_ file #2522

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- binja: fix crash when the IL of certain functions are not available. #2249 @xusheng6
- binja: major performance improvement on the binja extractor. #1414 @xusheng6
- cape: make Process model flexible and procmemory optional to load newest reports #2466 @mr-tz
- binja: fix unit test failure by fixing up the analysis for file al-khaser_x64.exe_ #2507 @xusheng6

### capa Explorer Web

Expand Down
11 changes: 6 additions & 5 deletions capa/features/extractors/binja/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ def is_stub_function(bv: BinaryView, addr: int) -> Optional[int]:
]:
return None

if llil.dest.value.type not in [
RegisterValueType.ImportedAddressValue,
RegisterValueType.ConstantValue,
RegisterValueType.ConstantPointerValue,
# The LLIL instruction retrieved by `get_llil_instr_at_addr` did not go through a full analysis, so we cannot check
# `llil.dest.value.type` here
if llil.dest.operation not in [
LowLevelILOperation.LLIL_CONST,
LowLevelILOperation.LLIL_CONST_PTR,
]:
return None

return llil.dest.value.value
return llil.dest.constant


def extract_insn_api_features(fh: FunctionHandle, bbh: BBHandle, ih: InsnHandle) -> Iterator[tuple[Feature, Address]]:
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ def get_binja_extractor(path: Path):
if path.name.endswith("kernel32-64.dll_"):
settings.set_bool("pdb.loadGlobalSymbols", old_pdb)

# TODO(xusheng6): Temporary fix for https://github.com/mandiant/capa/issues/2507. Remove this once it is fixed in
# binja
if "al-khaser_x64.exe_" in path.name:
bv.create_user_function(0x14004B4F0)
bv.update_analysis_and_wait()

extractor = capa.features.extractors.binja.extractor.BinjaFeatureExtractor(bv)

# overload the extractor so that the fixture exposes `extractor.path`
Expand Down
4 changes: 0 additions & 4 deletions tests/test_binja_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
indirect=["sample", "scope"],
)
def test_binja_features(sample, scope, feature, expected):
# TODO(mr-tz): BinaryNinja does not recognize this function
# https://github.com/mandiant/capa/issues/2507
if scope.__name__ == "function=0x14004B4F0":
pytest.xfail("BinaryNinja does not recognize this function")
fixtures.do_test_feature_presence(fixtures.get_binja_extractor, sample, scope, feature, expected)


Expand Down
Loading