Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor improvements #31

Merged
merged 4 commits into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/helpers/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -57,18 +57,21 @@ 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:
msg = "%s[WARNING]" % PrintColors.WARNING
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)
Expand All @@ -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()

7 changes: 4 additions & 3 deletions src/helpers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\""
Expand All @@ -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()

22 changes: 16 additions & 6 deletions src/stacoan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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()
Expand Down