Ejemplo n.º 1
0
 def find_sweet_spots_class_fields(self, sender, ran_fun):
     fields = self.get_referred_obj_fields(sender)
     for field in fields:
         self.sweet_objs.append(field)
         refs = x_ref([field[1], field[0]], 'class_var', self.p)
         for write_op in [r for r in refs if r.type == 'write']:
             m = self.p.blocks_to_methods[self.p.stmts_to_blocks[
                 write_op.stmt]]
             inp = {
                 'class_name': m.class_name,
                 'method_name': m.name,
                 'method_params': list(m.params),
                 'obj_class_name': field[1],
                 'obj_field_name': field[0],
                 'type': 'object_field'
             }
             _, tmp_dd, dep_caller = self.get_function_setter(inp, m)
             #if tmp_dd:
             #    import ipdb; ipdb.set_trace()
             self.sweet_spots += tmp_dd
             if dep_caller:
                 method_our_notation = [
                     m.class_name, m.name,
                     list(m.params), m.ret
                 ]
                 for caller in self.get_callers(method_our_notation):
                     self.iterative_sweet_spot_finder(caller, ran_fun)
Ejemplo n.º 2
0
    def get_data_dependent_functions(self, caller, callee):
        callee_invokes = self.get_method_invokes(caller, callee)

        dep_callers = []
        ddf_s = []

        for i in callee_invokes:
            arg_vars = self.get_invoke_args(i)
            for v in arg_vars:
                v_name = v.name
                inp = {
                    'class_name': caller[0],
                    'method_name': caller[1],
                    'method_params': caller[2],
                    'type': 'method_var',
                    'var_name': v_name
                }
                tainted_blocks, dd_f, dep_caller = self.get_function_setter(
                    inp, caller)

                ddf_s += dd_f
                if dep_caller:
                    dep_callers = [caller]

                # if the variable is not set withtin the function, let's check whether is a class
                # variable
                #FIXME: move this among the class fields?
                if not dd_f and not dep_caller:
                    current_var = v
                    v_ass = None
                    try:
                        while v_ass is None:
                            current_var = [
                                s.right_op for b in tainted_blocks
                                for s in b.statements
                                if type(s) == pysoot.sootir.soot_statement.
                                AssignStmt and hasattr(s.left_op, 'name')
                                and s.left_op.name == current_var.name
                            ]
                            current_var = current_var[0]
                            if hasattr(current_var, 'field'):
                                v_ass = current_var
                    except:
                        log.error("Could not find variable assignment")
                        continue

                    refs = x_ref([v_ass.field[1], v_ass.field[0]], 'class_var',
                                 self.p)
                    for write_op in [r for r in refs if r.type == 'write']:
                        m = self.p.blocks_to_methods[self.p.stmts_to_blocks[
                            write_op.stmt]]
                        inp = {
                            'class_name': m.class_name,
                            'method_name': m.name,
                            'method_params': list(m.params),
                            'obj_class_name': v_ass.field[1],
                            'obj_field_name': v_ass.field[0],
                            'type': 'object_field'
                        }
                        _, tmp_dd, dep_caller = self.get_function_setter(
                            inp, m)
                        if dep_caller:
                            dep_callers.append(
                                [m.class_name, m.name,
                                 list(m.params), m.ret])
                        dd_f += tmp_dd

        return ddf_s, dep_callers