fosslight-binary 5.1.33__tar.gz → 5.1.34__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/PKG-INFO +1 -1
  2. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/pyproject.toml +1 -1
  3. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/binary_analysis.py +125 -108
  4. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary.egg-info/PKG-INFO +1 -1
  5. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/LICENSE +0 -0
  6. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/LICENSES/Apache-2.0.txt +0 -0
  7. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/LICENSES/LicenseRef-3rd-party-licenses.txt +0 -0
  8. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/MANIFEST.in +0 -0
  9. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/README.md +0 -0
  10. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/setup.cfg +0 -0
  11. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/__init__.py +0 -0
  12. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/_binary.py +0 -0
  13. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/_binary_dao.py +0 -0
  14. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/_exclude.py +0 -0
  15. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/_help.py +0 -0
  16. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/_jar_analysis.py +0 -0
  17. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/_simple_mode.py +0 -0
  18. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary/cli.py +0 -0
  19. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary.egg-info/SOURCES.txt +0 -0
  20. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary.egg-info/dependency_links.txt +0 -0
  21. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary.egg-info/entry_points.txt +0 -0
  22. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary.egg-info/requires.txt +0 -0
  23. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/src/fosslight_binary.egg-info/top_level.txt +0 -0
  24. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/tests/test_fosslight_binary.py +0 -0
  25. {fosslight_binary-5.1.33 → fosslight_binary-5.1.34}/tests/test_kb_ssl.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_binary
3
- Version: 5.1.33
3
+ Version: 5.1.34
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "fosslight_binary"
10
- version = "5.1.33"
10
+ version = "5.1.34"
11
11
  description = "FOSSLight Binary Scanner"
12
12
  readme = "README.md"
13
13
  license = "Apache-2.0"
@@ -33,7 +33,7 @@ import shutil
33
33
  PKG_NAME = "fosslight_binary"
34
34
  logger = logging.getLogger(constant.LOGGER_NAME)
35
35
 
36
- _REMOVE_FILE_EXTENSION = ['json', 'js']
36
+ _REMOVE_FILE_EXTENSION = ['json', 'js', 'xlsx', 'xls', 'xlsm']
37
37
  _REMOVE_FILE_COMMAND_RESULT = ['timezone data', 'apple binary property list']
38
38
  INCLUDE_FILE_COMMAND_RESULT = ['current ar archive']
39
39
 
@@ -86,7 +86,9 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
86
86
  output_path = os.path.abspath(output_path)
87
87
 
88
88
  original_output_path = output_path
89
- output_path = os.path.join(output_path, '.fosslight_temp')
89
+ output_path = os.path.join(output_path, f'.fosslight_temp_{file_time}')
90
+ if os.path.isdir(output_path):
91
+ shutil.rmtree(output_path, ignore_errors=True)
90
92
 
91
93
  while len(output_files) < len(output_extensions):
92
94
  output_files.append(None)
