Skip to content

Commit 7659bfc

Browse files
committed
Don't yield None in BinaryView hlil|mlil_functions
1 parent 85d31f2 commit 7659bfc

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
@@ -2986,15 +2986,13 @@ def llil_basic_blocks(self) -> Generator['lowlevelil.LowLevelILBasicBlock', None
29862986
def mlil_basic_blocks(self) -> Generator['mediumlevelil.MediumLevelILBasicBlock', None, None]:
29872987
"""A generator of all MediumLevelILBasicBlock objects in the BinaryView"""
29882988
for func in self.mlil_functions():
2989-
if func is not None:
2990-
yield from func.basic_blocks
2989+
yield from func.basic_blocks
29912990

29922991
@property
29932992
def hlil_basic_blocks(self) -> Generator['highlevelil.HighLevelILBasicBlock', None, None]:
29942993
"""A generator of all HighLevelILBasicBlock objects in the BinaryView"""
29952994
for func in self.hlil_functions():
2996-
if func is not None:
2997-
yield from func.basic_blocks
2995+
yield from func.basic_blocks
29982996

29992997
@property
30002998
def instructions(self) -> InstructionsType:
@@ -3183,7 +3181,9 @@ def mlil_functions(
31833181
for func in AdvancedILFunctionList(
31843182
self, self.preload_limit if preload_limit is None else preload_limit, function_generator
31853183
):
3186-
yield func.mlil
3184+
mlil = func.mlil
3185+
if mlil is not None:
3186+
yield mlil
31873187

31883188
def hlil_functions(
31893189
self, preload_limit: Optional[int] = None,
@@ -3196,7 +3196,9 @@ def hlil_functions(
31963196
for func in AdvancedILFunctionList(
31973197
self, self.preload_limit if preload_limit is None else preload_limit, function_generator
31983198
):
3199-
yield func.hlil
3199+
hlil = func.hlil
3200+
if hlil is not None:
3201+
yield hlil
32003202

32013203
@property
32023204
def has_functions(self) -> bool:

python/function.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,13 +1546,21 @@ def comment(self, comment: str) -> None:
15461546
@property
15471547
def llil_basic_blocks(self) -> Generator['lowlevelil.LowLevelILBasicBlock', None, None]:
15481548
"""A generator of all LowLevelILBasicBlock objects in the current function"""
1549-
for block in self.llil:
1549+
llil = self.llil
1550+
if llil is None:
1551+
return
1552+
1553+
for block in llil:
15501554
yield block
15511555

15521556
@property
15531557
def mlil_basic_blocks(self) -> Generator['mediumlevelil.MediumLevelILBasicBlock', None, None]:
15541558
"""A generator of all MediumLevelILBasicBlock objects in the current function"""
1555-
for block in self.mlil:
1559+
mlil = self.mlil
1560+
if mlil is None:
1561+
return
1562+
1563+
for block in mlil:
15561564
yield block
15571565

15581566
@property
@@ -1880,6 +1888,10 @@ def get_llils_at(self, addr: int,
18801888
>>> func.get_llils_at(func.start)
18811889
[<il: push(rbp)>]
18821890
"""
1891+
llil = self.llil
1892+
if llil is None:
1893+
return []
1894+
18831895
if arch is None:
18841896
arch = self.arch
18851897
count = ctypes.c_ulonglong()
@@ -1888,7 +1900,7 @@ def get_llils_at(self, addr: int,
18881900
try:
18891901
result = []
18901902
for i in range(0, count.value):
1891-
result.append(self.llil[instrs[i]])
1903+
result.append(llil[instrs[i]])
18921904
return result
18931905
finally:
18941906
core.BNFreeILInstructionList(instrs)

0 commit comments

Comments
 (0)