Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -41,6 +41,9 @@ def generate_random_string(length=8):
|
|
41 |
def obfuscate_powershell_script(ps1_path):
|
42 |
try:
|
43 |
cmd = f'pwsh -f "{OBFUSCATOR_SCRIPT}"'
|
|
|
|
|
|
|
44 |
process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, text=True)
|
45 |
process.stdin.write(f"{ps1_path}\n")
|
46 |
process.stdin.flush()
|
@@ -54,7 +57,7 @@ def obfuscate_powershell_script(ps1_path):
|
|
54 |
raise Exception(f"Error obfuscating PowerShell script: {stderr}")
|
55 |
|
56 |
# Check if the obfuscated file was created
|
57 |
-
obfuscated_file = ps1_path.replace(".ps1", "
|
58 |
if not os.path.exists(obfuscated_file):
|
59 |
raise FileNotFoundError(f"Obfuscated file not found: {obfuscated_file}")
|
60 |
|
@@ -62,6 +65,10 @@ def obfuscate_powershell_script(ps1_path):
|
|
62 |
except Exception as e:
|
63 |
raise Exception(f"Obfuscation failed: {str(e)}")
|
64 |
|
|
|
|
|
|
|
|
|
65 |
def generate_nsi_script(folder_path, bin_file, ps1_file):
|
66 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
67 |
installer_output = os.path.join(folder_path, f"setup_{timestamp}.exe")
|
@@ -211,7 +218,7 @@ def process_request(request):
|
|
211 |
|
212 |
# Create the PowerShell script with the provided content
|
213 |
ps1_content = f'''
|
214 |
-
|
215 |
'''
|
216 |
ps1_path = os.path.join(temp_dir, generate_random_string() + ".ps1")
|
217 |
with open(ps1_path, 'w') as ps1_file:
|
|
|
41 |
def obfuscate_powershell_script(ps1_path):
|
42 |
try:
|
43 |
cmd = f'pwsh -f "{OBFUSCATOR_SCRIPT}"'
|
44 |
+
current_app.logger.info(f"Running obfuscation command: {cmd}")
|
45 |
+
current_app.logger.info(f"Input PowerShell script path: {ps1_path}")
|
46 |
+
|
47 |
process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, text=True)
|
48 |
process.stdin.write(f"{ps1_path}\n")
|
49 |
process.stdin.flush()
|
|
|
57 |
raise Exception(f"Error obfuscating PowerShell script: {stderr}")
|
58 |
|
59 |
# Check if the obfuscated file was created
|
60 |
+
obfuscated_file = ps1_path.replace(".ps1", "_obf.ps1")
|
61 |
if not os.path.exists(obfuscated_file):
|
62 |
raise FileNotFoundError(f"Obfuscated file not found: {obfuscated_file}")
|
63 |
|
|
|
65 |
except Exception as e:
|
66 |
raise Exception(f"Obfuscation failed: {str(e)}")
|
67 |
|
68 |
+
return obfuscated_file
|
69 |
+
except Exception as e:
|
70 |
+
raise Exception(f"Obfuscation failed: {str(e)}")
|
71 |
+
|
72 |
def generate_nsi_script(folder_path, bin_file, ps1_file):
|
73 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
74 |
installer_output = os.path.join(folder_path, f"setup_{timestamp}.exe")
|
|
|
218 |
|
219 |
# Create the PowerShell script with the provided content
|
220 |
ps1_content = f'''
|
221 |
+
Your PowerShell script content here
|
222 |
'''
|
223 |
ps1_path = os.path.join(temp_dir, generate_random_string() + ".ps1")
|
224 |
with open(ps1_path, 'w') as ps1_file:
|