Vector35 / binaryninja-api

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

Support for bitwise data structures #694

Open psifertex opened 7 years ago

psifertex commented 7 years ago

Need support for bitwise data structures.

joshwatson commented 6 years ago

Should probably change the title of this to be more explanatory

benjaminmordaunt commented 1 year ago

Trying to define a structure like:

struct sha_dma_config __packed
{
  union {
    uint32_t cfg;
    struct {
      uint32_t len : 17;
      ...
    }
}

... turns into whatever this is:

struct sha_dma_config __packed
{
    union
    {
        uint32_t cfg;
        struct
        {
            union
            {
                uint8_t len;
            } bitfield_0;
            union
            {
                uint8_t len;
            } bitfield_1;
            union
            {
                uint8_t len;
                uint8_t irq;
                uint8_t eod;
                uint8_t loop;
                uint8_t mode;
            } bitfield_2;
            union
            {
                uint8_t begin;
                uint8_t end;
                uint8_t op;
                uint8_t unk0;
                uint8_t enconly;
                uint8_t block;
                uint8_t err;
                uint8_t owner;
            } bitfield_3;
        };
    };
};

which doesn't appear to be equivalent in any meaningful way. Binary Ninja should really warn that it can't handle this instead of just going along with it and ruining type annotation in my pseudo-C. :-1:

Also, I'm surprised this doesn't have more support. Kind of necessary to produce readable abstractions based on bitfield/tightly packed structures.

vergil-SI commented 1 year ago

Agreed with @benjaminmordaunt. The current solution for this is not very helpful. Having a single named union to represent sometimes 16+ different bits worth of data provides very little context, but can still clutter the decompilation view. Can be a very frustrating experience when I run into bitfield packed structs in Binja.

bmuessig commented 1 year ago

I agree that it would be great if bitfields could be supported completely and be displayed more clearly