Offsets with custom base with specific register name

Hi all

I use “Offsets with custom base (CONTROL + R)” , but it is very cumbersome when the lines are too many and

there is a different register name in each line , also selecting a range of lines of disassembled code dose not

help , because the base address for offsets is applied to all of the immediate values in all lines of selected range,

I know that we can use a value range , but it is not useful in this scenario too , so is there any way to apply

“CONTROL-R“ to offset of a specific register name only (for example R1 or R13 …) in a selected range

(convert to offset “en masse”).

TIA

Currently such scenario is not supported, so I’d suggest making a script for it. Here’s a snippet I used in the past (will need to be adapted for the current API)

# helper function to iterate the instructions in an address range
def Instructions(start, end):
    """
    Get a list of instructions in a given range

    @return: ea of each instruction in the range [start..end)
    """
    fii = ida_funcs.func_item_iterator_t()
    ok = fii.set_range(start, end)
    while ok:
        yield fii.current()
        ok = fii.next_code()

s = SelStart()
e = SelEnd()
if s == BADADDR or e==BADADDR:
  Warning("select an address range before running the script!")
else:  
  rn = AskStr("r14", "Enter the register to track")
  if rn != None:
    reg = idaapi.str2reg(rn)
    rval = AskLong(0, "Enter register's value")
    for i in Instructions(s, e):
      ins = DecodeInstruction(i)
      if ins != None:
        if ins.itype==idaapi.PPC_addi and ins[1].reg == reg:   
          # addi rx, reg, #imm
          print "%08X: converting addi" % ins.ea
          OpOffEx(ins.ea, 2, REF_OFF32|REFINFO_NOBASE, BADADDR, rval, 0)
        elif ins[1].type==o_displ and ins[1].reg==reg:
          #lwz rx, delta(reg)
          print "%08X: converting displ" %ins.ea
          OpOffEx(ins.ea, 1, REF_OFF32|REFINFO_NOBASE, BADADDR, rval, 0)

Please note that if your target is PPC, the fixed r13 value (SDA) can be set in the processor-specific options.

1 Like

Hi

Thanks for your support and hint , I will try it.