Spaces:
Paused
Paused
File size: 2,345 Bytes
26ae9bc | 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 | import os
import subprocess
import shutil
import zipfile
import streamlit as st
from utils.apk_debug import debug_apk
def process_xapk(xapk_path):
try:
folder = os.path.dirname(xapk_path)
name_without_ext = os.path.splitext(os.path.basename(xapk_path))[0]
zip_path = os.path.join(folder, f"{name_without_ext}.zip")
extract_dir = os.path.join(folder, name_without_ext)
shutil.move(xapk_path, zip_path)
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_dir)
os.remove(zip_path)
command = f'java -jar APKEditor.jar m -i "{extract_dir}"'
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode == 0:
merged_apk_path = os.path.join(folder, f"{name_without_ext}_merged.apk")
st.write(f"Merged APK created at: {merged_apk_path}")
signed_apk_path = process_sign(merged_apk_path)
return signed_apk_path
else:
st.error(f"Error merging APK: {result.stderr}")
return None
except Exception as e:
st.error(f"Error processing XAPK: {str(e)}")
shutil.rmtree(extract_dir, ignore_errors=True)
return None
def process_sign(apk_path):
folder = os.path.dirname(apk_path)
command = f"java -jar uber-apk-signer.jar --apks {apk_path}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode == 0:
signed_apk_path = apk_path.replace('.apk', '-aligned-debugSigned.apk')
if os.path.exists(signed_apk_path):
st.write("APK signing successful!")
return signed_apk_path
else:
st.error("APK signing completed, but the signed file could not be found.")
return None
else:
st.error(f"Error signing APK: {result.stderr}")
return None
def xapk_debug(xapk_path, output_dir):
# Process the XAPK file first
signed_apk_path = process_xapk(xapk_path)
if signed_apk_path:
# Use the signed APK as input for debugging
debug_path = debug_apk(signed_apk_path, output_dir)
return debug_path
else:
st.error("Failed to process XAPK for debugging.")
return None |