You can register IDC functions from IDAPython plugins. See the %IDADIR%\python\examples\core\extend_idc.py
for the following snippet:
from __future__ import print_function
import ida_expr
if ida_expr.add_idc_func(
"pow",
lambda n, e: n ** e,
(ida_expr.VT_LONG, ida_expr.VT_LONG)):
print("The pow() function is now available in IDC")
else:
print("Failed to register pow() IDC function")
Next, your C/C++ plugin code can invoke IDC functions. See %IDASDK%\plugins\ex_debidc\ex_debidc.cpp
for an example of how to use expr.hpp::exec_idc_script
, whose prototype is as follows:
/// Compile and execute IDC function(s) from file.
/// \param result ptr to idc_value_t to hold result of the function.
/// If execution fails, this variable will contain
/// the exception information.
/// You may pass nullptr if you are not interested in the returned
/// value.
/// \param path text file containing text of IDC functions
/// \param func function name to execute
/// \param args array of parameters
/// \param argsnum number of parameters to pass to 'fname'
/// This number should be equal to number of parameters
/// the function expects.
/// \param[out] errbuf buffer for the error message
/// \retval true ok
/// \retval false error, see errbuf
THREAD_SAFE inline bool exec_idc_script(
idc_value_t *result,
const char *path,
const char *func,
const idc_value_t args[],
size_t argsnum,
qstring *errbuf=nullptr)