IDA C++ SDK 9.2
Loading...
Searching...
No Matches
segment.hpp File Reference

Functions that deal with segments. More...

Go to the source code of this file.

Classes

class  segment_t
 Describes a program segment. More...
class  lock_segment
 Helper class to lock a segment pointer so it stays valid. More...
class  lock_segment_ea
 Helper class to lock a segment by address so it stays valid. More...

Typedefs

typedef std::function< ea_t(ea_t seg_start_ea)> segment_selector_visitor_t
 Callback type for enumerate_segments_with_selector_ea().

Enumerations

enum  move_segm_code_t {
  MOVE_SEGM_OK = 0 , MOVE_SEGM_PARAM = -1 , MOVE_SEGM_ROOM = -2 , MOVE_SEGM_IDP = -3 ,
  MOVE_SEGM_CHUNK = -4 , MOVE_SEGM_LOADER = -5 , MOVE_SEGM_ODD = -6 , MOVE_SEGM_ORPHAN = -7 ,
  MOVE_SEGM_DEBUG = -8 , MOVE_SEGM_SOURCEFILES = -9 , MOVE_SEGM_MAPPING = -10 , MOVE_SEGM_INVAL = -11
}

Functions

 CASSERT (sizeof(segment_t)==192)
bool is_visible_segm (segment_t *s)
 See #SFL_HIDDEN.
bool is_finally_visible_segm (segment_t *s)
 See #SFL_HIDDEN, #SCF_SHHID_SEGM.
idaman DEPRECATED void ida_export set_visible_segm (segment_t *s, bool visible)
 See #SFL_HIDDEN.
idaman void ida_export set_visible_segment (ea_t ea, bool visible)
 Set segment visibility by address.
idaman bool ida_export is_spec_segm (uchar seg_type)
 Has segment a special type?
idaman bool ida_export is_spec_ea (ea_t ea)
 Does the address belong to a segment with a special type?
idaman DEPRECATED void ida_export lock_segm (const segment_t *segm, bool lock)
 Lock segment pointer.
idaman void ida_export lock_segment_by_ea (ea_t ea, bool lock)
 Lock segment by address.
idaman DEPRECATED bool ida_export is_segm_locked (const segment_t *segm)
 Is a segment pointer locked?
idaman bool ida_export is_segment_locked (ea_t ea)
 Is segment locked by address?
idaman bool ida_export getn_selector (sel_t *sel, ea_t *base, int n)
 Get description of selector (0..get_selector_qty()-1)
idaman size_t ida_export get_selector_qty ()
 Get number of defined selectors.
idaman sel_t ida_export setup_selector (ea_t segbase)
 Allocate a selector for a segment if necessary.
idaman sel_t ida_export allocate_selector (ea_t segbase)
 Allocate a selector for a segment unconditionally.
idaman sel_t ida_export find_free_selector ()
 Find first unused selector.
idaman int ida_export set_selector (sel_t selector, ea_t paragraph)
 Set mapping of selector to a paragraph.
idaman void ida_export del_selector (sel_t selector)
 Delete mapping of a selector.
idaman ea_t ida_export sel2para (sel_t selector)
 Get mapping of a selector.
ea_t idaapi sel2ea (sel_t selector)
 Get mapping of a selector as a linear address.
idaman sel_t ida_export find_selector (ea_t base)
 Find a selector that has mapping to the specified paragraph.
idaman int ida_export enumerate_selectors (int(idaapi *func)(sel_t sel, ea_t para))
 Enumerate all selectors from the translation table.
idaman DEPRECATED ea_t ida_export enumerate_segments_with_selector (sel_t selector, ea_t(idaapi *func)(segment_t *s, void *ud), void *ud=nullptr)
 Enumerate all segments with the specified selector.
idaman ea_t ida_export enumerate_segments_with_selector_ea (sel_t selector, const segment_selector_visitor_t &visitor)
 Enumerate all segments with the specified selector.
idaman DEPRECATED segment_t *ida_export get_segm_by_sel (sel_t selector)
 Get pointer to segment structure.
idaman ea_t ida_export get_segment_ea_by_sel (sel_t selector)
 Get segment start address by its selector.
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.
idaman bool ida_export set_segm_end (ea_t ea, ea_t newend, int flags)
 Set segment end address.
idaman bool ida_export set_segm_start (ea_t ea, ea_t newstart, int flags)
 Set segment start address.
idaman bool ida_export move_segm_start (ea_t ea, ea_t newstart, int mode)
 Move segment start.
