Example #1
0
File: ira.py Project: Junraa/miasm
    def post_add_bloc(self, bloc, ir_blocs):
        ir.post_add_bloc(self, bloc, ir_blocs)
        for irb in ir_blocs:
            pc_val = None
            lr_val = None
            for assignblk in irb.irs:
                pc_val = assignblk.get(PC, pc_val)
                lr_val = assignblk.get(RA, lr_val)

            if pc_val is None or lr_val is None:
                continue
            if not expr_is_int_or_label(lr_val):
                continue
            if expr_is_label(lr_val):
                lr_val = ExprInt32(lr_val.name.offset)

            l = bloc.lines[-2]
            if lr_val.arg != l.offset + 8:
                raise ValueError("Wrong arg")

            # CALL
            lbl = bloc.get_next()
            new_lbl = self.gen_label()
            irs = self.call_effects(pc_val)
            irs.append(AssignBlock([ExprAff(self.IRDst,
                                            ExprId(lbl, size=self.pc.size))]))
            nbloc = irbloc(new_lbl, irs)
            nbloc.lines = [l] * len(irs)
            self.blocs[new_lbl] = nbloc
            irb.dst = ExprId(new_lbl, size=self.pc.size)
Example #2
0
    def post_add_bloc(self, bloc, ir_blocs):
        ir.post_add_bloc(self, bloc, ir_blocs)
        for irb in ir_blocs:
            pc_val = None
            lr_val = None
            for assignblk in irb.irs:
                pc_val = assignblk.get(PC, pc_val)
                lr_val = assignblk.get(RA, lr_val)

            if pc_val is None or lr_val is None:
                continue
            if not expr_is_int_or_label(lr_val):
                continue
            if expr_is_label(lr_val):
                lr_val = ExprInt32(lr_val.name.offset)

            l = bloc.lines[-2]
            if lr_val.arg != l.offset + 8:
                raise ValueError("Wrong arg")

            # CALL
            lbl = bloc.get_next()
            new_lbl = self.gen_label()
            irs = self.call_effects(pc_val)
            irs.append(
                AssignBlock(
                    [ExprAff(self.IRDst, ExprId(lbl, size=self.pc.size))]))
            nbloc = irbloc(new_lbl, irs)
            nbloc.lines = [l] * len(irs)
            self.blocs[new_lbl] = nbloc
            irb.dst = ExprId(new_lbl, size=self.pc.size)
Example #3
0
    def _follow_nolabel(exprs):
        """Do not follow labels"""
        follow = set()
        for expr in exprs:
            if not expr_is_int_or_label(expr):
                follow.add(expr)

        return follow, set()
Example #4
0
    def _follow_nolabel(exprs):
        """Do not follow labels"""
        follow = set()
        for expr in exprs:
            if not expr_is_int_or_label(expr):
                follow.add(expr)

        return follow, set()
Example #5
0
    def post_add_bloc(self, bloc, ir_blocs):
        ir.post_add_bloc(self, bloc, ir_blocs)
        for irb in ir_blocs:
            # print 'X'*40
            # print irb
            pc_val = None
            lr_val = None
            for exprs in irb.irs:
                for e in exprs:
                    if e.dst == PC:
                        pc_val = e.src
                    if e.dst == RA:
                        lr_val = e.src
            #print "XXX", pc_val, lr_val
            if pc_val is None or lr_val is None:
                continue
            if not expr_is_int_or_label(lr_val):
                continue
            if expr_is_label(lr_val):
                lr_val = ExprInt32(lr_val.name.offset)

            l = bloc.lines[-2]
            #print 'TEST', l, hex(lr_val.arg), hex(l.offset + 8)
            #print lr_val.arg, hex(l.offset + l.l)
            if lr_val.arg != l.offset + 8:
                raise ValueError("Wrong arg")

            # print 'IS CALL!'
            lbl = bloc.get_next()
            new_lbl = self.gen_label()
            irs = self.call_effects(pc_val)
            irs.append([ExprAff(self.IRDst, ExprId(lbl, size=self.pc.size))])
            nbloc = irbloc(new_lbl, irs)
            nbloc.lines = [l]
            self.blocs[new_lbl] = nbloc
            irb.dst = ExprId(new_lbl, size=self.pc.size)
Example #6
0
    def post_add_bloc(self, bloc, ir_blocs):
        ir.post_add_bloc(self, bloc, ir_blocs)
        for irb in ir_blocs:
            # print 'X'*40
            # print irb
            pc_val = None
            lr_val = None
            for exprs in irb.irs:
                for e in exprs:
                    if e.dst == PC:
                        pc_val = e.src
                    if e.dst == RA:
                        lr_val = e.src
            #print "XXX", pc_val, lr_val
            if pc_val is None or lr_val is None:
                continue
            if not expr_is_int_or_label(lr_val):
                continue
            if expr_is_label(lr_val):
                lr_val = ExprInt32(lr_val.name.offset)

            l = bloc.lines[-2]
            #print 'TEST', l, hex(lr_val.arg), hex(l.offset + 8)
            #print lr_val.arg, hex(l.offset + l.l)
            if lr_val.arg != l.offset + 8:
                fds
                continue
            # print 'IS CALL!'
            lbl = bloc.get_next()
            new_lbl = self.gen_label()
            irs = self.call_effects(pc_val)
            irs.append([ExprAff(self.IRDst, ExprId(lbl, size=self.pc.size))])
            nbloc = irbloc(new_lbl, irs)
            nbloc.lines = [l]
            self.blocs[new_lbl] = nbloc
            irb.dst = ExprId(new_lbl, size=self.pc.size)