2

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

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

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 '):
        continue
    if ', =0x' not in l.disasm:
        continue
    addr = int(l.disasm.split(', =0x')[-1],16)

    if not is_address(addr) or addr in magic:
        continue

    ida_offset.op_offset_ex(l.ea,1,ri)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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