| import gradio as gr |
| from androguard.core.analysis import analysis |
| from androguard.core.analysis.analysis import Analysis |
| from androguard.core.bytecodes import dvm |
| from androguard.core.bytecodes.apk import APK |
| from androguard.core.bytecodes.dvm import DalvikVMFormat |
| from androguard.decompiler.dad import decompile |
| from androguard.decompiler.decompiler import DecompilerJADX |
| from androguard.misc import AnalyzeAPK |
|
|
|
|
|
|
| def chosen_class(chosen_class, apk_file): |
| text = "" |
| code = "" |
| if chosen_class != None and apk_file != None: |
|
|
| a, d, dx = AnalyzeAPK(apk_file.name) |
|
|
|
|
| for current_class in dx.get_classes(): |
| if current_class.name == chosen_class: |
|
|
| for method in current_class.get_methods(): |
| text = text + "\n" + method.name + "\n" |
| code = code + "\n" + method.name + "\n" |
| if method.is_external(): |
| continue |
| m = method.get_method() |
| for ins in m.get_instructions(): |
| print(ins.get_op_value(), ins.get_name(), ins.get_output()) |
| text = text + ins.get_output() + "\n" |
|
|
|
|
|
|
| |
| d = DalvikVMFormat(a) |
| |
| dx = Analysis(d) |
|
|
| |
| |
| |
| decompiler = DecompilerJADX(d, dx) |
|
|
| |
| d.set_decompiler(decompiler) |
|
|
|
|
| |
| for m in d.get_methods()[:10]: |
| print(m) |
| data = decompiler.get_source_method(m) |
| print(data) |
| code = code + data +"\n" |
|
|
|
|
|
|
| return text, code |
|
|
| def upload_file(file): |
|
|
| a, d, dx = AnalyzeAPK(file.name) |
|
|
| classes = dx.get_classes() |
|
|
| class_names = [] |
| for dex_class in classes: |
| class_names.append(dex_class.name) |
|
|
|
|
| info_data = { |
| "package_name": a.get_app_name(), |
| "package": a.get_package(), |
| "icon": a.get_app_icon(), |
| "permissions": a.get_permissions(), |
| "activities": a.get_activities(), |
| "android_version_code": a.get_androidversion_code(), |
| "android_version_name": a.get_androidversion_name(), |
| "min_sdk_version": a.get_min_sdk_version(), |
| "max_sdk_version": a.get_max_sdk_version(), |
| "target_sdk_version": a.get_target_sdk_version(), |
| "effective_sdk_version": a.get_effective_target_sdk_version() |
| } |
|
|
| return [file.name], gr.Dropdown.update(choices=class_names), info_data |
|
|
|
|
| with gr.Blocks() as demo: |
| file_drop_down = gr.Dropdown([""], interactive=True) |
| file_output = gr.File(interactive=False) |
| apk_stats = gr.Json(value="{}") |
| text_box_bytecode = gr.Textbox() |
| text_box_code = gr.Textbox() |
| upload_button = gr.UploadButton("Upload APK", file_types=["apk"]) |
| upload_button.upload(upload_file, upload_button, outputs=[file_output,file_drop_down,apk_stats]) |
| button = gr.Button(value="Process class") |
| button.click(fn=chosen_class, outputs=[text_box_bytecode,text_box_code], inputs=[file_drop_down,file_output]) |
|
|
| demo.launch(enable_queue = True) |