Vector35 / binaryninja-api

Public API, examples, documentation and issues for Binary Ninja
https://binary.ninja/
MIT License
900 stars 204 forks source link

repr of BasicBlock does not show start and end address in hex #4708

Closed xusheng6 closed 10 months ago

xusheng6 commented 11 months ago
>>> current_basic_block
<BasicBlock: x86_64@5368754260-5368754267>
lwerdna commented 10 months ago

This is a simple fix in api/python/basicblock.py:

    def __repr__(self):
        arch = self.arch
        if arch:
            return f"<{self.__class__.__name__}: {arch.name}@{self.start:x}-{self.end:x}>"
        else:
            return f"<{self.__class__.__name__}: {self.start:x}-{self.end:x}>"

Following my best guess at current convention, there is no leading "0x" and the letter characters are lowercase.

Many unit tests change as a result, having stored the decimal representation:

image

The question is: Is everyone in agreement that we should change to hex representation?

xusheng6 commented 10 months ago

This is a simple fix in api/python/basicblock.py:


  def __repr__(self):

      arch = self.arch

      if arch:

          return f"<{self.__class__.__name__}: {arch.name}@{self.start:x}-{self.end:x}>"

      else:

          return f"<{self.__class__.__name__}: {self.start:x}-{self.end:x}>"

Following my best guess at current convention, there is no leading "0x" and the letter characters are lowercase.

Many unit tests change as a result, having stored the decimal representation:

image

The question is: Is everyone in agreement that we should change to hex representation?

We want to keep the address in decimal if it is an IL basic block because we use decimal for IL index

plafosse commented 10 months ago

As there are subclasses for each BasicBlock type this is simple to fix

xusheng6 commented 10 months ago

Related to https://github.com/Vector35/binaryninja-api/issues/4771