@@ -181,12 +183,18 @@ def find_binaries(path_to_find_bin, output_dir, formats, kb_url="", kb_token="",
181
183
  if not path_to_find_bin.endswith(os.path.sep):
182
184
  _root_path += os.path.sep
183
185
 
186
+ output_path = ""
187
+ original_output_path = ""
188
+ log_file = ""
189
+ final_log_path = ""
190
+
184
191
  if simple_mode:
185
192
  mode = "Simple Mode"
186
193
  _result_log, binary_yaml_file, compressed_yaml_file = init_simple(output_dir, PKG_NAME, start_time)
187
194
  else:
188
195
  _result_log, result_reports, output_extensions, formats, output_path, original_output_path, log_file = init(
189
196
  path_to_find_bin, output_dir, formats, path_to_exclude)
197
+ final_log_path = os.path.join(original_output_path, f"fosslight_log_bin_{timestamp_for_filename(start_time)}.txt")
190
198
 
191
199
  total_bin_cnt = 0
192
200
  db_loaded_cnt = 0
@@ -196,130 +204,139 @@ def find_binaries(path_to_find_bin, output_dir, formats, kb_url="", kb_token="",
196
204
  bin_list = []
197
205
  scan_item = ScannerItem(PKG_NAME, "")
198
206
 
199
- if all_exclude_mode and len(all_exclude_mode) == 4:
200
- excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped = all_exclude_mode
201
- elif simple_mode:
202
- excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped \
203
- = get_excluded_paths(
204
- path_to_find_bin, path_to_exclude, REMOVE_FILE_EXTENSION_SIMPLE,
205
- exclude_filenames=EXCLUDE_FILENAME_BINARY)
206
- else:
207
- excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped \
208
- = get_excluded_paths(
209
- path_to_find_bin, path_to_exclude,
210
- exclude_filenames=EXCLUDE_FILENAME_BINARY)
211
- logger.debug(f"Skipped paths: {excluded_path_with_default_exclusion}")
212
-
213
- if not os.path.isdir(path_to_find_bin):
214
- error_occured(error_msg=f"(-p option) Can't find the directory: {path_to_find_bin}",
215
- result_log=_result_log,
216
- exit=True,
217
- mode=mode)
218
- if not correct_filepath:
219
- correct_filepath = path_to_find_bin
220
207
  try:
221
- _, file_list, found_jar = get_file_list(path_to_find_bin, excluded_files)
222
- return_list = list(return_bin_only(file_list))
223
- except Exception as ex:
224
- error_occured(error_msg=f"Failed to check whether it is binary or not : {ex}",
225
- result_log=_result_log,
226
- exit=True,
227
- mode=mode)
228
- if simple_mode:
208
+ if all_exclude_mode and len(all_exclude_mode) == 4:
209
+ excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped = all_exclude_mode
210
+ elif simple_mode:
211
+ excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped \
212
+ = get_excluded_paths(
213
+ path_to_find_bin, path_to_exclude, REMOVE_FILE_EXTENSION_SIMPLE,
214
+ exclude_filenames=EXCLUDE_FILENAME_BINARY)
215
+ else:
216
+ excluded_path_with_default_exclusion, excluded_path_without_dot, excluded_files, cnt_file_except_skipped \
217
+ = get_excluded_paths(
218
+ path_to_find_bin, path_to_exclude,
219
+ exclude_filenames=EXCLUDE_FILENAME_BINARY)
220
+ logger.debug(f"Skipped paths: {excluded_path_with_default_exclusion}")
221
+
222
+ if not os.path.isdir(path_to_find_bin):
223
+ error_occured(error_msg=f"(-p option) Can't find the directory: {path_to_find_bin}",
224
+ result_log=_result_log,
225
+ exit=True,
226
+ mode=mode)
227
+
228
+ if not correct_filepath:
229
+ correct_filepath = path_to_find_bin
229
230
  try:
230
- compressed_list, filtered_bin_list = filter_binary(return_list)
231
- results = print_simple_mode(binary_yaml_file, compressed_yaml_file, compressed_list, filtered_bin_list)
232
- total_bin_cnt = len(filtered_bin_list) + len(compressed_list)
231
+ _, file_list, found_jar = get_file_list(path_to_find_bin, excluded_files)
232
+ return_list = list(return_bin_only(file_list))
233
233
  except Exception as ex:
234
- error_occured(error_msg=f"Failed to run simple mode: {ex}",
234
+ error_occured(error_msg=f"Failed to check whether it is binary or not : {ex}",
235
235
  result_log=_result_log,
236
236
  exit=True,
237
- mode="Simple mode")
237
+ mode=mode)
238
238
 
239
- for success_to_write, writing_msg, result_file in results:
240
- if success_to_write:
241
- if result_file:
242
- logger.info(f"Output file :{result_file}")
243
- else:
244
- logger.warning(f"{writing_msg}")
245
- else:
246
- logger.error(f"Fail to generate result file.:{writing_msg}")
247
- else:
248
- total_bin_cnt = len(return_list)
249
- scan_item = ScannerItem(PKG_NAME, start_time)
250
- scan_item.set_cover_pathinfo(path_to_find_bin, excluded_path_without_dot)
251
- try:
252
- # Run JAR analysis via Maven Central API
253
- if found_jar:
254
- logger.info("Run to analyze .jar file")
255
- jar_items, success = analyze_jar_file(path_to_find_bin, excluded_files)
256
- if success:
257
- return_list = merge_binary_list(jar_items, return_list)
258
- else:
259
- logger.warning("Could not find OSS information for some jar files.")
260
-
261
- return_list, db_loaded_cnt, kb_cover_msg = get_oss_info_from_db(return_list, kb_url, kb_token)
262
- return_list = sorted(return_list, key=lambda row: (row.bin_name_with_path))
263
- scan_item.append_file_items(return_list, PKG_NAME)
264
- if correct_mode:
265
- success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_find_bin, scan_item)
266
- if not success:
267
- logger.info(f"No correction with yaml: {msg_correct}")
239
+ if simple_mode:
240
+ try:
241
+ compressed_list, filtered_bin_list = filter_binary(return_list)
242
+ results = print_simple_mode(binary_yaml_file, compressed_yaml_file, compressed_list, filtered_bin_list)
243
+ total_bin_cnt = len(filtered_bin_list) + len(compressed_list)
244
+ except Exception as ex:
245
+ error_occured(error_msg=f"Failed to run simple mode: {ex}",
246
+ result_log=_result_log,
247
+ exit=True,
248
+ mode="Simple mode")
249
+
250
+ for success_to_write, writing_msg, result_file in results:
251
+ if success_to_write:
252
+ if result_file:
253
+ logger.info(f"Output file :{result_file}")
254
+ else:
255
+ logger.warning(f"{writing_msg}")
268
256
  else:
269
- return_list = correct_list
270
- logger.info("Success to correct with yaml.")
257
+ logger.error(f"Fail to generate result file.:{writing_msg}")
258
+ else:
259
+ total_bin_cnt = len(return_list)
260
+ scan_item = ScannerItem(PKG_NAME, start_time)
261
+ scan_item.set_cover_pathinfo(path_to_find_bin, excluded_path_without_dot)
262
+ try:
263
+ if found_jar:
264
+ logger.info("Run to analyze .jar file")
265
+ jar_items, success = analyze_jar_file(path_to_find_bin, excluded_files)
266
+ if success:
267
+ return_list = merge_binary_list(jar_items, return_list)
268
+ else:
269
+ logger.warning("Could not find OSS information for some jar files.")
270
+
271
+ return_list, db_loaded_cnt, kb_cover_msg = get_oss_info_from_db(return_list, kb_url, kb_token)
272
+ return_list = sorted(return_list, key=lambda row: (row.bin_name_with_path))
273
+ scan_item.append_file_items(return_list, PKG_NAME)
274
+ if correct_mode:
275
+ success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_find_bin, scan_item)
276
+ if not success:
277
+ logger.info(f"No correction with yaml: {msg_correct}")
278
+ else:
279
+ return_list = correct_list
280
+ logger.info("Success to correct with yaml.")
271
281
 
272
- finish_time = current_timestamp_utc()
273
- scan_item.set_cover_comment(f"Detected binaries: {len(return_list)} (Scanned Files : {cnt_file_except_skipped})")
274
- if kb_cover_msg:
275
- scan_item.set_cover_comment(kb_cover_msg)
276
- scan_item.set_cover_finish_time(finish_time)
282
+ finish_time = current_timestamp_utc()
283
+ scan_item.set_cover_comment(f"Detected binaries: {len(return_list)} (Scanned Files : {cnt_file_except_skipped})")
284
+ if kb_cover_msg:
285
+ scan_item.set_cover_comment(kb_cover_msg)
286
+ scan_item.set_cover_finish_time(finish_time)
277
287
 
278
- for combined_path_and_file, output_extension, output_format in zip(result_reports, output_extensions, formats):
279
- results.append(write_output_file(combined_path_and_file, output_extension, scan_item,
280
- BIN_EXT_HEADER, HIDE_HEADER, output_format,
281
- scanner_covers=[scan_item.cover]))
288
+ for combined_path_and_file, output_extension, output_format in zip(result_reports, output_extensions, formats):
289
+ results.append(write_output_file(combined_path_and_file, output_extension, scan_item,
290
+ BIN_EXT_HEADER, HIDE_HEADER, output_format,
291
+ scanner_covers=[scan_item.cover]))
282
292
 
