fosslight-binary 5.0.0__tar.gz → 5.1.1__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 (23) hide show
  1. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/PKG-INFO +1 -1
  2. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/requirements.txt +1 -1
  3. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/setup.py +1 -1
  4. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/_binary.py +0 -1
  5. fosslight_binary-5.1.1/src/fosslight_binary/_simple_mode.py +118 -0
  6. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/binary_analysis.py +74 -34
  7. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/cli.py +2 -2
  8. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary.egg-info/PKG-INFO +1 -1
  9. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary.egg-info/SOURCES.txt +1 -0
  10. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary.egg-info/requires.txt +1 -1
  11. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/LICENSE +0 -0
  12. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/LICENSES/Apache-2.0.txt +0 -0
  13. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/LICENSES/LicenseRef-3rd_party_licenses.txt +0 -0
  14. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/MANIFEST.in +0 -0
  15. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/README.md +0 -0
  16. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/setup.cfg +0 -0
  17. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/__init__.py +0 -0
  18. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/_binary_dao.py +0 -0
  19. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/_help.py +0 -0
  20. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary/_jar_analysis.py +0 -0
  21. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary.egg-info/dependency_links.txt +0 -0
  22. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary.egg-info/entry_points.txt +0 -0
  23. {fosslight_binary-5.0.0 → fosslight_binary-5.1.1}/src/fosslight_binary.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight_binary
3
- Version: 5.0.0
3
+ Version: 5.1.1
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_binary_scanner
6
6
  Author: LG Electronics
@@ -8,5 +8,5 @@ py-tlsh
8
8
  pytz
9
9
  XlsxWriter
10
10
  PyYAML
11
- fosslight_util>=2.0.0
11
+ fosslight_util>=2.1.0
12
12
  dependency-check
@@ -33,7 +33,7 @@ if __name__ == "__main__":
33
33
 
