IDA SDK

- Main Page
- Header Files
- Classes
- Modules

- File List
- File Members

Classes | Functions | Macros | Variables
segment.hpp File Reference

## Detailed Description

Functions that deal with program segmentation.

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.

## Classes
class | segment_t
| Describes a program segment. More...
class | lock_segment
| Helper class to lock a segment pointer so it stays valid. More...

## Functions
bool | is_visible_segm (segment_t *s)
| See SFL_HIDDEN.
bool | is_finally_visible_segm (segment_t *s)
| See SFL_HIDDEN, SW_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?. More...
idaman bool ida_export | is_spec_ea (ea_t ea)
| Does the address belong to a segment with a special type?. More...
bool | is_segm_locked (const segment_t *segm)
| Is a segment pointer locked?
idaman bool ida_export | getn_selector (int n, sel_t *sel, ea_t *base)
| Get description of selector (0..get_selector_qty()-1)
idaman int 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. More...
idaman sel_t ida_export | allocate_selector (ea_t segbase)
| Allocate a selector for a segment unconditionally. More...
idaman sel_t ida_export | find_free_selector (void)
| Find first unused selector. More...
idaman int ida_export | set_selector (sel_t selector, ea_t paragraph)
| Set mapping of selector to a paragraph. More...
idaman void ida_export | del_selector (sel_t selector)
| Delete mapping of a selector. More...
idaman ea_t ida_export | ask_selector (sel_t selector)
| Get mapping of a selector. More...
idaman ea_t ida_export | sel2ea (sel_t selector)
| Get mapping of a selector as a linear address. More...
idaman sel_t ida_export | find_selector (ea_t base)
| Find a selector that has mapping to the specified paragraph. More...
idaman int ida_export | enumerate_selectors (int(idaapi *func)(sel_t sel, ea_t para))
| Enumerate all selectors from the translation table. More...
idaman ea_t ida_export | enumerate_segments_with_selector (sel_t selector, ea_t(idaapi *func)(segment_t *s, void *ud), void *ud)
| Enumerate all segments with the specified selector. More...
idaman segment_t *ida_export | get_segm_by_sel (sel_t selector)
| Get pointer to segment structure. More...
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.
idaman int ida_export | set_group_selector (sel_t grp, sel_t sel)
| Initialize groups. More...
idaman sel_t ida_export | get_group_selector (sel_t grpsel)
| Get common selector for a group of segments. More...
idaman bool ida_export | add_segment_translation (ea_t segstart, ea_t mappedseg)
| Add segment translation. More...
idaman bool ida_export | set_segment_translations (ea_t segstart, const ea_t *transmap)
| Set new translation list. More...
bool | del_segment_translations (ea_t ea)
| Delete the translation list.
idaman ea_t *ida_export | get_segment_translations (ea_t segstart, ea_t *buf, int bufsize)
| Get segment translation list. More...
char * | get_segment_cmt (const segment_t *s, bool repeatable)
| Get segment comment. More...
void | set_segment_cmt (segment_t *s, const char *cmt, bool repeatable)
| Set segment comment. More...
void | del_segment_cmt (segment_t *s, bool repeatable)
| Delete segment comment. More...
idaman void ida_export | std_gen_segm_footer (ea_t ea)
| Generate segment footer line as a comment line. More...
idaman int ida_export | vset_segm_name (segment_t *s, const char *format, va_list va)
| See set_segm_name()
int | set_segm_name (segment_t *s, const char *format,...)
| Rename segment. More...
idaman ssize_t ida_export | get_true_segm_name (const segment_t *s, char *buf, size_t bufsize)
| Get true segment name by pointer to segment. More...
idaman ssize_t ida_export | get_segm_name (const segment_t *s, char *buf, size_t bufsize)
| Get segment name by pointer to segment. More...
ssize_t idaapi | get_segm_name (ea_t ea, char *buf, size_t bufsize)
| Get segment name by linear address. More...
char * | get_segm_expr (ea_t from, sel_t sel, char *buf, size_t bufsize)
| Get colored segment name expression in the form (segname + displacement). More...
idaman ssize_t ida_export | get_segm_class (const segment_t *s, char *buf, size_t bufsize)
| Get segment class. More...
idaman int ida_export | set_segm_class (segment_t *s, const char *sclass)
| Set segment class. More...
idaman uchar ida_export | segtype (ea_t ea)
| Get segment type. More...
idaman const char *ida_export | get_segment_alignment (uchar align)
| Get text representation of segment alignment code. More...
idaman const char *ida_export | get_segment_combination (uchar comb)
| Get text representation of segment combination code. More...
idaman ea_t ida_export | get_segm_para (const segment_t *s)
| Get segment base paragraph. More...
idaman ea_t ida_export | get_segm_base (const segment_t *s)
| Get segment base linear address. More...
idaman bool ida_export | set_segm_addressing (segment_t *s, size_t bitness)
| Change segment addressing mode (16, 32, 64 bits). More...
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?
ea_t | correct_address (ea_t ea, ea_t from, ea_t to, ea_t size)
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.

