Module ida_segment
[frames] | no frames]

Module ida_segment

IDA Plugin SDK API wrapper: segment

Classes
  segment_t
Proxy of C++ segment_t class
  lock_segment
Proxy of C++ lock_segment class
Functions
bool
is_visible_segm(s)
See 'SFL_HIDDEN' .
bool
is_finally_visible_segm(s)
See 'SFL_HIDDEN' , 'SCF_SHHID_SEGM' .
 
set_visible_segm(s, visible)
See 'SFL_HIDDEN' .
bool
is_spec_segm(seg_type)
Has segment a special type?.
bool
is_spec_ea(ea)
Does the address belong to a segment with a special type?.
 
lock_segm(segm, lock)
Lock segment pointer Locked pointers are guaranteed to remain valid until they are unlocked.
bool
is_segm_locked(segm)
Is a segment pointer locked?
bool
getn_selector(n)
Get description of selector (0..
int
get_selector_qty()
Get number of defined selectors.
sel_t
setup_selector(segbase)
Allocate a selector for a segment if necessary.
sel_t
allocate_selector(segbase)
Allocate a selector for a segment unconditionally.
sel_t
find_free_selector()
Find first unused selector.
int
set_selector(selector, paragraph)
Set mapping of selector to a paragraph.
 
del_selector(selector)
Delete mapping of a selector.
ea_t
sel2para(selector)
Get mapping of a selector.
ea_t
sel2ea(selector)
Get mapping of a selector as a linear address.
sel_t
find_selector(base)
Find a selector that has mapping to the specified paragraph.
segment_t
get_segm_by_sel(selector)
Get pointer to segment structure.
bool
add_segm_ex(s, name, sclass, flags)
Add a new segment.
bool
add_segm(para, start, end, name, sclass, flags=0)
Add a new segment, second form.
bool
del_segm(ea, flags)
Delete a segment.
int
get_segm_qty()
Get number of segments.
segment_t
getseg(ea)
Get pointer to segment by linear address.
segment_t
getnseg(n)
Get pointer to segment by its number.Obsoleted because it can slow down the debugger (it has to refresh the whole memory segmentation to calculate the correct answer)
int
get_segm_num(ea)
Get number of segment by address.
segment_t
get_next_seg(ea)
Get pointer to the next segment.
segment_t
get_prev_seg(ea)
Get pointer to the previous segment.
segment_t
get_first_seg()
Get pointer to the first segment.
segment_t
get_last_seg()
Get pointer to the last segment.
segment_t
get_segm_by_name(name)
Get pointer to segment by its name.
bool
set_segm_end(ea, newend, flags)
Set segment end address.
bool
set_segm_start(ea, newstart, flags)
Set segment start address.
bool
move_segm_start(ea, newstart, mode)
Move segment start.
int
move_segm(s, to, flags=0)
Move a segment to a new address.
int
change_segment_status(s, is_deb_segm)
Convert a debugger segment to a regular segment and vice versa.
bool
take_memory_snapshot(only_loader_segs)
Take a memory snapshot of the running process.
bool
is_miniidb()
Is the database a miniidb created by the debugger?.
bool
set_segm_base(s, newbase)
Internal function.
int
set_group_selector(grp, sel)
Initialize groups.
sel_t
get_group_selector(grpsel)
Get common selector for a group of segments.
bool
add_segment_translation(segstart, mappedseg)
Add segment translation.
bool
set_segment_translations(segstart, transmap)
Set new translation list.
 
del_segment_translations(segstart)
Delete the translation list
ssize_t
get_segment_translations(transmap, segstart)
Get segment translation list.
ssize_t
get_segment_cmt(s, repeatable)
Get segment comment.
 
set_segment_cmt(s, cmt, repeatable)
Set segment comment.
 
std_out_segm_footer(ctx, seg)
Generate segment footer line as a comment line.
int
set_segm_name(s, name, flags=0)
Rename segment.
ssize_t
get_segm_name(s, flags=0)
Get true segment name by pointer to segment.
ssize_t
get_visible_segm_name(s)
Get segment name by pointer to segment.
ssize_t
get_segm_class(s)
Get segment class.
int
set_segm_class(s, sclass, flags=0)
Set segment class.
uchar
segtype(ea)
Get segment type.
char const *
get_segment_alignment(align)
Get text representation of segment alignment code.
char const *
get_segment_combination(comb)
Get text representation of segment combination code.
ea_t
get_segm_para(s)
Get segment base paragraph.
ea_t
get_segm_base(s)
Get segment base linear address.
bool
set_segm_addressing(s, bitness)
Change segment addressing mode (16, 32, 64 bits).
bool
update_segm(s)
adiff_t
segm_adjust_diff(s, delta)
Truncate and sign extend a delta depending on the segment.
ea_t
segm_adjust_ea(s, ea)
Truncate an address depending on the segment.
sel_t
get_defsr(s, reg)
 
set_defsr(s, reg, value)
int
rebase_program(delta, flags)
Rebase the whole program by 'delta' bytes.
Variables
  SREG_NUM = 16
Maximum number of segment registers is 16 (see 'segregs.hpp' )
  saAbs = 0
Absolute segment.
  saRelByte = 1
Relocatable, byte aligned.
  saRelWord = 2
Relocatable, word (2-byte) aligned.
  saRelPara = 3
Relocatable, paragraph (16-byte) aligned.
  saRelPage = 4
Relocatable, aligned on 256-byte boundary.
  saRelDble = 5
boundary.
  saRel4K = 6
alignment.
  saGroup = 7
Segment group.
  saRel32Bytes = 8
32 bytes
  saRel64Bytes = 9
64 bytes
  saRelQword = 10
8 bytes
  saRel128Bytes = 11
128 bytes
  saRel512Bytes = 12
512 bytes
  saRel1024Bytes = 13
1024 bytes
  saRel2048Bytes = 14
2048 bytes
  saRel_MAX_ALIGN_CODE = 14
  scPriv = 0
segment.
  scGroup = 1
Segment group.
  scPub = 2
the alignment requirement.
  scPub2 = 4
As defined by Microsoft, same as C=2 (public).
  scStack = 5
byte alignment.
  scCommon = 6
Common.
  scPub3 = 7
As defined by Microsoft, same as C=2 (public).
  sc_MAX_COMB_CODE = 7
  SEGPERM_EXEC = 1
Execute.
  SEGPERM_WRITE = 2
Write.
  SEGPERM_READ = 4
Read.
  SEGPERM_MAXVAL = 7
  SEG_MAX_BITNESS_CODE = 2
  SFL_COMORG = 1
IDP dependent field (IBM PC: if set, ORG directive is not commented out)
  SFL_OBOK = 2
Orgbase is present? (IDP dependent field)
  SFL_HIDDEN = 4
Is the segment hidden?
  SFL_DEBUG = 8
Is the segment created for the debugger?.
  SFL_LOADER = 16
Is the segment created by the loader?
  SFL_HIDETYPE = 32
Hide segment type (do not print it in the listing)
  SFL_HEADER = 64
Header segment (do not create offsets to it in the disassembly)
  SEG_NORM = 0
unknown type, no assumptions
  SEG_XTRN = 1
no instructions are allowed
  SEG_CODE = 2
code segment
  SEG_DATA = 3
data segment
  SEG_IMP = 4
java: implementation segment
  SEG_GRP = 6
group of segments
  SEG_NULL = 7
zero-length segment
  SEG_UNDF = 8
undefined segment type (not used)
  SEG_BSS = 9
uninitialized segment
  SEG_ABSSYM = 10
segment with definitions of absolute symbols
  SEG_COMM = 11
segment with communal definitions
  SEG_IMEM = 12
internal processor memory & sfr (8051)
  SEG_MAX_SEGTYPE_CODE = 12
  ADDSEG_NOSREG = 1
(undefine all default segment registers)
  ADDSEG_OR_DIE = 2
'qexit()' if can't add a segment
  ADDSEG_NOTRUNC = 4
destroy/truncate old segments instead.
  ADDSEG_QUIET = 8
silent mode, no "Adding segment..." in the messages window
  ADDSEG_FILLGAP = 16
fill gap between new segment and previous one.
  ADDSEG_SPARSE = 32
use sparse storage method for the new segment
  ADDSEG_NOAA = 64
do not mark new segment for auto-analysis
  ADDSEG_IDBENC = 128
non-ASCII bytes will be decoded accordingly
  SEGMOD_KILL = 1
disable addresses if segment gets shrinked or deleted
  SEGMOD_KEEP = 2
keep information (code & data, etc)
  SEGMOD_SILENT = 4
be silent
  SEGMOD_KEEP0 = 8
flag for internal use, don't set
  SEGMOD_KEEPSEL = 16
do not try to delete unused selector
  SEGMOD_NOMOVE = 32
(for 'set_segm_start()' )
  SEGMOD_SPARSE = 64
(for 'set_segm_start()' , 'set_segm_end()' )
  MSF_SILENT = 1
don't display a "please wait" box on the screen
  MSF_NOFIX = 2
don't call the loader to fix relocations
  MSF_LDKEEP = 4
keep the loader in the memory (optimization)
  MSF_FIXONCE = 8
valid for 'rebase_program()' .
  MSF_PRIORITY = 32
valid for 'move_segm()'
  MSF_NETNODES = 128
valid for 'rebase_program()'
  MOVE_SEGM_OK = 0
all ok
  MOVE_SEGM_PARAM = -1
The specified segment does not exist.
  MOVE_SEGM_ROOM = -2
Not enough free room at the target address.
  MOVE_SEGM_IDP = -3
IDP module forbids moving the segment.
  MOVE_SEGM_CHUNK = -4
Too many chunks are defined, can't move.
  MOVE_SEGM_LOADER = -5
The segment has been moved but the loader complained.
  MOVE_SEGM_ODD = -6
Cannot move segments by an odd number of bytes.
  MOVE_SEGM_ORPHAN = -7
Orphan bytes hinder segment movement.
  MOVE_SEGM_DEBUG = -8
Debugger segments cannot be moved.
  CSS_OK = 0
ok
  CSS_NODBG = -1
debugger is not running
  CSS_NORANGE = -2
could not find corresponding memory range
  CSS_NOMEM = -3
is too big)
  CSS_BREAK = -4
