Add Shortcut for IDAPython script in IDA

January 26, 2016

This post describes a way to associate an IDAPython script with a hotkey in IDA. The hotkeys are defined in Python and only require a small bit of bootstrap IDC code to initialize.

Modify startup script

First, modify IDA’s startup to run the custom hotkey code. IDA’s startup script is located in the ida.idc file which can be found at <IDADIR>/idc/ida.idc.

At the bottom of the file, edit the main() function with the line below. Change the directory (e.g. C:\\Users\\Alec) to point at a path where you will store your shortcut script.


static main(void)
    // ...

Create hotkey script

Create your Python hotkey script at the path specified in ida.idc. I named this file Here’s a simple exmaple that binds <CTRL>+<ALT>+<SHIFT>+H to the say_hi function.

import idaapi

def say_hi():
    print "Hi!"

idaapi.CompileLine('static py_say_hi() { RunPythonStatement("say_hi()"); }')

AddHotkey("Ctrl+Alt+Shift+H", 'py_say_hi')

To run an external script instead of in-file code, use the execfile function: (with execfile)

import idaapi

def say_hi():

idaapi.CompileLine('static py_say_hi() { RunPythonStatement("say_hi()"); }')

AddHotkey("Ctrl+Shift+H", 'py_say_hi')

Multiple hotkeys

If several IDAPython shortcuts are defined, repeating the steps above for each function can be tedius. The script below uses ida_run_python_function and idaapi.CompileLine to compile new functions. To use the script below, define a python function and use the AddHotkey function with your function name like this:

AddHotkey("Ctrl+Alt+Shift+H", ida_run_python_function("say_hi")); (with ida_run_python_function)

import idaapi
compiled_functions = {}
def ida_run_python_function(func_name):
    if func_name not in compiled_functions:
        ida_func_name = "py_%s" % func_name
        idaapi.CompileLine('static %s() { RunPythonStatement("%s()"); }' 
            % (ida_func_name, func_name))
        compiled_functions[func_name] = ida_func_name
    return ida_func_name

def say_hi():

def search_asserts():

AddHotkey("Ctrl+Alt+Shift+H", ida_run_python_function("say_hi"));
AddHotkey("Ctrl+Shift+A", ida_run_python_function("search_asserts"));