Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support spdx #126

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ py-tlsh
pytz
XlsxWriter
PyYAML
fosslight_util>=2.0.0
fosslight_util>=2.1.0
dependency-check
1 change: 0 additions & 1 deletion src/fosslight_binary/_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
37 changes: 30 additions & 7 deletions src/fosslight_binary/binary_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +14,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
Expand Down Expand Up @@ -83,7 +84,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 == "":
Expand All @@ -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:
Expand Down Expand Up @@ -221,8 +243,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)
Expand Down
2 changes: 1 addition & 1 deletion src/fosslight_binary/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading