I want to script a x86Emu plugin (an IDA emulator) with IdaPython. It's registered idc functions. Below is function names from the plugin source code.

/* add IDC functions for interacting with the emulator
EmuSetReg(regno, value);

This functions works well in idc. I found a class calling idc function in idaapi.py.

class _IdcFunction(object):
Internal class that calls pyw_call_idc_func() with a context
def \_\_init\_\_(self, ctxptr):
    self.ctxptr = ctxptr
    # Take a reference to the ctypes callback
    # (note: this will create a circular reference)
    self.cb   = _IDCFUNC_CB_T(self)
fp_ptr = property(lambda self: ctypes.cast(self.cb, ctypes.c_void_p).value)
def \_\_call\_\_(self, args, res):
    return call_idc_func__(self.ctxptr, args, res)

When I type this:

import ctypes
idaapi._IdcFuntion( ctypes ).\_\_call\_\_( 'EmuStepOne', ctypes.c_voidp ) 

I get the following error:

ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know how to convert parameter 1

I don't know why I get this error, has anyone an idea ?

  • If not need, call the idaapi.run_statements( IDC_SCRIPT_HERE ) it's returned bool
    – names
    May 4, 2015 at 17:49
  • idc.Eval("Some IDC Expression") is another option.
    – tmr232
    Jul 16, 2015 at 22:40

1 Answer 1


You get these errors because you're trying to use ctypes, which calls native functions from python using conversions from python objects to low-level C-like types.

Obviously, a python exception is not something ctypes can convert to native representation, so it fails.

There's a really simple way to call IDC code from within IDAPython, using idc.Eval, like the following:


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.