Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
from flask import Flask, request, send_file, Response
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
UPLOAD_FOLDER = "uploads"
|
| 9 |
+
OUTPUT_FOLDER = "decompiled_source"
|
| 10 |
+
ZIP_NAME = "source_code"
|
| 11 |
+
|
| 12 |
+
# Cleanup function
|
| 13 |
+
def cleanup():
|
| 14 |
+
if os.path.exists(UPLOAD_FOLDER):
|
| 15 |
+
shutil.rmtree(UPLOAD_FOLDER)
|
| 16 |
+
if os.path.exists(OUTPUT_FOLDER):
|
| 17 |
+
shutil.rmtree(OUTPUT_FOLDER)
|
| 18 |
+
if os.path.exists(f"{ZIP_NAME}.zip"):
|
| 19 |
+
os.remove(f"{ZIP_NAME}.zip")
|
| 20 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
@app.route('/')
|
| 23 |
+
def index():
|
| 24 |
+
return '''
|
| 25 |
+
<!doctype html>
|
| 26 |
+
<html style="background:#1e1e2e; color:white; font-family:sans-serif; text-align:center; padding:50px;">
|
| 27 |
+
<h1>🔓 APK to Source Code (Decompiler)</h1>
|
| 28 |
+
<p>Upload APK & Get Java/XML Source Code Zip</p>
|
| 29 |
+
<form action="/decompile" method="post" enctype="multipart/form-data">
|
| 30 |
+
<input type="file" name="file" accept=".apk" required style="padding:10px;">
|
| 31 |
+
<br><br>
|
| 32 |
+
<button type="submit" style="padding:15px 30px; background:#4CAF50; color:white; border:none; border-radius:5px; cursor:pointer;">
|
| 33 |
+
Extract Source Code
|
| 34 |
+
</button>
|
| 35 |
+
</form>
|
| 36 |
+
</html>
|
| 37 |
+
'''
|
| 38 |
+
|
| 39 |
+
@app.route('/decompile', methods=['POST'])
|
| 40 |
+
def decompile():
|
| 41 |
+
cleanup()
|
| 42 |
+
|
| 43 |
+
file = request.files['file']
|
| 44 |
+
if not file or file.filename == '':
|
| 45 |
+
return "No file selected", 400
|
| 46 |
+
|
| 47 |
+
apk_path = os.path.join(UPLOAD_FOLDER, "app.apk")
|
| 48 |
+
file.save(apk_path)
|
| 49 |
+
|
| 50 |
+
# Command to run JADX
|
| 51 |
+
# -d = output directory
|
| 52 |
+
# --no-replace-consts = code thora saaf dikhta hai
|
| 53 |
+
cmd = ["jadx", "-d", OUTPUT_FOLDER, apk_path]
|
| 54 |
+
|
| 55 |
+
try:
|
| 56 |
+
# Run Decompiler
|
| 57 |
+
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 58 |
+
|
| 59 |
+
if result.returncode == 0:
|
| 60 |
+
# Create ZIP of the source code
|
| 61 |
+
shutil.make_archive(ZIP_NAME, 'zip', OUTPUT_FOLDER)
|
| 62 |
+
|
| 63 |
+
return send_file(
|
| 64 |
+
f"{ZIP_NAME}.zip",
|
| 65 |
+
as_attachment=True,
|
| 66 |
+
download_name=f"{file.filename}_Source.zip",
|
| 67 |
+
mimetype="application/zip"
|
| 68 |
+
)
|
| 69 |
+
else:
|
| 70 |
+
return Response(f"Decompilation Failed!\n\nLogs:\n{result.stderr}", mimetype="text/plain", status=500)
|
| 71 |
+
|
| 72 |
+
except Exception as e:
|
| 73 |
+
return f"System Error: {str(e)}", 500
|
| 74 |
+
|
| 75 |
+
if __name__ == '__main__':
|
| 76 |
+
cleanup()
|
| 77 |
+
app.run(host='0.0.0.0', port=7860)
|