IDA C++ SDK 9.2
Loading...
Searching...
No Matches
Segment manipulation functions

Add/Delete/Modify segments. More...

Topics

 Add segment flags
 Passed as 'flags' parameter to add_segm_ex()
 Segment modification flags
 Used by functions in Segment manipulation functions.
 Get segment info flags
 Flags for get_segment_info() to request additional string fields.

Functions

idaman DEPRECATED bool ida_export add_segm_ex (segment_t *NONNULL s, const char *name, const char *sclass, int flags)
 Add a new segment.
idaman bool ida_export add_segment_ex (segment_info_t *si, int flags)
 Add a new segment using segment_info_t.
idaman bool ida_export add_segm (ea_t para, ea_t start, ea_t end, const char *name, const char *sclass, int flags=0)
 Add a new segment, second form.
idaman bool ida_export del_segm (ea_t ea, int flags)
 Delete a segment.
idaman int ida_export get_segm_qty ()
 Get number of segments.
idaman DEPRECATED segment_t *ida_export getseg (ea_t ea)
 Get pointer to segment by linear address.
idaman bool ida_export get_segment_info (segment_info_t *out, ea_t ea, int flags=0)
 Fill segment_info_t structure for segment at the specified address.
idaman bool ida_export set_segment_info (segment_info_t *si, int flags=0)
 Apply segment_info_t modifications to the database.
idaman ea_t ida_export get_segment_ea (ea_t ea)
 Get segment start address.
idaman DEPRECATED segment_t *ida_export getnseg (int n)
 Get pointer to segment by its number.
idaman bool ida_export get_segment_info_by_num (segment_info_t *out, int n, int flags=0)
 Fill segment_info_t structure for segment by its number.
idaman ea_t ida_export get_segment_ea_by_num (int n)
 Get segment start address by its number.
idaman int ida_export get_segm_num (ea_t ea)
 Get number of segment by address.
idaman DEPRECATED segment_t *ida_export get_next_seg (ea_t ea)
 Get pointer to the next segment.
idaman ea_t ida_export get_next_segment_ea (ea_t seg_ea)
 Get start address of the next segment.
idaman DEPRECATED segment_t *ida_export get_prev_seg (ea_t ea)
 Get pointer to the previous segment.
idaman ea_t ida_export get_prev_segment_ea (ea_t seg_ea)
 Get start address of the previous segment.
idaman DEPRECATED segment_t *ida_export get_first_seg ()
 Get pointer to the first segment.
idaman ea_t ida_export get_first_segment_ea ()
 Get start address of the first segment.
idaman DEPRECATED segment_t *ida_export get_last_seg ()
 Get pointer to the last segment.
idaman ea_t ida_export get_last_segment_ea ()
 Get start address of the last segment.
idaman DEPRECATED segment_t *ida_export get_segm_by_name (const char *name)
 Get pointer to segment by its name.
idaman ea_t ida_export get_segment_ea_by_name (const char *name)
 Get segment start address by its name.

Detailed Description

Add/Delete/Modify segments.

Function Documentation

◆ add_segm_ex()

idaman DEPRECATED bool ida_export add_segm_ex ( segment_t *NONNULL s,
const char * name,
const char * sclass,
int flags )

Add a new segment.

Deprecated
Use add_segment_ex() for safer access without pointer lifetime issues. If a segment already exists at the specified range of addresses, this segment will be truncated. Instructions and data in the old segment will be deleted if the new segment has another addressing mode or another segment base address.
Parameters
spointer to filled segment structure. segment selector should have proper mapping (see set_selector()).
  • if s.start_ea==#BADADDR then s.start_ea <- get_segm_base(&s)
  • if s.end_ea==#BADADDR, then a segment up to the next segment will be created (if the next segment doesn't exist, then 1 byte segment will be created).
  • if the s.end_ea < s.start_ea, then fail.
  • if s.end_ea is too high and the new segment would overlap the next segment, s.end_ea is adjusted properly.
namename of new segment. may be nullptr. if specified, the segment is immediately renamed
sclassclass of the segment. may be nullptr. if specified, the segment class is immediately changed
flagsAdd segment flags
Return values
1ok
0failed, a warning message is displayed The specified default segment register values may be modified by processor modules (see ev_creating_segm). Also, if the default data segment value is BADSEL, it will be changed to the selector of the newly created segment. This ensures that the data segment is always correctly set, which is a good default for most processors.

