Skip to content

Commit 688841f

Browse files
xusheng6williballenthin
authored andcommitted
binja: fix crash when the IL of certain functions are not available. #2249
1 parent 2a6ba62 commit 688841f

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- IDA Pro: rename ida to idapro module for plugin and idalib in IDA 9.0 #2453 @mr-tz
2929
- ghidra: fix saving of base address @mr-tz
3030
- binja: support loading raw x86/x86_64 shellcode #2489 @xusheng6
31+
- binja: fix crash when the IL of certain functions are not available. #2249 @xusheng6
3132

3233
### capa Explorer Web
3334

capa/features/extractors/binja/extractor.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Iterator
99

1010
import binaryninja as binja
11+
from binaryninja import ILException
1112

1213
import capa.features.extractors.elf
1314
import capa.features.extractors.binja.file
@@ -55,7 +56,15 @@ def get_basic_blocks(self, fh: FunctionHandle) -> Iterator[BBHandle]:
5556
f: binja.Function = fh.inner
5657
# Set up a MLIL basic block dict look up to associate the disassembly basic block with its MLIL basic block
5758
mlil_lookup = {}
58-
for mlil_bb in f.mlil.basic_blocks:
59+
try:
60+
mlil = f.mlil
61+
except ILException:
62+
return
63+
64+
if mlil is None:
65+
return
66+
67+
for mlil_bb in mlil.basic_blocks:
5968
mlil_lookup[mlil_bb.source_block.start] = mlil_bb
6069

6170
for bb in f.basic_blocks:

capa/features/extractors/binja/function.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# See the License for the specific language governing permissions and limitations under the License.
88
from typing import Iterator
99

10-
from binaryninja import Function, BinaryView, SymbolType, RegisterValueType, LowLevelILOperation
10+
from binaryninja import Function, BinaryView, SymbolType, ILException, RegisterValueType, LowLevelILOperation
1111

1212
from capa.features.file import FunctionName
1313
from capa.features.common import Feature, Characteristic
@@ -24,7 +24,14 @@ def extract_function_calls_to(fh: FunctionHandle):
2424
# Everything that is a code reference to the current function is considered a caller, which actually includes
2525
# many other references that are NOT a caller. For example, an instruction `push function_start` will also be
2626
# considered a caller to the function
27-
llil = caller.llil
27+
llil = None
28+
try:
29+
# Temporary fix for https://github.com/Vector35/binaryninja-api/issues/6020. Since `.llil` can throw an
30+
# exception rather than returning None
31+
llil = caller.llil
32+
except ILException:
33+
continue
34+
2835
if (llil is None) or llil.operation not in [
2936
LowLevelILOperation.LLIL_CALL,
3037
LowLevelILOperation.LLIL_CALL_STACK_ADJUST,

capa/features/extractors/binja/insn.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
BinaryView,
1414
ILRegister,
1515
SymbolType,
16+
ILException,
1617
BinaryReader,
1718
RegisterValueType,
1819
LowLevelILOperation,
@@ -43,7 +44,15 @@ def is_stub_function(bv: BinaryView, addr: int) -> Optional[int]:
4344

4445
call_count = 0
4546
call_target = None
46-
for il in func.llil.instructions:
47+
try:
48+
llil = func.llil
49+
except ILException:
50+
return None
51+
52+
if llil is None:
53+
continue
54+
55+
for il in llil.instructions:
4756
if il.operation in [
4857
LowLevelILOperation.LLIL_CALL,
4958
LowLevelILOperation.LLIL_CALL_STACK_ADJUST,

0 commit comments

Comments
 (0)