def enable_olefile_logging(): """ enable logging olefile e.g., to get debug info from OleFileIO """ olefile.enable_logging()
def main(cmd_line_args=None): """ main function, called when running this as script Per default (cmd_line_args=None) uses sys.argv. For testing, however, can provide other arguments. """ # print banner with version print('oleobj %s - http://decalage.info/oletools' % __version__) print('THIS IS WORK IN PROGRESS - Check updates regularly!') print('Please report any issue at ' 'https://github.com/decalage2/oletools/issues') print('') usage = 'usage: %(prog)s [options] <filename> [filename2 ...]' parser = argparse.ArgumentParser(usage=usage) # parser.add_argument('-o', '--outfile', dest='outfile', # help='output file') # parser.add_argument('-c', '--csv', dest='csv', # help='export results to a CSV file') parser.add_argument("-r", action="store_true", dest="recursive", help='find files recursively in subdirectories.') parser.add_argument("-d", type=str, dest="output_dir", default=None, help='use specified directory to output files.') parser.add_argument("-z", "--zip", dest='zip_password', type=str, default=None, help='if the file is a zip archive, open first file ' 'from it, using the provided password (requires ' 'Python 2.6+)') parser.add_argument("-f", "--zipfname", dest='zip_fname', type=str, default='*', help='if the file is a zip archive, file(s) to be ' 'opened within the zip. Wildcards * and ? are ' 'supported. (default:*)') parser.add_argument('-l', '--loglevel', dest="loglevel", action="store", default=DEFAULT_LOG_LEVEL, help='logging level debug/info/warning/error/critical ' '(default=%(default)s)') parser.add_argument('input', nargs='*', type=existing_file, metavar='FILE', help='Office files to parse (same as -i)') # options for compatibility with ripOLE parser.add_argument('-i', '--more-input', type=str, metavar='FILE', help='Additional file to parse (same as positional ' 'arguments)') parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode, set logging to DEBUG ' '(overwrites -l)') options = parser.parse_args(cmd_line_args) if options.more_input: options.input += [ options.more_input, ] if options.verbose: options.loglevel = 'debug' # Print help if no arguments are passed if not options.input: parser.print_help() return RETURN_ERR_ARGS # Setup logging to the console: # here we use stdout instead of stderr by default, so that the output # can be redirected properly. logging.basicConfig(level=LOG_LEVELS[options.loglevel], stream=sys.stdout, format='%(levelname)-8s %(message)s') # enable logging in the modules: log.setLevel(logging.NOTSET) if options.loglevel == 'debug-olefile': olefile.enable_logging() # remember if there was a problem and continue with other data any_err_stream = False any_err_dumping = False any_did_dump = False for container, filename, data in \ xglob.iter_files(options.input, recursive=options.recursive, zip_password=options.zip_password, zip_fname=options.zip_fname): # ignore directory names stored in zip files: if container and filename.endswith('/'): continue err_stream, err_dumping, did_dump = \ process_file(filename, data, options.output_dir) any_err_stream |= err_stream any_err_dumping |= err_dumping any_did_dump |= did_dump # assemble return value return_val = RETURN_NO_DUMP if any_did_dump: return_val += RETURN_DID_DUMP if any_err_stream: return_val += RETURN_ERR_STREAM if any_err_dumping: return_val += RETURN_ERR_DUMP return return_val
def main(cmd_line_args=None): """ main function, called when running this as script Per default (cmd_line_args=None) uses sys.argv. For testing, however, can provide other arguments. """ # print banner with version print('oleobj %s - http://decalage.info/oletools' % __version__) print('THIS IS WORK IN PROGRESS - Check updates regularly!') print('Please report any issue at ' 'https://github.com/decalage2/oletools/issues') print('') usage = 'usage: %(prog)s [options] <filename> [filename2 ...]' parser = argparse.ArgumentParser(usage=usage) # parser.add_argument('-o', '--outfile', dest='outfile', # help='output file') # parser.add_argument('-c', '--csv', dest='csv', # help='export results to a CSV file') parser.add_argument("-r", action="store_true", dest="recursive", help='find files recursively in subdirectories.') parser.add_argument("-d", type=str, dest="output_dir", default=None, help='use specified directory to output files.') parser.add_argument("-z", "--zip", dest='zip_password', type=str, default=None, help='if the file is a zip archive, open first file ' 'from it, using the provided password (requires ' 'Python 2.6+)') parser.add_argument("-f", "--zipfname", dest='zip_fname', type=str, default='*', help='if the file is a zip archive, file(s) to be ' 'opened within the zip. Wildcards * and ? are ' 'supported. (default:*)') parser.add_argument('-l', '--loglevel', dest="loglevel", action="store", default=DEFAULT_LOG_LEVEL, help='logging level debug/info/warning/error/critical ' '(default=%(default)s)') parser.add_argument('input', nargs='*', type=existing_file, metavar='FILE', help='Office files to parse (same as -i)') # options for compatibility with ripOLE parser.add_argument('-i', '--more-input', type=str, metavar='FILE', help='Additional file to parse (same as positional ' 'arguments)') parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode, set logging to DEBUG ' '(overwrites -l)') options = parser.parse_args(cmd_line_args) if options.more_input: options.input += [options.more_input, ] if options.verbose: options.loglevel = 'debug' # Print help if no arguments are passed if not options.input: parser.print_help() return RETURN_ERR_ARGS # Setup logging to the console: # here we use stdout instead of stderr by default, so that the output # can be redirected properly. logging.basicConfig(level=LOG_LEVELS[options.loglevel], stream=sys.stdout, format='%(levelname)-8s %(message)s') # enable logging in the modules: log.setLevel(logging.NOTSET) if options.loglevel == 'debug-olefile': olefile.enable_logging() # remember if there was a problem and continue with other data any_err_stream = False any_err_dumping = False any_did_dump = False for container, filename, data in \ xglob.iter_files(options.input, recursive=options.recursive, zip_password=options.zip_password, zip_fname=options.zip_fname): # ignore directory names stored in zip files: if container and filename.endswith('/'): continue err_stream, err_dumping, did_dump = \ process_file(filename, data, options.output_dir) any_err_stream |= err_stream any_err_dumping |= err_dumping any_did_dump |= did_dump # assemble return value return_val = RETURN_NO_DUMP if any_did_dump: return_val += RETURN_DID_DUMP if any_err_stream: return_val += RETURN_ERR_STREAM if any_err_dumping: return_val += RETURN_ERR_DUMP return return_val