Previosuly, we’ve covered creating structures from C code using the Local Types window, however this may be not very convenient when you have complex types with many dependencies (especially of scattered over several fiels or depending on preprocessor defines). In such case it may be nore convenient to parse the original header file(s) on disk.
Parsing header files
If you happen to have the types you need in a header file, you can try using IDA’s built-in C parser via the File > Load file > Parse C header file… (shortcut Ctrl+F9).
Just like a compiler, IDA will handle the preprocessor directives (
#ifdef and so on), and add any types discovered to the Local Types list, from where they can be used in the decompiler (or the disassembly, after importing into the IDB).
Setting compiler options
IDA’s built-in parser can mimic several popular compilers, including Visual C++, GCC (and compatibles), Borland C++ Builder, or Watcom. For many stuctured files the compiler is preset to a detected or guessed value, but you can also change or set it via Options > Compiler… dialog:
In this dialog you can also adjust settings necessary for the preprocessing step, such as the predefined preprocessor macros (
#defines) or the include paths for the
#include directives. They are pre-filled from the
CC_PARMS setting in
The built-in parser is quite basic and handles mostly simple C syntax or very basic C++ (e.g templates are not supported). If you have complex files employing new, modern C or C++ features, you may have more luck using the Clang-based parser added in IDA 7.7. It can be selected in the Source parser dropdown of the compiler options dialog and will be used next time you invoke the Parse C header file command. For the details on using it, see the dedicated IDAClang tutorial.