Skip to content

Commit 979515f

Browse files
committed
Don't yield None in BinaryView hlil|mlil_functions
1 parent f373878 commit 979515f

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

python/binaryview.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,15 +2998,13 @@ def llil_basic_blocks(self) -> Generator['lowlevelil.LowLevelILBasicBlock', None
29982998
def mlil_basic_blocks(self) -> Generator['mediumlevelil.MediumLevelILBasicBlock', None, None]:
29992999
"""A generator of all MediumLevelILBasicBlock objects in the BinaryView"""
30003000
for func in self.mlil_functions():
3001-
if func is not None:
3002-
yield from func.basic_blocks
3001+
yield from func.basic_blocks
30033002

30043003
@property
30053004
def hlil_basic_blocks(self) -> Generator['highlevelil.HighLevelILBasicBlock', None, None]:
30063005
"""A generator of all HighLevelILBasicBlock objects in the BinaryView"""
30073006
for func in self.hlil_functions():
3008-
if func is not None:
3009-
yield from func.basic_blocks
3007+
yield from func.basic_blocks
30103008

30113009
@property
30123010
def instructions(self) -> InstructionsType:
@@ -3195,7 +3193,9 @@ def mlil_functions(
31953193
for func in AdvancedILFunctionList(
31963194
self, self.preload_limit if preload_limit is None else preload_limit, function_generator
31973195
):
3198-
yield func.mlil
3196+
mlil = func.mlil
3197+
if mlil is not None:
3198+
yield mlil
31993199

32003200
def hlil_functions(
32013201
self, preload_limit: Optional[int] = None,
@@ -3208,7 +3208,9 @@ def hlil_functions(
32083208
for func in AdvancedILFunctionList(
32093209
self, self.preload_limit if preload_limit is None else preload_limit, function_generator
32103210
):
3211-
yield func.hlil
3211+
hlil = func.hlil
3212+
if hlil is not None:
3213+
yield hlil
32123214

32133215
@property
32143216
def has_functions(self) -> bool:

python/function.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,13 +1549,21 @@ def comment(self, comment: str) -> None:
15491549
@property
15501550
def llil_basic_blocks(self) -> Generator['lowlevelil.LowLevelILBasicBlock', None, None]:
15511551
"""A generator of all LowLevelILBasicBlock objects in the current function"""
1552-
for block in self.llil:
1552+
llil = self.llil
1553+
if llil is None:
1554+
return
1555+
1556+
for block in llil:
15531557
yield block
15541558

15551559
@property
15561560
def mlil_basic_blocks(self) -> Generator['mediumlevelil.MediumLevelILBasicBlock', None, None]:
15571561
"""A generator of all MediumLevelILBasicBlock objects in the current function"""
1558-
for block in self.mlil:
1562+
mlil = self.mlil
1563+
if mlil is None:
1564+
return
1565+
1566+
for block in mlil:
15591567
yield block
15601568

15611569
@property
@@ -1883,6 +1891,10 @@ def get_llils_at(self, addr: int,
18831891
>>> func.get_llils_at(func.start)
18841892
[<il: push(rbp)>]
18851893
"""
1894+
llil = self.llil
1895+
if llil is None:
1896+
return []
1897+
18861898
if arch is None:
18871899
arch = self.arch
18881900
count = ctypes.c_ulonglong()
@@ -1891,7 +1903,7 @@ def get_llils_at(self, addr: int,
18911903
try:
18921904
result = []
18931905
for i in range(0, count.value):
1894-
result.append(self.llil[instrs[i]])
1906+
result.append(llil[instrs[i]])
18951907
return result
18961908
finally:
18971909
core.BNFreeILInstructionList(instrs)

0 commit comments

Comments
 (0)