Beispiel #1
0
def arm_epilogue(blk):
    if len(blk.bap.stmts) > 1:
        last_stmt = blk.bap.stmts[-1]
        if isinstance(last_stmt, JmpStmt) \
                and isinstance(last_stmt.kind, RetKind):
            stmt = blk.bap.stmts[-2]
            if isinstance(stmt.lhs, RegVar) \
                    and stmt.lhs.name == 'SP' \
                    and isinstance(stmt.rhs, BinOpExp) \
                    and isinstance(stmt.rhs.e1, RegVar) \
                    and isinstance(stmt.rhs.e2, IntExp) \
                    and stmt.rhs.e1.name == 'SP':
                for i in range(len(blk.bap.stmts) - 3, -1, -1):
                    stmt = blk.bap.stmts[i]
                    if isinstance(stmt, DefStmt) \
                            and isinstance(stmt.lhs, RegVar) \
                            and isinstance(stmt.rhs, LoadExp):
                        base_pointer, offset, access = mem_addr(
                            stmt.rhs.addr, blk, stmt.pc)
                        if base_pointer is not None and base_pointer.base_register == 'SP':
                            make_temp_offset(base_pointer.base_register,
                                             offset, blk, stmt.pc)
                            make_giv_reg(stmt.lhs.name, stmt.lhs.index, blk,
                                         stmt.pc)
                        else:
                            break
                    else:
                        break
Beispiel #2
0
def x64_epilogue(blk):
    for stmt in blk.bap.stmts:
        if stmt.insn is not None \
                and stmt.insn.startswith('POP') \
                and isinstance(stmt, DefStmt) \
                and isinstance(stmt.lhs, RegVar) \
                and isinstance(stmt.rhs, LoadExp):
            base_pointer, offset, access = mem_addr(stmt.rhs.addr, blk,
                                                    stmt.pc)
            if base_pointer is not None \
                    and base_pointer.base_register == 'RSP':
                make_temp_offset(base_pointer.base_register, offset, blk,
                                 stmt.pc)
                make_giv_reg(stmt.lhs.name, stmt.lhs.index, blk, stmt.pc)
Beispiel #3
0
def arm_call_args(blk):
    if len(blk.bap.stmts) > 0:
        last_stmt_bap = blk.bap.stmts[-1]
        if isinstance(last_stmt_bap, JmpStmt) \
                and isinstance(last_stmt_bap.kind, CallKind):
            call = last_stmt_bap
            for i in range(len(blk.bap.stmts) - 3, -1, -1):
                stmt = blk.bap.stmts[i]
                if isinstance(stmt, DefStmt):
                    lhs = stmt.lhs
                    rhs = stmt.rhs
                    if isinstance(lhs, RegVar) \
                            and lhs.name in ARM_FUN_ARG_REGS:
                        key = lhs.name
                        if key not in call.kind.args:
                            make_giv_reg(lhs.name, lhs.index, blk, stmt.pc)
                            call.kind.args[key] = (rhs, stmt.pc)
Beispiel #4
0
def arm_prologue(blk):
    for stmt in blk.bap.stmts:
        if stmt.pc is not None \
                and stmt.pc == blk.function.low_pc \
                and isinstance(stmt, DefStmt) \
                and isinstance(stmt.lhs, MemVar) \
                and isinstance(stmt.rhs, StoreExp) \
                and isinstance(stmt.rhs.exp, RegVar):
            base_pointer, offset, access = mem_addr(stmt.rhs.addr, blk,
                                                    stmt.pc)
            if base_pointer is not None and base_pointer.base_register == 'SP':
                make_temp_offset(base_pointer.base_register, offset, blk,
                                 stmt.pc)
                make_giv_reg(stmt.rhs.exp.name, stmt.rhs.exp.index, blk,
                             stmt.pc)
            else:
                break
Beispiel #5
0
def x86_prologue(blk):
    for stmt in blk.bap.stmts:
        if stmt.insn is not None \
                and stmt.insn.startswith('PUSH') \
                and isinstance(stmt.lhs, MemVar) \
                and isinstance(stmt.rhs, StoreExp):
            if isinstance(stmt.rhs.exp, RegVar):
                make_giv_reg(stmt.rhs.exp.name, stmt.rhs.exp.index, blk,
                             stmt.pc)
            elif isinstance(stmt.rhs.exp, VirtualVar) \
                    and isinstance(get_virtual_exp(stmt.rhs.exp, blk).exp, RegVar):
                virtual_exp = get_virtual_exp(stmt.rhs.exp, blk)
                reg = virtual_exp.exp
                make_giv_reg(reg.name, reg.index, blk, stmt.pc)
                make_giv_reg(reg.name, reg.index, blk, virtual_exp.pc)