예제 #1
0
def mc_has_any_selector(function, selector_names, search_substring = False):
    '''
    Check if the `function` has a `Selector` with one of the specified names or will be loaded via NSSelectorFromString(...). 
    Can also be a c function (e.g. [c_func_res() someSelector]).
    
    Parameters
    ----------
    function: FunctionInterface
    selectorname: list<string>
        name of the `Selector` (without arguments filled, e.g: "setProperty:forKey:") 
    search_substring: bool
        If True match even if just substring found (`find`).
        Otherwise check for exact equality via `==`.
    '''
    if mc_is_function(function):
        # check if selector will be loaded via NSSelectorFromString(selectorname)
        if is_c_function(function):
            for sel_name in selector_names:
                if mc_sel_via_nsselector_from_string(function, sel_name):
                    return True
        
        for arg in function:
            # check if selector found
            if ModelUtil.is_selector(arg):
                for selname in selector_names:
                    if ut_search_string(arg.selector_name, selname, search_substring = search_substring):
                        return True
        
            # go deeper into structure
            if mc_is_function(arg):
                if mc_has_any_selector(arg, selector_names, search_substring):
                    return True
    return False
예제 #2
0
def mc_sel_via_nsselector_from_string(function, sel_name):
    ''' Check if a `Selector` is loaded via the NSSelectorFromString function ''' 
    if ModelUtil.is_c_function(function):
        if function.function == 'NSSelectorFromString':
            if function.cnt_has_arguments() >= 1:
                arg = function.func_arguments[0]
                return ut_search_string(str(arg), sel_name, search_substring = True, ignore_case = True)
    return False
예제 #3
0
파일: Cpu.py 프로젝트: nachtmaar/vizasm
 def _read_c_func(self, c_func):
     ''' Read a c function or subroutine like e.g. "sub_10013ec80" '''
     if ModelUtil.is_c_function(c_func):
         # use heuristic from `AssignmentMatchingSystem` to determine the number of arguments for the function
         arguments = self.get_memory().get_arguments_from_asm_heuristic()
         c_func.set_func_arguments(arguments)
         self._store_function(c_func)
         return True
     return False
예제 #4
0
def md_is_static_category_method(function):
    ''' Check if the category is static.
    This means that the method that the category overwrites is static.
    
    E.g. "+[NSURLRequest(AnyHttpsCert) allowsAnyHTTPSCertificateForHost:]" is static ("+").
    "-[NSURLRequest(AnyHttpsCert) allowsAnyHTTPSCertificateForHost:]" is not static ("-").
    '''
    if ModelUtil.is_method_implementation(function):
        return function.is_static
    return False
예제 #5
0
def mc_has_objc_class(function):
    ''' 
    Check if the receiver of a message is an objective c class.
    E.g. "[[NSString alloc] init]" is an objective c function and NSString is the objective c class.
    
    But sending a message to the return result of a c function (e.g. "[c_func() anyThing]")
    means that the objective c function does not an objective c class. 
    
    Parameters
    ----------
    function: FunctionInterface
    ''' 
    if mc_is_objectivec_function(function):
        return ModelUtil.is_objc_class(function.get_msg_receiver())
    return False
예제 #6
0
def md_get_category_class(function):
    ''' Get the category class.
    
    E.g. "+[NSURLRequest(AnyHttpsCert) allowsAnyHTTPSCertificateForHost:]" has the category class "NSURLRequest(AnyHttpsCert)".
     
    Parameters
    ----------
    function: FunctionInterface
    
    Returns
    -------
    CategoryClass
    None
        if `msg_send` is no category
    '''
    if MethodCallFilterUtil.mc_is_objectivec_function(function):
        receiver = function.msg_receiver
        md_is_category = ModelUtil.is_category_class(receiver)
        if md_is_category:
            return receiver
    return None    
    
예제 #7
0
def mc_is_objectivec_function(function):
    ''' Check if the function is an objective c function '''
    return ModelUtil.is_msg_send(function)
예제 #8
0
def mc_is_c_function(function):
    ''' Check if the function is a c function '''
    return ModelUtil.is_c_function(function)
예제 #9
0
def is_iterable_no_string(iterable):
    ''' Check if `iterable` is iterable and no python string '''
    from vizasm.model import ModelUtil
    return isinstance(iterable, collections.Iterable) and not ModelUtil.is_python_string(iterable)
예제 #10
0
def md_is_category(function):
    ''' Check if `function` is a category '''
    category_class = md_get_category_class(function)
    return ModelUtil.is_category_class(category_class)