0 Votes

IDA API

Last modified by WikiBot on 2025/05/12 21:59

Introduction

IDA ICE communicates between instances, and with external programs, by socket communication facilitated by the ZeroMQ framework. On each computer running IDA ICE, the IDA message broker runs (see the IDA message broker chapter), and passes messages between registered clients. Each registered client has a unique (on that computer) id number (which is written in Help/About IDA/API id). This id is used to communicate to that client. The API id is in many cases the same as the Process ID of the client process. Once a session is started (by calling the client with some function), the session is locked, and no other API sessions can talk to that client until the session has been closed.

IDA Message Broker Service

The IDA Message Broker Service is a service with the name IDAMessageBrokerService. It is installed into the c:\ProgramData\equa\ folder. The service can be removed and installed by executing the IDAMessageBrokerService.exe with the flags /install and /remove from a command prompt with elevated rights. It is installed by default during installation of IDA ICE. The service can be started and stopped with the help of the usual Windows service management tool, or by calling sc start(or stop) IDAMessageBrokerService in an elevated command prompt. When started, the ports on which the program is communicating is written to the file ida_ports.txt in c:\ProgramData\equa. Here is also a ida_message_broker_log.txt-file, where some logging is done. If you want to open the message broker for external communication, please place a file named ida_external.txt into the c:\ProgramData\equa folder and restart the service. The content of this file is irrelevant.

The idaapi2.dll

The idaapi2.dll is a .dll (a dynamic-link library), which opens up the IDA API for external programs. Every program language where you can load a Windows .dll-file, and use the ANSI C/C++ function calls, can use the API. In this document, both the technical parts of using the .dll and the API itself will be discussed.
If you want to move the idaapi.dll from the default location, please also copy the libzmq-v100-mt-4_0_4.dll-file to the same location as the idaapi2.dll. There is some logging of the API calls in the file ida_api_dll_log.txt placed in the Windows Temp-folder (usually c:\users\username\appdata\local\temp\). Please check this if you are experiencing problems. To find the correct variable/parameter/object names in IDA ICE, the best way is to first go to Options/Preferences/Developer and check the Do not translate names-checkbox. This makes IDA ICE show the true names in the Outline view. In the outline view, however, not everything is actual objects; entries preceded by a : is a collection, which is just shown for convenience, and does not exist as actual object. Instead, objects listed under the collection, are actually place directly under the parent object for the collection.

Functions in the idaapi2.dll

The functions, except for the connect/disconnect, switch… and get_err and getIDAStatus, are put in a results queue, which you then poll to get the actual result when it is done. These functions immediately return true/false, and then when the real results is done, that result in the pollForQueuedResults call. When a function description say that it returns “A list of child nodes”, it means that pollForQueuedResults returns that after a successful call.
In the idaapi2.dll, the following functions are exposed:

Functions for connecting/disconnecting with IDA:

Function nameTypeparameterreturnsexample
connect_to_idaboolchar *port_c, char *remote_idTrue/Falseconnect_to_ida("5945", "4076")
switch_remote_connectionboolconst char *new_remote_idTrue/Falseswitch_remote_connection("4077")
switch_api_versionboollong new_version_numberTrue/Falseswitch_api_version(1)
call_ida_functionlongchar *function, char *values, char *out, int out_len-1, 0, 1<call_ida_function("+","[{\"type\": \"integer\", \"value\": 4},{\"type\": \"integer\", \"value\": 5}]", out, 500)
ida_disconnectbool True/Falseida_disconnect()
get_errlongchar *out, int out_len-1, 0, 1<get_err(out, 500)

DOM api-functions

All functions return -1 if something went wrong, 0 if everything went well, and a positive number if the string buffer sent in is too small. In out, the string representation of a json-structure is located. This can be parsed and used: it is either a structure {"type": type, "value": value}, or a list with such structures. All object values are longs. They are translated back to objects in IDA.

Function nameTypeparameterreturns
childNodeslonglong node, char * out, int out_lenJSON list of child nodes to node
parentNodelonglong node, char * out, int out_lenparent node of node
setParentNodelonglong node, long parent, char * out, int out_lenSets the parent node of node to parent.
Returns the parent node
hasChildNodeslonglong node, char * out, int out_lenReturns true/false depending on whether node has any child nodes
firstChildlonglong node, char * out, int out_lenReturns the first child node of node
lastChildlonglong node, char * out, int out_lenReturns the last child node of node
nextSiblinglonglong node, char * out, int out_lenReturns the next sibling node of node
previousSiblinglonglong node, char * out, int out_lenReturns the previous sibling node of node
childNodesLengthlonglong node, char * out, int out_lenReturns the number of child nodes of node
cloneNodelonglong node, char * out, int out_lenClones, and inserts, the node node. Returns the new node
createNodelonglong node, char * value, char * out, int out_lenCreates a new node as a child to node, according to the l-form given in the value-parameter. Returns the new node
containslonglong node, long node2, char * out, int out_lenChecks if node is contained within node2. Returns true/false
domAncestorlonglong node, long node2, char * out, int out_lenChecks if node is ancestor to node2. Returns true/false
itemlonglong index, long node, char * out, int out_lenReturns the node with index index in the list of children of node
appendChildlonglong child, long parent, char * out, int out_lenAppends child as a child node to parent. Returns the new list of children
removeChildlonglong child, long parent, char * out, int out_lenRemoves child from parent. Returns the new list of children
replaceChildlonglong child, long child_rep, long parent, char * out, int out_lenReplaces child with child_rep. Returns the parent
setAttributelongchar * attribute, long node, char * value, char * out, int out_lenSets the attribute attribute of node node to value given by the json structure submitted (in text form) in the value parameter. Returns the value of the attribute
getAttributelongchar * attribute, long node, char * out, int out_lenReturns the value of the attribute attribute of node node

