File size: 1,973 Bytes
3ef37b3
12102c5
 
 
 
 
 
 
 
ad10389
 
 
12102c5
 
9cee6e7
 
12102c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abf597c
12102c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
import subprocess
import shutil
import tempfile

# Function to install Node.js and apk-mitm
def install_node_and_apk_mitm():
    # Install Node.js
  # st.write("Installing Node.js...")
   # os.system("curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -")
   # os.system("sudo apt-get install -y nodejs")
    
    # Install apk-mitm
    st.write("Installing apk-mitm...")
   # os.system("npm install -g apk-mitm")

# Function to process APK file
def process_apk(file_path, output_path):
    # Run apk-mitm command
    command = f"apk-mitm {file_path} -o {output_path}"
    result = subprocess.run(command, shell=True, capture_output=True, text=True)
    return result

# Streamlit app interface
st.title("APK File Processor")

# Install Node.js and apk-mitm if not installed
if not shutil.which("apk-mitm"):
    install_node_and_apk_mitm()

# File upload
uploaded_file = st.file_uploader("Upload APK file", type="apk")
if uploaded_file is not None:
    # Create temporary file paths
    temp_dir = tempfile.mkdtemp()
    input_path = os.path.join(temp_dir, uploaded_file.name)
    output_path = os.path.join(temp_dir, "patched-" + uploaded_file.name)
    
    # Save uploaded file
    with open(input_path, "wb") as f:
        f.write(uploaded_file.read())
    
    # Process APK
    st.write("Processing APK...")
    result = process_apk(input_path, output_path)
    
    if result.returncode == 0:
        st.success("APK processed successfully!")
        st.write("Processing result:")
        st.text(result.stdout)
        
        # Provide download link for processed APK
        with open(output_path, "rb") as f:
            st.download_button(
                label="Download Patched APK",
                data=f,
                file_name=os.path.basename(output_path),
                mime="application/vnd.android.package-archive"
            )
    else:
        st.error(f"Error processing APK: {result.stderr}")