IDA SDK
Classes | Functions | Macros | Typedefs
fixup.hpp File Reference

Detailed Description

Functions that deal with fixup information.

A loader should setup fixup information using set_fixup().

Classes

struct  fixup_data_t
 
struct  fixup_handler_t
 Implements the core behavior of a custom fixup. More...
 
struct  fixup_info_t
 Collect fixup records for the specified range. More...
 

Functions

bool is_fixup_custom (fixup_type_t type)
 Is fixup processed by processor module?
 
idaman bool ida_export get_fixup (fixup_data_t *fd, ea_t source)
 Get fixup information.
 
bool exists_fixup (ea_t source)
 Check that a fixup exists at the given address.
 
idaman void ida_export set_fixup (ea_t source, const fixup_data_t &fd)
 Set fixup information. More...
 
idaman void ida_export del_fixup (ea_t source)
 Delete fixup information.
 
idaman const fixup_handler_t *ida_export get_fixup_handler (fixup_type_t type)
 Get handler of standard or custom fixup.
 
idaman bool ida_export apply_fixup (ea_t item_ea, ea_t fixup_ea, int n, bool is_macro)
 Use fixup information for an address. More...
 
idaman uval_t ida_export get_fixup_value (ea_t ea, fixup_type_t type)
 Get the operand value. More...
 
idaman bool ida_export patch_fixup_value (ea_t ea, const fixup_data_t &fd)
 Patch the fixup bytes. More...
 
idaman const char *ida_export get_fixup_desc (qstring *buf, ea_t source, const fixup_data_t &fd)
 Get FIXUP description comment.
 
idaman int ida_export calc_fixup_size (fixup_type_t type)
 Calculate size of fixup in bytes (the number of bytes the fixup patches) More...
 
idaman bool ida_export get_fixups (fixups_t *out, ea_t ea, asize_t size)
 
bool contains_fixups (ea_t ea, asize_t size)
 Does the specified address range contain any fixup information?
 
idaman void ida_export gen_fix_fixups (ea_t from, ea_t to, asize_t size)
 Relocate the bytes with fixup information once more (generic function). More...
 
Enumerate addresses with fixup information:
idaman ea_t ida_export get_first_fixup_ea (void)
 
idaman ea_t ida_export get_next_fixup_ea (ea_t ea)
 
idaman ea_t ida_export get_prev_fixup_ea (ea_t ea)
 
std_get_value()

This internal function takes Tuning options to determine how to get the operand value.

It is opposite in meaning to the `std_patch_value()`. 1) it gets the fixup_handler_t::size bytes at the given address, 2) it shifts the result left by fixup_handler_t::shift bits, 3) it returns the rightmost fixup_handler_t::width bits as a signed value.

idaman fixup_type_t ida_export register_custom_fixup (const fixup_handler_t *cfh)
 Register a new custom fixup. More...
 
idaman bool ida_export unregister_custom_fixup (fixup_type_t type)
 Unregister a new custom fixup format. More...
 
idaman fixup_type_t ida_export find_custom_fixup (const char *name)
 Get id of a custom fixup handler. More...
 

Macros

#define FIXUPF_REL   0x0001
 fixup is relative to the linear address `base'. More...
 
#define FIXUPF_EXTDEF   0x0002
 target is a location (otherwise - segment). More...
 
#define FIXUPF_UNUSED   0x0004
 fixup is ignored by IDA More...
 
#define FIXUPF_CREATED   0x0008
 fixup was not present in the input file
 
#define FIXUPF_LOADER_MASK   0xF0000000
 additional flags. More...
 
#define FHF_VERIFY   0x0001
 verify that the value fits into `width' More...
 
Fixup standard types
#define FIXUP_OFF8   13
 8-bit offset
 
#define FIXUP_OFF16   1
 16-bit offset
 
#define FIXUP_SEG16   2
 16-bit base–logical segment base (selector)
 
