BLACK FRIDAY DISCOUNT See conditions
Hex-Rays logo State-of-the-art binary code analysis tools
email icon
xref.hpp File Reference

Functions that deal with cross-references. More...

Classes

struct  xrefblk_t
 Structure to enumerate all xrefs. More...
 

Macros

#define XREF_USER   0x20
 User specified xref. More...
 
#define XREF_TAIL   0x40
 Reference to tail byte in extrn symbols.
 
#define XREF_BASE   0x80
 Reference to the base part of an offset.
 
#define XREF_MASK   0x1F
 Mask to get xref type.
 
#define XREF_PASTEND   0x100
 Reference is past item. More...
 
#define XREF_ALL   0x00
 return all references
 
#define XREF_FAR   0x01
 don't return ordinary flow xrefs
 
#define XREF_DATA   0x02
 return data references only
 

Enumerations

enum  cref_t {
  fl_U , fl_CF = 16 , fl_CN , fl_JF ,
  fl_JN , fl_USobsolete , fl_F
}
 CODE xref types. More...
 
enum  dref_t {
  dr_U , dr_O , dr_W , dr_R ,
  dr_T , dr_I , dr_S
}
 DATA xref types. More...
 

Functions

idaman char ida_export xrefchar (char xrtype)
 Get character describing the xref type. More...
 
idaman bool ida_export add_cref (ea_t from, ea_t to, cref_t type)
 Create a code cross-reference. More...
 
idaman bool ida_export del_cref (ea_t from, ea_t to, bool expand)
 Delete a code cross-reference. More...
 
idaman bool ida_export add_dref (ea_t from, ea_t to, dref_t type)
 Create a data cross-reference. More...
 
idaman void ida_export del_dref (ea_t from, ea_t to)
 Delete a data cross-reference. More...
 
Helper functions

Should not be called directly!

idaman bool ida_export xrefblk_t_first_from (xrefblk_t *, ea_t from, int flags)
 
idaman bool ida_export xrefblk_t_next_from (xrefblk_t *)
 
idaman bool ida_export xrefblk_t_first_to (xrefblk_t *, ea_t to, int flags)
 
idaman bool ida_export xrefblk_t_next_to (xrefblk_t *)
 
idaman ea_t ida_export get_first_dref_from (ea_t from)
 Get first data referenced from the specified address. More...
 
idaman ea_t ida_export get_next_dref_from (ea_t from, ea_t current)
 Get next data referenced from the specified address. More...
 
idaman ea_t ida_export get_first_dref_to (ea_t to)
 Get address of instruction/data referencing to the specified data. More...
 
idaman ea_t ida_export get_next_dref_to (ea_t to, ea_t current)
 Get address of instruction/data referencing to the specified data. More...
 
idaman ea_t ida_export get_first_cref_from (ea_t from)
 Get first instruction referenced from the specified instruction. More...
 
idaman ea_t ida_export get_next_cref_from (ea_t from, ea_t current)
 Get next instruction referenced from the specified instruction. More...
 
idaman ea_t ida_export get_first_cref_to (ea_t to)
 Get first instruction referencing to the specified instruction. More...
 
idaman ea_t ida_export get_next_cref_to (ea_t to, ea_t current)
 Get next instruction referencing to the specified instruction. More...
 
Far code references

The following functions are similar to get_{first|next}_cref_{from|to} functions.

The only difference is that they don't take into account ordinary flow of execution. Only jump and call xrefs are returned. (fcref means "far code reference")

idaman ea_t ida_export get_first_fcref_from (ea_t from)
 
idaman ea_t ida_export get_next_fcref_from (ea_t from, ea_t current)
 
idaman ea_t ida_export get_first_fcref_to (ea_t to)
 
idaman ea_t ida_export get_next_fcref_to (ea_t to, ea_t current)
 
idaman bool ida_export has_external_refs (func_t *pfn, ea_t ea)
 Does 'ea' have references from outside of 'pfn'?
 

Detailed Description

Functions that deal with cross-references.

There are 2 types of xrefs: CODE and DATA references. All xrefs are kept in the bTree except ordinary execution flow to the next instruction. Ordinary execution flow to the next instruction is kept in flags (see bytes.hpp)

The source address of a cross-reference must be an item head (is_head) or a structure member id.

Cross-references are automatically sorted.

Macro Definition Documentation

◆ XREF_USER

#define XREF_USER   0x20

User specified xref.

This xref will not be deleted by IDA. This bit should be combined with the existing xref types (cref_t & dref_t) Cannot be used for fl_F xrefs

◆ XREF_PASTEND

#define XREF_PASTEND   0x100

Reference is past item.

This bit may be passed to add_dref() functions but it won't be saved in the database. It will prevent the destruction of eventual alignment directives.

Enumeration Type Documentation

◆ cref_t

enum cref_t

CODE xref types.

Enumerator
fl_U 

unknown – for compatibility with old versions.

Should not be used anymore.

fl_CF 

Call Far This xref creates a function at the referenced location.

fl_CN 

Call Near This xref creates a function at the referenced location.

fl_JF 

Jump Far.

fl_JN 

Jump Near.

fl_USobsolete 

