def test_contains_with_correct_sequence(): subset = ["getCellLocation", "sendTextMessage"] target = ["put", "getCellLocation", "query", "sendTextMessage"] result = contains(subset, target) assert result is True
def test_contains_with_superset(): subset = ["put", "getCellLocation", "query", "sendTextMessage"] target = ["put", "query"] result = contains(subset, target) assert result is False
def test_contains_with_mutually_exclusive_list(): subset = ["getCellLocation", "sendTextMessage"] target = ["put", "query"] result = contains(subset, target) assert result is False
def check_sequence(self, mutual_parent, first_method_list, second_method_list): """ Check if the first function appeared before the second function. :param mutual_parent: function that call the first function and second functions at the same time. :param first_method_list: the first show up function, which is (class_name, method_name) :param second_method_list: the second show up function, which is (class_name, method_name) :return: True or False """ state = False for first_call_method in first_method_list: for second_call_method in second_method_list: seq_table = [] for _, call, number in mutual_parent.get_xref_to(): if call in (first_call_method, second_call_method): seq_table.append((call, number)) # sorting based on the value of the number if len(seq_table) < 2: # Not Found sequence in same_method continue seq_table.sort(key=operator.itemgetter(1)) # seq_table would look like: [(getLocation, 1256), (sendSms, 1566), (sendSms, 2398)] method_list_need_check = [x[0] for x in seq_table] sequence_pattern_method = [first_call_method, second_call_method] if tools.contains(sequence_pattern_method, method_list_need_check): state = True return state
def check_sequence( self, mutual_parent, first_method_list, second_method_list ): """ Check if the first function appeared before the second function. :param mutual_parent: function that call the first function and second functions at the same time. :param first_method_list: the first show up function, which is a MethodAnalysis :param second_method_list: the second show up function, which is a MethodAnalysis :return: True or False """ state = False for first_call_method in first_method_list: for second_call_method in second_method_list: seq_table = [ (call, number) for call, number in self.apkinfo.lowerfunc(mutual_parent) if call in (first_call_method, second_call_method) ] # sorting based on the value of the number if len(seq_table) < 2: # Not Found sequence in same_method continue seq_table.sort(key=operator.itemgetter(1)) # seq_table would look like: [(getLocation, 1256), (sendSms, 1566), (sendSms, 2398)] method_list_need_check = [x[0] for x in seq_table] sequence_pattern_method = [ first_call_method, second_call_method, ] if tools.contains( sequence_pattern_method, method_list_need_check ): state = True # Record the mapping between the parent function and the wrapper method self.quark_analysis.parent_wrapper_mapping[ mutual_parent.full_name ] = self.apkinfo.get_wrapper_smali( mutual_parent, first_call_method, second_call_method ) return state
def check_sequence(self, same_method, first_func, second_func): """ Check if the first function appeared before the second function. :param same_method: function that call the first function and second functions at the same time. :param first_func: the first show up function, which is (class_name, method_name) :param second_func: the second show up function, which is (class_name, method_name) :return: True or False """ same_class_name, same_method_name = same_method first_class_name, first_method_name = first_func second_class_name, second_method_name = second_func method_set = self.apkinfo.find_method( same_class_name, same_method_name, ) seq_table = [] if method_set is not None: for method in method_set: for _, call, number in method.get_xref_to(): to_md_name = str(call.name) if (to_md_name == first_method_name) or ( to_md_name == second_method_name ): seq_table.append((call.name, number)) # sorting based on the value of the number if len(seq_table) < 2: # Not Found sequence in same_method return False seq_table.sort(key=operator.itemgetter(1)) # seq_table would look like: [(getLocation, 1256), (sendSms, 1566), (sendSms, 2398)] method_list = [x[0] for x in seq_table] check_sequence_method = [first_method_name, second_method_name] return tools.contains(check_sequence_method, method_list) else: return False