Spaces:
Running
Running
File size: 3,505 Bytes
3ef37b3 12102c5 92387b0 21fd4fa 12102c5 59b7cd2 12102c5 9b68160 12102c5 edf7019 8719474 15ed6e7 8719474 12102c5 cc2e390 21fd4fa 92387b0 101246c 21fd4fa 59b7cd2 01f3963 12102c5 59b7cd2 12102c5 8719474 12102c5 92387b0 2d2e11e 12102c5 8719474 59b7cd2 92387b0 101246c 92387b0 6e92fb6 92387b0 01f3963 92387b0 8719474 92387b0 01f3963 92387b0 101246c 92387b0 12102c5 8719474 92387b0 8719474 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
import streamlit as st
import os
import subprocess
import shutil
import requests
# Function to process APK file
def process_apk(input_path, output_dir):
# Run apk-mitm command
command = f"java -jar uber-apk-signer.jar --apks {input_path}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
#st.write(f"Processed APK file found at: {result}")
# Check if the process was successful
if result.returncode == 0:
out_path = input_path.replace('.apk', '-aligned-debugSigned.apk')
return out_path
else:
st.error(f"Error processing APK: {result.stderr}")
return None
# Streamlit app interface
st.title("APK File Processor")
# File upload
uploaded_file = st.file_uploader("Upload APK file", type=['apk', 'xapk', 'apks'])
# URL upload
url_input = st.text_input("Or enter APK URL")
if uploaded_file is not None or url_input:
# Create directories if they don't exist
upload_dir = "uploads"
if not os.path.exists(upload_dir):
os.makedirs(upload_dir)
if uploaded_file is not None:
# Save uploaded file
input_path = os.path.join(upload_dir, uploaded_file.name)
with open(input_path, "wb") as f:
f.write(uploaded_file.read())
elif url_input:
# Download APK from URL
st.write("Downloading APK from URL...")
response = requests.get(url_input)
if response.status_code == 200:
input_path = os.path.join(upload_dir, os.path.basename(url_input))
with open(input_path, "wb") as f:
f.write(response.content)
else:
st.error("Failed to download APK from URL. Please check the URL and try again.")
st.stop()
# Define output directory for the patched APK
output_dir = upload_dir
# Process APK
st.write("Processing APK...")
result = process_apk(input_path, output_dir)
if result:
st.success("APK processed successfully!")
st.write("Processing result:")
st.text(result)
# Extract the patched APK file name from the output path
output_file_name = os.path.basename(result)
output_path = os.path.join(output_dir, output_file_name)
# Check if the processed APK file exists
if os.path.exists(output_path):
st.write(f"Processed APK file found at: {output_path}")
# Provide download link for the patched APK file
with open(output_path, "rb") as f:
file_data = f.read()
if file_data:
st.download_button(
label="Download Patched APK",
data=file_data,
file_name=output_file_name,
mime="application/vnd.android.package-archive"
)
else:
st.error("Failed to read file data.")
else:
st.error("Processed APK file not found. Please try again.")
else:
st.error("Failed to process APK. Please try again.")
# Clean up the uploaded and processed files
def cleanup_files(input_path, output_path):
if os.path.exists(input_path):
os.remove(input_path)
if os.path.exists(output_path):
os.remove(output_path)
# Cleanup is done after download button appears to ensure the file is available for download
cleanup_files(input_path, output_path)
|