binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Pointers are created as 64bit

Open RevPanda opened this issue 1 year ago • 4 comments

Pointers are created as 64 bit, instead of the expected 16bit, whether created via the UI with "y" or programmatically like this:

type = self.parse_type_string("void *vector");
self.define_data_var(0x8000, type[0])

RevPanda avatar Apr 14 '24 14:04 RevPanda

Note that creating pointers via the O hotkey (Type>Make Pointer in context menu) will create appropriately sized 16-bit pointers, and that the architecture correctly specifies the address size as 2 bytes:

>>> bv.arch
<arch: 6502>
>>> bv.arch.address_size
2 / 0x2

galenbwill avatar Apr 16 '24 16:04 galenbwill

Unfortunately, the width of pointer types parsed from strings will be 8 bytes due to a couple of factors in the interface to our clang type parser which depends on fixing this issue: https://github.com/Vector35/binaryninja-api/issues/4868

However, it is worth pointing out that this works "correctly" for the arch:

>>> Type.pointer(bv.arch, bv.parse_type_string('void')[0])
<type: immutable:PointerTypeClass 'void*'>
>>> _.width
2 / 0x2

As another workaround, defining or setting a variable in the UI using type void in the dialog, and then letting Binary Ninja turn it into a pointer, results in a proper-width pointer:

https://github.com/Vector35/6502/assets/12259536/b7c9863f-d7ab-49ff-9380-0697eabd9b31

galenbwill avatar Apr 16 '24 19:04 galenbwill

Thanks for the workarounds! Have checked in a change to the module using this.

RevPanda avatar Apr 18 '24 00:04 RevPanda

Couple updates on this from a few weeks ago:

  1. You can now specify custom type parser arguments with the new Platform::AdjustTypeParserInput callback, which you can use to give clang a --target=etc if your target is supported (or if a different, supported target has similar type sizes)
  2. Even if the platform pointers are not the size you expected, you can annotate a differently-sized pointer with the new void* __ptr16 syntax (or custom size with void* __ptr_width(2))

CouleeApps avatar Jun 24 '24 21:06 CouleeApps