diff --git a/Makefile.amiga b/Makefile.amiga new file mode 100644 index 0000000..3795452 --- /dev/null +++ b/Makefile.amiga @@ -0,0 +1,20 @@ +# +# Project: flawfinder +# Created by George "walkero" Sokianos +# 2022-07-25 +# + +release: clean + mkdir -p release/flawfinder + cp -r release_files/* release/flawfinder/ + cp flawfinder.py release/flawfinder/flawfinder + protect release/flawfinder/flawfinder srwed + cp -r simplejson release/flawfinder + cp ChangeLog release/flawfinder/ + cp README.md release/flawfinder/ + cp COPYING release/flawfinder/ + lha -aeqr3 a flawfinder.lha release/ + +clean: + rm -f simplejson/#?.pyc + diff --git a/flawfinder.py b/flawfinder.py old mode 100755 new mode 100644 index 1e7eb04..63de5a5 --- a/flawfinder.py +++ b/flawfinder.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!python """flawfinder: Find potential security flaws ("hits") in source code. Usage: @@ -40,7 +40,7 @@ # That *finally* makes it possible to semi-gracefully transition. from __future__ import division -from __future__ import print_function +# from __future__ import print_function import functools import sys import re @@ -53,7 +53,7 @@ import operator # To support filename expansion on Windows import time import csv # To support generating CSV format import hashlib -import json +import simplejson as json version = "2.0.19" @@ -488,16 +488,16 @@ def print_multi_line(text): prefix = " " starting_position = len(prefix) + 1 # - print(prefix, end='') + print(prefix), position = starting_position # for w in text.split(): if len(w) + position >= width: - print() - print(prefix, end='') + print '\n', + print(prefix), position = starting_position - print(' ', end='') - print(w, end='') + # print(' '), + print(w), position += len(w) + 1 @@ -608,44 +608,44 @@ class Hit(object): if sarif_output: return if output_format: - print("
  • ", end='') + print("
  • "), sys.stdout.write(h(self.filename)) if show_columns: - print(":%(line)s:%(column)s:" % self, end='') + print(":%(line)s:%(column)s:" % self), else: - print(":%(line)s:" % self, end='') + print(":%(line)s:" % self), if output_format: - print(" ", end='') + print(" "), # Extra space before risk level in text, makes it easier to find: - print(" [%(level)s]" % self, end=' ') + print(" [%(level)s] " % self), if output_format: - print(" ", end='') - print("(%(category)s)" % self, end=' ') + print(" "), + print("(%(category)s) " % self), if output_format: - print(" ", end='') - print(h("%(name)s:" % self), end='') + print(" "), + print(h("%(name)s:" % self)), main_text = h("%(warning)s. " % self) if output_format: # Create HTML link to CWE definitions main_text = link_cwe_pattern.sub( r'\1\3', main_text) if single_line: - print(main_text, end='') + print(main_text), if self.suggestion: - print(" " + h(self.suggestion) + ".", end='') - print(' ' + h(self.note), end='') + print(" " + h(self.suggestion) + "."), + print(' ' + h(self.note)), else: if self.suggestion: main_text += h(self.suggestion) + ". " main_text += h(self.note) - print() + print '\n', print_multi_line(main_text) if output_format: - print(" ", end='') - print("
  • ", end='') - print() + print(" "), + print(""), + print '\n', if show_context: if output_format: print("
    ")
    @@ -676,7 +676,8 @@ def add_warning(hit):
     
     
     def internal_warn(message):
    -    print(h(message), file=sys.stderr)
    +    # print(h(message), file=sys.stderr)
    +    print h(message)
     
     
     # C Language Specific
    @@ -1756,9 +1757,9 @@ def process_c_file(f, patch_infos):
     
         if not quiet:
             if output_format:
    -            print("Examining", h(f), "
    ") + print 'Examining %s
    ' % (h(f)) else: - print("Examining", f) + print 'Examining %s' % (h(f)) sys.stdout.flush() # Python3 is often configured to use only UTF-8, and presumes @@ -1767,10 +1768,10 @@ def process_c_file(f, patch_infos): # in such cases - with some hints on how to solve it. try: text = "".join(my_input.readlines()) - except UnicodeDecodeError as err: + except UnicodeDecodeError, err: print('Error: encoding error in', h(f)) print(err) - print() + print '\n', print('Python3 requires input character data to be perfectly encoded;') print('it also requires perfectly correct system encoding settings.') print('Unfortunately, your data and/or system settings are not.') @@ -1948,8 +1949,7 @@ def display_ruleset(ruleset): def initialize_ruleset(): expand_ruleset(c_ruleset) if showheading: - print("Number of rules (primarily dangerous function names) in C/C++ ruleset:", len( - c_ruleset)) + print 'Number of rules (primarily dangerous function names) in C/C++ ruleset: %d' % len(c_ruleset) if output_format: print("

    ") if list_rules: @@ -2313,7 +2313,7 @@ def process_options(): diffhitlist_filename = value display_header() if showheading: - print("Showing hits not in", value) + print("Showing hits not in %s" % value) elif opt == "--version": print(version) sys.exit(0) @@ -2338,7 +2338,7 @@ def process_options(): # In Python 2 the convention is "getopt.GetoptError", but we # use "getopt.error" here so it's compatible with both # Python 1.5 and Python 2. - except getopt.error as text: + except getopt.error, text: print("*** getopt error:", text) usage() sys.exit(16) @@ -2384,13 +2384,13 @@ def show_final_results(): for i in possible_levels: # Initialize count_per_level_and_up count_per_level_and_up[i] = 0 if show_immediately or not quiet: # Separate the final results. - print() + print '\n', if showheading: if output_format: print("

    Final Results

    ") else: print("FINAL RESULTS:") - print() + print '\n', hitlist.sort(key=hitlist_sort_key) # Display results. The HTML format now uses #