IDA SDK

- Main Page
- Header Files
- Classes
- Modules

- File List
- File Members

Classes | Functions | Macros | Typedefs | Enumerations | Variables
expr.hpp File Reference

## Detailed Description

Functions that deal with C-like expressions and built-in IDC language.

Functions marked THREAD_SAFE may be called from any thread. No simultaneous calls should be made for the same variable. We protect only global structures, individual variables must be protected manually.

## Classes
class | idc_value_t
| Class to hold idc values. More...
struct | idc_global_t
| Global idc variable. More...
struct | extfun_t
| Element of functions table. See funcset_t::f. More...
struct | funcset_t
| Describes an array of IDC functions. More...
struct | highlighter_cbs_t
struct | syntax_highlighter_t
| Base class for syntax highligters. More...
struct | extlang_t
| External language (to support third party language interpreters) More...

## Functions
idaman THREAD_SAFE error_t ida_export | VarLong (idc_value_t *v)
| Convert IDC variable to a long (32/64bit) number. More...
idaman THREAD_SAFE error_t ida_export | VarInt64 (idc_value_t *v)
| Convert IDC variable to a 64bit number. More...
idaman THREAD_SAFE error_t ida_export | VarNum (idc_value_t *v)
| Convert IDC variable to a long number. More...
idaman THREAD_SAFE error_t ida_export | VarString2 (idc_value_t *v)
| Convert IDC variable to a text string.
idaman THREAD_SAFE error_t ida_export | VarFloat (idc_value_t *v)
| Convert IDC variable to a floating point.
idaman THREAD_SAFE error_t ida_export | VarObject (idc_value_t *v, const idc_class_t *icls=NULL)
| Create an IDC object. More...
idaman THREAD_SAFE error_t ida_export | VarCopy (idc_value_t *dst, const idc_value_t *src)
| Copy an IDC object. More...
idaman THREAD_SAFE void ida_export | VarFree (idc_value_t *v)
| Free storage used by VT_STR2/VT_OBJ IDC variables. More...
idaman THREAD_SAFE void ida_export | VarSwap (idc_value_t *v1, idc_value_t *v2)
| Swap 2 variables.
idaman THREAD_SAFE error_t ida_export | VarGetClassName (const idc_value_t *obj, qstring *name)
| Retrieves the IDC object class name. More...
idaman THREAD_SAFE error_t ida_export | VarGetAttr (const idc_value_t *obj, const char *attr, idc_value_t *res, bool may_use_getattr=false)
| Get an object attribute. More...
idaman THREAD_SAFE error_t ida_export | VarSetAttr (idc_value_t *obj, const char *attr, const idc_value_t *value, bool may_use_setattr=false)
| Set an object attribute. More...
idaman THREAD_SAFE error_t ida_export | VarDelAttr (idc_value_t *obj, const char *attr)
| Delete an object attribute. More...
idaman THREAD_SAFE error_t ida_export | VarAssign (idc_value_t *dst, const idc_value_t *src)
| Assign 'src' to 'dst'.
idaman THREAD_SAFE error_t ida_export | VarMove (idc_value_t *dst, idc_value_t *src)
| Move 'src' to 'dst'. More...
idaman bool ida_export | VarPrint (qstring *out, const idc_value_t *v, const char *name=NULL, int indent=0)
| Get text representation of idc_value_t.
idaman THREAD_SAFE error_t ida_export | VarGetSlice (const idc_value_t *v, uval_t i1, uval_t i2, idc_value_t *res, int flags=0)
| Get slice. More...
idaman THREAD_SAFE error_t ida_export | VarSetSlice (idc_value_t *v, uval_t i1, uval_t i2, const idc_value_t *in, int flags=0)
| Set slice. More...
idaman THREAD_SAFE idc_class_t *ida_export | add_idc_class (const char *name, const idc_class_t *super=NULL)
| Create a new IDC class. More...
idaman THREAD_SAFE idc_class_t *ida_export | find_idc_class (const char *name)
| Find an existing IDC class by its name. More...
idaman THREAD_SAFE bool ida_export | set_idc_method (idc_class_t *icls, const char *fullfuncname)
| Set an IDC class method. More...
idaman THREAD_SAFE const char *ida_export | set_idc_dtor (idc_class_t *icls, const char *fullfuncname)
| Set a destructor for an idc class. More...
idaman THREAD_SAFE idc_value_t *ida_export | VarDeref (idc_value_t *v, int vref_flags)
| Dereference a VT_REF variable. More...
idaman THREAD_SAFE bool ida_export | VarRef (idc_value_t *ref, const idc_value_t *v)
| Create a variable reference. More...
idaman THREAD_SAFE idc_value_t *ida_export | add_idc_gvar (const char *name)
| Add global IDC variable. More...
idaman THREAD_SAFE idc_value_t *ida_export | find_idc_gvar (const char *name)
| Find an existing global IDC variable by its name. More...
idaman THREAD_SAFE bool ida_export | set_idc_func_ex (const char *name, idc_func_t *fp, const char *args, int extfunc_flags)
| Add/remove a built-in IDC function. More...
idaman bool ida_export | install_extlang (const extlang_t *el)
| Install an external language interpreter. More...
idaman bool ida_export | remove_extlang (const extlang_t *el)
| Uninstall an external language interpreter. More...
idaman bool ida_export | select_extlang (const extlang_t *el)
| Selects the external language interpreter. More...
const char * | get_extlang_fileext (void)
| Get the file extension for the current language.
idaman const extlangs_t *ida_export | get_extlangs ()
| Get the list of the registered extlangs.
idaman const extlang_t *ida_export | find_extlang_by_ext (const char *ext)
| Get the extlang that can handle the given file extension.
idaman const extlang_t *ida_export | find_extlang_by_name (const char *name)
| Find an extlang by name.
idaman THREAD_SAFE bool ida_export | set_header_path (const char *path, bool add)
| Set or append a header path. More...
idaman THREAD_SAFE char *ida_export | get_idc_filename (char *buf, size_t bufsize, const char *file)
| Get full name of IDC file name. More...
idaman THREAD_SAFE bool ida_export | dosysfile (bool complain_if_no_file, const char *file)
| Compile and execute "main" function from system file. More...
idaman bool ida_export | calcexpr_long (ea_t where, const char *line, sval_t *res, char *errbuf, size_t errbufsize)
| Compile and calculate an expression. More...
bool idaapi | calcexpr_long (ea_t where, const char *line, uval_t *res, char *errbuf, size_t errbufsize)
| See calcexpr_long()
idaman bool ida_export | calcexpr (ea_t where, const char *line, idc_value_t *rv, char *errbuf, size_t errbufsize)
| Compile and calculate an expression. More...
idaman bool ida_export | calc_idc_expr (ea_t where, const char *buf, idc_value_t *rv, char *errbuf, size_t errbufsize)
| Same as calcexpr(), but will always use the IDC interpreter regardless of the currently installed extlang. More...
idaman bool ida_export | execute (const char *line)
| Compile and execute IDC expression. More...
idaman THREAD_SAFE bool ida_export | CompileEx (const char *file, int cpl_flags, char *errbuf, size_t errbufsize)
| Compile a text file with IDC function(s). More...
bool idaapi | Compile (const char *file, char *errbuf, size_t errbufsize)
| Compile a text file with IDC functions (Also see CompileEx()). More...
bool idaapi | extlang_compile_file_exists (const extlang_t *el=NULL)
| Does the extlang_t::compile_file() callback exist?
bool | compile_script_file (const char *file, char *errbuf, size_t errbufsize)
| Compiles a script using the active extlang or with Compile() if no extlang is active.
bool | extlang_unload_procmod (const char *file, char *errbuf, size_t errbufsize)
| Unload processor module.
idaman bool ida_export | extlang_compile_file (const char *file, char *errbuf, size_t errbufsize, const extlang_t **el)
| Compiles a file using the appropriate extlang, otherwise Compile() is used. More...
idaman THREAD_SAFE bool ida_export | CompileLineEx (const char *line, char *errbuf, size_t bufsize, uval_t(idaapi *_getname)(const char *name)=NULL, bool only_safe_funcs=false)
| Compile one text line with IDC function(s). More...
idaman bool ida_export | compile_script_func (const char *name, ea_t current_ea, const char *expr, char *errbuf, size_t errbufsize)
| Compile idc or extlang function.
idaman bool ida_export | Run (const char *fname, int argsnum, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Execute an IDC function. More...
bool | run_script_func (const char *fname, int argsnum, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Execute idc or extlang function.
idaman bool ida_export | create_idc_object (const char *name, int argsnum, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Create an IDC object. More...
bool idaapi | extlang_get_attr_exists (void)
| Does the get_attr() extlang callback exist?
bool | get_script_attr (const idc_value_t *obj, const char *attr, idc_value_t *result)
| Get idc or extlang object attribute.
bool idaapi | extlang_set_attr_exists (void)
| Does the set_attr() extlang callback exist?
bool | set_script_attr (idc_value_t *obj, const char *attr, idc_value_t *value)
| Set idc or extlang object attribute.
bool idaapi | extlang_create_object_exists (void)
| Does the create_object() extlang callback exist?
bool | create_script_object (const char *name, int nargs, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Create idc or extlang object.
idaman bool ida_export | call_idc_method (const idc_value_t *obj, const char *name, int nargs, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Call an IDC object method. More...
bool idaapi | extlang_call_method_exists (void)
| Does the call_method() extlang callback exist?
bool idaapi | call_script_method (const idc_value_t *obj, const char *name, int nargs, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Call a member function of a script object. More...
bool idaapi | extlang_run_statements_exists (const extlang_t *elang=NULL)
| Does the extlang_t::run_statements callback exist?
idaman bool ida_export | run_statements (const char *str, char *errbuf, size_t errbufsize, const extlang_t *elang=NULL)
| Run statements using extlang. More...
idaman THREAD_SAFE bool ida_export | ExecuteLine (const char *line, const char *func, uval_t(idaapi *getname)(const char *name), int argsnum, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Compile and execute IDC function(s) on one line of text. More...
idaman THREAD_SAFE bool ida_export | ExecuteFile (const char *file, const char *func, int argsnum, const idc_value_t args[], idc_value_t *result, char *errbuf, size_t errbufsize)
| Compile and execute IDC function(s) from file. More...
idaman THREAD_SAFE bool ida_export | set_idc_func_body (const char *name, int narg, const uchar *body, size_t len)
| Add a compiled IDC function to the pool of compiled functions. More...
idaman THREAD_SAFE uchar *ida_export | get_idc_func_body (const char *name, int *narg, size_t *len)
| Get the body of a compiled IDC function. More...
idaman void ida_export | setup_lowcnd_regfuncs (idc_func_t *getreg, idc_func_t *setreg)
| Setup lowcnd callbacks to read/write registers. More...
bool | get_idptype_and_data (int *vtype, const void **vdata, const idc_value_t &v)
| Extract type & data from the idc_value_t instance that was passed to parse_config_value(). More...
Enumerate object attributes
idaman THREAD_SAFE const char *ida_export | VarFirstAttr (const idc_value_t *obj)
idaman THREAD_SAFE const char *ida_export | VarLastAttr (const idc_value_t *obj)
idaman THREAD_SAFE const char *ida_export | VarNextAttr (const idc_value_t *obj, const char *attr)
idaman THREAD_SAFE const char *ida_export | VarPrevAttr (const idc_value_t *obj, const char *attr)
Set user-defined functions to work with object attributes.
If the function name is NULL, the definitions are removed. Returns name of the old attribute function. NULL means error, "" means no previous attr func
idaman THREAD_SAFE const char *ida_export | set_idc_getattr (idc_class_t *icls, const char *fullfuncname)
idaman THREAD_SAFE const char *ida_export | set_idc_setattr (idc_class_t *icls, const char *fullfuncname)

## Macros
#define | IDC_LANG_EXT "idc"
| IDC script extension.
#define | VARSLICE_SINGLE 0x0001
| return single index (i2 is ignored)
#define | VREF_LOOP 0x0000
| dereference until we get a non VT_REF
#define | VREF_ONCE 0x0001
| dereference only once, do not loop
#define | VREF_COPY 0x0002
| copy the result to the input var (v)
#define | VT_LONG 2
| Integer (see idc_value_t::num)
#define | VT_FLOAT 3
| Floating point (see idc_value_t::e)
#define | VT_WILD 4
| Function with arbitrary number of arguments. More...
#define | VT_OBJ 5
| Object (see idc_value_t::obj)
#define | VT_FUNC 6
| Function (see idc_value_t::funcidx)
#define | VT_STR2 7
| String (see qstr() and similar functions)
#define | VT_PVOID 8
| void *
#define | VT_INT64 9
| i64
#define | VT_REF 10
| Reference.
#define | eExecThrow 90
| See return value of idc_func_t.
#define | EXTFUN_BASE 0x0001
| requires open database.
#define | EXTFUN_NORET 0x0002
| does not return. More...
#define | EXTFUN_SAFE 0x0004
| thread safe function. More...
#define | HF_FIRST HF_KEYWORD1
#define | CPL_DEL_MACROS 0x0001
| delete macros at the end of compilation
#define | CPL_USE_LABELS 0x0002
| allow program labels in the script
#define | CPL_ONLY_SAFE 0x0004
| allow calls of only thread-safe functions

## Typedefs
typedef qvector< idc_global_t > | idc_vars_t
| vector of global idc variables
typedef error_t idaapi | idc_func_t(idc_value_t *argv, idc_value_t *r)
| Prototype of an external IDC function (implemented in C). More...
typedef qvector< const extlang_t * > | extlangs_t
| vector of external language descriptions

## Enumerations
enum | syntax_highlight_style { HF_DEFAULT = 0, HF_KEYWORD1 = 1, HF_KEYWORD2 = 2, HF_KEYWORD3 = 3, HF_STRING = 4, HF_COMMENT = 5, HF_PREPROC = 6, HF_NUMBER = 7, HF_MAX }
| Possible syntax element highlighting style names.

## Variables
idaman funcset_t ida_export_data | IDCFuncs
| Array of built-in IDA functions.
idaman ida_export_data const extlang_t * | extlang
| current active external language

## Typedef Documentation

typedef error_t idaapi idc_func_t(idc_value_t *argv, idc_value_t *r)

Prototype of an external IDC function (implemented in C).

Parameters

  argv | vector of input arguments. IDA will convert all arguments to types specified by extfun_t::args, except for VT_WILD
  r | return value of the function or exception

Returns
  0 if ok, all other values indicate error. the error code must be set with set_qerrno():
  - eExecThrow - a new exception has been generated, see 'r'
  - other values - runtime error has occurred

## Function Documentation

idaman THREAD_SAFE error_t ida_export VarLong | ( | idc_value_t * | v | ) |

Convert IDC variable to a long (32/64bit) number.

Returns
  v = 0 if impossible to convert to long

idaman THREAD_SAFE error_t ida_export VarInt64 | ( | idc_value_t * | v | ) |

Convert IDC variable to a 64bit number.

Returns
  v = 0 if impossible to convert to int64

idaman THREAD_SAFE error_t ida_export VarNum | ( | idc_value_t * | v | ) |

Convert IDC variable to a long number.

Returns
  - v = 0 if IDC variable = "false" string
  - v = 1 if IDC variable = "true" string
  - v = number if IDC variable is number or string containing a number
  - eTypeConflict if IDC variable = empty string

idaman THREAD_SAFE error_t ida_export VarObject | ( | idc_value_t * | v,
|  | const idc_class_t * | icls = `NULL`
| ) |  |

Create an IDC object.

The original value of 'v' is discarded (freed).

Parameters

  v | variable to hold the object. any previous value will be cleaned
  icls | ptr to the desired class. NULL means "object" class this ptr must be returned by add_idc_class() or find_idc_class()

Returns
  always eOk

idaman THREAD_SAFE error_t ida_export VarCopy | ( | idc_value_t * | dst,
|  | const idc_value_t * | src
| ) |  |

Copy an IDC object.

If 'src' is not an object, simple variable assignment will be performed

idaman THREAD_SAFE void ida_export VarFree | ( | idc_value_t * | v | ) |

Free storage used by VT_STR2/VT_OBJ IDC variables.

After this call the variable has a numeric value 0

idaman THREAD_SAFE error_t ida_export VarGetClassName | ( | const idc_value_t * | obj,
|  | qstring * | name
| ) |  |

Retrieves the IDC object class name.

Parameters

  obj | class instance variable
  name | qstring ptr for the class name. Can be NULL.

Returns
  error code, eOk on success

idaman THREAD_SAFE error_t ida_export VarGetAttr | ( | const idc_value_t * | obj,
|  | const char * | attr,
|  | idc_value_t * | res,
|  | bool | may_use_getattr = `false`
| ) |  |

Get an object attribute.

Parameters

  obj | variable that holds an object reference. if obj is NULL it searches global variables, then user functions
  attr | attribute name
  res | buffer for the attribute value
  may_use_getattr | may call getattr functions to calculate the attribute if it does not exist

Returns
  error code, eOk on success

idaman THREAD_SAFE error_t ida_export VarSetAttr | ( | idc_value_t * | obj,
|  | const char * | attr,
|  | const idc_value_t * | value,
|  | bool | may_use_setattr = `false`
| ) |  |

Set an object attribute.

Parameters

  obj | variable that holds an object reference. if obj is NULL then it tries to modify a global variable with the attribute name
  attr | attribute name
  value | new attribute value
  may_use_setattr | may call setattr functions for the class

Returns
  error code, eOk on success

idaman THREAD_SAFE error_t ida_export VarDelAttr | ( | idc_value_t * | obj,
|  | const char * | attr
| ) |  |

Delete an object attribute.

Parameters

  obj | variable that holds an object reference
  attr | attribute name

Returns
  error code, eOk on success

idaman THREAD_SAFE error_t ida_export VarMove | ( | idc_value_t * | dst,
|  | idc_value_t * | src
| ) |  |

Move 'src' to 'dst'.

This function is more effective than VarAssign since it never copies big amounts of data.

idaman THREAD_SAFE error_t ida_export VarGetSlice | ( | const idc_value_t * | v,
|  | uval_t | i1,
|  | uval_t | i2,
|  | idc_value_t * | res,
|  | int | flags = `0`
| ) |  |

Get slice.

Parameters

  v | input variable (string or object)
  i1 | slice start index
  i2 | slice end index (excluded)
  res | output variable that will contain the slice
  flags | IDC variable slice flags or 0

Returns
  eOk if success

idaman THREAD_SAFE error_t ida_export VarSetSlice | ( | idc_value_t * | v,
|  | uval_t | i1,
|  | uval_t | i2,
|  | const idc_value_t * | in,
|  | int | flags = `0`
| ) |  |

Set slice.

Parameters

  v | variable to modify (string or object)
  i1 | slice start index
  i2 | slice end index (excluded)
  in | new value for the slice
  flags | IDC variable slice flags or 0

Returns
  eOk on success

idaman THREAD_SAFE idc_class_t* ida_export add_idc_class | ( | const char * | name,
|  | const idc_class_t * | super = `NULL`
| ) |  |

Create a new IDC class.

Parameters

  name | name of the new class
  super | the base class for the new class. if the new class is not based on any other class, pass NULL

Returns
  pointer to the created class. If such a class already exists, a pointer to it will be returned. Pointers to other existing classes may be invalidated by this call.

idaman THREAD_SAFE idc_class_t* ida_export find_idc_class | ( | const char * | name | ) |

Find an existing IDC class by its name.

Parameters

  name | name of the class

Returns
  pointer to the class or NULL. The returned pointer is valid until a new call to add_idc_class()

idaman THREAD_SAFE bool ida_export set_idc_method | ( | idc_class_t * | icls,
|  | const char * | fullfuncname
| ) |  |

Set an IDC class method.

Parameters

  icls | pointer to the class
  fullfuncname | name of the function to call. use full method name: classname.funcname

Return values

  true | success
  false | the function could not be found

idaman THREAD_SAFE const char* ida_export set_idc_dtor | ( | idc_class_t * | icls,
|  | const char * | fullfuncname
| ) |  |

Set a destructor for an idc class.

The destructor is called before deleting any object of the specified class. Exceptions that escape the destructor are silently ignored, runtime errors too.

idaman THREAD_SAFE idc_value_t* ida_export VarDeref | ( | idc_value_t * | v,
|  | int | vref_flags
| ) |  |

Dereference a VT_REF variable.

Parameters

  v | variable to dereference
  vref_flags | Dereference IDC variable flags

Returns
  pointer to the dereference result or NULL. If returns NULL, qerrno is set to eExecBadRef "Illegal variable reference"

idaman THREAD_SAFE bool ida_export VarRef | ( | idc_value_t * | ref,
|  | const idc_value_t * | v
| ) |  |

Create a variable reference.

Currently only references to global variables can be created.

Parameters

  ref | ptr to the result
  v | variable to reference

Returns
  success

idaman THREAD_SAFE idc_value_t* ida_export add_idc_gvar | ( | const char * | name | ) |

Add global IDC variable.

Parameters

  name | name of the global variable

Returns
  pointer to the created variable or existing variable. NB: the returned pointer is valid until a new global var is added.

idaman THREAD_SAFE idc_value_t* ida_export find_idc_gvar | ( | const char * | name | ) |

Find an existing global IDC variable by its name.

Parameters

  name | name of the global variable

Returns
  pointer to the variable or NULL. NB: the returned pointer is valid until a new global var is added. FIXME: it is difficult to use this function in a thread safe manner

idaman THREAD_SAFE bool ida_export set_idc_func_ex | ( | const char * | name,
|  | idc_func_t * | fp,
|  | const char * | args,
|  | int | extfunc_flags
| ) |  |

Add/remove a built-in IDC function.

This function does not modify the predefined kernel functions Example:

1 static const char myfunc5_args[] = { VT_LONG, VT_STR, 0 };
2
3 static error_t idaapi myfunc5(idc_value_t *argv, idc_value_t *res)
4 {
5 msg("myfunc is called with arg0=%a and arg1=%s\n", argv[0].num, argv[1].str);
6 res->num = 5; // let's return 5
7 return eOk;
8 }
9
10 // after this:
11 set_idc_func("MyFunc5", myfunc5, myfunc5_args);
12
13 // there is a new IDC function which can be called like this:
14 MyFunc5(0x123, "test");

Parameters

  name | function name to modify
  fp | pointer to the function which will handle this IDC function. == NULL: remove the specified function
  args | prototype of the function, zero terminated array of IDC value types
  extfunc_flags | Function description flags or 0

Returns
  success

idaman bool ida_export install_extlang | ( | const extlang_t * | el | ) |

Install an external language interpreter.

Any previously registered interpreter will be automatically unregistered. The installed extlang can be used in select_extlang().

Parameters

  el | description of the new language. must point to static storage.

Returns
  success

idaman bool ida_export remove_extlang | ( | const extlang_t * | el | ) |

Uninstall an external language interpreter.

Returns
  success

idaman bool ida_export select_extlang | ( | const extlang_t * | el | ) |

Selects the external language interpreter.

The specified extlang must be registered before selecting it. It will be used to evaluate expressions entered in dialog boxes. It will also replace the calcexpr() and calcexpr_long() functions.

Returns
  success

idaman THREAD_SAFE bool ida_export set_header_path | ( | const char * | path,
|  | bool | add
| ) |  |

Set or append a header path.

IDA looks for the include files in the appended header paths, then in the ida executable directory.

Parameters

  path | list of directories to add (separated by ';') may be NULL, in this case nothing is added
  add | true: append. false: remove old paths.

Return values

  true | success
  false | no memory

idaman THREAD_SAFE char* ida_export get_idc_filename | ( | char * | buf,
|  | size_t | bufsize,
|  | const char * | file
| ) |  |

Get full name of IDC file name.

Search for file in list of include directories, IDCPATH directory and the current directory.

Parameters

  buf | buffer for the answer
  bufsize | buffer size
  file | file name without full path

Returns
  NULL is file not found. otherwise returns pointer to buf

idaman THREAD_SAFE bool ida_export dosysfile | ( | bool | complain_if_no_file,
|  | const char * | file
| ) |  |

Compile and execute "main" function from system file.

Parameters

  file | file name with IDC function(s). The file will be searched in: the current directory IDA.EXE directory in PATH
  complain_if_no_file | 1: display warning if the file is not found 0: don't complain if file doesn't exist

Return values

  1 | ok, file is compiled and executed
  0 | failure, compilation or execution error, warning is displayed

idaman bool ida_export calcexpr_long | ( | ea_t | where,
|  | const char * | line,
|  | sval_t * | res,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Compile and calculate an expression.

Parameters

  | where | the current linear address in the addressing space of the program being disassembled. it will be used to resolve names of local variables, etc. if not applicable, then should be BADADDR
  | line | a text line with IDC expression
  | res | pointer to result. The result will be converted to 32/64bit number. Use calcexpr() if you need the result of another type.
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf

idaman bool ida_export calcexpr | ( | ea_t | where,
|  | const char * | line,
|  | idc_value_t * | rv,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Compile and calculate an expression.

Parameters

  | where | the current linear address in the addressing space of the program being disassembled. If will be used to resolve names of local variables etc. if not applicable, then should be BADADDR.
  | line | the expression to evaluate
  | rv | pointer to the result
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf

idaman bool ida_export calc_idc_expr | ( | ea_t | where,
|  | const char * | buf,
|  | idc_value_t * | rv,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Same as calcexpr(), but will always use the IDC interpreter regardless of the currently installed extlang.

One subtle difference: the current value of rv will be discarded while calcexpr() frees it before storing the return value.

idaman bool ida_export execute | ( | const char * | line | ) |

Compile and execute IDC expression.

Parameters

  line | a text line with IDC expression

Return values

  1 | ok
  0 | failure, a warning message is displayed

idaman THREAD_SAFE bool ida_export CompileEx | ( | const char * | file,
|  | int | cpl_flags,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Compile a text file with IDC function(s).

Parameters

  | file | name of file to compile if NULL, then "File not found" is returned.
  | cpl_flags | Compile IDC file flags or 0
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf

bool idaapi Compile | ( | const char * | file,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |
| inline

Compile a text file with IDC functions (Also see CompileEx()).

idaman bool ida_export extlang_compile_file | ( | const char * | file,
|  | char * | errbuf,
|  | size_t | errbufsize,
|  | const extlang_t ** | el
| ) |  |

Compiles a file using the appropriate extlang, otherwise Compile() is used.

(extlang is determined based on the extension of the file)

Parameters

  | file | script file name (can't be NULL!)
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf
  | el | the extlang that was used to compile the script. NULL indicates that IDC was used.

Return values

  true | ok
  false | error, see errbuf

idaman THREAD_SAFE bool ida_export CompileLineEx | ( | const char * | line,
|  | char * | errbuf,
|  | size_t | bufsize,
|  | uval_t(idaapi *)(const char *name) | _getname = `NULL`,
|  | bool | only_safe_funcs = `false`
| ) |  |

Compile one text line with IDC function(s).

Parameters

  | line | line with IDC function(s) (can't be NULL!)
  [out] | errbuf | buffer for the error message
  | bufsize | size of errbuf
  | _getname | callback function to get values of undefined variables This function will be called if IDC function contains references to undefined variables. May be NULL.
  | only_safe_funcs | if true, any calls to functions without EXTFUN_SAFE flag will lead to a compilation error.

Return values

  true | ok
  false | error, see errbuf

idaman bool ida_export Run | ( | const char * | fname,
|  | int | argsnum,
|  | const idc_value_t | args[],
|  | idc_value_t * | result,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Execute an IDC function.

Parameters

  | fname | function name. User-defined functions, built-in functions, and plugin-defined functions are accepted.
  | argsnum | number of parameters to pass to 'fname'. This number should be equal to number of parameters the function expects.
  | args | array of parameters
  [out] | result | pointer to idc_value_t to hold the return value of the function. If execution fails, this variable will contain the exception information. Can be NULL if return value is not required.
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf

idaman bool ida_export create_idc_object | ( | const char * | name,
|  | int | argsnum,
|  | const idc_value_t | args[],
|  | idc_value_t * | result,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Create an IDC object.

Parameters

  | name | class name. May be NULL for the built-in object_t class.
  | argsnum | number of arguments to pass to object constructor.
  | args | array of arguments
  [out] | result | pointer to idc_value_t to hold the created object. If execution fails, this variable will contain the exception information.
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf and exception info in 'result'

idaman bool ida_export call_idc_method | ( | const idc_value_t * | obj,
|  | const char * | name,
|  | int | nargs,
|  | const idc_value_t | args[],
|  | idc_value_t * | result,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Call an IDC object method.

Parameters

  | obj | object. if NULL and name != NULL, a gvar or global func specified by 'name' will be called.
  | name | name of the method to call. if NULL, obj must be a function reference. the referenced function will be called. both obj and name can not be NULL.
  | nargs | number of arguments to pass to method.
  | args | array of arguments. 'this' argument will be supplied by ida.
  [out] | result | pointer to idc_value_t to hold the created object. If execution fails, this variable will contain the exception information.
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf and exception info in 'result'

bool idaapi call_script_method | ( | const idc_value_t * | obj,
|  | const char * | name,
|  | int | nargs,
|  | const idc_value_t | args[],
|  | idc_value_t * | result,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |
| inline

Call a member function of a script object.

Parameters

  | obj | object instance
  | name | method name to call
  | nargs | number of input arguments
  | args | input arguments
  [out] | result | function result or exception
  [out] | errbuf | error message if evaluation fails
  | errbufsize | size of the error buffer

Return values

  true | ok
  false | error, see errbuf and exception info in 'result'

idaman bool ida_export run_statements | ( | const char * | str,
|  | char * | errbuf,
|  | size_t | errbufsize,
|  | const extlang_t * | elang = `NULL`
| ) |  |

Run statements using extlang.

Parameters

  | str | input string to execute
  [out] | errbuf | error message if evaluation fails
  | errbufsize | size of the error buffer
  | elang | optional extlang to use.

idaman THREAD_SAFE bool ida_export ExecuteLine | ( | const char * | line,
|  | const char * | func,
|  | uval_t(idaapi *)(const char *name) | getname,
|  | int | argsnum,
|  | const idc_value_t | args[],
|  | idc_value_t * | result,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Compile and execute IDC function(s) on one line of text.

Parameters

  | line | text of IDC functions
  | func | function name to execute
  | getname | callback function to get values of undefined variables This function will be called if IDC function contains references to a undefined variable. May be NULL.
  | argsnum | number of parameters to pass to 'fname' This number should be equal to the number of parameters the function expects.
  | args | array of parameters
  | 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 NULL if you are not interested in the returned value.
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf

idaman THREAD_SAFE bool ida_export ExecuteFile | ( | const char * | file,
|  | const char * | func,
|  | int | argsnum,
|  | const idc_value_t | args[],
|  | idc_value_t * | result,
|  | char * | errbuf,
|  | size_t | errbufsize
| ) |  |

Compile and execute IDC function(s) from file.

Parameters

  | file | text file containing text of IDC functions
  | func | function name to execute
  | argsnum | number of parameters to pass to 'fname' This number should be equal to number of parameters the function expects.
  | args | array of parameters
  | 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 NULL if you are not interested in the returned value.
  [out] | errbuf | buffer for the error message
  | errbufsize | size of errbuf

Return values

  true | ok
  false | error, see errbuf

idaman THREAD_SAFE bool ida_export set_idc_func_body | ( | const char * | name,
|  | int | narg,
|  | const uchar * | body,
|  | size_t | len
| ) |  |

Add a compiled IDC function to the pool of compiled functions.

This function makes the input function available to be executed.

Parameters

  name | name of the function
  narg | number of the function parameters
  body | compiled body of the function
  len | length of the function body in bytes.

Returns
  success (may fail on funcs that are being executed/compiled)

idaman THREAD_SAFE uchar* ida_export get_idc_func_body | ( | const char * | name,
|  | int * | narg,
|  | size_t * | len
| ) |  |

Get the body of a compiled IDC function.

Parameters

  name | name of the function
  narg | pointer to the number of the function parameters (out)
  len | out: length of the function body (may be NULL)

Returns
  pointer to the buffer with the function body. buffer will be allocated using qalloc(). NULL indicates failure (no such defined function)

idaman void ida_export setup_lowcnd_regfuncs | ( | idc_func_t * | getreg,
|  | idc_func_t * | setreg
| ) |  |

Setup lowcnd callbacks to read/write registers.

These callbacks will be used by the idc engine to read/write registers while calculating low level breakpoint conditions for local debuggers.

bool get_idptype_and_data | ( | int * | vtype,
|  | const void ** | vdata,
|  | const idc_value_t & | v
| ) |  |
| inline

Extract type & data from the idc_value_t instance that was passed to parse_config_value().

Parameters

  vtype | pointer to storage that will hold the type (Option value types)
  vdata | pointer to storage that contains the value (see Option value types for what type of data is pointed to.)
  v | the value holder

Returns
  true in case of success, false if 'v' is of unexpected type