diff --git a/src/helpers/logger.py b/src/helpers/logger.py index cc8dd4d..d757c58 100644 --- a/src/helpers/logger.py +++ b/src/helpers/logger.py @@ -36,14 +36,14 @@ def dump(self): with open(self.logpath, 'w') as f: print(Logger.log_html_document.gethtml(), file=f) - def __init__(self, message, level): + def __init__(self, message, level, rewriteLine): # First call of the logger, so it builds the title of the log-page Logger.log_html_document.header("log") Logger.log_html_document.navigation() with Logger.log_html_document.tag("h1", klass="center-align"): Logger.log_html_document.text("Log-file") self.logmodule.append(self) - self.log(message, level) + self.log(message, level, rewriteLine) @staticmethod def timeString(): @@ -57,7 +57,7 @@ def __make_log_entry(self, message, color): Logger.log_html_document.text("%s: %s" % (self.timeString, message)) @staticmethod - def cPrint(message, level): + def cPrint(message, level, rewriteLine): if level == 1: msg = "%s[ERROR]" % PrintColors.ERROR elif level == 2: @@ -65,10 +65,13 @@ def cPrint(message, level): else: msg = "%s[INFO]%s" % (PrintColors.INFO, PrintColors.END) msg += " %s%s" % (message, PrintColors.END) - print(msg) + if rewriteLine: + print(msg, end='\r') + else: + print(msg) - def log(self, message, level=3): - self.cPrint(message, level) + def log(self, message, level=3, rewriteLine=False): + self.cPrint(message, level, rewriteLine) if int(level) == 1 and int(self.loglevel) >= 1: self.__make_log_entry(message, "red") sleep(7) @@ -80,13 +83,12 @@ def log(self, message, level=3): instance = None - def __init__(self, message, level=3): + def __init__(self, message, level=3, rewriteLine=False): if not Logger.instance: - Logger.instance = Logger.__Logger(message, level) + Logger.instance = Logger.__Logger(message, level, rewriteLine) else: - Logger.instance.log(message, level) + Logger.instance.log(message, level, rewriteLine) def dump(): # passing the dump command to the singleton Logger.instance.dump() - diff --git a/src/helpers/project.py b/src/helpers/project.py index 6c4dbf4..68d476b 100644 --- a/src/helpers/project.py +++ b/src/helpers/project.py @@ -102,11 +102,13 @@ def app_prepper(self): # For Android: decompile with JADX if self.application_file.lower().endswith("apk"): jadx_folder = os.path.join(new_folder, "jadx_source_code") + jadx_path = os.path.join(os.getcwd(), "jadx", "bin", "jadx") Logger(jadx_folder) if not os.path.exists(jadx_folder): os.makedirs(jadx_folder) - if not os.access(os.path.join(os.getcwd(), "jadx", "bin", "jadx"), os.X_OK) and not os.name == 'nt': - Logger( "jadx is not executable. Run \"chmod +x jadx/bin/jadx\"", 1) + if not os.access(jadx_path, os.X_OK) and not os.name == 'nt': + Logger( "jadx is not executable. Performing automatic fix.", 2) + os.chmod(jadx_path, 0o755) # if i.startswith("'") and i.endswith("'"): if not ((self.application_file.startswith("'") and self.application_file.endswith("'") ) or (self.application_file.startswith("\"") and self.application_file.endswith("\"") )): self.application_file = "\"" + self.application_file + "\"" @@ -123,4 +125,3 @@ def app_prepper(self): elif self.application_file.lower().endswith("ipa"): Logger(".ipa files not implemented yet.", Logger.ERROR) sys.exit() - diff --git a/src/stacoan.py b/src/stacoan.py index d1d875a..84cfc1b 100644 --- a/src/stacoan.py +++ b/src/stacoan.py @@ -4,8 +4,8 @@ import os import sys import webbrowser - import configparser +from time import time from helpers.logger import Logger from helpers.project import Project @@ -18,10 +18,14 @@ def program(): if not os.path.dirname(os.path.abspath(__file__)) == os.getcwd(): Logger("Script cannot be called outside directory", Logger.ERROR) + # Keep track of execution time + start_time = time() + # Read information from config file config = configparser.ConfigParser() config.read("config.ini") report_folder = config.get("ProgramConfig", 'report_folder') + report_folder_start = os.path.join(os.getcwd(), report_folder, "start.html") development = config.getint("Development", 'development') # Import the searchwords lists Searchwords.searchwords_import(Searchwords()) @@ -50,8 +54,7 @@ def program(): amount_files = len(all_files) i = 0 for file in all_files: - #os.system('cls' if os.name == 'nt' else 'clear') # This function is making the program 5000% slower - Logger("progress: "+str(format((i/amount_files)*100, '.2f'))+"%") + Logger("progress: "+str(format((i/amount_files)*100, '.2f'))+"%", rewriteLine=True) i += 1 hash_object = hashlib.md5(file.encode('utf-8')) file_report_file = os.path.join(report_folder, hash_object.hexdigest()+'.html') @@ -64,6 +67,7 @@ def program(): f.write(overview_html.gethtml()) # with open(file_report_file, 'w') as f: # print(overview_html.gethtml(), file=f) + Logger("progress: 100% ") # Generate the startpage file_report_file = os.path.join(report_folder, 'start.html') @@ -106,16 +110,22 @@ def program(): # with open(tree_js_file_path, 'w') as f: # print(Report_html.Tree_builder.tree_js_file(Project.projects[project_path]), file=f) - # Generate looty.js file, for the zip creation process at the lootbox page Report_html().make_loot_report_content() # Write all log-events to logfile Logger.dump() + # Log some end results + print("\n--------------------\n") + Logger("Static code analyzer completed succesfully in %fs." % (time() - start_time)) + Logger("HTML report is available at: %s" % report_folder_start) + Logger("Now automatically opening the HTML report.") + # Open the webbrowser to the generated start page. - url = os.path.join(report_folder, "start.html") - webbrowser.open(url) + if sys.platform == "darwin": # check if on OSX + report_folder_start = "file:///" + report_folder_start + webbrowser.open(report_folder_start) # Exit program sys.exit()