예제 #1
0
def main():
    ea = ScreenEA()
    rv = None

    func = idaapi.get_func(ea)
    if func is None:
        Message("Error: not in a function\n")
        return

    reg = get_highlighted_identifier()
    if reg is None:
        Message("Error: no highlighted name\n")
        return

    # it's not a reg ? we get the renaming for it then
    if reg not in REGS:
        rv = org_reg(reg, ea, func)
        if rv is None:
            Message(
                "Error: the highlighted name is neither a register nor a renamed register\n"
            )
            return

    new = AskStr(reg, "new name[;comment]")
    if new is None:
        Message("Cancelled\n")
        return
    if ";" in new:
        new, cmt = new.split(";")
    else:
        cmt = ""

    # was there a previous rename ? let's truncate it
    if rv is not None:
        s, e, c, u, cmt = rv.startEA, rv.endEA, rv.canon, rv.user, rv.cmt
        idaapi.del_regvar(func, s, e, c)
        idaapi.add_regvar(func, s, ea - 1, c, u, cmt)

    idaapi.add_regvar(func, ea, func.endEA, reg if rv is None else rv.canon,
                      new, cmt)

    # optional / to be perfected- added end ranges
    #idc.ExtLinA(ea, 0, "{")
    #idc.ExtLinB(func.endEA, 0, "} %s => %s ;%s" % (reg, new, cmt))

    return
예제 #2
0
def remove_regvars(func_addr):
    func = idaapi.get_func(func_addr)

    # Store register renaming.
    addr = func.startEA
    regvars = set()
    while addr <= func.endEA:
        for reg_str in __builtin__.REGISTERS._to_idx.keys():
            regvar = idaapi.find_regvar(func, addr, reg_str)
            if regvar is not None:

                regvars.add((reg_str, regvar.user, regvar.cmt, regvar.startEA,
                             regvar.endEA))
        addr += 1

    # Since IDA places two not connected CFGs sometimes in the same
    # functions (multiple entry basic blocks), we have to go
    # through all basic blocks also.
    ida_blocks = list(idaapi.FlowChart(func))
    for b in ida_blocks:

        addr = b.startEA
        block_end = b.endEA
        while addr != BADADDR and addr < block_end:

            for reg_str in __builtin__.REGISTERS._to_idx.keys():

                regvar = idaapi.find_regvar(func, addr, reg_str)

                if regvar is not None:

                    regvars.add((reg_str, regvar.user, regvar.cmt,
                                 regvar.startEA, regvar.endEA))
            addr = NextHead(addr)

    # Remove register renaming.
    for regvar in regvars:
        idaapi.del_regvar(
            func,
            regvar[3],  # startEA
            regvar[4],  # endEA
            regvar[0])  # register string

    return regvars
예제 #3
0
def main():
    ea = ScreenEA()
    rv = None

    func = idaapi.get_func(ea)
    if func is None:
        Message("Error: not in a function\n")
        return

    reg = get_highlighted_identifier()
    if reg is None:
        Message("Error: no highlighted name\n")
        return

    # it's not a reg ? we get the renaming for it then
    if reg not in REGS:
        rv = org_reg(reg, ea, func)
        if rv is None:
            Message("Error: the highlighted name is neither a register nor a renamed register\n")
            return

    new = AskStr(reg, "new name[;comment]")
    if new is None:
        Message("Cancelled\n")
        return
    if ";" in new:
        new, cmt = new.split(";")
    else:
        cmt = ""

    # was there a previous rename ? let's truncate it
    if rv is not None:
        s, e, c, u, cmt = rv.startEA, rv.endEA, rv.canon, rv.user, rv.cmt
        idaapi.del_regvar(func, s, e,c )
        idaapi.add_regvar(func, s, ea - 1, c, u, cmt)

    idaapi.add_regvar(func, ea, func.endEA, reg if rv is None else rv.canon, new, cmt)

    # optional / to be perfected- added end ranges
    #idc.ExtLinA(ea, 0, "{")
    #idc.ExtLinB(func.endEA, 0, "} %s => %s ;%s" % (reg, new, cmt))

    return
예제 #4
0
 def removeAllRegisterRenamingsInFunc(self, func_t):
     for reg in self.regDict.values():
         idaapi.del_regvar(func_t, func_t.startEA, func_t.endEA, reg)
예제 #5
0
 def removeAllRegisterRenamingsInFunc(self, func_t):
     for reg in self.regDict.values():
         idaapi.del_regvar(func_t, func_t.startEA, func_t.endEA, reg)