Пример #1
0
def find_content_providers():
    """
    Find all content providers and return the list
    """
    cp_list = common.find_ext('ContentProvider')

    growing = 1
    #TODO - This is ugly and needs to be re-written
    #The intention here is to loop endlessly until all extensions are found
    while growing:
        cp_list_count_old = len(cp_list)
        cp_list += common.tree(cp_list)
        if len(cp_list) == cp_list_count_old:
            growing = 0

    cp_list.append(['ContentProvider', ''])

    cp_decs = []
    cp_decs.append([])
    for x in cp_list:
        if len(x) > 0:
            tmp = r'' + re.escape(str(x[0])) + r'\s\w+[;=]'
            cp_decs += common.text_scan(common.java_files, tmp)
            tmp = r'(private .*|protected.*)' + re.escape(str(
                x[0])) + r'\s\w+;'
            cp_decs += common.text_scan(common.java_files, tmp)
            tmp = r'\w+\s[;=]\snew\s' + re.escape(str(x[0])) + r'\('
            cp_decs += common.text_scan(common.java_files, tmp)
            tmp = r'\(.*' + re.escape(
                str(x[0])
            ) + r'\s\w+.*\)'  # Need to ensure this is working properly

    tmp_list2 = []
    tmp_list2.append([])
    for z in cp_decs:
        if len(z) > 0:
            #conditional declarations will cause conditional positives
            #BUG sometimes Z[0] is a list, rather than just a list element. Need to separate, remove and re-parse
            if (len(z[0]) > 1 and not isinstance(z[0], str)):
                for x in z[0]:
                    foo = [x, z[1]]
                    tmp_list2.append(foo)
                cp_decs.pop()
                continue
            else:
                tmp_list2.append(z)
        else:
            tmp_list2.append(z)

    tmp_list2 = filter(None, tmp_list2)

    for y in tmp_list2:
        if len(y) > 0:
            y[0] = re.sub(r';\\n', '', str(y[0]).strip('[]\''))
            y[0] = re.sub(r'\\t*', '', y[0])
            y[0] = re.sub(r'\s*private\b', '', y[0])
            y[0] = re.sub(r'\s*protected\b', '', y[0])
            y[0] = re.sub(r'\s*static\b', '', y[0])
            y[0] = re.sub(r'^\s*ContentProvider\b', '', y[0])
            y[0] = re.sub(r'\s*[;=]\s*new\sContentProvider\s.*', '', y[0])
            y[0] = re.sub(r'\s*[;=]\s*new\s\w+\(.*\)', '', y[0])
            y[0] = re.sub(r'^\s*', '', y[0])
            y[0] = re.sub(r'\s*$', '', y[0])
            y[0] = re.sub(r'^\w+\s', '', y[0])
            y[0] = re.sub(r';$', '', y[0])
            #remove whitespace
            y[0] = y[0].strip(' \t\r\n')

    tmp_list2 = common.dedup(tmp_list2)
    return tmp_list2