memory reading process stopped by user
  MAX_GROUPS = 8
max number of segment groups
  MAX_SEGM_TRANSLATIONS = 64
max number of segment translations
  __package__ = None
Function Details

is_visible_segm(s)

 

See 'SFL_HIDDEN' .

Parameters:
  • s, (C++ - segment_t *)
Returns: bool

is_finally_visible_segm(s)

 

See 'SFL_HIDDEN' , 'SCF_SHHID_SEGM' .

Parameters:
  • s, (C++ - segment_t *)
Returns: bool

set_visible_segm(s, visible)

 

See 'SFL_HIDDEN' .

Parameters:
  • s, (C++ - segment_t *)
  • visible, (C++ - bool)

is_spec_segm(seg_type)

 

Has segment a special type?. ( 'SEG_XTRN' , 'SEG_GRP' , 'SEG_ABSSYM' , 'SEG_COMM' )

Parameters:
  • seg_type, (C++ - uchar)
Returns: bool

is_spec_ea(ea)

 

Does the address belong to a segment with a special type?. ( 'SEG_XTRN' , 'SEG_GRP' , 'SEG_ABSSYM' , 'SEG_COMM' )

Parameters:
  • ea - linear address (C++: ea_t)
Returns: bool

lock_segm(segm, lock)

 