◆ add_segment_ex()

idaman bool ida_export add_segment_ex ( segment_info_t * si,
int flags )

Add a new segment using segment_info_t.

If a segment already exists at the specified range of addresses, this segment will be truncated. Instructions and data in the old segment will be deleted if the new segment has another addressing mode or another segment base address. The segment name and class and comments are taken from the segment_info_t structure.

Parameters
sisegment_info_t structure containing segment properties. Required fields: start_ea, end_ea, sel (or use setup_selector()). Optional fields: name, sclass, comments, align, comb, bitness, type, perm, flags, orgbase, defsr, color. segment selector should have proper mapping (see set_selector()).
  • if s.start_ea==#BADADDR then s.start_ea <- get_segm_base(&s)
  • if s.end_ea==#BADADDR, then a segment up to the next segment will be created (if the next segment doesn't exist, then 1 byte segment will be created).
  • if the s.end_ea < s.start_ea, then fail.
  • if s.end_ea is too high and the new segment would overlap the next segment, s.end_ea is adjusted properly.
flagsAdd segment flags
Return values
truesegment was created successfully
falsefailed, a warning message is displayed The specified default segment register values may be modified by processor modules (see ev_creating_segment). Also, if the default data segment value is BADSEL, it will be changed to the selector of the newly created segment. This ensures that the data segment is always correctly set, which is a good default for most processors.

◆ add_segm()

idaman bool ida_export add_segm ( ea_t para,
ea_t start,
ea_t end,
const char * name,
const char * sclass,
int flags = 0 )

Add a new segment, second form.

Segment alignment is set to #saRelByte. Segment combination is "public" or "stack" (if segment class is "STACK"). Addressing mode of segment is taken as default (16-bit or 32-bit). Default segment registers are set to #BADSEL. If a segment already exists at the specified range of addresses, this segment will be truncated. Instructions and data in the old segment will be deleted if the new segment has another addressing mode or another segment base address.

Parameters
parasegment base paragraph. if paragraph can't fit in 16-bit, then a new selector is allocated and mapped to the paragraph.
startstart address of the segment. if start==#BADADDR then start <- to_ea(para,0).
endend address of the segment. end address should be higher than start address. For emulate empty segments, use #SEG_NULL segment type. If the end address is lower than start address, then fail. If end==#BADADDR, then a segment up to the next segment will be created (if the next segment doesn't exist, then 1 byte segment will be created). If 'end' is too high and the new segment would overlap the next segment, 'end' is adjusted properly.
namename of new segment. may be nullptr
sclassclass of the segment. may be nullptr. type of the new segment is modified if class is one of predefined names:
  • "CODE" -> #SEG_CODE
  • "DATA" -> #SEG_DATA
  • "CONST" -> #SEG_DATA
  • "STACK" -> #SEG_BSS
  • "BSS" -> #SEG_BSS
  • "XTRN" -> #SEG_XTRN
  • "COMM" -> #SEG_COMM
  • "ABS" -> #SEG_ABSSYM
flagsAdd segment flags
Return values
1ok
0failed, a warning message is displayed

◆ del_segm()

idaman bool ida_export del_segm ( ea_t ea,
int flags )

Delete a segment.

Parameters
eaany address belonging to the segment
flagsSegment modification flags
Return values
1ok
0failed, no segment at 'ea'.

◆ get_segm_qty()

idaman int ida_export get_segm_qty ( )

Get number of segments.

◆ getseg()

idaman DEPRECATED segment_t *ida_export getseg ( ea_t ea)

Get pointer to segment by linear address.

Deprecated
Use get_segment_info() for safer access without pointer lifetime issues.
Parameters
ealinear address belonging to the segment
Returns
nullptr or pointer to segment structure

◆ get_segment_info()

idaman bool ida_export get_segment_info ( segment_info_t * out,
ea_t ea,
int flags = 0 )

Fill segment_info_t structure for segment at the specified address.

By default, only fields present in segment_t are filled. Use GSI_* flags to request additional string fields (name, class, comments).

Parameters
outoutput structure to fill (can be nullptr)
ealinear address belonging to the segment
flagscombination of Get segment info flags flags (default: 0)
Returns
true if segment found, false otherwise

◆ set_segment_info()

idaman bool ida_export set_segment_info ( segment_info_t * si,
int flags = 0 )

