IDAPython 8.4
Loading...
Searching...
No Matches
ida_offset Namespace Reference

Detailed Description

Functions that deal with offsets.

"Being an offset" is a characteristic of an operand. This means that operand or
its part represent offset from some address in the program. This linear address
is called "offset base". Some operands may have 2 offsets simultaneously.
Generally, IDA doesn't handle this except for Motorola outer offsets. Thus there
may be two offset values in an operand: simple offset and outer offset.

Outer offsets are handled by specifying special operand number: it should be
ORed with OPND_OUTER value.

See bytes.hpp for further explanation of operand numbers.

Functions

"reftype_t" get_default_reftype (*args)
 get_default_reftype(ea) -> reftype_t Get default reference type depending on the segment.
 
"bool" op_offset_ex (*args)
 op_offset_ex(ea, n, ri) -> bool Convert operand to a reference.
 
"bool" op_offset (*args)
 op_offset(ea, n, type_and_flags, target=BADADDR, base=0, tdelta=0) -> bool See op_offset_ex()
 
"bool" op_plain_offset (*args)
 op_plain_offset(ea, n, base) -> bool Convert operand to a reference with the default reference type.
 
"ea_t" get_offbase (*args)
 get_offbase(ea, n) -> ea_t Get offset base value
 
"qstring *" get_offset_expression (*args)
 get_offset_expression(ea, n, _from, offset, getn_flags=0) -> str Get offset expression (in the form "offset name+displ").
 
"qstring *" get_offset_expr (*args)
 get_offset_expr(ea, n, ri, _from, offset, getn_flags=0) -> str See get_offset_expression()
 
"ea_t" can_be_off32 (*args)
 can_be_off32(ea) -> ea_t Does the specified address contain a valid OFF32 value?.
 
"ea_t" calc_offset_base (*args)
 calc_offset_base(ea, n) -> ea_t Try to calculate the offset base This function takes into account the fixup information, current ds and cs values.
 
"ea_t" calc_probable_base_by_value (*args)
 calc_probable_base_by_value(ea, off) -> ea_t Try to calculate the offset base.
 
"bool" calc_reference_data (*args)
 calc_reference_data(target, base, _from, ri, opval) -> bool Calculate the target and base addresses of an offset expression.
 
"ea_t" add_refinfo_dref (*args)
 add_refinfo_dref(insn, _from, ri, opval, type, opoff) -> ea_t Add xrefs for a reference from the given instruction ( insn_t::ea).
 
"ea_t" calc_target (*args)
 calc_target(_from, opval, ri) -> ea_t Retrieve refinfo_t structure and calculate the target.
 
"ea_t" calc_basevalue (*args)
 calc_basevalue(target, base) -> ea_t Calculate the value of the reference base.
 

Function Documentation

◆ add_refinfo_dref()

"ea_t" add_refinfo_dref ( * args)

This function creates a cross references to the target and the base. insn_t::add_off_drefs() calls this function to create xrefs for 'offset' operand.

Parameters
insn(C++: const insn_t &) the referencing instruction
from(C++: ea_t) the referencing instruction/data address
ri(C++: const refinfo_t &) reference info block from the database
opval(C++: adiff_t) operand value (usually op_t::value or op_t::addr)
type(C++: dref_t) type of xref
opoff(C++: int) offset of the operand from the start of instruction
Returns
: the target address of the reference

◆ calc_basevalue()

"ea_t" calc_basevalue ( * args)
Parameters
target(C++: ea_t)
base(C++: ea_t)

◆ calc_offset_base()

"ea_t" calc_offset_base ( * args)
Parameters
ea(C++: ea_t) the referencing instruction/data address
n(C++: int) operand number
  • 0: first operand
  • 1: second operand
  • ...
  • 7: eighth operand
Returns
: output base address or BADADDR

◆ calc_probable_base_by_value()

"ea_t" calc_probable_base_by_value ( * args)

2 bases are checked: current ds and cs. If fails, return BADADDR

Parameters
ea(C++: ea_t)
off(C++: uval_t)

◆ calc_reference_data()

"bool" calc_reference_data ( * args)

