├── .github └── workflows │ ├── docs-deploy.yml │ └── kdoc-deploy.yml ├── .gitignore ├── Core ├── .gitignore ├── CMakeLists.txt ├── dexkit │ ├── analyze.cpp │ ├── beans.cpp │ ├── common.cpp │ ├── dex_item.cpp │ ├── dex_item_batch_find.cpp │ ├── dex_item_find.cpp │ ├── dex_item_matcher.cpp │ ├── dexkit.cpp │ ├── include │ │ ├── analyze.h │ │ ├── beans.h │ │ ├── common.h │ │ ├── constant.h │ │ ├── dex_item.h │ │ ├── dexkit.h │ │ ├── dexkit_error.h │ │ ├── dexkit_error_list.h │ │ ├── file_helper.h │ │ ├── mmap_windows.h │ │ ├── package_trie.h │ │ ├── schema │ │ │ ├── encode_value_generated.h │ │ │ ├── enums_generated.h │ │ │ ├── matchers_generated.h │ │ │ ├── querys_generated.h │ │ │ ├── ranges_generated.h │ │ │ └── results_generated.h │ │ └── string_match.h │ └── utils │ │ ├── byte_code_util.h │ │ ├── dex_descriptor_util.h │ │ └── opcode_util.h ├── main.cpp └── third_party │ ├── aho_corasick_trie │ └── acdat │ │ ├── AhoCorasickDoubleArrayTrie.h │ │ ├── Builder.h │ │ └── State.h │ ├── flatbuffers │ └── include │ │ └── flatbuffers │ │ ├── allocator.h │ │ ├── array.h │ │ ├── base.h │ │ ├── buffer.h │ │ ├── buffer_ref.h │ │ ├── code_generator.h │ │ ├── code_generators.h │ │ ├── default_allocator.h │ │ ├── detached_buffer.h │ │ ├── file_manager.h │ │ ├── flatbuffer_builder.h │ │ ├── flatbuffers.h │ │ ├── flatc.h │ │ ├── flex_flat_util.h │ │ ├── flexbuffers.h │ │ ├── grpc.h │ │ ├── hash.h │ │ ├── idl.h │ │ ├── minireflect.h │ │ ├── pch │ │ ├── flatc_pch.h │ │ └── pch.h │ │ ├── reflection.h │ │ ├── reflection_generated.h │ │ ├── registry.h │ │ ├── stl_emulation.h │ │ ├── string.h │ │ ├── struct.h │ │ ├── table.h │ │ ├── util.h │ │ ├── vector.h │ │ ├── vector_downward.h │ │ └── verifier.h │ ├── parallel_hashmap │ └── parallel_hashmap │ │ ├── btree.h │ │ ├── meminfo.h │ │ ├── phmap.h │ │ ├── phmap_base.h │ │ ├── phmap_bits.h │ │ ├── phmap_config.h │ │ ├── phmap_dump.h │ │ ├── phmap_fwd_decl.h │ │ └── phmap_utils.h │ ├── slicer │ ├── bytecode_encoder.cc │ ├── code_ir.cc │ ├── common.cc │ ├── control_flow_graph.cc │ ├── debuginfo_encoder.cc │ ├── dex_bytecode.cc │ ├── dex_format.cc │ ├── dex_ir.cc │ ├── dex_ir_builder.cc │ ├── dex_utf8.cc │ ├── export │ │ └── slicer │ │ │ ├── arrayview.h │ │ │ ├── buffer.h │ │ │ ├── bytecode_encoder.h │ │ │ ├── chronometer.h │ │ │ ├── code_ir.h │ │ │ ├── common.h │ │ │ ├── control_flow_graph.h │ │ │ ├── debuginfo_encoder.h │ │ │ ├── dex_bytecode.h │ │ │ ├── dex_format.h │ │ │ ├── dex_instruction_list.h │ │ │ ├── dex_ir.h │ │ │ ├── dex_ir_builder.h │ │ │ ├── dex_leb128.h │ │ │ ├── dex_utf8.h │ │ │ ├── hash_table.h │ │ │ ├── index_map.h │ │ │ ├── instrumentation.h │ │ │ ├── intrusive_list.h │ │ │ ├── memview.h │ │ │ ├── reader.h │ │ │ ├── scopeguard.h │ │ │ ├── tryblocks_encoder.h │ │ │ └── writer.h │ ├── instrumentation.cc │ ├── reader.cc │ ├── tryblocks_encoder.cc │ └── writer.cc │ └── thread_helper │ ├── ThreadPool.h │ └── ThreadVariable.h ├── LICENSE ├── README.md ├── README_zh.md ├── build.gradle ├── demo ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── org │ │ └── luckypray │ │ └── dexkit │ │ └── demo │ │ ├── DemoApplication.java │ │ ├── MainActivity.java │ │ ├── PlayActivity.java │ │ ├── RandomUtil.java │ │ ├── RouterManager.java │ │ ├── annotations │ │ └── Router.java │ │ └── hook │ │ └── Hooker.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ └── activity_play.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-mdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── mipmap-xxxhdpi │ ├── ic_launcher.webp │ └── ic_launcher_round.webp │ ├── values-night │ └── themes.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── themes.xml ├── dexkit-android ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ └── AndroidManifest.xml ├── dexkit ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── cpp │ │ ├── CMakeLists.txt │ │ └── native-bridge.cpp │ └── java │ │ └── org │ │ └── luckypray │ │ └── dexkit │ │ ├── Alias.kt │ │ ├── DexKitBridge.kt │ │ ├── annotations │ │ └── DexKitDsl.kt │ │ ├── exceptions │ │ ├── NoResultException.kt │ │ └── NonUniqueResultException.kt │ │ ├── query │ │ ├── BatchFindClassUsingStrings.kt │ │ ├── BatchFindMethodUsingStrings.kt │ │ ├── FindClass.kt │ │ ├── FindField.kt │ │ ├── FindMethod.kt │ │ ├── MatcherCollections.kt │ │ ├── base │ │ │ ├── BaseQuery.kt │ │ │ ├── IAnnotationEncodeValue.kt │ │ │ ├── INumberEncodeValue.kt │ │ │ └── IQuery.kt │ │ ├── enums │ │ │ ├── AnnotationEncodeValueType.kt │ │ │ ├── AnnotationVisibilityType.kt │ │ │ ├── MatchType.kt │ │ │ ├── NumberEncodeValueType.kt │ │ │ ├── OpCodeMatchType.kt │ │ │ ├── RetentionPolicyType.kt │ │ │ ├── StringMatchType.kt │ │ │ ├── TargetElementType.kt │ │ │ └── UsingType.kt │ │ └── matchers │ │ │ ├── AnnotationElementMatcher.kt │ │ │ ├── AnnotationElementsMatcher.kt │ │ │ ├── AnnotationEncodeArrayMatcher.kt │ │ │ ├── AnnotationMatcher.kt │ │ │ ├── AnnotationsMatcher.kt │ │ │ ├── ClassMatcher.kt │ │ │ ├── EncodeValues.kt │ │ │ ├── FieldMatcher.kt │ │ │ ├── FieldsMatcher.kt │ │ │ ├── InterfacesMatcher.kt │ │ │ ├── MethodMatcher.kt │ │ │ ├── MethodsMatcher.kt │ │ │ ├── ParameterMatcher.kt │ │ │ ├── ParametersMatcher.kt │ │ │ ├── StringMatchersGroup.kt │ │ │ ├── UsingFieldMatcher.kt │ │ │ └── base │ │ │ ├── AccessFlagsMatcher.kt │ │ │ ├── AnnotationEncodeValueMatcher.kt │ │ │ ├── IntRange.kt │ │ │ ├── NumberEncodeValueMatcher.kt │ │ │ ├── OpCodesMatcher.kt │ │ │ ├── StringMatcher.kt │ │ │ └── TargetElementTypesMatcher.kt │ │ ├── result │ │ ├── AnnotationData.kt │ │ ├── AnnotationElementData.kt │ │ ├── AnnotationEncodeArrayData.kt │ │ ├── AnnotationEncodeValue.kt │ │ ├── ClassData.kt │ │ ├── DataCollections.kt │ │ ├── FieldData.kt │ │ ├── FieldUsingType.kt │ │ ├── MethodData.kt │ │ ├── UsingFieldData.kt │ │ └── base │ │ │ └── BaseData.kt │ │ ├── schema │ │ ├── AccessFlagsMatcher.kt │ │ ├── AnnotationElementMatcher.kt │ │ ├── AnnotationElementMeta.kt │ │ ├── AnnotationElementsMatcher.kt │ │ ├── AnnotationEncodeArray.kt │ │ ├── AnnotationEncodeArrayMatcher.kt │ │ ├── AnnotationEncodeValue.kt │ │ ├── AnnotationEncodeValueMatcher.kt │ │ ├── AnnotationEncodeValueMeta.kt │ │ ├── AnnotationEncodeValueType.kt │ │ ├── AnnotationMatcher.kt │ │ ├── AnnotationMeta.kt │ │ ├── AnnotationMetaArrayHolder.kt │ │ ├── AnnotationVisibilityType.kt │ │ ├── AnnotationsMatcher.kt │ │ ├── BatchClassMeta.kt │ │ ├── BatchClassMetaArrayHolder.kt │ │ ├── BatchFindClassUsingStrings.kt │ │ ├── BatchFindMethodUsingStrings.kt │ │ ├── BatchMethodMeta.kt │ │ ├── BatchMethodMetaArrayHolder.kt │ │ ├── BatchUsingStringsMatcher.kt │ │ ├── ClassMatcher.kt │ │ ├── ClassMeta.kt │ │ ├── ClassMetaArrayHolder.kt │ │ ├── EncodeValueBoolean.kt │ │ ├── EncodeValueByte.kt │ │ ├── EncodeValueChar.kt │ │ ├── EncodeValueDouble.kt │ │ ├── EncodeValueFloat.kt │ │ ├── EncodeValueInt.kt │ │ ├── EncodeValueLong.kt │ │ ├── EncodeValueNull.kt │ │ ├── EncodeValueShort.kt │ │ ├── EncodeValueString.kt │ │ ├── FieldMatcher.kt │ │ ├── FieldMeta.kt │ │ ├── FieldMetaArrayHolder.kt │ │ ├── FieldsMatcher.kt │ │ ├── FindClass.kt │ │ ├── FindField.kt │ │ ├── FindMethod.kt │ │ ├── IntRange.kt │ │ ├── InterfacesMatcher.kt │ │ ├── LongRange.kt │ │ ├── MatchType.kt │ │ ├── MethodMatcher.kt │ │ ├── MethodMeta.kt │ │ ├── MethodMetaArrayHolder.kt │ │ ├── MethodsMatcher.kt │ │ ├── Number.kt │ │ ├── OpCodeMatchType.kt │ │ ├── OpCodesMatcher.kt │ │ ├── ParameterMatcher.kt │ │ ├── ParametersAnnotationMetaArrayHoler.kt │ │ ├── ParametersMatcher.kt │ │ ├── RetentionPolicyType.kt │ │ ├── StringMatchType.kt │ │ ├── StringMatcher.kt │ │ ├── TargetElementType.kt │ │ ├── TargetElementTypesMatcher.kt │ │ ├── UsingFieldMatcher.kt │ │ ├── UsingFieldMeta.kt │ │ ├── UsingFieldMetaArrayHolder.kt │ │ └── UsingType.kt │ │ ├── util │ │ ├── DexSignUtil.kt │ │ ├── InstanceUtil.kt │ │ ├── MUtf8Util.java │ │ ├── OpCodeUtil.kt │ │ ├── StringUnicodeEncoderDecoder.java │ │ └── WeakCache.kt │ │ └── wrap │ │ ├── DexClass.kt │ │ ├── DexField.kt │ │ ├── DexMethod.kt │ │ └── ISerializable.kt │ └── test │ └── java │ └── org │ └── luckypray │ └── dexkit │ ├── JavaReadMeTest.java │ ├── KtReadMeTest.kt │ ├── LibLoader.kt │ ├── UnitTest.kt │ └── util │ └── InstanceUtilTest.kt ├── doc-source ├── .gitignore ├── package.json ├── src │ ├── .vuepress │ │ ├── config.ts │ │ └── configs │ │ │ ├── client.ts │ │ │ ├── template.ts │ │ │ └── utils.ts │ ├── en │ │ ├── about │ │ │ ├── about.md │ │ │ └── contacts.md │ │ ├── guide │ │ │ ├── example.md │ │ │ ├── home.md │ │ │ ├── knowledge.md │ │ │ ├── performance-optimization.md │ │ │ ├── quick-start.md │ │ │ ├── run-on-desktop.md │ │ │ └── structural-zoom-table.md │ │ └── index.md │ ├── index.md │ └── zh-cn │ │ ├── about │ │ ├── about.md │ │ └── contacts.md │ │ ├── guide │ │ ├── example.md │ │ ├── home.md │ │ ├── knowledge.md │ │ ├── performance-optimization.md │ │ ├── quick-start.md │ │ ├── run-on-desktop.md │ │ └── structural-zoom-table.md │ │ └── index.md └── yarn.lock ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lint-rules ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── luckypray │ └── dexkit │ └── lint │ ├── DexKitIssueRegistry.kt │ ├── detector │ ├── DexKitCreateDetector.kt │ └── DexKitDataFirstDetector.kt │ └── util │ └── Utils.kt ├── main ├── .gitignore ├── README.md ├── build.gradle └── src │ └── main │ └── java │ └── Main.kt ├── schema ├── .gitignore ├── README.md ├── fbs │ ├── encode_value.fbs │ ├── enums.fbs │ ├── matchers.fbs │ ├── querys.fbs │ ├── ranges.fbs │ └── results.fbs └── gen_code.py └── settings.gradle /.github/workflows/docs-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Vuepress Document Deploy 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths: 8 | - 'doc-source/**' 9 | - '.github/workflows/docs-deploy.yml' 10 | 11 | permissions: 12 | contents: write 13 | 14 | jobs: 15 | vuepress-doc-deploy: 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - name: Clone master branch 20 | uses: actions/checkout@v3.3.0 21 | 22 | - name: vuepress-deploy 23 | uses: jenkey2011/vuepress-deploy@master 24 | env: 25 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 26 | TARGET_REPO: ${{ github.repository }} 27 | TARGET_BRANCH: docs 28 | BUILD_SCRIPT: | 29 | git config --global --add safe.directory "*" \ 30 | && cd doc-source && yarn -i --network-timeout 1000000000 && yarn docs:build 31 | BUILD_DIR: ../docs 32 | -------------------------------------------------------------------------------- /.github/workflows/kdoc-deploy.yml: -------------------------------------------------------------------------------- 1 | name: KDoc Build and Deploy 2 | 3 | on: 4 | push: 5 | tags: 6 | - '**' 7 | 8 | jobs: 9 | KDoc-deploy: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Clone master branch 14 | uses: actions/checkout@v3.3.0 15 | 16 | - name: Prepare Java 17 17 | uses: actions/setup-java@v3.10.0 18 | with: 19 | java-version: 17 20 | distribution: adopt 21 | 22 | - name: Cache Gradle packages 23 | uses: actions/cache@v3 24 | with: 25 | path: ~/.gradle/caches 26 | key: ${{ runner.os }}-gradle-${{ hashFiles('/*.gradle') }}-${{ hashFiles('/*.gradle.kts') }} 27 | 28 | - name: Build KDoc and deploy 29 | env: 30 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 31 | run: | 32 | chmod +x ./gradlew \ 33 | && ./gradlew clean \ 34 | && ./gradlew :dexkit-android:dokkaHtml \ 35 | && ./gradlew :dexkit-android:updateKDoc 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .DS_Store 3 | /build 4 | /captures 5 | .gradle 6 | .externalNativeBuild 7 | .cxx 8 | local.properties 9 | 10 | /docs 11 | /apk -------------------------------------------------------------------------------- /Core/.gitignore: -------------------------------------------------------------------------------- 1 | ### C++ template 2 | # Prerequisites 3 | *.d 4 | 5 | # Compiled Object files 6 | *.slo 7 | *.lo 8 | *.o 9 | *.obj 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | # Compiled Dynamic libraries 16 | *.so 17 | *.dylib 18 | *.dll 19 | 20 | # Fortran module files 21 | *.mod 22 | *.smod 23 | 24 | # Compiled Static libraries 25 | *.lai 26 | *.la 27 | *.a 28 | *.lib 29 | 30 | # Executables 31 | *.exe 32 | *.out 33 | *.app 34 | 35 | ### CMake template 36 | CMakeLists.txt.user 37 | CMakeCache.txt 38 | CMakeFiles 39 | CMakeScripts 40 | Testing 41 | Makefile 42 | cmake_install.cmake 43 | install_manifest.txt 44 | compile_commands.json 45 | CTestTestfile.cmake 46 | _deps 47 | 48 | 49 | cmake-build*/ 50 | .idea 51 | #CMakeLists.txt 52 | 53 | *.dex 54 | *.apk 55 | /apks -------------------------------------------------------------------------------- /Core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1...3.27) 2 | project(dexkit) 3 | 4 | find_program(CCACHE ccache) 5 | 6 | if (CCACHE) 7 | set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE}) 8 | set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE}) 9 | endif () 10 | 11 | set(CMAKE_CXX_STANDARD 20) 12 | 13 | file(GLOB_RECURSE SLICER_SRC_FILES third_party/slicer/*.cc) 14 | file(GLOB_RECURSE DEXKIT_SRC_FILES dexkit/*.cpp) 15 | 16 | set(SLICER_SOURCES 17 | ${SLICER_SRC_FILES} 18 | ) 19 | 20 | set(COMPILE_FLAGS "-Wno-empty-body -Wno-unused-private-field \ 21 | -Wno-unused-value -Wno-unused-variable -Wno-unused-function") 22 | set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}") 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") 25 | 26 | add_library(${PROJECT_NAME}_static 27 | STATIC 28 | ${SLICER_SOURCES} 29 | ${DEXKIT_SRC_FILES} 30 | ) 31 | target_include_directories(${PROJECT_NAME}_static 32 | PUBLIC 33 | dexkit/include 34 | third_party/slicer/export 35 | third_party/thread_helper 36 | third_party/aho_corasick_trie 37 | third_party/parallel_hashmap 38 | third_party/flatbuffers/include 39 | ) 40 | target_link_libraries(${PROJECT_NAME}_static 41 | PUBLIC 42 | z 43 | ) 44 | 45 | option(EXECUTABLE_TEST "execute test cpp" OFF) 46 | if (EXECUTABLE_TEST) 47 | link_libraries(z ${PROJECT_NAME}_static) 48 | add_executable(${PROJECT_NAME} 49 | main.cpp 50 | ) 51 | endif () -------------------------------------------------------------------------------- /Core/dexkit/common.cpp: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #include "common.h" 22 | 23 | #include 24 | #include 25 | 26 | namespace dexkit { 27 | 28 | void _checkFailed(const char *expr, int line, const char *file) { 29 | printf("\nDEXKIT_CHECK failed [%s] at %s:%d\n\n", expr, file, line); 30 | abort(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /Core/dexkit/include/analyze.h: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #pragma once 22 | 23 | #include "schema/querys_generated.h" 24 | #include "schema/matchers_generated.h" 25 | 26 | // max depth of analyze type. 27 | // type name must in this dex->TypeIds() 28 | // type class maybe in this dex->TypeIds() or other dex->TypeIds() 29 | #define MAX_ANALYZE_TYPE_DEPTH 2 30 | 31 | namespace dexkit { 32 | 33 | // optional init 34 | const uint32_t kClassAnnotation = 0x0010; 35 | const uint32_t kFieldAnnotation = 0x0020; 36 | const uint32_t kMethodAnnotation = 0x0040; 37 | const uint32_t kParamAnnotation = 0x0080; 38 | 39 | // code 40 | const uint32_t kUsingString = 0x0100; 41 | const uint32_t kMethodInvoking = 0x0200; 42 | const uint32_t kCallerMethod = 0x0400; // cross 43 | const uint32_t kMethodUsingField = 0x0800; 44 | const uint32_t kRwFieldMethod = 0x1000; // cross 45 | const uint32_t kOpSequence = 0x2000; 46 | const uint32_t kUsingNumber = 0x4000; 47 | 48 | struct AnalyzeRet { 49 | uint32_t need_flags = 0; 50 | std::vector declare_class; 51 | }; 52 | 53 | AnalyzeRet Analyze(const schema::ClassMatcher *matcher, int dex_depth); 54 | AnalyzeRet Analyze(const schema::FieldMatcher *matcher, int dex_depth); 55 | AnalyzeRet Analyze(const schema::MethodMatcher *matcher, int dex_depth); 56 | 57 | AnalyzeRet Analyze(const schema::AnnotationEncodeArrayMatcher *matcher, int dex_depth); 58 | AnalyzeRet Analyze(const schema::AnnotationElementMatcher *matcher, int dex_depth); 59 | AnalyzeRet Analyze(const schema::AnnotationElementsMatcher *matcher, int dex_depth); 60 | AnalyzeRet Analyze(const schema::AnnotationMatcher *matcher, int dex_depth); 61 | AnalyzeRet Analyze(const schema::AnnotationsMatcher *matcher, int dex_depth); 62 | AnalyzeRet Analyze(const schema::InterfacesMatcher *matcher, int dex_depth); 63 | AnalyzeRet Analyze(const schema::FieldsMatcher *matcher, int dex_depth); 64 | AnalyzeRet Analyze(const schema::MethodsMatcher *matcher, int dex_depth); 65 | 66 | AnalyzeRet Analyze(const schema::ParameterMatcher *matcher, int dex_depth); 67 | AnalyzeRet Analyze(const schema::ParametersMatcher *matcher, int dex_depth); 68 | 69 | } // namespace dexkit -------------------------------------------------------------------------------- /Core/dexkit/include/constant.h: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "slicer/dex_ir.h" 28 | 29 | // null_param is used to match any param 30 | const static std::optional> null_param = std::nullopt; 31 | const static std::vector empty_param; 32 | 33 | // init cached flag 34 | constexpr dex::u4 fHeader = 0x0001; 35 | constexpr dex::u4 fString = 0x0002; 36 | constexpr dex::u4 fType = 0x0004; 37 | constexpr dex::u4 fProto = 0x0008; 38 | constexpr dex::u4 fField = 0x0010; 39 | constexpr dex::u4 fMethod = 0x0020; 40 | constexpr dex::u4 fAnnotation = 0x0040; 41 | constexpr dex::u4 fOpCodeSeq = 0x1000; 42 | constexpr dex::u4 fDefault = fHeader | fString | fType | fProto | fMethod; 43 | 44 | // used field flag 45 | constexpr dex::u4 fGetting = 0x1; 46 | constexpr dex::u4 fSetting = 0x2; 47 | constexpr dex::u4 fUsing = fGetting | fSetting; 48 | 49 | // match type 50 | // mFull : full string match, eg. 51 | // full_match(search = "abc", target = "abc") = true 52 | // full_match(search = "abc", target = "abcd") = false 53 | constexpr dex::u4 mFull = 0; 54 | // mContains : contains string match, eg. 55 | // contains_match(search = "abc", target = "abcd") = true 56 | // contains_match(search = "abc", target = "abc") = true 57 | // contains_match(search = "abc", target = "ab") = false 58 | constexpr dex::u4 mContains = 1; 59 | // mSimilarRegex : similar regex matches, only support: '^', '$' eg. 60 | // similar_regex_match(search = "abc", target = "abc") == true 61 | // similar_regex_match(search = "^abc", target = "abc") == true 62 | // similar_regex_match(search = "abc$", target = "bc") == true 63 | // similar_regex_match(search = "^abc$", target = "abc") == true 64 | // similar_regex_match(search = "^abc$", target = "abcd") == false 65 | constexpr dex::u4 mSimilarRegex = 2; 66 | -------------------------------------------------------------------------------- /Core/dexkit/include/dexkit_error.h: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #pragma once 22 | 23 | #include 24 | 25 | namespace dexkit { 26 | 27 | enum class Error : uint16_t { 28 | #define DEXKIT_ERROR(name, msg) name, 29 | #include "dexkit_error_list.h" 30 | DEXKIT_ERROR_LIST(DEXKIT_ERROR) 31 | #undef DEXKIT_ERROR_LIST 32 | #undef DEXKIT_ERROR 33 | }; 34 | 35 | constexpr std::string_view error_messages[] = { 36 | #define DEXKIT_ERROR(name, msg) msg, 37 | #include "dexkit_error_list.h" 38 | DEXKIT_ERROR_LIST(DEXKIT_ERROR) 39 | #undef DEXKIT_ERROR_LIST 40 | #undef DEXKIT_ERROR 41 | }; 42 | 43 | constexpr size_t error_messages_size = sizeof(error_messages) / sizeof(std::string_view); 44 | 45 | inline std::string_view GetErrorMessage(Error e) { 46 | if (static_cast(e) >= error_messages_size) return ""; 47 | return error_messages[static_cast(e)]; 48 | } 49 | 50 | } // namespace dexkit -------------------------------------------------------------------------------- /Core/dexkit/include/dexkit_error_list.h: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #ifndef DEXKIT_ERROR_LIST_H 22 | #define DEXKIT_ERROR_LIST_H 23 | 24 | 25 | // V(name, msg) 26 | #define DEXKIT_ERROR_LIST(V) \ 27 | V(SUCCESS, "Success") \ 28 | V(EXPORT_DEX_FP_NULL, "Export dex file pointer is null") \ 29 | V(FILE_NOT_FOUND, "File not found") \ 30 | V(OPEN_ZIP_FILE_FAILED, "Open zip file failed") \ 31 | V(OPEN_FILE_FAILED, "Open file failed") \ 32 | V(ADD_DEX_AFTER_CROSS_BUILD, "Add dex after cross build")\ 33 | V(WRITE_FILE_INCOMPLETE, "Incomplete file written") 34 | 35 | 36 | #endif //DEXKIT_ERROR_LIST_H 37 | #undef DEXKIT_ERROR_LIST_H -------------------------------------------------------------------------------- /Core/dexkit/include/package_trie.h: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | namespace trie { 27 | 28 | const int NODE_SIZE = UINT8_MAX + 1; 29 | 30 | struct PackageTrie { 31 | std::vector> nodes; 32 | std::vector flags; 33 | 34 | PackageTrie() { 35 | nodes.emplace_back(NODE_SIZE, -1); 36 | flags.emplace_back(0); 37 | } 38 | 39 | void insert(const std::string_view word, bool is_white, bool ignore_case = false) { 40 | int currentNode = 0; 41 | 42 | for (uint8_t c : word) { 43 | if (ignore_case) { 44 | c = c >= 'A' && c <= 'Z' ? (c + 32) : c; 45 | } 46 | if (nodes[currentNode][c] == -1) { 47 | nodes[currentNode][c] = (int) nodes.size(); 48 | nodes.emplace_back(NODE_SIZE, -1); 49 | flags.emplace_back(0); 50 | } 51 | currentNode = nodes[currentNode][c]; 52 | } 53 | 54 | flags[currentNode] = flags[currentNode] | (1 << is_white); 55 | } 56 | 57 | uint8_t search(const std::string_view word, bool ignore_case = false) { 58 | int currentNode = 0; 59 | std::vector result; 60 | 61 | uint8_t flag = 0; 62 | 63 | for (uint8_t c : word) { 64 | if (ignore_case) { 65 | c = c >= 'A' && c <= 'Z' ? (c + 32) : c; 66 | } 67 | if (nodes[currentNode][c] == -1) { 68 | return flag; 69 | } 70 | currentNode = nodes[currentNode][c]; 71 | 72 | if (flags[currentNode]) { 73 | if (flags[currentNode] & 1) { 74 | flag |= 1; 75 | } 76 | if (flags[currentNode] & 2) { 77 | flag |= 2; 78 | } 79 | } 80 | } 81 | 82 | return flag; 83 | } 84 | }; 85 | 86 | } -------------------------------------------------------------------------------- /Core/dexkit/utils/byte_code_util.h: -------------------------------------------------------------------------------- 1 | // DexKit - An high-performance runtime parsing library for dex 2 | // implemented in C++. 3 | // Copyright (C) 2022-2023 LuckyPray 4 | // https://github.com/LuckyPray/DexKit 5 | // 6 | // This program is free software: you can redistribute it and/or 7 | // modify it under the terms of the GNU Lesser General Public 8 | // License as published by the Free Software Foundation, either 9 | // version 3 of the License, or (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see 18 | // . 19 | // . 20 | 21 | #pragma once 22 | 23 | #include "slicer/dex_format.h" 24 | 25 | namespace dexkit { 26 | 27 | inline dex::u4 ReadInt(const dex::u2 **ptr) { 28 | const dex::u2 *p = *ptr; 29 | int res = *p++; 30 | res |= (*p++ << 16); 31 | *ptr = p; 32 | return res; 33 | } 34 | 35 | inline dex::u4 ReadInt(const dex::u2 *ptr) { 36 | return ptr[0] | (ptr[1] << 16); 37 | } 38 | 39 | inline dex::u2 ReadShort(const dex::u2 **ptr) { 40 | const dex::u2 *p = *ptr; 41 | int res = *p++; 42 | *ptr = p; 43 | return res; 44 | } 45 | 46 | inline dex::u2 ReadShort(const dex::u2 *ptr) { 47 | return *ptr; 48 | } 49 | 50 | inline dex::u8 ReadLong(const dex::u2 **ptr) { 51 | const dex::u2 *p = *ptr; 52 | dex::u8 res = *p++; 53 | res |= ((dex::u8) *p++ << 16); 54 | res |= ((dex::u8) *p++ << 32); 55 | res |= ((dex::u8) *p++ << 48); 56 | *ptr = p; 57 | return res; 58 | } 59 | 60 | inline dex::u8 ReadLong(const dex::u2 *ptr) { 61 | return ptr[0] | ((dex::u8) ptr[1] << 16) | ((dex::u8) ptr[2] << 32) | ((dex::u8) ptr[3] << 48); 62 | } 63 | 64 | inline dex::u4 ReadULeb128(const dex::u1 **ptr) { 65 | const dex::u1 *p = *ptr; 66 | dex::u1 size = 0; 67 | dex::u4 res = 0; 68 | do { 69 | res |= (*p & 0x7f) << 7 * size++; 70 | } while ((*p++ & 0x80) == 0x80); 71 | *ptr = p; 72 | return res; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_ALLOCATOR_H_ 18 | #define FLATBUFFERS_ALLOCATOR_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | 22 | namespace flatbuffers { 23 | 24 | // Allocator interface. This is flatbuffers-specific and meant only for 25 | // `vector_downward` usage. 26 | class Allocator { 27 | public: 28 | virtual ~Allocator() {} 29 | 30 | // Allocate `size` bytes of memory. 31 | virtual uint8_t *allocate(size_t size) = 0; 32 | 33 | // Deallocate `size` bytes of memory at `p` allocated by this allocator. 34 | virtual void deallocate(uint8_t *p, size_t size) = 0; 35 | 36 | // Reallocate `new_size` bytes of memory, replacing the old region of size 37 | // `old_size` at `p`. In contrast to a normal realloc, this grows downwards, 38 | // and is intended specifcally for `vector_downward` use. 39 | // `in_use_back` and `in_use_front` indicate how much of `old_size` is 40 | // actually in use at each end, and needs to be copied. 41 | virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, 42 | size_t new_size, size_t in_use_back, 43 | size_t in_use_front) { 44 | FLATBUFFERS_ASSERT(new_size > old_size); // vector_downward only grows 45 | uint8_t *new_p = allocate(new_size); 46 | memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, 47 | in_use_front); 48 | deallocate(old_p, old_size); 49 | return new_p; 50 | } 51 | 52 | protected: 53 | // Called by `reallocate_downward` to copy memory from `old_p` of `old_size` 54 | // to `new_p` of `new_size`. Only memory of size `in_use_front` and 55 | // `in_use_back` will be copied from the front and back of the old memory 56 | // allocation. 57 | void memcpy_downward(uint8_t *old_p, size_t old_size, uint8_t *new_p, 58 | size_t new_size, size_t in_use_back, 59 | size_t in_use_front) { 60 | memcpy(new_p + new_size - in_use_back, old_p + old_size - in_use_back, 61 | in_use_back); 62 | memcpy(new_p, old_p, in_use_front); 63 | } 64 | }; 65 | 66 | } // namespace flatbuffers 67 | 68 | #endif // FLATBUFFERS_ALLOCATOR_H_ 69 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/buffer_ref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_BUFFER_REF_H_ 18 | #define FLATBUFFERS_BUFFER_REF_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | #include "flatbuffers/verifier.h" 22 | 23 | namespace flatbuffers { 24 | 25 | // Convenient way to bundle a buffer and its length, to pass it around 26 | // typed by its root. 27 | // A BufferRef does not own its buffer. 28 | struct BufferRefBase {}; // for std::is_base_of 29 | 30 | template struct BufferRef : BufferRefBase { 31 | BufferRef() : buf(nullptr), len(0), must_free(false) {} 32 | BufferRef(uint8_t *_buf, uoffset_t _len) 33 | : buf(_buf), len(_len), must_free(false) {} 34 | 35 | ~BufferRef() { 36 | if (must_free) free(buf); 37 | } 38 | 39 | const T *GetRoot() const { return flatbuffers::GetRoot(buf); } 40 | 41 | bool Verify() { 42 | Verifier verifier(buf, len); 43 | return verifier.VerifyBuffer(nullptr); 44 | } 45 | 46 | uint8_t *buf; 47 | uoffset_t len; 48 | bool must_free; 49 | }; 50 | 51 | } // namespace flatbuffers 52 | 53 | #endif // FLATBUFFERS_BUFFER_REF_H_ 54 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/default_allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_DEFAULT_ALLOCATOR_H_ 18 | #define FLATBUFFERS_DEFAULT_ALLOCATOR_H_ 19 | 20 | #include "flatbuffers/allocator.h" 21 | #include "flatbuffers/base.h" 22 | 23 | namespace flatbuffers { 24 | 25 | // DefaultAllocator uses new/delete to allocate memory regions 26 | class DefaultAllocator : public Allocator { 27 | public: 28 | uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE { 29 | return new uint8_t[size]; 30 | } 31 | 32 | void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; } 33 | 34 | static void dealloc(void *p, size_t) { delete[] static_cast(p); } 35 | }; 36 | 37 | // These functions allow for a null allocator to mean use the default allocator, 38 | // as used by DetachedBuffer and vector_downward below. 39 | // This is to avoid having a statically or dynamically allocated default 40 | // allocator, or having to move it between the classes that may own it. 41 | inline uint8_t *Allocate(Allocator *allocator, size_t size) { 42 | return allocator ? allocator->allocate(size) 43 | : DefaultAllocator().allocate(size); 44 | } 45 | 46 | inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) { 47 | if (allocator) 48 | allocator->deallocate(p, size); 49 | else 50 | DefaultAllocator().deallocate(p, size); 51 | } 52 | 53 | inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p, 54 | size_t old_size, size_t new_size, 55 | size_t in_use_back, size_t in_use_front) { 56 | return allocator ? allocator->reallocate_downward(old_p, old_size, new_size, 57 | in_use_back, in_use_front) 58 | : DefaultAllocator().reallocate_downward( 59 | old_p, old_size, new_size, in_use_back, in_use_front); 60 | } 61 | 62 | } // namespace flatbuffers 63 | 64 | #endif // FLATBUFFERS_DEFAULT_ALLOCATOR_H_ 65 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/file_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_FILE_MANAGER_H_ 18 | #define FLATBUFFERS_FILE_MANAGER_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "flatbuffers/util.h" 24 | 25 | namespace flatbuffers { 26 | 27 | // A File interface to write data to file by default or 28 | // save only file names 29 | class FileManager { 30 | public: 31 | FileManager() = default; 32 | virtual ~FileManager() = default; 33 | 34 | virtual bool SaveFile(const std::string &absolute_file_name, 35 | const std::string &content) = 0; 36 | 37 | virtual bool LoadFile(const std::string &absolute_file_name, 38 | std::string *buf) = 0; 39 | 40 | private: 41 | // Copying is not supported. 42 | FileManager(const FileManager &) = delete; 43 | FileManager &operator=(const FileManager &) = delete; 44 | }; 45 | 46 | } // namespace flatbuffers 47 | 48 | #endif // FLATBUFFERS_FILE_MANAGER_H_ 49 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/flex_flat_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_FLEX_FLAT_UTIL_H_ 18 | #define FLATBUFFERS_FLEX_FLAT_UTIL_H_ 19 | 20 | #include "flatbuffers/flatbuffers.h" 21 | #include "flatbuffers/flexbuffers.h" 22 | 23 | namespace flexbuffers { 24 | 25 | // Verifies the `nested` flexbuffer within a flatbuffer vector is valid. 26 | inline bool VerifyNestedFlexBuffer( 27 | const flatbuffers::Vector *const nested, 28 | flatbuffers::Verifier &verifier) { 29 | if (!nested) return true; 30 | return verifier.Check(flexbuffers::VerifyBuffer( 31 | nested->data(), nested->size(), verifier.GetFlexReuseTracker())); 32 | } 33 | 34 | } // namespace flexbuffers 35 | 36 | #endif // FLATBUFFERS_FLEX_FLAT_UTIL_H_ 37 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_FLATC_PCH_H_ 18 | #define FLATBUFFERS_FLATC_PCH_H_ 19 | 20 | // stl 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | // flatbuffers 33 | #include "flatbuffers/pch/pch.h" 34 | #include "flatbuffers/code_generators.h" 35 | #include "flatbuffers/flatbuffers.h" 36 | #include "flatbuffers/flexbuffers.h" 37 | #include "flatbuffers/idl.h" 38 | 39 | #endif // FLATBUFFERS_FLATC_PCH_H_ 40 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/pch/pch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_PCH_H_ 18 | #define FLATBUFFERS_PCH_H_ 19 | 20 | // stl 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | // flatbuffers 36 | #include "flatbuffers/util.h" 37 | 38 | #endif // FLATBUFFERS_PCH_H_ 39 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_STRING_H_ 18 | #define FLATBUFFERS_STRING_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | #include "flatbuffers/vector.h" 22 | 23 | namespace flatbuffers { 24 | 25 | struct String : public Vector { 26 | const char *c_str() const { return reinterpret_cast(Data()); } 27 | std::string str() const { return std::string(c_str(), size()); } 28 | 29 | // clang-format off 30 | #ifdef FLATBUFFERS_HAS_STRING_VIEW 31 | flatbuffers::string_view string_view() const { 32 | return flatbuffers::string_view(c_str(), size()); 33 | } 34 | #endif // FLATBUFFERS_HAS_STRING_VIEW 35 | // clang-format on 36 | 37 | bool operator<(const String &o) const { 38 | return StringLessThan(this->data(), this->size(), o.data(), o.size()); 39 | } 40 | }; 41 | 42 | // Convenience function to get std::string from a String returning an empty 43 | // string on null pointer. 44 | static inline std::string GetString(const String *str) { 45 | return str ? str->str() : ""; 46 | } 47 | 48 | // Convenience function to get char* from a String returning an empty string on 49 | // null pointer. 50 | static inline const char *GetCstring(const String *str) { 51 | return str ? str->c_str() : ""; 52 | } 53 | 54 | #ifdef FLATBUFFERS_HAS_STRING_VIEW 55 | // Convenience function to get string_view from a String returning an empty 56 | // string_view on null pointer. 57 | static inline flatbuffers::string_view GetStringView(const String *str) { 58 | return str ? str->string_view() : flatbuffers::string_view(); 59 | } 60 | #endif // FLATBUFFERS_HAS_STRING_VIEW 61 | 62 | } // namespace flatbuffers 63 | 64 | #endif // FLATBUFFERS_STRING_H_ 65 | -------------------------------------------------------------------------------- /Core/third_party/flatbuffers/include/flatbuffers/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 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 | #ifndef FLATBUFFERS_STRUCT_H_ 18 | #define FLATBUFFERS_STRUCT_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | 22 | namespace flatbuffers { 23 | 24 | // "structs" are flat structures that do not have an offset table, thus 25 | // always have all members present and do not support forwards/backwards 26 | // compatible extensions. 27 | 28 | class Struct FLATBUFFERS_FINAL_CLASS { 29 | public: 30 | template T GetField(uoffset_t o) const { 31 | return ReadScalar(&data_[o]); 32 | } 33 | 34 | template T GetStruct(uoffset_t o) const { 35 | return reinterpret_cast(&data_[o]); 36 | } 37 | 38 | const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; } 39 | uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; } 40 | 41 | private: 42 | // private constructor & copy constructor: you obtain instances of this 43 | // class by pointing to existing data only 44 | Struct(); 45 | Struct(const Struct &); 46 | Struct &operator=(const Struct &); 47 | 48 | uint8_t data_[1]; 49 | }; 50 | 51 | } // namespace flatbuffers 52 | 53 | #endif // FLATBUFFERS_STRUCT_H_ 54 | -------------------------------------------------------------------------------- /Core/third_party/slicer/common.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #include "slicer/common.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace slicer { 26 | 27 | // Helper for the default SLICER_CHECK() policy 28 | void _checkFailed(const char* expr, int line, const char* file) { 29 | printf("\nSLICER_CHECK failed [%s] at %s:%d\n\n", expr, file, line); 30 | abort(); 31 | } 32 | 33 | // keep track of the failures we already saw to avoid spamming with duplicates 34 | thread_local std::set> weak_failures; 35 | 36 | // Helper for the default SLICER_WEAK_CHECK() policy 37 | // 38 | // TODO: implement a modal switch (abort/continue) 39 | // 40 | void _weakCheckFailed(const char* expr, int line, const char* file) { 41 | auto failure_id = std::make_pair(line, file); 42 | if (weak_failures.find(failure_id) == weak_failures.end()) { 43 | printf("\nSLICER_WEAK_CHECK failed [%s] at %s:%d\n\n", expr, file, line); 44 | weak_failures.insert(failure_id); 45 | } 46 | } 47 | 48 | // Prints a formatted message and aborts 49 | void _fatal(const char* format, ...) { 50 | va_list args; 51 | va_start(args, format); 52 | vprintf(format, args); 53 | va_end(args); 54 | abort(); 55 | } 56 | 57 | } // namespace export 58 | -------------------------------------------------------------------------------- /Core/third_party/slicer/dex_utf8.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #include "slicer/dex_format.h" 18 | 19 | namespace dex { 20 | 21 | // Retrieve the next UTF-16 character from a UTF-8 string. 22 | // Advances "*pUtf8Ptr" to the start of the next character. 23 | // 24 | // NOTE: If a string is corrupted by dropping a '\0' in the middle 25 | // of a 3-byte sequence, you can end up overrunning the buffer with 26 | // reads (and possibly with the writes if the length was computed and 27 | // cached before the damage). For performance reasons, this function 28 | // assumes that the string being parsed is known to be valid (e.g., by 29 | // already being verified). 30 | static u2 GetUtf16FromUtf8(const char **pUtf8Ptr) { 31 | u4 one = *(*pUtf8Ptr)++; 32 | if ((one & 0x80) != 0) { 33 | // two- or three-byte encoding 34 | u4 two = *(*pUtf8Ptr)++; 35 | if ((one & 0x20) != 0) { 36 | // three-byte encoding 37 | u4 three = *(*pUtf8Ptr)++; 38 | return ((one & 0x0f) << 12) | ((two & 0x3f) << 6) | (three & 0x3f); 39 | } else { 40 | // two-byte encoding 41 | return ((one & 0x1f) << 6) | (two & 0x3f); 42 | } 43 | } else { 44 | // one-byte encoding 45 | return one; 46 | } 47 | } 48 | 49 | int Utf8Cmp(const char *s1, const char *s2) { 50 | for (;;) { 51 | if (*s1 == '\0') { 52 | if (*s2 == '\0') { 53 | return 0; 54 | } 55 | return -1; 56 | } else if (*s2 == '\0') { 57 | return 1; 58 | } 59 | 60 | int utf1 = GetUtf16FromUtf8(&s1); 61 | int utf2 = GetUtf16FromUtf8(&s2); 62 | int diff = utf1 - utf2; 63 | 64 | if (diff != 0) { 65 | return diff; 66 | } 67 | } 68 | } 69 | 70 | } // namespace dex 71 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/arrayview.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include "common.h" 20 | 21 | #include 22 | 23 | namespace slicer { 24 | 25 | // A shallow array view 26 | template 27 | class ArrayView { 28 | public: 29 | ArrayView() = default; 30 | 31 | ArrayView(const ArrayView &) = default; 32 | 33 | ArrayView &operator=(const ArrayView &) = default; 34 | 35 | ArrayView(T *ptr, size_t count) : begin_(ptr), end_(ptr + count) {} 36 | 37 | T *begin() const { return begin_; } 38 | 39 | T *end() const { return end_; } 40 | 41 | T *data() const { return begin_; } 42 | 43 | T &operator[](size_t i) const { 44 | SLICER_CHECK(i < size()); 45 | return *(begin_ + i); 46 | } 47 | 48 | [[nodiscard]] size_t size() const { return end_ - begin_; } 49 | 50 | [[nodiscard]] bool empty() const { return begin_ == end_; } 51 | 52 | private: 53 | T *begin_ = nullptr; 54 | T *end_ = nullptr; 55 | }; 56 | 57 | } // namespace export 58 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/chronometer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include 20 | 21 | namespace slicer { 22 | 23 | // A very simple timing chronometer 24 | class Chronometer { 25 | using Clock = std::chrono::high_resolution_clock; 26 | 27 | public: 28 | // elapsed time is in milliseconds 29 | explicit Chronometer(double &elapsed, bool cumulative = false) : 30 | elapsed_(elapsed), cumulative_(cumulative) { 31 | start_time_ = Clock::now(); 32 | } 33 | 34 | ~Chronometer() { 35 | Clock::time_point end_time = Clock::now(); 36 | std::chrono::duration ms = end_time - start_time_; 37 | if (cumulative_) { 38 | elapsed_ += ms.count(); 39 | } else { 40 | elapsed_ = ms.count(); 41 | } 42 | } 43 | 44 | Chronometer(const Chronometer &) = delete; 45 | 46 | Chronometer &operator=(const Chronometer &) = delete; 47 | 48 | private: 49 | double &elapsed_; 50 | Clock::time_point start_time_; 51 | bool cumulative_; 52 | }; 53 | 54 | } // namespace export 55 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | namespace slicer { 20 | 21 | // Encapsulate the runtime check and error reporting policy. 22 | // (currently a simple fail-fast but the the intention is to allow customization) 23 | void _checkFailed(const char *expr, int line, const char *file) __attribute__((noreturn)); 24 | 25 | #ifdef NDEBUG 26 | #define SLICER_CHECK(expr) 27 | #else 28 | #define SLICER_CHECK(expr) do { if(!(expr)) slicer::_checkFailed(#expr, __LINE__, __FILE__); } while(false) 29 | #endif 30 | 31 | // A modal check: if the strict mode is enabled, it behaves as a SLICER_CHECK, 32 | // otherwise it will only log a warning and continue 33 | // 34 | // NOTE: we use SLICER_WEAK_CHECK for .dex format validations that are frequently 35 | // violated by existing apps. So we need to be able to annotate these common 36 | // problems and potentially ignoring them for parity with the Android runtime. 37 | // 38 | void _weakCheckFailed(const char *expr, int line, const char *file); 39 | 40 | #ifdef NDEBUG 41 | #define SLICER_WEAK_CHECK(expr) 42 | #else 43 | #define SLICER_WEAK_CHECK(expr) do { if(!(expr)) slicer::_weakCheckFailed(#expr, __LINE__, __FILE__); } while(false) 44 | #endif 45 | 46 | // Report a fatal condition with a printf-formatted message 47 | void _fatal(const char *format, ...) __attribute__((noreturn)); 48 | 49 | #define SLICER_FATAL(format, ...) slicer::_fatal("\nSLICER_FATAL: " format "\n\n", ##__VA_ARGS__) 50 | 51 | // Annotation customization point for extra validation / state. 52 | #ifdef NDEBUG 53 | #define SLICER_EXTRA(x) 54 | #else 55 | #define SLICER_EXTRA(x) x 56 | #endif 57 | 58 | #ifndef FALLTHROUGH_INTENDED 59 | #ifdef __clang__ 60 | #define FALLTHROUGH_INTENDED [[clang::fallthrough]] 61 | #else 62 | #define FALLTHROUGH_INTENDED 63 | #endif // __clang__ 64 | #endif // FALLTHROUGH_INTENDED 65 | 66 | } // namespace export 67 | 68 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/debuginfo_encoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include "buffer.h" 20 | #include "chronometer.h" 21 | #include "common.h" 22 | #include "code_ir.h" 23 | #include "dex_ir.h" 24 | 25 | #include 26 | 27 | namespace lir { 28 | 29 | // Generates debug info from code IR 30 | class DebugInfoEncoder : public Visitor { 31 | private: 32 | bool Visit(DbgInfoHeader *dbg_header) override; 33 | 34 | bool Visit(DbgInfoAnnotation *dbg_annotation) override; 35 | 36 | public: 37 | explicit DebugInfoEncoder(const InstructionsList &instructions) 38 | : instructions_(instructions) { 39 | } 40 | 41 | ~DebugInfoEncoder() override = default; 42 | 43 | void Encode(ir::EncodedMethod *ir_method, std::shared_ptr dex_ir); 44 | 45 | private: 46 | std::vector *param_names_ = nullptr; 47 | dex::u4 line_start_ = 0; 48 | dex::u4 last_line_ = 0; 49 | dex::u4 last_address_ = 0; 50 | ir::String *source_file_ = nullptr; 51 | slicer::Buffer dbginfo_; 52 | const InstructionsList &instructions_; 53 | }; 54 | 55 | } // namespace lir 56 | 57 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/dex_utf8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include "dex_format.h" 20 | 21 | // MUTF-8 (Modified UTF-8) Encoding helpers: 22 | // https://source.android.com/devices/tech/dalvik/dex-format.html 23 | 24 | namespace dex { 25 | 26 | // Compare two '\0'-terminated modified UTF-8 strings, using Unicode 27 | // code point values for comparison. This treats different encodings 28 | // for the same code point as equivalent, except that only a real '\0' 29 | // byte is considered the string terminator. The return value is as 30 | // for strcmp(). 31 | int Utf8Cmp(const char *s1, const char *s2); 32 | 33 | } // namespace dex 34 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/index_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include "common.h" 20 | #include "dex_format.h" 21 | 22 | #include 23 | 24 | namespace ir { 25 | 26 | // A simple index tracking and allocator 27 | class IndexMap { 28 | public: 29 | dex::u4 AllocateIndex() { 30 | const auto size = indexes_map_.size(); 31 | while (alloc_pos_ < size && indexes_map_[alloc_pos_]) { 32 | ++alloc_pos_; 33 | } 34 | MarkUsedIndex(alloc_pos_); 35 | return alloc_pos_++; 36 | } 37 | 38 | void MarkUsedIndex(dex::u4 index) { 39 | if (index >= indexes_map_.size()) { 40 | indexes_map_.resize(index + 1); 41 | } 42 | SLICER_CHECK(!indexes_map_[index]); 43 | indexes_map_[index] = true; 44 | } 45 | 46 | private: 47 | std::vector indexes_map_; 48 | dex::u4 alloc_pos_ = 0; 49 | }; 50 | 51 | } // namespace ir 52 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/memview.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include "common.h" 20 | 21 | #include 22 | #include 23 | 24 | namespace slicer { 25 | 26 | // A shallow, non-owning reference to a "view" inside a memory buffer 27 | class MemView { 28 | public: 29 | MemView() : ptr_(nullptr), size_(0) {} 30 | 31 | MemView(const void *ptr, size_t size) : ptr_(ptr), size_(size) { 32 | assert(size > 0); 33 | } 34 | 35 | ~MemView() = default; 36 | 37 | template 38 | const T *ptr() const { 39 | return static_cast(ptr_); 40 | } 41 | 42 | [[nodiscard]] size_t size() const { return size_; } 43 | 44 | private: 45 | const void *ptr_; 46 | size_t size_; 47 | }; 48 | 49 | } // namespace export 50 | 51 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/scopeguard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | namespace slicer { 20 | 21 | // A simple and lightweight scope guard and macro 22 | // (inspired by Andrei Alexandrescu's C++11 Scope Guard) 23 | // 24 | // Here is how it's used: 25 | // 26 | // FILE* file = std::fopen(...); 27 | // SLICER_SCOPE_EXIT { 28 | // std::fclose(file); 29 | // }; 30 | // 31 | // "file" will be closed at the end of the enclosing scope, 32 | // regardless of how the scope is exited 33 | // 34 | class ScopeGuardHelper { 35 | template 36 | class ScopeGuard { 37 | public: 38 | explicit ScopeGuard(T closure) : 39 | closure_(std::move(closure)) { 40 | } 41 | 42 | ~ScopeGuard() { 43 | closure_(); 44 | } 45 | 46 | // move constructor only 47 | ScopeGuard(ScopeGuard &&) noexcept = default; 48 | 49 | ScopeGuard(const ScopeGuard &) = delete; 50 | 51 | ScopeGuard &operator=(const ScopeGuard &) = delete; 52 | 53 | ScopeGuard &operator=(ScopeGuard &&) = delete; 54 | 55 | private: 56 | T closure_; 57 | }; 58 | 59 | public: 60 | template 61 | ScopeGuard operator<<(T closure) { 62 | return ScopeGuard(std::move(closure)); 63 | } 64 | }; 65 | 66 | #define SLICER_SG_MACRO_CONCAT2(a, b) a ## b 67 | #define SLICER_SG_MACRO_CONCAT(a, b) SLICER_SG_MACRO_CONCAT2(a, b) 68 | #define SLICER_SG_ANONYMOUS(prefix) SLICER_SG_MACRO_CONCAT(prefix, __COUNTER__) 69 | 70 | #define SLICER_SCOPE_EXIT \ 71 | auto SLICER_SG_ANONYMOUS(_scope_guard_) = slicer::ScopeGuardHelper() << [&]() 72 | 73 | } // namespace export 74 | -------------------------------------------------------------------------------- /Core/third_party/slicer/export/slicer/tryblocks_encoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Android Open Source Project 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 | #pragma once 18 | 19 | #include "buffer.h" 20 | #include "chronometer.h" 21 | #include "code_ir.h" 22 | #include "common.h" 23 | #include "dex_ir.h" 24 | 25 | namespace lir { 26 | 27 | // Generates try/catch blocks from code IR 28 | class TryBlocksEncoder : public Visitor { 29 | private: 30 | bool Visit(TryBlockEnd *try_end) override; 31 | 32 | public: 33 | explicit TryBlocksEncoder(const InstructionsList &instructions) 34 | : instructions_(instructions) { 35 | } 36 | 37 | ~TryBlocksEncoder() override = default; 38 | 39 | void Encode(ir::Code *ir_code, std::shared_ptr dex_ir); 40 | 41 | private: 42 | slicer::Buffer handlers_; 43 | slicer::Buffer tries_; 44 | const InstructionsList &instructions_; 45 | }; 46 | 47 | } // namespace lir 48 | 49 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | kotlin_version = "1.9.20" 6 | kotlin_require_version = "1.5.0" 7 | 8 | dokka_version = "1.9.10" 9 | lint_version = "31.2.0" 10 | 11 | android_gradle_plugin = "8.2.0" 12 | } 13 | repositories { 14 | google() 15 | mavenCentral() 16 | maven { url "https://jitpack.io" } 17 | } 18 | dependencies { 19 | classpath("com.android.tools.build:gradle:$android_gradle_plugin") 20 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") 21 | } 22 | } 23 | 24 | plugins { 25 | id "com.android.application" version "$android_gradle_plugin" apply false 26 | id "com.android.library" version "$android_gradle_plugin" apply false 27 | id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false 28 | id "org.jetbrains.kotlin.jvm" version "$kotlin_version" apply false 29 | id "org.jetbrains.dokka" version "$dokka_version" apply false 30 | } 31 | 32 | tasks.register("clean", Delete) { 33 | group "build" 34 | delete rootProject.layout.buildDirectory.get() 35 | } -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("org.jetbrains.kotlin.android") 4 | } 5 | 6 | android { 7 | namespace = "org.luckypray.dexkit.demo" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | applicationId "org.luckypray.dexkit.demo" 12 | minSdk = 21 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled = true 23 | shrinkResources = true 24 | proguardFiles "proguard-rules.pro" 25 | } 26 | } 27 | 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_11 30 | targetCompatibility JavaVersion.VERSION_11 31 | } 32 | 33 | packagingOptions { 34 | jniLibs { 35 | useLegacyPackaging false 36 | } 37 | } 38 | 39 | kotlinOptions { 40 | jvmTarget = JavaVersion.VERSION_11 41 | } 42 | } 43 | 44 | dependencies { 45 | compileOnly("de.robv.android.xposed:api:82") 46 | implementation("androidx.appcompat:appcompat:1.6.1") 47 | implementation("com.google.android.material:material:1.10.0") 48 | // implementation("org.luckypray:dexkit:2.0.0") 49 | compileOnly(project(":dexkit")) 50 | implementation(project(":dexkit-android")) 51 | } 52 | -------------------------------------------------------------------------------- /demo/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | 23 | -keepattributes SourceFile 24 | -keep class * extends java.lang.annotation.Annotation {*;} 25 | -dontshrink 26 | -keep class !org.luckypray.dexkit.demo.** {*;} 27 | -keep class org.luckypray.dexkit.demo.R$* {*;} 28 | -keep class org.luckypray.dexkit.demo.** { 29 | static ; 30 | } 31 | 32 | -dontwarn javax.lang.model.element.Modifier -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /demo/src/main/java/org/luckypray/dexkit/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package org.luckypray.dexkit.demo; 2 | 3 | import android.app.Application; 4 | 5 | public class DemoApplication extends Application { 6 | 7 | private static Application sApplication; 8 | 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | RouterManager.getInstance().init(this); 13 | sApplication = this; 14 | } 15 | 16 | public static Application getApplication() { 17 | return sApplication; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /demo/src/main/java/org/luckypray/dexkit/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.luckypray.dexkit.demo; 2 | 3 | import android.os.Bundle; 4 | import android.util.Log; 5 | import android.view.View; 6 | import android.widget.Button; 7 | 8 | import androidx.appcompat.app.AppCompatActivity; 9 | 10 | import org.luckypray.dexkit.demo.annotations.Router; 11 | 12 | @Router(path = "/main") 13 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 14 | 15 | public static final String TAG = "MainActivity"; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | Log.d(TAG, "onCreate"); 22 | Button playButton = findViewById(R.id.go_play_button); 23 | playButton.setOnClickListener(this); 24 | } 25 | 26 | @Override 27 | public void onClick(View v) { 28 | Log.d(TAG, "onClick: playButton"); 29 | RouterManager.getInstance().router("/play"); 30 | } 31 | } -------------------------------------------------------------------------------- /demo/src/main/java/org/luckypray/dexkit/demo/PlayActivity.java: -------------------------------------------------------------------------------- 1 | package org.luckypray.dexkit.demo; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.HandlerThread; 6 | import android.os.Message; 7 | import android.util.Log; 8 | import android.widget.Button; 9 | import android.widget.TextView; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.appcompat.app.AppCompatActivity; 13 | 14 | import org.luckypray.dexkit.demo.annotations.Router; 15 | 16 | import java.util.Random; 17 | 18 | @Router(path = "/play") 19 | public class PlayActivity extends AppCompatActivity { 20 | 21 | private static final String TAG = "PlayActivity"; 22 | 23 | private TextView resultText; 24 | private Handler handler; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_play); 30 | Log.d(TAG, "onCreate"); 31 | 32 | HandlerThread handlerThread = new HandlerThread("PlayActivity"); 33 | handlerThread.start(); 34 | 35 | handler = new Handler(handlerThread.getLooper()) { 36 | @Override 37 | public void handleMessage(@NonNull Message msg) { 38 | super.handleMessage(msg); 39 | switch (msg.what) { 40 | case -1: 41 | System.exit(0); 42 | break; 43 | case 0: 44 | runOnUiThread(() -> rollDice(false)); 45 | break; 46 | case 114514: 47 | runOnUiThread(() -> rollDice(true)); 48 | break; 49 | } 50 | } 51 | }; 52 | 53 | resultText = findViewById(R.id.resultText); 54 | Button rollButton = findViewById(R.id.rollButton); 55 | rollButton.setOnClickListener(v -> { 56 | Log.d(TAG, "onClick: rollButton"); 57 | float r = new Random().nextFloat(); 58 | if (r < 0.01) { 59 | handler.sendEmptyMessage(-1); 60 | } else if(r < 0.987f) { 61 | handler.sendEmptyMessage(0); 62 | } else { 63 | handler.sendEmptyMessage(114514); 64 | } 65 | }); 66 | } 67 | 68 | public void rollDice(boolean jackpot) { 69 | int diceValue; 70 | if (!jackpot) { 71 | diceValue = RandomUtil.getRandomDice(); 72 | } else { 73 | diceValue = 6; 74 | } 75 | String result = "You rolled a " + diceValue; 76 | resultText.setText(result); 77 | Log.d(TAG, "rollDice: " + result); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /demo/src/main/java/org/luckypray/dexkit/demo/RandomUtil.java: -------------------------------------------------------------------------------- 1 | package org.luckypray.dexkit.demo; 2 | 3 | import android.util.Log; 4 | 5 | import java.util.Random; 6 | 7 | public abstract class RandomUtil { 8 | 9 | public static String TAG = "RandomUtil"; 10 | 11 | public static int getRandomDice() { 12 | int randValue = new Random().nextInt(6) + 1; 13 | Log.d(TAG, "getRandomDice: " + randValue); 14 | return randValue; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /demo/src/main/java/org/luckypray/dexkit/demo/RouterManager.java: -------------------------------------------------------------------------------- 1 | package org.luckypray.dexkit.demo; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | import android.content.Intent; 6 | import android.util.Log; 7 | 8 | import org.luckypray.dexkit.demo.annotations.Router; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class RouterManager { 14 | 15 | public static final String TAG = "RouterManager"; 16 | 17 | private Map map = new HashMap<>(); 18 | 19 | private static Application sApplication; 20 | 21 | private static final class Host { 22 | private static final RouterManager INSTANCE = new RouterManager(); 23 | } 24 | 25 | public void init(Application application) { 26 | sApplication = application; 27 | Host.INSTANCE.register(MainActivity.class); 28 | Host.INSTANCE.register(PlayActivity.class); 29 | } 30 | 31 | public static RouterManager getInstance() { 32 | return Host.INSTANCE; 33 | } 34 | 35 | public void register(Class clazz) { 36 | Router event = clazz.getAnnotation(Router.class); 37 | if (event != null) { 38 | Log.d(TAG, "register: " + clazz.getName() + " " + event.path()); 39 | map.put(event.path(), clazz.getName()); 40 | } 41 | } 42 | 43 | public void router(String path) { 44 | String className = map.get(path); 45 | Log.d(TAG, "router: " + className); 46 | if (className != null) { 47 | try { 48 | Class clazz = Class.forName(className); 49 | Intent intent = new Intent(Intent.ACTION_VIEW); 50 | intent.setClass(sApplication, clazz); 51 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 52 | sApplication.startActivity(intent); 53 | } catch (Exception e) { 54 | Log.e(TAG, "router error", e); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /demo/src/main/java/org/luckypray/dexkit/demo/annotations/Router.java: -------------------------------------------------------------------------------- 1 | package org.luckypray.dexkit.demo.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Router { 11 | public String path(); 12 | } 13 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 |