From 13d85c64bd96f13cfed10b58c2e08a9025ebf5a0 Mon Sep 17 00:00:00 2001 From: Veha0001 Date: Fri, 29 Nov 2024 06:16:21 +0700 Subject: [PATCH] make verify the apk dirs --- README.md | 166 +++++++++++++++++++++++++++++------------------------ autogen.py | 37 ++++++++++++ 2 files changed, 128 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index d9ed1a3..6d89e5d 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,22 @@ DemoAPk is a tool for modifying and editing the APK package name that has been decoded by [APKEditor](https://github.com/REAndroid/APKEditor) and includes a patcher for editing binary files. +## Overview + +DemodAPK is a Python-based tool designed to modify decompiled APK files. It enables developers to: + +- Update Facebook App credentials (App ID, Client Token, Login Protocol Scheme). +- Rename package names in the APK manifest and associated files. +- Apply binary patches and remove metadata. + ## Features + - **Package Renaming**: Easily rename package names in APK files. - **Resource Modification**: Modify resources in APK files as needed. +- **Facebook API Updates**: Automatically replaces Facebook App details in the appropriate XML files. - **Metadata Adjustment**: Update application metadata in the AndroidManifest.xml file. - **Configurable Settings**: Store and manage settings in a JSON configuration file. -+ [x] Replace Facebook App API -+ [x] Inject libil2cpp.so -+ [x] Update package name - -### InComplete -- [x] Update App Name -- [x] Replace Google App API -- [x] More Patch Ability? -- [x] Clean code? +- **For educational purposes**: You're learning how APK files work or exploring reverse engineering ethically. ## Requirements @@ -37,119 +39,133 @@ DemoAPk is a tool for modifying and editing the APK package name that has been d ## Usage Run the script with the following command: + ```bash python autogen.py --config ``` + ### Patcher + ```bash python patcher.py # default is config.json ``` + - Configuration of Patcher + ```json { - "Patcher": { - "input_file": "apkdir/root/lib/arm64-v8a/libil2cpp.so", - "dump_file": "dump.cs", - "output_file": "libil2cpp_patched.so", - "patches": [ - { - "method_name": "UnlockAll", - "hex_code": "20 00 80 D2 C0 03 5F D6" - }, - { - "offset": "0x111111", - "hex_code": "1F 20 03 D5" - }, - { - "wildcard": "AA DD F5 ?? ?? ?? 00 01", - "hex_code": "00 E0 AF D2 C0 03 5F D6" - } - ] - } + "Patcher": { + "input_file": "apkdir/root/lib/arm64-v8a/libil2cpp.so", + "dump_file": "dump.cs", + "output_file": "libil2cpp_patched.so", + "patches": [ + { + "method_name": "UnlockAll", + "hex_code": "20 00 80 D2 C0 03 5F D6" + }, + { + "offset": "0x111111", + "hex_code": "1F 20 03 D5" + }, + { + "wildcard": "AA DD F5 ?? ?? ?? 00 01", + "hex_code": "00 E0 AF D2 C0 03 5F D6" + } + ] + } } ``` ## Performance Notice -The `patcher.py` file may work slowly when performing wildcard scans. If you want to run it faster, consider using the C++ version. +The `patcher.py` file may work slowly when performing wildcard scans. If you want to run it faster, consider using the C++ version. ### Building the C++ Version To build the C++ version, you will need to have `g++` or `gcc` installed, along with the `nlohmann-json` library. You can build it using the following command: + ```bash g++ -o patcher patcher.cpp -O2 ``` + For **Windows** using [MSYS2](https://www.msys2.org/) First Install some package: + ```bash pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-nlohmann-json gcc ``` + Then run the gcc command: `g++ patcher.cpp -o patcher.exe -O2` + > [!NOTE] > Edit by method_name may work on some dump.cs file. > The dump.cs file is get from [Il2CppDumper](https://github.com/Perfare/Il2CppDumper). ## Arguments -* --config: Path to the JSON configuration file (default: config.json). -* : Path to the APK directory that contains the files to be modified. +- --config: Path to the JSON configuration file (default: config.json). + +- : Path to the APK directory that contains the files to be modified. ## Example + > Run with a custom config file. + ```bash python autogen.py --config config.json /path/to/apk/directory ``` + > An Example of config.json + ```json { - "facebook": { - "app_id": "1234567890", - "client_token": "aaabbbcccddd0001", - "login_protocol_scheme": "fb1234567890" + "facebook": { + "app_id": "1234567890", + "client_token": "aaabbbcccddd0001", + "login_protocol_scheme": "fb1234567890" + }, + "package": { + "new_name": "com.app.master", + "new_path": "Lcom/app/master" + }, + "files": [ + { + "replace": { + "target": "root/lib/arm64-v8a/libil2cpp.so", + "source": "/path/to/external/bin.so", + "backup": true + } }, - "package": { - "new_name": "com.app.master", - "new_path": "Lcom/app/master" - }, - "files": [ - { - "replace": { - "target": "root/lib/arm64-v8a/libil2cpp.so", - "source": "/path/to/external/bin.so", - "backup": true - } - }, - { - "replace": { - "target": "resources/package_1/res/values/strings.xml", - "source": "./path/to/external/strings_new.xml" - } - } - ], - "metadata_to_remove": [ - "" - ], - "Patcher": { - "input_file": "apkdir/root/lib/arm64-v8a/libil2cpp.so", - "dump_file": "dump.cs", - "output_file": "libil2cpp_patched.so", - "patches": [ - { - "method_name": "UnlockAll", - "hex_code": "20 00 80 D2 C0 03 5F D6" - }, - { - "offset": "0x111111", - "hex_code": "1F 20 03 D5" - }, - { - "wildcard": "AA DD F5 ?? ?? ?? 00 01", - "hex_code": "00 E0 AF D2 C0 03 5F D6" - } - ] + { + "replace": { + "target": "resources/package_1/res/values/strings.xml", + "source": "./path/to/external/strings_new.xml" + } } + ], + "metadata_to_remove": [""], + "Patcher": { + "input_file": "apkdir/root/lib/arm64-v8a/libil2cpp.so", + "dump_file": "dump.cs", + "output_file": "libil2cpp_patched.so", + "patches": [ + { + "method_name": "UnlockAll", + "hex_code": "20 00 80 D2 C0 03 5F D6" + }, + { + "offset": "0x111111", + "hex_code": "1F 20 03 D5" + }, + { + "wildcard": "AA DD F5 ?? ?? ?? 00 01", + "hex_code": "00 E0 AF D2 C0 03 5F D6" + } + ] + } } ``` + Follow the prompts to select the APK file and modify its contents according to your preferences. ## License diff --git a/autogen.py b/autogen.py index 412faf7..35a31c6 100755 --- a/autogen.py +++ b/autogen.py @@ -521,9 +521,46 @@ def parse_arguments(): def verify_apk_directory(apk_dir): + """ + Verifies if the given directory is a valid decoded APK directory. + + Args: + apk_dir (str): Path to the APK directory. + + Returns: + str: Verified APK directory path. + """ if not os.path.exists(apk_dir): msg.error(f"The directory {apk_dir} does not exist.") sys.exit(1) + + # Check for required files and folders + required_files = ["AndroidManifest.xml"] + required_folders = ["resources", "root"] + optional_folders = ["dex", "smali"] + + # Check for required files + for req_file in required_files: + if not os.path.isfile(os.path.join(apk_dir, req_file)): + msg.error(f"Missing required file '{req_file}' in {apk_dir}.") + sys.exit(1) + + # Check for required folders + for req_folder in required_folders: + if not os.path.isdir(os.path.join(apk_dir, req_folder)): + msg.error(f"Missing required folder '{req_folder}' in {apk_dir}.") + sys.exit(1) + + # Check for at least one optional folder + if not any( + os.path.isdir(os.path.join(apk_dir, folder)) for folder in optional_folders + ): + msg.error( + f"At least one of the following folders is required in {apk_dir}: {', '.join(optional_folders)}." + ) + sys.exit(1) + + msg.info(f"APK directory verified: {apk_dir}") return apk_dir