#define FIXUP_PTR16   3
 32-bit long pointer (16-bit base:16-bit More...
 
#define FIXUP_OFF32   4
 32-bit offset
 
#define FIXUP_PTR32   5
 48-bit pointer (16-bit base:32-bit offset)
 
#define FIXUP_HI8   6
 high 8 bits of 16bit offset
 
#define FIXUP_HI16   7
 high 16 bits of 32bit offset
 
#define FIXUP_LOW8   8
 low 8 bits of 16bit offset
 
#define FIXUP_LOW16   9
 low 16 bits of 32bit offset
 
#define V695_FIXUP_VHIGH   10
 obsolete
 
#define V695_FIXUP_VLOW   11
 obsolete
 
#define FIXUP_OFF64   12
 64-bit offset
 
#define FIXUP_CUSTOM   0x8000
 start of the custom types range
 

Typedefs

typedef uint16 fixup_type_t
 Fixup information structure. More...
 
typedef qvector< fixup_info_tfixups_t
 

Macro Definition Documentation

#define FIXUP_PTR16   3

32-bit long pointer (16-bit base:16-bit

offset)

Typedef Documentation

Fixup information structure.

see Types of fixups

Function Documentation

idaman void ida_export set_fixup ( ea_t  source,
const fixup_data_t fd 
)

Set fixup information.

You should fill fixup_data_t and call this function and the kernel will remember information in the database.

Parameters
sourcethe fixup source address, i.e. the address modified by the fixup
fdfixup data
idaman bool ida_export apply_fixup ( ea_t  item_ea,
ea_t  fixup_ea,
int  n,
bool  is_macro 
)

Use fixup information for an address.

This function converts item_ea flags to offsets/segments. For undefined bytes, you may set item_ea == fixup_ea. In this case this function will create an item (byte, word, dword) there.

Parameters
item_eastart address of item to modify
fixup_eaaddress of fixup record
nnumber of operand. may be 0, 1, 2
is_macrois the instruction at 'item_ea' a macro? if yes, then partial fixups (HIGH, LOW) won't be applied
Return values
falseno fixup at fixup_ea or it has FIXUPF_UNUSED flag
trueok, the fixup information was applied
idaman uval_t ida_export get_fixup_value ( ea_t  ea,
fixup_type_t  type 
)

Get the operand value.

This function get fixup bytes from data or an instruction at `ea' and convert them to the operand value (maybe partially). It is opposite in meaning to the `patch_fixup_value()`. For example, FIXUP_HI8 read a byte at `ea' and shifts it left by 8 bits, or AArch64's custom fixup BRANCH26 get low 26 bits of the insn at `ea' and shifts it left by 2 bits. This function is mainly used to get a relocation addend.

Parameters
eaaddress to get fixup bytes from, the size of the fixup bytes depends on the fixup type.
See also
fixup_handler_t::size
Parameters
typefixup type
Return values
operandvalue
idaman bool ida_export patch_fixup_value ( ea_t  ea,
const fixup_data_t fd 
)

Patch the fixup bytes.

This function updates data or an instruction at `ea' to the fixup bytes. For example, FIXUP_HI8 updates a byte at `ea' to the high byte of `fd->off', or AArch64's custom fixup BRANCH26 updates low 26 bits of the insn at `ea' to the value of `fd->off' shifted right by 2.

Parameters
eaaddress where data are changed, the size of the changed data depends on the fixup type.
See also
fixup_handler_t::size
Parameters
fdfixup data
Return values
falsethe fixup bytes do not fit (e.g. `fd->off' is greater than 0xFFFFFFC for BRANCH26). The database is changed even in this case.
idaman int ida_export calc_fixup_size ( fixup_type_t  type)

Calculate size of fixup in bytes (the number of bytes the fixup patches)

Return values
-1means error
idaman fixup_type_t ida_export register_custom_fixup ( const fixup_handler_t cfh)

Register a new custom fixup.

This function must be called by a processor module or plugin, but not by a file loader. File loaders should use find_custom_fixup() function to find the handler created by the processor module.

Returns
id of the new custom fixup handler with FIXUP_CUSTOM bit set or 0 (e.g. when the custom fixup handler with the same name was already registered).
idaman bool ida_export unregister_custom_fixup ( fixup_type_t  type)

Unregister a new custom fixup format.

Should be called by the processor module before the database gets closed.

idaman fixup_type_t ida_export find_custom_fixup ( const char *  name)

Get id of a custom fixup handler.

Parameters
namename of the custom fixup handler
Returns
id with FIXUP_CUSTOM bit set or 0
idaman void ida_export gen_fix_fixups ( ea_t  from,
ea_t  to,
asize_t  size 
)

Relocate the bytes with fixup information once more (generic function).

This function may be called from loader_t::move_segm() if it suits the goal. If loader_t::move_segm is not defined then this function will be called automatically when moving segments or rebasing the entire program. Special parameter values (from = BADADDR, size = 0, to = delta) are used when the function is called from rebase_program(delta).