Apply segment_info_t modifications to the database.

Uses start_ea as the segment handle.

Parameters
sisegment_info_t with modifications (set via set_* methods)
flagscombination of Add segment flags flags (default: 0)
Returns
true on success, false if segment not found

◆ get_segment_ea()

idaman ea_t ida_export get_segment_ea ( ea_t ea)

Get segment start address.

Parameters
ealinear address belonging to the segment
Returns
segment start_ea, or BADADDR if not found

◆ getnseg()

idaman DEPRECATED segment_t *ida_export getnseg ( int n)

Get pointer to segment by its number.

Deprecated
Use get_segment_info_by_num() for safer access.
Warning
Obsoleted because it can slow down the debugger (it has to refresh the whole memory segmentation to calculate the correct answer)
Parameters
nsegment number in the range (0..get_segm_qty()-1)
Returns
nullptr or pointer to segment structure

◆ get_segment_info_by_num()

idaman bool ida_export get_segment_info_by_num ( segment_info_t * out,
int n,
int flags = 0 )

Fill segment_info_t structure for segment by its number.

By default, only fields present in segment_t are filled. Use GSI_* flags to request additional string fields (name, class, comments).

Parameters
outoutput structure to fill (can be nullptr)
nsegment number (0..get_segm_qty()-1)
flagscombination of Get segment info flags flags (default: 0)
Returns
true if segment found, false otherwise

◆ get_segment_ea_by_num()

idaman ea_t ida_export get_segment_ea_by_num ( int n)

Get segment start address by its number.

The returned address can be used as a handle for other segment_* functions.

Parameters
nsegment number in the range (0..get_segm_qty()-1)
Returns
segment start_ea, or BADADDR if not found

◆ get_segm_num()

idaman int ida_export get_segm_num ( ea_t ea)

Get number of segment by address.

Parameters
ealinear address belonging to the segment
Returns
-1 if no segment occupies the specified address. otherwise returns number of the specified segment (0..get_segm_qty()-1)

◆ get_next_seg()

idaman DEPRECATED segment_t *ida_export get_next_seg ( ea_t ea)

Get pointer to the next segment.

Deprecated
Use get_next_segment_ea() for safer access.

◆ get_next_segment_ea()

idaman ea_t ida_export get_next_segment_ea ( ea_t seg_ea)

Get start address of the next segment.

Parameters
seg_ealinear address belonging to the segment
Returns
start_ea of next segment, or BADADDR if no more segments

◆ get_prev_seg()

idaman DEPRECATED segment_t *ida_export get_prev_seg ( ea_t ea)

Get pointer to the previous segment.

Deprecated
Use get_prev_segment_ea() for safer access.

◆ get_prev_segment_ea()

idaman ea_t ida_export get_prev_segment_ea ( ea_t seg_ea)

Get start address of the previous segment.

Parameters
seg_ealinear address belonging to the segment
Returns
start_ea of previous segment, or BADADDR if no more segments

◆ get_first_seg()

idaman DEPRECATED segment_t *ida_export get_first_seg ( )

Get pointer to the first segment.

Deprecated
Use get_first_segment_ea() for safer access.

◆ get_first_segment_ea()

idaman ea_t ida_export get_first_segment_ea ( )

Get start address of the first segment.

The returned address can be used as a handle for other segment_* functions.

Returns
segment start_ea, or BADADDR if no segments exist

◆ get_last_seg()

idaman DEPRECATED segment_t *ida_export get_last_seg ( )

Get pointer to the last segment.

Deprecated
Use get_last_segment_ea() for safer access.

◆ get_last_segment_ea()

idaman ea_t ida_export get_last_segment_ea ( )

Get start address of the last segment.

Returns
segment start_ea, or BADADDR if no segments exist

◆ get_segm_by_name()

idaman DEPRECATED segment_t *ida_export get_segm_by_name ( const char * name)

Get pointer to segment by its name.

Deprecated
Use get_segment_ea_by_name() for safer access. If there are several segments with the same name, returns the first of them.
Parameters
namesegment name. may be nullptr.
Returns
nullptr or pointer to segment structure

◆ get_segment_ea_by_name()

idaman ea_t ida_export get_segment_ea_by_name ( const char * name)

Get segment start address by its name.

If there are several segments with the same name, returns the first of them.

Parameters
namesegment name (may be nullptr)
Returns
segment start_ea, or BADADDR if not found