def find_content_providers():
    """
    Find all content providers and return the list
    """
    cp_list=common.find_ext('ContentProvider')

    growing=1
    #TODO - This is ugly and needs to be re-written
    #The intention here is to loop endlessly until all extensions are found
    while growing:
        cp_list_count_old=len(cp_list)
        cp_list+=common.tree(cp_list)
        if len(cp_list) == cp_list_count_old:
            growing=0

    cp_list.append(['ContentProvider',''])

    cp_decs=[]
    cp_decs.append([])
    for x in cp_list:
        if len(x)>0:
            tmp=r''+re.escape(str(x[0]))+r'\s\w+[;=]'
            cp_decs+=common.text_scan(common.java_files,tmp)
            tmp=r'(private .*|protected.*)'+ re.escape(str(x[0]))+r'\s\w+;'
            cp_decs+=common.text_scan(common.java_files,tmp)
            tmp=r'\w+\s[;=]\snew\s'+re.escape(str(x[0]))+r'\('
            cp_decs+=common.text_scan(common.java_files,tmp)
            tmp=r'\(.*'+re.escape(str(x[0]))+r'\s\w+.*\)' # Need to ensure this is working properly

    tmp_list2=[]
    tmp_list2.append([])
    for z in cp_decs:
        if len(z)>0:
            #conditional declarations will cause conditional positives
            #BUG sometimes Z[0] is a list, rather than just a list element. Need to separate, remove and re-parse
            if (len(z[0])>1 and not isinstance(z[0],str)):
                for x in z[0]:
                    foo=[x,z[1]]
                    tmp_list2.append(foo)
                cp_decs.pop()
                continue
            else:
                tmp_list2.append(z)
        else:
            tmp_list2.append(z)

    tmp_list2=filter(None,tmp_list2)

    for y in tmp_list2:
        if len(y)>0:
            y[0]=re.sub(r';\\n','',str(y[0]).strip('[]\''))
            y[0]=re.sub(r'\\t*','',y[0])
            y[0]=re.sub(r'\s*private\b','',y[0])
            y[0]=re.sub(r'\s*protected\b','',y[0])
            y[0]=re.sub(r'\s*static\b','',y[0])
            y[0]=re.sub(r'^\s*ContentProvider\b','',y[0])
            y[0]=re.sub(r'\s*[;=]\s*new\sContentProvider\s.*','',y[0])
            y[0]=re.sub(r'\s*[;=]\s*new\s\w+\(.*\)','',y[0])
            y[0]=re.sub(r'^\s*','',y[0])
            y[0]=re.sub(r'\s*$','',y[0])
            y[0]=re.sub(r'^\w+\s','',y[0])
            y[0]=re.sub(r';$','',y[0])
            #remove whitespace
            y[0]=y[0].strip(' \t\r\n')

    tmp_list2=common.dedup(tmp_list2)
    return tmp_list2
Пример #3
0
def find_webviews():
    """
    Finds all webviews in the decompiled source code
    """
    #1. Look for classes that extend WebView
    #Find classes that extend Web View
    wv_list = find_ext('WebView')
    #2. Look for classes that extend classes that extend WebView
    while len(common.tree(wv_list)) > 1:
        wv_list += common.tree(wv_list)

    wv_list.append(['WebView', ''])
    #3. Cleanup?
    #4. Look for all declaration of WebViews using normal and extended class names
    #BUG sometimes multiple declarations are coming back for z[0], need to figure out what is going on there
    #Currently there may be false negatives
    #BUG - Need to review this for optional/multiple spaces
    wv_decs = []
    wv_decs.append([])
    for x in wv_list:
        if len(x) > 0:
            tmp = r'' + re.escape(str(x[0])) + r'\s\w+[;=]'
            wv_decs += common.text_scan(common.java_files, tmp)
            tmp = r'(private .*|protected.*)' + re.escape(str(
                x[0])) + r'\s\w+;'
            wv_decs += common.text_scan(common.java_files, tmp)
            tmp = r'\w+\s[;=]\snew\s' + re.escape(str(x[0])) + r'\('
            wv_decs += common.text_scan(common.java_files, tmp)
            tmp = r'\(.*' + re.escape(
                str(x[0])
            ) + r'\s\w+.*\)'  # Need to ensure this is working properly

    tmp_list2 = []
    tmp_list2.append([])
    for z in wv_decs:
        if len(z) > 0:
            #conditional declarations will cause conditional positives
            #BUG sometimes Z[0] is a list, rather than just a list element. Need to separate, remove and re-parse
            if (len(z[0]) > 1 and not isinstance(z[0], str)):
                for x in z[0]:
                    foo = [x, z[1]]
                    tmp_list2.append(foo)
                wv_decs.pop()
                continue
            else:
                tmp_list2.append(z)
        else:
            tmp_list2.append(z)

    tmp_list2 = filter(None, tmp_list2)

    for y in tmp_list2:
        if len(y) > 0:
            y[0] = re.sub(r';\\n', '', str(y[0]).strip('[]\''))
            y[0] = re.sub(r'\\t*', '', y[0])
            y[0] = re.sub(r'\s*private\b', '', y[0])
            y[0] = re.sub(r'\s*protected\b', '', y[0])
            y[0] = re.sub(r'\s*static\b', '', y[0])
            y[0] = re.sub(r'^\s*WebView\b', '', y[0])
            y[0] = re.sub(r'\s*[;=]\s*new\sWebView\s.*', '', y[0])
            y[0] = re.sub(r'\s*[;=]\s*new\s\w+\(.*\)', '', y[0])
            y[0] = re.sub(r'^\s*', '', y[0])
            y[0] = re.sub(r'\s*$', '', y[0])
            y[0] = re.sub(r'^\w+\s', '', y[0])
            y[0] = re.sub(r';$', '', y[0])
            #remove whitespace
            y[0] = y[0].strip(' \t\r\n')

    tmp_list2 = common.dedup(tmp_list2)

    return tmp_list2
