From 4be4add6313c55d6a7d52f86ebff9f74b62567e9 Mon Sep 17 00:00:00 2001 From: "jiyeong.seok" Date: Fri, 4 Oct 2024 18:17:33 +0900 Subject: [PATCH 1/2] Update spdx function Signed-off-by: jiyeong.seok --- requirements.txt | 2 +- src/fosslight_binary/_binary.py | 1 - src/fosslight_binary/binary_analysis.py | 9 +++++---- src/fosslight_binary/cli.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 148d24c..4f5a7dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,5 +8,5 @@ py-tlsh pytz XlsxWriter PyYAML -fosslight_util>=2.0.0 +fosslight_util>=2.0.1 dependency-check diff --git a/src/fosslight_binary/_binary.py b/src/fosslight_binary/_binary.py index cb8d2f1..277bce9 100755 --- a/src/fosslight_binary/_binary.py +++ b/src/fosslight_binary/_binary.py @@ -24,7 +24,6 @@ def __init__(self, value): super().__init__("") self.exclude = False self.source_name_or_path = "" - self.checksum = TLSH_CHECKSUM_NULL self.tlsh = TLSH_CHECKSUM_NULL self.vulnerability_items = [] self.binary_name_without_path = "" diff --git a/src/fosslight_binary/binary_analysis.py b/src/fosslight_binary/binary_analysis.py index d60165f..d8d56ae 100755 --- a/src/fosslight_binary/binary_analysis.py +++ b/src/fosslight_binary/binary_analysis.py @@ -13,7 +13,7 @@ import stat from fosslight_util.set_log import init_log import fosslight_util.constant as constant -from fosslight_util.output_format import check_output_formats, write_output_file +from fosslight_util.output_format import check_output_formats_v2, write_output_file from ._binary_dao import get_oss_info_from_db from ._binary import BinaryItem, TLSH_CHECKSUM_NULL from ._jar_analysis import analyze_jar_file, merge_binary_list @@ -83,7 +83,7 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]): if not path_to_find_bin.endswith(os.path.sep): _root_path += os.path.sep - success, msg, output_path, output_files, output_extensions = check_output_formats(output_file_name, formats) + success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats) if success: if output_path == "": @@ -221,8 +221,9 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F scan_item.set_cover_comment("(No binary detected.) ") scan_item.set_cover_comment(f"Total number of files: {total_file_cnt}") - for combined_path_and_file, output_extension in zip(result_reports, output_extensions): - results.append(write_output_file(combined_path_and_file, output_extension, scan_item, BIN_EXT_HEADER, HIDE_HEADER)) + for combined_path_and_file, output_extension, output_format in zip(result_reports, output_extensions, formats): + results.append(write_output_file(combined_path_and_file, output_extension, scan_item, + BIN_EXT_HEADER, HIDE_HEADER, output_format)) except Exception as ex: error_occured(error_msg=str(ex), exit=False) diff --git a/src/fosslight_binary/cli.py b/src/fosslight_binary/cli.py index 2086d34..95eb6e4 100644 --- a/src/fosslight_binary/cli.py +++ b/src/fosslight_binary/cli.py @@ -18,7 +18,7 @@ def main(): path_to_find_bin = "" path_to_exclude = [] output_dir = "" - format = "" + format = [] db_url = "" simple_mode = False correct_mode = True From 8df29948ca0d358379399889a5e5bfddb4505dd9 Mon Sep 17 00:00:00 2001 From: "jiyeong.seok" Date: Mon, 7 Oct 2024 17:04:25 +0900 Subject: [PATCH 2/2] Update fosslight util version Signed-off-by: jiyeong.seok --- requirements.txt | 2 +- src/fosslight_binary/binary_analysis.py | 28 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4f5a7dc..9b53f8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,5 +8,5 @@ py-tlsh pytz XlsxWriter PyYAML -fosslight_util>=2.0.1 +fosslight_util>=2.1.0 dependency-check diff --git a/src/fosslight_binary/binary_analysis.py b/src/fosslight_binary/binary_analysis.py index d8d56ae..d67a691 100755 --- a/src/fosslight_binary/binary_analysis.py +++ b/src/fosslight_binary/binary_analysis.py @@ -5,6 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 import os import sys +import platform from datetime import datetime from binaryornot.check import is_binary import magic @@ -93,12 +94,33 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]): while len(output_files) < len(output_extensions): output_files.append(None) + to_remove = [] # elements of spdx format on windows that should be removed for i, output_extension in enumerate(output_extensions): if output_files[i] is None or output_files[i] == "": - if output_extension == _json_ext: - output_files[i] = f"fosslight_opossum_bin_{_start_time}" + if formats: + if formats[i].startswith('spdx'): + if platform.system() != 'Windows': + output_files[i] = f"fosslight_spdx_bin_{_start_time}" + else: + logger.warning('spdx format is not supported on Windows. Please remove spdx from format.') + to_remove.append(i) + else: + if output_extension == _json_ext: + output_files[i] = f"fosslight_opossum_bin_{_start_time}" + else: + output_files[i] = f"fosslight_report_bin_{_start_time}" else: - output_files[i] = f"fosslight_report_bin_{_start_time}" + if output_extension == _json_ext: + output_files[i] = f"fosslight_opossum_bin_{_start_time}" + else: + output_files[i] = f"fosslight_report_bin_{_start_time}" + for index in sorted(to_remove, reverse=True): + # remove elements of spdx format on windows + del output_files[index] + del output_extensions[index] + del formats[index] + if len(output_extensions) < 1: + sys.exit(0) combined_paths_and_files = [os.path.join(output_path, file) for file in output_files] else: