Latest available version: IDA and decompilers v8.4.240320sp1 see all releases
Hex-Rays logo State-of-the-art binary code analysis tools
email icon
Segment selectors

The kernel maintains a table to translate selector values to segment base paragraphs. More...

Functions

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

Detailed Description

The kernel maintains a table to translate selector values to segment base paragraphs.

A Paragraph is a 16byte quantity. This table and translation is necessary because IBM PC uses 16bit selectors in instructions but segments may reside anywhere in the linear addressing space. For example, if a segment with selector 5 resides at 0x400000, we need to have selector translation 5 -> 0x400000. For 16bit programs the selector translation table is usually empty, selector values are equal to segment base paragraphs.

Function Documentation

◆ 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
segbasea 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
segbasea 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
selectornumber 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.
paragraphparagraph to map selector
Return values
1ok
0failure (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
selectornumber of selector to remove from the translation table

◆ sel2para()

idaman ea_t ida_export sel2para ( sel_t  selector)

Get mapping of a selector.

Parameters
selectornumber of selector to translate
Returns
paragraph the specified selector is mapped to. if there is no mapping, returns 'selector'.

◆ sel2ea()

ea_t idaapi sel2ea ( sel_t  selector)
inline

Get mapping of a selector as a linear address.

Parameters
selectornumber 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
baseparagraph 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
funccallback 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
selectorsegments that have this selector are enumerated
funccallback function
  • s: pointer to segment structure
  • ud: user data
udpointer 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
selectora segment with the specified selector will be returned
Returns
pointer to segment or nullptr