Previously we’ve talked about using type libraries shipped with IDA, but what can be done when dealing with uncommon or custom APIs or SDKs not covered by them?
In such situation it is possible to use the tilib
utility available for IDA Pro users from our download center.
Creating type libraries
tilib
is a powerful command-line utility and the full list of options may look somewhat scary.
Type Information Library Utility v1.227 Copyright (c) 2000-2021 Hex-Rays usage: tilib [-sw] til-file -c create til-file -t... set til-file title -h... parse .h file -P C++ mode (not ready yet) -D... define a symbol -I... list of include dirs -M... create macro defs file -x external display types -i internal display types -z debug .h file parsing (use it!) -B... dump bad macro defs -q internal check: unpack types -C... compiler info(-C? help) -G... mangling format (n=org.name) -m... parse macro defs file -S strip macro table -dt... delete type definition -rtX:Y rename type X as Y -ds... delete symbol definition -rsX:Y rename symbol X as Y -b... use base til -o... directory with til files -l[1csxf] show til-file contents; 1-with decorated names, c-as c code s-dump struct layout, x-exercise udt serialization, f-dump funcarg locations -v verbose -e ignore errors -R allow redeclarations -n ignore til macro table -u+ uncompress til-file -u- compress til-tile -U set 'universal til' bit -em suppress macro creation errors -# enable ordinal types -#- disable ordinal types -p... load types from PDB (Win32) -TL lower existing type -TAL assume low level types -TH keep high types -g[nb]X:Y move macro X (regex) to group Y; n-name, b-body @... response file with switches example: tilib -c -Cc1 -hstdio.h stdio.til
However, as mentioned at the botttom, the basic usage can be quite simple:
tilib -c -Cc1 -hstdio.h stdio.til
This creates a type library stdio.til
by parsing the header file stdio.h
as a Visual C++ compiler.
Advanced options
The sample commandline might work in simple cases (e.g. a single, self-contained header) but with real life SDKs you will likely run into problems quickly. To handle them, additional options may be necessary:
- Include directories for headers from
#include
directives:-I<directory>
(can be specified multiple times); - preprocessor defines:
-Dname[=value]
;
Instead of using -D
on command line, you can also create a new header with #define
statements and include other headers from it.
Response files
To avoid specifying the same options again and again, you can use response files. These files contain one command line option per line and can be passed to tilib
using the @
option:
tilib @vc32.cfg -c -hinput.h output.til
There are sample response files shipped with the tilib package for Visual C++ (32- and 64-bit), GCC and Borland C++.
Examining type libraries
You can dump the contents of a til file using the -l
switch:
tilib -l mylib.til
Using created type libraries in IDA
To make the custom type library available in IDA, copy it in the til/<processor>
subdirectory of IDA. For example, libraries for x86/x64 files should go under til/pc
. After this, the new library should appear in the list shown when you invoke the “Load type library” command.
Advanced example
One of our users made a very nice write-up on generating a type library for Apache modules. Please find it here: https://github.com/trou/apache-module-ida-til.
See also readme.txt in the tilib package for advanced usage such as creating enums from groups of preprocessor macro definitions.