Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic Block __len__ #19

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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