Skip to content

Commit

Permalink
Merge pull request #19 from quarkslab/add_bb_len
Browse files Browse the repository at this point in the history
Add Basic Block __len__
  • Loading branch information
RobinDavid authored Apr 24, 2024
2 parents b6ba134 + 0d79f5e commit c38e585
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/binexport/basic_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(

self.addr: Addr = None #: basic bloc address
self.bytes = b"" #: bytes of the basic block
self._len = 0 #: Length of the basic block (number of instructions)

# Ranges are in fact the true basic blocks but BinExport
# doesn't have the same basic block semantic and merge multiple basic blocks into one.
Expand All @@ -46,6 +47,7 @@ def __init__(
for rng in pb_bb.instruction_index:
for idx in instruction_index_range(rng):
self.bytes += self.program.proto.instruction[idx].raw_bytes
self._len += 1

# The first instruction determines the basic block address
if self.addr is None:
Expand All @@ -65,6 +67,9 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return "<%s:0x%x>" % (type(self).__name__, self.addr)

def __len__(self) -> int:
return self._len

@property
def program(self) -> ProgramBinExport:
"""
Expand Down

0 comments on commit c38e585

Please sign in to comment.