# Getting Started

### idalib <a href="#idalib" id="idalib"></a>

Get up and running with idalib - the IDA headless automation interface.

### Prerequisites

* IDA Pro 9.0 or newer installed and running

## Installation for C++

To use the ida library from the C++, please refer to the idalib.hpp header file shipped with C++ SDK where you will find the relevant information.

## Installation for Python

To use the ida library Python module, you need to install and configure `idapro` package by following these steps:

**Install ida library Python module**

1. Navigate to the `idalib/python` folder within the IDA Pro installation directory
2. Run the command: `pip install .`

{% hint style="info" %}
When setting up idalib to work with IDA Feeds and your virtual environment (venv), make sure to run the above command from within your activated venv.
{% endhint %}

### Setting up the ida library Python module

**Run the Activation Script**

1. You need to inform the `idapro` Python module of your IDA Pro installation. To do this, run the `py-activate-idalib.py` script located in your IDA Pro installation folder, or inside the `idalib/python` folder (depends on the system version you use):

   ```
   python /path/to/IDA/installation/py-activate-idalib.py [-d /path/to/active/IDA/installation]
   ```

   If the `-d` option is omitted, the script will automatically select the IDA installation folder from which it was executed.

## Using the ida library Python module

**Import `idapro` in your script**

1. Make sure to import the `idapro` package as **the first import** in your Python script
   * After importing, you can utilize the existing IDAPython APIs

### Example script

For a reference on how to use the ida module, check the `idalib/examples` folder in your IDA Pro installation directory or look at the sample script provided below.

```python
#!/usr/bin/env python3
import argparse
import os
import json
import idapro
from pathlib import Path
import ida_segment
import ida_idaapi
import ida_funcs
import ida_idp
import ida_auto
import ida_undo



class sig_hooks_t(ida_idp.IDB_Hooks):

    def __init__(self):
        ida_idp.IDB_Hooks.__init__(self)
        self.matched_funcs = set()

    def func_added(self, pfn):
        self.matched_funcs.add(pfn.start_ea)

    def func_deleted(self, func_ea):
        try:
            self.matched_funcs.remove(func_ea)
        except:
            pass

    def func_updated(self, pfn):
        self.matched_funcs.add(pfn.start_ea)

    def idasgn_loaded(self, sig_name):
        return print(f"Sig {sig_name} loaded")

    def dump_matches(self):
        for fea in self.matched_funcs:
            print(f"Matched function {ida_funcs.get_func_name(fea)}")


### List the segments for the loaded binary
def list_segments():
    nb_items = ida_segment.get_segm_qty()
    print("Segments number:",  nb_items)
    for i in range(0, nb_items):
        seg_src = ida_segment.getnseg(i)
        print(str(i+1) + ".")
        print("\tname:", ida_segment.get_segm_name(seg_src))
        print("\tstart_address:", hex(seg_src.start_ea))
        print("\tend_address", hex(seg_src.end_ea))
        print("\tis_data_segment:", ida_segment.get_segm_class(seg_src) == ida_segment.SEG_DATA)
        print("\tbitness:", seg_src.bitness)
        print("\tpermissions:",  seg_src.perm, "\n")

### Just call an existing python script
def run_script(script_file_name:str):
    if not os.path.isfile(script_file_name):
        print(f"The specified script file {script_file_name} is not a valid python script")
        return
    ida_idaapi.IDAPython_ExecScript(script_file_name, globals())
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hex-rays.com/core/idalib/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
