0 Votes

Executing IDA scripts from foreign code

Last modified by WikiBot on 2025/03/20 14:16

Executing IDA scripts from foreign code

From an external function called from an IDA script, it is possible to execute another IDA script.

long idaExec(char* script)

Executes the given script, using the environment that was active when the external function was called. The objects may be referenced in scripts as !handler.

Returns the type code of the result. 

long idaResultInt()

Returns the result of the last call of idaExec as an integer. See also the table of conversions below.

double idaResultReal()

Returns the result of the last call of idaExec as a real number in 8-byte floating format. See also the table of conversions below.

long idaResult(void* buffer, long type, long count)

Copies the result (or a part of the result) of the last call of idaEcec to the buffer. Does nothing and returns 0 if the requested type is not compatible with the actual type of the result.

Arguments:

 
buffer
type
count

Returns: The actual number of copied elements.

Conversion table

Actual type

idaResultInt

idaResultReal

Integer

no conversion

converted to double

Real

Rounded

no conversion

Boolean

0 or 1

0.0

Character

character code

0.0

String

reads from string; 0 if not an integer

reads from string; 0.0 if not a number

Symbol

0

0.0

Void

0

0.0

Array (except string)

If the array contains a single element, it is returned as a scalar, see above. Otherwise 0 is returned.

Type codes

   
Name Value Comment
IDA_TYPE_VOID 0 No result. In combination with IDA_TYPE_PTR – empty array.
IDA_TYPE_INT 1 Integer type
IDA_TYPE_REAL 2 Floating-point type
IDA_TYPE_CHAR 3 Character type
IDA_TYPE_BOOL 4 Boolean type (true or false)
IDA_TYPE_OBJECT 5 Handle of IDA object (unsigned integer)
IDA_TYPE_PTR 0x80 Array type. Used in combination with types above.
IDA_TYPE_STRING 0x83 Text string (0-terminated array of characters)
IDA_TYPE_SYMBOL 0x8B IDA symbol represented as a text string
IDA_TYPE_BYTE
IDA_TYPE_SHORT
IDA_TYPE_LONG 
0x20
0x40
0x60 
These codes may be used in argument type of function idaResult (in combination with other type codes) to modify the element width in the result buffer

Field widths in the result buffer

Type

Width in bytes

Default

Byte

Short

Long

IDA_TYPE_INT

4

1

2

4

IDA_TYPE_REAL

8

4

4

8

IDA_TYPE_CHAR

1

1

2

2

IDA_TYPE_BOOL

4

1

2

4

IDA_TYPE_OBJECT

4

4

4

4

IDA_TYPE_STRING

1

1

2

2

IDA_TYPE_SYMBOL

1

1

2

2

Type conversions in function idaResult:

The types IDA_TYPE_REAL, IDA_TYPE_BOOL, IDA_TYPE_CHAR, IDA_TYPE_OBJECT may be converted to IDA_TYPE_INT.

The type IDA_TYPE_INT may be converted to IDA_TYPE_REAL and IDA_TYPE_BOOL.