34
34
  setup(
35
35
  name=_PACKAEG_NAME,
36
- version='5.0.0',
36
+ version='5.1.1',
37
37
  package_dir={"": "src"},
38
38
  packages=find_packages(where='src'),
39
39
  description='FOSSLight Binary Scanner',
@@ -24,7 +24,6 @@ class BinaryItem(FileItem):
24
24
  super().__init__("")
25
25
  self.exclude = False
26
26
  self.source_name_or_path = ""
27
- self.checksum = TLSH_CHECKSUM_NULL
28
27
  self.tlsh = TLSH_CHECKSUM_NULL
29
28
  self.vulnerability_items = []
30
29
  self.binary_name_without_path = ""
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # FOSSLight Binary analysis script
4
+ # Copyright (c) 2024 LG Electronics Inc.
5
+ # SPDX-License-Identifier: Apache-2.0
6
+ import os
7
+ import re
8
+ import logging
9
+ import zipfile
10
+ import tarfile
11
+ import fosslight_util.constant as constant
12
+ from fosslight_util.write_txt import write_txt_file
13
+ from fosslight_util.set_log import init_log
14
+
15
+ REMOVE_FILE_EXTENSION_SIMPLE = ['ttf', 'otf', 'png', 'gif', 'jpg', 'bmp', 'jpeg']
16
+ logger = logging.getLogger(constant.LOGGER_NAME)
17
+
18
+
19
+ def is_compressed_file(filename):
20
+ if filename.lower().endswith('.jar'):
21
+ return False
22
+ return zipfile.is_zipfile(filename) or tarfile.is_tarfile(filename)
23
+
24
+
25
+ def exclude_bin_for_simple_mode(binary_list):
26
+ bin_list = []
27
+ compressed_list = []
28
+
29
+ for bin in binary_list:
30
+ file_lower_case = bin.bin_name_with_path.lower()
31
+ extension = os.path.splitext(file_lower_case)[1][1:].strip()
32
+
33
+ if is_compressed_file(bin.bin_name_with_path):
34
+ compressed_list.append(bin.bin_name_with_path)
35
+ continue
36
+
37
+ remove_file_ext_list = REMOVE_FILE_EXTENSION_SIMPLE
38
+ if any(extension == remove_ext for remove_ext in remove_file_ext_list):
39
+ continue
40
+ if re.search(r".*sources\.jar", bin.bin_name_with_path.lower()) or bin.exclude:
41
+ continue
42
+
43
+ bin_list.append(bin.bin_name_with_path)
44
+ return compressed_list, bin_list
45
+
46
+
47
+ def convert_list_to_str(input_list):
48
+ output_text = '\n'.join(map(str, input_list))
49
+ return output_text
50
+
51
+
52
+ def check_output_path(output, start_time):
53
+ compressed_list_txt = ""
54
+ simple_bin_list_txt = ""
55
+ output_path = ""
56
+
57
+ if output != "":
58
+ if not os.path.isdir(output) and output.endswith('.txt'):
59
+ output_path = os.path.dirname(output)
60
+ basename = os.path.basename(output)
61
+ basename_file, _ = os.path.splitext(basename)
62
+ compressed_list_txt = f"{basename_file}_compressed_list.txt"
63
+ simple_bin_list_txt = f"{basename_file}.txt"
64
+ else:
65
+ output_path = output
66
+ compressed_list_txt = f"compressed_list_{start_time}.txt"
67
+ simple_bin_list_txt = f"binary_list_{start_time}.txt"
68
+ else:
69
+ compressed_list_txt = f"compressed_list_{start_time}.txt"
70
+ simple_bin_list_txt = f"binary_list_{start_time}.txt"
71
+
72
+ if output_path == "":
73
+ output_path = os.getcwd()
74
+ else:
75
+ output_path = os.path.abspath(output_path)
76
+
77
+ compressed_list_txt = os.path.join(output_path, compressed_list_txt)
78
+ simple_bin_list_txt = os.path.join(output_path, simple_bin_list_txt)
79
+
80
+ return output_path, compressed_list_txt, simple_bin_list_txt
81
+
82
+
83
+ def init_simple(output_file_name, pkg_name, start_time):
84
+ global logger, _result_log
85
+
86
+ output_path, compressed_list_txt, simple_bin_list_txt = check_output_path(output_file_name, start_time)
87
+
88
+ log_file = os.path.join(output_path, f"fosslight_log_bin_{start_time}.txt")
89
+ logger, _result_log = init_log(log_file, False, logging.INFO, logging.DEBUG, pkg_name)
90
+
91
+ return _result_log, compressed_list_txt, simple_bin_list_txt
92
+
93
+
94
+ def print_simple_mode(compressed_list_txt, simple_bin_list_txt, compressed_list, bin_list):
95
+ results = []
96
+ success = True
97
+ msg = ""
98
+ output_file = ""
99
+ if compressed_list:
100
+ success, error = write_txt_file(compressed_list_txt, convert_list_to_str(compressed_list))
101
+ if success:
102
+ output_file = compressed_list_txt
103
+ else:
104
+ msg = f"Error to write compressed list file for simple mode : {error}"
105
+ results.append(tuple([success, msg, output_file]))
106
+ if bin_list:
107
+ success, error = write_txt_file(simple_bin_list_txt, convert_list_to_str(bin_list))
108
+ if success:
109
+ output_file = simple_bin_list_txt
110
+ else:
111
+ msg = f"Error to write binary list file for simple mode : {error}"
112
+ results.append(tuple([success, msg, output_file]))
113
+ return results
114
+
115
+
116
+ def filter_binary(bin_list):
117
+ compressed_list, bin_list = exclude_bin_for_simple_mode(bin_list)
118
+ return compressed_list, bin_list
@@ -5,6 +5,7 @@
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
  import os
7
7
  import sys
8
+ import platform
8
9
  from datetime import datetime
9
10
  from binaryornot.check import is_binary
10
11
  import magic
@@ -13,10 +14,11 @@ import yaml
13
14
  import stat
14
15
  from fosslight_util.set_log import init_log
15
16
  import fosslight_util.constant as constant
16
- from fosslight_util.output_format import check_output_formats, write_output_file
17
+ from fosslight_util.output_format import check_output_formats_v2, write_output_file
17
18
  from ._binary_dao import get_oss_info_from_db
18
19
  from ._binary import BinaryItem, TLSH_CHECKSUM_NULL
19
20
  from ._jar_analysis import analyze_jar_file, merge_binary_list
21
+ from ._simple_mode import print_simple_mode, filter_binary, init_simple
20
22
  from fosslight_util.correct import correct_with_yaml
21
23
  from fosslight_util.oss_item import ScannerItem
22
24
  import hashlib
@@ -40,7 +42,7 @@ _REMOVE_DIR = ['.git']
40
42
  _REMOVE_DIR = [os.path.sep + dir_name + os.path.sep for dir_name in _REMOVE_DIR]
41
43
  _error_logs = []
42
44
  _root_path = ""
43
- _start_time = ""
45
+ start_time = ""
44
46
  windows = False
45
47
  BYTES = 2048
46
48
  BIN_EXT_HEADER = {'BIN_FL_Binary': ['ID', 'Binary Path', 'OSS Name',
@@ -71,19 +73,10 @@ def get_checksum_and_tlsh(bin_with_path):
71
73
 
72
74
 
73
75
  def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
74
- global _root_path, logger, _start_time
76
+ global logger, _result_log
75
77
 
76
78
  _json_ext = ".json"
77
- _start_time = datetime.now().strftime('%y%m%d_%H%M')
78
- _result_log = {
79
- "Tool Info": PKG_NAME
80
- }
81
-
82
- _root_path = path_to_find_bin
83
- if not path_to_find_bin.endswith(os.path.sep):
84
- _root_path += os.path.sep
85
-
86
- success, msg, output_path, output_files, output_extensions = check_output_formats(output_file_name, formats)
79
+ success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats)
87
80
 
88
81
  if success:
89
82
  if output_path == "":
@@ -93,19 +86,40 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
93
86
 
94
87
  while len(output_files) < len(output_extensions):
95
88
  output_files.append(None)
89
+ to_remove = [] # elements of spdx format on windows that should be removed
96
90
  for i, output_extension in enumerate(output_extensions):
97
91
  if output_files[i] is None or output_files[i] == "":
98
- if output_extension == _json_ext:
99
- output_files[i] = f"fosslight_opossum_bin_{_start_time}"
92
+ if formats:
93
+ if formats[i].startswith('spdx'):
94
+ if platform.system() != 'Windows':
95
+ output_files[i] = f"fosslight_spdx_bin_{start_time}"
96
+ else:
97
+ logger.warning('spdx format is not supported on Windows. Please remove spdx from format.')
98
+ to_remove.append(i)
99
+ else:
100
+ if output_extension == _json_ext:
101
+ output_files[i] = f"fosslight_opossum_bin_{start_time}"
102
+ else:
103
+ output_files[i] = f"fosslight_report_bin_{start_time}"
100
104
  else:
101
- output_files[i] = f"fosslight_report_bin_{_start_time}"
105
+ if output_extension == _json_ext:
106
+ output_files[i] = f"fosslight_opossum_bin_{start_time}"
107
+ else:
108
+ output_files[i] = f"fosslight_report_bin_{start_time}"
109
+ for index in sorted(to_remove, reverse=True):
110
+ # remove elements of spdx format on windows
111
+ del output_files[index]
112
+ del output_extensions[index]
113
+ del formats[index]
114
+ if len(output_extensions) < 1:
115
+ sys.exit(0)
102
116
 
103
117
  combined_paths_and_files = [os.path.join(output_path, file) for file in output_files]
104
118
  else:
105
119
  logger.error(f"Format error - {msg}")
106
120
  sys.exit(1)
107
121
 
108
- log_file = os.path.join(output_path, f"fosslight_log_bin_{_start_time}.txt")
122
+ log_file = os.path.join(output_path, f"fosslight_log_bin_{start_time}.txt")
109
123
  logger, _result_log = init_log(log_file, True, logging.INFO, logging.DEBUG,
110
124
  PKG_NAME, path_to_find_bin, path_to_exclude)
111
125
 
@@ -154,6 +168,8 @@ def get_file_list(path_to_find, abs_path_to_exclude):
154
168
  bin_item.exclude = True
155
169
  elif extension in _EXCLUDE_FILE_EXTENSION:
156
170
  bin_item.exclude = True
171
+ elif file.startswith('.'):
172
+ bin_item.exclude = True
157
173
  bin_list.append(bin_item)
158
174
  file_cnt += 1
159
175
  return file_cnt, bin_list, found_jar
@@ -161,9 +177,21 @@ def get_file_list(path_to_find, abs_path_to_exclude):
161
177
 
162
178
  def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=False,
163
179
  correct_mode=True, correct_filepath="", path_to_exclude=[]):
180
+ global start_time, _root_path, _result_log
164
181
 
165
- _result_log, result_reports, output_extensions = init(
166
- path_to_find_bin, output_dir, formats, path_to_exclude)
182
+ mode = "Normal Mode"
183
+ start_time = datetime.now().strftime('%y%m%d_%H%M')
184
+
185
+ _root_path = path_to_find_bin
186
+ if not path_to_find_bin.endswith(os.path.sep):
187
+ _root_path += os.path.sep
188
+
189
+ if simple_mode:
190
+ mode = "Simple Mode"
191
+ _result_log, compressed_list_txt, simple_bin_list_txt = init_simple(output_dir, PKG_NAME, start_time)
192
+ else:
193
+ _result_log, result_reports, output_extensions = init(
194
+ path_to_find_bin, output_dir, formats, path_to_exclude)
167
195
 
168
196
  total_bin_cnt = 0
169
197
  total_file_cnt = 0
@@ -179,7 +207,8 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
179
207
  if not os.path.isdir(path_to_find_bin):
180
208
  error_occured(error_msg=f"Can't find the directory : {path_to_find_bin}",
181
209
  result_log=_result_log,
182
- exit=True)
210
+ exit=True,
211
+ mode=mode)
183
212
  if not correct_filepath:
184
213
  correct_filepath = path_to_find_bin
185
214
  try:
@@ -188,12 +217,21 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
188
217
  except Exception as ex:
189
218
  error_occured(error_msg=f"Failed to check whether it is binary or not : {ex}",
190
219
  result_log=_result_log,
191
- exit=True)
192
- total_bin_cnt = len(return_list)
220
+ exit=True,
221
+ mode=mode)
193
222
  if simple_mode:
194
- bin_list = [bin.bin_name_with_path for bin in return_list]
223
+ try:
224
+ compressed_list, filtered_bin_list = filter_binary(return_list)
225
+ results = print_simple_mode(compressed_list_txt, simple_bin_list_txt, compressed_list, filtered_bin_list)
226
+ total_bin_cnt = len(filtered_bin_list)
227
+ except Exception as ex:
228
+ error_occured(error_msg=f"Failed to run simple mode: {ex}",
229
+ result_log=_result_log,
230
+ exit=True,
231
+ mode="Simple mode")
195
232
  else:
196
- scan_item = ScannerItem(PKG_NAME, _start_time)
233
+ total_bin_cnt = len(return_list)
234
+ scan_item = ScannerItem(PKG_NAME, start_time)
197
235
  scan_item.set_cover_pathinfo(path_to_find_bin, path_to_exclude)
