fosslight-binary 5.1.0__tar.gz → 5.1.2__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.1.0 → fosslight_binary-5.1.2}/PKG-INFO +1 -1
  2. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/requirements.txt +2 -2
  3. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/setup.py +1 -1
  4. fosslight_binary-5.1.2/src/fosslight_binary/_simple_mode.py +118 -0
  5. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/binary_analysis.py +58 -39
  6. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/cli.py +23 -3
  7. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary.egg-info/PKG-INFO +1 -1
  8. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary.egg-info/SOURCES.txt +1 -0
  9. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary.egg-info/requires.txt +2 -2
  10. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/LICENSE +0 -0
  11. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/LICENSES/Apache-2.0.txt +0 -0
  12. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/LICENSES/LicenseRef-3rd_party_licenses.txt +0 -0
  13. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/MANIFEST.in +0 -0
  14. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/README.md +0 -0
  15. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/setup.cfg +0 -0
  16. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/__init__.py +0 -0
  17. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/_binary.py +0 -0
  18. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/_binary_dao.py +0 -0
  19. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/_help.py +0 -0
  20. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary/_jar_analysis.py +0 -0
  21. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary.egg-info/dependency_links.txt +0 -0
  22. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/src/fosslight_binary.egg-info/entry_points.txt +0 -0
  23. {fosslight_binary-5.1.0 → fosslight_binary-5.1.2}/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.1.0
3
+ Version: 5.1.2
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_binary_scanner
6
6
  Author: LG Electronics
@@ -2,11 +2,11 @@ binaryornot
2
2
  numpy
3
3
  pandas
4
4
  parmap
5
- psycopg2-binary
5
+ psycopg2-binary==2.9.9
6
6
  python-dateutil
7
7
  py-tlsh
8
8
  pytz
9
9
  XlsxWriter
10
10
  PyYAML
11
- fosslight_util>=2.1.0
11
+ fosslight_util>=2.1.6
12
12
  dependency-check
@@ -33,7 +33,7 @@ if __name__ == "__main__":
33
33
 
