# Types

## Working with Types: A Beginner Guide

## IDA type system fundamentals

The IDA type system is based on C-like constructs such as:

* **Structures**: Aggregate data types that group multiple members.
* **Unions**: Allow overlapping the same memory with different data types.
* **Enums**: Provide named integer constants.

IDA ships with [type libraries](#type-libraries) out-of-the-box, but you can define custom types in the [Local Types window](#type-management-essentials-local-types-view).

### Type definitions sources

* Built-in or custom [type libraries](#type-libraries)(.til files)
* Custom types
* Debug information (e.g., PDB or DWARF)

### Type libraries

IDA ships with type libraries for popular platforms and operating systems. They provide predefined data types that can be used in your analysis. You can view a list of currently loaded type libraries in **Type Libraries** window (**View -> Open subviews -> Type Libraries**, or <kbd>Shift</kbd>+<kbd>F11</kbd>)

#### Load additional type libraries

1. Go to the **Type Libraries** window. Right-click on the libraries list and select **Load type library...**, or press the <kbd>Ins</kbd> key.

![Load type library](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-2afa7f836040554009189449995a4638eece305f%2Fload-type-library.png?alt=media)

2. Select the type library from the list and click **OK**.

Once loaded, type library definitions are accessible throughout IDA, including the **Local Types** window.

{% hint style="info" %}
**Relation between Local Types and Type Libraries**:\
In IDA, **Local Types** are custom or imported type definitions specific to your current project, while **Type Libraries** provide pre-defined types for common platforms and architectures. Types in the **Type Libraries**, once referenced, are copied into the IDB and appear under the **Local Types** window.
{% endhint %}

See also:

* Check [TILIB tutorial](types/type-libraries/tilib) for creating custom type libraries

## Type management essentials: Local Types view

The Local Types view provides a centralized hub for managing and customizing type definitions directly within the IDA UI. To access this view, navigate to **View -> Open subviews -> Local Types** or press <kbd>Shift</kbd>+<kbd>F1</kbd> keys.

![Local Types window](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-d0ee3ad9f9e648565ab718c25d0bd0857b004858%2Flocal-types-window.png?alt=media)

In the **Local Types** window, you can:

* [Add new types](#add-new-types) (structures, unions, and enumerations), including [importing types from loaded type libraries](#import-types-from-loaded-type-libraries)
* [Modify existing types](#modify-existing-types)
* [Delete existing types](#delete-existing-types)

### Add new types

In the **Add type** dialog, you can create a custom [structure](#create-a-structure-struct), [union](#create-a-union), and [enumeration](#create-an-enumeration-enum), or [import them from loaded libraries](#import-types-from-loaded-type-libraries). To add a new type:

* press the <kbd>Ins</kbd> key or
* right-click on the types list and select **Add type...** from the context menu.

#### Create a structure (struct)

1. Open the **Add type** dialog and in the **Struct** tab configure the structure settings: ![Add struct](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-25640c265aa4b78a5c9e836ddacc46b93336fa16%2Fadd-struct.png?alt=media)

Understanding structure options:

* **Name**: the unique name of your struct.
* **Fixed layout** (default: enabled)\
  When checked:
  * It locks the struct size and members. It prevents accidentally changing the struct size, for example, if the user moves members around while modifying another type.
  * You need to specify the **Structure size** in bytes.
* **Make Type Choosable** (default: enabled)\
  When checked:
  * It includes this struct in the type listing.
* **Pack fields** (default: disabled)\
  When checked:
  * It packs the fields of the struct (removes padding) and saves memory.
* **Create union** (Leave unchecked for structures)
  * Only check it when creating a union instead of a struct.

2. Click **OK**.

As an alternative, you can create or edit structures via [free-text editor](#addedit-types-via-free-text-editor).

#### Create a union

{% hint style="info" %}
A union is de facto a type of a struct. Creating and editing unions follow the same principles as working with structs.
{% endhint %}

1. Open the **Add type** dialog and in the **Struct** tab configure the union settings:
   * specify the unique name of your union, and
   * check the **Create union** checkbox.

![Add union](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-29bbec8d0796c87c2d96a9b088b0a2e9796bf03d%2Fadd-union.png?alt=media)

{% hint style="info" %}
When you choose to create a union, the fixed layout option will no longer be available. If you would like to turn a union to a fixed layout structure, first change "union" to "struct" in the **C syntax** tab, and then edit the struct.
{% endhint %}

2. Click **OK**.

#### Create an enumeration (enum)

1. Open the **Add type** dialog and in the **Enum** tab configure the enum settings: ![Add enum](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-9779970a418b2b253669f262d52709a203687e35%2Fadd-enum.png?alt=media)

Understanding enum options:

* **Name**: specify the unique name of your enum
* **Size**: (default: auto)
  * It determines how much memory the enum values will occupy
  * You can select from dropdown the number of bytes (1, 2, 4, or 8 bytes)
  * The auto option let the compiler decide based on values
* **Number representation**: defines how enum values are displayed in IDA
  * Select the format for enum members from the available options: **Hexadecimal**, **Decimal**, **Octal**, **Binary** or **Character** (ASCII/Unicode)
* **Signed**: (default: disabled)
  * It determines if enum values can be negative
* **Bitmask**: (default: disabled)\
  When checked:
  * It makes the enum a **bitfield**, and allows the representation of multiple flags in a single value using bitwise operations (e.g., OR, AND)

2. Click **OK**.

As an alternative, you can create or edit enums via [free-text editor](#addedit-types-via-free-text-editor).

#### Modify existing types

To modify an existing type:

* press <kbd>Ctrl</kbd>+<kbd>E</kbd> or
* right-click on the list of existing types and select **Edit type...** from the context menu.

#### Delete existing types

To delete an existing type:

* press <kbd>Del</kbd> or
* right-click on the list of existing types and select **Delete type...** from the context menu.

#### Add/edit types via free-text editor

The Struct/Enum tabs are perfect for learning IDA type system and creating simple, single types. However, for more complex tasks—such as copying types from existing source code or defining multiple related types simultaneously—the text editor offers greater efficiency and flexibility.

**To add or edit a type using C code:**

1. Open the **Add type** dialog.
2. Go to the **C syntax** tab.

![C syntax tab](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-eb5791f06f187fa496d6d164cb8ecd2b31fad0c7%2Fc-syntax.png?alt=media)

### Importing types

#### Import types from loaded type libraries

Before you start importing types from type libraries, ensure that your desired library is already loaded in the **Type Libraries** window.

**Import standard structures**

If you want to import an existing standard structure:

1.  Open the **Add type** dialog and in the **Struct** tab, click _Import standard structure_.

    ![Import struct](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-bee6ca706d39f8d6ada34eb9aca161d6a3679b18%2Fimport-struct.png?alt=media)
2. In the new dialog, browse and select the structure from the list of all corresponding types in the loaded libraries, then click **OK** to import it.

**Import standard enums**

If you want to import an existing standard enum from the type library:

1. Open the **Add type** dialog and in the **Enum** tab, click:

* _Import standard enum by enum name_ (1), or
* _Import standard enum by symbol name_ (2) (useful when you know member names but not the enum name).

![Import enum](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-86d9deb516a32f26a1d059c75b0272f13c7492e7%2Fimport-enum.png?alt=media)

2. In the new dialog, browse and select the enum from the list of all corresponding types in the loaded libraries, then click **OK** to import it.

#### Import types definitions from C/C++ header files

Header files can be parsed by two different parsers:

* a **default parser**, shipped out-of-the-box with IDA, that supports basic C, or
* **IDACLang**, which deals with complex C/C++/Objective-C source code.

You can select source parser in **Options → Compiler...**:\
![Compiler options](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-2e03cad70d9bbb1b428a5a45ef62935e39d3db01%2Fcompiler-options.png?alt=media)

**To import type definitions from header files**:

1. Navigate to **Files -> Load file -> Parse C header file...**
2. Select your header file and click **OK** to import it. You should see a notification about a successful compilation. When you import a header file, all the type definitions from that file are added to your **Local Types**.

**How can I download IDACLang?**\
IDAClang is a standalone command line tool to produce type libraries, that you can get from [My Hex-Rays download center](https://my.hex-rays.com/dashboard/download-center/downloads).

**See also**:

* [IDAClang tutorial](types/type-libraries/idaclang_tutorial)

#### Import debug information

IDA supports debugging information formats such as PDB and DWARF. If your input file includes debugging information with types data, IDA will automatically import the types while loading the file.\
![DWARF info](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-c8bf75233bb787c461ac9d6841dd621af6c7ecfb%2Fdwarf-info.png?alt=media)\


The imported types will be displayed in the **Local Types** window, organized under the corresponding folder (either dwarf or pdb).

![Types imported with debug info](https://545602138-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FucByjS46IhJacH1pbIKC%2Fuploads%2Fgit-blob-d7e82421b642bc98de53cffa7cebf98789edc866%2Flocal-types-debug-info.png?alt=media)

### Working with types programmatically

In addition to the manual approach through IDA's graphical interface, types can be created, modified, and managed programmatically using our APIs. This, among others, allows for the automation of type-related tasks or the creation of complex data structures, making it particularly useful for handling large sets of types or performing repetitive operations.

**What next**:

* Check [IDAPython examples](../../developer-guide/idapython/idapython-examples#working-with-types-types) dedicated to working with types
