### Complete Root Check Implementation Source: https://context7.com/scottyab/rootbeer/llms.txt A comprehensive example showing how to run all individual root checks and report the results, including a method to perform a complete device compromise check. ```APIDOC ## Complete Root Check Implementation ### Description Provides a comprehensive implementation for performing various root checks using the RootBeer library. It includes methods to get detailed results for each check and a general method to determine if the device is rooted. ### Method N/A (This is a class implementation) ### Endpoint N/A ### Parameters None ### Request Example ```kotlin import com.scottyab.rootbeer.RootBeer import android.content.Context import android.util.Log import kotlinx.coroutines.* class RootCheckService(private val context: Context) { data class RootCheckResult( val checkName: String, val detected: Boolean ) fun performComprehensiveRootCheck(): List { val rootBeer = RootBeer(context) return listOf( RootCheckResult("Root Management Apps", rootBeer.detectRootManagementApps()), RootCheckResult("Potentially Dangerous Apps", rootBeer.detectPotentiallyDangerousApps()), RootCheckResult("Root Cloaking Apps", rootBeer.detectRootCloakingApps()), RootCheckResult("Test Keys", rootBeer.detectTestKeys()), RootCheckResult("SU Binary", rootBeer.checkForSuBinary()), RootCheckResult("SU Exists (which)", rootBeer.checkSuExists()), RootCheckResult("Magisk Binary", rootBeer.checkForMagiskBinary()), RootCheckResult("BusyBox Binary", rootBeer.checkForBusyBoxBinary()), RootCheckResult("Dangerous Props", rootBeer.checkForDangerousProps()), RootCheckResult("RW System Paths", rootBeer.checkForRWPaths()), RootCheckResult("Native Root Check", rootBeer.checkForRootNative()) ) } fun isDeviceCompromised(): Boolean { val rootBeer = RootBeer(context) return rootBeer.isRooted() } } // Usage Example in an Activity or Service: // val service = RootCheckService(applicationContext) // val results = service.performComprehensiveRootCheck() // val isRooted = results.any { it.detected } ``` ### Response #### Success Response (List or Boolean) - **performComprehensiveRootCheck()**: Returns a list of `RootCheckResult` objects, each containing the name of the check and a boolean indicating if it was detected. - **isDeviceCompromised()**: Returns `true` if the device is considered rooted, `false` otherwise. #### Response Example ```json [ { "checkName": "Root Management Apps", "detected": false }, { "checkName": "SU Binary", "detected": true } ] ``` ```kotlin // For isDeviceCompromised() val isRooted = true ``` ``` -------------------------------- ### Check for BusyBox Binary Source: https://context7.com/scottyab/rootbeer/llms.txt Detects the presence of BusyBox, a collection of Unix utilities often installed on rooted devices. Note that some manufacturers include this in stock ROMs. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean hasBusyBox = rootBeer.checkForBusyBoxBinary(); if (hasBusyBox) { Log.i("Security", "BusyBox binary detected"); } ``` -------------------------------- ### Install RootBeer Library Source: https://context7.com/scottyab/rootbeer/llms.txt Adds the RootBeer library dependency to an Android project's module-level build.gradle file. This is the first step to using the library's root detection capabilities. ```groovy // build.gradle (Module level) dependencies { implementation 'com.scottyab:rootbeer-lib:0.1.2' } ``` -------------------------------- ### Detect Root Management Apps Source: https://context7.com/scottyab/rootbeer/llms.txt Checks for the presence of known root management applications installed on the device using the PackageManager. This includes common apps like SuperSU, Magisk, and KingRoot. Custom package names can also be provided for extended detection. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Check for known root management apps boolean hasRootApps = rootBeer.detectRootManagementApps(); // Check with additional custom package names String[] customRootApps = { "com.custom.rootmanager", "com.another.suapp" }; boolean hasRootAppsExtended = rootBeer.detectRootManagementApps(customRootApps); if (hasRootApps) { Log.w("Security", "Root management app detected (SuperSU, Magisk, etc.)"); } ``` -------------------------------- ### Implement Comprehensive Root Checks Source: https://context7.com/scottyab/rootbeer/llms.txt A Kotlin implementation demonstrating how to execute multiple individual root detection checks and aggregate the results for security reporting. ```kotlin import com.scottyab.rootbeer.RootBeer class RootCheckService(private val context: Context) { data class RootCheckResult( val checkName: String, val detected: Boolean ) fun performComprehensiveRootCheck(): List { val rootBeer = RootBeer(context) return listOf( RootCheckResult("Root Management Apps", rootBeer.detectRootManagementApps()), RootCheckResult("Potentially Dangerous Apps", rootBeer.detectPotentiallyDangerousApps()), RootCheckResult("Root Cloaking Apps", rootBeer.detectRootCloakingApps()), RootCheckResult("Test Keys", rootBeer.detectTestKeys()), RootCheckResult("SU Binary", rootBeer.checkForSuBinary()), RootCheckResult("SU Exists (which)", rootBeer.checkSuExists()), RootCheckResult("Magisk Binary", rootBeer.checkForMagiskBinary()), RootCheckResult("BusyBox Binary", rootBeer.checkForBusyBoxBinary()), RootCheckResult("Dangerous Props", rootBeer.checkForDangerousProps()), RootCheckResult("RW System Paths", rootBeer.checkForRWPaths()), RootCheckResult("Native Root Check", rootBeer.checkForRootNative()) ) } fun isDeviceCompromised(): Boolean { val rootBeer = RootBeer(context) return rootBeer.isRooted() } } ``` -------------------------------- ### Perform Root Detection with BusyBox Check Source: https://github.com/scottyab/rootbeer/blob/master/README.md Shows how to perform a root check that explicitly includes the detection of the BusyBox binary, which is sometimes present on non-rooted stock ROMs. ```java rootBeer.isRootedWithBusyBoxCheck(); ``` -------------------------------- ### Detect Root Status in Android Source: https://github.com/scottyab/rootbeer/blob/master/README.md Demonstrates how to instantiate the RootBeer class and perform a basic root check. It is recommended to execute these checks on a background thread due to disk I/O operations. ```java RootBeer rootBeer = new RootBeer(context); if (rootBeer.isRooted()) { //we found indication of root } else { //we didn't find indication of root } ``` -------------------------------- ### Configure CMake Build for Native Security Library Source: https://github.com/scottyab/rootbeer/blob/master/rootbeerlib/src/main/cpp/CMakeLists.txt Sets up the build environment for the toolChecker shared library. It applies security-focused compiler flags like stack-protector-all and RELRO, and links the library against Android and log system libraries. ```cmake cmake_minimum_required(VERSION 3.4.1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,relro -Wl,-z,now") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,relro -Wl,-z,now -Wl,-z,max-page-size=16384") set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_library(toolChecker SHARED toolChecker.cpp) target_link_libraries(toolChecker android log) ``` -------------------------------- ### Check SU via Which Command Source: https://context7.com/scottyab/rootbeer/llms.txt Uses the 'which' command to locate the 'su' binary via the system PATH, serving as an alternative detection method. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Uses 'which su' command boolean suExists = rootBeer.checkSuExists(); if (suExists) { Log.w("Security", "SU found via 'which' command"); } ``` -------------------------------- ### canLoadNativeLibrary Source: https://context7.com/scottyab/rootbeer/llms.txt Verifies if the native toolChecker library can be loaded. Failure to load may indicate root cloaking apps blocking native libraries. ```APIDOC ## canLoadNativeLibrary ### Description Verifies if the native toolChecker library can be loaded. Failure to load may indicate root cloaking apps blocking native libraries. ### Method N/A (This is a method call within the library) ### Endpoint N/A ### Parameters None ### Request Example ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean canLoad = rootBeer.canLoadNativeLibrary(); ``` ### Response #### Success Response (boolean) - **true**: The native library loaded successfully. - **false**: The native library failed to load. #### Response Example ```java boolean canLoad = true; ``` ``` -------------------------------- ### Perform Basic Root Detection (isRooted) Source: https://context7.com/scottyab/rootbeer/llms.txt Checks if a device exhibits common signs of being rooted by running a comprehensive set of detection methods. It's recommended to execute this check on a background thread to avoid blocking the UI thread due to potential disk I/O operations. ```java import com.scottyab.rootbeer.RootBeer; // Basic root detection RootBeer rootBeer = new RootBeer(context); if (rootBeer.isRooted()) { // Device shows indication of root Log.w("Security", "Root detected - restricting sensitive features"); disableSensitiveFeatures(); } else { // No indication of root found (could still be cloaked) Log.i("Security", "No root indication detected"); enableAllFeatures(); } // Run from background thread (recommended) new Thread(() -> { RootBeer rootBeer = new RootBeer(getApplicationContext()); boolean isRooted = rootBeer.isRooted(); runOnUiThread(() -> { updateUIBasedOnRootStatus(isRooted); }); }).start(); ``` -------------------------------- ### Check for Read-Write Paths Source: https://context7.com/scottyab/rootbeer/llms.txt Verifies if critical system partitions are mounted as read-write, which is a common indicator of root-level modifications. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean hasRWPaths = rootBeer.checkForRWPaths(); if (hasRWPaths) { Log.w("Security", "System paths mounted as read-write"); } ``` -------------------------------- ### Verify Native Library Loading Source: https://context7.com/scottyab/rootbeer/llms.txt Checks if the native toolChecker library can be loaded. Failure to load often indicates the presence of root cloaking applications that block native library execution. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean canLoad = rootBeer.canLoadNativeLibrary(); if (!canLoad) { Log.w("Security", "Native library blocked - potential root cloaking"); } ``` -------------------------------- ### Extended Root Detection with BusyBox Check Source: https://context7.com/scottyab/rootbeer/llms.txt Performs root detection including a check for the BusyBox binary. Use this method cautiously as BusyBox can be present on non-rooted production devices from certain manufacturers (e.g., OnePlus, Moto E, OPPO), potentially leading to false positives. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Standard check (excludes busybox - recommended) boolean isRooted = rootBeer.isRooted(); // Extended check including busybox detection // Warning: May cause false positives on some devices boolean isRootedWithBusyBox = rootBeer.isRootedWithBusyBoxCheck(); if (isRootedWithBusyBox && !isRooted) { // Only busybox was detected - might be a false positive Log.i("Security", "BusyBox detected but no other root indicators"); } ``` -------------------------------- ### Check for Root via Native Library Source: https://context7.com/scottyab/rootbeer/llms.txt Performs root detection using native C/C++ code, which is generally more resistant to bypass attempts by cloaking apps. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Check if native library can be loaded first if (rootBeer.canLoadNativeLibrary()) { boolean nativeRootCheck = rootBeer.checkForRootNative(); if (nativeRootCheck) { Log.w("Security", "Native check detected root"); } } else { Log.w("Security", "Could not load native library - may indicate root cloaking"); } ``` -------------------------------- ### Check for SU Binary Source: https://context7.com/scottyab/rootbeer/llms.txt Searches for the presence of the 'su' binary in standard system directories and the PATH environment variable. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean hasSuBinary = rootBeer.checkForSuBinary(); if (hasSuBinary) { Log.w("Security", "SU binary found on device"); } ``` -------------------------------- ### Check for Magisk Binary Source: https://context7.com/scottyab/rootbeer/llms.txt Specifically targets the Magisk binary, which is commonly used for systemless root access. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean hasMagisk = rootBeer.checkForMagiskBinary(); if (hasMagisk) { Log.w("Security", "Magisk binary detected - systemless root likely present"); } ``` -------------------------------- ### Check for Generic Binary Source: https://context7.com/scottyab/rootbeer/llms.txt A flexible method to check for any specific binary file across standard root-related paths. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Check for specific binaries boolean hasSu = rootBeer.checkForBinary("su"); boolean hasDaemonsu = rootBeer.checkForBinary("daemonsu"); boolean hasCustomBinary = rootBeer.checkForBinary("customroot"); if (hasDaemonsu) { Log.w("Security", "Daemonsu binary found"); } ``` -------------------------------- ### checkForNativeLibraryReadAccess Source: https://context7.com/scottyab/rootbeer/llms.txt Checks if the app has read access to native libraries. RootCloak blocks read access while still allowing libraries to load, so this can detect cloaking. ```APIDOC ## checkForNativeLibraryReadAccess ### Description Checks if the app has read access to native libraries. RootCloak blocks read access while still allowing libraries to load, so this can detect cloaking. ### Method N/A (This is a method call within the library) ### Endpoint N/A ### Parameters None ### Request Example ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); if (rootBeer.canLoadNativeLibrary()) { boolean hasReadAccess = rootBeer.checkForNativeLibraryReadAccess(); } ``` ### Response #### Success Response (boolean) - **true**: The app has read access to native libraries. - **false**: The app does not have read access, indicating potential RootCloak. #### Response Example ```java boolean hasReadAccess = false; ``` ``` -------------------------------- ### Check for Dangerous System Properties Source: https://context7.com/scottyab/rootbeer/llms.txt Examines system properties for insecure configurations like ro.debuggable=1 or ro.secure=0. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean hasDangerousProps = rootBeer.checkForDangerousProps(); if (hasDangerousProps) { Log.w("Security", "Dangerous system properties detected"); } ``` -------------------------------- ### Root Detection API Source: https://github.com/scottyab/rootbeer/blob/master/README.md Methods for checking the root status of an Android device. ```APIDOC ## RootBeer Detection Methods ### Description Provides methods to determine if an Android device is rooted. It is recommended to run these checks on a background thread as they involve disk I/O. ### Methods - `isRooted()`: Performs standard root detection checks. - `isRootedWithBusyBoxCheck()`: Performs standard root detection including a check for the busybox binary. - `checkForBinary(String binaryName)`: Checks for the existence of a specific binary. ### Usage Example ```java RootBeer rootBeer = new RootBeer(context); if (rootBeer.isRooted()) { // Root detected } else { // No root detected } ``` ### Dependency Add the following to your `build.gradle` file: ```gradle dependencies { implementation 'com.scottyab:rootbeer-lib:0.1.2' } ``` ``` -------------------------------- ### Check Native Library Read Access Source: https://context7.com/scottyab/rootbeer/llms.txt Verifies if the application has read access to native libraries. This is useful for detecting RootCloak, which may allow libraries to load while blocking read access. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); if (rootBeer.canLoadNativeLibrary()) { boolean hasReadAccess = rootBeer.checkForNativeLibraryReadAccess(); if (!hasReadAccess) { Log.w("Security", "Native library read access blocked - RootCloak detected"); } } ``` -------------------------------- ### Include RootBeer Dependency via Gradle Source: https://github.com/scottyab/rootbeer/blob/master/README.md Configuration snippet to add the RootBeer library as a dependency in an Android project using Gradle. ```gradle dependencies { implementation 'com.scottyab:rootbeer-lib:0.1.2' } ``` -------------------------------- ### Configure Library Logging Source: https://context7.com/scottyab/rootbeer/llms.txt Enables or disables debug logging for the RootBeer library. This is intended for development environments to troubleshoot which specific checks are triggering. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Enable detailed logging (development only) rootBeer.setLogging(true); // Run checks with logging enabled boolean isRooted = rootBeer.isRooted(); // Disable logging for production rootBeer.setLogging(false); ``` -------------------------------- ### setLogging Source: https://context7.com/scottyab/rootbeer/llms.txt Enables or disables debug logging for the RootBeer library. Useful during development to see which checks are triggering. ```APIDOC ## setLogging ### Description Enables or disables debug logging for the RootBeer library. Useful during development to see which checks are triggering. ### Method N/A (This is a method call within the library) ### Endpoint N/A ### Parameters - **enable** (boolean) - Required - Set to `true` to enable logging, `false` to disable. ### Request Example ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Enable detailed logging rootBeer.setLogging(true); // Run checks boolean isRooted = rootBeer.isRooted(); // Disable logging rootBeer.setLogging(false); ``` ### Response N/A (This method does not return a value) ### Response Example N/A ``` -------------------------------- ### Detect Android Test Keys Source: https://context7.com/scottyab/rootbeer/llms.txt Checks if the device firmware is signed with test-keys, which often indicates custom ROMs or AOSP builds. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); boolean hasTestKeys = rootBeer.detectTestKeys(); if (hasTestKeys) { Log.w("Security", "Device signed with test-keys - custom/AOSP firmware detected"); } ``` -------------------------------- ### Detect Root Cloaking Apps Source: https://context7.com/scottyab/rootbeer/llms.txt Identifies apps like RootCloak or Xposed that hide root status. It can accept an optional array of custom package names to check against. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Check for root cloaking apps boolean hasCloakingApps = rootBeer.detectRootCloakingApps(); // Check with additional cloaking package names String[] additionalCloakingApps = { "com.custom.hider", "org.xposed.custommod" }; boolean hasCloakingAppsExtended = rootBeer.detectRootCloakingApps(additionalCloakingApps); if (hasCloakingApps) { Log.w("Security", "Root cloaking detected - device may be hiding root status"); } ``` -------------------------------- ### Detect Potentially Dangerous Apps Source: https://context7.com/scottyab/rootbeer/llms.txt Identifies applications that are often associated with device tampering or require root access, such as Lucky Patcher, ROM managers, and game cheating tools. Additional custom package names can be supplied for a broader check. ```java import com.scottyab.rootbeer.RootBeer; RootBeer rootBeer = new RootBeer(context); // Check for dangerous apps boolean hasDangerousApps = rootBeer.detectPotentiallyDangerousApps(); // Check with additional package names String[] additionalDangerousApps = { "com.suspicious.billing.hack", "org.piracy.market" }; boolean hasDangerousAppsExtended = rootBeer.detectPotentiallyDangerousApps(additionalDangerousApps); if (hasDangerousApps) { Log.w("Security", "Potentially dangerous app detected (Lucky Patcher, piracy tools, etc.)"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.