This commit is contained in:
Mariusz B. / mgeeky 2021-10-23 16:35:25 +02:00
parent c9681b2ae7
commit d6de562a65
1 changed files with 7 additions and 5 deletions

View File

@ -35,7 +35,7 @@ from itertools import product
from multiprocessing import Pool, Queue, Process, freeze_support, Manager, Lock from multiprocessing import Pool, Queue, Process, freeze_support, Manager, Lock
DEFAULT_COLUMN_SORTED = 'symbol' DEFAULT_COLUMN_SORTED = 'filename'
headers = [ headers = [
'filename', 'filename',
@ -228,6 +228,7 @@ def processFile(args, regexes, path, results, uniqueSymbols, filesProcessed, sym
mod.parse_data_directories() mod.parse_data_directories()
except: except:
mod.close()
return return
imports = collectImports(args, mod) imports = collectImports(args, mod)
@ -319,6 +320,7 @@ def init_worker():
def processDir(args, regexes, path, results, uniqueSymbols, filesProcessed, symbolsProcessed): def processDir(args, regexes, path, results, uniqueSymbols, filesProcessed, symbolsProcessed):
filePaths = [] filePaths = []
out('[.] Building list of files to process...')
for file in glob.glob(os.path.join(path, '**'), recursive=args.recurse): for file in glob.glob(os.path.join(path, '**'), recursive=args.recurse):
try: try:
if len(args.extension) > 0: if len(args.extension) > 0:
@ -351,14 +353,14 @@ def processDir(args, regexes, path, results, uniqueSymbols, filesProcessed, symb
try: try:
arguments = [[args, regexes, _path, results, uniqueSymbols, filesProcessed, symbolsProcessed] for _path in filePaths] arguments = [[args, regexes, _path, results, uniqueSymbols, filesProcessed, symbolsProcessed] for _path in filePaths]
out(f'[.] Will scan {len(filePaths)} files...') out(f'[.] Scanning {Logger.colored(args, len(filePaths), "yellow")} files...')
if len(filePaths) > 5000: if len(filePaths) > 5000:
out(f'[.] Be patient that\'s gonna take a long while...') out(f'[.] Be patient that\'s gonna take a long while...')
res = pool.map(processFileWorker, arguments) res = pool.map(processFileWorker, arguments)
except KeyboardInterrupt: except KeyboardInterrupt:
out(f'[-] User interrupted the scan after {filesProcessed.value} files.') out(f'[-] User interrupted the scan after {Logger.colored(args, filesProcessed.value, "red")} files.')
pool.terminate() pool.terminate()
pool.join() pool.join()
@ -471,7 +473,7 @@ def main():
with open(args.output, 'w') as f: with open(args.output, 'w') as f:
f.write(dumped) f.write(dumped)
else: else:
print(dumped) print('\n' + dumped)
else: else:
resultsList = list(results) resultsList = list(results)
if len(resultsList) > 0: if len(resultsList) > 0:
@ -491,7 +493,7 @@ def main():
with open(args.output, 'w', encoding='utf-8') as f: with open(args.output, 'w', encoding='utf-8') as f:
f.write(str(table)) f.write(str(table))
else: else:
print(table) print('\n' + table)
if args.first > 0: if args.first > 0:
out(f'\n[+] Found {Logger.colored(args, len(resultsList), "green")} symbols meeting all the criterias (but shown only first {Logger.colored(args, args.first, "magenta")} ones).\n') out(f'\n[+] Found {Logger.colored(args, len(resultsList), "green")} symbols meeting all the criterias (but shown only first {Logger.colored(args, args.first, "magenta")} ones).\n')