idaman const char *ida_export move_segm_strerror (move_segm_code_t code)
 Return string describing error MOVE_SEGM_... code.
idaman DEPRECATED move_segm_code_t ida_export move_segm (segment_t *s, ea_t to, int flags=0)
 This function moves all information to the new address.
idaman move_segm_code_t ida_export move_segment (ea_t seg_ea, ea_t to, int flags=0)
 Move segment to a new address.
idaman move_segm_code_t ida_export rebase_program (adiff_t delta, int flags)
 Rebase the whole program by 'delta' bytes.
idaman DEPRECATED int ida_export change_segment_status (segment_t *s, bool is_deb_segm)
 Convert a debugger segment to a regular segment and vice versa.
idaman int ida_export change_segment_status_by_ea (ea_t ea, bool is_deb_segm)
 Convert a debugger segment to a regular segment and vice versa by address.
idaman bool ida_export take_memory_snapshot (int type)
 Take a memory snapshot of the running process.
idaman bool ida_export is_miniidb ()
 Is the database a miniidb created by the debugger?
idaman DEPRECATED bool ida_export set_segm_base (segment_t *s, ea_t newbase)
 Internal function.
idaman bool ida_export set_segment_base_ea (ea_t seg_ea, ea_t newbase)
 Set segment base.
idaman int ida_export set_group_selector (sel_t grp, sel_t sel)
 Create a new group of segments (used OMF files).
idaman sel_t ida_export get_group_selector (sel_t grpsel)
 Get common selector for a group of segments.
idaman bool ida_export add_segment_translation (ea_t segstart, ea_t mappedseg)
 Add segment translation.
idaman bool ida_export set_segment_translations (ea_t segstart, const eavec_t &transmap)
 Set new translation list.
idaman void ida_export del_segment_translations (ea_t segstart)
 Delete the translation list.
idaman ssize_t ida_export get_segment_translations (eavec_t *transmap, ea_t segstart)
 Get segment translation list.
idaman DEPRECATED ssize_t ida_export get_segment_cmt (qstring *buf, const segment_t *s, bool repeatable)
 Get segment comment.
idaman ssize_t ida_export get_segment_cmt_by_ea (qstring *buf, ea_t ea, bool repeatable)
 Get segment comment by address.
idaman DEPRECATED void ida_export set_segment_cmt (const segment_t *s, const char *cmt, bool repeatable)
 Set segment comment.
idaman void ida_export set_segment_cmt_by_ea (ea_t ea, const char *cmt, bool repeatable)
 Set segment comment by address.
idaman DEPRECATED void ida_export std_out_segm_footer (struct outctx_t &ctx, segment_t *seg)
 Generate segment footer line as a comment line.
idaman void ida_export std_out_segment_footer (struct outctx_t &ctx, ea_t seg_ea)
 Generate segment footer line as a comment line by address.
idaman DEPRECATED int ida_export set_segm_name (segment_t *s, const char *name, int flags=0)
 Rename segment.
idaman int ida_export set_segment_name (ea_t ea, const char *name, int flags=0)
 Rename segment by address.
idaman DEPRECATED ssize_t ida_export get_segm_name (qstring *buf, const segment_t *s, int flags=0)
 Get true segment name by pointer to segment.
idaman ssize_t ida_export get_segment_name (qstring *buf, ea_t ea, int flags=0)
 Get segment name by address.
DEPRECATED ssize_t idaapi get_visible_segm_name (qstring *buf, const segment_t *s)
 Get segment name by pointer to segment.
ssize_t get_segm_expr (qstring *buf, ea_t from, sel_t sel)
 Get colored segment name expression in the form (segname + displacement).
idaman DEPRECATED ssize_t ida_export get_segm_class (qstring *buf, const segment_t *s)
 Get segment class.
idaman ssize_t ida_export get_segment_class (qstring *buf, ea_t ea)
 Get segment class by address.
idaman DEPRECATED int ida_export set_segm_class (segment_t *s, const char *sclass, int flags=0)
 Set segment class.
idaman int ida_export set_segment_class (ea_t ea, const char *sclass, int flags=0)
 Set segment class by address.
idaman uchar ida_export segtype (ea_t ea)
 Get segment type.
idaman const char *ida_export get_segment_alignment (uchar align)
 Get text representation of segment alignment code.
idaman const char *ida_export get_segment_combination (uchar comb)
 Get text representation of segment combination code.
idaman DEPRECATED ea_t ida_export get_segm_para (const segment_t *s)
 Get segment base paragraph.
idaman ea_t ida_export get_segment_para (ea_t ea)
 Get segment base paragraph by address.