Special IDA api-functions

Function nameTypeparameterresultcomment/example
openDocumentlongchar *path, char *out, int out_lenOpens the building specified in path. Returns the building object 
openDocByTypeAndNamelongconst char * name, const char *type, char * out, int out_lenReturns the building object of type type and name name (without .idm) for an already opened building 
saveDocumentlonglong building_object, char * new_path, long unpacked, char * out, int out_lenSaves the building object. If new_path is just an empty string, it saves, otherwise, it tries to Save as...new_path can e.g. be "d:\\temp\\building47.idm"
unpacked can be set to 1 if you want unpacked cases, or 0 if you want packed (default behaviour) cases.
Returns true/false.
runSimulationlonglong building_object, long simulation_type, char * out, int out_len 

Acccording to the simulation_type parameter, the building building_object is run as simulation_type:
1) Custom simulation
2) Energy simulation
3) Cooling load simulation
4) Heating load simulation
5) Advanced level Run model... simulation

pollForQueuedResultslongchar * out, int out_lenReturns false if no queued results exists. Returns a list if queued results exist, where first element is true/false depending if calculation is done. If done, the second element in the list contains the result 
closeSessionboolchar * out, int out_lenCloses down the current session, so a new one can connect to the child instance 
exitSessionboolchar * out, int out_lenCloses down the application, for the current session 
getZoneslonglong node, char * out, int out_lenIf node is a building object, returns a list of the bulding's zones. Otherwise tries to return a list of the node's building's zones (same as above). 
getWindowslonglong object, char * out, int out_lenIf object is a building object, a list of all windows in the building is returned. If a zone object, a list of all external windows in the zone 
getAllSubobjectsOfTypelonglong node, char *type, char *out, int out_lenReturns a list of all subobjects of type type recursively for an object 
runIDAScriptlonglong node, char *script, char *out, int out_lenExecutes a general IDA script with node as base object 
copyObjectlonglong node, char *new_name, char *out, int *out_lenMakes a copy of node node and names it new_name. Returns new node 
findObjectsByCriteriumlonglong node, char *criterium, char *out, int *out_lenReturns a list of all subobjects (recursively) of node, and returns a list with structures as: (object ("Object name" "Parent name" "Grandparent name.." etc, down to building name)))Criterium must be an IDA script expression evaluating to true/false. (E.g. "(= (:call name [@]) "Zone name")" "(eq 'SCHEDULE-DATA (:call model-type [@]))"
findUseOfResourcelonglong resource, char *out, int *out_lenResource must be a resource object. Returns a list of all objects where the resource is used 
printReportlonglong report, char *out_path, long report_type, char *out, int *out_lenWrites a report to out_path.
 

report must be a report object. report_type specifies what type of report you want

1. .html
2. .pdf

compareResultslongchar *building_objects, char *out_path, long report_type, char *out, int *out_lenbuilding_objects must be a json-list with building objects: "[{\"type\": "\object\", \"value:\": 1}, {\"type\": "\object\", \"value:\": 1}]"

report_type specifies what type of report you want:

1. .html
2. .pdf

getIDAStatuslongchar * out, int out_lenReturns a list with the present status of the simulation/IDA, and possible other information. The first element is always the statePossible normal states:
1) Idle
2) Reading in model
3) Creating math model
4) Simulating (incl. progress)
5) Finished
6) Terminated
7) Saving
getChildrenOfTypelonglong node, char * type, char * out, int out_lenReturns a list of all the child nodes of node with type type 
findNamedChildlonglong node, char * name, char * out, int out_lenReturns one or zero child nodes of node with name name, will try first string version, then symbol version of name 
export3dViewlonglong building_object, char * output_file, long view, char * out, int out_lenExports an image of the 3D-view to file output_file given building building_object. Several views are available0. Default view (as you looked at the case last)
1. Top view
2. Bottom view
3. Front View
4. Back view
5. Left view
6. Right view
exportDiagramlonglong diagram_object, char * output_file, long save_type, char * out, int out_lenExports an image of the diagram diagram_object to file output_fileSave_type can be:
0. .emf-file
1. .wmf-file
2. .png-file.
getNamedObjectFromPathlonglong object, char * path, long save_type, char * out, int out_lenReturns an object from a potentially deep structure. Object is parent object, and in path, you can specify the path down to an object you want to access

The path should be a text representation of a JSON array, with type, value pairs, like this: "[{\"type\":\"string\",\"value\": \"Zone\"}, {\"type\":\"string\",\"value\": \"GROUP\"}]"
This would return the GROUP object from the “Zone” object in the building, if the building object was passed in the object argument. This avoids nesting calls just to get to an object, if you are not interested in the objects in between the parent object and the deepest one

openIFCFilelong const char * name, const char *type, char * out, int out_lenReturns the imported building object. Imports the .ifc file specified by path. The three parameters mergeWindows keepIntersectingSpaces and ignoreRoof can be set to 0 (do not use) or 1 (use). The parameters are from the IFC import options in IDA ICE.