From 14996956ead5daf127e005f6624b316bf8ff41a2 Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Mon, 3 Nov 2025 12:42:26 +0000 Subject: [PATCH] binja: fix lints --- capa/features/extractors/binja/file.py | 3 +-- capa/features/extractors/binja/helpers.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/capa/features/extractors/binja/file.py b/capa/features/extractors/binja/file.py index 27fee628..02355c5f 100644 --- a/capa/features/extractors/binja/file.py +++ b/capa/features/extractors/binja/file.py @@ -32,8 +32,7 @@ from capa.features.common import ( Characteristic, ) from capa.features.address import NO_ADDRESS, Address, FileOffsetAddress, AbsoluteVirtualAddress -from capa.features.extractors.binja.helpers import read_c_string, unmangle_c_name -from capa.features.extractors.binja.helpers import va_to_file_offset +from capa.features.extractors.binja.helpers import read_c_string, unmangle_c_name, va_to_file_offset def check_segment_for_pe(bv: BinaryView, seg: Segment) -> Iterator[tuple[Feature, Address]]: diff --git a/capa/features/extractors/binja/helpers.py b/capa/features/extractors/binja/helpers.py index 12cff91f..49e50a87 100644 --- a/capa/features/extractors/binja/helpers.py +++ b/capa/features/extractors/binja/helpers.py @@ -95,7 +95,8 @@ def va_to_file_offset(bv: BinaryView, va: int) -> int: file_offset = segment.data_offset + (va - segment.start) - If no containing segment/section is found, this function raises a `RuntimeError`. + If no containing segment/section is found, fall back to returning the + given virtual address as an integer. """ # prefer segments (they map ranges of the file view) for seg in bv.segments: @@ -107,6 +108,5 @@ def va_to_file_offset(bv: BinaryView, va: int) -> int: if sec.start <= va < sec.start + sec.length: return int(sec.data_offset + (va - sec.start)) - # If we cannot map the VA to a file offset via segments or sections, raise. - # This enforces strict mapping so callers must handle missing mappings explicitly. - raise RuntimeError(f"unable to map virtual address to file offset: 0x{va:x}") + # fallback + return int(va)