Skip to content

Types

types

Classes:

  • LibraryAddFlags

    Flags for changing the way type libraries are added to the database

  • LibraryAddResult

    Return values for library add operation

  • TypeFormattingFlags

    Type formatting flags used to control type parsing, formatting and printing

  • TypeKind

    Type category enumeration.

  • Types

    Provides access to type information and manipulation in the IDA database.

LibraryAddFlags

Bases: IntFlag

Flags for changing the way type libraries are added to the database

Attributes:

ADD_DEFAULT class-attribute instance-attribute

ADD_DEFAULT = ADDTIL_DEFAULT

Default behavior

ADD_INCOMPATIBLE class-attribute instance-attribute

ADD_INCOMPATIBLE = ADDTIL_INCOMP

Add incompatible type libraries

ADD_SILENT class-attribute instance-attribute

ADD_SILENT = ADDTIL_SILENT

Do not ask any questions

LibraryAddResult

Bases: IntEnum

Return values for library add operation

Attributes:

  • ABORTED

    Library not loaded, rejected by the user

  • FAILED

    Loading library failed

  • INCOMPATIBLE

    Library loaded but is incompatible

  • SUCCESS

    Library successfully loaded

ABORTED class-attribute instance-attribute

ABORTED = ADDTIL_ABORTED

Library not loaded, rejected by the user

FAILED class-attribute instance-attribute

FAILED = ADDTIL_FAILED

Loading library failed

INCOMPATIBLE class-attribute instance-attribute

INCOMPATIBLE = ADDTIL_COMP

Library loaded but is incompatible

SUCCESS class-attribute instance-attribute

SUCCESS = ADDTIL_OK

Library successfully loaded

TypeFormattingFlags

Bases: IntFlag

Type formatting flags used to control type parsing, formatting and printing

Attributes:

  • HTI_DCL

    Don't complain about redeclarations

  • HTI_EXT

    Debug: print external representation of types

  • HTI_FIL

    "Input" is file name, otherwise "input" contains a C declaration

  • HTI_HIGH

    Assume high level prototypes (with hidden args, etc)

  • HTI_INT

    Debug: print internal representation of types

  • HTI_LEX

    Debug: print tokens

  • HTI_LOWER

    Lower the function prototypes

  • HTI_MAC

    Define macros from the base tils

  • HTI_NDC

    Don't decorate names

  • HTI_NER

    Ignore all errors but display them

  • HTI_NOBASE

    Do not inspect base tils

  • HTI_NWR

    No warning messages

  • HTI_PAK

    Explicit structure pack value (#pragma pack)

  • HTI_PAK1

    pragma pack(1)

  • HTI_PAK16

    pragma pack(16)

  • HTI_PAK2

    pragma pack(2)

  • HTI_PAK4

    pragma pack(4)

  • HTI_PAK8

    pragma pack(8)

  • HTI_PAKDEF

    Default pack value

  • HTI_PAK_SHIFT

    Shift for HTI_PAK. This field should be used if you want to remember

  • HTI_RAWARGS

    Leave argument names unchanged (do not remove underscores)

  • HTI_RELAXED

    Accept references to unknown namespaces

  • HTI_SEMICOLON

    Do not complain if the terminating semicolon is absent

  • HTI_TST

    Test mode: discard the result

  • HTI_UNP

    Debug: check the result by unpacking it

HTI_DCL class-attribute instance-attribute

HTI_DCL = HTI_DCL

Don't complain about redeclarations

HTI_EXT class-attribute instance-attribute

HTI_EXT = HTI_EXT

Debug: print external representation of types

HTI_FIL class-attribute instance-attribute

HTI_FIL = HTI_FIL

"Input" is file name, otherwise "input" contains a C declaration

HTI_HIGH class-attribute instance-attribute

HTI_HIGH = HTI_HIGH

Assume high level prototypes (with hidden args, etc)

HTI_INT class-attribute instance-attribute

HTI_INT = HTI_INT

Debug: print internal representation of types

HTI_LEX class-attribute instance-attribute

HTI_LEX = HTI_LEX

Debug: print tokens

HTI_LOWER class-attribute instance-attribute

HTI_LOWER = HTI_LOWER

Lower the function prototypes

HTI_MAC class-attribute instance-attribute

HTI_MAC = HTI_MAC

Define macros from the base tils

HTI_NDC class-attribute instance-attribute

HTI_NDC = HTI_NDC

Don't decorate names

HTI_NER class-attribute instance-attribute

HTI_NER = HTI_NER

Ignore all errors but display them

HTI_NOBASE class-attribute instance-attribute

HTI_NOBASE = HTI_NOBASE

Do not inspect base tils

HTI_NWR class-attribute instance-attribute

HTI_NWR = HTI_NWR

No warning messages

HTI_PAK class-attribute instance-attribute

HTI_PAK = HTI_PAK

Explicit structure pack value (#pragma pack)

HTI_PAK1 class-attribute instance-attribute

HTI_PAK1 = HTI_PAK1
pragma pack(1)

HTI_PAK16 class-attribute instance-attribute

HTI_PAK16 = HTI_PAK16
pragma pack(16)

HTI_PAK2 class-attribute instance-attribute

HTI_PAK2 = HTI_PAK2
pragma pack(2)

HTI_PAK4 class-attribute instance-attribute

HTI_PAK4 = HTI_PAK4
pragma pack(4)

HTI_PAK8 class-attribute instance-attribute

HTI_PAK8 = HTI_PAK8
pragma pack(8)

HTI_PAKDEF class-attribute instance-attribute

HTI_PAKDEF = HTI_PAKDEF

Default pack value

HTI_PAK_SHIFT class-attribute instance-attribute

HTI_PAK_SHIFT = HTI_PAK_SHIFT

Shift for HTI_PAK. This field should be used if you want to remember an explicit pack value for each structure/union type. See HTI_PAK... definitions

HTI_RAWARGS class-attribute instance-attribute

HTI_RAWARGS = HTI_RAWARGS

Leave argument names unchanged (do not remove underscores)

HTI_RELAXED class-attribute instance-attribute

HTI_RELAXED = HTI_RELAXED

Accept references to unknown namespaces

HTI_SEMICOLON class-attribute instance-attribute

HTI_SEMICOLON = HTI_SEMICOLON

Do not complain if the terminating semicolon is absent

HTI_TST class-attribute instance-attribute

HTI_TST = HTI_TST

Test mode: discard the result

HTI_UNP class-attribute instance-attribute

HTI_UNP = HTI_UNP

Debug: check the result by unpacking it

TypeKind

Bases: Enum

Type category enumeration.

Attributes:

NAMED class-attribute instance-attribute

NAMED = 1

NUMBERED class-attribute instance-attribute

NUMBERED = 2

Types

Types(database: Database)

Bases: DatabaseEntity

Provides access to type information and manipulation in the IDA database.

Can be used to iterate over all types in the opened database.

Args: database: Reference to the active IDA database.

Methods:

  • apply_named_type_at

    Applies a named type to the given address.

  • copy_type

    Copies a type and all dependent types from one library to another.

  • create_library

    Initializes a new type library.

  • export_type

    Exports a type and all dependent types from the local (database) library

  • export_types_to_library

    Export all types from local library to external library.

  • get_all

    Retrieves an iterator over all types in the specified type library.

  • get_type_name_at

    Retrieves the type information of the item at the given address.

  • import_type

    Imports a type and all dependent types from an external (loaded) library

  • import_types_from_library

    Imports the types from an external library to the local (database) library.

  • load_library

    Loads a type library file in memory.

  • parse_declarations

    Parse type declarations from string and store created types into a library.

  • parse_header_file

    Parse type declarations from file and store created types into a library.

  • save_library

    Stores the type library to a file.

  • unload_library

    Unload library (free underlying object).

Attributes:

database property

database: Database

Get the database reference, guaranteed to be non-None when called from methods decorated with @check_db_open.

Returns: The active database instance.

Note: This property should only be used in methods decorated with @check_db_open, which ensures m_database is not None.

m_database instance-attribute

m_database = database

apply_named_type_at

apply_named_type_at(type: str, ea: ea_t) -> bool

Applies a named type to the given address.

Args: ea: The effective address. type: The name of the type to apply.

Returns: True if the type was applied successfully, false otherwise.

Raises: InvalidEAError: If the effective address is invalid.

copy_type

copy_type(
    source: til_t, destination: til_t, name: str
) -> int

Copies a type and all dependent types from one library to another.

Args: source: The source library. destination: The destination library. name: The name of the type.

Raises: RuntimeError: If the copy operation failed.

Returns: The ordinal number of the copied type.

create_library

create_library(file: Path, description: str) -> til_t

Initializes a new type library.

Args: file: The name of the library. description: The description of the library.

Returns: An initialized library.

export_type

export_type(destination: til_t, name: str) -> int

Exports a type and all dependent types from the local (database) library into a loaded (external) library.

Numbered types will be automatically enabled for the external library.

Args: destination: The loaded type library from where to import the type. name: The name of the type.

Raises: RuntimeError: If the export operation failed.

Returns: The ordinal number of the imported type.

export_types_to_library

export_types_to_library(library: til_t) -> None

Export all types from local library to external library. Numbered types will be automatically enabled for the external library.

Args: library: The destination library.

get_all

get_all(
    library: Optional[til_t] = None,
    type_kind: TypeKind = NAMED,
) -> Iterator[tinfo_t]

Retrieves an iterator over all types in the specified type library.

Args: library: library instance to iterate over (defaults to local library). type_kind: type kind to iterate over (defaults to 'NAMED').

Returns: A types iterator.

get_type_name_at

get_type_name_at(ea: ea_t) -> str | None

Retrieves the type information of the item at the given address.

Args: ea: The effective address.

Returns: The type name or None if it does not exist.

Raises: InvalidEAError: If the effective address is invalid.

import_type

import_type(source: til_t, name: str) -> int

Imports a type and all dependent types from an external (loaded) library into the local (database) library.

Args: source: The loaded type library from where to import the type. name: The name of the type.

Raises: RuntimeError: If the import operation failed.

Returns: The ordinal number of the imported type.

import_types_from_library

import_types_from_library(library: til_t) -> None

Imports the types from an external library to the local (database) library.

Args: library: The library instance to import from.

Returns: The status of the add library operation.

load_library

load_library(file: Path) -> til_t

Loads a type library file in memory.

Args: file: The path of the library file to load. The library name can be passed with or without extension (.til extension will be forced) and as a relative (default ida til directory will be used) or absolute path.

Returns: The loaded til_t object.

parse_declarations

parse_declarations(
    library: til_t,
    decl: str,
    flags: TypeFormattingFlags = HTI_DCL | HTI_PAKDEF,
) -> int

Parse type declarations from string and store created types into a library.

Args: library: The type library into where the parsed types will be stored. decl: C type declarations input string. flags: Optional combination of TypeFormattingFlags.

Returns: Number of parse errors.

parse_header_file

parse_header_file(
    library: til_t,
    header: Path,
    flags: TypeFormattingFlags = HTI_FIL | HTI_PAKDEF,
) -> int

Parse type declarations from file and store created types into a library.

Args: library: The type library into where the parsed types will be stored. header: The path to a header file. flags: Optional combination of TypeFormattingFlags.

Returns: Number of parse errors.

save_library

save_library(library: til_t, file: Path) -> bool

Stores the type library to a file. If the library contains garbage, it will be collected before storing it. Also compacts the library before saving.

Args: library: The type library instance to save to disk. file: The path to save the library to.

Returns: True if the operation succeeded, False otherwise.

unload_library

unload_library(library: til_t) -> None

Unload library (free underlying object).

Args: library: The library instance to unload.