File size: 2,421 Bytes
2eb18f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import shutil
import subprocess
from flask import Flask, request, send_file, Response

app = Flask(__name__)

UPLOAD_FOLDER = "uploads"
OUTPUT_FOLDER = "decompiled_source"
ZIP_NAME = "source_code"

# Cleanup function
def cleanup():
    if os.path.exists(UPLOAD_FOLDER):
        shutil.rmtree(UPLOAD_FOLDER)
    if os.path.exists(OUTPUT_FOLDER):
        shutil.rmtree(OUTPUT_FOLDER)
    if os.path.exists(f"{ZIP_NAME}.zip"):
        os.remove(f"{ZIP_NAME}.zip")
    os.makedirs(UPLOAD_FOLDER, exist_ok=True)

@app.route('/')
def index():
    return '''
    <!doctype html>
    <html style="background:#1e1e2e; color:white; font-family:sans-serif; text-align:center; padding:50px;">
    <h1>🔓 APK to Source Code (Decompiler)</h1>
    <p>Upload APK & Get Java/XML Source Code Zip</p>
    <form action="/decompile" method="post" enctype="multipart/form-data">
      <input type="file" name="file" accept=".apk" required style="padding:10px;">
      <br><br>
      <button type="submit" style="padding:15px 30px; background:#4CAF50; color:white; border:none; border-radius:5px; cursor:pointer;">
        Extract Source Code
      </button>
    </form>
    </html>
    '''

@app.route('/decompile', methods=['POST'])
def decompile():
    cleanup()
    
    file = request.files['file']
    if not file or file.filename == '':
        return "No file selected", 400

    apk_path = os.path.join(UPLOAD_FOLDER, "app.apk")
    file.save(apk_path)

    # Command to run JADX
    # -d = output directory
    # --no-replace-consts = code thora saaf dikhta hai
    cmd = ["jadx", "-d", OUTPUT_FOLDER, apk_path]

    try:
        # Run Decompiler
        result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
        
        if result.returncode == 0:
            # Create ZIP of the source code
            shutil.make_archive(ZIP_NAME, 'zip', OUTPUT_FOLDER)
            
            return send_file(
                f"{ZIP_NAME}.zip",
                as_attachment=True,
                download_name=f"{file.filename}_Source.zip",
                mimetype="application/zip"
            )
        else:
            return Response(f"Decompilation Failed!\n\nLogs:\n{result.stderr}", mimetype="text/plain", status=500)
            
    except Exception as e:
        return f"System Error: {str(e)}", 500

if __name__ == '__main__':
    cleanup()
    app.run(host='0.0.0.0', port=7860)