Functions that deal with segments. More...
Classes | |
class | segment_t |
Describes a program segment. More... | |
class | lock_segment |
Helper class to lock a segment pointer so it stays valid. More... | |
Macros | |
#define | SREG_NUM 16 |
Maximum number of segment registers is 16 (see segregs.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) boundary. More... | |
#define | saRel4K 6 |
This value is used by the PharLap OMF for page (4K) alignment. 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 | ADDSEG_NOSREG 0x0001 |
set all default segment register values to BADSEL (undefine all default segment registers) | |
#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 ranges of the created segment. More... | |
#define | ADDSEG_NOAA 0x0040 |
do not mark new segment for auto-analysis | |
#define | ADDSEG_IDBENC 0x0080 |
'name' and 'sclass' are given in the IDB encoding; non-ASCII bytes will be decoded accordingly | |
#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 (for set_segm_start()) | |
#define | SEGMOD_SPARSE 0x0040 |
use sparse storage if extending the segment (for set_segm_start(), set_segm_end()) | |
#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 | MSF_PRIORITY 0x0020 |
loader segments will overwrite any existing debugger segments when moved. More... | |
#define | MSF_NETNODES 0x0080 |
move netnodes instead of changing inf.netdelta (this is slower); valid for rebase_program() | |
#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 |
Cannot move segments by an odd number of bytes. | |
#define | MOVE_SEGM_ORPHAN -7 |
Orphan bytes hinder segment movement. | |
#define | MOVE_SEGM_DEBUG -8 |
Debugger segments cannot be moved. | |
#define | MOVE_SEGM_SOURCEFILES -9 |
Source files ranges of addresses hinder segment movement. | |
#define | MOVE_SEGM_MAPPING -10 |
Memory mapping ranges of addresses hinder segment movement. | |
#define | MOVE_SEGM_INVAL -11 |
Invalid argument (delta/target does not fit the address space) | |
#define | CSS_OK 0 |
ok | |
#define | CSS_NODBG -1 |
debugger is not running | |
#define | CSS_NORANGE -2 |
could not find corresponding memory range | |
#define | CSS_NOMEM -3 |
not enough memory (might be because the segment is too big) | |
#define | CSS_BREAK -4 |
memory reading process stopped by user | |
#define | SNAP_ALL_SEG 0 |
Take a snapshot of all segments. | |
#define | SNAP_LOAD_SEG 1 |
Take a snapshot of loader segments. | |
#define | SNAP_CUR_SEG 2 |
Take a snapshot of current segment. | |
#define | MAX_GROUPS 8 |
max number of segment groups | |
#define | MAX_SEGM_TRANSLATIONS 64 |
max number of segment translations | |
Segment flag: ORG directive | |
See SFL_COMORG | |
#define | SFL_OBOK 0x02 |
Orgbase is present? (IDP dependent field) | |
Segment flag: orgbase | |
See SFL_OBOK | |
#define | SFL_HIDDEN 0x04 |
Is the segment hidden? | |
Segment flag: hidden | |
See SFL_HIDDEN | |
#define | SFL_DEBUG 0x08 |
Is the segment created for the debugger?. More... | |
Segment flag: debugger segment | |
See SFL_DEBUG | |
#define | SFL_LOADER 0x10 |
Is the segment created by the loader? | |
Segment flag: loader segment | |
See SFL_LOADER | |
#define | SFL_HIDETYPE 0x20 |
Hide segment type (do not print it in the listing) | |
Segment flag: hide segment type | |
See SFL_HIDETYPE | |
#define | SFL_HEADER 0x40 |
Header segment (do not create offsets to it in the disassembly) | |
Segment flag: header segment | |
See SFL_HEADER | |
#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 |
Functions | |
CASSERT (sizeof(segment_t)==104) | |
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?. More... | |
idaman bool ida_export | is_spec_ea (ea_t ea) |
Does the address belong to a segment with a special type?. More... | |
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. More... | |
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. 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 | sel2para (sel_t selector) |
Get mapping of a selector. More... | |
ea_t idaapi | 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=nullptr) |
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 *NONNULL 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, int flags=0) |
Add a new segment, second form. More... | |
idaman bool ida_export | del_segm (ea_t ea, int flags) |
Delete a segment. More... | |
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. More... | |
idaman segment_t *ida_export | getnseg (int n) |
Get pointer to segment by its number. More... | |
idaman int ida_export | get_segm_num (ea_t ea) |
Get number of segment by address. More... | |
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. 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 (int type) |
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) |
Create a new group of segments (used OMF files). 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 eavec_t &transmap) |
Set new translation list. More... | |
idaman void ida_export | del_segment_translations (ea_t segstart) |
Delete the translation list. More... | |
idaman ssize_t ida_export | get_segment_translations (eavec_t *transmap, ea_t segstart) |
Get segment translation list. More... | |
idaman ssize_t ida_export | get_segment_cmt (qstring *buf, const segment_t *s, bool repeatable) |
Get segment comment. More... | |
idaman void ida_export | set_segment_cmt (const segment_t *s, const char *cmt, bool repeatable) |
Set segment comment. More... | |
idaman void ida_export | std_out_segm_footer (struct outctx_t &ctx, segment_t *seg) |
Generate segment footer line as a comment line. More... | |
idaman int ida_export | set_segm_name (segment_t *s, const char *name, int flags=0) |
Rename segment. More... | |
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. More... | |
ssize_t idaapi | get_visible_segm_name (qstring *buf, const segment_t *s) |
Get segment name by pointer to segment. More... | |
ssize_t | get_segm_expr (qstring *buf, ea_t from, sel_t sel) |
Get colored segment name expression in the form (segname + displacement). More... | |
idaman ssize_t ida_export | get_segm_class (qstring *buf, const segment_t *s) |
Get segment class. More... | |
idaman int ida_export | set_segm_class (segment_t *s, const char *sclass, int flags=0) |
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, 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.
Macro Definition Documentation
◆ saRelDble
#define saRelDble 5 |
Relocatable, aligned on a double word (4-byte) boundary.
◆ saRel4K
#define saRel4K 6 |
This value is used by the PharLap OMF for page (4K) alignment.
It is not supported by LINK.
◆ scPriv
#define scPriv 0 |
Private.
Do not combine with any other program segment.
◆ scPub
#define scPub 2 |
Public.
Combine by appending at an offset that meets the alignment requirement.
◆ scStack
#define scStack 5 |
Stack.
Combine as for C=2. This combine type forces byte alignment.
◆ SEG_XTRN
#define SEG_XTRN 1 |
* segment with 'extern' definitions.
no instructions are allowed
◆ ADDSEG_NOTRUNC
#define ADDSEG_NOTRUNC 0x0004 |
don't truncate the new segment at the beginning of the next segment if they overlap.
destroy/truncate old segments instead.
◆ ADDSEG_FILLGAP
#define ADDSEG_FILLGAP 0x0010 |
fill gap between new segment and previous one.
i.e. if such a gap exists, and this gap is less than 64K, then fill the gap by extending the previous segment and adding .align directive to it. This way we avoid gaps between segments. too many gaps lead to a virtual array failure. it cannot hold more than ~1000 gaps.
◆ ADDSEG_SPARSE
#define ADDSEG_SPARSE 0x0020 |
use sparse storage method for the new ranges of the created segment.
please note that the ranges that were already enabled before creating the segment will not change their storage type.
◆ MSF_FIXONCE
#define MSF_FIXONCE 0x0008 |
call loader only once with the special calling method.
valid for rebase_program(). see loader_t::move_segm.
◆ MSF_PRIORITY
#define MSF_PRIORITY 0x0020 |
loader segments will overwrite any existing debugger segments when moved.
valid for move_segm()
Function Documentation
◆ is_spec_segm()
idaman bool ida_export is_spec_segm | ( | uchar | seg_type | ) |
Has segment a special type?.
◆ is_spec_ea()
idaman bool ida_export is_spec_ea | ( | ea_t | ea | ) |
Does the address belong to a segment with a special type?.
(SEG_XTRN, SEG_GRP, SEG_ABSSYM, SEG_COMM)
- Parameters
-
ea linear address
◆ lock_segm()
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.
Ranges with locked pointers cannot be deleted or moved.
◆ setup_selector()
idaman sel_t ida_export setup_selector | ( | ea_t | segbase | ) |
Allocate a selector for a segment if necessary.
You must call this function before calling add_segm_ex(). add_segm() calls this function itself, so you don't need to allocate a selector. This function will allocate a selector if 'segbase' requires more than 16 bits and the current processor is IBM PC. Otherwise it will return the segbase value.
- Parameters
-
segbase a new segment base paragraph
- Returns
- the allocated selector number
◆ allocate_selector()
idaman sel_t ida_export allocate_selector | ( | ea_t | segbase | ) |
Allocate a selector for a segment unconditionally.
You must call this function before calling add_segm_ex(). add_segm() calls this function itself, so you don't need to allocate a selector. This function will allocate a new free selector and setup its mapping using find_free_selector() and set_selector() functions.
- Parameters
-
segbase a new segment base paragraph
- Returns
- the allocated selector number
◆ find_free_selector()
idaman sel_t ida_export find_free_selector | ( | void | ) |
Find first unused selector.
- Returns
- a number >= 1
◆ set_selector()
idaman int ida_export set_selector | ( | sel_t | selector, |
ea_t | paragraph | ||
) |
Set mapping of selector to a paragraph.
You should call this function _before_ creating a segment which uses the selector, otherwise the creation of the segment will fail.
- Parameters
-
selector number of selector to map - if selector == BADSEL, then return 0 (fail)
- if the selector has had a mapping, old mapping is destroyed
- if the selector number is equal to paragraph value, then the mapping is destroyed because we don't need to keep trivial mappings.
paragraph paragraph to map selector
- Return values
-
1 ok 0 failure (bad selector or too many mappings)
◆ del_selector()
idaman void ida_export del_selector | ( | sel_t | selector | ) |
Delete mapping of a selector.
Be wary of deleting selectors that are being used in the program, this can make a mess in the segments.
- Parameters
-
selector number of selector to remove from the translation table
◆ sel2para()
idaman ea_t ida_export sel2para | ( | sel_t | selector | ) |
Get mapping of a selector.
- Parameters
-
selector number of selector to translate
- Returns
- paragraph the specified selector is mapped to. if there is no mapping, returns 'selector'.
◆ sel2ea()
|
inline |
Get mapping of a selector as a linear address.
- Parameters
-
selector number of selector to translate to linear address
- Returns
- linear address the specified selector is mapped to. if there is no mapping, returns to_ea(selector,0);
◆ find_selector()
idaman sel_t ida_export find_selector | ( | ea_t | base | ) |
Find a selector that has mapping to the specified paragraph.
- Parameters
-
base paragraph to search in the translation table
- Returns
- selector value or base
◆ enumerate_selectors()
idaman int ida_export enumerate_selectors | ( | int(idaapi *)(sel_t sel, ea_t para) | func | ) |
Enumerate all selectors from the translation table.
This function calls 'func' for each selector in the translation table. If 'func' returns non-zero code, enumeration is stopped and this code is returned.
- Parameters
-
func callback function - sel: selector number
- para: selector mapping
- Returns
- 0 or code returned by 'func'.
◆ enumerate_segments_with_selector()
idaman ea_t ida_export enumerate_segments_with_selector | ( | sel_t | selector, |
ea_t(idaapi *)(segment_t *s, void *ud) | func, | ||
void * | ud = nullptr |
||
) |
Enumerate all segments with the specified selector.
This function will call the callback function 'func' for each segment that has the specified selector. Enumeration starts from the last segment and stops at the first segment (reverse order). If the callback function 'func' returns a value != BADADDR, the enumeration is stopped and this value is returned to the caller.
- Parameters
-
selector segments that have this selector are enumerated func callback function - s: pointer to segment structure
- ud: user data
ud pointer to user data. this pointer will be passed to the callback function
- Returns
- BADADDR or the value returned by the callback function 'func'
◆ get_segm_by_sel()
idaman segment_t *ida_export get_segm_by_sel | ( | sel_t | selector | ) |
Get pointer to segment structure.
This function finds a segment by its selector. If there are several segments with the same selectors, the last one will be returned.
- Parameters
-
selector a segment with the specified selector will be returned
- Returns
- pointer to segment or nullptr
◆ add_segm_ex()
idaman bool ida_export add_segm_ex | ( | segment_t *NONNULL | 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.start_ea==BADADDR then s.start_ea <- get_segm_base(&s)
- if s.end_ea==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.end_ea < s.start_ea, then fail.
- if s.end_ea is too high and the new segment would overlap the next segment, s.end_ea is adjusted properly.
name name of new segment. may be nullptr. if specified, the segment is immediately renamed sclass class of the segment. may be nullptr. if specified, the segment class is immediately changed flags Add segment flags
- Return values
-
1 ok 0 failed, a warning message is displayed
◆ add_segm()
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.
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 <- to_ea(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 nullptr sclass class of the segment. may be nullptr. type of the new segment is modified if class is one of predefined names: flags Add segment flags
- Return values
-
1 ok 0 failed, a warning message is displayed
◆ del_segm()
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'.
◆ getseg()
idaman segment_t *ida_export getseg | ( | ea_t | ea | ) |
Get pointer to segment by linear address.
- Parameters
-
ea linear address belonging to the segment
- Returns
- nullptr or pointer to segment structure
◆ getnseg()
idaman segment_t *ida_export getnseg | ( | int | n | ) |
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
- nullptr or pointer to segment structure
◆ get_segm_num()
idaman int ida_export get_segm_num | ( | ea_t | ea | ) |
Get number of segment by address.
- Parameters
-
ea linear address belonging to the segment
- Returns
- -1 if no segment occupies the specified address. otherwise returns number of the specified segment (0..get_segm_qty()-1)
◆ get_segm_by_name()
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 nullptr.
- Returns
- nullptr or pointer to segment structure
◆ set_segm_end()
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
◆ set_segm_start()
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
◆ move_segm_start()
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
◆ move_segm()
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. For the file format dependent address sensitive information, loader_t::move_segm is called. Also IDB notification event idb_event::segm_moved is called.
- Parameters
-
s segment to move to new segment start address flags Move segment flags
- Returns
- Move segment result codes
◆ rebase_program()
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
◆ change_segment_status()
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
◆ take_memory_snapshot()
idaman bool ida_export take_memory_snapshot | ( | int | type | ) |
Take a memory snapshot of the running process.
- Parameters
-
type specifies which snapshot we want (see SNAP_ Snapshot types)
- Returns
- success
◆ is_miniidb()
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
◆ set_group_selector()
idaman int ida_export set_group_selector | ( | sel_t | grp, |
sel_t | sel | ||
) |
Create a new group of segments (used OMF files).
- Parameters
-
grp selector of group segment (segment type is SEG_GRP) You should create an 'empty' (1 byte) group segment It won't contain anything and will be used to redirect references to the group of segments to the common selector. sel common selector of all segments belonging to the segment You should create all segments within the group with the same selector value.
- Returns
- 1 ok
- 0 too many groups (see MAX_GROUPS)
◆ get_group_selector()
idaman sel_t ida_export get_group_selector | ( | sel_t | grpsel | ) |
Get common selector for a group of segments.
- Parameters
-
grpsel selector of group segment
- Returns
- common selector of the group or 'grpsel' if no such group is found
◆ add_segment_translation()
idaman bool ida_export add_segment_translation | ( | ea_t | segstart, |
ea_t | mappedseg | ||
) |
Add segment translation.
- Parameters
-
segstart start address of the segment to add translation to mappedseg start address of the overlayed segment
- Return values
-
1 ok 0 too many translations or bad segstart
◆ set_segment_translations()
idaman bool ida_export set_segment_translations | ( | ea_t | segstart, |
const eavec_t & | transmap | ||
) |
Set new translation list.
- Parameters
-
segstart start address of the segment to add translation to transmap vector of segment start addresses for the translation list. If transmap is empty, the translation list is deleted.
- Return values
-
1 ok 0 too many translations or bad segstart
◆ del_segment_translations()
idaman void ida_export del_segment_translations | ( | ea_t | segstart | ) |
Delete the translation list.
- Parameters
-
segstart start address of the segment to delete translation list
◆ get_segment_translations()
Get segment translation list.
- Parameters
-
transmap vector of segment start addresses for the translation list segstart start address of the segment to get information about
- Returns
- -1 if no translation list or bad segstart. otherwise returns size of translation list.
◆ get_segment_cmt()
Get segment comment.
- Parameters
-
buf buffer for the comment s pointer to segment structure repeatable 0: get regular comment. 1: get repeatable comment.
- Returns
- size of comment or -1
◆ set_segment_cmt()
idaman void ida_export set_segment_cmt | ( | const segment_t * | s, |
const char * | cmt, | ||
bool | repeatable | ||
) |
Set segment comment.
- Parameters
-
s pointer to segment structure cmt comment string, may be multiline (with '
'). maximal size is 4096 bytes. Use empty str ("") to delete commentrepeatable 0: set regular comment. 1: set repeatable comment.
◆ std_out_segm_footer()
Generate segment footer line as a comment line.
This function may be used in IDP modules to generate segment footer if the target assembler doesn't have 'ends' directive.
◆ set_segm_name()
idaman int ida_export set_segm_name | ( | segment_t * | s, |
const char * | name, | ||
int | flags = 0 |
||
) |
Rename segment.
The new name is validated (see validate_name). A segment always has a name. If you hadn't specified a name, the kernel will assign it "seg###" name where ### is segment number.
- Parameters
-
s pointer to segment (may be nullptr) name new segment name flags ADDSEG_IDBENC or 0
- Return values
-
1 ok, name is good and segment is renamed 0 failure, name is bad or segment is nullptr
◆ get_segm_name()
Get true segment name by pointer to segment.
- Parameters
-
buf output buffer. cannot be nullptr s pointer to segment flags 0-return name as is; 1-substitute bad symbols with _ 1 corresponds to GN_VISIBLE
- Returns
- size of segment name (-1 if s==nullptr)
◆ get_visible_segm_name()
Get segment name by pointer to segment.
- Parameters
-
buf output buffer. cannot be nullptr s pointer to segment
- Returns
- size of segment name (-1 if s==nullptr)
◆ get_segm_expr()
Get colored segment name expression in the form (segname + displacement).
- Parameters
-
buf output buffer to hold segment expression from linear address of instruction operand or data referring to the name. This address will be used to get fixup information, so it should point to exact position of operand in the instruction. sel value to convert to segment expression
- Returns
- size of segment expression or -1
◆ get_segm_class()
Get segment class.
Segment class is arbitrary text (max 8 characters).
- Parameters
-
buf output buffer. cannot be nullptr. s pointer to segment
- Returns
- size of segment class (-1 if s==nullptr or bufsize<=0)
◆ set_segm_class()
idaman int ida_export set_segm_class | ( | segment_t * | s, |
const char * | sclass, | ||
int | flags = 0 |
||
) |
Set segment class.
- Parameters
-
s pointer to segment (may be nullptr) sclass segment class (may be nullptr). If segment type is SEG_NORM and segment class is one of predefined names, then segment type is changed to: flags Add segment flags
- Return values
-
1 ok, name is good and segment is renamed 0 failure, name is nullptr or bad or segment is nullptr
◆ segtype()
idaman uchar ida_export segtype | ( | ea_t | ea | ) |
Get segment type.
- Parameters
-
ea any linear address within the segment
- Returns
- Segment types, SEG_UNDF if no segment found at 'ea'
◆ get_segment_alignment()
idaman const char *ida_export get_segment_alignment | ( | uchar | align | ) |
Get text representation of segment alignment code.
- Returns
- text digestable by IBM PC assembler.
◆ get_segment_combination()
idaman const char *ida_export get_segment_combination | ( | uchar | comb | ) |
Get text representation of segment combination code.
- Returns
- text digestable by IBM PC assembler.
◆ get_segm_para()
idaman ea_t ida_export get_segm_para | ( | const segment_t * | s | ) |
Get segment base paragraph.
Segment base paragraph may be converted to segment base linear address using to_ea() function. In fact, to_ea(get_segm_para(s), 0) == get_segm_base(s).
- Parameters
-
s pointer to segment
- Returns
- 0 if s == nullptr, the segment base paragraph
◆ get_segm_base()
idaman ea_t ida_export get_segm_base | ( | const segment_t * | s | ) |
Get segment base linear address.
Segment base linear address is used to calculate virtual addresses. The virtual address of the first byte of the segment will be (start address of segment - segment base linear address)
- Parameters
-
s pointer to segment
- Returns
- 0 if s == nullptr, otherwise segment base linear address
◆ set_segm_addressing()
idaman bool ida_export set_segm_addressing | ( | segment_t * | s, |
size_t | bitness | ||
) |
Change segment addressing mode (16, 32, 64 bits).
You must use this function to change segment addressing, never change the 'bitness' field directly. This function will delete all instructions, comments and names in the segment
- Parameters
-
s pointer to segment bitness new addressing mode of segment - 2: 64bit segment
- 1: 32bit segment
- 0: 16bit segment
- Returns
- success
Generated by