| import gradio as gr |
| import subprocess |
| import os |
| import shutil |
| import re |
|
|
| def fix_apk(apk_file): |
| if apk_file is None: |
| return "لطفاً یک فایل انتخاب کنید.", None |
| |
| apk_path = apk_file.name |
| output_dir = "extracted_apk" |
| |
| |
| if os.path.exists(output_dir): |
| shutil.rmtree(output_dir) |
| if os.path.exists("fixed.apk"): |
| os.remove("fixed.apk") |
| if os.path.exists("final_signed_game.apk"): |
| os.remove("final_signed_game.apk") |
| |
| try: |
| |
| subprocess.run(["apktool", "d", apk_path, "-o", output_dir, "-f"], check=True) |
| |
| |
| manifest_path = os.path.join(output_dir, "AndroidManifest.xml") |
| with open(manifest_path, "r", encoding="utf-8") as f: |
| manifest = f.read() |
| |
| manifest = re.sub(r'targetSdkVersion="[0-9]+"', 'targetSdkVersion="34"', manifest) |
| manifest = manifest.replace('<activity ', '<activity android:exported="true" ') |
| |
| with open(manifest_path, "w", encoding="utf-8") as f: |
| f.write(manifest) |
| |
| |
| subprocess.run(["apktool", "b", output_dir, "-o", "fixed.apk"], check=True) |
| |
| |
| if not os.path.exists("mykey.keystore"): |
| subprocess.run(["keytool", "-genkey", "-v", "-keystore", "mykey.keystore", "-alias", "myalias", "-keyalg", "RSA", "-keysize", "2048", "-validity", "10000", "-storepass", "123456", "-keypass", "123456", "-dname", "CN=Android,O=Android,C=US"], check=True) |
| |
| |
| subprocess.run(["apksigner", "sign", "--ks", "mykey.keystore", "--ks-pass", "pass:123456", "--out", "final_signed_game.apk", "fixed.apk"], check=True) |
| |
| return "جراحی با موفقیت انجام شد! حالا میتوانید بازی را نصب کنید.", "final_signed_game.apk" |
| |
| except Exception as e: |
| return f"خطا در پردازش: {str(e)}", None |
|
|
| |
| iface = gr.Interface( |
| fn=fix_apk, |
| inputs=gr.File(label="فایل APK قدیمی بازی را اینجا آپلود کنید"), |
| outputs=[ |
| gr.Textbox(label="وضعیت عملیات"), |
| gr.File(label="دانلود فایل نهایی و سالم") |
| ], |
| title="اتاق عمل بازی 🛠️", |
| description="فایل بازی خود را آپلود کنید تا کدهای آن برای اجرا روی دستگاههای جدید بازسازی شود." |
| ) |
|
|
| iface.launch() |