From 897d19d7f4ef3b9e11834c27d53ad9c729c22d65 Mon Sep 17 00:00:00 2001 From: Kevin De Koninck Date: Sun, 18 Feb 2018 01:29:23 +0100 Subject: [PATCH 1/4] Automaticly fix jadx file permissions --- src/helpers/project.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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() - From bbb922e6ff1824442cd6431b7c23829ef9f3698f Mon Sep 17 00:00:00 2001 From: Kevin De Koninck Date: Sun, 18 Feb 2018 01:44:35 +0100 Subject: [PATCH 2/4] Bugfix: Open browser on macOS Browser did not open automatically on macOS. --- src/stacoan.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/stacoan.py b/src/stacoan.py index d1d875a..871867d 100644 --- a/src/stacoan.py +++ b/src/stacoan.py @@ -114,8 +114,10 @@ def program(): Logger.dump() # Open the webbrowser to the generated start page. - url = os.path.join(report_folder, "start.html") - webbrowser.open(url) + report_folder_start = os.path.join(os.getcwd(), report_folder, "start.html") + if sys.platform == "darwin": # check if on OSX + report_folder_start = "file:///" + report_folder_start + webbrowser.open(report_folder_start) # Exit program sys.exit() From f4ae48477f712f0f8fb74b831a1746f1e49b18fa Mon Sep 17 00:00:00 2001 From: Kevin De Koninck Date: Sun, 18 Feb 2018 01:56:08 +0100 Subject: [PATCH 3/4] Show a summary at the end You can add more statistics here, so that the user has a nice summary. --- src/stacoan.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/stacoan.py b/src/stacoan.py index 871867d..56ae0a8 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()) @@ -106,15 +110,19 @@ 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. - report_folder_start = os.path.join(os.getcwd(), report_folder, "start.html") if sys.platform == "darwin": # check if on OSX report_folder_start = "file:///" + report_folder_start webbrowser.open(report_folder_start) From 0fd4e858ecfa33af8ffb8dd2aad1af7b65eff346 Mon Sep 17 00:00:00 2001 From: Kevin De Koninck Date: Sun, 18 Feb 2018 02:07:13 +0100 Subject: [PATCH 4/4] Reduce cmdline output by overwriting progress line --- src/helpers/logger.py | 22 ++++++++++++---------- src/stacoan.py | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) 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/stacoan.py b/src/stacoan.py index 56ae0a8..84cfc1b 100644 --- a/src/stacoan.py +++ b/src/stacoan.py @@ -54,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') @@ -68,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')