From 9c087ecf833053492b3d462a9b47c8af81a750a4 Mon Sep 17 00:00:00 2001 From: Jonathan Phillips Date: Sat, 13 Apr 2024 23:29:48 -0400 Subject: [PATCH] we can now run ASHE remotely via script files! --- .gitignore | 4 ++- ashe_scripts/run_ashe_for_stats.py | 42 +++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 1817c4b..3f0e130 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ jdk* .vscode/ -.idea \ No newline at end of file +.idea + +*config.properties \ No newline at end of file diff --git a/ashe_scripts/run_ashe_for_stats.py b/ashe_scripts/run_ashe_for_stats.py index 90575a9..228a013 100644 --- a/ashe_scripts/run_ashe_for_stats.py +++ b/ashe_scripts/run_ashe_for_stats.py @@ -6,28 +6,35 @@ Date: April 13, 2024 Usage: -python3 run_ashe_for_stats.py +python3 run_ashe_for_stats.py """ - import subprocess -import os import sys +import threading +import datetime +import time +import os -def run(ashe_path: str, csv_path: str, clone_path: str): +def run(ashe_path: str, csv_path: str, clone_path: str, props_file_path: str): """ Run ASHE and Specimin scripts to analyze the log file. Args: ashe_path: absolute path to clone the ASHE repository csv_path: absolute path to the CSV file containing the repositories ASHE will iterate over clone_path: absolute path to clone the repositories in the CSV file ASHE will iterate over + props_file_path: absolute path to the directory containing the config.properties files for ASHE """ ashe_url: str = "https://github.com/jonathan-m-phillips/ASHE_Automated-Software-Hardening-for-Entrypoints" # clone or update repository __git_clone_or_update(ashe_url, ashe_path) - __build_and_run_ashe(csv_path, clone_path, working_dir=ashe_path) + start_time: datetime = datetime.datetime.now() + status_thread: threading.Thread = threading.Thread(target=__print_ashe_runtime, args=(start_time,)) + status_thread.daemon = True + status_thread.start() + __build_and_run_ashe(csv_path, clone_path, props_file_path, working_dir=ashe_path) current_dir = os.path.dirname(os.path.abspath(__file__)) stats_script = os.path.join(current_dir, 'specimin_statistics.py') @@ -60,19 +67,19 @@ def __git_clone_or_update(repo_url, ashe_path): print("Repository exists. Checking if it's a Git repository...") if not os.path.exists(os.path.join(ashe_path, '.git')): print(f"The directory {ashe_path} is not a Git repository.") - __run_command(f"git clone -b gradle-command {repo_url} {ashe_path}") + __run_command(f"git clone {repo_url} {ashe_path}") else: print("Updating the repository...") os.chdir(ashe_path) __run_command("git pull") -def __build_and_run_ashe(csv_path: str, clone_path: str, working_dir: str): +def __build_and_run_ashe(csv_path: str, clone_path: str, props_file_path: str, working_dir: str): """Build and run the ASHE project using gradle.""" # build ASHE build_command: str = './gradlew build' model_type: str = "dryrun" - run_automation_command: str = f"./gradlew runRepositoryAutomation -PrepositoriesCsvPath=\"{csv_path}\" -PcloneDirectory=\"{clone_path}\" -Pllm=\"{model_type}\"" + run_automation_command: str = f"./gradlew runRepositoryAutomation -PrepositoriesCsvPath=\"{csv_path}\" -PcloneDirectory=\"{clone_path}\" -Pllm=\"{model_type}\" -PpropsFilePath=\"{props_file_path}\"" print("Building ASHE...") __run_command(build_command, working_dir=working_dir) @@ -81,9 +88,20 @@ def __build_and_run_ashe(csv_path: str, clone_path: str, working_dir: str): __run_command(run_automation_command, working_dir=working_dir) +def __print_ashe_runtime(start_time): + """Function to print the elapsed time since ASHE started.""" + print("ASHE started.") + print("ASHE runtime: 00:00:00") + while True: + time.sleep(300) # sleep for 5 minute + elapsed_time = datetime.datetime.now() - start_time + # format elapsed time into H:M:S + formatted_time = str(elapsed_time).split('.')[0] # remove microseconds + print(f"ASHE runtime: {formatted_time}") + + if __name__ == "__main__": - if len(sys.argv) < 3: - print( - "Usage: python3 run_ashe_for_stats.py ") + if len(sys.argv) < 4: + print("Usage: python3 run_ashe_for_stats.py ") sys.exit(1) - run(sys.argv[1], sys.argv[2], sys.argv[3]) + run(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])