1616import fosslight_util .constant as constant
1717from fosslight_util .output_format import check_output_formats_v2 , write_output_file
1818from ._binary_dao import get_oss_info_from_db
19- from ._binary import BinaryItem , TLSH_CHECKSUM_NULL , is_package_dir
19+ from ._binary import BinaryItem , TLSH_CHECKSUM_NULL
2020from ._jar_analysis import analyze_jar_file , merge_binary_list
2121from ._simple_mode import print_simple_mode , filter_binary , init_simple
2222from fosslight_util .correct import correct_with_yaml
@@ -131,19 +131,16 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
131131 return _result_log , combined_paths_and_files , output_extensions , formats
132132
133133
134- def get_file_list (path_to_find , abs_path_to_exclude ):
134+ def get_file_list (path_to_find , excluded_files ):
135135 bin_list = []
136136 file_cnt = 0
137137 found_jar = False
138138
139139 for root , dirs , files in os .walk (path_to_find ):
140- if os .path .abspath (root ) in abs_path_to_exclude :
141- continue
142140 for file in files :
143- file_path = os .path .join (root , file )
144- file_abs_path = os .path .abspath (file_path )
145- if any (os .path .commonpath ([file_abs_path , exclude_path ]) == exclude_path
146- for exclude_path in abs_path_to_exclude ):
141+ bin_with_path = os .path .join (root , file )
142+ rel_path_file = os .path .relpath (bin_with_path , path_to_find ).replace ('\\ ' , '/' )
143+ if rel_path_file in excluded_files :
147144 continue
148145 file_lower_case = file .lower ()
149146 extension = os .path .splitext (file_lower_case )[1 ][1 :].strip ()
@@ -155,26 +152,18 @@ def get_file_list(path_to_find, abs_path_to_exclude):
155152 dir_path = directory .replace (_root_path , '' , 1 ).lower ()
156153 dir_path = os .path .sep + dir_path + os .path .sep
157154
158- bin_with_path = os .path .join (root , file )
159155 bin_item = BinaryItem (bin_with_path )
160156 bin_item .binary_name_without_path = file
161157 bin_item .source_name_or_path = bin_with_path .replace (_root_path , '' , 1 )
162158
163- is_pkg , pkg_path = is_package_dir (bin_with_path , _root_path )
164- if is_pkg :
165- bin_item .source_name_or_path = pkg_path
166- if not any (x .source_name_or_path == bin_item .source_name_or_path for x in bin_list ):
167- bin_item .exclude = True
168- bin_list .append (bin_item )
169- continue
170-
171159 bin_list .append (bin_item )
172160 file_cnt += 1
173161 return file_cnt , bin_list , found_jar
174162
175163
176164def find_binaries (path_to_find_bin , output_dir , formats , dburl = "" , simple_mode = False ,
177- correct_mode = True , correct_filepath = "" , path_to_exclude = []):
165+ correct_mode = True , correct_filepath = "" , path_to_exclude = [],
166+ all_exclude_mode = ()):
178167 global start_time , _root_path , _result_log
179168
180169 mode = "Normal Mode"
@@ -200,10 +189,12 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
200189 bin_list = []
201190 scan_item = ScannerItem (PKG_NAME , "" )
202191
203- excluded_path_with_default_exclusion , excluded_path_without_dot , excluded_files , cnt_file_except_skipped \
204- = get_excluded_paths (path_to_find_bin , path_to_exclude )
205-
206- abs_path_to_exclude = [os .path .abspath (os .path .join (path_to_find_bin , path )) for path in excluded_files ]
192+ if all_exclude_mode and len (all_exclude_mode ) == 4 :
193+ excluded_path_with_default_exclusion , excluded_path_without_dot , excluded_files , cnt_file_except_skipped = all_exclude_mode
194+ else :
195+ excluded_path_with_default_exclusion , excluded_path_without_dot , excluded_files , cnt_file_except_skipped \
196+ = get_excluded_paths (path_to_find_bin , path_to_exclude )
197+ logger .debug (f"Skipped paths: { excluded_path_with_default_exclusion } " )
207198
208199 if not os .path .isdir (path_to_find_bin ):
209200 error_occured (error_msg = f"(-p option) Can't find the directory: { path_to_find_bin } " ,
@@ -213,7 +204,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
213204 if not correct_filepath :
214205 correct_filepath = path_to_find_bin
215206 try :
216- total_file_cnt , file_list , found_jar = get_file_list (path_to_find_bin , abs_path_to_exclude )
207+ total_file_cnt , file_list , found_jar = get_file_list (path_to_find_bin , excluded_files )
217208 return_list = list (return_bin_only (file_list ))
218209 except Exception as ex :
219210 error_occured (error_msg = f"Failed to check whether it is binary or not : { ex } " ,
@@ -245,7 +236,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
245236 logger .warning (f"Java version { java_ver } detected (<11). FOSSLight Binary Scanner requires Java 11+ to analyze .jar files." )
246237 else :
247238 logger .info ("Run OWASP Dependency-check to analyze .jar file" )
248- owasp_items , vulnerability_items , success = analyze_jar_file (path_to_find_bin , abs_path_to_exclude )
239+ owasp_items , vulnerability_items , success = analyze_jar_file (path_to_find_bin , excluded_files )
249240 if success :
250241 return_list = merge_binary_list (owasp_items , vulnerability_items , return_list )
251242 else :
@@ -263,8 +254,6 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
263254 logger .info ("Success to correct with yaml." )
264255
265256 scan_item .set_cover_comment (f"Detected binaries: { len (return_list )} (Scanned Files : { cnt_file_except_skipped } )" )
266- if total_bin_cnt == 0 :
267- scan_item .set_cover_comment ("(No binary detected.) " )
268257
269258 for combined_path_and_file , output_extension , output_format in zip (result_reports , output_extensions , formats ):
270259 results .append (write_output_file (combined_path_and_file , output_extension , scan_item ,
0 commit comments