Skip to content

Segments

segments

Classes:

  • Segments

    Provides access to segment-related operations in the IDA database.

Segments

Segments(database: Database)

Bases: DatabaseEntity

Provides access to segment-related operations in the IDA database.

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

Args: database: Reference to the active IDA database.

Note: Since this class does not manage the lifetime of IDA kernel objects (segment_t*), it is recommended to use these pointers within a limited scope. Obtain the pointer, perform the necessary operations, and avoid retaining references beyond the immediate context to prevent potential issues with object invalidation.

Methods:

  • get_all

    Retrieves an iterator over all segments in the database.

  • get_at

    Retrieves the segment that contains the given address.

  • get_name

    Retrieves the name of the given segment.

  • set_name

    Renames a segment.

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

get_all

get_all() -> Iterator[segment_t]

Retrieves an iterator over all segments in the database.

Returns: A generator yielding all segments in the database.

get_at

get_at(ea: ea_t) -> Optional[segment_t]

Retrieves the segment that contains the given address.

Args: ea: The effective address to search.

Returns: A pointer to the containing segment, or None if none found.

Raises: InvalidEAError: If the effective address is invalid.

get_name

get_name(segment: segment_t) -> str

Retrieves the name of the given segment.

Args: segment: Pointer to the segment.

Returns: The segment name as a string, or an empty string if unavailable.

set_name

set_name(segment: segment_t, name: str) -> bool

Renames a segment.

Args: segment: Pointer to the segment to rename. name: The new name to assign to the segment.

Returns: True if the rename operation succeeded, False otherwise.