I want to end up in something like the following using idapython to determine if given a specific address there is an xref (without caring where the XREF comes from)

ea_start = #
ea_end = #
for ea in range(ea_start,ea_end):
    if hasXREF(ea):

def hasXREF(addr):
    if [something]:
        return true
        return false

2 Answers 2


Take a look at this link: https://www.hex-rays.com/products/ida/support/idapython_docs/idautils-module.html#XrefsTo

You can use the function: XrefsTo(ea, flags=0).

From the description, it Return all references to address ea.

And XrefsFrom(ea, flags=0), which Return all references from address 'ea'

You should have anything for your script now :)

I have an example of a working IDA Python script that you can use as a reference here (It count the number of XrefTo per functions of a binary): https://github.com/GuillaumeOrlando/MalwareAnalysisArtifacts/blob/master/IDA_Scripts/XrefChecker.py.


You can use the flags which are attached to each address and, among other info, store information about whether the address has any xrefs to it.

def hasXREF(addr):        
    return has_xref(get_flags(addr))

BTW, instead of inspecting every address it's better and faster to inspect only head bytes (starts of instructions or data items) which are returned by the idautils.Heads() iterator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.