Skip to content

Commit 3c4d726

Browse files
authored
Merge pull request #171 from fosslight/develop
Add function for getting excluded path
2 parents 317d1a7 + c21ad3c commit 3c4d726

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ py-tlsh
88
pytz
99
XlsxWriter
1010
PyYAML
11-
fosslight_util>=2.1.13
11+
fosslight_util>=2.1.35

src/fosslight_binary/binary_analysis.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from ._simple_mode import print_simple_mode, filter_binary, init_simple
2222
from fosslight_util.correct import correct_with_yaml
2323
from fosslight_util.oss_item import ScannerItem
24-
from fosslight_util.exclude import excluding_files
24+
from fosslight_util.exclude import get_excluded_paths
2525
import hashlib
2626
import tlsh
2727
from io import open
@@ -38,11 +38,9 @@
3838
INCLUDE_FILE_COMMAND_RESULT = ['current ar archive']
3939
_EXCLUDE_FILE_EXTENSION = ['class']
4040
_EXCLUDE_FILE = ['fosslight_bin', 'fosslight_bin.exe']
41-
_EXCLUDE_DIR = ["test", "tests", "doc", "docs", "intermediates"]
41+
_EXCLUDE_DIR = ['intermediates']
4242
_EXCLUDE_DIR = [os.path.sep + dir_name + os.path.sep for dir_name in _EXCLUDE_DIR]
4343
_EXCLUDE_DIR.append("/.")
44-
_REMOVE_DIR = ['.git']
45-
_REMOVE_DIR = [os.path.sep + dir_name + os.path.sep for dir_name in _REMOVE_DIR]
4644
_error_logs = []
4745
_root_path = ""
4846
start_time = ""
@@ -161,8 +159,6 @@ def get_file_list(path_to_find, abs_path_to_exclude):
161159
directory = root + os.path.sep
162160
dir_path = directory.replace(_root_path, '', 1).lower()
163161
dir_path = os.path.sep + dir_path + os.path.sep
164-
if any(dir_name in dir_path for dir_name in _REMOVE_DIR):
165-
continue
166162

167163
bin_with_path = os.path.join(root, file)
168164
bin_item = BinaryItem(bin_with_path)
@@ -216,8 +212,11 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
216212
results = []
217213
bin_list = []
218214
scan_item = ScannerItem(PKG_NAME, "")
219-
exclude_path = excluding_files(path_to_exclude, path_to_find_bin)
220-
abs_path_to_exclude = [os.path.abspath(path) for path in exclude_path]
215+
216+
excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped \
217+
= get_excluded_paths(path_to_find_bin, path_to_exclude + _EXCLUDE_DIR, _EXCLUDE_FILE_EXTENSION + _REMOVE_FILE_EXTENSION)
218+
219+
abs_path_to_exclude = [os.path.abspath(os.path.join(path_to_find_bin, path)) for path in excluded_files]
221220

222221
if not os.path.isdir(path_to_find_bin):
223222
error_occured(error_msg=f"(-p option) Can't find the directory: {path_to_find_bin}",
@@ -247,7 +246,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
247246
else:
248247
total_bin_cnt = len(return_list)
249248
scan_item = ScannerItem(PKG_NAME, start_time)
250-
scan_item.set_cover_pathinfo(path_to_find_bin, path_to_exclude)
249+
scan_item.set_cover_pathinfo(path_to_find_bin, excluded_path_without_dot)
251250
try:
252251
# Run OWASP Dependency-check
253252
if found_jar:
@@ -276,10 +275,9 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
276275
return_list = correct_list
277276
logger.info("Success to correct with yaml.")
278277

279-
scan_item.set_cover_comment(f"Total number of binaries: {total_bin_cnt}")
278+
scan_item.set_cover_comment(f"Detected binaries: {len(return_list)} (Scanned Files : {cnt_file_except_skipped})")
280279
if total_bin_cnt == 0:
281280
scan_item.set_cover_comment("(No binary detected.) ")
282-
scan_item.set_cover_comment(f"Total number of files: {total_file_cnt}")
283281

284282
for combined_path_and_file, output_extension, output_format in zip(result_reports, output_extensions, formats):
285283
results.append(write_output_file(combined_path_and_file, output_extension, scan_item,

0 commit comments

Comments
 (0)