1

I want to retrieve IDA Pro .idb database's each type info, such as:

  • size and name of a structure;
  • each member variable type and name;
  • each member variable size and offset;

And dump it to a .h file in a formatted manner. ("Create C header file..." just dumps without sizes and offsets and does not allow to pre-format it.) How to do this?

1
  • 1
    You can use ida_struct API to retrieve the needed information via Python terminal/plugins
    – mimak
    Commented Sep 8, 2023 at 12:08

1 Answer 1

4

It's obviously doable (you already noted the Create C header file functionality), but if you want to customize the output, you'll have to code it yourself.

Here's what you'll need:

  • ida_typeinf.first_named_type and ida_typeinf.next_named_type to iterate through all of the type names in a TIL (i.e., the main TIL for an IDB).
  • To retrieve a tinfo_t type object from a type name, create tif = ida_typeinf.tinfo_t(), then do tif.get_named_type(name) with the name returned from the functions above.
  • Once you have the tinfo_t tif object, if tif.is_struct() returns True, you can get the structure details via the function tif.get_udt_details by passing it a new ida_typeinf.udt_type_data_t data structure.
  • ida_typeinf.udt_type_data_t is a vector of udt_member_t objects (plus additional information, e.g. size and alignment). Each udt_member_t object describes one field in a struct or union. You can retrieve member names via the .name field, and each field's tinfo_t type via the .type field.

That's all you need. However, if you've never worked with types programmatically before, you're going to find it tricky. It is already evident from the above that tinfo_t is a mutually recursive data structure, i.e., the tinfo_t for a structure contains other data structures (like udt_type_data_t) that themselves contain tinfo_t objects to describe structure field types. Due to the mutual recursion in the data structures, functions involving tinfo_t objects are often mutually recursive.

2
  • Thank you so much for such a detailed answer! I will try this
    – void_17
    Commented Sep 9, 2023 at 15:28
  • Very nice. Thanks for the explanation. It took me like 2 hours to find your answer and only then I managed to understand how I have to walk up the inheritance tree all the classes and also walk all the members of classes.
    – KulaGGin
    Commented Nov 13, 2023 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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