IDA SDK

- Main Page
- Header Files
- Classes
- Modules

- File List
- File Members

Classes | Functions | Macros | Enumerations | Variables
xref.hpp File Reference

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

Cross-references are automatically sorted.

## Classes
struct | xrefblk_t
| Structure to enumerate all xrefs. 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 int 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...
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...
idaman bool ida_export | has_external_refs (func_t *pfn, ea_t ea)
| Has a location external to the function references?
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 *)
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)

## 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 }
| DATA xref types. More...

## Variables
char | lastXR
| This variable will contains type of the last xref returned by the following functions. More...

## Function Documentation

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

Create a code cross-reference.

Parameters

  from | linear address of referencing instruction
  to | linear address of referenced instruction
  type | cross-reference type

Returns
  success

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

Delete a code cross-reference.

Parameters

  from | linear address of referencing instruction
  to | linear address of referenced instruction
  expand | policy 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

  1 | the referenced instruction will be deleted
  0 | the referenced instruction will not be deleted

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

Create a data cross-reference.

Parameters

  from | linear address of referencing instruction or data
  to | linear address of referenced data
  type | cross-reference type

Returns
  success (may fail if user-defined xref exists from->to)

idaman void ida_export del_dref | ( | ea_t | from,
|  | ea_t | to
| ) |  |

Delete a data cross-reference.

Parameters

  from | linear address of referencing instruction or data
  to | linear address of referenced data

idaman ea_t ida_export get_first_dref_from | ( | ea_t | from | ) |

Get first data referenced from the specified address.

Parameters

  from | linear address of referencing instruction or data

Returns
  linear address of first (lowest) data referenced from the specified address. The lastXR variable contains type of the reference. Return BADADDR if the specified instruction/data doesn't reference to anything.

idaman ea_t ida_export get_next_dref_from | ( | ea_t | from,
|  | ea_t | current
| ) |  |

Get next data referenced from the specified address.

Parameters

  from | linear address of referencing instruction or data
  current | linear 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. The lastXR variable contains type of the reference

idaman ea_t ida_export get_first_dref_to | ( | ea_t | to | ) |

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

Parameters

  to | linear address of referencing instruction or data

Returns
  BADADDR if nobody refers to the specified data. The lastXR variable contains type of the reference.

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

  to | linear address of referencing instruction or data
  current | current 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. The lastXR variable contains type of the reference.

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

  from | linear address of referencing instruction

Returns
  first referenced address. The lastXR variable contains type of the reference. If the specified instruction doesn't reference to other instructions then returns BADADDR.

idaman ea_t ida_export get_next_cref_from | ( | ea_t | from,
|  | ea_t | current
| ) |  |

Get next instruction referenced from the specified instruction.

Parameters

  from | linear address of referencing instruction
  current | linear 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. The lastXR variable contains type of the reference.

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

  to | linear address of referenced instruction

Returns
  linear address of the first referencing instruction or BADADDR. The lastXR variable contains type of the reference.

idaman ea_t ida_export get_next_cref_to | ( | ea_t | to,
|  | ea_t | current
| ) |  |

Get next instruction referencing to the specified instruction.

Parameters

  to | linear address of referenced instruction
  current | linear 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. The lastXR variable contains type of the reference.

## Variable Documentation

char lastXR

This variable will contains type of the last xref returned by the following functions.

It is not exported, so if you need to know the cross reference type, please use the xrefblk_t structure to enumerate the cross references.