9

I defined a struct in a header file, similar to this one:

struct STRUCT
{
    char a;
    int b;
};

This is parsed successfully by IDA, however it adds padding bytes after the char:

00000000 STRUCT          struc ; (sizeof=0x4)
00000000 a               db ?
00000001                 db ? ; undefined
00000002 b               dw ?
00000004 STRUCT          ends

I can't remove the padding field using u, so the question is: How can one remove padding fields automatically inserted by IDA, or how can one prevent IDA from creating padding fields?

heinrich5991
  • 627
  • 11
  • 21

2 Answers2

13

You can use #pragma pack(1) before the declaration.

Igor Skochinsky
  • 36,553
  • 7
  • 65
  • 115
9

removing undefined byte

click on an undefined padding byte, then with Shrink struct (right-click menu, or Ctrl-S), choose how many bytes you want to remove - it automatically sets the right amount to the next defined offset.

preventing auto add

It depends on the parameter in the Options/Compiler menu: Change the default alignment to 1 to remove padding, then import your header

Ange
  • 6,694
  • 3
  • 28
  • 62