• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AndroidHiddenApiBypass
2
3[![Android CI status](https://github.com/LSPosed/AndroidHiddenApiBypass/actions/workflows/android.yml/badge.svg?branch=main)](https://github.com/LSPosed/AndroidHiddenApiBypass/actions/workflows/android.yml)
4
5Bypass restrictions on non-SDK interfaces.
6
7## Why AndroidHiddenApiBypass?
8
9- Pure Java: no native code used.
10- Reliable: does not rely on specific behaviors, so it will not be blocked like meta-reflection or `dexfile`.
11- Stable: `unsafe`, art structs and `setHiddenApiExemptions` are stable APIs.
12
13[How it works (Chinese)](https://lovesykun.cn/archives/android-hidden-api-bypass.html)
14
15## Integration
16
17Gradle:
18
19```gradle
20repositories {
21    mavenCentral()
22}
23dependencies {
24    implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'
25}
26```
27
28## Usage
29
301. Invoke a restricted method:
31    ```java
32    HiddenApiBypass.invoke(ApplicationInfo.class, new ApplicationInfo(), "usesNonSdkApi"/*, args*/)
33    ```
341. Invoke restricted constructor:
35    ```java
36    Object instance = HiddenApiBypass.newInstance(Class.forName("android.app.IActivityManager$Default")/*, args*/);
37    ```
381. Get all methods including restricted ones from a class:
39    ```java
40    var allMethods = HiddenApiBypass.getDeclaredMethods(ApplicationInfo.class);
41    ((Method).stream(allMethods).filter(e -> e.getName().equals("usesNonSdkApi")).findFirst().get()).invoke(new ApplicationInfo());
42    ```
431. Get all non-static fields including restricted ones from a class:
44    ```java
45    var allInstanceFields = HiddenApiBypass.getInstanceFields(ApplicationInfo.class);
46    ((Method).stream(allInstanceFields).filter(e -> e.getName().equals("longVersionCode")).findFirst().get()).get(new ApplicationInfo());
47    ```
481. Get all static fields including restricted ones from a class:
49    ```java
50    var allStaticFields = HiddenApiBypass.getStaticFields(ApplicationInfo.class);
51    ((Method).stream(allInstanceFields).filter(e -> e.getName().equals("HIDDEN_API_ENFORCEMENT_DEFAULT")).findFirst().get()).get(null);
52    ```
531. Get specific class method or class constructor
54    ```java
55    var ctor = HiddenApiBypass.getDeclaredConstructor(ClipDrawable.class /*, args */);
56    var method = HiddenApiBypass.getDeclaredMethod(ApplicationInfo.class, "getHiddenApiEnforcementPolicy" /*, args */);
57    ```
581. Add a class to exemption list:
59    ```java
60    HiddenApiBypass.addHiddenApiExemptions(
61        "Landroid/content/pm/ApplicationInfo;", // one specific class
62        "Ldalvik/system" // all classes in packages dalvik.system
63        "Lx" // all classes whose full name is started with x
64    );
65    ```
66    if you are going to add all classes to exemption list, just leave an empty prefix:
67    ```java
68    HiddenApiBypass.addHiddenApiExemptions("");
69    ```
70## License
71
72    Copyright 2021 LSPosed
73
74    Licensed under the Apache License, Version 2.0 (the "License");
75    you may not use this file except in compliance with the License.
76    You may obtain a copy of the License at
77
78        https://www.apache.org/licenses/LICENSE-2.0
79
80    Unless required by applicable law or agreed to in writing, software
81    distributed under the License is distributed on an "AS IS" BASIS,
82    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
83    See the License for the specific language governing permissions and
84    limitations under the License.
85