idaman DEPRECATED ea_t ida_export get_segm_base (const segment_t *s)
 Get segment base linear address.
idaman ea_t ida_export get_segment_base (ea_t ea)
 Get segment base linear address by address.
idaman DEPRECATED bool ida_export set_segm_addressing (segment_t *s, size_t bitness)
 Change segment addressing mode (16, 32, 64 bits).
idaman bool ida_export set_segment_addressing (ea_t ea, size_t bitness)
 Change segment addressing mode (16, 32, 64 bits) by address.
idaman bool ida_export is_same_segment (ea_t ea1, ea_t ea2)
 Check two addresses belong to one segment.
bool is_debugger_segm (ea_t ea)
 Does the address belong to a debug segment?
bool is_ephemeral_segm (ea_t ea)
 Does the address belong to an ephemeral segment?
idaman ea_t ida_export correct_address (ea_t ea, ea_t from, ea_t to, ea_t size, bool skip_check=false)
idaman bool ida_export update_segm (segment_t *s)
idaman DEPRECATED adiff_t ida_export segm_adjust_diff (const segment_t *s, adiff_t delta)
 Truncate and sign extend a delta depending on the segment.
idaman adiff_t ida_export adjust_segment_diff (ea_t seg_ea, adiff_t delta)
 Truncate and sign extend a delta depending on the segment by address.
idaman DEPRECATED ea_t ida_export segm_adjust_ea (const segment_t *s, ea_t ea)
 Truncate an address depending on the segment.
idaman ea_t ida_export adjust_segment_ea (ea_t seg_ea, ea_t ea)
 Truncate an address depending on the segment by address.

Detailed Description

Functions that deal with segments.

IDA requires that all program addresses belong to segments (each address must belong to exactly one segment). The situation when an address doesn't belong to any segment is allowed as a temporary situation only when the user changes program segmentation. Bytes outside a segment can't be converted to instructions, have names, comments, etc. Each segment has its start address, ending address and represents a contiguous range of addresses. There might be unused holes between segments.

Each segment has its unique segment selector. This selector is used to distinguish the segment from other segments. For 16-bit programs the selector is equal to the segment base paragraph. For 32-bit programs there is special array to translate the selectors to the segment base paragraphs. A selector is a 32/64 bit value.

The segment base paragraph determines the offsets in the segment. If the start address of the segment == (base << 4) then the first offset in the segment will be 0. The start address should be higher or equal to (base << 4). We will call the offsets in the segment 'virtual addresses'. So, the virtual address of the first byte of the segment is

    (start address of segment - segment base linear address)

For IBM PC, the virtual address corresponds to the offset part of the address. For other processors (Z80, for example), virtual addresses correspond to Z80 addresses and linear addresses are used only internally. For MS Windows programs the segment base paragraph is 0 and therefore the segment virtual addresses are equal to linear addresses.

Function Documentation

◆ is_debugger_segm()

bool is_debugger_segm ( ea_t ea)
inline

Does the address belong to a debug segment?

◆ is_ephemeral_segm()

bool is_ephemeral_segm ( ea_t ea)
inline

Does the address belong to an ephemeral segment?

◆ correct_address()

idaman ea_t ida_export correct_address ( ea_t ea,
ea_t from,
ea_t to,
ea_t size,
bool skip_check = false )

◆ update_segm()

idaman bool ida_export update_segm ( segment_t * s)

◆ segm_adjust_diff()

idaman DEPRECATED adiff_t ida_export segm_adjust_diff ( const segment_t * s,
adiff_t delta )

Truncate and sign extend a delta depending on the segment.

Deprecated
Use adjust_segment_diff() for safer access.

◆ adjust_segment_diff()

idaman adiff_t ida_export adjust_segment_diff ( ea_t seg_ea,
adiff_t delta )

Truncate and sign extend a delta depending on the segment by address.

Parameters
seg_eaany address within the segment
deltadelta to adjust
Returns
adjusted delta (0 if no segment at seg_ea)

◆ segm_adjust_ea()

idaman DEPRECATED ea_t ida_export segm_adjust_ea ( const segment_t * s,
ea_t ea )

Truncate an address depending on the segment.

Deprecated
Use adjust_segment_ea() for safer access.

◆ adjust_segment_ea()

idaman ea_t ida_export adjust_segment_ea ( ea_t seg_ea,
ea_t ea )

Truncate an address depending on the segment by address.

Parameters
seg_eaany address within the segment (used to determine bitness)
eaaddress to adjust
Returns
adjusted address (ea if no segment at seg_ea)