IDA SDK

- Main Page
- Header Files
- Classes
- Modules

Modules | Functions
Segment manipulation functions
Segments

## Detailed Description

Add/Delete/Modify segments.

## Modules
| Add segment flags
| Passed as 'flags' parameter to add_segm_ex()
| Segment modification flags
| Used by functions in Segment manipulation functions.
| Move segment flags
| Passed as 'flags' parameter to move_segm() and rebase_program()
| Move segment result codes
| Return values for move_segm() add rebase_program()
| Change segment status result codes
| Return values for change_segment_status()

## Functions
idaman bool ida_export | add_segm_ex (segment_t *s, const char *name, const char *sclass, int flags)
| Add a new segment. More...
idaman bool ida_export | add_segm (ea_t para, ea_t start, ea_t end, const char *name, const char *sclass)
| Add a new segment, second form. More...
idaman bool ida_export | del_segm (ea_t ea, int flags)
| Delete a segment. More...
int | get_segm_qty (void)
| Get number of segments.
segment_t * | getseg (ea_t ea)
| Get pointer to segment by linear address. More...
segment_t * | getnseg (int n)
| Get pointer to segment by its number. More...
segment_t * | get_next_seg (ea_t ea)
| Get pointer to the next segment.
segment_t * | get_prev_seg (ea_t ea)
| Get pointer to the previous segment.
segment_t * | get_first_seg (void)
| Get pointer to the first segment.
segment_t * | get_last_seg (void)
| Get pointer to the last segment.
idaman segment_t *ida_export | get_segm_by_name (const char *name)
| Get pointer to segment by its name. More...
idaman bool ida_export | set_segm_end (ea_t ea, ea_t newend, int flags)
| Set segment end address. More...
idaman bool ida_export | set_segm_start (ea_t ea, ea_t newstart, int flags)
| Set segment start address. More...
idaman bool ida_export | move_segm_start (ea_t ea, ea_t newstart, int mode)
| Move segment start. More...
idaman int ida_export | move_segm (segment_t *s, ea_t to, int flags=0)
| Move a segment to a new address. More...
idaman int ida_export | rebase_program (adiff_t delta, int flags)
| Rebase the whole program by 'delta' bytes. More...
idaman int ida_export | change_segment_status (segment_t *s, bool is_deb_segm)
| Convert a debugger segment to a regular segment and vice versa. More...
idaman bool ida_export | take_memory_snapshot (bool only_loader_segs)
| Take a memory snapshot of the running process. More...
idaman bool ida_export | is_miniidb (void)
| Is the database a miniidb created by the debugger?. More...
idaman bool ida_export | set_segm_base (segment_t *s, ea_t newbase)
| Internal function.

## Function Documentation

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

Add a new segment.

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

  s | pointer to filled segment structure. segment selector should have proper mapping (see set_selector()). if s.startEA==BADADDR then s.startEA <- get_segm_base(&s) if s.endEA==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.endEA < s.startEA, then fail. if s.endEA is too high and the new segment would overlap the next segment, s.endEA is adjusted properly.
  name | name of new segment. may be NULL. if specified, the segment is immediately renamed
  sclass | class of the segment. may be NULL. if specified, the segment class is immediately changed
  flags | Add segment flags

Return values

  1 | ok
  0 | failed, a warning message is displayed

idaman bool ida_export add_segm | ( | ea_t | para,
|  | ea_t | start,
|  | ea_t | end,
|  | const char * | name,
|  | const char * | sclass
| ) |  |

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 (16bit or 32bit). 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

  para | segment base paragraph. if paragraph can't fit in 16bit, then a new selector is allocated and mapped to the paragraph.
  start | start address of the segment. if start==BADADDR then start <- toEA(para,0).
  end | end 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.
  name | name of new segment. may be NULL
  sclass | class of the segment. may be NULL. 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

Return values

  1 | ok
  0 | failed, a warning message is displayed

idaman bool ida_export del_segm | ( | ea_t | ea,
|  | int | flags
| ) |  |

Delete a segment.

Parameters

  ea | any address belonging to the segment
  flags | Segment modification flags

Return values

  1 | ok
  0 | failed, no segment at 'ea'.

segment_t* getseg | ( | ea_t | ea | ) |
| inline

Get pointer to segment by linear address.

Parameters

  ea | linear address belonging to the segment

