### Full LSPatch JAR Example with Multiple Options Source: https://context7.com/jingmatrix/lspatch/llms.txt A comprehensive example demonstrating various LSPatch JAR options including output directory, debuggable flag, signature bypass level, embedded module, version override, and force patching. ```bash java -jar lspatch.jar com.example.app.apk \ -o ./patched/ \ -d \ -l 2 \ -m xposed-module.apk \ -v \ -f ``` -------------------------------- ### LSPatch Project Setup Source: https://github.com/jingmatrix/lspatch/blob/master/patch-loader/src/main/jni/CMakeLists.txt Configures the CMake project, sets the C++ standard to 23, and includes the core library. This is the foundational setup for the project. ```cmake project(lspatch) cmake_minimum_required(VERSION 3.28) set(CMAKE_CXX_STANDARD 23) add_subdirectory(${CORE_ROOT} core) ``` -------------------------------- ### Allow Downgrade Installation with LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Override the version code to allow downgrade installations by using the `-r` flag. ```bash java -jar lspatch.jar target-app.apk -r ``` -------------------------------- ### Programmatic PatchConfig Creation Source: https://context7.com/jingmatrix/lspatch/llms.txt Example of creating a `PatchConfig` object programmatically. Set `useManager` to `false` for Integrated Mode. ```java // Creating a PatchConfig programmatically PatchConfig config = new PatchConfig( false, // useManager: false for Integrated Mode true, // debuggable: enable debugging false, // overrideVersionCode: keep original version 2, // sigBypassLevel: PM + openat hooks "308203...signature...", // originalSignature: base64 encoded "com.example.AppFactory" // appComponentFactory: original factory class ); ``` -------------------------------- ### Parse Android Manifest from InputStream in Java Source: https://context7.com/jingmatrix/lspatch/llms.txt Parses an Android manifest file from an InputStream to extract package name, app component factory, and minimum SDK version. Requires an AxmlParser and utility to get bytes from the stream. ```java package org.lsposed.patch.util; import java.io.IOException; import java.io.InputStream; import java.io.FileInputStream; public class ManifestParser { // Parse result containing package info public static class Pair { public String packageName; public String appComponentFactory; public int minSdkVersion; // Constructor added for completeness, assuming it exists based on usage public Pair(String packageName, String appComponentFactory, int minSdkVersion) { this.packageName = packageName; this.appComponentFactory = appComponentFactory; this.minSdkVersion = minSdkVersion; } } // Parse manifest from input stream public static Pair parseManifestFile(InputStream is) throws IOException { AxmlParser parser = new AxmlParser(Utils.getBytesFromInputStream(is)); String packageName = null; String appComponentFactory = null; int minSdkVersion = 0; while (true) { int type = parser.next(); if (type == AxmlParser.END_FILE) break; if (type == AxmlParser.START_TAG) { String name = parser.getName(); int attrCount = parser.getAttributeCount(); for (int i = 0; i < attrCount; i++) { String attrName = parser.getAttrName(i); if ("manifest".equals(name) && "package".equals(attrName)) { packageName = parser.getAttrValue(i).toString(); } if ("uses-sdk".equals(name) && "minSdkVersion".equals(attrName)) { minSdkVersion = Integer.parseInt(parser.getAttrValue(i).toString()); } if ("appComponentFactory".equals(attrName)) { appComponentFactory = parser.getAttrValue(i).toString(); } } } } return new Pair(packageName, appComponentFactory, minSdkVersion); } // Parse manifest from file path public static Pair parseManifestFile(String filePath) throws IOException { try (var is = new FileInputStream(filePath)) { return parseManifestFile(is); } } } ``` -------------------------------- ### Basic LSPatch JAR Command Source: https://context7.com/jingmatrix/lspatch/llms.txt Use this command for basic patching of an APK. The patched APK will be created in the current directory. ```bash java -jar lspatch.jar target-app.apk ``` -------------------------------- ### Patch with Custom Signing Keystore using LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Patch an APK using a custom keystore for signing with the `-k` flag, providing the keystore file, password, alias, and alias password. ```bash java -jar lspatch.jar target-app.apk -k keystore.jks password alias aliasPassword ``` -------------------------------- ### Embed Xposed Modules with LSPatch JAR (Integrated Mode) Source: https://context7.com/jingmatrix/lspatch/llms.txt Patch an APK and embed Xposed modules directly using the `-m` flag for Integrated Mode. ```bash java -jar lspatch.jar target-app.apk -m module1.apk -m module2.apk ``` -------------------------------- ### Specify Output Directory with LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Patch an APK and specify a custom output directory for the patched file using the `-o` flag. ```bash java -jar lspatch.jar target-app.apk -o ./output/ ``` -------------------------------- ### Patch for Manager Mode with LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Prepare an APK for Manager Mode, enabling dynamic module management through the LSPatch manager app, using the `--manager` flag. ```bash java -jar lspatch.jar target-app.apk --manager ``` -------------------------------- ### Patch Multiple Split APKs with LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Patch multiple split APKs by listing them after the `lspatch.jar` command. Ensure the base APK is listed first. ```bash java -jar lspatch.jar base.apk split_config.arm64_v8a.apk split_config.en.apk ``` -------------------------------- ### Enable Debuggable Flag with LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Patch an APK and enable the debuggable flag using the `-d` option, which is useful for development purposes. ```bash java -jar lspatch.jar target-app.apk -d ``` -------------------------------- ### Define Framework Constants in Java Source: https://context7.com/jingmatrix/lspatch/llms.txt This class defines fixed paths and values used throughout the LSPatch framework, including asset paths, file naming conventions, and signature bypass levels. ```java package org.lsposed.lspatch.share; public class Constants { // Asset paths within patched APK public static final String CONFIG_ASSET_PATH = "assets/lspatch/config.json"; public static final String LOADER_DEX_ASSET_PATH = "assets/lspatch/loader.dex"; public static final String META_LOADER_DEX_ASSET_PATH = "assets/lspatch/metaloader.dex"; public static final String ORIGINAL_APK_ASSET_PATH = "assets/lspatch/origin.apk"; public static final String EMBEDDED_MODULES_ASSET_PATH = "assets/lspatch/modules/"; // File naming public static final String PATCH_FILE_SUFFIX = "-lspatched.apk"; // Component factory for runtime initialization public static final String PROXY_APP_COMPONENT_FACTORY = "org.lsposed.lspatch.metaloader.LSPAppComponentFactoryStub"; // Manager package name public static final String MANAGER_PACKAGE_NAME = "org.lsposed.lspatch"; // Signature bypass levels public static final int SIGBYPASS_LV_DISABLE = 0; // No bypass public static final int SIGBYPASS_LV_PM = 1; // Hook PackageManager APIs public static final int SIGBYPASS_LV_PM_OPENAT = 2; // PM + native file hooks public static final int SIGBYPASS_LV_MAX = 3; } ``` -------------------------------- ### Set Signature Bypass Level with LSPatch JAR Source: https://context7.com/jingmatrix/lspatch/llms.txt Configure the signature bypass level using the `-l` flag. Level 2 includes PackageManager and openat hooks. ```bash java -jar lspatch.jar target-app.apk -l 2 ``` -------------------------------- ### Source File Declaration Source: https://github.com/jingmatrix/lspatch/blob/master/patch-loader/src/main/jni/CMakeLists.txt Collects source files from the 'src' and 'src/jni' directories, and explicitly adds 'api/patch_main.cpp'. These files are used to build the library. ```cmake aux_source_directory(src SRC_LIST) aux_source_directory(src/jni SRC_LIST) set(SRC_LIST ${SRC_LIST} api/patch_main.cpp) ``` -------------------------------- ### Library Target Configuration Source: https://github.com/jingmatrix/lspatch/blob/master/patch-loader/src/main/jni/CMakeLists.txt Defines the main shared library for the project using the collected source files. It also sets public and private include directories and links necessary libraries. ```cmake add_library(${PROJECT_NAME} SHARED ${SRC_LIST}) target_include_directories(${PROJECT_NAME} PUBLIC include) target_include_directories(${PROJECT_NAME} PRIVATE src) target_link_libraries(${PROJECT_NAME} core log) ``` -------------------------------- ### Signature Bypass Levels Constants Source: https://context7.com/jingmatrix/lspatch/llms.txt Defines the constants for signature bypass levels used in `PatchConfig`. Level 0 is disabled, Level 1 uses PackageManager hooks, and Level 2 uses both PackageManager and openat hooks. ```java // Signature bypass levels // Constants.SIGBYPASS_LV_DISABLE = 0 // No bypass // Constants.SIGBYPASS_LV_PM = 1 // Hook PackageManager // Constants.SIGBYPASS_LV_PM_OPENAT = 2 // Hook PM + native openat ``` -------------------------------- ### PatchConfig Class Definition Source: https://context7.com/jingmatrix/lspatch/llms.txt The `PatchConfig` class defines all parameters for patching an APK, which are embedded and read by the runtime loader. ```java package org.lsposed.lspatch.share; // PatchConfig holds all patching parameters public class PatchConfig { public final boolean useManager; // Use Manager Mode for dynamic modules public final boolean debuggable; // Make app debuggable public final boolean overrideVersionCode; // Set versionCode to 1 for downgrades public final int sigBypassLevel; // Signature bypass level (0-2) public final String originalSignature; // Original APK signature for bypass public final String appComponentFactory; // Original app component factory public final LSPConfig lspConfig; // LSPatch version info } ``` -------------------------------- ### Debug Symbols Handling Source: https://github.com/jingmatrix/lspatch/blob/master/patch-loader/src/main/jni/CMakeLists.txt Conditionally adds a custom command to handle debug symbols if DEBUG_SYMBOLS_PATH is defined. This command creates directories, extracts debug symbols, strips the binary, and links the debug symbols. ```cmake if (DEFINED DEBUG_SYMBOLS_PATH) set(DEBUG_SYMBOLS_PATH ${DEBUG_SYMBOLS_PATH}/${API}) message(STATUS "Debug symbols will be placed at ${DEBUG_SYMBOLS_PATH}") add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${DEBUG_SYMBOLS_PATH}/${ANDROID_ABI} COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ ${DEBUG_SYMBOLS_PATH}/${ANDROID_ABI}/${PROJECT_NAME}.debug COMMAND ${CMAKE_STRIP} --strip-all $ COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink ${DEBUG_SYMBOLS_PATH}/${ANDROID_ABI}/${PROJECT_NAME}.debug $) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.