在 IDA Pro for MIPS 中重命名子程序

逆向工程 艾达 米普
2021-06-21 17:33:08

我正在 IDA Pro 中处理 mipsel 二进制文件,但在重命名子例程时遇到了一些问题。

我在 0x739644 有子程序“系统”。我使用 N 热键重命名了它。

子程序重命名为系统

现在,如果我点击 X,一些外部参照已被替换:

JALR 很好

所有的 JALR 指令都很好。

但是,有时子程序的调用方式如下:

替代呼叫

在这种情况下,有时引用已被重命名,有时则没有。不过,它们都出现在外部参照中:

有些工作,有些没有

为什么是这样?我可以重命名它们吗?

1个回答

可能是因为 IDA 将la参数视为整数。尝试以下操作:转到system显示为数字的位置之一,将光标定位在该数字上,按下O并重新检查它是否仍被引用为数字。

基于评论更新 - 此代码说明了如何自动修复它的总体思路。注意:此代码未经测试,仅用于说明目的:

#I didn't check this code, 
#use carefully, 
#beware of errors !

import idc
import idautils
import idaapi


#this function will pass over all assembly commands in correspondiong parameter
#and will set as offsets all operands mentioned in second parameter
#   @param list_of_ranges --> list of tuples of start and end of code ranges where it 
#            should be applied
#   @list_of_commands_and_operands--> list of tuples of assembly commands as string 
#            and number of operands where it should be applied

def multi_convert_op_to_offset(list_of_ranges, list_of_commands_and_operands):
    for (start, end) in list_of_ranges:
        for h in idautils.Heads(start, end):
            dis = idc.GetDisasm(h).split()
            mnemonic = dis[0]
            for mnem, op in list_of_commands_and_operands:
                if mnem == mnemonic:
                    idc.OpOff(h, op, 0)


#Usage:

start = start_of_your_relevant_code
end = end_of_your_relevant_code

l_of_rng = []

l_of_rng.append((start, end))

l_of_cmds_and_ops = []

l_of_cmds_and_ops.append(("la", 1))

multi_convert_op_to_offset(l_of_rng, l_of_cmds_and_ops)