def scan(path, count): """selects files to process, checks file names""" log_comment('scanning %s:' % path) scanned = 0 bar_width = 32 if count < bar_width: bar_width = count if count == 0: bar_width = 1 sys.stdout.write('%s\n' % ("=" * bar_width)) bar_blocksize = count / bar_width bar_left = bar_width bar_count = 0 for root, dirs, files in os.walk(path): for skip in SKIP: if skip in dirs: dirs.remove(skip) for filename in files: abspath = os.path.abspath(os.path.join(root, filename)) res = RGX_INFILENAME.search(filename.lower()) if res: log_secret(res.group(), abspath) try: ftype, supported = type_file(abspath) except TypeError as e: log_error(str(e), abspath) continue if supported: if ftype in ENCRYPTED: # report but do not process log_encrypted(ftype, abspath) if ftype in EXE: # report but do not process if looks_uniform(filename=abspath): log_packed(ftype, abspath) else: log_exe(ftype, abspath) else: # process the file do_file(ftype, abspath) scanned += 1 # update progress bar bar_count += 1 if bar_count >= bar_blocksize and bar_left: sys.stdout.write("=") sys.stdout.flush() bar_count = 0 bar_left -= 1 sys.stdout.write("\n") log_comment('%d files supported were processed' % scanned) return scanned
def process(selected): for afile, ftype in selected: do_file(ftype, afile)