283
- except Exception as ex:
284
- error_occured(error_msg=str(ex), exit=False)
293
+ except Exception as ex:
294
+ error_occured(error_msg=str(ex), exit=False)
285
295
 
286
- for success_to_write, writing_msg, result_file in results:
287
- if success_to_write:
288
- if result_file:
289
- logger.info(f"Output file :{os.path.join(original_output_path, os.path.basename(result_file))}")
296
+ for success_to_write, writing_msg, result_file in results:
297
+ if success_to_write:
298
+ if result_file:
299
+ logger.info(f"Output file :{os.path.join(original_output_path, os.path.basename(result_file))}")
300
+ else:
301
+ logger.warning(f"{writing_msg}")
302
+ for row in scan_item.get_cover_comment():
303
+ logger.info(row)
290
304
  else:
291
- logger.warning(f"{writing_msg}")
292
- for row in scan_item.get_cover_comment():
293
- logger.info(row)
294
- else:
295
- logger.error(f"Fail to generate result file.:{writing_msg}")
305
+ logger.error(f"Fail to generate result file.:{writing_msg}")
296
306
 
297
- try:
298
- if os.path.isfile(log_file):
299
- move_log_file(log_file, os.path.join(original_output_path, f"fosslight_log_bin_{timestamp_for_filename(start_time)}.txt"))
300
- else:
301
- logger.debug("Moving binary analysis log file is skipped")
302
- except Exception as ex:
303
- logger.debug(f"Failed to move log file: {ex}")
307
+ try:
308
+ if os.path.isdir(output_path):
309
+ shutil.copytree(output_path, original_output_path, dirs_exist_ok=True)
310
+ else:
311
+ logger.debug(f"Temp directory not found, skip moving: {output_path}")
312
+ except Exception as ex:
313
+ logger.debug(f"Failed to move temp files: {ex}")
314
+ success_to_write = False
304
315
 
305
316
  try:
306
- if os.path.isdir(output_path):
307
- shutil.copytree(output_path, original_output_path, dirs_exist_ok=True)
308
- shutil.rmtree(output_path)
309
- else:
310
- logger.debug(f"Temp directory not found, skip moving: {output_path}")
317
+ print_result_log(mode=mode, success=True, result_log=_result_log,
318
+ file_cnt=str(cnt_file_except_skipped),
319
+ bin_file_cnt=str(total_bin_cnt),
320
+ auto_bin_cnt=str(db_loaded_cnt), bin_list=bin_list)
311
321
  except Exception as ex:
312
- logger.debug(f"Failed to move temp files: {ex}")
322
+ error_occured(error_msg=f"Print log : {ex}", exit=False)
313
323
 
314
- try:
315
- print_result_log(mode=mode, success=True, result_log=_result_log,
316
- file_cnt=str(cnt_file_except_skipped),
317
- bin_file_cnt=str(total_bin_cnt),
318
- auto_bin_cnt=str(db_loaded_cnt), bin_list=bin_list)
319
- except Exception as ex:
320
- error_occured(error_msg=f"Print log : {ex}", exit=False)
324
+ return success_to_write, scan_item
325
+ finally:
326
+ if output_path:
327
+ try:
328
+ if log_file and final_log_path and os.path.isfile(log_file):
329
+ move_log_file(log_file, final_log_path)
330
+ elif log_file:
331
+ logger.debug("Moving binary analysis log file is skipped")
332
+ except Exception as ex:
333
+ logger.debug(f"Failed to move log file: {ex}")
321
334
 
322
- return success_to_write, scan_item
335
+ try:
336
+ if os.path.isdir(output_path):
337
+ shutil.rmtree(output_path)
338
+ except Exception as ex:
339
+ logger.debug(f"Failed to cleanup temp files: {ex}")
323
340
 
324
341
 
325
342
  def return_bin_only(file_list, need_checksum_tlsh=True):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_binary
3
- Version: 5.1.33
3
+ Version: 5.1.34
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Author: LG Electronics
6
6
  License-Expression: Apache-2.0