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

`typedef` types can get lost in type propagation

Open alexrp opened this issue 2 years ago • 2 comments

Version and Platform (required):

  • Binary Ninja Version: 3.5.4430-dev Personal (79725014)
  • OS: Windows
  • OS Version: 10.0.23511.1000
  • CPU Architecture: x64

Bug Description: I like to define typedefs for primitive types when they represent something special, such as the ID of a game object, or a Boolean, or whatever:

typedef int64_t S1GameId;
typedef uint32_t BOOL;

Unfortunately, BN's type propagation sometimes loses the typedef and just propagates the underlying type. This happens basically all the time for structure fields, for example; if I have a field typed as BOOL, then local variables typed according to the field become uint32_t.

I vaguely recall other situations where the typedef seemed to have been lost, but I can't recall exactly when. In any case, structure fields is the big one here.

Steps To Reproduce: Define a typedef, a structure with a field typed as that typedef, and observe the type propagation behavior.

Expected Behavior: The typedef type should propagate instead of the underlying type.

alexrp avatar Aug 08 '23 05:08 alexrp

I guess it's bit worse now, as typedef info is lost for types even it is not within any structures, but for type in general: image.png

This issue even makes some features from objc workflow (ObjectiveNinja) useless. For example: workflow trying to customise rendering of relative offsets which is actually just a typedefs to ints, thus linked code never pass the comparison as this types hasn't any names.

mostobriv avatar Jun 01 '24 11:06 mostobriv

Wanted to upvote this issue, as I'm triggering it in BinSync as well:

  1. Manually make a typedef: typedef int my_int;
  2. Grab it in the Python API:
>>> typedef = bv.types["my_int"]
>>> type(typedef)
<class 'binaryninja.types.IntegerType'>

Any info that this was a typedef is lost. registered_name is None as well.

mahaloz avatar Aug 04 '24 19:08 mahaloz