0

Suppose we have the following C source:

typedef struct {
  int bit0 : 1;
  int bit1 : 1;
  int bit2 : 1;
  int bit3 : 1;
} bit_struct;

bit_struct a;

void setBit3()
{
  a.bit3 = 1;
}

When we compile it and open the result in Ghidra, the decompilation window shows

void setBit3(void)
{
  a = a | 8;
  return;
}

If we give Ghidra the declaration of bit_struct (using File -> Parse C Source), and then go to the location of a and set its data type to bit_struct, the decompilation changes to

a = (bit_struct)((byte)a | 8);

which still doesn't access bit3 by declared name.

How can we make Ghidra properly decompile it?

0

Looks like full bitfield support for the decompiler is slated for a future release according to a comment on Ghidra's github issues: Bitfields don't seem to decompile very well #1059

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.