Vector35 / binaryninja-api

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

Tags Are Not Accessible via BinaryView #4501

Open w1282 opened 1 year ago

w1282 commented 1 year ago

Version and Platform (required):

Bug Description: Access to tags via the BinaryView is no longer functioning as expected. bv.tags, bv.get_tags(), and bv.get_tags_at(addr) and the other related methods consistently return [] even when tags exist.

I have confirmed that the bv is not some spurious bv to which tags have not been applied.

Function.tags and other Function methods still recover tags as expected.

Steps To Reproduce: Please provide all steps required to reproduce the behavior:

  1. Create a tag at a location in a function
  2. Execute bv.tags and observe no tag data is returned
  3. Execute current_function.tags and observe tag data is returned as expected

Expected Behavior: All existing tags will be returned via bv.tags

fuzyll commented 1 year ago

I typed out this whole comment on July 19 and then...apparently just left the browser tab open without clicking 'Comment'. Oops!

So, what's happening here is that, under the hood, there are multiple different 'kinds' of tags. When you call bv.tags, Binary Ninja is going to look up all of the data tags and return those to you. But, what you're looking for is a function tag, which belongs to a Function and not a BinaryView. This is why current_function.tags works as expected.

Although this is basically "working as intended", I'm still going to leave this issue open for the time being. I think this is surprising to a user, and we should fix this by either:

  1. Changing the behavior of bv.tags to return all tags (more difficult to do, possible performance issues depending on implementation).
  2. Surfacing the 'kind' of tag, so the user knows which they're looking at, and adding a bunch of documentation to explain how this is intended to work (easier to do, still no easy way to get all tags from the API).
river-li commented 4 months ago

Changing the behavior of bv.tags to return all tags (more difficult to do, possible performance issues depending on implementation).

We have a BNGetAllTagReferences API that hasn't been implemented in Python. It should be pretty easy to solve it in this way, we just need to add a function and let bv.tags return the results from BNGetAllTagReferences.