Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,70 +1,70 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import subprocess
|
4 |
-
import
|
5 |
-
import zipfile
|
6 |
|
7 |
# Function to process APK file
|
8 |
-
def process_apk(
|
9 |
# Run apk-mitm command
|
10 |
-
command = f"apk-mitm {
|
11 |
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
12 |
return result
|
13 |
|
14 |
-
# Function to zip the processed APK file
|
15 |
-
def zip_file(file_path, zip_path):
|
16 |
-
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
17 |
-
zipf.write(file_path, os.path.basename(file_path))
|
18 |
-
|
19 |
# Streamlit app interface
|
20 |
st.title("APK File Processor")
|
21 |
|
22 |
# File upload
|
23 |
uploaded_file = st.file_uploader("Upload APK file", type="apk")
|
24 |
if uploaded_file is not None:
|
25 |
-
# Create
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
zip_path = os.path.join(temp_dir, "patched-apk.zip")
|
30 |
|
31 |
# Save uploaded file
|
|
|
32 |
with open(input_path, "wb") as f:
|
33 |
f.write(uploaded_file.read())
|
34 |
-
|
35 |
-
|
|
|
36 |
|
37 |
# Process APK
|
38 |
st.write("Processing APK...")
|
39 |
result = process_apk(input_path, output_path)
|
40 |
|
41 |
-
st.write(f"Process command: apk-mitm {input_path} -o {output_path}")
|
42 |
-
st.write(f"Processing output: {result.stdout}")
|
43 |
-
st.write(f"Processing error: {result.stderr}")
|
44 |
-
|
45 |
if result.returncode == 0:
|
46 |
st.success("APK processed successfully!")
|
|
|
|
|
47 |
|
48 |
-
#
|
49 |
if os.path.exists(output_path):
|
50 |
-
st.write(f"Processed APK file
|
51 |
-
|
52 |
-
# Zip the processed APK file
|
53 |
-
zip_file(output_path, zip_path)
|
54 |
-
st.write(f"ZIP file created at: {zip_path}")
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
|
|
|
|
|
59 |
st.download_button(
|
60 |
-
label="Download Patched APK
|
61 |
-
data=
|
62 |
-
file_name=os.path.basename(
|
63 |
-
mime="application/
|
64 |
)
|
65 |
-
|
66 |
-
|
67 |
else:
|
68 |
-
st.error(
|
69 |
else:
|
70 |
st.error(f"Error processing APK: {result.stderr}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import subprocess
|
4 |
+
import shutil
|
|
|
5 |
|
6 |
# Function to process APK file
|
7 |
+
def process_apk(input_path, output_path):
|
8 |
# Run apk-mitm command
|
9 |
+
command = f"apk-mitm {input_path} -o {output_path}"
|
10 |
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
11 |
return result
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
# Streamlit app interface
|
14 |
st.title("APK File Processor")
|
15 |
|
16 |
# File upload
|
17 |
uploaded_file = st.file_uploader("Upload APK file", type="apk")
|
18 |
if uploaded_file is not None:
|
19 |
+
# Create directories if they don't exist
|
20 |
+
upload_dir = "uploads"
|
21 |
+
if not os.path.exists(upload_dir):
|
22 |
+
os.makedirs(upload_dir)
|
|
|
23 |
|
24 |
# Save uploaded file
|
25 |
+
input_path = os.path.join(upload_dir, uploaded_file.name)
|
26 |
with open(input_path, "wb") as f:
|
27 |
f.write(uploaded_file.read())
|
28 |
+
|
29 |
+
# Define output path for the patched APK
|
30 |
+
output_path = os.path.join(upload_dir, "patched-" + uploaded_file.name)
|
31 |
|
32 |
# Process APK
|
33 |
st.write("Processing APK...")
|
34 |
result = process_apk(input_path, output_path)
|
35 |
|
|
|
|
|
|
|
|
|
36 |
if result.returncode == 0:
|
37 |
st.success("APK processed successfully!")
|
38 |
+
st.write("Processing result:")
|
39 |
+
st.text(result.stdout)
|
40 |
|
41 |
+
# Check if the processed APK file exists
|
42 |
if os.path.exists(output_path):
|
43 |
+
st.write(f"Processed APK file found at: {output_path}")
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# Provide download link for the patched APK file
|
46 |
+
with open(output_path, "rb") as f:
|
47 |
+
file_data = f.read()
|
48 |
+
if file_data:
|
49 |
+
st.write("File data read successfully.")
|
50 |
st.download_button(
|
51 |
+
label="Download Patched APK",
|
52 |
+
data=file_data,
|
53 |
+
file_name=os.path.basename(output_path),
|
54 |
+
mime="application/vnd.android.package-archive"
|
55 |
)
|
56 |
+
else:
|
57 |
+
st.error("Failed to read file data.")
|
58 |
else:
|
59 |
+
st.error("Processed APK file not found. Please try again.")
|
60 |
else:
|
61 |
st.error(f"Error processing APK: {result.stderr}")
|
62 |
+
|
63 |
+
# Clean up the uploaded and processed files
|
64 |
+
def cleanup_files(input_path, output_path):
|
65 |
+
if os.path.exists(input_path):
|
66 |
+
os.remove(input_path)
|
67 |
+
if os.path.exists(output_path):
|
68 |
+
os.remove(output_path)
|
69 |
+
|
70 |
+
cleanup_files(input_path, output_path)
|