|
29 | 29 | from .extractor import Extractor
|
30 | 30 | from .strings import Strings
|
31 | 31 | from .file import is_binary
|
| 32 | +from .OutputEngine import OutputEngine |
32 | 33 |
|
33 | 34 | from .cvedb import CVEDB
|
34 | 35 | from .log import LOGGER
|
@@ -291,18 +292,6 @@ def scan_files_unpack(unpacked):
|
291 | 292 | return scan_files(*unpacked)
|
292 | 293 |
|
293 | 294 |
|
294 |
| -def output_cves(outfile, modules): |
295 |
| - """ Output a list of CVEs |
296 |
| - format is modules[checker_name][version] = dict{id: severity} |
297 |
| - """ |
298 |
| - writer = csv.writer(outfile) |
299 |
| - for modulename, versions in modules.items(): |
300 |
| - for version, cve_list in versions.items(): |
301 |
| - for cve_number, cve_severity in cve_list.items(): |
302 |
| - row = [modulename, version, cve_number, cve_severity] |
303 |
| - writer.writerow(row) |
304 |
| - |
305 |
| - |
306 | 295 | def main(argv=None, outfile=sys.stdout):
|
307 | 296 | """ Scan a binary file for certain open source libraries that may have CVEs """
|
308 | 297 | if argv is None:
|
@@ -338,6 +327,21 @@ def main(argv=None, outfile=sys.stdout):
|
338 | 327 | action=LogAction,
|
339 | 328 | choices=["debug", "info", "warning", "error", "critical"],
|
340 | 329 | )
|
| 330 | + output_group.add_argument( |
| 331 | + "-o", |
| 332 | + "--output", |
| 333 | + action="store", |
| 334 | + choices=["csv", "json", "console"], |
| 335 | + default="console", |
| 336 | + help="update output format (default: console)", |
| 337 | + ) |
| 338 | + output_group.add_argument( |
| 339 | + "-f", |
| 340 | + "--filename", |
| 341 | + action="store", |
| 342 | + default=None, |
| 343 | + help="provide output file name", |
| 344 | + ) |
341 | 345 | parser.add_argument(
|
342 | 346 | "-v", "--version", action="version", version=f"{get_version_string()}",
|
343 | 347 | )
|
@@ -478,8 +482,19 @@ def main(argv=None, outfile=sys.stdout):
|
478 | 482 | )
|
479 | 483 | )
|
480 | 484 | LOGGER.info(f"Known CVEs in {affected_string}:")
|
481 |
| - if LOGGER.getEffectiveLevel() != logging.CRITICAL: |
482 |
| - output_cves(outfile, scanner.all_cves) |
| 485 | + |
| 486 | + # Creates a Object for OutputEngine |
| 487 | + output = OutputEngine(modules=scanner.all_cves, filename=args.filename) |
| 488 | + |
| 489 | + if ( |
| 490 | + LOGGER.getEffectiveLevel() != logging.CRITICAL |
| 491 | + and args.output == "console" |
| 492 | + ): |
| 493 | + output.output_cves(outfile) |
| 494 | + |
| 495 | + # If the args are passed for csv we will generate a CSV output |
| 496 | + if args.output == "csv": |
| 497 | + output.output_csv() |
483 | 498 |
|
484 | 499 | # Use the number of files with known cves as error code
|
485 | 500 | # as requested by folk planning to automate use of this script.
|
|
0 commit comments