i.e. What is the IDA API equivalent to pressing 'O'?

  • 1
    This question can be made better by adding an example and a more detailed description.
    – NirIzr
    Commented Jul 28, 2018 at 18:06

1 Answer 1


In Python:

import ida_nalt
import ida_offset
ri.target = -1
ri.flags = 2
EA = 0xdeadbeef
OPND = 1
ida_offset.op_offset_ex(EA, OPND, ri)

Where EA is the address of the line you want to change and OPND is the operand number of the immediate you want to change in the line.

Example script of making everything that looks like a reference in a specific section into a reference:

import sark, ida_nalt, ida_offset

ri = ida_nalt.refinfo_t()
ri.target = -1
ri.flags = 2

magic = [0x45670123]
segment_ranges =  [(s.startEA, s.endEA) for s in sark.segments()]
def is_address(ea):
    return any(start < ea < end for (start,end) in segment_ranges)

for l in sark.Segment(name='ROM').lines:
    if not l.disasm.startswith('LDR '):
    if ', =0x' not in l.disasm:
    addr = int(l.disasm.split(', =0x')[-1],16)

    if not is_address(addr) or addr in magic:


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.