Vector35 / Vector35/binaryninja-api
[Bug] xrefs not updating when setting data vars in python
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 298
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 19
Description
Version and Platform (required):
- Binary Ninja Version 5.0.7486
- Edition: Non-Commercial
- OS: Windows 11
- OS Version: 24H2 26100.4349
- CPU Architecture: x86_64
Bug Description:
When setting a type for a datavar in python, the Data References don't get updated in the UI.
Weirdly however, if you set the type to a string containing the name of the type, it does update the UI, however it takes significantly longer to process, which is no good for scripts that are running this hundreds of times.
Even if you force a re-analysis, it doesn't detect the xrefs.
Steps To Reproduce:
- Open a project and pick an offset with undefined bytes to test with.
- Copy the address, and open the python console and paste it in the python below, replacing
offsetwith your own offset`
# set this to whatever address you want to test this in. I did it in a section of undefined bytes.
offset = 0xDEADBEEF
# create a dummy struct
ty = types.StructureBuilder.create(packed=True)
ty.append(Type.int(width=1), "testing")
ty = Type.structure_type(ty)
# define the type as "MyCustomType"
bv.define_user_type("MyCustomType", ty)
# get the type from bv, so that it shows the type name in the UI, instead of the struct layout.
ty = bv.get_type_by_name("MyCustomType")
# set the offset to the type
bv.define_user_data_var(offset, ty)
After running this, the linear view updates to show the new type, e.g. data_100323ea3: MyCustomType
However, if you click on the MyCustomType on that same line, you'll notice the cross references are empty.
If you now run this in the python console:
bv.define_user_data_var(offset, "struct MyCustomType")
and check the cross references again, you'll see that it now appears correctly. The same effect can be done by right clicking the datavar, clicking "change type", don't change anything, and simply press apply
Expected Behavior:
When setting the datavar to a type (the first codeblock), the references should be updated, just like they do when you set the datavar to a string containing the type (the second codeblock)
Screenshots/Video Recording:
https://github.com/user-attachments/assets/0b94b32c-40e7-4260-a274-8bdfa095df00
Binary:
General issue, not binary-specific
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Python API entry point bv.define_user_data_var and reproduce the difference between passing a Type object and a string type name using the supplied script. Trace how each form updates the data variable and references, then verify that the Type-object path produces the same cross references without requiring a second update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api, reverse-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100