Returns
  NULL or pointer to segment structure

segment_t* getnseg | ( | int | n | ) |
| inline

Get pointer to segment by its number.

Warning
  Obsoleted because it can slow down the debugger (it has to refresh the whole memory segmentation to calculate the correct answer)

Parameters

  n | segment number in the range (0..get_segm_qty()-1)

Returns
  NULL or pointer to segment structure

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

Get pointer to segment by its name.

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

Parameters

  name | segment name. may be NULL.

Returns
  NULL or pointer to segment structure

idaman bool ida_export set_segm_end | ( | ea_t | ea,
|  | ea_t | newend,
|  | int | flags
| ) |  |

Set segment end address.

The next segment is shrinked to allow expansion of the specified segment. The kernel might even delete the next segment if necessary. The kernel will ask the user for a permission to destroy instructions or data going out of segment scope if such instructions exist.

Parameters

  ea | any address belonging to the segment
  newend | new end address of the segment
  flags | Segment modification flags

Return values

  1 | ok
  0 | failed, a warning message is displayed

idaman bool ida_export set_segm_start | ( | ea_t | ea,
|  | ea_t | newstart,
|  | int | flags
| ) |  |

Set segment start address.

The previous segment is trimmed to allow expansion of the specified segment. The kernel might even delete the previous segment if necessary. The kernel will ask the user for a permission to destroy instructions or data going out of segment scope if such instructions exist.

Parameters

  ea | any address belonging to the segment
  newstart | new start address of the segment note that segment start address should be higher than segment base linear address.
  flags | Segment modification flags

Return values

  1 | ok
  0 | failed, a warning message is displayed

idaman bool ida_export move_segm_start | ( | ea_t | ea,
|  | ea_t | newstart,
|  | int | mode
| ) |  |

Move segment start.

The main difference between this function and set_segm_start() is that this function may expand the previous segment while set_segm_start() never does it. So, this function allows to change bounds of two segments simultaneously. If the previous segment and the specified segment have the same addressing mode and segment base, then instructions and data are not destroyed - they simply move from one segment to another. Otherwise all instructions/data which migrate from one segment to another are destroyed.

Note
  this function never disables addresses.

Parameters

  ea | any address belonging to the segment
  newstart | new start address of the segment note that segment start address should be higher than segment base linear address.
  mode | policy for destroying defined items 0: if it is necessary to destroy defined items, display a dialog box and ask confirmation 1: if it is necessary to destroy defined items, just destroy them without asking the user -1: if it is necessary to destroy defined items, don't destroy them (i.e. function will fail) -2: don't destroy defined items (function will succeed)

Return values

  1 | ok
  0 | failed, a warning message is displayed

idaman int ida_export move_segm | ( | segment_t * | s,
|  | ea_t | to,
|  | int | flags = `0`
| ) |  |

Move a segment to a new address.

This function moves all information to the new address. It fixes up address sensitive information in the kernel. The total effect is equal to reloading the segment to the target address. SDK: For the module dependent address sensitive information, processor_t::move_segm is called. For the file format dependent address sensitive information, loader_t::move_segm is called.

Parameters

  s | segment to move
  to | new segment start address
  flags | Move segment flags

Returns
  Move segment result codes

idaman int ida_export rebase_program | ( | adiff_t | delta,
|  | int | flags
| ) |  |

Rebase the whole program by 'delta' bytes.

Parameters

  delta | number of bytes to move the program
  flags | Move segment flags it is recommended to use MSF_FIXONCE so that the loader takes care of global variables it stored in the database

Returns
  Move segment result codes

idaman int ida_export change_segment_status | ( | segment_t * | s,
|  | bool | is_deb_segm
| ) |  |

Convert a debugger segment to a regular segment and vice versa.

When converting debug->regular, the memory contents will be copied to the database.

Parameters

  s | segment to modify
  is_deb_segm | new status of the segment

Returns
  Change segment status result codes

idaman bool ida_export take_memory_snapshot | ( | bool | only_loader_segs | ) |

Take a memory snapshot of the running process.

Parameters

  only_loader_segs | only is_loader_segm() segments will be affected

Returns
  success

idaman bool ida_export is_miniidb | ( | void |  | ) |

Is the database a miniidb created by the debugger?.

Returns
  true if the database contains no segments or only debugger segments