To safely get all references from a certain EA
, there's idc.XrefsFrom(ea, flags)
. You'll get an iterator for cross references from a certain EA
(the switch-case's branch/jump instruction). switch-cases are easy to identify as they're always with more than two cross references targets.
According to this the flags
parameter is one of the following:
XREF_USER = 32
XREF_TAIL = 64
XREF_BASE = 128
XREF_MASK = 31
XREF_PASTEND = 256
XREF_ALL = 0
XREF_FAR = 1
XREF_DATA = 2
The object you'll get from each iteration is an ida_xref
object, exposing the following attributes:
frm
- The source of the cross reference, the code that performs the jump in our case.
to
- The target of the cross reference, the code that will be executed according to the jump table selector in our case.
iscode
- Boolean, True
if cross reference is a code cross reference, must be True
in our case.
type
- One of the available type values, see below. You could use idautils.XrefTypeName(typecode)
to translate the integer you get here to a readable string.
user
- Boolean, True if this cross reference was created by the user, opposed to being automatically created by IDA.
The valid cross reference types are, according to this:
ref_types = {
0 : 'Data_Unknown',
1 : 'Data_Offset',
2 : 'Data_Write',
3 : 'Data_Read',
4 : 'Data_Text',
5 : 'Data_Informational',
16 : 'Code_Far_Call',
17 : 'Code_Near_Call',
18 : 'Code_Far_Jump',
19 : 'Code_Near_Jump',
20 : 'Code_User',
21 : 'Ordinary_Flow'
}