APK_Analyser / app.py
vrkforever's picture
Update app.py
32eb707 verified
import gradio as gr
import tempfile
import os
from androguard.misc import AnalyzeAPK
def extract_apk_info(apk_file):
if apk_file is None:
return "No file uploaded. Please upload an APK file."
temp_apk_path = None
try:
# Create a temporary file
with tempfile.NamedTemporaryFile(delete=False, suffix=".apk") as temp_apk:
# Write the content directly as binary data
temp_apk.write(apk_file) # Write the uploaded file content as bytes
temp_apk_path = temp_apk.name
a, d, dx = AnalyzeAPK(temp_apk_path)
output = []
output.append(f"Package: {a.get_package()}")
output.append(f"Version: {a.get_androidversion_name()}")
output.append(f"Main Activity: {a.get_main_activity()}")
output.append("\nPermissions:")
for permission in a.get_permissions():
output.append(f"- {permission}")
output.append("\nActivities:")
for activity in a.get_activities():
output.append(f"- {activity}")
output.append("\nServices:")
for service in a.get_services():
output.append(f"- {service}")
output.append("\nReceivers:")
for receiver in a.get_receivers():
output.append(f"- {receiver}")
output.append("\nProviders:")
for provider in a.get_providers():
output.append(f"- {provider}")
return "\n".join(output)
except Exception as e:
return f"Error analyzing APK: {str(e)}"
finally:
# Clean up the temporary file
if temp_apk_path and os.path.exists(temp_apk_path):
os.unlink(temp_apk_path)
# Create Gradio interface
iface = gr.Interface(
fn=extract_apk_info,
inputs=gr.File(label="Upload APK File", file_types=['.apk']),
outputs=gr.Textbox(label="Extracted APK Information", lines=25),
title="APK Extractor",
description="Upload an APK file to extract and view its components."
)
# Launch the interface
iface.launch()