import os import zipfile import shutil import gradio as gr # Active session ke liye file paths map karne ki global dictionary session_files = {} def process_and_extract_apk(file_obj): global session_files session_files.clear() # Purana data saaf karna if file_obj is None: return gr.update(choices=[]), "āš ļø Error: Please upload a valid APK file first.", None try: apk_path = file_obj.name extract_dir = "extracted_source_temp" output_zip_path = "apk_full_source_code.zip" # Agar purana data maujood hai toh mita dena if os.path.exists(extract_dir): shutil.rmtree(extract_dir) if os.path.exists(output_zip_path): os.remove(output_zip_path) # 1. APK ko temporary folder mein unzip karna with zipfile.ZipFile(apk_path, 'r') as zip_ref: zip_ref.extractall(extract_dir) # 2. Saari files ko list aur session map mein daalna file_list = [] for root, dirs, files in os.walk(extract_dir): for file in files: full_path = os.path.join(root, file) relative_path = os.path.relpath(full_path, extract_dir) file_list.append(relative_path) session_files[relative_path] = full_path file_list.sort() if len(file_list) == 0: return gr.update(choices=[]), "āš ļø Warning: APK extracted but no files found inside.", None # 3. Pure source code folder ka download ke liye ek naya ZIP banana shutil.make_archive("apk_full_source_code", 'zip', extract_dir) status_msg = f"šŸ”„ SUCCESS: APK Analysed! {len(file_list)} files extracted inside vault.\n\nšŸ‘‰ Click the download link below to get ALL files at once!" return gr.update(choices=file_list, value=file_list[0] if file_list else None), status_msg, output_zip_path except Exception as e: return gr.update(choices=[]), f"āŒ Failed to decompile package: {str(e)}", None def read_selected_file_code(relative_path): global session_files if not relative_path or relative_path not in session_files: return "No file selected or file data trace lost." full_target_path = session_files[relative_path] readable_extensions = ('.txt', '.json', '.html', '.css', '.js', '.properties', '.xml', '.mf', '.sf') try: if not relative_path.lower().endswith(readable_extensions): file_size = os.path.getsize(full_target_path) return f"āš™ļø [COMPILED BINARY DATA LAYER]\n\nFile Name: {relative_path}\nSize: {file_size} bytes\n\nThis is a compiled Android binary file (like .dex, .arsc, or .so). Raw machine bytecode cannot be displayed as plain text directly without an assembler model framework." with open(full_target_path, 'r', encoding='utf-8', errors='ignore') as f: code_content = f.read() if not code_content.strip(): return "--- EMPTY FILE OR BLANK SOURCE STREAM ---" return code_content except Exception as e: return f"āŒ Error reading file data stream: {str(e)}" # --- Matrix Cyber Neon Theme CSS Stylesheet --- cyber_theme_css = """ body, .gradio-container { background-color: #010401 !important; color: #00ff00 !important; font-family: 'Courier New', monospace !important; } .code-box textarea { background-color: #000000 !important; color: #1aff1a !important; font-family: 'Courier New', monospace !important; border: 1px solid #00ff00 !important; } .dropdown-style { background-color: #000000 !important; color: #00ff00 !important; } button { background-color: #003300 !important; color: #00ff00 !important; border: 1px solid #00ff00 !important; font-weight: bold; } button:hover { background-color: #00ff00 !important; color: #000000 !important; box-shadow: 0 0 15px #00ff00; } """ # --- UI Layout Design Setup --- with gr.Blocks(css=cyber_theme_css) as app: gr.Markdown( """

⚔ CYBER STATIC APK REVERSE PORTAL ⚔

Docker Node Container - Secure Web Interface for Packaging Log Inspection

""" ) with gr.Row(): with gr.Column(scale=1): gr.Markdown("### šŸ“„ STEP 1: UPLOAD TARGET") input_apk = gr.File(label="Upload .APK Package File", file_types=[".apk"]) analyze_btn = gr.Button("RUN DECOMPILER ENGINE āš™ļø") gr.Markdown("### šŸ“¦ DOWNLOAD FULL SOURCE CODE") output_file = gr.File(label="Download All Files (ZIP Format)", interactive=False) gr.Markdown("### šŸ“‚ STEP 2: SELECT FILE TREE") file_dropdown = gr.Dropdown(label="Extracted Package Directory", choices=[], interactive=True, elem_classes=["dropdown-style"]) with gr.Column(scale=2): gr.Markdown("### šŸ’» CODE / INSIGHT DATA FEED") status_output = gr.Markdown("System Status: Awaiting Target Package...") code_viewer = gr.Textbox(label="Source Data Inspector View", lines=25, max_lines=38, elem_classes=["code-box"], interactive=False) # Click aur Change Events ki connectivity analyze_btn.click( fn=process_and_extract_apk, inputs=[input_apk], outputs=[file_dropdown, status_output, output_file] ) file_dropdown.change( fn=read_selected_file_code, inputs=[file_dropdown], outputs=[code_viewer] ) # Docker Node Port Mapping Trigger if __name__ == "__main__": app.launch(server_name="0.0.0.0", server_port=7860)