1

How can I load C header file with IDAPython in IDA Pro?

I'm trying automatically load C header file with IDAPython, such as Load("filename.h").

2

Well, w s's answer actually points out what you should do. Here I give a more detailed answer:

In short, create file 1.h under your E: drive, fill with some struct definitions and try this in your IDA's Output Window:

idaapi.idc_parse_types("E:\\1.h", idc.PT_FILE)

This function will return number of errors it encounters when parsing your .h file. If you get 0, it means there is nothing wrong in your header file.

NOTE1: IDA Python keeps changing. The above code works for me (I use IDA Pro 6.8). Some changes may be needed if you use a different version. Try IDA Python Reference.

NOTE2: You should find the new types appear in your Local Types window (Press Shift+F1 to open it), which displays the types in TIL. If you actually need structures (which belongs to IDB), try idaapi.til2idb or idaapi.import_type to import them.

| improve this answer | |
1

See below the quote from idc.py

def parse_decls(inputtype, flags = 0):
    """
    Parse type declarations
    @param inputtype: file name or C declarations (depending on the flags)
    @param flags: combination of PT_... constants or 0
    @return: number of parsing errors (0 no errors)
    """
    return ida_typeinf.idc_parse_types(inputtype, flags)


PT_FILE =   0x0001  # input if a file name (otherwise contains type declarations)
PT_SILENT = 0x0002  # silent mode
PT_PAKDEF = 0x0000  # default pack value
PT_PAK1 =   0x0010  # #pragma pack(1)
PT_PAK2 =   0x0020  # #pragma pack(2)
PT_PAK4 =   0x0030  # #pragma pack(4)
PT_PAK8 =   0x0040  # #pragma pack(8)
PT_PAK16 =  0x0050  # #pragma pack(16)
PT_HIGH  =  0x0080  # assume high level prototypes
                    # (with hidden args, etc)
PT_LOWER =  0x0100  # lower the function prototypes
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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