├── .gitattributes ├── .github ├── cuttlefish.sh └── workflows │ ├── android.yml │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle.kts ├── consumer-rules.pro └── src │ ├── androidTest │ ├── AndroidManifest.xml │ └── java │ │ └── org │ │ └── lsposed │ │ └── hiddenapibypass │ │ ├── HiddenApiBypassTest.java │ │ └── LSPassTest.java │ └── main │ ├── AndroidManifest.xml │ └── java │ └── org │ └── lsposed │ └── hiddenapibypass │ ├── CoreOjClassLoader.java │ ├── Helper.java │ ├── HiddenApiBypass.java │ └── LSPass.java ├── settings.gradle.kts └── stub ├── .gitignore ├── build.gradle.kts └── src └── main ├── AndroidManifest.xml └── java └── stub ├── dalvik └── system │ └── VMRuntime.java └── sun └── misc └── Unsafe.java /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.bat text eol=crlf 4 | *.jar binary 5 | -------------------------------------------------------------------------------- /.github/cuttlefish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -xe 4 | export PATH="$PATH:$ANDROID_HOME/platform-tools" 5 | sdk="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" 6 | cvd_args="-daemon -enable_sandbox=false -memory_mb=8192 -report_anonymous_usage_stats=n" 7 | 8 | cleanup() { 9 | print_error "! An error occurred" 10 | run_cvd_bin stop_cvd || true 11 | } 12 | 13 | run_cvd_bin() { 14 | local exe=$1 15 | shift 16 | HOME=$CF_HOME $CF_HOME/bin/$exe "$@" 17 | } 18 | 19 | setup_env() { 20 | curl -LO https://github.com/user-attachments/files/18728876/cuttlefish-base_1.2.0_amd64.zip 21 | sudo dpkg -i ./cuttlefish-base_*_*64.zip || sudo apt-get install -f 22 | rm cuttlefish-base_*_*64.zip 23 | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules 24 | sudo udevadm control --reload-rules 25 | sudo udevadm trigger 26 | sudo usermod -aG kvm,cvdnetwork,render $USER 27 | yes | "$sdk" --licenses > /dev/null 28 | "$sdk" --channel=3 platform-tools 29 | } 30 | 31 | download_cf() { 32 | local branch=$1 33 | local device=$2 34 | 35 | if [ -z $branch ]; then 36 | branch='aosp-main' 37 | fi 38 | if [ -z $device ]; then 39 | device='aosp_cf_x86_64_phone' 40 | fi 41 | local target="${device}-trunk_staging-userdebug" 42 | 43 | local build_id=$(curl -sL https://ci.android.com/builds/branches/${branch}/status.json | \ 44 | jq -r ".targets[] | select(.name == \"$target\") | .last_known_good_build") 45 | local sys_img_url="https://ci.android.com/builds/submitted/${build_id}/${target}/latest/raw/${device}-img-${build_id}.zip" 46 | local host_pkg_url="https://ci.android.com/builds/submitted/${build_id}/${target}/latest/raw/cvd-host_package.tar.gz" 47 | 48 | curl -L $sys_img_url -o aosp_cf_phone-img.zip 49 | curl -LO $host_pkg_url 50 | rm -rf $CF_HOME 51 | mkdir -p $CF_HOME 52 | tar xvf cvd-host_package.tar.gz -C $CF_HOME 53 | unzip aosp_cf_phone-img.zip -d $CF_HOME 54 | rm -f cvd-host_package.tar.gz aosp_cf_phone-img.zip 55 | } 56 | 57 | 58 | test_main() { 59 | run_cvd_bin launch_cvd $cvd_args 60 | adb wait-for-device 61 | ./gradlew connectedCheck 62 | run_cvd_bin stop_cvd || true 63 | } 64 | 65 | if [ -z $CF_HOME ]; then 66 | print_error "! Environment variable CF_HOME is required" 67 | exit 1 68 | fi 69 | 70 | case "$1" in 71 | setup ) 72 | setup_env 73 | ;; 74 | download ) 75 | download_cf $2 $3 76 | ;; 77 | test ) 78 | trap cleanup EXIT 79 | export -f run_cvd_bin 80 | test_main 81 | trap - EXIT 82 | ;; 83 | * ) 84 | exit 1 85 | ;; 86 | esac 87 | -------------------------------------------------------------------------------- /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - 'main' 8 | 9 | jobs: 10 | build: 11 | name: Build on ${{ matrix.os }} 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | os: [ ubuntu-latest, windows-latest, macOS-latest ] 17 | 18 | steps: 19 | - name: Check out 20 | uses: actions/checkout@v4 21 | - name: Set up JDK 21 22 | uses: actions/setup-java@v4 23 | with: 24 | distribution: 'temurin' 25 | java-version: '21' 26 | - name: Setup Gradle 27 | uses: gradle/actions/setup-gradle@v4 28 | - name: Build with Gradle 29 | run: | 30 | echo 'org.gradle.caching=true' >> gradle.properties 31 | echo 'org.gradle.parallel=true' >> gradle.properties 32 | echo 'org.gradle.jvmargs=-Xmx2048m' >> gradle.properties 33 | ./gradlew publishToMavenLocal 34 | env: 35 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.maven_pgp_signingKey }} 36 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.maven_pgp_signingPassword }} 37 | - name: Upload library 38 | uses: actions/upload-artifact@v4 39 | with: 40 | name: ${{ matrix.os }}-library 41 | path: ~/.m2 42 | include-hidden-files: true 43 | 44 | test: 45 | name: Test on API ${{ matrix.api-level }} ${{ matrix.arch }} 46 | needs: build 47 | runs-on: ubuntu-latest 48 | strategy: 49 | fail-fast: false 50 | matrix: 51 | include: 52 | - api-level: 28 53 | target: default 54 | arch: x86_64 55 | - api-level: 28 56 | target: default 57 | arch: x86 58 | - api-level: 29 59 | target: default 60 | arch: x86_64 61 | - api-level: 29 62 | target: default 63 | arch: x86 64 | - api-level: 30 65 | target: aosp_atd 66 | arch: x86_64 67 | - api-level: 30 68 | target: google_apis 69 | arch: x86 70 | - api-level: 31 71 | target: aosp_atd 72 | arch: x86_64 73 | - api-level: 31 74 | target: android-tv 75 | arch: x86 76 | - api-level: 32 77 | target: aosp_atd 78 | arch: x86_64 79 | - api-level: 33 80 | target: aosp_atd 81 | arch: x86_64 82 | - api-level: 33 83 | target: android-tv 84 | arch: x86 85 | - api-level: 34 86 | target: aosp_atd 87 | arch: x86_64 88 | - api-level: 35 89 | target: aosp_atd 90 | arch: x86_64 91 | - api-level: Baklava 92 | target: google_apis 93 | arch: x86_64 94 | steps: 95 | - name: checkout 96 | uses: actions/checkout@v4 97 | - name: Set up JDK 21 98 | uses: actions/setup-java@v4 99 | with: 100 | distribution: 'temurin' 101 | java-version: '21' 102 | - name: Setup Gradle 103 | uses: gradle/actions/setup-gradle@v4 104 | - name: Enable KVM group perms 105 | run: | 106 | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules 107 | sudo udevadm control --reload-rules 108 | sudo udevadm trigger --name-match=kvm 109 | - name: run tests 110 | uses: reactivecircus/android-emulator-runner@b683a061eaff4aac4d0b585bfd0cf714a40aee93 111 | with: 112 | api-level: ${{ matrix.api-level }} 113 | arch: ${{ matrix.arch }} 114 | target: ${{ matrix.target }} 115 | script: ./gradlew connectedCheck 116 | force-avd-creation: false 117 | emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none 118 | disable-animations: true 119 | 120 | cf-test: 121 | name: Test ${{ matrix.device }} 122 | runs-on: ubuntu-24.04 123 | needs: build 124 | env: 125 | CF_HOME: /home/runner/aosp_cf_phone 126 | strategy: 127 | fail-fast: false 128 | matrix: 129 | include: 130 | - branch: "aosp-main" 131 | device: "aosp_cf_x86_64_phone" 132 | 133 | steps: 134 | - name: Check out 135 | uses: actions/checkout@v4 136 | - name: Set up JDK 21 137 | uses: actions/setup-java@v4 138 | with: 139 | distribution: 'temurin' 140 | java-version: '21' 141 | - name: Setup Cuttlefish environment 142 | run: | 143 | .github/cuttlefish.sh setup 144 | .github/cuttlefish.sh download ${{ matrix.branch }} ${{ matrix.device }} 145 | - name: Run Cuttlefish test 146 | timeout-minutes: 10 147 | run: su $USER -c '.github/cuttlefish.sh test' 148 | - name: Upload logs on error 149 | if: ${{ failure() }} 150 | uses: actions/upload-artifact@v4 151 | with: 152 | name: "cvd-logs-${{ matrix.device }}" 153 | path: | 154 | /home/runner/aosp_cf_phone/cuttlefish/instances/cvd-1/logs 155 | /home/runner/aosp_cf_phone/cuttlefish/instances/cvd-1/cuttlefish_config.json 156 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Maven 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | name: Build 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Check out 12 | uses: actions/checkout@v4 13 | with: 14 | submodules: 'recursive' 15 | fetch-depth: 0 16 | - name: Set up JDK 21 17 | uses: actions/setup-java@v4 18 | with: 19 | distribution: 'temurin' 20 | java-version: '21' 21 | - name: Build with Gradle 22 | run: ./gradlew publish 23 | env: 24 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.maven_pgp_signingKey }} 25 | ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.maven_pgp_signingPassword }} 26 | ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.maven_ossrhUsername }} 27 | ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.maven_ossrhPassword }} 28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Hidden Api Bypass 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 | ![](https://img.shields.io/badge/Android-1.0%20--%2016-blue.svg) 5 | ![](https://img.shields.io/maven-central/v/org.lsposed.hiddenapibypass/hiddenapibypass.svg) 6 | 7 | Bypass restrictions on non-SDK interfaces. 8 | 9 | ## Why HiddenApiBypass? 10 | 11 | - Pure Java: no native code used. 12 | - Reliable: does not rely on specific behaviors, so it will not be blocked like meta-reflection or `dexfile`. 13 | - Stable: does not rely on internal ART structures on Android 10+. `Unsafe` and `setHiddenApiExemptions` are stable APIs. 14 | 15 | ## And LSPass? 16 | 17 | - Fast: no I/O, initializing faster than HiddenApiBypass. 18 | - Safe: no `Unsafe`. 19 | - Unreliable: can be blocked as easily as meta-reflection. 20 | 21 | ## How it works 22 | 23 | HiddenApiBypass: [Unsafe](https://lovesykun.cn/archives/android-hidden-api-bypass.html) 24 | 25 | LSPass: [Property.of()](https://github.com/michalbednarski/LeakValue?tab=readme-ov-file#putting-it-all-together) 26 | 27 | ## Integration 28 | 29 | Gradle: 30 | 31 | ```gradle 32 | repositories { 33 | mavenCentral() 34 | } 35 | dependencies { 36 | implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:+' 37 | } 38 | ``` 39 | 40 | ## Usage 41 | 42 | This library has two variants of bypassing, they have the same API. 43 | When initializing, LSPass is faster than HiddenApiBypass, but LSPass maybe blocked in future Android releases. 44 | Replace `HiddenApiBypass` with `LSPass` if you do not want to use `Unsafe`. 45 | 46 | 1. Invoke a restricted method: 47 | ```java 48 | HiddenApiBypass.invoke(ApplicationInfo.class, new ApplicationInfo(), "usesNonSdkApi"/*, args*/) 49 | ``` 50 | 1. Invoke restricted constructor: 51 | ```java 52 | Object instance = HiddenApiBypass.newInstance(Class.forName("android.app.IActivityManager$Default")/*, args*/); 53 | ``` 54 | 1. Get all methods including restricted ones from a class: 55 | ```java 56 | var allMethods = HiddenApiBypass.getDeclaredMethods(ApplicationInfo.class); 57 | ((Method).stream(allMethods).filter(e -> e.getName().equals("usesNonSdkApi")).findFirst().get()).invoke(new ApplicationInfo()); 58 | ``` 59 | 1. Get all non-static fields including restricted ones from a class: 60 | ```java 61 | var allInstanceFields = HiddenApiBypass.getInstanceFields(ApplicationInfo.class); 62 | ((Method).stream(allInstanceFields).filter(e -> e.getName().equals("longVersionCode")).findFirst().get()).get(new ApplicationInfo()); 63 | ``` 64 | 1. Get all static fields including restricted ones from a class: 65 | ```java 66 | var allStaticFields = HiddenApiBypass.getStaticFields(ApplicationInfo.class); 67 | ((Method).stream(allStaticFields).filter(e -> e.getName().equals("HIDDEN_API_ENFORCEMENT_DEFAULT")).findFirst().get()).get(null); 68 | ``` 69 | 1. Get specific class method or class constructor 70 | ```java 71 | var ctor = HiddenApiBypass.getDeclaredConstructor(ClipDrawable.class /*, args */); 72 | var method = HiddenApiBypass.getDeclaredMethod(ApplicationInfo.class, "getHiddenApiEnforcementPolicy" /*, args */); 73 | ``` 74 | 1. Add a class to exemption list: 75 | ```java 76 | HiddenApiBypass.addHiddenApiExemptions( 77 | "Landroid/content/pm/ApplicationInfo;", // one specific class 78 | "Ldalvik/system" // all classes in packages dalvik.system 79 | "Lx" // all classes whose full name is started with x 80 | ); 81 | ``` 82 | if you are going to add all classes to exemption list, just leave an empty prefix: 83 | ```java 84 | HiddenApiBypass.addHiddenApiExemptions(""); 85 | ``` 86 | ## License 87 | 88 | Copyright 2021-2025 LSPosed 89 | 90 | Licensed under the Apache License, Version 2.0 (the "License"); 91 | you may not use this file except in compliance with the License. 92 | You may obtain a copy of the License at 93 | 94 | https://www.apache.org/licenses/LICENSE-2.0 95 | 96 | Unless required by applicable law or agreed to in writing, software 97 | distributed under the License is distributed on an "AS IS" BASIS, 98 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 99 | See the License for the specific language governing permissions and 100 | limitations under the License. 101 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.lsplugin.publish) 3 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | android.useAndroidX=true 2 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | [libraries] 3 | androidx-annotation = { module = "androidx.annotation:annotation", version= "1.9.1" } 4 | test-ext-junit = { module = "androidx.test.ext:junit", version = "1.2.1" } 5 | test-rules = { module = "androidx.test:rules", version = "1.6.1" } 6 | 7 | [plugins] 8 | agp-lib = { id = "com.android.library", version = "8.8.0" } 9 | lsplugin-jgit = { id = "org.lsposed.lsplugin.jgit", version = "1.1" } 10 | lsplugin-publish = { id = "org.lsposed.lsplugin.publish", version = "1.1" } 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LSPosed/AndroidHiddenApiBypass/71aaad4ce558530b4788da67d0e3d9bb3596e9d3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | org.gradle.wrapper.GradleWrapperMain \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.android.build.api.artifact.SingleArtifact 2 | import com.android.build.api.instrumentation.AsmClassVisitorFactory 3 | import com.android.build.api.instrumentation.ClassContext 4 | import com.android.build.api.instrumentation.ClassData 5 | import com.android.build.api.instrumentation.InstrumentationParameters 6 | import com.android.build.api.instrumentation.InstrumentationScope 7 | import org.objectweb.asm.ClassVisitor 8 | import org.objectweb.asm.commons.ClassRemapper 9 | import org.objectweb.asm.commons.Remapper 10 | 11 | plugins { 12 | alias(libs.plugins.agp.lib) 13 | alias(libs.plugins.lsplugin.jgit) 14 | alias(libs.plugins.lsplugin.publish) 15 | `maven-publish` 16 | signing 17 | } 18 | 19 | android { 20 | compileSdk = 35 21 | buildToolsVersion = "35.0.1" 22 | namespace = "org.lsposed.hiddenapibypass.library" 23 | 24 | buildFeatures { 25 | androidResources = false 26 | buildConfig = true 27 | } 28 | defaultConfig { 29 | minSdk = 1 30 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 31 | } 32 | testOptions { 33 | targetSdk = 35 34 | } 35 | buildTypes { 36 | release { 37 | consumerProguardFiles("consumer-rules.pro") 38 | } 39 | } 40 | compileOptions { 41 | sourceCompatibility = JavaVersion.VERSION_11 42 | targetCompatibility = JavaVersion.VERSION_11 43 | } 44 | packaging { 45 | resources { 46 | excludes += "/META-INF/**" 47 | excludes += "/*.properties" 48 | } 49 | } 50 | publishing { 51 | singleVariant("release") { 52 | withSourcesJar() 53 | withJavadocJar() 54 | } 55 | } 56 | } 57 | 58 | dependencies { 59 | compileOnly(projects.stub) 60 | compileOnly(libs.androidx.annotation) 61 | androidTestImplementation(libs.test.ext.junit) 62 | androidTestImplementation(libs.test.rules) 63 | androidTestCompileOnly(projects.stub) 64 | } 65 | 66 | androidComponents.onVariants { variant -> 67 | variant.instrumentation.transformClassesWith( 68 | ClassVisitorFactory::class.java, InstrumentationScope.PROJECT 69 | ) {} 70 | } 71 | 72 | abstract class ClassVisitorFactory : AsmClassVisitorFactory { 73 | override fun createClassVisitor( 74 | classContext: ClassContext, 75 | nextClassVisitor: ClassVisitor 76 | ): ClassVisitor { 77 | return ClassRemapper(nextClassVisitor, object : Remapper() { 78 | override fun map(name: String): String { 79 | if (name.startsWith("stub/")) { 80 | return name.substring(name.indexOf('/') + 1) 81 | } 82 | return name 83 | } 84 | }) 85 | } 86 | 87 | override fun isInstrumentable(classData: ClassData): Boolean { 88 | return classData.className.endsWith("ass") 89 | } 90 | } 91 | 92 | @CacheableTask 93 | abstract class ManifestUpdater : DefaultTask() { 94 | @get:InputFile 95 | @get:PathSensitive(PathSensitivity.RELATIVE) 96 | abstract val mergedManifest: RegularFileProperty 97 | 98 | @get:OutputFile 99 | abstract val outputManifest: RegularFileProperty 100 | 101 | @TaskAction 102 | fun taskAction() { 103 | outputManifest.get().asFile.writeText( 104 | mergedManifest.get().asFile.readText() 105 | .replace(" 112 | val variantName = variant.name 113 | val manifestUpdater = 114 | project.tasks.register("${variantName}ManifestUpdater", ManifestUpdater::class.java) 115 | variant.artifacts.use(manifestUpdater) 116 | .wiredWithFiles( 117 | ManifestUpdater::mergedManifest, 118 | ManifestUpdater::outputManifest 119 | ) 120 | .toTransform(SingleArtifact.MERGED_MANIFEST) 121 | } 122 | 123 | 124 | val repo = jgit.repo(true) 125 | version = repo?.latestTag?.removePrefix("v") ?: "0.0" 126 | println("${rootProject.name} version: $version") 127 | 128 | publish { 129 | githubRepo = "LSPosed/AndroidHiddenApiBypass" 130 | publications { 131 | register("hiddenapibypass") { 132 | group = "org.lsposed.hiddenapibypass" 133 | artifactId = "hiddenapibypass" 134 | version = version 135 | afterEvaluate { 136 | from(components.getByName("release")) 137 | } 138 | pom { 139 | name = "Android Hidden Api Bypass" 140 | description = "Bypass restrictions on non-SDK interfaces" 141 | url = "https://github.com/LSPosed/AndroidHiddenApiBypass" 142 | licenses { 143 | license { 144 | name = "The Apache Software License, Version 2.0" 145 | url = "http://www.apache.org/licenses/LICENSE-2.0.txt" 146 | } 147 | } 148 | developers { 149 | developer { 150 | name = "LSPosed" 151 | url = "https://lsposed.org" 152 | } 153 | } 154 | scm { 155 | connection = "scm:git:https://github.com/LSPosed/AndroidHiddenApiBypass.git" 156 | url = "https://github.com/LSPosed/AndroidHiddenApiBypass" 157 | } 158 | } 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /library/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -dontwarn dalvik.system.VMRuntime 2 | 3 | -if class org.lsposed.hiddenapibypass.HiddenApiBypass 4 | -keepclassmembers class org.lsposed.hiddenapibypass.Helper$* { *; } 5 | 6 | -assumenosideeffects class android.util.Property{ 7 | public static *** of(...); 8 | } 9 | -------------------------------------------------------------------------------- /library/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /library/src/androidTest/java/org/lsposed/hiddenapibypass/HiddenApiBypassTest.java: -------------------------------------------------------------------------------- 1 | package org.lsposed.hiddenapibypass; 2 | 3 | import static org.hamcrest.core.StringContains.containsString; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertNotEquals; 6 | import static org.junit.Assert.assertSame; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | import android.content.pm.ApplicationInfo; 10 | import android.graphics.drawable.ClipDrawable; 11 | import android.os.Build; 12 | 13 | import androidx.test.ext.junit.runners.AndroidJUnit4; 14 | import androidx.test.filters.SdkSuppress; 15 | 16 | import org.junit.FixMethodOrder; 17 | import org.junit.Rule; 18 | import org.junit.Test; 19 | import org.junit.rules.ExpectedException; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.MethodSorters; 22 | 23 | import java.lang.reflect.Executable; 24 | import java.lang.reflect.InvocationTargetException; 25 | import java.util.List; 26 | import java.util.Optional; 27 | 28 | @SuppressWarnings("JavaReflectionMemberAccess") 29 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 30 | @SdkSuppress(minSdkVersion = Build.VERSION_CODES.P) 31 | @RunWith(AndroidJUnit4.class) 32 | public class HiddenApiBypassTest { 33 | 34 | private final Class runtime = Class.forName("dalvik.system.VMRuntime"); 35 | 36 | @Rule 37 | public ExpectedException exception = ExpectedException.none(); 38 | 39 | public HiddenApiBypassTest() throws ClassNotFoundException { 40 | } 41 | 42 | @Test 43 | public void AgetDeclaredMethods() { 44 | List methods = HiddenApiBypass.getDeclaredMethods(runtime); 45 | Optional getRuntime = methods.stream().filter(it -> it.getName().equals("getRuntime")).findFirst(); 46 | assertTrue(getRuntime.isPresent()); 47 | Optional setHiddenApiExemptions = methods.stream().filter(it -> it.getName().equals("setHiddenApiExemptions")).findFirst(); 48 | assertTrue(setHiddenApiExemptions.isPresent()); 49 | } 50 | 51 | @Test(expected = NoSuchMethodException.class) 52 | public void BusesNonSdkApiIsHiddenApi() throws NoSuchMethodException { 53 | ApplicationInfo.class.getMethod("getHiddenApiEnforcementPolicy"); 54 | } 55 | 56 | @Test(expected = NoSuchMethodException.class) 57 | public void CsetHiddenApiExemptionsIsHiddenApi() throws NoSuchMethodException { 58 | runtime.getMethod("setHiddenApiExemptions", String[].class); 59 | } 60 | 61 | @Test(expected = NoSuchMethodException.class) 62 | public void DnewClipDrawableIsHiddenApi() throws NoSuchMethodException { 63 | ClipDrawable.class.getDeclaredConstructor(); 64 | } 65 | 66 | @Test(expected = NoSuchFieldException.class) 67 | public void ElongVersionCodeIsHiddenApi() throws NoSuchFieldException { 68 | ApplicationInfo.class.getDeclaredField("longVersionCode"); 69 | } 70 | 71 | @Test(expected = NoSuchFieldException.class) 72 | public void FHiddenApiEnforcementDefaultIsHiddenApi() throws NoSuchFieldException { 73 | ApplicationInfo.class.getDeclaredField("HIDDEN_API_ENFORCEMENT_DEFAULT"); 74 | } 75 | 76 | @Test 77 | public void GtestGetInstanceFields() { 78 | assertTrue(HiddenApiBypass.getInstanceFields(ApplicationInfo.class).stream().anyMatch(i -> i.getName().equals("longVersionCode"))); 79 | } 80 | 81 | @Test 82 | public void HtestGetStaticFields() { 83 | assertTrue(HiddenApiBypass.getStaticFields(ApplicationInfo.class).stream().anyMatch(i -> i.getName().equals("HIDDEN_API_ENFORCEMENT_DEFAULT"))); 84 | } 85 | 86 | @Test 87 | public void IinvokeNonSdkApiWithoutExemption() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { 88 | assertNotEquals(HiddenApiBypass.getDeclaredMethod(ApplicationInfo.class, "getHiddenApiEnforcementPolicy"), null); 89 | HiddenApiBypass.invoke(ApplicationInfo.class, new ApplicationInfo(), "getHiddenApiEnforcementPolicy"); 90 | } 91 | 92 | @Test 93 | public void JnewClipDrawableWithoutExemption() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { 94 | assertNotEquals(HiddenApiBypass.getDeclaredConstructor(ClipDrawable.class), null); 95 | Object instance = HiddenApiBypass.newInstance(ClipDrawable.class); 96 | assertSame(instance.getClass(), ClipDrawable.class); 97 | } 98 | 99 | @Test 100 | public void KgetAllMethodsWithoutExemption() { 101 | assertTrue(HiddenApiBypass.getDeclaredMethods(ApplicationInfo.class).stream().anyMatch(e -> e.getName().equals("getHiddenApiEnforcementPolicy"))); 102 | } 103 | 104 | @Test 105 | public void LsetHiddenApiExemptions() throws NoSuchMethodException, NoSuchFieldException { 106 | assertTrue(HiddenApiBypass.setHiddenApiExemptions("Landroid/content/pm/ApplicationInfo;")); 107 | ApplicationInfo.class.getMethod("getHiddenApiEnforcementPolicy"); 108 | ApplicationInfo.class.getDeclaredField("longVersionCode"); 109 | ApplicationInfo.class.getDeclaredField("HIDDEN_API_ENFORCEMENT_DEFAULT"); 110 | } 111 | 112 | @Test 113 | public void MclearHiddenApiExemptions() throws NoSuchMethodException { 114 | exception.expect(NoSuchMethodException.class); 115 | exception.expectMessage(containsString("setHiddenApiExemptions")); 116 | assertTrue(HiddenApiBypass.setHiddenApiExemptions("L")); 117 | ApplicationInfo.class.getMethod("getHiddenApiEnforcementPolicy"); 118 | assertTrue(HiddenApiBypass.clearHiddenApiExemptions()); 119 | runtime.getMethod("setHiddenApiExemptions", String[].class); 120 | } 121 | 122 | @Test 123 | public void NaddHiddenApiExemptionsTest() throws NoSuchMethodException { 124 | assertTrue(HiddenApiBypass.addHiddenApiExemptions("Landroid/content/pm/ApplicationInfo;")); 125 | ApplicationInfo.class.getMethod("getHiddenApiEnforcementPolicy"); 126 | assertTrue(HiddenApiBypass.addHiddenApiExemptions("Ldalvik/system/VMRuntime;")); 127 | runtime.getMethod("setHiddenApiExemptions", String[].class); 128 | } 129 | 130 | @Test 131 | public void OtestCheckArgsForInvokeMethod() { 132 | class X { 133 | } 134 | assertFalse(Helper.checkArgsForInvokeMethod(new Class[]{}, new Object[]{new Object()})); 135 | assertTrue(Helper.checkArgsForInvokeMethod(new Class[]{int.class}, new Object[]{1})); 136 | assertFalse(Helper.checkArgsForInvokeMethod(new Class[]{int.class}, new Object[]{1.0})); 137 | assertFalse(Helper.checkArgsForInvokeMethod(new Class[]{int.class}, new Object[]{null})); 138 | assertTrue(Helper.checkArgsForInvokeMethod(new Class[]{Integer.class}, new Object[]{1})); 139 | assertTrue(Helper.checkArgsForInvokeMethod(new Class[]{Integer.class}, new Object[]{null})); 140 | assertTrue(Helper.checkArgsForInvokeMethod(new Class[]{Object.class}, new Object[]{new X()})); 141 | assertFalse(Helper.checkArgsForInvokeMethod(new Class[]{X.class}, new Object[]{new Object()})); 142 | assertTrue(Helper.checkArgsForInvokeMethod(new Class[]{Object.class, int.class, byte.class, short.class, char.class, double.class, float.class, boolean.class, long.class}, new Object[]{new X(), 1, (byte) 0, (short) 2, 'c', 1.1, 1.2f, false, 114514L})); 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /library/src/androidTest/java/org/lsposed/hiddenapibypass/LSPassTest.java: -------------------------------------------------------------------------------- 1 | package org.lsposed.hiddenapibypass; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotEquals; 5 | import static org.junit.Assert.assertNotNull; 6 | import static org.junit.Assert.assertSame; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | import android.app.ActivityOptions; 10 | import android.os.Build; 11 | 12 | import androidx.test.ext.junit.runners.AndroidJUnit4; 13 | import androidx.test.filters.SdkSuppress; 14 | 15 | import org.junit.FixMethodOrder; 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | import org.junit.runners.MethodSorters; 19 | 20 | import java.lang.reflect.InvocationTargetException; 21 | 22 | @SuppressWarnings("JavaReflectionMemberAccess") 23 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 24 | @SdkSuppress(minSdkVersion = Build.VERSION_CODES.P) 25 | @RunWith(AndroidJUnit4.class) 26 | public class LSPassTest { 27 | 28 | @Test(expected = NoSuchMethodException.class) 29 | public void AnewActivityOptionsIsHiddenApi() throws NoSuchMethodException { 30 | ActivityOptions.class.getDeclaredConstructor(); 31 | } 32 | 33 | @Test(expected = NoSuchMethodException.class) 34 | public void BgetHeightIsHiddenApi() throws NoSuchMethodException { 35 | ActivityOptions.class.getDeclaredMethod("getHeight"); 36 | } 37 | 38 | @Test(expected = NoSuchFieldException.class) 39 | public void CmHeightIsHiddenApi() throws NoSuchFieldException { 40 | ActivityOptions.class.getDeclaredField("mHeight"); 41 | } 42 | 43 | @Test 44 | public void DgetDeclaredFieldsTest() { 45 | var fields = LSPass.getDeclaredFields(ActivityOptions.class); 46 | assertTrue(fields.stream().anyMatch(i -> i.getName().equals("mHeight"))); 47 | var instance = LSPass.getInstanceFields(ActivityOptions.class); 48 | assertTrue(instance.stream().anyMatch(i -> i.getName().equals("mHeight"))); 49 | var staticFields = LSPass.getStaticFields(ActivityOptions.class); 50 | assertTrue(staticFields.stream().anyMatch(i -> i.getName().equals("ANIM_NONE"))); 51 | assertEquals(fields.size(), instance.size() + staticFields.size()); 52 | } 53 | 54 | @Test 55 | public void EgetDeclaredMethodTest() throws NoSuchMethodException { 56 | assertNotNull(LSPass.getDeclaredMethod(ActivityOptions.class, "getHeight")); 57 | } 58 | 59 | @Test 60 | public void FnewActivityOptionsWithoutExemption() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException { 61 | assertNotEquals(null, LSPass.getDeclaredConstructor(ActivityOptions.class)); 62 | Object instance = LSPass.newInstance(ActivityOptions.class); 63 | assertSame(ActivityOptions.class, instance.getClass()); 64 | } 65 | 66 | @Test(expected = NoSuchFieldException.class) 67 | public void GclearHiddenApiExemptionsTest() throws NoSuchFieldException { 68 | assertTrue(LSPass.addHiddenApiExemptions("L")); 69 | assertTrue(LSPass.clearHiddenApiExemptions()); 70 | ActivityOptions.class.getDeclaredField("mHeight"); 71 | } 72 | 73 | @Test 74 | public void HaddHiddenApiExemptionsTest() throws NoSuchMethodException { 75 | assertTrue(LSPass.addHiddenApiExemptions("L")); 76 | assertTrue(LSPass.addHiddenApiExemptions("xx")); 77 | ActivityOptions.class.getDeclaredMethod("getHeight"); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /library/src/main/java/org/lsposed/hiddenapibypass/CoreOjClassLoader.java: -------------------------------------------------------------------------------- 1 | package org.lsposed.hiddenapibypass; 2 | 3 | import android.os.Build; 4 | 5 | import androidx.annotation.RequiresApi; 6 | 7 | import java.lang.invoke.MethodHandle; 8 | import java.lang.reflect.Executable; 9 | 10 | import dalvik.system.PathClassLoader; 11 | 12 | @RequiresApi(Build.VERSION_CODES.P) 13 | final class CoreOjClassLoader extends PathClassLoader { 14 | private static String getCoreOjPath() { 15 | String bootClassPath = System.getProperty("java.boot.class.path", ""); 16 | assert bootClassPath != null; 17 | return bootClassPath.split(":", 2)[0]; 18 | } 19 | 20 | CoreOjClassLoader() { 21 | super(getCoreOjPath(), null); 22 | } 23 | 24 | @Override 25 | public Class loadClass(String name) throws ClassNotFoundException { 26 | if (Object.class.getName().equals(name)) { 27 | return Object.class; 28 | } 29 | try { 30 | return findClass(name); 31 | } catch (ClassNotFoundException ignored) { 32 | // no class file in jar before art moved to apex. 33 | } 34 | if (Executable.class.getName().equals(name)) { 35 | return Helper.Executable.class; 36 | } else if (MethodHandle.class.getName().equals(name)) { 37 | return Helper.MethodHandle.class; 38 | } else if (Class.class.getName().equals(name)) { 39 | return Helper.Class.class; 40 | } 41 | return super.loadClass(name); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /library/src/main/java/org/lsposed/hiddenapibypass/Helper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021-2025 LSPosed 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.lsposed.hiddenapibypass; 18 | 19 | import java.lang.invoke.MethodType; 20 | import java.util.HashSet; 21 | import java.util.Set; 22 | 23 | @SuppressWarnings("unused") 24 | public class Helper { 25 | static final Set signaturePrefixes = new HashSet<>(); 26 | 27 | static boolean checkArgsForInvokeMethod(java.lang.Class[] params, Object[] args) { 28 | if (params.length != args.length) return false; 29 | for (int i = 0; i < params.length; ++i) { 30 | if (params[i].isPrimitive()) { 31 | if (params[i] == int.class && !(args[i] instanceof Integer)) return false; 32 | else if (params[i] == byte.class && !(args[i] instanceof Byte)) return false; 33 | else if (params[i] == char.class && !(args[i] instanceof Character)) return false; 34 | else if (params[i] == boolean.class && !(args[i] instanceof Boolean)) return false; 35 | else if (params[i] == double.class && !(args[i] instanceof Double)) return false; 36 | else if (params[i] == float.class && !(args[i] instanceof Float)) return false; 37 | else if (params[i] == long.class && !(args[i] instanceof Long)) return false; 38 | else if (params[i] == short.class && !(args[i] instanceof Short)) return false; 39 | } else if (args[i] != null && !params[i].isInstance(args[i])) return false; 40 | } 41 | return true; 42 | } 43 | 44 | static public class MethodHandle { 45 | private final MethodType type = null; 46 | private MethodType nominalType; 47 | private MethodHandle cachedSpreadInvoker; 48 | protected final int handleKind = 0; 49 | 50 | // The ArtMethod* or ArtField* associated with this method handle (used by the runtime). 51 | protected final long artFieldOrMethod = 0; 52 | } 53 | 54 | static final public class Class { 55 | private transient ClassLoader classLoader; 56 | private transient java.lang.Class componentType; 57 | private transient Object dexCache; 58 | private transient Object extData; 59 | private transient Object[] ifTable; 60 | private transient String name; 61 | private transient java.lang.Class superClass; 62 | private transient Object vtable; 63 | private transient long iFields; 64 | private transient long methods; 65 | private transient long sFields; 66 | private transient int accessFlags; 67 | private transient int classFlags; 68 | private transient int classSize; 69 | private transient int clinitThreadId; 70 | private transient int dexClassDefIndex; 71 | private transient volatile int dexTypeIndex; 72 | private transient int numReferenceInstanceFields; 73 | private transient int numReferenceStaticFields; 74 | private transient int objectSize; 75 | private transient int objectSizeAllocFastPath; 76 | private transient int primitiveType; 77 | private transient int referenceInstanceOffsets; 78 | private transient int status; 79 | private transient short copiedMethodsOffset; 80 | private transient short virtualMethodsOffset; 81 | } 82 | 83 | static public class AccessibleObject { 84 | private boolean override; 85 | } 86 | 87 | static final public class Executable extends AccessibleObject { 88 | private Class declaringClass; 89 | private Class declaringClassOfOverriddenMethod; 90 | private Object[] parameters; 91 | private long artMethod; 92 | private int accessFlags; 93 | } 94 | 95 | @SuppressWarnings("EmptyMethod") 96 | public static class NeverCall { 97 | private static void a() { 98 | } 99 | 100 | private static void b() { 101 | } 102 | 103 | private static int s; 104 | private static int t; 105 | private int i; 106 | private int j; 107 | } 108 | 109 | public static class InvokeStub { 110 | private static Object invoke(Object... args) { 111 | throw new IllegalStateException("Failed to invoke the method"); 112 | } 113 | 114 | private InvokeStub(Object... args) { 115 | throw new IllegalStateException("Failed to new a instance"); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /library/src/main/java/org/lsposed/hiddenapibypass/HiddenApiBypass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021-2025 LSPosed 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.lsposed.hiddenapibypass; 18 | 19 | import android.os.Build; 20 | import android.util.Log; 21 | 22 | import androidx.annotation.NonNull; 23 | import androidx.annotation.Nullable; 24 | import androidx.annotation.RequiresApi; 25 | 26 | import org.lsposed.hiddenapibypass.library.BuildConfig; 27 | 28 | import java.lang.invoke.MethodHandle; 29 | import java.lang.invoke.MethodHandles; 30 | import java.lang.reflect.Constructor; 31 | import java.lang.reflect.Executable; 32 | import java.lang.reflect.Field; 33 | import java.lang.reflect.InvocationTargetException; 34 | import java.lang.reflect.Method; 35 | import java.lang.reflect.Modifier; 36 | import java.lang.reflect.Type; 37 | import java.util.ArrayList; 38 | import java.util.Arrays; 39 | import java.util.List; 40 | import java.util.stream.Collectors; 41 | 42 | import stub.dalvik.system.VMRuntime; 43 | import stub.sun.misc.Unsafe; 44 | 45 | @RequiresApi(Build.VERSION_CODES.P) 46 | public final class HiddenApiBypass { 47 | private static final String TAG = "HiddenApiBypass"; 48 | private static final Unsafe unsafe; 49 | private static final long methodOffset; 50 | private static final long classOffset; 51 | private static final long artOffset; 52 | private static final long methodsOffset; 53 | private static final long iFieldOffset; 54 | private static final long sFieldOffset; 55 | private static final long artMethodSize; 56 | private static final long artMethodBias; 57 | private static final long artFieldSize; 58 | private static final long artFieldBias; 59 | 60 | static { 61 | try { 62 | //noinspection JavaReflectionMemberAccess DiscouragedPrivateApi 63 | unsafe = (Unsafe) Unsafe.class.getDeclaredMethod("getUnsafe").invoke(null); 64 | assert unsafe != null; 65 | ClassLoader bootClassloader = new CoreOjClassLoader(); 66 | Class executableClass = bootClassloader.loadClass(Executable.class.getName()); 67 | Class methodHandleClass = bootClassloader.loadClass(MethodHandle.class.getName()); 68 | Class classClass = bootClassloader.loadClass(Class.class.getName()); 69 | methodOffset = unsafe.objectFieldOffset(executableClass.getDeclaredField("artMethod")); 70 | classOffset = unsafe.objectFieldOffset(executableClass.getDeclaredField("declaringClass")); 71 | artOffset = unsafe.objectFieldOffset(methodHandleClass.getDeclaredField("artFieldOrMethod")); 72 | long iField; 73 | long sField; 74 | try { 75 | iField = unsafe.objectFieldOffset(classClass.getDeclaredField("fields")); 76 | sField = iField; 77 | } catch (NoSuchFieldException e) { 78 | iField = unsafe.objectFieldOffset(classClass.getDeclaredField("iFields")); 79 | sField = unsafe.objectFieldOffset(classClass.getDeclaredField("sFields")); 80 | } 81 | iFieldOffset = iField; 82 | sFieldOffset = sField; 83 | methodsOffset = unsafe.objectFieldOffset(classClass.getDeclaredField("methods")); 84 | Method mA = Helper.NeverCall.class.getDeclaredMethod("a"); 85 | Method mB = Helper.NeverCall.class.getDeclaredMethod("b"); 86 | mA.setAccessible(true); 87 | mB.setAccessible(true); 88 | MethodHandle mhA = MethodHandles.lookup().unreflect(mA); 89 | MethodHandle mhB = MethodHandles.lookup().unreflect(mB); 90 | long aAddr = unsafe.getLong(mhA, artOffset); 91 | long bAddr = unsafe.getLong(mhB, artOffset); 92 | long aMethods = unsafe.getLong(Helper.NeverCall.class, methodsOffset); 93 | artMethodSize = bAddr - aAddr; 94 | if (BuildConfig.DEBUG) Log.v(TAG, artMethodSize + " " + 95 | Long.toString(aAddr, 16) + ", " + 96 | Long.toString(bAddr, 16) + ", " + 97 | Long.toString(aMethods, 16)); 98 | artMethodBias = aAddr - aMethods - artMethodSize; 99 | Field fI = Helper.NeverCall.class.getDeclaredField("i"); 100 | Field fJ = Helper.NeverCall.class.getDeclaredField("j"); 101 | fI.setAccessible(true); 102 | fJ.setAccessible(true); 103 | MethodHandle mhI = MethodHandles.lookup().unreflectGetter(fI); 104 | MethodHandle mhJ = MethodHandles.lookup().unreflectGetter(fJ); 105 | long iAddr = unsafe.getLong(mhI, artOffset); 106 | long jAddr = unsafe.getLong(mhJ, artOffset); 107 | long iFields = unsafe.getLong(Helper.NeverCall.class, iFieldOffset); 108 | artFieldSize = jAddr - iAddr; 109 | if (BuildConfig.DEBUG) Log.v(TAG, artFieldSize + " " + 110 | Long.toString(iAddr, 16) + ", " + 111 | Long.toString(jAddr, 16) + ", " + 112 | Long.toString(iFields, 16)); 113 | artFieldBias = iAddr - iFields; 114 | } catch (ReflectiveOperationException e) { 115 | Log.e(TAG, "Initialize error", e); 116 | throw new ExceptionInInitializerError(e); 117 | } 118 | } 119 | 120 | /** 121 | * create an instance of the given class {@code clazz} calling the restricted constructor with arguments {@code args} 122 | * 123 | * @param clazz the class of the instance to new 124 | * @param initargs arguments to call constructor 125 | * @return the new instance 126 | * @see Constructor#newInstance(Object...) 127 | */ 128 | public static Object newInstance(@NonNull Class clazz, Object... initargs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { 129 | Method stub = Helper.InvokeStub.class.getDeclaredMethod("invoke", Object[].class); 130 | Constructor ctor = Helper.InvokeStub.class.getDeclaredConstructor(Object[].class); 131 | ctor.setAccessible(true); 132 | long methods = unsafe.getLong(clazz, methodsOffset); 133 | if (methods == 0) throw new NoSuchMethodException("Cannot find matching constructor"); 134 | int numMethods = unsafe.getInt(methods); 135 | if (BuildConfig.DEBUG) Log.d(TAG, clazz + " has " + numMethods + " methods"); 136 | for (int i = 0; i < numMethods; i++) { 137 | long method = methods + i * artMethodSize + artMethodBias; 138 | unsafe.putLong(stub, methodOffset, method); 139 | if (BuildConfig.DEBUG) Log.v(TAG, "got " + clazz.getTypeName() + "." + stub.getName() + 140 | "(" + Arrays.stream(stub.getParameterTypes()).map(Type::getTypeName).collect(Collectors.joining()) + ")"); 141 | if ("".equals(stub.getName())) { 142 | unsafe.putLong(ctor, methodOffset, method); 143 | unsafe.putObject(ctor, classOffset, clazz); 144 | Class[] params = ctor.getParameterTypes(); 145 | if (Helper.checkArgsForInvokeMethod(params, initargs)) 146 | return ctor.newInstance(initargs); 147 | } 148 | } 149 | throw new NoSuchMethodException("Cannot find matching constructor"); 150 | } 151 | 152 | /** 153 | * invoke a restrict method named {@code methodName} of the given class {@code clazz} with this object {@code thiz} and arguments {@code args} 154 | * 155 | * @param clazz the class call the method on (this parameter is required because this method cannot call inherit method) 156 | * @param thiz this object, which can be {@code null} if the target method is static 157 | * @param methodName the method name 158 | * @param args arguments to call the method with name {@code methodName} 159 | * @return the return value of the method 160 | * @see Method#invoke(Object, Object...) 161 | */ 162 | public static Object invoke(@NonNull Class clazz, @Nullable Object thiz, @NonNull String methodName, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { 163 | if (thiz != null && !clazz.isInstance(thiz)) { 164 | throw new IllegalArgumentException("this object is not an instance of the given class"); 165 | } 166 | Method stub = Helper.InvokeStub.class.getDeclaredMethod("invoke", Object[].class); 167 | stub.setAccessible(true); 168 | long methods = unsafe.getLong(clazz, methodsOffset); 169 | if (methods == 0) throw new NoSuchMethodException("Cannot find matching method"); 170 | int numMethods = unsafe.getInt(methods); 171 | if (BuildConfig.DEBUG) Log.d(TAG, clazz + " has " + numMethods + " methods"); 172 | for (int i = 0; i < numMethods; i++) { 173 | long method = methods + i * artMethodSize + artMethodBias; 174 | unsafe.putLong(stub, methodOffset, method); 175 | if (BuildConfig.DEBUG) Log.v(TAG, "got " + clazz.getTypeName() + "." + stub.getName() + 176 | "(" + Arrays.stream(stub.getParameterTypes()).map(Type::getTypeName).collect(Collectors.joining()) + ")"); 177 | if (methodName.equals(stub.getName())) { 178 | Class[] params = stub.getParameterTypes(); 179 | if (Helper.checkArgsForInvokeMethod(params, args)) 180 | return stub.invoke(thiz, args); 181 | } 182 | } 183 | throw new NoSuchMethodException("Cannot find matching method"); 184 | } 185 | 186 | /** 187 | * get declared methods of given class without hidden api restriction 188 | * 189 | * @param clazz the class to fetch declared methods (including constructors with name `<init>`) 190 | * @return list of declared methods of {@code clazz} 191 | */ 192 | @NonNull 193 | public static List getDeclaredMethods(@NonNull Class clazz) { 194 | if (clazz.isPrimitive() || clazz.isArray()) return List.of(); 195 | MethodHandle mh; 196 | try { 197 | Method mA = Helper.NeverCall.class.getDeclaredMethod("a"); 198 | mA.setAccessible(true); 199 | mh = MethodHandles.lookup().unreflect(mA); 200 | } catch (NoSuchMethodException | IllegalAccessException e) { 201 | return List.of(); 202 | } 203 | long methods = unsafe.getLong(clazz, methodsOffset); 204 | if (methods == 0) return List.of(); 205 | int numMethods = unsafe.getInt(methods); 206 | if (BuildConfig.DEBUG) Log.d(TAG, clazz + " has " + numMethods + " methods"); 207 | List list = new ArrayList<>(numMethods); 208 | for (int i = 0; i < numMethods; i++) { 209 | long method = methods + i * artMethodSize + artMethodBias; 210 | unsafe.putLong(mh, artOffset, method); 211 | Executable member = MethodHandles.reflectAs(Executable.class, mh); 212 | if (BuildConfig.DEBUG) 213 | Log.v(TAG, "got " + clazz.getTypeName() + "." + member.getName() + 214 | "(" + Arrays.stream(member.getParameterTypes()).map(Type::getTypeName).collect(Collectors.joining()) + ")"); 215 | list.add(member); 216 | } 217 | return list; 218 | } 219 | 220 | /** 221 | * get a restrict method named {@code methodName} of the given class {@code clazz} with argument types {@code parameterTypes} 222 | * 223 | * @param clazz the class where the expected method declares 224 | * @param methodName the expected method's name 225 | * @param parameterTypes argument types of the expected method with name {@code methodName} 226 | * @return the found method 227 | * @throws NoSuchMethodException when no method matches the given parameters 228 | * @see Class#getDeclaredMethod(String, Class[]) 229 | */ 230 | @NonNull 231 | public static Method getDeclaredMethod(@NonNull Class clazz, @NonNull String methodName, @NonNull Class... parameterTypes) throws NoSuchMethodException { 232 | List methods = getDeclaredMethods(clazz); 233 | allMethods: 234 | for (Executable method : methods) { 235 | if (!method.getName().equals(methodName)) continue; 236 | if (!(method instanceof Method)) continue; 237 | Class[] expectedTypes = method.getParameterTypes(); 238 | if (expectedTypes.length != parameterTypes.length) continue; 239 | for (int i = 0; i < parameterTypes.length; ++i) { 240 | if (parameterTypes[i] != expectedTypes[i]) continue allMethods; 241 | } 242 | return (Method) method; 243 | } 244 | throw new NoSuchMethodException("Cannot find matching method"); 245 | } 246 | 247 | /** 248 | * get a restrict constructor of the given class {@code clazz} with argument types {@code parameterTypes} 249 | * 250 | * @param clazz the class where the expected constructor declares 251 | * @param parameterTypes argument types of the expected constructor 252 | * @return the found constructor 253 | * @throws NoSuchMethodException when no constructor matches the given parameters 254 | * @see Class#getDeclaredConstructor(Class[]) 255 | */ 256 | @NonNull 257 | public static Constructor getDeclaredConstructor(@NonNull Class clazz, @NonNull Class... parameterTypes) throws NoSuchMethodException { 258 | List methods = getDeclaredMethods(clazz); 259 | allMethods: 260 | for (Executable method : methods) { 261 | if (!(method instanceof Constructor)) continue; 262 | Class[] expectedTypes = method.getParameterTypes(); 263 | if (expectedTypes.length != parameterTypes.length) continue; 264 | for (int i = 0; i < parameterTypes.length; ++i) { 265 | if (parameterTypes[i] != expectedTypes[i]) continue allMethods; 266 | } 267 | return (Constructor) method; 268 | } 269 | throw new NoSuchMethodException("Cannot find matching constructor"); 270 | } 271 | 272 | 273 | /** 274 | * get declared non-static fields of given class without hidden api restriction 275 | * 276 | * @param clazz the class to fetch declared methods 277 | * @return list of declared non-static fields of {@code clazz} 278 | */ 279 | @NonNull 280 | public static List getInstanceFields(@NonNull Class clazz) { 281 | if (clazz.isPrimitive() || clazz.isArray()) return List.of(); 282 | MethodHandle mh; 283 | try { 284 | Field fI = Helper.NeverCall.class.getDeclaredField("i"); 285 | fI.setAccessible(true); 286 | mh = MethodHandles.lookup().unreflectGetter(fI); 287 | } catch (IllegalAccessException | NoSuchFieldException e) { 288 | return List.of(); 289 | } 290 | long fields = unsafe.getLong(clazz, iFieldOffset); 291 | if (fields == 0) return List.of(); 292 | int numFields = unsafe.getInt(fields); 293 | if (BuildConfig.DEBUG) Log.d(TAG, clazz + " has " + numFields + " fields"); 294 | List list = new ArrayList<>(numFields); 295 | for (int i = 0; i < numFields; i++) { 296 | long field = fields + i * artFieldSize + artFieldBias; 297 | unsafe.putLong(mh, artOffset, field); 298 | Field member = MethodHandles.reflectAs(Field.class, mh); 299 | if (BuildConfig.DEBUG) 300 | Log.v(TAG, "got " + member.getType() + " " + clazz.getTypeName() + "." + member.getName()); 301 | if (!Modifier.isStatic(member.getModifiers())) 302 | list.add(member); 303 | } 304 | return list; 305 | } 306 | 307 | /** 308 | * get declared static fields of given class without hidden api restriction 309 | * 310 | * @param clazz the class to fetch declared methods 311 | * @return list of declared static fields of {@code clazz} 312 | */ 313 | @NonNull 314 | public static List getStaticFields(@NonNull Class clazz) { 315 | if (clazz.isPrimitive() || clazz.isArray()) return List.of(); 316 | MethodHandle mh; 317 | try { 318 | Field fS = Helper.NeverCall.class.getDeclaredField("s"); 319 | fS.setAccessible(true); 320 | mh = MethodHandles.lookup().unreflectGetter(fS); 321 | } catch (IllegalAccessException | NoSuchFieldException e) { 322 | return List.of(); 323 | } 324 | long fields = unsafe.getLong(clazz, sFieldOffset); 325 | if (fields == 0) return List.of(); 326 | int numFields = unsafe.getInt(fields); 327 | if (BuildConfig.DEBUG) Log.d(TAG, clazz + " has " + numFields + " fields"); 328 | List list = new ArrayList<>(numFields); 329 | for (int i = 0; i < numFields; i++) { 330 | long field = fields + i * artFieldSize + artFieldBias; 331 | unsafe.putLong(mh, artOffset, field); 332 | Field member = MethodHandles.reflectAs(Field.class, mh); 333 | if (BuildConfig.DEBUG) 334 | Log.v(TAG, "got " + member.getType() + " " + clazz.getTypeName() + "." + member.getName()); 335 | if (Modifier.isStatic(member.getModifiers())) 336 | list.add(member); 337 | } 338 | return list; 339 | } 340 | 341 | /** 342 | * Sets the list of exemptions from hidden API access enforcement. 343 | * 344 | * @param signaturePrefixes A list of class signature prefixes. Each item in the list is a prefix match on the type 345 | * signature of a blacklisted API. All matching APIs are treated as if they were on 346 | * the whitelist: access permitted, and no logging.. 347 | * @return whether the operation is successful 348 | */ 349 | public static boolean setHiddenApiExemptions(@NonNull String... signaturePrefixes) { 350 | try { 351 | Object runtime = invoke(VMRuntime.class, null, "getRuntime"); 352 | invoke(VMRuntime.class, runtime, "setHiddenApiExemptions", (Object) signaturePrefixes); 353 | return true; 354 | } catch (ReflectiveOperationException e) { 355 | Log.w(TAG, "setHiddenApiExemptions", e); 356 | return false; 357 | } 358 | } 359 | 360 | /** 361 | * Adds the list of exemptions from hidden API access enforcement. 362 | * 363 | * @param signaturePrefixes A list of class signature prefixes. Each item in the list is a prefix match on the type 364 | * signature of a blacklisted API. All matching APIs are treated as if they were on 365 | * the whitelist: access permitted, and no logging.. 366 | * @return whether the operation is successful 367 | */ 368 | public static boolean addHiddenApiExemptions(String... signaturePrefixes) { 369 | Helper.signaturePrefixes.addAll(Arrays.asList(signaturePrefixes)); 370 | String[] strings = new String[Helper.signaturePrefixes.size()]; 371 | Helper.signaturePrefixes.toArray(strings); 372 | return setHiddenApiExemptions(strings); 373 | } 374 | 375 | /** 376 | * Clear the list of exemptions from hidden API access enforcement. 377 | * Android runtime will cache access flags, so if a hidden API has been accessed unrestrictedly, 378 | * running this method will not restore the restriction on it. 379 | * 380 | * @return whether the operation is successful 381 | */ 382 | public static boolean clearHiddenApiExemptions() { 383 | Helper.signaturePrefixes.clear(); 384 | return setHiddenApiExemptions(); 385 | } 386 | } 387 | -------------------------------------------------------------------------------- /library/src/main/java/org/lsposed/hiddenapibypass/LSPass.java: -------------------------------------------------------------------------------- 1 | package org.lsposed.hiddenapibypass; 2 | 3 | import android.os.Build; 4 | import android.util.Log; 5 | import android.util.Property; 6 | 7 | import androidx.annotation.NonNull; 8 | import androidx.annotation.Nullable; 9 | import androidx.annotation.RequiresApi; 10 | 11 | import java.lang.reflect.Constructor; 12 | import java.lang.reflect.Field; 13 | import java.lang.reflect.InvocationTargetException; 14 | import java.lang.reflect.Method; 15 | import java.lang.reflect.Modifier; 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.List; 19 | 20 | import stub.dalvik.system.VMRuntime; 21 | 22 | @SuppressWarnings("rawtypes") 23 | @RequiresApi(Build.VERSION_CODES.P) 24 | public final class LSPass { 25 | private static final String TAG = "LSPass"; 26 | private static final Property methods; 27 | private static final Property constructors; 28 | private static final Property fields; 29 | 30 | static { 31 | methods = Property.of(Class.class, Method[].class, "DeclaredMethods"); 32 | constructors = Property.of(Class.class, Constructor[].class, "DeclaredConstructors"); 33 | fields = Property.of(Class.class, Field[].class, "DeclaredFields"); 34 | } 35 | 36 | /** 37 | * get declared methods of given class without hidden api restriction 38 | * 39 | * @param clazz the class to fetch declared methods 40 | * @return list of declared methods of {@code clazz} 41 | */ 42 | public static List getDeclaredMethods(@NonNull Class clazz) { 43 | return Arrays.asList(methods.get(clazz)); 44 | } 45 | 46 | /** 47 | * get declared constructors of given class without hidden api restriction 48 | * 49 | * @param clazz the class to fetch declared constructors 50 | * @return list of declared constructors of {@code clazz} 51 | */ 52 | public static List> getDeclaredConstructors(@NonNull Class clazz) { 53 | return Arrays.>asList(constructors.get(clazz)); 54 | } 55 | 56 | /** 57 | * get declared fields of given class without hidden api restriction 58 | * 59 | * @param clazz the class to fetch declared methods 60 | * @return list of declared fields of {@code clazz} 61 | */ 62 | public static List getDeclaredFields(@NonNull Class clazz) { 63 | return Arrays.asList(fields.get(clazz)); 64 | } 65 | 66 | /** 67 | * get declared non-static fields of given class without hidden api restriction 68 | * 69 | * @param clazz the class to fetch declared methods 70 | * @return list of declared non-static fields of {@code clazz} 71 | */ 72 | @NonNull 73 | public static List getInstanceFields(@NonNull Class clazz) { 74 | var list = new ArrayList(); 75 | for (var member : getDeclaredFields(clazz)) { 76 | if (!Modifier.isStatic(member.getModifiers())) 77 | list.add(member); 78 | } 79 | return list; 80 | } 81 | 82 | /** 83 | * get declared static fields of given class without hidden api restriction 84 | * 85 | * @param clazz the class to fetch declared methods 86 | * @return list of declared static fields of {@code clazz} 87 | */ 88 | @NonNull 89 | public static List getStaticFields(@NonNull Class clazz) { 90 | var list = new ArrayList(); 91 | for (var member : getDeclaredFields(clazz)) { 92 | if (Modifier.isStatic(member.getModifiers())) 93 | list.add(member); 94 | } 95 | return list; 96 | } 97 | 98 | /** 99 | * get a restrict method named {@code methodName} of the given class {@code clazz} with argument types {@code parameterTypes} 100 | * 101 | * @param clazz the class where the expected method declares 102 | * @param methodName the expected method's name 103 | * @param parameterTypes argument types of the expected method with name {@code methodName} 104 | * @return the found method 105 | * @throws NoSuchMethodException when no method matches the given parameters 106 | * @see Class#getDeclaredMethod(String, Class[]) 107 | */ 108 | @NonNull 109 | public static Method getDeclaredMethod(@NonNull Class clazz, @NonNull String methodName, @NonNull Class... parameterTypes) throws NoSuchMethodException { 110 | var methods = getDeclaredMethods(clazz); 111 | all: 112 | for (var method : methods) { 113 | if (!method.getName().equals(methodName)) continue; 114 | var expectedTypes = method.getParameterTypes(); 115 | if (expectedTypes.length != parameterTypes.length) continue; 116 | for (int i = 0; i < parameterTypes.length; ++i) { 117 | if (parameterTypes[i] != expectedTypes[i]) continue all; 118 | } 119 | return method; 120 | } 121 | throw new NoSuchMethodException("Cannot find matching method"); 122 | } 123 | 124 | /** 125 | * get a restrict constructor of the given class {@code clazz} with argument types {@code parameterTypes} 126 | * 127 | * @param clazz the class where the expected constructor declares 128 | * @param parameterTypes argument types of the expected constructor 129 | * @return the found constructor 130 | * @throws NoSuchMethodException when no constructor matches the given parameters 131 | * @see Class#getDeclaredConstructor(Class[]) 132 | */ 133 | @NonNull 134 | public static Constructor getDeclaredConstructor(@NonNull Class clazz, @NonNull Class... parameterTypes) throws NoSuchMethodException { 135 | var constructors = getDeclaredConstructors(clazz); 136 | all: 137 | for (var constructor : constructors) { 138 | var expectedTypes = constructor.getParameterTypes(); 139 | if (expectedTypes.length != parameterTypes.length) continue; 140 | for (int i = 0; i < parameterTypes.length; ++i) { 141 | if (parameterTypes[i] != expectedTypes[i]) continue all; 142 | } 143 | return constructor; 144 | } 145 | throw new NoSuchMethodException("Cannot find matching constructor"); 146 | } 147 | 148 | /** 149 | * create an instance of the given class {@code clazz} calling the restricted constructor with arguments {@code args} 150 | * 151 | * @param clazz the class of the instance to new 152 | * @param initargs arguments to call constructor 153 | * @return the new instance 154 | * @see Constructor#newInstance(Object...) 155 | */ 156 | public static Object newInstance(@NonNull Class clazz, Object... initargs) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { 157 | var constructors = getDeclaredConstructors(clazz); 158 | for (var constructor : constructors) { 159 | var params = constructor.getParameterTypes(); 160 | if (!Helper.checkArgsForInvokeMethod(params, initargs)) continue; 161 | constructor.setAccessible(true); 162 | return constructor.newInstance(initargs); 163 | } 164 | throw new NoSuchMethodException("Cannot find matching constructor"); 165 | } 166 | 167 | /** 168 | * invoke a restrict method named {@code methodName} of the given class {@code clazz} with this object {@code thiz} and arguments {@code args} 169 | * 170 | * @param clazz the class call the method on (this parameter is required because this method cannot call inherit method) 171 | * @param thiz this object, which can be {@code null} if the target method is static 172 | * @param methodName the method name 173 | * @param args arguments to call the method with name {@code methodName} 174 | * @return the return value of the method 175 | * @see Method#invoke(Object, Object...) 176 | */ 177 | public static Object invoke(@NonNull Class clazz, @Nullable Object thiz, @NonNull String methodName, Object... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { 178 | var methods = getDeclaredMethods(clazz); 179 | for (var method : methods) { 180 | if (!method.getName().equals(methodName)) continue; 181 | var params = method.getParameterTypes(); 182 | if (!Helper.checkArgsForInvokeMethod(params, args)) continue; 183 | method.setAccessible(true); 184 | return method.invoke(thiz, args); 185 | } 186 | throw new NoSuchMethodException("Cannot find matching method"); 187 | } 188 | 189 | /** 190 | * Sets the list of exemptions from hidden API access enforcement. 191 | * 192 | * @param signaturePrefixes A list of class signature prefixes. Each item in the list is a prefix match on the type 193 | * signature of a blacklisted API. All matching APIs are treated as if they were on 194 | * the whitelist: access permitted, and no logging.. 195 | * @return whether the operation is successful 196 | */ 197 | public static boolean setHiddenApiExemptions(@NonNull String... signaturePrefixes) { 198 | try { 199 | var runtime = invoke(VMRuntime.class, null, "getRuntime"); 200 | invoke(VMRuntime.class, runtime, "setHiddenApiExemptions", (Object) signaturePrefixes); 201 | return true; 202 | } catch (ReflectiveOperationException e) { 203 | Log.w(TAG, "setHiddenApiExemptions", e); 204 | return false; 205 | } 206 | } 207 | 208 | /** 209 | * Adds the list of exemptions from hidden API access enforcement. 210 | * 211 | * @param signaturePrefixes A list of class signature prefixes. Each item in the list is a prefix match on the type 212 | * signature of a blacklisted API. All matching APIs are treated as if they were on 213 | * the whitelist: access permitted, and no logging.. 214 | * @return whether the operation is successful 215 | */ 216 | public static boolean addHiddenApiExemptions(String... signaturePrefixes) { 217 | Helper.signaturePrefixes.addAll(Arrays.asList(signaturePrefixes)); 218 | var strings = new String[Helper.signaturePrefixes.size()]; 219 | Helper.signaturePrefixes.toArray(strings); 220 | return setHiddenApiExemptions(strings); 221 | } 222 | 223 | /** 224 | * Clear the list of exemptions from hidden API access enforcement. 225 | * Android runtime will cache access flags, so if a hidden API has been accessed unrestrictedly, 226 | * running this method will not restore the restriction on it. 227 | * 228 | * @return whether the operation is successful 229 | */ 230 | public static boolean clearHiddenApiExemptions() { 231 | Helper.signaturePrefixes.clear(); 232 | return setHiddenApiExemptions(); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") 2 | 3 | pluginManagement { 4 | repositories { 5 | gradlePluginPortal() 6 | google() 7 | mavenCentral() 8 | } 9 | } 10 | 11 | dependencyResolutionManagement { 12 | repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | } 18 | include(":stub", ":library") 19 | rootProject.name = "HiddenApiBypass" 20 | -------------------------------------------------------------------------------- /stub/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /stub/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | java { 6 | sourceCompatibility = JavaVersion.VERSION_11 7 | targetCompatibility = JavaVersion.VERSION_11 8 | } 9 | -------------------------------------------------------------------------------- /stub/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /stub/src/main/java/stub/dalvik/system/VMRuntime.java: -------------------------------------------------------------------------------- 1 | package stub.dalvik.system; 2 | 3 | @SuppressWarnings("unused") 4 | public class VMRuntime { 5 | public static VMRuntime getRuntime() { 6 | throw new IllegalArgumentException("stub"); 7 | } 8 | public native void setHiddenApiExemptions(String[] signaturePrefixes); 9 | } 10 | -------------------------------------------------------------------------------- /stub/src/main/java/stub/sun/misc/Unsafe.java: -------------------------------------------------------------------------------- 1 | package stub.sun.misc; 2 | 3 | @SuppressWarnings({"unused", "rawtypes"}) 4 | public class Unsafe { 5 | public native long getLong(Object obj, long offset); 6 | public native void putLong(Object obj, long offset, long newValue); 7 | public native int getInt(Object obj, long offset); 8 | public native void putInt(java.lang.Object obj, long offset, int newValue); 9 | public native short getShort(java.lang.Object obj, long offset); 10 | public native Object getObject(Object obj, long offset); 11 | public native void putObject(Object obj, long offset, Object newValue); 12 | public native byte getByte(long address); 13 | public native void putByte(long address, byte x); 14 | public native int addressSize(); 15 | public native int getInt(long address); 16 | public native long getLong(long address); 17 | public int arrayBaseOffset(Class clazz) { 18 | throw new RuntimeException("Stub!"); 19 | } 20 | public long objectFieldOffset(java.lang.reflect.Field field) { 21 | throw new RuntimeException("Stub!"); 22 | } 23 | } 24 | --------------------------------------------------------------------------------