Пример #4
0
def find_webviews():
    """
    Finds all webviews in the decompiled source code
    """
    #1. Look for classes that extend WebView
    #Find classes that extend Web View
    wv_list=find_ext('WebView')
    #2. Look for classes that extend classes that extend WebView
    while len(common.tree(wv_list)) > 1:
        wv_list+=common.tree(wv_list)

    wv_list.append(['WebView','']) 
    #3. Cleanup?
    #4. Look for all declaration of WebViews using normal and extended class names
    #BUG sometimes multiple declarations are coming back for z[0], need to figure out what is going on there
    #Currently there may be false negatives
    #BUG - Need to review this for optional/multiple spaces
    wv_decs=[]
    wv_decs.append([])
    for x in wv_list:
        if len(x)>0:
            tmp=r''+re.escape(str(x[0]))+r'\s\w+[;=]'
            wv_decs+=common.text_scan(common.java_files,tmp)
            tmp=r'(private .*|protected.*)'+ re.escape(str(x[0]))+r'\s\w+;'
            wv_decs+=common.text_scan(common.java_files,tmp)
            tmp=r'\w+\s[;=]\snew\s'+re.escape(str(x[0]))+r'\('
            wv_decs+=common.text_scan(common.java_files,tmp)
            tmp=r'\(.*'+re.escape(str(x[0]))+r'\s\w+.*\)' # Need to ensure this is working properly

    tmp_list2=[]
    tmp_list2.append([])
    for z in wv_decs:
        if len(z)>0:
            #conditional declarations will cause conditional positives
            #BUG sometimes Z[0] is a list, rather than just a list element. Need to separate, remove and re-parse
            if (len(z[0])>1 and not isinstance(z[0],str)):
                for x in z[0]:
                    foo=[x,z[1]]
                    tmp_list2.append(foo)
                wv_decs.pop()
                continue
            else:
                tmp_list2.append(z)
        else:
            tmp_list2.append(z)

    tmp_list2=filter(None,tmp_list2)

    for y in tmp_list2:
        if len(y)>0:
            y[0]=re.sub(r';\\n','',str(y[0]).strip('[]\''))
            y[0]=re.sub(r'\\t*','',y[0])
            y[0]=re.sub(r'\s*private\b','',y[0])
            y[0]=re.sub(r'\s*protected\b','',y[0])
            y[0]=re.sub(r'\s*static\b','',y[0])
            y[0]=re.sub(r'^\s*WebView\b','',y[0])
            y[0]=re.sub(r'\s*[;=]\s*new\sWebView\s.*','',y[0])
            y[0]=re.sub(r'\s*[;=]\s*new\s\w+\(.*\)','',y[0])
            y[0]=re.sub(r'^\s*','',y[0])
            y[0]=re.sub(r'\s*$','',y[0])
            y[0]=re.sub(r'^\w+\s','',y[0])
            y[0]=re.sub(r';$','',y[0])
            #remove whitespace
            y[0]=y[0].strip(' \t\r\n')

    tmp_list2=common.dedup(tmp_list2)

    return tmp_list2