mirror of
https://github.com/86Box/bios-tools.git
synced 2026-02-27 17:34:25 -07:00
Optimize analysis by not running strings for analyzers with no checks
This commit is contained in:
@@ -316,25 +316,26 @@ def analyze_dir(formatter, scan_base, file_analyzers, scan_dir_path, scan_file_n
|
||||
bonus_analyzer_oroms = analyzer.oroms
|
||||
continue
|
||||
|
||||
# Run strings on the file data if required (only once).
|
||||
if not strings:
|
||||
try:
|
||||
strings = subprocess.run(['strings', '-n8'], input=file_data, stdout=subprocess.PIPE).stdout.decode('ascii', 'ignore').split('\n')
|
||||
except:
|
||||
util.log_traceback('running strings on', os.path.join(scan_dir_path, scan_file_name))
|
||||
continue
|
||||
# Run strings on the file data if required (only once if requested by analyzer).
|
||||
if analyzer.can_analyze():
|
||||
if not strings:
|
||||
try:
|
||||
strings = subprocess.run(['strings', '-n8'], input=file_data, stdout=subprocess.PIPE).stdout.decode('ascii', 'ignore').split('\n')
|
||||
except:
|
||||
util.log_traceback('running strings on', os.path.join(scan_dir_path, scan_file_name))
|
||||
continue
|
||||
|
||||
# Analyze each string.
|
||||
try:
|
||||
for string in strings:
|
||||
analyzer.analyze_line(string)
|
||||
except analyzers.AbortAnalysisError:
|
||||
# Analysis aborted.
|
||||
pass
|
||||
except:
|
||||
# Log an error.
|
||||
util.log_traceback('analyzing', os.path.join(scan_dir_path, scan_file_name))
|
||||
continue
|
||||
# Analyze each string.
|
||||
try:
|
||||
for string in strings:
|
||||
analyzer.analyze_line(string)
|
||||
except analyzers.AbortAnalysisError:
|
||||
# Analysis aborted.
|
||||
pass
|
||||
except:
|
||||
# Log an error.
|
||||
util.log_traceback('analyzing', os.path.join(scan_dir_path, scan_file_name))
|
||||
continue
|
||||
|
||||
# Take this analyzer if it produced a version.
|
||||
if analyzer.version:
|
||||
|
||||
@@ -127,6 +127,10 @@ class Analyzer:
|
||||
self.debug_print(callback_func.__name__, line)
|
||||
return callback_result
|
||||
|
||||
def can_analyze(self):
|
||||
"""Returns True if the given file's strings should be analyzed."""
|
||||
return len(self._check_list) > 0
|
||||
|
||||
def can_handle(self, file_data, header_data):
|
||||
"""Returns True if this analyzer can handle the given file data.
|
||||
header_data contains data from the :header: flag file, or
|
||||
|
||||
Reference in New Issue
Block a user