"Fixed" Structures exporting problem

Hi, I feel there is a significant bug in exporting (to c) “fixed-size” structures:

  1. The size itself isn’t exported
  2. The alignment isn’t exported
  3. “padding bytes” inside aren’t exported

Experiment 1

created fixed-size struct “struct_test” in size 0x2a:

00000000 struct __fixed struct_test // sizeof=0x2A
00000000 {
00000000 __int16 field_0;
00000002 __int16 field_2;
00000004 char field_4;
00000005 char field_5;
00000006 char field_6;
00000007 int field_7;
0000000B __int16 field_B;
0000000D char field_D;
0000000E char field_E;
0000000F char field_F;
00000010 char field_10;
00000011 char field_11;
00000012 char field_12;
00000013 char field_13;
00000014 // padding byte
00000015 // padding byte
00000016 char field_16;
00000017 char field_17;
00000018 char field_18;
00000019 int field_19;
0000001D // padding byte
0000001E __int64 field_1E;
00000026 __int16 field_26;
00000028 char field_28;
00000029 // padding byte
0000002A };

When I export it to .h it looks:

struct __fixed struct_test
{ 
  __int16 field_0;
  __int16 field_2;
  char field_4;
  char field_5;
  char field_6;
  int field_7;
  __int16 field_B;
  char field_D;
  char field_E;
  char field_F;
  char field_10;
  char field_11;
  char field_12;
  char field_13;
  char field_16;
  char field_17;
  char field_18;
  int field_19;
  __int64 field_1E;
  __int16 field_26;
  char field_28;
};

And When I actually import it to IDA it looks:

00000000 struct struct_test // sizeof=0x30
00000000 {
00000000     __int16 field_0;
00000002     __int16 field_2;
00000004     char field_4;
00000005     char field_5;
00000006     char field_6;
00000007     // padding byte
00000008     int field_7;
0000000C     __int16 field_B;
0000000E     char field_D;
0000000F     char field_E;
00000010     char field_F;
00000011     char field_10;
00000012     char field_11;
00000013     char field_12;
00000014     char field_13;
00000015     char field_16;
00000016     char field_17;
00000017     char field_18;
00000018     int field_19;
0000001C     // padding byte
0000001D     // padding byte
0000001E     // padding byte
0000001F     // padding byte
00000020     __int64 field_1E;
00000028     __int16 field_26;
0000002A     char field_28;
0000002B     // padding byte
0000002C     // padding byte
0000002D     // padding byte
0000002E     // padding byte
0000002F     // padding byte
00000030 };

I work a lot with those fixed-size structure and now when I tried to share with colleagues some header files the IDBs getting messed up :frowning:

Would be glad if you could fix it soon, Please.

Regards, Uriel

Thank you for the report! I would suggest two workarounds:

  1. for important structures, turn off the “Fixed layout” flag and make sure the layout is still correct (e.g. add explicit padding members or alignment).
  2. use File > Produce file > Export typeinfo to IDC instead of header export. This uses low level API which should retain all struct attributes.

Thank you for the workarounds, I’ll use them in the meantime.

For the long term I’d really love to use the fixed-layout (great feature!), and I still prefer to export as (c) because I use the LabSync plugin which is much user-friendly this way. Do you have any estimation when it will be fixed?

We need to invent a way to represent fixed structures in C/C++, and more importantly, teach clang to support them. I’m not sure if it is possible to give you an estimate of the work needed for that.

perhaps LabSync can be modified to use the low-level APIs for fixed structs (or even all types)? We’ll be happy to help the maintainers in this task.

Well I’m not LabSync maintainer but I guess it’s a change that can be done, although I can see why it’s a great bonus to have your local types history backed up in a Git repo

Thank you.