User specified (obsolete)

fl_F 

Ordinary flow: used to specify execution flow to the next instruction.

◆ dref_t

enum dref_t

DATA xref types.

Enumerator
dr_U 

Unknown – for compatibility with old versions.

Should not be used anymore.

dr_O 

Offset The reference uses 'offset' of data rather than its value OR The reference appeared because the "OFFSET" flag of instruction is set.

The meaning of this type is IDP dependent.

dr_W 

Write access.

dr_R 

Read access.

dr_T 

Text (for forced operands only) Name of data is used in manual operand.

dr_I 

Informational (a derived java class references its base class informationally)

dr_S 

Reference to enum member (symbolic constant)

Function Documentation

◆ xrefchar()

idaman char ida_export xrefchar ( char  xrtype)

Get character describing the xref type.

Parameters
xrtypecombination of Cross-Reference type flags and a cref_t of dref_t value

◆ add_cref()

idaman bool ida_export add_cref ( ea_t  from,
ea_t  to,
cref_t  type 
)

Create a code cross-reference.

Parameters
fromlinear address of referencing instruction
tolinear address of referenced instruction
typecross-reference type
Returns
success

◆ del_cref()

idaman bool ida_export del_cref ( ea_t  from,
ea_t  to,
bool  expand 
)

Delete a code cross-reference.

Parameters
fromlinear address of referencing instruction
tolinear address of referenced instruction
expandpolicy to delete the referenced instruction
  • 1: plan to delete the referenced instruction if it has no more references.
  • 0: don't delete the referenced instruction even if no more cross-references point to it
Return values
trueif the referenced instruction will be deleted

◆ add_dref()

idaman bool ida_export add_dref ( ea_t  from,
ea_t  to,
dref_t  type 
)

Create a data cross-reference.

Parameters
fromlinear address of referencing instruction or data
tolinear address of referenced data
typecross-reference type
Returns
success (may fail if user-defined xref exists from->to)

◆ del_dref()

idaman void ida_export del_dref ( ea_t  from,
ea_t  to 
)

Delete a data cross-reference.

Parameters
fromlinear address of referencing instruction or data
tolinear address of referenced data

◆ get_first_dref_from()

idaman ea_t ida_export get_first_dref_from ( ea_t  from)

Get first data referenced from the specified address.

Parameters
fromlinear address of referencing instruction or data
Returns
linear address of first (lowest) data referenced from the specified address. Return BADADDR if the specified instruction/data doesn't reference to anything.

◆ get_next_dref_from()

idaman ea_t ida_export get_next_dref_from ( ea_t  from,
ea_t  current 
)

Get next data referenced from the specified address.

Parameters
fromlinear address of referencing instruction or data
currentlinear address of current referenced data. This value is returned by get_first_dref_from() or previous call to get_next_dref_from() functions.
Returns
linear address of next data or BADADDR.

◆ get_first_dref_to()

idaman ea_t ida_export get_first_dref_to ( ea_t  to)

Get address of instruction/data referencing to the specified data.

Parameters
tolinear address of referencing instruction or data
Returns
BADADDR if nobody refers to the specified data.

◆ get_next_dref_to()

idaman ea_t ida_export get_next_dref_to ( ea_t  to,
ea_t  current 
)

Get address of instruction/data referencing to the specified data.

Parameters
tolinear address of referencing instruction or data
currentcurrent linear address. This value is returned by get_first_dref_to() or previous call to get_next_dref_to() functions.
Returns
BADADDR if nobody refers to the specified data.

◆ get_first_cref_from()

idaman ea_t ida_export get_first_cref_from ( ea_t  from)

Get first instruction referenced from the specified instruction.

If the specified instruction passes execution to the next instruction then the next instruction is returned. Otherwise the lowest referenced address is returned (remember that xrefs are kept sorted!).

Parameters
fromlinear address of referencing instruction
Returns
first referenced address. If the specified instruction doesn't reference to other instructions then returns BADADDR.

◆ get_next_cref_from()

idaman ea_t ida_export get_next_cref_from ( ea_t  from,
ea_t  current 
)

Get next instruction referenced from the specified instruction.

Parameters
fromlinear address of referencing instruction
currentlinear address of current referenced instruction This value is returned by get_first_cref_from() or previous call to get_next_cref_from() functions.
Returns
next referenced address or BADADDR.

◆ get_first_cref_to()

idaman ea_t ida_export get_first_cref_to ( ea_t  to)

Get first instruction referencing to the specified instruction.

If the specified instruction may be executed immediately after its previous instruction then the previous instruction is returned. Otherwise the lowest referencing address is returned. (remember that xrefs are kept sorted!).

Parameters
tolinear address of referenced instruction
Returns
linear address of the first referencing instruction or BADADDR.

◆ get_next_cref_to()

idaman ea_t ida_export get_next_cref_to ( ea_t  to,
ea_t  current 
)

Get next instruction referencing to the specified instruction.

Parameters
tolinear address of referenced instruction
currentlinear address of current referenced instruction This value is returned by get_first_cref_to() or previous call to get_next_cref_to() functions.
Returns
linear address of the next referencing instruction or BADADDR.