binja: fix lints

This commit is contained in:
Willi Ballenthin
2025-11-03 12:42:26 +00:00
parent 2ce7c6a388
commit 14996956ea
2 changed files with 5 additions and 6 deletions
+1 -2
View File
@@ -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]]:
+4 -4
View File
@@ -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)