Lock segment pointer Locked pointers are guaranteed to remain valid until they are unlocked. Ranges with locked pointers cannot be deleted or moved.

Parameters:
  • segm, (C++ - const segment_t *)
  • lock, (C++ - bool)

is_segm_locked(segm)

 

Is a segment pointer locked?

Parameters:
  • segm, (C++ - const segment_t *)
Returns: bool

getn_selector(n)

 

Get description of selector (0.. 'get_selector_qty()' -1)

Parameters:
  • n, (C++ - int)
Returns: bool

setup_selector(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 (C++: ea_t)
Returns: sel_t
the allocated selector number

allocate_selector(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 (C++: ea_t)
Returns: sel_t
the allocated selector number

find_free_selector()

 

Find first unused selector.

Returns: sel_t
a number >= 1

set_selector(selector, paragraph)

 

Set mapping of selector to a paragraph. You should call this functionbeforecreating 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. (C++: sel_t)
  • paragraph - paragraph to map selector (C++: ea_t)
Returns: int

del_selector(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 (C++: sel_t)

sel2para(selector)

 

Get mapping of a selector.

Parameters:
  • selector - number of selector to translate (C++: sel_t)
Returns: ea_t
paragraph the specified selector is mapped to. if there is no mapping, returns 'selector'.

sel2ea(selector)

 

Get mapping of a selector as a linear address.

Parameters:
  • selector - number of selector to translate to linear address (C++: sel_t)
Returns: ea_t
linear address the specified selector is mapped to. if there is no mapping, returns to_ea(selector,0);

find_selector(base)

 

Find a selector that has mapping to the specified paragraph.

Parameters:
  • base - paragraph to search in the translation table (C++: ea_t)
Returns: sel_t
selector value or base

get_segm_by_sel(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 (C++: sel_t)
Returns: segment_t
pointer to segment or NULL

add_segm_ex(s, name, sclass, 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. (C++: segment_t *)
  • name - name of new segment. may be NULL. if specified, the segment is immediately renamed (C++: const char *)
  • sclass - class of the segment. may be NULL. if specified, the segment class is immediately changed (C++: const char *)
  • flags - Add segment flags (C++: int)
Returns: bool

add_segm(para, start, end, name, sclass, 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. (C++: ea_t)
  • start - start address of the segment. if start== BADADDR then start <- to_ea(para,0). (C++: ea_t)
  • 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. (C++: ea_t)
  • name - name of new segment. may be NULL (C++: const char *)
  • sclass - class of the segment. may be NULL. type of the new segment is modified if class is one of predefined names: "CODE" -> SEG_CODE "DATA" -> SEG_DATA "CONST" -> SEG_DATA "STACK" -> SEG_BSS "BSS" -> SEG_BSS "XTRN" -> SEG_XTRN "COMM" -> SEG_COMM "ABS" -> SEG_ABSSYM (C++: const char *)
  • flags, (C++ - int)
Returns: bool

del_segm(ea, flags)

 

Delete a segment.

Parameters:
  • ea - any address belonging to the segment (C++: ea_t)
  • flags - Segment modification flags (C++: int)
Returns: bool

getseg(ea)

 

Get pointer to segment by linear address.

Parameters:
  • ea - linear address belonging to the segment (C++: ea_t)
Returns: segment_t
NULL or pointer to segment structure

getnseg(n)

 

Get pointer to segment by its number.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) (C++: int)
Returns: segment_t
NULL or pointer to segment structure

get_segm_num(ea)

 

Get number of segment by address.

Parameters:
  • ea - linear address belonging to the segment (C++: ea_t)
Returns: int
-1 if no segment occupies the specified address. otherwise returns number of the specified segment (0.. get_segm_qty() -1)

get_next_seg(ea)

 

Get pointer to the next segment.

Parameters:
  • ea, (C++ - ea_t)
Returns: segment_t

get_prev_seg(ea)

 

Get pointer to the previous segment.

Parameters:
  • ea, (C++ - ea_t)
Returns: segment_t

get_segm_by_name(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 NULL. (C++: const char *)
Returns: segment_t
NULL or pointer to segment structure

set_segm_end(ea, newend, 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 (C++: ea_t)
  • newend - new end address of the segment (C++: ea_t)
  • flags - Segment modification flags (C++: int)
Returns: bool

set_segm_start(ea, newstart, 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 (C++: ea_t)
  • newstart - new start address of the segment note that segment start address should be higher than segment base linear address. (C++: ea_t)
  • flags - Segment modification flags (C++: int)
Returns: bool

move_segm_start(ea, newstart, 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.this function never disables addresses.

Parameters:
  • ea - any address belonging to the segment (C++: ea_t)
  • newstart - new start address of the segment note that segment start address should be higher than segment base linear address. (C++: ea_t)
  • 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) (C++: int)
Returns: bool

move_segm(s, to, 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 (C++: segment_t *)
  • to - new segment start address (C++: ea_t)
  • flags - Move segment flags (C++: int)
Returns: int
Move segment result codes

change_segment_status(s, 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 (C++: segment_t *)
  • is_deb_segm - new status of the segment (C++: bool)
Returns: int
Change segment status result codes

take_memory_snapshot(only_loader_segs)

 

Take a memory snapshot of the running process.

Parameters:
  • only_loader_segs - only is_loader_segm() segments will be affected (C++: bool)
Returns: bool
success

is_miniidb()

 

Is the database a miniidb created by the debugger?.

Returns: bool
true if the database contains no segments or only debugger segments

set_segm_base(s, newbase)

 

Internal function.

Parameters:
  • s, (C++ - segment_t *)
  • newbase, (C++ - ea_t)
Returns: bool

set_group_selector(grp, sel)

 

Initialize groups. The kernel calls this function at the start of work.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. (C++: sel_t)
  • sel - common selector of all segments belonging to the segment You should create all segments within the group with the same selector value. (C++: sel_t)
Returns: int
1 ok

get_group_selector(grpsel)

 

Get common selector for a group of segments.

Parameters:
  • grpsel - selector of group segment (C++: sel_t)
Returns: sel_t
common selector of the group or 'grpsel' if no such group is found

add_segment_translation(segstart, mappedseg)

 

Add segment translation.

Parameters:
  • segstart - start address of the segment to add translation to (C++: ea_t)
  • mappedseg - start address of the overlayed segment (C++: ea_t)
Returns: bool

set_segment_translations(segstart, transmap)

 

Set new translation list.

Parameters:
  • segstart - start address of the segment to add translation to (C++: ea_t)
  • transmap - vector of segment start addresses for the translation list. If transmap is empty, the translation list is deleted. (C++: const eavec_t &)
Returns: bool

del_segment_translations(segstart)

 

Delete the translation list

Parameters:
  • segstart - start address of the segment to delete translation list (C++: ea_t)

get_segment_translations(transmap, segstart)

 

Get segment translation list.

Parameters:
  • transmap - vector of segment start addresses for the translation list (C++: eavec_t *)
  • segstart - start address of the segment to get information about (C++: ea_t)
Returns: ssize_t
-1 if no translation list or bad segstart. otherwise returns size of translation list.

get_segment_cmt(s, repeatable)

 

Get segment comment.

Parameters:
  • s - pointer to segment structure (C++: const segment_t *)
  • repeatable - 0: get regular comment. 1: get repeatable comment. (C++: bool)
Returns: ssize_t
size of comment or -1

set_segment_cmt(s, cmt, repeatable)

 

Set segment comment.

Parameters:
  • s - pointer to segment structure (C++: const segment_t *)
  • cmt - comment string, may be multiline (with ' '). maximal size is 4096 bytes. Use empty str ("") to delete comment (C++: const char *)
  • repeatable - 0: set regular comment. 1: set repeatable comment. (C++: bool)

std_out_segm_footer(ctx, seg)

 

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.

Parameters:
  • ctx, (C++ - struct outctx_t &)
  • seg, (C++ - segment_t *)

set_segm_name(s, name, 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 NULL) (C++: segment_t *)
  • name - new segment name (C++: const char *)
  • flags - ADDSEG_IDBENC or 0 (C++: int)
Returns: int

get_segm_name(s, flags=0)

 

Get true segment name by pointer to segment.

Parameters:
  • s - pointer to segment (C++: const segment_t *)
  • flags - 0-return name as is; 1-substitute bad symbols with _ 1 corresponds to GN_VISIBLE (C++: int)
Returns: ssize_t
size of segment name (-1 if s==NULL)

get_visible_segm_name(s)

 

Get segment name by pointer to segment.

Parameters:
  • s - pointer to segment (C++: const segment_t *)
Returns: ssize_t
size of segment name (-1 if s==NULL)

get_segm_class(s)

 

Get segment class. Segment class is arbitrary text (max 8 characters).

Parameters:
  • s - pointer to segment (C++: const segment_t *)
Returns: ssize_t
size of segment class (-1 if s==NULL or bufsize<=0)

set_segm_class(s, sclass, flags=0)

 

Set segment class.

Parameters:
  • s - pointer to segment (may be NULL) (C++: segment_t *)
  • sclass - segment class (may be NULL). If segment type is SEG_NORM and segment class is one of predefined names, then segment type is changed to: "CODE" -> SEG_CODE "DATA" -> SEG_DATA "STACK" -> SEG_BSS "BSS" -> SEG_BSS if "UNK" then segment type is reset to SEG_NORM . (C++: const char *)
  • flags, (C++ - int)
Returns: int

segtype(ea)

 

Get segment type.

Parameters:
  • ea - any linear address within the segment (C++: ea_t)
Returns: uchar
Segment types , SEG_UNDF if no segment found at 'ea'

get_segment_alignment(align)

 

Get text representation of segment alignment code.

Parameters:
  • align, (C++ - uchar)
Returns: char const *
text digestable by IBM PC assembler.

get_segment_combination(comb)

 

Get text representation of segment combination code.

Parameters:
  • comb, (C++ - uchar)
Returns: char const *
text digestable by IBM PC assembler.

get_segm_para(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 (C++: const segment_t *)
Returns: ea_t
0 if s == NULL, the segment base paragraph

get_segm_base(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 (C++: const segment_t *)
Returns: ea_t
0 if s == NULL, otherwise segment base linear address

set_segm_addressing(s, 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 (C++: segment_t *)
  • bitness - new addressing mode of segment 2: 64bit segment 1: 32bit segment 0: 16bit segment (C++: size_t)
Returns: bool
success

segm_adjust_diff(s, delta)

 

Truncate and sign extend a delta depending on the segment.

Parameters:
  • s, (C++ - const segment_t *)
  • delta, (C++ - adiff_t)
Returns: adiff_t

segm_adjust_ea(s, ea)

 

Truncate an address depending on the segment.

Parameters:
  • s, (C++ - const segment_t *)
  • ea, (C++ - ea_t)
Returns: ea_t

rebase_program(delta, flags)

 

Rebase the whole program by 'delta' bytes.

Parameters:
  • delta - number of bytes to move the program (C++: adiff_t)
  • 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 (C++: int)
Returns: int
Move segment result codes

Variables Details

saRelDble

boundary.

Relocatable, aligned on a double word (4-byte)

Value:
5

saRel4K

alignment. It is not supported by LINK.

This value is used by the PharLap OMF for page (4K)

Value:
6

scPriv

segment.

Private. Do not combine with any other program

Value:
0

scPub

the alignment requirement.

Public. Combine by appending at an offset that meets

Value:
2

scStack

byte alignment.

Stack. Combine as for C=2. This combine type forces

Value:
5

scCommon

Common. Combine by overlay using maximum size.

Value:
6

SFL_DEBUG

Is the segment created for the debugger?. Such segments are temporary and do not have permanent flags.

Value:
8

SEG_XTRN

no instructions are allowed

segment with 'extern' definitions.

Value:
1

ADDSEG_NOSREG

(undefine all default segment registers)

set all default segment register values to 'BADSEL'

Value:
1

ADDSEG_NOTRUNC

destroy/truncate old segments instead.

don't truncate the new segment at the beginning of the next segment if they overlap.

Value:
4

ADDSEG_FILLGAP

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.

Value:
16

ADDSEG_IDBENC

non-ASCII bytes will be decoded accordingly

'name' and 'sclass' are given in the IDB encoding;

Value:
128

SEGMOD_NOMOVE

(for 'set_segm_start()' )

don't move info from the start of segment to the new start address

Value:
32

SEGMOD_SPARSE

(for 'set_segm_start()' , 'set_segm_end()' )

use sparse storage if extending the segment

Value:
64

MSF_FIXONCE

valid for 'rebase_program()' . see 'loader_t::move_segm' .

call loader only once with the special calling method.

Value:
8

MSF_PRIORITY

valid for 'move_segm()'

loader segments will overwrite any existing debugger segments when moved.

Value:
32

MSF_NETNODES

valid for 'rebase_program()'

move netnodes instead of changing inf.netdelta (this is slower)

Value:
128

CSS_NOMEM

is too big)

not enough memory (might be because the segment

Value:
-3