Android Hidden Api Bypass Documentation

repository·main·Indexed 25 days ago

https://github.com/lsposed/androidhiddenapibypass

A library for bypassing restrictions on non-SDK (hidden) interfaces in Android. It provides mechanisms to access internal platform APIs via HiddenApiBypass (using Unsafe) or LSPass (using Property.of()), allowing developers to invoke restricted methods, constructors, and fields, or add classes to the hidden API exemption list.

Tokens
874
Snippets
2
Records
5
Agent score
32%

What's inside Android Hidden Api Bypass

  1. Choose between HiddenApiBypass and LSPass

    main

    The library provides two variants for bypassing restrictions. They share the same API, so you can switch between them by replacing the class name.

    FeatureHiddenApiBypassLSPass
    MechanismUses UnsafeUses Property.of()
    ProsReliable, stable on Android 10+, pure JavaFaster initialization, no Unsafe usage
    ConsUses UnsafeMay be blocked by future Android releases

    Use LSPass if you want to avoid Unsafe, but use HiddenApiBypass if you require maximum reliability against future platform restrictions.

  2. Integrate Android Hidden Api Bypass into your project

    main

    To use this library, add mavenCentral() to your repositories and include the dependency in your build.gradle.

    Important: Google Play may flag the usage of hidden APIs. To prevent your app from failing app review, you must disable dependencies info reporting in your android block by setting includeInApk and includeInBundle to false.

    android {
        dependenciesInfo {
            includeInApk = false
            includeInBundle = false
        }
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:+'
    }
  3. Access restricted fields and methods via reflection

    main

    The library allows you to retrieve all methods or fields (including restricted ones) from a class to perform manual reflection.

    // Get all methods including restricted ones
    var allMethods = HiddenApiBypass.getDeclaredMethods(ApplicationInfo.class);
    ((Method).stream(allMethods).filter(e -> e.getName().equals("usesNonSdkApi")).findFirst().get()).invoke(new ApplicationInfo());
    
    // Get all non-static fields including restricted ones
    var allInstanceFields = HiddenApiBypass.getInstanceFields(ApplicationInfo.class);
    ((Method).stream(allInstanceFields).filter(e -> e.getName().equals("longVersionCode")).findFirst().get()).get(new ApplicationInfo());
    
    // Get all static fields including restricted ones
    var allStaticFields = HiddenApiBypass.getStaticFields(ApplicationInfo.class);
    ((Method).stream(allStaticFields).filter(e -> e.getName().equals("HIDDEN_API_ENFORCEMENT_DEFAULT")).findFirst().get()).get(null);
  4. Add classes to the hidden API exemption list

    main

    You can explicitly add specific classes or entire packages to the exemption list using addHiddenApiExemptions. This uses descriptor strings (e.g., Landroid/content/pm/ApplicationInfo;).

    To exempt all classes, pass an empty string to setHiddenApiExemptions("").