34
34
  setup(
35
35
  name=_PACKAEG_NAME,
36
- version='5.1.0',
36
+ version='5.1.2',
37
37
  package_dir={"": "src"},
38
38
  packages=find_packages(where='src'),
39
39
  description='FOSSLight Binary Scanner',
@@ -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
@@ -18,6 +18,7 @@ from fosslight_util.output_format import check_output_formats_v2, write_output_f
18
18
  from ._binary_dao import get_oss_info_from_db
19
19
  from ._binary import BinaryItem, TLSH_CHECKSUM_NULL
20
20
  from ._jar_analysis import analyze_jar_file, merge_binary_list
21
+ from ._simple_mode import print_simple_mode, filter_binary, init_simple
21
22
  from fosslight_util.correct import correct_with_yaml
22
23
  from fosslight_util.oss_item import ScannerItem
23
24
  import hashlib
@@ -41,7 +42,7 @@ _REMOVE_DIR = ['.git']
41
42
  _REMOVE_DIR = [os.path.sep + dir_name + os.path.sep for dir_name in _REMOVE_DIR]
42
43
  _error_logs = []
43
44
  _root_path = ""
44
- _start_time = ""
45
+ start_time = ""
45
46
  windows = False
46
47
  BYTES = 2048
47
48
  BIN_EXT_HEADER = {'BIN_FL_Binary': ['ID', 'Binary Path', 'OSS Name',
@@ -72,18 +73,9 @@ def get_checksum_and_tlsh(bin_with_path):
72
73
 
73
74
 
74
75
  def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
75
- global _root_path, logger, _start_time
76
+ global logger, _result_log
76
77
 
77
78
  _json_ext = ".json"
78
- _start_time = datetime.now().strftime('%y%m%d_%H%M')
79
- _result_log = {
80
- "Tool Info": PKG_NAME
81
- }
82
-
83
- _root_path = path_to_find_bin
84
- if not path_to_find_bin.endswith(os.path.sep):
85
- _root_path += os.path.sep
86
-
87
79
  success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats)
88
80
 
89
81
  if success:
@@ -98,22 +90,25 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
98
90
  for i, output_extension in enumerate(output_extensions):
99
91
  if output_files[i] is None or output_files[i] == "":
100
92
  if formats:
101
- if formats[i].startswith('spdx'):
102
- if platform.system() != 'Windows':
103
- output_files[i] = f"fosslight_spdx_bin_{_start_time}"
104
- else:
105
- logger.warning('spdx format is not supported on Windows. Please remove spdx from format.')
93
+ if formats[i].startswith('spdx') or formats[i].startswith('cyclonedx'):
94
+ if platform.system() == 'Windows':
95
+ logger.warning(f'{formats[i]} is not supported on Windows. Please remove {formats[i]} from format.')
106
96
  to_remove.append(i)
97
+ else:
98
+ if formats[i].startswith('spdx'):
99
+ output_files[i] = f"fosslight_spdx_bin_{start_time}"
100
+ elif formats[i].startswith('cyclonedx'):
101
+ output_files[i] = f'fosslight_cyclonedx_bin_{start_time}'
107
102
  else:
108
103
  if output_extension == _json_ext:
109
- output_files[i] = f"fosslight_opossum_bin_{_start_time}"
104
+ output_files[i] = f"fosslight_opossum_bin_{start_time}"
110
105
  else:
111
- output_files[i] = f"fosslight_report_bin_{_start_time}"
106
+ output_files[i] = f"fosslight_report_bin_{start_time}"
112
107
  else:
113
108
  if output_extension == _json_ext:
114
- output_files[i] = f"fosslight_opossum_bin_{_start_time}"
109
+ output_files[i] = f"fosslight_opossum_bin_{start_time}"
115
110
  else:
116
- output_files[i] = f"fosslight_report_bin_{_start_time}"
111
+ output_files[i] = f"fosslight_report_bin_{start_time}"
117
112
  for index in sorted(to_remove, reverse=True):
118
113
  # remove elements of spdx format on windows
119
114
  del output_files[index]
@@ -127,7 +122,7 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
127
122
  logger.error(f"Format error - {msg}")
128
123
  sys.exit(1)
129
124
 
130
- log_file = os.path.join(output_path, f"fosslight_log_bin_{_start_time}.txt")
125
+ log_file = os.path.join(output_path, f"fosslight_log_bin_{start_time}.txt")
131
126
  logger, _result_log = init_log(log_file, True, logging.INFO, logging.DEBUG,
132
127
  PKG_NAME, path_to_find_bin, path_to_exclude)
133
128
 
@@ -176,6 +171,8 @@ def get_file_list(path_to_find, abs_path_to_exclude):
176
171
  bin_item.exclude = True
177
172
  elif extension in _EXCLUDE_FILE_EXTENSION:
178
173
  bin_item.exclude = True
174
+ elif file.startswith('.'):
175
+ bin_item.exclude = True
179
176
  bin_list.append(bin_item)
180
177
  file_cnt += 1
181
178
  return file_cnt, bin_list, found_jar
@@ -183,9 +180,21 @@ def get_file_list(path_to_find, abs_path_to_exclude):
183
180
 
184
181
  def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=False,
185
182
  correct_mode=True, correct_filepath="", path_to_exclude=[]):
183
+ global start_time, _root_path, _result_log
186
184
 
187
- _result_log, result_reports, output_extensions = init(
188
- path_to_find_bin, output_dir, formats, path_to_exclude)
185
+ mode = "Normal Mode"
186
+ start_time = datetime.now().strftime('%y%m%d_%H%M')
187
+
188
+ _root_path = path_to_find_bin
189
+ if not path_to_find_bin.endswith(os.path.sep):
190
+ _root_path += os.path.sep
191
+
192
+ if simple_mode:
193
+ mode = "Simple Mode"
194
+ _result_log, compressed_list_txt, simple_bin_list_txt = init_simple(output_dir, PKG_NAME, start_time)
195
+ else:
196
+ _result_log, result_reports, output_extensions = init(
197
+ path_to_find_bin, output_dir, formats, path_to_exclude)
189
198
 
190
199
  total_bin_cnt = 0
191
200
  total_file_cnt = 0
@@ -194,14 +203,14 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
194
203
  writing_msg = ""
195
204
  results = []
196
205
  bin_list = []
197
- base_dir_name = os.path.basename(path_to_find_bin)
198
206
  scan_item = ScannerItem(PKG_NAME, "")
199
- abs_path_to_exclude = [os.path.abspath(os.path.join(base_dir_name, path)) for path in path_to_exclude if path.strip() != ""]
207
+ abs_path_to_exclude = [os.path.abspath(path) for path in path_to_exclude if path.strip() != ""]
200
208
 
201
209
  if not os.path.isdir(path_to_find_bin):
202
- error_occured(error_msg=f"Can't find the directory : {path_to_find_bin}",
210
+ error_occured(error_msg=f"(-p option) Can't find the directory: {path_to_find_bin}",
203
211
  result_log=_result_log,
204
- exit=True)
212
+ exit=True,
213
+ mode=mode)
205
214
  if not correct_filepath:
206
215
  correct_filepath = path_to_find_bin
207
216
  try:
@@ -210,12 +219,21 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
210
219
  except Exception as ex:
211
220
  error_occured(error_msg=f"Failed to check whether it is binary or not : {ex}",
212
221
  result_log=_result_log,
213
- exit=True)
214
- total_bin_cnt = len(return_list)
222
+ exit=True,
223
+ mode=mode)
215
224
  if simple_mode:
216
- bin_list = [bin.bin_name_with_path for bin in return_list]
225
+ try:
226
+ compressed_list, filtered_bin_list = filter_binary(return_list)
227
+ results = print_simple_mode(compressed_list_txt, simple_bin_list_txt, compressed_list, filtered_bin_list)
228
+ total_bin_cnt = len(filtered_bin_list)
229
+ except Exception as ex:
230
+ error_occured(error_msg=f"Failed to run simple mode: {ex}",
231
+ result_log=_result_log,
232
+ exit=True,
233
+ mode="Simple mode")
217
234
  else:
218
- scan_item = ScannerItem(PKG_NAME, _start_time)
235
+ total_bin_cnt = len(return_list)
236
+ scan_item = ScannerItem(PKG_NAME, start_time)
219
237
  scan_item.set_cover_pathinfo(path_to_find_bin, path_to_exclude)
220
238
  try:
221
239
  # Run OWASP Dependency-check
@@ -262,7 +280,7 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
262
280
  logger.error(f"Fail to generate result file.:{writing_msg}")
263
281
 
264
282
  try:
265
- print_result_log(success=True, result_log=_result_log,
283
+ print_result_log(mode=mode, success=True, result_log=_result_log,
266
284
  file_cnt=str(total_file_cnt),
267
285
  bin_file_cnt=str(total_bin_cnt),
268
286
  auto_bin_cnt=str(db_loaded_cnt), bin_list=bin_list)
@@ -279,7 +297,7 @@ def return_bin_only(file_list, need_checksum_tlsh=True):
279
297
  if need_checksum_tlsh:
280
298
  file_item.checksum, file_item.tlsh, error_msg = get_checksum_and_tlsh(file_item.bin_name_with_path)
281
299
  if error_msg:
282
- error_occured(error_msg=error_msg, exit=False)
300
+ error_occured(modeerror_msg=error_msg, exit=False)
283
301
  yield file_item
284
302
  except Exception as ex:
285
303
  logger.debug(f"Exception in get_file_list: {ex}")
@@ -317,21 +335,22 @@ def check_binary(file_with_path):
317
335
  return is_bin_confirmed
318
336
 
319
337
 
320
- def error_occured(error_msg, exit=False, result_log={}):
338
+ def error_occured(error_msg, exit=False, result_log={}, mode="Normal mode"):
321
339
  global _error_logs
322
340
  _error_logs.append(error_msg)
323
341
  if exit:
324
- print_result_log(success=False, result_log=result_log)
342
+ print_result_log(mode, success=False, result_log=result_log)
325
343
  sys.exit()
326
344
 
327
345
 
328
- def print_result_log(success=True, result_log={}, file_cnt="", bin_file_cnt="", auto_bin_cnt="", bin_list=[]):
346
+ def print_result_log(mode="Normal Mode", success=True, result_log={}, file_cnt="", bin_file_cnt="", auto_bin_cnt="", bin_list=[]):
329
347
 
330
348
  if "Running time" in result_log:
331
- start_time = result_log["Running time"]
349
+ starttime = result_log["Running time"]
332
350
  else:
333
- start_time = _start_time
334
- result_log["Running time"] = start_time + " ~ " + \
351
+ starttime = start_time
352
+ result_log["Mode"] = mode
353
+ result_log["Running time"] = starttime + " ~ " + \
335
354
  datetime.now().strftime('%Y%m%d_%H%M%S')
336
355
  result_log["Execution result"] = 'Success' if success else 'Error occurred'
337
356
  result_log["Binaries / Scanned files"] = f"{bin_file_cnt}/{file_cnt}"
@@ -5,6 +5,7 @@
5
5
  import argparse
6
6
  import sys
7
7
  import os
8
+ import shutil
8
9
  from fosslight_util.help import print_package_version
9
10
  from fosslight_binary._help import print_help_msg
10
11
  from fosslight_binary.binary_analysis import find_binaries
@@ -13,6 +14,23 @@ from fosslight_util.timer_thread import TimerThread
13
14
  _PKG_NAME = "fosslight_binary"
14
15
 
15
16
 
17
+ def get_terminal_size():
18
+ size = shutil.get_terminal_size()
19
+ return size.lines
20
+
21
+
22
+ def paginate_file(file_path):
23
+ lines_per_page = get_terminal_size() - 1
24
+ with open(file_path, 'r', encoding='utf8') as file:
25
+ lines = file.readlines()
26
+
27
+ for i in range(0, len(lines), lines_per_page):
28
+ os.system('clear' if os.name == 'posix' else 'cls')
29
+ print(''.join(lines[i: i + lines_per_page]))
30
+ if i + lines_per_page < len(lines):
31
+ input("Press Enter to see the next page...")
32
+
33
+
16
34
  def main():
17
35
  global windows
18
36
  path_to_find_bin = ""
@@ -49,7 +67,7 @@ def main():
49
67
  print_package_version(_PKG_NAME, "FOSSLight Binary Scanner Version:")
50
68
  sys.exit(0)
51
69
 
52
- if args.simple:
70
+ if args.simple: # -s option
53
71
  simple_mode = True
54
72
 
55
73
  if args.path: # -p option
@@ -85,8 +103,10 @@ def main():
85
103
  data_path = os.path.join(base_path, 'LICENSES')
86
104
  print(f"*** {_PKG_NAME} open source license notice ***")
87
105
  for ff in os.listdir(data_path):
88
- f = open(os.path.join(data_path, ff), 'r', encoding='utf8')
89
- print(f.read())
106
+ source_file = os.path.join(data_path, ff)
107
+ destination_file = os.path.join(base_path, ff)
108
+ paginate_file(source_file)
109
+ shutil.copyfile(source_file, destination_file)
90
110
  sys.exit(0)
91
111
 
92
112
  timer = TimerThread()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-binary
3
- Version: 5.1.0
3
+ Version: 5.1.2
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
@@ -2,13 +2,13 @@ binaryornot
2
2
  numpy
3
3
  pandas
4
4
  parmap
5
- psycopg2-binary
5
+ psycopg2-binary==2.9.9
6
6
  python-dateutil
7
7
  py-tlsh
8
8
  pytz
9
9
  XlsxWriter
10
10
  PyYAML
11
- fosslight_util>=2.1.0
11
+ fosslight_util>=2.1.6
12
12
  dependency-check
13
13
 
14
14
  [:"darwin" in sys_platform]