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...

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 void ida_export set_visible_segm (segment_t *s, bool visible)
 See #SFL_HIDDEN.
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 void ida_export lock_segm (const segment_t *segm, bool lock)
 Lock segment pointer Locked pointers are guaranteed to remain valid until they are unlocked.
idaman bool ida_export is_segm_locked (const segment_t *segm)
 Is a segment pointer locked?
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 (void)
 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 (void)
 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 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 segment_t *ida_export get_segm_by_sel (sel_t selector)
 Get pointer to segment structure.
idaman 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_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 (void)
 Get number of segments.
idaman segment_t *ida_export getseg (ea_t ea)
 Get pointer to segment by linear address.
idaman segment_t *ida_export getnseg (int n)
 Get pointer to segment by its number.
idaman int ida_export get_segm_num (ea_t ea)
 Get number of segment by address.
idaman segment_t *ida_export get_next_seg (ea_t ea)
 Get pointer to the next segment.
idaman segment_t *ida_export get_prev_seg (ea_t ea)
 Get pointer to the previous segment.
idaman segment_t *ida_export get_first_seg (void)
 Get pointer to the first segment.
idaman segment_t *ida_export 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.
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 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 rebase_program (adiff_t delta, int flags)
 Rebase the whole program by 'delta' bytes.
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.
idaman bool ida_export take_memory_snapshot (int type)
 Take a memory snapshot of the running process.
idaman bool ida_export is_miniidb (void)
 Is the database a miniidb created by the debugger?
idaman bool ida_export set_segm_base (segment_t *s, ea_t newbase)
 Internal function.
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 ssize_t ida_export get_segment_cmt (qstring *buf, const segment_t *s, bool repeatable)
 Get segment comment.
idaman void ida_export set_segment_cmt (const segment_t *s, const char *cmt, bool repeatable)
 Set segment comment.
idaman void ida_export std_out_segm_footer (struct outctx_t &ctx, segment_t *seg)
 Generate segment footer line as a comment line.
idaman int ida_export set_segm_name (segment_t *s, const char *name, int flags=0)
 Rename segment.
idaman ssize_t ida_export get_segm_name (qstring *buf, const segment_t *s, int flags=0)
 Get true segment name by pointer to segment.
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 ssize_t ida_export get_segm_class (qstring *buf, const segment_t *s)
 Get segment class.
idaman int ida_export set_segm_class (segment_t *s, const char *sclass, int flags=0)
 Set segment class.
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 ea_t ida_export get_segm_para (const segment_t *s)
 Get segment base paragraph.
idaman ea_t ida_export get_segm_base (const segment_t *s)
 Get segment base linear address.
idaman bool ida_export set_segm_addressing (segment_t *s, size_t bitness)
 Change segment addressing mode (16, 32, 64 bits).
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 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 ea_t ida_export segm_adjust_ea (const segment_t *s, ea_t ea)
 Truncate an address depending on the segment.

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 adiff_t ida_export segm_adjust_diff ( const segment_t * s,
adiff_t delta )

Truncate and sign extend a delta depending on the segment.

◆ segm_adjust_ea()

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

Truncate an address depending on the segment.