198
236
  try:
199
237
  # Run OWASP Dependency-check
@@ -221,8 +259,9 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
221
259
  scan_item.set_cover_comment("(No binary detected.) ")
222
260
  scan_item.set_cover_comment(f"Total number of files: {total_file_cnt}")
223
261
 
224
- for combined_path_and_file, output_extension in zip(result_reports, output_extensions):
225
- results.append(write_output_file(combined_path_and_file, output_extension, scan_item, BIN_EXT_HEADER, HIDE_HEADER))
262
+ for combined_path_and_file, output_extension, output_format in zip(result_reports, output_extensions, formats):
263
+ results.append(write_output_file(combined_path_and_file, output_extension, scan_item,
264
+ BIN_EXT_HEADER, HIDE_HEADER, output_format))
226
265
 
227
266
  except Exception as ex:
228
267
  error_occured(error_msg=str(ex), exit=False)
@@ -239,7 +278,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
239
278
  logger.error(f"Fail to generate result file.:{writing_msg}")
240
279
 
241
280
  try:
242
- print_result_log(success=True, result_log=_result_log,
281
+ print_result_log(mode=mode, success=True, result_log=_result_log,
243
282
  file_cnt=str(total_file_cnt),
244
283
  bin_file_cnt=str(total_bin_cnt),
245
284
  auto_bin_cnt=str(db_loaded_cnt), bin_list=bin_list)
@@ -256,7 +295,7 @@ def return_bin_only(file_list, need_checksum_tlsh=True):
256
295
  if need_checksum_tlsh:
257
296
  file_item.checksum, file_item.tlsh, error_msg = get_checksum_and_tlsh(file_item.bin_name_with_path)
258
297
  if error_msg:
259
- error_occured(error_msg=error_msg, exit=False)
298
+ error_occured(modeerror_msg=error_msg, exit=False)
260
299
  yield file_item
261
300
  except Exception as ex:
262
301
  logger.debug(f"Exception in get_file_list: {ex}")
@@ -294,21 +333,22 @@ def check_binary(file_with_path):
294
333
  return is_bin_confirmed
295
334
 
296
335
 
297
- def error_occured(error_msg, exit=False, result_log={}):
336
+ def error_occured(error_msg, exit=False, result_log={}, mode="Normal mode"):
298
337
  global _error_logs
299
338
  _error_logs.append(error_msg)
300
339
  if exit:
301
- print_result_log(success=False, result_log=result_log)
340
+ print_result_log(mode, success=False, result_log=result_log)
302
341
  sys.exit()
303
342
 
304
343
 
305
- def print_result_log(success=True, result_log={}, file_cnt="", bin_file_cnt="", auto_bin_cnt="", bin_list=[]):
344
+ def print_result_log(mode="Normal Mode", success=True, result_log={}, file_cnt="", bin_file_cnt="", auto_bin_cnt="", bin_list=[]):
306
345
 
307
346
  if "Running time" in result_log:
308
- start_time = result_log["Running time"]
347
+ starttime = result_log["Running time"]
309
348
  else:
310
- start_time = _start_time
311
- result_log["Running time"] = start_time + " ~ " + \
349
+ starttime = start_time
350
+ result_log["Mode"] = mode
351
+ result_log["Running time"] = starttime + " ~ " + \
312
352
  datetime.now().strftime('%Y%m%d_%H%M%S')
313
353
  result_log["Execution result"] = 'Success' if success else 'Error occurred'
314
354
  result_log["Binaries / Scanned files"] = f"{bin_file_cnt}/{file_cnt}"
@@ -18,7 +18,7 @@ def main():
18
18
  path_to_find_bin = ""
19
19
  path_to_exclude = []
20
20
  output_dir = ""
21
- format = ""
21
+ format = []
22
22
  db_url = ""
23
23
  simple_mode = False
24
24
  correct_mode = True
@@ -49,7 +49,7 @@ def main():
49
49
  print_package_version(_PKG_NAME, "FOSSLight Binary Scanner Version:")
50
50
  sys.exit(0)
51
51
 
52
- if args.simple:
52
+ if args.simple: # -s option
53
53
  simple_mode = True
54
54
 
55
55
  if args.path: # -p option
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-binary
3
- Version: 5.0.0
3
+ Version: 5.1.1
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_binary_scanner
6
6
  Author: LG Electronics
@@ -11,6 +11,7 @@ src/fosslight_binary/_binary.py
11
11
  src/fosslight_binary/_binary_dao.py
12
12
  src/fosslight_binary/_help.py
13
13
  src/fosslight_binary/_jar_analysis.py
14
+ src/fosslight_binary/_simple_mode.py
14
15
  src/fosslight_binary/binary_analysis.py
15
16
  src/fosslight_binary/cli.py
16
17
  src/fosslight_binary.egg-info/PKG-INFO
@@ -8,7 +8,7 @@ py-tlsh
8
8
  pytz
9
9
  XlsxWriter
10
10
  PyYAML
11
- fosslight_util>=2.0.0
11
+ fosslight_util>=2.1.0
12
12
  dependency-check
13
13
 
14
14
  [:"darwin" in sys_platform]