The IDAPython API provides you a range of functions to interact with the disassembler, navigate through the output, and manipulate various elements such as functions, instructions, data, and comments.
This guide is is designed to speed up the learning curve in IDAPython API and kickstart your journey with scripting in IDA, assuming that you are already found your way around IDA and got familiar with IDA basics.
First, check basics for the core concepts like common variables, then dive into our simple, reusable code snippets showing examples of commonly used functions. When you feel comfortable with some of the most popular IDAPython API usage, you can delve into our set of more complex examples.
IDAPython API is organized in modules, however their number may be a bit overwhelming for the first sigh. Here's the list of modules that should catch your attention first:
idautils
: This module extracts the most useful and handy functions allowing you to jump right away and interact with the disassembly without the need to scrutinize the whole IDAPython API from the start. You can find here functions to iterate through whole segments, functions (founded by IDA and also user-defined), named locations, etc.
ida_idaapi
: The ida_idaapi
module comes handy when you want to create custom plugins or handle events, as it gives you access to more advanced functions and allows interaction with overall system
idc
: This module provides functions that were originally part of native IDA IDC scripting language, wrapped for use in IDAPython API. This is a great starting point if you're already familiar with IDC scripting.
ida_funcs
: This module gives you tools to create and manipulate functions within IDA.
ida_kernwin
: This module provides functionality to interact with IDA UI, so you can create custom dialogs and more.
When you start working with IDAPython, you'll realize that one of the most commonly passed variables is ea
, which refers to the valid memory address (effective address). On the other hand, the BADADDR
is a constant that indicates an invalid address. It is used to indicate that an operation (such as querying a function) has failed or returned an invalid result, or signify that a specific memory location is unusable. Whenever you're working with functions that return memory addresses, it's a best practice to check whether the result equals BADADDR to ensure the operation was successful.
Here you can check the most common functions grouped by topics and short code samples that can serve as building blocks for longer scripts. They are usually focused on performing one specific action and can be easily reusable in more complex scripts, which you can find later under examples.
get_first_seg()
If you feel more comfortable with IDAPython now, you can delve into more complex and advanced examples shipped with your IDA instance. You can find them in the python/examples
folder where your IDA is installed or check them from our docs These collection gathered more advanced code samples, which usually make use of more modules and APIs.
Delve into our tutorial on how to create your first custom plugin in IDAPython.