Module index

# Module `ida_segregs`

Functions that deal with the segment registers.

If your processor doesn't use segment registers, then these functions are of no use for you. However, you should define two virtual segment registers - CS and DS (for code segment and data segment) and specify their internal numbers in the LPH structure (processor_t::reg_code_sreg and processor_t::reg_data_sreg).

## Global variables

`var SR_auto`

  the value is determined by IDA

`var SR_autostart`

  used as SR_auto for segment starting address

`var SR_inherit`

  the value is inherited from the previous range

`var SR_user`

  the value is specified by the user

## Functions

`def copy_sreg_ranges(dst_rg: int, src_rg: int, map_selector: bool = False)`

  copy_sreg_ranges(dst_rg, src_rg, map_selector=False) Duplicate segment register ranges.

  @param dst_rg: (C++: int) number of destination segment register @param src_rg: (C++: int) copy ranges from @param map_selector: (C++: bool) map selectors to linear addresses using sel2ea()

`def del_sreg_range(ea: ea_t, rg: int)`

  del_sreg_range(ea, rg) -> bool Delete segment register range started at ea. When a segment register range is deleted, the previous range is extended to cover the empty space. The segment register range at the beginning of a segment cannot be deleted.

  @param ea: (C++: ea_t) start_ea of the deleted range @param rg: (C++: int) the segment register number @return: success

`def get_prev_sreg_range(out: sreg_range_t, ea: ea_t, rg: int)`

  get_prev_sreg_range(out, ea, rg) -> bool Get segment register range previous to one with address. @note: more efficient then get_sreg_range(reg, ea-1)

  @param out: (C++: sreg_range_t *) segment register range @param ea: (C++: ea_t) any linear address in the program @param rg: (C++: int) the segment register number @return: success

`def get_sreg(ea: ea_t, rg: int)`

  get_sreg(ea, rg) -> sel_t Get value of a segment register. This function uses segment register range and default segment register values stored in the segment structure.

  @param ea: (C++: ea_t) linear address in the program @param rg: (C++: int) number of the segment register @return: value of the segment register, BADSEL if value is unknown.

`def get_sreg_range(out: sreg_range_t, ea: ea_t, rg: int)`

  get_sreg_range(out, ea, rg) -> bool Get segment register range by linear address.

  @param out: (C++: sreg_range_t *) segment register range @param ea: (C++: ea_t) any linear address in the program @param rg: (C++: int) the segment register number @return: success

`def get_sreg_range_num(ea: ea_t, rg: int)`

  get_sreg_range_num(ea, rg) -> int Get number of segment register range by address.

  @param ea: (C++: ea_t) any address in the range @param rg: (C++: int) the segment register number @return: -1 if no range occupies the specified address. otherwise returns number of the specified range (0..get_srranges_qty()-1)

`def get_sreg_ranges_qty(rg: int)`

  get_sreg_ranges_qty(rg) -> size_t Get number of segment register ranges.

  @param rg: (C++: int) the segment register number

`def getn_sreg_range(out: sreg_range_t, rg: int, n: int) ‑> bool`

  getn_sreg_range(out, rg, n) -> bool Get segment register range by its number.

  @param out: (C++: sreg_range_t *) segment register range @param rg: (C++: int) the segment register number @param n: (C++: int) number of range (0..qty()-1) @return: success

`def set_default_dataseg(ds_sel: sel_t)`

  set_default_dataseg(ds_sel) Set default value of DS register for all segments.

  @param ds_sel: (C++: sel_t)

`def set_default_sreg_value(sg: segment_t *, rg: int, value: sel_t)`

  set_default_sreg_value(sg, rg, value) -> bool Set default value of a segment register for a segment.

  @param sg: (C++: segment_t *) pointer to segment structure if nullptr, then set the register for all segments @param rg: (C++: int) number of segment register @param value: (C++: sel_t) its default value. this value will be used by get_sreg() if value of the register is unknown at the specified address. @return: success

`def set_sreg_at_next_code(ea1: ea_t, ea2: ea_t, rg: int, value: sel_t)`

  set_sreg_at_next_code(ea1, ea2, rg, value) Set the segment register value at the next instruction. This function is designed to be called from idb_event::sgr_changed handler in order to contain the effect of changing a segment register value only until the next instruction.

  It is useful, for example, in the ARM module: the modification of the T register does not affect existing instructions later in the code.

  @param ea1: (C++: ea_t) address to start to search for an instruction @param ea2: (C++: ea_t) the maximal address @param rg: (C++: int) the segment register number @param value: (C++: sel_t) the segment register value

`def split_sreg_range(ea: ea_t, rg: int, v: sel_t, tag: uchar, silent: bool = False)`

  split_sreg_range(ea, rg, v, tag, silent=False) -> bool Create a new segment register range. This function is used when the IDP emulator detects that a segment register changes its value.

  @param ea: (C++: ea_t) linear address where the segment register will have a new value. if ea==BADADDR, nothing to do. @param rg: (C++: int) the number of the segment register @param v: (C++: sel_t) the new value of the segment register. If the value is unknown, you should specify BADSEL. @param tag: (C++: uchar) the register info tag. see Segment register range tags @param silent: (C++: bool) if false, display a warning() in the case of failure @return: success

## Classes

`class sreg_range_t`

  Proxy of C++ sreg_range_t class.

  init(self) -> sreg_range_t

  ### Ancestors

  - range_t

  ### Instance variables

  `var tag : uchar`

    Segment register range tags

  `var val : sel_t`

    segment register value

  ### Inherited members

  - `range_t`:
    - `clear`
    - `compare`
    - `contains`
    - `empty`
    - `end_ea`
    - `extend`
    - `intersect`
    - `overlaps`
    - `size`
    - `start_ea`
    - `thisown`