From 2658ac93a82ea6069616aeb5cce2bdb4e9552b0e Mon Sep 17 00:00:00 2001 From: Scott Cutler Date: Mon, 12 Feb 2018 16:43:57 -0800 Subject: [PATCH] adding windows compatibility --- appmon.py | 19 +++++++++++++------ database/__init__.py | 8 +++++++- viewreport.py | 6 ++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/appmon.py b/appmon.py index 6b4da62..84aa579 100644 --- a/appmon.py +++ b/appmon.py @@ -16,10 +16,11 @@ # limitations under the License. ### -import os, sys, argparse, time, codecs, binascii, frida, json, traceback, subprocess +import os, sys, argparse, time, codecs, binascii, frida, json, traceback, subprocess, tempfile from flask import Flask, request, render_template from termcolor import colored import database as db +import platform as platform_module print """ ___ .______ .______ .___ ___. ______ .__ __. @@ -37,7 +38,8 @@ device = '' session = '' -merged_script_path = '/tmp/merged.js' +temp_dir = tempfile.mkdtemp() +merged_script_path = os.path.join(temp_dir,'merged.js') APP_LIST = [] @@ -76,8 +78,9 @@ def monitor_page(): def landing_page(): global APP_LIST, DB_MAP - for root, dirs, files in os.walk('./app_dumps'): - path = root.split('/') + app_dumps_dir = os.path.join('.','app_dumps') + for root, dirs, files in os.walk(app_dumps_dir): + path = root.split(os.sep) for file in files: file_path = os.path.join(root, file) if file_path.endswith('.db'): @@ -124,7 +127,7 @@ def init_opts(): list_apps = int(results.list_apps) spawn = int(results.spawn) - output_dir = results.output_dir if results.output_dir else './app_dumps' + output_dir = results.output_dir if results.output_dir else os.path.join('.','app_dumps') report_name = results.report if results.report else app_name @@ -179,7 +182,11 @@ def on_detached(): def on_message(message, data): - current_time = time.strftime('%b %d %Y %l:%M %p', time.localtime()) + os_string = platform_module.system() + if os_string == "Windows": + current_time = time.strftime('%b %d %Y %I:%M %p', time.localtime()) + else: + current_time = time.strftime('%b %d %Y %l:%M %p', time.localtime()) if not os.path.exists(output_dir): os.makedirs(output_dir) diff --git a/database/__init__.py b/database/__init__.py index fd2be55..068c7db 100644 --- a/database/__init__.py +++ b/database/__init__.py @@ -16,6 +16,7 @@ ### import dataset, json, time, htmlentities +import platform as platform_module from xml.sax.saxutils import escape def save_to_database(db_path, str_json): @@ -23,7 +24,12 @@ def save_to_database(db_path, str_json): str_json = json.loads(str_json.replace("\n", "
").replace("\r", "
"), strict=False) db = dataset.connect('sqlite:///%s' % (db_path.replace("'", "_"))) table = db['api_captures'] - table.insert(dict(time=time.strftime('%b %d %Y %l:%M %p', time.localtime()), + os_string = platform_module.system() + if os_string == "Windows": + formatted_time = time.strftime('%b %d %Y %I:%M %p', time.localtime()) + else: + formatted_time = time.strftime('%b %d %Y %l:%M %p', time.localtime()) + table.insert(dict(time=formatted_time, operation=str_json['txnType'], artifact=json.dumps(str_json['artifact']), method=str_json['method'], diff --git a/viewreport.py b/viewreport.py index 6c9242a..e565b2d 100644 --- a/viewreport.py +++ b/viewreport.py @@ -65,8 +65,10 @@ def landing_page(): global APP_LIST global DB_MAP APP_LIST = [] - for root, dirs, files in os.walk('./app_dumps'): - path = root.split('/') + + app_dumps_dir = os.path.join('.','app_dumps') + for root, dirs, files in os.walk(app_dumps_dir): + path = root.split(os.sep) for file in files: file_path = os.path.join(root, file) if file_path.endswith('.db'):