The calculated target and base addresses are returned in the locations pointed by 'base' and 'target'. In case 'ri.base' is BADADDR, the function calculates the offset base address from the referencing instruction/data address. The target address is copied from ri.target. If ri.target is BADADDR then the target is calculated using the base address and 'opval'. This function also checks if 'opval' matches the full value of the reference and takes in account the memory-mapping.

Parameters
target(C++: ea_t *) output target address
base(C++: ea_t *) output base address
from(C++: ea_t) the referencing instruction/data address
ri(C++: const refinfo_t &) reference info block from the database
opval(C++: adiff_t) operand value (usually op_t::value or op_t::addr)
Returns
: success

◆ calc_target()

"ea_t" calc_target ( * args)
Parameters
from(C++: ea_t)
opval(C++: adiff_t)
rirefinfo_t const &

calc_target(_from, ea, n, opval) -> ea_t

Parameters
fromea_t
eaea_t
nint
opvaladiff_t

◆ can_be_off32()

"ea_t" can_be_off32 ( * args)

For symbols in special segments the displacement is not taken into account. If yes, then the target address of OFF32 will be returned. If not, then BADADDR is returned.

Parameters
ea(C++: ea_t)

◆ get_default_reftype()

"reftype_t" get_default_reftype ( * args)
Parameters
ea(C++: ea_t)
Returns
: one of REF_OFF8, REF_OFF16, REF_OFF32, REF_OFF64

◆ get_offbase()

"ea_t" get_offbase ( * args)
Parameters
ea(C++: ea_t) linear address
n(C++: int) 0..UA_MAXOP-1 operand number
Returns
: offset base or BADADDR

◆ get_offset_expr()

"qstring *" get_offset_expr ( * args)
Parameters
ea(C++: ea_t)
n(C++: int)
ri(C++: const refinfo_t &) refinfo_t const &
from(C++: ea_t)
offset(C++: adiff_t)
getn_flags(C++: int)

◆ get_offset_expression()

"qstring *" get_offset_expression ( * args)

This function uses offset translation function ( processor_t::translate) if your IDP module has such a function. Translation function is used to map linear addresses in the program (only for offsets).

Example: suppose we have instruction at linear address 0x00011000: mov ax, [bx+7422h] and at ds:7422h: array dw ... We want to represent the second operand with an offset expression, so then we call: get_offset_expresion(0x001100, 1, 0x001102, 0x7422, buf); | | | | | | | | | +output buffer | | | +value of offset expression | | +address offset value in the instruction | +the second operand +address of instruction and the function will return a colored string: offset array

Parameters
ea(C++: ea_t) start of instruction or data with the offset expression
n(C++: int) operand number (may be ORed with OPND_OUTER)
  • 0: first operand
  • 1: second operand
  • ...
  • 7: eighth operand
from(C++: ea_t) 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.
offset(C++: adiff_t) value of operand or its part. The function will return text representation of this value as offset expression.
getn_flags(C++: int) combination of:
  • GETN_APPZERO: meaningful only if the name refers to a structure. appends the struct field name if the field offset is zero
  • GETN_NODUMMY: do not generate dummy names for the expression but pretend they already exist (useful to verify that the offset expression can be represented)
Return values
0can't convert to offset expression
1ok, a simple offset expression
2ok, a complex offset expression

◆ op_offset()

"bool" op_offset ( * args)
Parameters
ea(C++: ea_t)
n(C++: int)
type_and_flags(C++: uint32)
target(C++: ea_t)
base(C++: ea_t)
tdelta(C++: adiff_t)

◆ op_offset_ex()

"bool" op_offset_ex ( * args)

To delete an offset, use clr_op_type() function.

Parameters
ea(C++: ea_t) linear address. if 'ea' has unexplored bytes, try to convert them to
  • no segment: fail
  • 16bit segment: to 16bit word data
  • 32bit segment: to dword
n(C++: int) operand number (may be ORed with OPND_OUTER)
  • 0: first
  • 1: second
  • ...
  • 7: eighth operand
  • OPND_MASK: all operands
ri(C++: const refinfo_t *) reference information
Returns
: success

◆ op_plain_offset()

"bool" op_plain_offset ( * args)
Parameters
ea(C++: ea_t)
n(C++: int)
base(C++: ea_t)