(**kwargs)
return return_list
Helper function for searching text files

    This function will take a list of file paths and search through
    them with a given regex. Relevant messages will be printed to the console
    and log.

    Expected kwargs: file_paths, regex, message_text, message_box
Helper function for searching text files
Helper function for searching text files
def regex_vuln_search(**kwargs):
    """Helper function for searching text files

    This function will take a list of file paths and search through
    them with a given regex. Relevant messages will be printed to the console
    and log.

    Expected kwargs: file_paths, regex, message_text, message_box
    """
    # Start a list of dictionaries for files with interesting content.
    return_list = []

    # Open up each individual file and read the text into memory.
    for file_name in kwargs['file_paths']:
        return_dict = {}

        # Continue if we can't access the file.
        if not os.access(file_name, os.R_OK):
            continue

        file_object = open(file_name, 'r')
        file_text = file_object.read()
        # Use the regex we pass in to the function to look for vulns.
        found = re.findall(kwargs['regex'], file_text)

        # Save the file name and the interesting lines of text
        if found:
            return_dict['file_name'] = file_name
            return_dict['text'] = found
            return_list.append(return_dict)

    # If the function is supplied with message info, print to console and log.
    # This function may be used instead as input to another function, so we
    # don't always want to print here.
    if return_list and kwargs['message_text'] and kwargs['message_box']:
        # Print to console and log the interesting file names and content.
        tee("")
        tee(kwargs['message_text'], box=kwargs['message_box'])
        for item in return_list:
            tee("  {}:".format(item['file_name']))
            for text in item['text']:
                tee("    {}".format(text))
            tee("")

    if ARGS.debug:
        print("DEBUG, SEARCH RESULTS")
        for item in return_list:
            print(item['file_name'])
            for text in item['text']:
                print("  {}".format(text))

    return return_list
def regex_vuln_search ( * * kwargs ) : # Start a list of dictionaries for files with interesting content. return_list = [ ] # Open up each individual file and read the text into memory. for file_name in kwargs [ 'file_paths' ] : return_dict = { } # Continue if we can't access the file. if not os . access ( file_name , os . R_OK ) : continue file_object = open ( file_name , 'r' ) file_text = file_object . read ( ) # Use the regex we pass in to the function to look for vulns. found = re . findall ( kwargs [ 'regex' ] , file_text ) # Save the file name and the interesting lines of text if found : return_dict [ 'file_name' ] = file_name return_dict [ 'text' ] = found return_list . append ( return_dict ) # If the function is supplied with message info, print to console and log. # This function may be used instead as input to another function, so we # don't always want to print here. if return_list and kwargs [ 'message_text' ] and kwargs [ 'message_box' ] : # Print to console and log the interesting file names and content. tee ( "" ) tee ( kwargs [ 'message_text' ] , box = kwargs [ 'message_box' ] ) for item in return_list : tee ( "  {}:" . format ( item [ 'file_name' ] ) ) for text in item [ 'text' ] : tee ( "    {}" . format ( text ) ) tee ( "" ) if ARGS . debug : print ( "DEBUG, SEARCH RESULTS" ) for item in return_list : print ( item [ 'file_name' ] ) for text in item [ 'text' ] : print ( "  {}" . format ( text ) ) return return_list