## Macros
#define | SREG_NUM 16
| Maximum number of segment registers is 16 (see srarea.hpp)
#define | saAbs 0
| Absolute segment.
#define | saRelByte 1
| Relocatable, byte aligned.
#define | saRelWord 2
| Relocatable, word (2-byte) aligned.
#define | saRelPara 3
| Relocatable, paragraph (16-byte) aligned.
#define | saRelPage 4
| Relocatable, aligned on 256-byte boundary.
#define | saRelDble 5
| Relocatable, aligned on a double word (4-byte) More...
#define | saRel4K 6
| This value is used by the PharLap OMF for page (4K) More...
#define | saGroup 7
| Segment group.
#define | saRel32Bytes 8
| 32 bytes
#define | saRel64Bytes 9
| 64 bytes
#define | saRelQword 10
| 8 bytes
#define | saRel128Bytes 11
| 128 bytes
#define | saRel512Bytes 12
| 512 bytes
#define | saRel1024Bytes 13
| 1024 bytes
#define | saRel2048Bytes 14
| 2048 bytes
#define | saRel_MAX_ALIGN_CODE saRel2048Bytes
#define | scPriv 0
| Private. More...
#define | scGroup 1
| Segment group.
#define | scPub 2
| Public. More...
#define | scPub2 4
| As defined by Microsoft, same as C=2 (public).
#define | scStack 5
| Stack. More...
#define | scCommon 6
| Common. Combine by overlay using maximum size.
#define | scPub3 7
| As defined by Microsoft, same as C=2 (public).
#define | sc_MAX_COMB_CODE scPub3
#define | SEGPERM_EXEC 1
| Execute.
#define | SEGPERM_WRITE 2
| Write.
#define | SEGPERM_READ 4
| Read.
#define | SEGPERM_MAXVAL (SEGPERM_EXEC + SEGPERM_WRITE + SEGPERM_READ)
#define | SEG_MAX_BITNESS_CODE 2
#define | SFL_COMORG 0x01
| IDP dependent field (IBM PC: if set, ORG directive is not commented out)
#define | SFL_OBOK 0x02
| Orgbase is present? (IDP dependent field)
#define | SFL_HIDDEN 0x04
| Is the segment hidden?
#define | SFL_DEBUG 0x08
| Is the segment created for the debugger?. More...
#define | SFL_LOADER 0x10
| Is the segment created by the loader?
#define | SFL_HIDETYPE 0x20
| Hide segment type (do not print it in the listing)
#define | SEG_NORM 0
| unknown type, no assumptions
#define | SEG_XTRN 1
| * segment with 'extern' definitions. More...
#define | SEG_CODE 2
| code segment
#define | SEG_DATA 3
| data segment
#define | SEG_IMP 4
| java: implementation segment
#define | SEG_GRP 6
| * group of segments
#define | SEG_NULL 7
| zero-length segment
#define | SEG_UNDF 8
| undefined segment type (not used)
#define | SEG_BSS 9
| uninitialized segment
#define | SEG_ABSSYM 10
| * segment with definitions of absolute symbols
#define | SEG_COMM 11
| * segment with communal definitions
#define | SEG_IMEM 12
| internal processor memory & sfr (8051)
#define | SEG_MAX_SEGTYPE_CODE SEG_IMEM
#define | ADDSEG_NOSREG 0x0001
| set all default segment register values to BADSEL More...
#define | ADDSEG_OR_DIE 0x0002
| qexit() if can't add a segment
#define | ADDSEG_NOTRUNC 0x0004
| don't truncate the new segment at the beginning of the next segment if they overlap. More...
#define | ADDSEG_QUIET 0x0008
| silent mode, no "Adding segment..." in the messages window
#define | ADDSEG_FILLGAP 0x0010
| fill gap between new segment and previous one. More...
#define | ADDSEG_SPARSE 0x0020
| use sparse storage method for the new segment
#define | ADDSEG_NOAA 0x0040
| do not mark new segment for auto-analysis
#define | SEGMOD_KILL 0x0001
| disable addresses if segment gets shrinked or deleted
#define | SEGMOD_KEEP 0x0002
| keep information (code & data, etc)
#define | SEGMOD_SILENT 0x0004
| be silent
#define | SEGMOD_KEEP0 0x0008
| flag for internal use, don't set
#define | SEGMOD_KEEPSEL 0x0010
| do not try to delete unused selector
#define | SEGMOD_NOMOVE 0x0020
| don't move info from the start of segment to the new start address More...
#define | SEGMOD_SPARSE 0x0040
| use sparse storage if extending the segment More...
#define | MSF_SILENT 0x0001
| don't display a "please wait" box on the screen
#define | MSF_NOFIX 0x0002
| don't call the loader to fix relocations
#define | MSF_LDKEEP 0x0004
| keep the loader in the memory (optimization)
#define | MSF_FIXONCE 0x0008
| call loader only once with the special calling method. More...
#define | MOVE_SEGM_OK 0
| all ok
#define | MOVE_SEGM_PARAM -1
| The specified segment does not exist.
#define | MOVE_SEGM_ROOM -2
| Not enough free room at the target address.
#define | MOVE_SEGM_IDP -3
| IDP module forbids moving the segment.
#define | MOVE_SEGM_CHUNK -4
| Too many chunks are defined, can't move.
#define | MOVE_SEGM_LOADER -5
| The segment has been moved but the loader complained.
#define | MOVE_SEGM_ODD -6
| Can not move segments by an odd number of bytes.
#define | MOVE_SEGM_ORPHAN -7
| Orphan bytes hinder segment movement.
#define | CSS_OK 0
| ok
#define | CSS_NODBG -1
| debugger is not running
#define | CSS_NOAREA -2
| could not find corresponding memory area
#define | CSS_NOMEM -3
| not enough memory (might be because the segment More...
#define | CSS_BREAK -4
| memory reading process stopped by user
#define | MAX_GROUPS 8
| max number of segment groups
#define | MAX_SEGM_TRANSLATIONS 64
| max number of segment translations

## Variables
idaman areacb_t ida_export_data | segs
| Area control block for segments.