3

I've recently started writing a few IDAPython plugins or scripts instead of using the native SDK, but I think I did not really figure out which module(s) are recommended to be imported. Typically, my script imports look somehow like this:

import ida_funcs
import ida_kernwin
import ida_lines
import ida_nalt
import ida_name
import ida_segment
import ida_struct
import idaapi
import idautils
import idc
from ida_bytes import *
from PyQt5 import QtCore, QtGui, QtWidgets

I've only just now realized that the idaapi module imports all the single modules. For example, I can define an action handler as

class MyHandler(ida_kernwin.action_handler_t):

but also as

class MyHandler(idaapi.action_handler_t):

So far, I was always trying to find the module the members originate from, and replace idaapi with the original module name where possible. But then I found BADADDR to originate from an ida_idaapi module, and the name feels so ridiculous, I wondered if I've been doing the right thing all along. The source and documentation on it is quite empty.

  • Is it recommended to use idaapi instead of the single modules? Why does idaapi exist?

Then, on the other hand, there is idc, which seems to provide IDC like functions, even with C style name casing. If I recall correctly, I read that the usage of this module is deprecated and only meant for quickly porting IDC scripts; the documentation prominently states

This file is subject to change without any notice.
Future versions of IDA may use other definitions.
  • Should I use ida_* / idaapi methods instead and, if possible, ignore idc completely?

1 Answer 1

4

Short answer is that both idaapi and idc modules should be avoided if possible.

The idaapi module is there for backwards compatibility and should be avoided if possible. It will be dropped in a future version of IDA (probably with little to no warning ahead of time). You should strongly prefer the ida_ prefixed modules.

In older versions of IDA, a single module exposed all IDA functionality (that was idaapi), with a few modules implementing utility functions (in idautils) and IDC-translations to ease migration from IDC to IDAPython (in idc).

With IDA 6.95, IDA's python SDK was divided into multiple modules and idaapi was left to avoid breaking all existing code that relies on the idaapi module.

Since the idc module has been part of IDA for a long while (since IDAPython started), I think it'll remain part of IDA for longer than idaapi, so if you have to pick whether to use idc or idaapi (and cannot use the specific ida_* modules, for some obscure reason), I suggest you prefer idc over idaapi.

It's also important to note that idaapi has nearly no content on itself, and you'll see that nowadays idaapi.py is mostly composed of importing the other modules into it's namespace. This is also wrong for several reasons (accidental namespace overshadowing, longer load times by loading unnecessary code) and was part of the reason the namespace was split.

The ida_idaapi module, however, is part of the new interface and should be used whenever needed. This is where general definitions that have no other reasonable module are made.

Protip: When I want to convert an idaapi usage to an ida_* usage, I simply import the object at hand and print it's help, which will list where is this object actually defined.

P.S. Although not really a duplicate, this is somewhat related to How is IDAPython API structured?

4
  • Thanks for clearing that up! The link to your answer (which I fixed, was cut off at the start) also gives a great insight on the history :)
    – Ray
    Commented Feb 11, 2019 at 14:03
  • Is this still valid? Even the example idapythonrc.py still references idaapi ...
    – 0xC0000022L
    Commented Jul 17, 2023 at 21:20
  • 1
    @0xC0000022L I believe so. idaapi is a wrapper around other ida_* modules and is left there for backwards compatibility. the idapythonrc.py example is a good example of why the backwards compatibility is still there. If you take a look at it's history you'll see it hasn't really changed for quite a while, while newer idapython script files use the ida_* modules instead.
    – NirIzr
    Commented Jul 19, 2023 at 6:03
  • Hmm, interesting. Thanks. It does indeed seem to be left alone. But backwards compatibility seems odd, given the break we head in compatibility just some versions ago (both because of an overhaul of all the names and Python 2.x vs. Python 3.x). Dropping that aspect would have been very easy at that point, IMO. Now anything going forward making use of the idaapi functionality without heeding the (not very obvious) warning signs of its deprecation is going to mean another breakage down the road :-|
    – 0xC0000022L
    Commented Jul 19, 2023 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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