### Project Setup and Compiler Cache Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Initializes the CMake project and configures Ccache for faster builds if available. Ensure ccache is installed and in your PATH. ```cmake cmake_minimum_required(VERSION 3.28.0) project("apjni") find_program(CCACHE ccache) if (CCACHE) set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE}) set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE}) endif () ``` -------------------------------- ### Implement Lua Module Lifecycle Hooks Source: https://context7.com/lyravoid/folkpatch/llms.txt Define a module table with callback functions for post-fs-data, service, and boot-completed stages. Use the provided helper functions for file I/O and module installation. ```lua -- Module file: /data/adb/modules/mymodule/mymodule.lua -- Must return a table with callback functions local M = {} -- Called during post-fs-data stage function M.post_fs_data() info("Post-fs-data stage triggered") -- Perform early initialization end -- Called during service stage function M.service() info("Service stage triggered") end -- Called during boot-completed stage function M.boot_completed() info("Boot completed") end -- Called when user triggers module action function M.action() info("Action triggered by user") -- Save persistent data save_text("mymodule_state.txt", "last_run=" .. os.time()) -- Load saved data local state = load_text("mymodule_state.txt") info("Loaded state: " .. state) end -- Install another module programmatically function M.install_helper() install_module("/sdcard/Download/helper_module.zip") end return M ``` -------------------------------- ### APD CLI - Root Shell and Module Management Source: https://context7.com/lyravoid/folkpatch/llms.txt Use the APD CLI to manage root access and modules. Invoke the root shell, install, list, enable, disable, or uninstall modules. Trigger boot events and start the UID listener for root permission synchronization. ```bash # Root shell invocation (when called as 'su' or 'kp') /data/adb/apd ``` ```bash # Install a module from ZIP file apd --superkey module install /path/to/module.zip ``` ```bash # List all installed modules (outputs JSON) apd --superkey module list ``` ```bash # Enable/disable a module apd --superkey module enable ``` ```bash apd --superkey module disable ``` ```bash # Uninstall a module (marks for removal on next boot) apd --superkey module uninstall ``` ```bash # Undo pending uninstall apd --superkey module undo-uninstall ``` ```bash # Run module action script apd --superkey module action ``` ```bash # Trigger boot events apd --superkey post-fs-data ``` ```bash apd --superkey services ``` ```bash apd --superkey boot-completed ``` ```bash # Start UID listener for root permission synchronization apd --superkey uid-listener ``` -------------------------------- ### Resetprop - System Property Tool Source: https://context7.com/lyravoid/folkpatch/llms.txt Manipulate Android system properties using Resetprop. List all properties, get specific values, set new properties, or delete existing ones. Supports direct memory operations, persistent properties, and loading from files. ```bash # List all system properties resetprop ``` ```bash # Get a specific property resetprop ro.build.fingerprint ``` ```bash # Set a property value resetprop ro.debuggable 1 ``` ```bash # Set property bypassing property_service (direct mmap) resetprop -n persist.sys.config mtp ``` ```bash # Delete a property resetprop -d ro.secure ``` ```bash # Work with persistent properties resetprop -p persist.sys.timezone America/New_York ``` ```bash # Load properties from a file resetprop -f /data/adb/modules/mymodule/system.prop ``` ```bash # Wait for a property to exist resetprop -w sys.boot_completed ``` ```bash # Wait for property with specific value and timeout resetprop -w sys.boot_completed 1 --timeout 30 ``` ```bash # Compact property area memory resetprop -c ``` ```bash # Show SELinux context when listing resetprop -Z ``` -------------------------------- ### APD Module Management Source: https://context7.com/lyravoid/folkpatch/llms.txt Endpoints for managing the lifecycle of modules, including installation, listing, enabling, and removal. ```APIDOC ## APD Module Management ### Description Manage module lifecycle operations including installation, listing, and state toggling. ### Parameters #### Query Parameters - **superkey** (string) - Required - Authentication key for root operations. ### Request Example apd --superkey module install /path/to/module.zip ### Response #### Success Response (200) - **output** (json) - Returns module list or operation status. ``` -------------------------------- ### Linking Libraries and Options Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Links the 'log' library and applies specific linker options for optimization and symbol stripping. These options are crucial for production builds. ```cmake target_link_libraries(${PROJECT_NAME} PRIVATE log) target_compile_options(${PROJECT_NAME} PRIVATE -flto) target_link_options(${PROJECT_NAME} PRIVATE "-Wl,--build-id=none" "-Wl,-icf=all,--lto-O3" "-Wl,-s,-x,--gc-sections" "-Wl,--no-undefined") ``` -------------------------------- ### CXX Library Integration Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Finds and links the 'cxx' library, which is required for the project. This assumes the 'cxx' library is available and configured for CMake. ```cmake find_package(cxx REQUIRED CONFIG) link_libraries(cxx::cxx) ``` -------------------------------- ### Define APM Module Metadata Source: https://context7.com/lyravoid/folkpatch/llms.txt Configure the module.prop file to specify identity, versioning, and update information for the FolkPatch module. ```properties # module.prop example id=mymodule name=My Custom Module version=v1.0.0 versionCode=1 author=Developer Name description=A sample FolkPatch module updateJson=https://example.com/update.json ``` -------------------------------- ### MagiskPolicy - SELinux Policy Patch Tool Source: https://context7.com/lyravoid/folkpatch/llms.txt Manage SELinux policies with MagiskPolicy. Apply built-in Magisk rules, custom policy statements, or rules from a file to the live policy. Load, save, compile split CIL policies, and print all current rules. ```bash # Apply built-in Magisk rules to live policy magiskpolicy --live --magisk ``` ```bash # Apply custom policy statements magiskpolicy --live "allow untrusted_app system_file file read" ``` ```bash # Apply rules from a file magiskpolicy --live --apply /data/adb/modules/mymodule/sepolicy.rule ``` ```bash # Load and save policy magiskpolicy --load /sepolicy --save /data/modified_policy ``` ```bash # Compile split CIL policies magiskpolicy --compile-split --save /data/compiled_policy ``` ```bash # Print all rules in current policy magiskpolicy --print-rules ``` -------------------------------- ### Library Target and Post-Build Stripping Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Defines a shared library target named 'apjni' and adds a post-build command to strip symbols and specific sections. This reduces the final library size. ```cmake add_library(${PROJECT_NAME} SHARED apjni.cpp security.cpp) add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-all --remove-section=.note.gnu.build-id --remove-section=.note.android.ident $) ``` -------------------------------- ### APD Module Configuration Source: https://context7.com/lyravoid/folkpatch/llms.txt Endpoints for managing persistent and temporary key-value configurations for modules. ```APIDOC ## APD Module Configuration ### Description Set, get, and delete configuration entries for modules. Supports persistent and temporary storage. ### Parameters #### Query Parameters - **superkey** (string) - Required - Authentication key. - **temp** (flag) - Optional - If set, config is cleared on reboot. ### Request Example apd --superkey module config set mykey "myvalue" ``` -------------------------------- ### MagiskPolicy SELinux Tool Source: https://context7.com/lyravoid/folkpatch/llms.txt Tool for loading, modifying, and applying SELinux policies. ```APIDOC ## MagiskPolicy ### Description Apply SELinux policy rules to the live kernel or compile policy files. ### Request Example magiskpolicy --live "allow untrusted_app system_file file read" ``` -------------------------------- ### Execute Supercall Kernel Operations Source: https://context7.com/lyravoid/folkpatch/llms.txt Interact with the daemon using internal Rust APIs for root management, KPM module loading, and kernel state checks. ```rust // Internal Rust API examples (apd/src/supercall.rs) // Grant root to a UID with SELinux context let profile = SuProfile { uid: 10123, to_uid: 0, scontext: convert_string_to_u8_array("u:r:magisk:s0"), }; sc_su_grant_uid(&superkey, &profile); // Revoke root from UID sc_su_revoke_uid(&superkey, 10123); // Get list of UIDs with root access let count = sc_su_uid_nums(&superkey); let mut uids = vec![0u32; count as usize]; sc_su_allow_uids(&superkey, &mut uids); // Load KPM module sc_kpm_load(&superkey, &module_path, &args); // Check safe mode status let is_safe_mode = sc_su_get_safemode(&superkey); // Reset su binary path sc_su_reset_path(&superkey, &new_path); // Set UID exclusion from module modifications sc_set_ap_mod_exclude(&superkey, uid, exclude_flag); ``` -------------------------------- ### Resetprop System Property Tool Source: https://context7.com/lyravoid/folkpatch/llms.txt Tool for reading, writing, and manipulating Android system properties. ```APIDOC ## Resetprop ### Description Manipulate Android system properties, including direct memory operations and persistent storage. ### Request Example resetprop ro.debuggable 1 ### Response #### Success Response (200) - **value** (string) - Returns property value or status. ``` -------------------------------- ### Compiler Flags with Polly Optimization Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Sets extensive compiler flags for C and C++ including Polly optimizations for performance. These flags enable aggressive optimizations and specific Polly passes. ```cmake set(CHERISH_POLLY_FLAGS "-mllvm -polly -mllvm -polly-run-dce -mllvm -polly-run-inliner -mllvm -polly-reschedule=1 -mllvm -polly-loopfusion-greedy=1 -mllvm -polly-postopts=1 -mllvm -polly-num-threads=0 -mllvm -polly-omp-backend=LLVM -mllvm -polly-scheduling=dynamic -mllvm -polly-scheduling-chunksize=1 -mllvm -polly-isl-arg=--no-schedule-serialize-sccs -mllvm -polly-ast-use-context -mllvm -polly-detect-keep-going -mllvm -polly-position=before-vectorizer -mllvm -polly-vectorizer=stripmine -mllvm -polly-detect-profitability-min-per-loop-insts=40 -mllvm -polly-invariant-load-hoisting") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CHERISH_POLLY_FLAGS} -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -flto -Wno-vla-cxx-extension -finput-charset=UTF-8 -fexec-charset=UTF-8") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CHERISH_POLLY_FLAGS} -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -fno-rtti -fno-exceptions -O3 -flto -Wno-vla-cxx-extension -finput-charset=UTF-8 -fexec-charset=UTF-8") ``` -------------------------------- ### APD CLI - Module Configuration System Source: https://context7.com/lyravoid/folkpatch/llms.txt Manage module configurations using APD. Set persistent or temporary key-value pairs, retrieve values, list entries, delete specific entries, or clear all configurations. Internal configurations for system operations are also supported. ```bash # Set a persistent config value apd --superkey module config set mykey "myvalue" ``` ```bash # Set a temporary config value (cleared on reboot) apd --superkey module config set mykey "tempvalue" --temp ``` ```bash # Get a config value (temp overrides persist) apd --superkey module config get mykey ``` ```bash # List all config entries for current module apd --superkey module config list ``` ```bash # Delete a config entry apd --superkey module config delete mykey ``` ```bash # Clear all config entries apd --superkey module config clear ``` ```bash # Use internal module config (for system operations) apd --superkey module config --internal mymodule get somekey ``` -------------------------------- ### Set C++ Standard Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Sets the C++ standard to C++23 for the project. This ensures modern C++ features are available. ```cmake set(CMAKE_CXX_STANDARD 23) ``` -------------------------------- ### CMake Option Setter Macro Source: https://github.com/lyravoid/folkpatch/blob/main/app/src/main/cpp/CMakeLists.txt Defines a macro to set CMake cache variables. Use this for internal configuration options that should not be exposed to the user. ```cmake macro(SET_OPTION option value) set(${option} ${value} CACHE INTERNAL "" FORCE) endmacro() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.