refactor: background task support

This commit is contained in:
Dobin
2024-03-08 11:46:55 +00:00
parent 387862866b
commit 03291aed98
5 changed files with 50 additions and 19 deletions
+18
View File
@@ -0,0 +1,18 @@
<html>
<head>
<title>Building</title>
<meta http-equiv="refresh" content="1">
</head>
<body>
<p>
Building {{project_name}}, please wait...
</p>
<p>
This page automatically refreshes every 1 seconds until the building is finished
</p>
Log:
<pre>{{logdata}}</pre>
</body>
</html>
+29 -3
View File
@@ -1,4 +1,5 @@
from flask import Blueprint, current_app, flash, request, redirect, url_for, render_template, send_file, make_response, session, escape
from flask import Flask, Blueprint, current_app, request, redirect, url_for, render_template, send_file, make_response, session, escape
from threading import Thread
from werkzeug.utils import secure_filename
import os
import logging
@@ -20,6 +21,8 @@ views = Blueprint('views', __name__)
conv = Ansi2HTMLConverter()
config.load()
thread_running = False
@views.route("/")
def index():
@@ -129,8 +132,16 @@ def add_project():
)
def supermega_thread(settings: Settings):
global thread_running
start(settings)
thread_running = False
@views.route("/start_project", methods=['POST', 'GET'])
def start_project():
global thread_running
#project_name = request.args.get('project_name')
project_name = request.form.get('project_name')
try_start = request.form.get('try_start')
@@ -140,8 +151,23 @@ def start_project():
try_start = False
project = storage.get_project(project_name)
project.settings.try_start_final_infected_exe = try_start
start(project.settings)
return redirect("/project/{}".format(project_name), code=302)
thread = Thread(target=supermega_thread, args=(project.settings, ))
thread.start()
thread_running = True
return redirect("/status_project/{}".format(project_name), code=302)
@views.route("/status_project/<project_name>")
def status_project(project_name):
global thread_running
if thread_running:
return render_template('status_project.html',
project_name=project_name,
logdata = "asdf")
else:
return redirect("/project/{}".format(project_name), code=302)
def get_logfiles():
-12
View File
@@ -157,18 +157,6 @@ def get_function_stubs(asm_in: FilePath) -> List[str]:
print(" > loader shellcode IAT requirement: {}".format(func_name))
functions.append(func_name)
if False:
if "EXTRN __imp_" in line:
a = line
a = a.split("__imp_")[1]
a = a.split(":PROC")[0]
func_name = a
#func_name = line.strip("\r\n ")
#func_name = line.replace("EXTRN\t__imp_", "")
#func_name = line.replace(":PROC", "")
print("-----> {}".format(func_name))
functions.append(func_name)
return functions
-2
View File
@@ -86,8 +86,6 @@ class ReusedataAsmFileParser():
hex = part.split('H')[0]
if len(hex) == 3:
hex = hex.lstrip('0')
#print("--> {}".format(line))
#print("---> {}".format(hex))
value += bytes.fromhex(hex)
if not name in self.fixups:
+3 -2
View File
@@ -128,7 +128,8 @@ def main():
settings.inject_exe_in = args.inject
settings.inject_exe_out = args.inject.replace(".exe", ".infected.exe")
start(settings)
exit_code = start(settings)
exit(exit_code)
def start(settings: Settings):
@@ -224,7 +225,7 @@ def start(settings: Settings):
clean_files()
writelog()
exit(exit_code)
return exit_code
def obfuscate_shc_loader(file_shc_in, file_shc_out):