mirror of
https://github.com/mandiant/capa.git
synced 2026-07-28 22:50:59 -07:00
binja: fix lints
This commit is contained in:
@@ -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]]:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user