├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml └── misc.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── jnitraceKey.jks ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── xposed_init │ ├── cpp │ ├── CMakeLists.txt │ ├── hook │ │ ├── JnitraceForC.cpp │ │ ├── invokePrintf.cpp │ │ ├── linkerHandler.cpp │ │ └── stringHandler.cpp │ ├── includes │ │ ├── JnitraceForC.h │ │ ├── invokePrintf.h │ │ ├── linkerHandler.h │ │ └── stringHandler.h │ ├── main.cpp │ └── sec │ │ ├── CMakeLists.txt │ │ ├── Md5Utils.cpp │ │ ├── Md5Utils.h │ │ ├── cert.cpp │ │ ├── cert.h │ │ └── checkSign.cpp │ ├── java │ └── com │ │ ├── xiaoyouProject │ │ └── searchbox │ │ │ ├── SearchFragment.java │ │ │ ├── adapter │ │ │ └── SearchHistoryAdapter.java │ │ │ ├── custom │ │ │ ├── CircularRevealAnim.java │ │ │ ├── IOnItemClickListener.java │ │ │ └── IOnSearchClickListener.java │ │ │ ├── db │ │ │ └── SearchHistoryDB.java │ │ │ ├── entity │ │ │ └── CustomLink.java │ │ │ └── utils │ │ │ └── KeyBoardUtils.java │ │ └── zhenxi │ │ ├── external │ │ └── gson │ │ │ ├── DefaultDateTypeAdapter.java │ │ │ ├── ExclusionStrategy.java │ │ │ ├── FieldAttributes.java │ │ │ ├── FieldNamingPolicy.java │ │ │ ├── FieldNamingStrategy.java │ │ │ ├── Gson.java │ │ │ ├── GsonBuilder.java │ │ │ ├── InstanceCreator.java │ │ │ ├── JsonArray.java │ │ │ ├── JsonDeserializationContext.java │ │ │ ├── JsonDeserializer.java │ │ │ ├── JsonElement.java │ │ │ ├── JsonIOException.java │ │ │ ├── JsonNull.java │ │ │ ├── JsonObject.java │ │ │ ├── JsonParseException.java │ │ │ ├── JsonParser.java │ │ │ ├── JsonPrimitive.java │ │ │ ├── JsonSerializationContext.java │ │ │ ├── JsonSerializer.java │ │ │ ├── JsonStreamParser.java │ │ │ ├── JsonSyntaxException.java │ │ │ ├── LongSerializationPolicy.java │ │ │ ├── TypeAdapter.java │ │ │ ├── TypeAdapterFactory.java │ │ │ ├── annotations │ │ │ ├── Expose.java │ │ │ ├── JsonAdapter.java │ │ │ ├── SerializedName.java │ │ │ ├── Since.java │ │ │ ├── Until.java │ │ │ └── package-info.java │ │ │ ├── internal │ │ │ ├── $Gson$Preconditions.java │ │ │ ├── $Gson$Types.java │ │ │ ├── ConstructorConstructor.java │ │ │ ├── Excluder.java │ │ │ ├── JavaVersion.java │ │ │ ├── JsonReaderInternalAccess.java │ │ │ ├── LazilyParsedNumber.java │ │ │ ├── LinkedHashTreeMap.java │ │ │ ├── LinkedTreeMap.java │ │ │ ├── ObjectConstructor.java │ │ │ ├── PreJava9DateFormatProvider.java │ │ │ ├── Primitives.java │ │ │ ├── Streams.java │ │ │ ├── UnsafeAllocator.java │ │ │ ├── bind │ │ │ │ ├── ArrayTypeAdapter.java │ │ │ │ ├── CollectionTypeAdapterFactory.java │ │ │ │ ├── DateTypeAdapter.java │ │ │ │ ├── JsonAdapterAnnotationTypeAdapterFactory.java │ │ │ │ ├── JsonTreeReader.java │ │ │ │ ├── JsonTreeWriter.java │ │ │ │ ├── MapTypeAdapterFactory.java │ │ │ │ ├── ObjectTypeAdapter.java │ │ │ │ ├── ReflectiveTypeAdapterFactory.java │ │ │ │ ├── SqlDateTypeAdapter.java │ │ │ │ ├── TimeTypeAdapter.java │ │ │ │ ├── TreeTypeAdapter.java │ │ │ │ ├── TypeAdapterRuntimeTypeWrapper.java │ │ │ │ ├── TypeAdapters.java │ │ │ │ └── util │ │ │ │ │ └── ISO8601Utils.java │ │ │ ├── package-info.java │ │ │ └── reflect │ │ │ │ ├── PreJava9ReflectionAccessor.java │ │ │ │ ├── ReflectionAccessor.java │ │ │ │ └── UnsafeReflectionAccessor.java │ │ │ ├── package-info.java │ │ │ ├── reflect │ │ │ ├── TypeToken.java │ │ │ └── package-info.java │ │ │ └── stream │ │ │ ├── JsonReader.java │ │ │ ├── JsonScope.java │ │ │ ├── JsonToken.java │ │ │ ├── JsonWriter.java │ │ │ └── MalformedJsonException.java │ │ └── jnitrace │ │ ├── App.java │ │ ├── LHook.java │ │ ├── MainActivity.java │ │ ├── adapter │ │ └── MainListViewAdapter.java │ │ ├── bean │ │ └── AppBean.java │ │ ├── config │ │ └── ConfigKey.java │ │ ├── utils │ │ ├── AES.java │ │ ├── CLog.java │ │ ├── ChooseUtils.java │ │ ├── ClassUtils.java │ │ ├── Constants.java │ │ ├── ContextUtils.java │ │ ├── FileUtils.java │ │ ├── GsonUtils.java │ │ ├── HookServer.java │ │ ├── HookSpUtil.java │ │ ├── IntoMySoUtils.java │ │ ├── PermissionUtils.java │ │ ├── RootUtils.java │ │ ├── SpUtil.java │ │ ├── ThreadUtils.java │ │ ├── ToastUtils.java │ │ ├── UnZipUtils.java │ │ └── XposedRandomDevcies.java │ │ └── view │ │ └── Xiaomiquan.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── ic_back_24dp.xml │ ├── ic_close_16dp.xml │ ├── ic_history_24dp.xml │ ├── ic_launcher_background.xml │ ├── ic_link.xml │ ├── ic_search_24dp.xml │ ├── ic_search_bg_24dp.xml │ ├── iocn.jpg │ ├── menu.png │ ├── search.png │ ├── shape_corner_white.xml │ ├── stop.png │ └── xiaomiquan.png │ ├── layout │ ├── activity_list_item.xml │ ├── activity_main.xml │ ├── activity_xiaomiquan.xml │ ├── content_xiaomiquan.xml │ ├── dialog_input.xml │ ├── dialog_search.xml │ ├── item_search_history.xml │ └── item_search_link.xml │ ├── menu │ └── main_activity.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── nativeLib ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── cpp │ ├── CMakeLists.txt │ ├── adapter │ │ ├── CMakeLists.txt │ │ └── adapter.cpp │ ├── dlfc │ │ ├── CMakeLists.txt │ │ ├── dlfcn_compat.cpp │ │ ├── dlfcn_nougat.cpp │ │ └── elf_util.cpp │ ├── hook │ │ ├── CMakeLists.txt │ │ ├── Dobby │ │ │ ├── .clang-format │ │ │ ├── CMakeLists.txt │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── README_zh-cn.md │ │ │ ├── builtin-plugin │ │ │ │ ├── ApplicationEventMonitor │ │ │ │ │ ├── MGCopyAnswerMonitor.cc │ │ │ │ │ ├── dynamic_loader_monitor.cc │ │ │ │ │ ├── file_operation_monitor.cc │ │ │ │ │ ├── memory_operation_instrument.cc │ │ │ │ │ ├── posix_file_descriptor_operation_monitor.cc │ │ │ │ │ └── posix_socket_network_monitor.cc │ │ │ │ ├── BionicLinkerUtil │ │ │ │ │ ├── bionic_linker_demo.cc │ │ │ │ │ ├── bionic_linker_util.cc │ │ │ │ │ └── bionic_linker_util.h │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── ImportTableReplace │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── dobby_import_replace.cc │ │ │ │ │ └── dobby_import_replace.h │ │ │ │ ├── ObjcRuntimeReplace │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── objc_runtime_repalce.h │ │ │ │ │ └── objc_runtime_replace.mm │ │ │ │ ├── SupervisorCallMonitor │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── README │ │ │ │ │ ├── mach_system_call_log_handler.cc │ │ │ │ │ ├── misc_utility.cc │ │ │ │ │ ├── misc_utility.h │ │ │ │ │ ├── sensitive_api_monitor.cc │ │ │ │ │ ├── supervisor_call_monitor.cc │ │ │ │ │ ├── supervisor_call_monitor.h │ │ │ │ │ ├── system_call_log_handler.cc │ │ │ │ │ └── test_supervisor_call_monitor.cc │ │ │ │ └── SymbolResolver │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── dobby_symbol_resolver.h │ │ │ │ │ ├── elf │ │ │ │ │ └── dobby_symbol_resolver.cc │ │ │ │ │ ├── macho │ │ │ │ │ ├── dobby_symbol_resolver.cc │ │ │ │ │ ├── dobby_symbol_resolver_priv.h │ │ │ │ │ ├── dyld_shared_cache_symbol_table_iterator.cc │ │ │ │ │ ├── shared-cache │ │ │ │ │ │ └── dyld_cache_format.h │ │ │ │ │ └── shared_cache_internal.h │ │ │ │ │ └── pe │ │ │ │ │ └── dobby_symbol_resolver.cc │ │ │ ├── cmake │ │ │ │ ├── Macros.cmake │ │ │ │ ├── Util.cmake │ │ │ │ ├── auto_source_group.cmake │ │ │ │ ├── build_environment_check.cmake │ │ │ │ ├── compiler_and_linker.cmake │ │ │ │ ├── dobby.xcode.source.cmake │ │ │ │ ├── platform │ │ │ │ │ └── platform-darwin.cmake │ │ │ │ └── xcode_generator_helper.cmake │ │ │ ├── docs │ │ │ │ └── compile.md │ │ │ ├── examples │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── main.cc │ │ │ │ └── socket_example.cc │ │ │ ├── external │ │ │ │ ├── TINYSTL │ │ │ │ │ ├── allocator.h │ │ │ │ │ ├── buffer.h │ │ │ │ │ ├── hash.h │ │ │ │ │ ├── hash_base.h │ │ │ │ │ ├── new.h │ │ │ │ │ ├── stddef.h │ │ │ │ │ ├── string.h │ │ │ │ │ ├── string_view.h │ │ │ │ │ ├── traits.h │ │ │ │ │ ├── unordered_map.h │ │ │ │ │ ├── unordered_set.h │ │ │ │ │ └── vector.h │ │ │ │ ├── deprecated │ │ │ │ │ └── misc-helper │ │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ │ ├── async_logger.cc │ │ │ │ │ │ ├── deprecated │ │ │ │ │ │ ├── pthread_helper.cc │ │ │ │ │ │ ├── pthread_helper.h │ │ │ │ │ │ └── unistd_helper.h │ │ │ │ │ │ ├── format_printer.cc │ │ │ │ │ │ ├── misc-helper │ │ │ │ │ │ ├── async_logger.h │ │ │ │ │ │ ├── format_printer.h │ │ │ │ │ │ └── variable_cache.h │ │ │ │ │ │ └── variable_cache.c │ │ │ │ ├── logging │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── cxxlogging.cc │ │ │ │ │ ├── kernel_logging.c │ │ │ │ │ ├── logging.c │ │ │ │ │ └── logging │ │ │ │ │ │ ├── check_logging.h │ │ │ │ │ │ ├── cxxlogging.h │ │ │ │ │ │ └── logging.h │ │ │ │ └── misc-helper │ │ │ │ │ ├── CMakeLists.txt │ │ │ │ │ ├── async_logger.cc │ │ │ │ │ ├── deprecated │ │ │ │ │ ├── pthread_helper.cc │ │ │ │ │ ├── pthread_helper.h │ │ │ │ │ └── unistd_helper.h │ │ │ │ │ ├── format_printer.cc │ │ │ │ │ ├── misc-helper │ │ │ │ │ ├── async_logger.h │ │ │ │ │ ├── format_printer.h │ │ │ │ │ └── variable_cache.h │ │ │ │ │ └── variable_cache.c │ │ │ ├── include │ │ │ │ └── dobby.h │ │ │ ├── scripts │ │ │ │ ├── Dockerfile │ │ │ │ ├── platform_builder.py │ │ │ │ ├── setup_linux_cross_compile.sh │ │ │ │ └── setup_macos_cross_compile.sh │ │ │ ├── source │ │ │ │ ├── Backend │ │ │ │ │ ├── KernelMode │ │ │ │ │ │ ├── ExecMemory │ │ │ │ │ │ │ ├── clear-cache-tool-all.c │ │ │ │ │ │ │ └── code-patch-tool-darwin.cc │ │ │ │ │ │ ├── PlatformUtil │ │ │ │ │ │ │ ├── Darwin │ │ │ │ │ │ │ │ └── ProcessRuntimeUtility.cc │ │ │ │ │ │ │ └── ProcessRuntimeUtility.h │ │ │ │ │ │ └── UnifiedInterface │ │ │ │ │ │ │ ├── exec_mem_placeholder.asm │ │ │ │ │ │ │ ├── platform-darwin.cc │ │ │ │ │ │ │ └── platform.h │ │ │ │ │ └── UserMode │ │ │ │ │ │ ├── ExecMemory │ │ │ │ │ │ ├── clear-cache-tool-all.c │ │ │ │ │ │ ├── clear-cache-tool │ │ │ │ │ │ │ ├── clear-cache-tool-arm-dummy.cc │ │ │ │ │ │ │ └── clear-cache-tool-arm64-dummy.cc │ │ │ │ │ │ ├── code-patch-tool-darwin.cc │ │ │ │ │ │ ├── code-patch-tool-posix.cc │ │ │ │ │ │ ├── code-patch-tool-windows.cc │ │ │ │ │ │ └── substrated │ │ │ │ │ │ │ ├── include │ │ │ │ │ │ │ ├── bootstrap.h │ │ │ │ │ │ │ └── xpc │ │ │ │ │ │ │ │ └── base.h │ │ │ │ │ │ │ └── mach_interface_support │ │ │ │ │ │ │ ├── substrated.defs │ │ │ │ │ │ │ ├── substrated_client.c │ │ │ │ │ │ │ ├── substrated_client.h │ │ │ │ │ │ │ ├── substrated_server.c │ │ │ │ │ │ │ └── substrated_server.h │ │ │ │ │ │ ├── MultiThreadSupport │ │ │ │ │ │ ├── ThreadSupport.cpp │ │ │ │ │ │ └── ThreadSupport.h │ │ │ │ │ │ ├── PlatformUtil │ │ │ │ │ │ ├── Darwin │ │ │ │ │ │ │ └── ProcessRuntimeUtility.cc │ │ │ │ │ │ ├── Linux │ │ │ │ │ │ │ └── ProcessRuntimeUtility.cc │ │ │ │ │ │ ├── ProcessRuntimeUtility.h │ │ │ │ │ │ └── Windows │ │ │ │ │ │ │ └── ProcessRuntimeUtility.cc │ │ │ │ │ │ ├── Thread │ │ │ │ │ │ ├── PlatformThread.cc │ │ │ │ │ │ ├── PlatformThread.h │ │ │ │ │ │ ├── platform-thread-posix.cc │ │ │ │ │ │ └── platform-thread-windows.cc │ │ │ │ │ │ └── UnifiedInterface │ │ │ │ │ │ ├── platform-darwin │ │ │ │ │ │ └── mach_vm.h │ │ │ │ │ │ ├── platform-posix.cc │ │ │ │ │ │ ├── platform-windows.cc │ │ │ │ │ │ ├── platform.h │ │ │ │ │ │ ├── semaphore.cc │ │ │ │ │ │ └── semaphore.h │ │ │ │ ├── InstructionRelocation │ │ │ │ │ ├── InstructionRelocation.h │ │ │ │ │ ├── arm │ │ │ │ │ │ ├── InstructionRelocationARM.cc │ │ │ │ │ │ └── InstructionRelocationARM.h │ │ │ │ │ ├── arm64 │ │ │ │ │ │ ├── InstructionRelocationARM64.cc │ │ │ │ │ │ ├── InstructionRelocationARM64.h │ │ │ │ │ │ ├── inst_constants.h │ │ │ │ │ │ └── inst_decode_encode_kit.h │ │ │ │ │ ├── x64 │ │ │ │ │ │ ├── InstructionRelocationX64.cc │ │ │ │ │ │ └── InstructionRelocationX64.h │ │ │ │ │ └── x86 │ │ │ │ │ │ ├── InstructionRelocationX86.cc │ │ │ │ │ │ ├── InstructionRelocationX86.h │ │ │ │ │ │ ├── InstructionRelocationX86Shared.cc │ │ │ │ │ │ ├── InstructionRelocationX86Shared.h │ │ │ │ │ │ ├── deprecated │ │ │ │ │ │ ├── Ia32Disassembler.cc │ │ │ │ │ │ ├── X86OpcodoDecodeTable.cc │ │ │ │ │ │ └── X86OpcodoDecodeTable.h │ │ │ │ │ │ └── x86_insn_decode │ │ │ │ │ │ ├── build_config.h │ │ │ │ │ │ ├── x86_insn_decode.c │ │ │ │ │ │ ├── x86_insn_decode.h │ │ │ │ │ │ ├── x86_insn_reader.c │ │ │ │ │ │ ├── x86_opcode_modrm_reg_group.c │ │ │ │ │ │ ├── x86_opcode_one_byte.c │ │ │ │ │ │ ├── x86_opcode_sse_group.c │ │ │ │ │ │ └── x86_opcode_two_byte.c │ │ │ │ ├── InterceptEntry.cpp │ │ │ │ ├── InterceptEntry.h │ │ │ │ ├── InterceptRouting │ │ │ │ │ ├── InterceptRouting.cpp │ │ │ │ │ ├── InterceptRouting.h │ │ │ │ │ ├── Routing │ │ │ │ │ │ ├── FunctionInlineHook │ │ │ │ │ │ │ ├── FunctionInlineHook.cc │ │ │ │ │ │ │ ├── FunctionInlineHookRouting.h │ │ │ │ │ │ │ └── RoutingImpl.cc │ │ │ │ │ │ ├── FunctionWrapper │ │ │ │ │ │ │ ├── FunctionWrapperExport.cc │ │ │ │ │ │ │ ├── function-wrapper.cc │ │ │ │ │ │ │ ├── function-wrapper.h │ │ │ │ │ │ │ ├── intercept_routing_handler.cc │ │ │ │ │ │ │ └── intercept_routing_handler.h │ │ │ │ │ │ └── InstructionInstrument │ │ │ │ │ │ │ ├── InstructionInstrument.cc │ │ │ │ │ │ │ ├── InstructionInstrumentRouting.h │ │ │ │ │ │ │ ├── RoutingImpl.cc │ │ │ │ │ │ │ ├── instrument_routing_handler.cc │ │ │ │ │ │ │ └── instrument_routing_handler.h │ │ │ │ │ └── RoutingPlugin │ │ │ │ │ │ ├── NearBranchTrampoline │ │ │ │ │ │ ├── NearBranchTrampoline.cc │ │ │ │ │ │ ├── NearBranchTrampoline.h │ │ │ │ │ │ └── near_trampoline_arm64.cc │ │ │ │ │ │ ├── RoutingPlugin.cc │ │ │ │ │ │ └── RoutingPlugin.h │ │ │ │ ├── Interceptor.cpp │ │ │ │ ├── Interceptor.h │ │ │ │ ├── MemoryAllocator │ │ │ │ │ ├── AssemblyCodeBuilder.cc │ │ │ │ │ ├── AssemblyCodeBuilder.h │ │ │ │ │ ├── CodeBuffer │ │ │ │ │ │ ├── CodeBufferBase.cc │ │ │ │ │ │ ├── CodeBufferBase.h │ │ │ │ │ │ ├── code-buffer-arm.h │ │ │ │ │ │ ├── code-buffer-arm64.h │ │ │ │ │ │ ├── code-buffer-x64.h │ │ │ │ │ │ ├── code-buffer-x86.cc │ │ │ │ │ │ ├── code-buffer-x86.h │ │ │ │ │ │ ├── code_buffer_arm.h │ │ │ │ │ │ ├── code_buffer_arm64.h │ │ │ │ │ │ ├── code_buffer_x64.h │ │ │ │ │ │ └── code_buffer_x86.h │ │ │ │ │ ├── MemoryAllocator.cc │ │ │ │ │ ├── NearMemoryAllocator.cc │ │ │ │ │ └── NearMemoryAllocator.h │ │ │ │ ├── PlatformUnifiedInterface │ │ │ │ │ ├── ExecMemory │ │ │ │ │ │ ├── ClearCacheTool.h │ │ │ │ │ │ └── CodePatchTool.h │ │ │ │ │ └── MemoryAllocator.h │ │ │ │ ├── TrampolineBridge │ │ │ │ │ ├── ClosureTrampolineBridge │ │ │ │ │ │ ├── ClosureTrampoline.h │ │ │ │ │ │ ├── arm │ │ │ │ │ │ │ ├── ClosureTrampolineARM.cc │ │ │ │ │ │ │ ├── closure_bridge_arm.cc │ │ │ │ │ │ │ ├── dummy │ │ │ │ │ │ │ │ ├── closure-bridge-template-arm.cc │ │ │ │ │ │ │ │ └── closure-trampoline-template-arm.S │ │ │ │ │ │ │ └── helper_arm.cc │ │ │ │ │ │ ├── arm64 │ │ │ │ │ │ │ ├── ClosureTrampolineARM64.cc │ │ │ │ │ │ │ ├── closure_bridge_arm64.cc │ │ │ │ │ │ │ ├── dummy │ │ │ │ │ │ │ │ ├── closure-bridge-template-arm64.c │ │ │ │ │ │ │ │ ├── closure-trampoline-template-arm64.S │ │ │ │ │ │ │ │ └── dynamic-closure-trampoline-template-arm64.S │ │ │ │ │ │ │ └── helper_arm64.cc │ │ │ │ │ │ ├── common_bridge_handler.cc │ │ │ │ │ │ ├── common_bridge_handler.h │ │ │ │ │ │ ├── x64 │ │ │ │ │ │ │ ├── ClosureTrampolineX64.cc │ │ │ │ │ │ │ ├── closure_bridge_x64.cc │ │ │ │ │ │ │ ├── dummy │ │ │ │ │ │ │ │ ├── closure-bridge-template-x64.c │ │ │ │ │ │ │ │ └── closure-trampoline-template-x64.S │ │ │ │ │ │ │ └── helper_x64.cc │ │ │ │ │ │ └── x86 │ │ │ │ │ │ │ ├── ClosureTrampolineX86.cc │ │ │ │ │ │ │ ├── closure_bridge_x86.cc │ │ │ │ │ │ │ └── helper_x86.cc │ │ │ │ │ └── Trampoline │ │ │ │ │ │ ├── Trampoline.h │ │ │ │ │ │ ├── arm │ │ │ │ │ │ └── trampoline_arm.cc │ │ │ │ │ │ ├── arm64 │ │ │ │ │ │ └── trampoline_arm64.cc │ │ │ │ │ │ ├── x64 │ │ │ │ │ │ └── trampoline_x64.cc │ │ │ │ │ │ └── x86 │ │ │ │ │ │ └── trampoline_x86.cc │ │ │ │ ├── core │ │ │ │ │ ├── arch │ │ │ │ │ │ ├── Cpu.cc │ │ │ │ │ │ ├── Cpu.h │ │ │ │ │ │ ├── CpuFeature.cc │ │ │ │ │ │ ├── CpuFeature.h │ │ │ │ │ │ ├── CpuRegister.cc │ │ │ │ │ │ ├── CpuRegister.h │ │ │ │ │ │ ├── CpuUtils.h │ │ │ │ │ │ ├── arm │ │ │ │ │ │ │ ├── constants-arm.h │ │ │ │ │ │ │ └── registers-arm.h │ │ │ │ │ │ ├── arm64 │ │ │ │ │ │ │ ├── constants-arm64.h │ │ │ │ │ │ │ └── registers-arm64.h │ │ │ │ │ │ ├── x64 │ │ │ │ │ │ │ ├── constants-x64.h │ │ │ │ │ │ │ └── registers-x64.h │ │ │ │ │ │ └── x86 │ │ │ │ │ │ │ ├── constants-x86.h │ │ │ │ │ │ │ ├── cpu-x86.cc │ │ │ │ │ │ │ ├── cpu-x86.h │ │ │ │ │ │ │ └── registers-x86.h │ │ │ │ │ ├── assembler │ │ │ │ │ │ ├── AssemblerPseudoLabel.h │ │ │ │ │ │ ├── assembler-arch.h │ │ │ │ │ │ ├── assembler-arm.cc │ │ │ │ │ │ ├── assembler-arm.h │ │ │ │ │ │ ├── assembler-arm64.cc │ │ │ │ │ │ ├── assembler-arm64.h │ │ │ │ │ │ ├── assembler-ia32.cc │ │ │ │ │ │ ├── assembler-ia32.h │ │ │ │ │ │ ├── assembler-x64.cc │ │ │ │ │ │ ├── assembler-x64.h │ │ │ │ │ │ ├── assembler-x86-shared.cc │ │ │ │ │ │ ├── assembler-x86-shared.h │ │ │ │ │ │ ├── assembler.cc │ │ │ │ │ │ └── assembler.h │ │ │ │ │ ├── codegen │ │ │ │ │ │ ├── codegen-arm.cc │ │ │ │ │ │ ├── codegen-arm.h │ │ │ │ │ │ ├── codegen-arm64.cc │ │ │ │ │ │ ├── codegen-arm64.h │ │ │ │ │ │ ├── codegen-ia32.cc │ │ │ │ │ │ ├── codegen-ia32.h │ │ │ │ │ │ ├── codegen-x64.cc │ │ │ │ │ │ ├── codegen-x64.h │ │ │ │ │ │ └── codegen.h │ │ │ │ │ └── emulator │ │ │ │ │ │ └── dummy.cc │ │ │ │ ├── dobby.cpp │ │ │ │ ├── dobby_internal.h │ │ │ │ └── include │ │ │ │ │ ├── common_header.h │ │ │ │ │ ├── kernel_mode_header.h │ │ │ │ │ ├── list_c.h │ │ │ │ │ ├── platform_header.h │ │ │ │ │ ├── platform_macro.h │ │ │ │ │ ├── type_header.h │ │ │ │ │ └── utility_macro.h │ │ │ └── tests │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── UniconEmulator.cpp │ │ │ │ ├── UniconEmulator.h │ │ │ │ ├── test_insn_decoder_x86.cpp │ │ │ │ ├── test_insn_relo_arm.cpp │ │ │ │ ├── test_insn_relo_arm64.cpp │ │ │ │ ├── test_insn_relo_x64.cpp │ │ │ │ └── test_native.cpp │ │ ├── HookUtils.cpp │ │ └── signhook │ │ │ ├── CMakeLists.txt │ │ │ ├── common │ │ │ ├── base.h │ │ │ ├── compiler.h │ │ │ ├── cow_vector.h │ │ │ ├── dlfcn_nougat.cc │ │ │ ├── dlfcn_nougat.h │ │ │ ├── elf.cpp │ │ │ ├── elf.h │ │ │ ├── elf_util.cc │ │ │ ├── elf_util.h │ │ │ ├── log.h │ │ │ ├── types.cc │ │ │ └── types.h │ │ │ ├── exts │ │ │ ├── distorm │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── config.h │ │ │ │ ├── decoder.c │ │ │ │ ├── decoder.h │ │ │ │ ├── distorm.c │ │ │ │ ├── distorm.h │ │ │ │ ├── instructions.c │ │ │ │ ├── instructions.h │ │ │ │ ├── insts.c │ │ │ │ ├── insts.h │ │ │ │ ├── mnemonics.c │ │ │ │ ├── mnemonics.h │ │ │ │ ├── operands.c │ │ │ │ ├── operands.h │ │ │ │ ├── prefix.c │ │ │ │ ├── prefix.h │ │ │ │ ├── textdefs.c │ │ │ │ ├── textdefs.h │ │ │ │ ├── wstring.c │ │ │ │ ├── wstring.h │ │ │ │ └── x86defs.h │ │ │ ├── ucontext │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── aarch64 │ │ │ │ │ ├── common │ │ │ │ │ │ └── sysdep.h │ │ │ │ │ ├── config.h │ │ │ │ │ ├── getcontext.S │ │ │ │ │ ├── kernel_rt_sigframe.h │ │ │ │ │ ├── libc-symbols.h │ │ │ │ │ ├── makecontext.c │ │ │ │ │ ├── setcontext.S │ │ │ │ │ ├── swapcontext.S │ │ │ │ │ ├── sysdep.c │ │ │ │ │ ├── sysdep.h │ │ │ │ │ ├── ucontext-internal.h │ │ │ │ │ ├── ucontext_i.h │ │ │ │ │ └── ucontext_i.sym │ │ │ │ ├── arm │ │ │ │ │ ├── arm_bx.h │ │ │ │ │ ├── common │ │ │ │ │ │ └── sysdep.h │ │ │ │ │ ├── getcontext.S │ │ │ │ │ ├── makecontext.c │ │ │ │ │ ├── scripts │ │ │ │ │ │ └── gen-as-const.awk │ │ │ │ │ ├── setcontext.S │ │ │ │ │ ├── swapcontext.S │ │ │ │ │ ├── sysdep.h │ │ │ │ │ ├── ucontext.mk │ │ │ │ │ ├── ucontext_i.h │ │ │ │ │ └── ucontext_i.sym │ │ │ │ ├── breakpad_getcontext.S │ │ │ │ └── ucontext_constants.h │ │ │ └── vixl │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── aarch32 │ │ │ │ ├── assembler-aarch32.cc │ │ │ │ ├── assembler-aarch32.h │ │ │ │ ├── constants-aarch32.cc │ │ │ │ ├── constants-aarch32.h │ │ │ │ ├── disasm-aarch32.cc │ │ │ │ ├── disasm-aarch32.h │ │ │ │ ├── instructions-aarch32.cc │ │ │ │ ├── instructions-aarch32.h │ │ │ │ ├── location-aarch32.cc │ │ │ │ ├── location-aarch32.h │ │ │ │ ├── macro-assembler-aarch32.cc │ │ │ │ ├── macro-assembler-aarch32.h │ │ │ │ ├── operands-aarch32.cc │ │ │ │ └── operands-aarch32.h │ │ │ │ ├── aarch64 │ │ │ │ ├── abi-aarch64.h │ │ │ │ ├── assembler-aarch64.cc │ │ │ │ ├── assembler-aarch64.h │ │ │ │ ├── constants-aarch64.h │ │ │ │ ├── cpu-aarch64.cc │ │ │ │ ├── cpu-aarch64.h │ │ │ │ ├── cpu-features-auditor-aarch64.cc │ │ │ │ ├── cpu-features-auditor-aarch64.h │ │ │ │ ├── decoder-aarch64.cc │ │ │ │ ├── decoder-aarch64.h │ │ │ │ ├── decoder-constants-aarch64.h │ │ │ │ ├── disasm-aarch64.cc │ │ │ │ ├── disasm-aarch64.h │ │ │ │ ├── instructions-aarch64.cc │ │ │ │ ├── instructions-aarch64.h │ │ │ │ ├── instrument-aarch64.cc │ │ │ │ ├── instrument-aarch64.h │ │ │ │ ├── logic-aarch64.cc │ │ │ │ ├── macro-assembler-aarch64.cc │ │ │ │ ├── macro-assembler-aarch64.h │ │ │ │ ├── operands-aarch64.cc │ │ │ │ ├── operands-aarch64.h │ │ │ │ ├── pointer-auth-aarch64.cc │ │ │ │ ├── simulator-aarch64.cc │ │ │ │ ├── simulator-aarch64.h │ │ │ │ └── simulator-constants-aarch64.h │ │ │ │ ├── assembler-base-vixl.h │ │ │ │ ├── code-buffer-vixl.cc │ │ │ │ ├── code-buffer-vixl.h │ │ │ │ ├── code-generation-scopes-vixl.h │ │ │ │ ├── compiler-intrinsics-vixl.cc │ │ │ │ ├── compiler-intrinsics-vixl.h │ │ │ │ ├── cpu-features.cc │ │ │ │ ├── cpu-features.h │ │ │ │ ├── globals-vixl.h │ │ │ │ ├── invalset-vixl.h │ │ │ │ ├── macro-assembler-interface.h │ │ │ │ ├── platform-vixl.h │ │ │ │ ├── pool-manager-impl.h │ │ │ │ ├── pool-manager.h │ │ │ │ ├── utils-vixl.cc │ │ │ │ └── utils-vixl.h │ │ │ ├── include │ │ │ └── inline_hook.h │ │ │ ├── inline │ │ │ ├── arm32 │ │ │ │ └── inline_hook_arm32.cpp │ │ │ ├── arm64 │ │ │ │ └── inline_hook_arm64.cc │ │ │ └── inline_hook.cc │ │ │ ├── instrcache │ │ │ ├── arm32 │ │ │ │ ├── translator.cc │ │ │ │ └── translator.h │ │ │ ├── arm64 │ │ │ │ ├── translator.cc │ │ │ │ └── translator.h │ │ │ └── instr_cache.h │ │ │ ├── memory │ │ │ ├── code_buffer.cc │ │ │ └── code_buffer.h │ │ │ └── platform │ │ │ ├── memory.cc │ │ │ └── memory.h │ ├── includes │ │ ├── AllInclude.h │ │ ├── HookClassUtils.h │ │ ├── HookUtils.h │ │ ├── MMKV.h │ │ ├── MapItemInfo.h │ │ ├── ZhenxiLog.h │ │ ├── adapter.h │ │ ├── appUtils.h │ │ ├── arch.h │ │ ├── dlfcn_compat.h │ │ ├── dlfcn_nougat.h │ │ ├── elf_util.h │ │ ├── fileUtils.h │ │ ├── libpath.h │ │ ├── logging.h │ │ ├── macros.h │ │ ├── mylibc.h │ │ ├── parse.h │ │ ├── raw_syscall.h │ │ ├── stringUtils.h │ │ └── version.h │ ├── libpath │ │ ├── CMakeLists.txt │ │ └── libpath.cpp │ ├── raw_syscall │ │ ├── CMakeLists.txt │ │ ├── syscall32.S │ │ └── syscall64.S │ └── utils │ │ ├── CMakeLists.txt │ │ ├── appUtils.cpp │ │ ├── fileUtils.cpp │ │ ├── parse.cpp │ │ └── stringUtils.cpp │ └── res │ └── values │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/README.md -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/jnitraceKey.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/jnitraceKey.jks -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | 3 | -keep public class com.zhenxi.jnitrace.LHook 4 | 5 | -keep public class com.zhenxi.jnitrace.MainActivity 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/assets/xposed_init: -------------------------------------------------------------------------------- 1 | com.zhenxi.jnitrace.LHook -------------------------------------------------------------------------------- /app/src/main/cpp/includes/JnitraceForC.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef QCONTAINER_PRO_APPUTILS_H 4 | #define QCONTAINER_PRO_APPUTILS_H 5 | 6 | #include "AllInclude.h" 7 | 8 | 9 | 10 | typedef size_t Addr; 11 | 12 | 13 | class Jnitrace { 14 | public: 15 | /** 16 | * start jni trace 17 | * 18 | * @param env jniEnv 19 | * @param hookAll lister all so jni 20 | * @param forbid_list not lister so list 21 | * @param filter_list lister so list 22 | * @param os using the list to save the entire collection, 23 | * the jnitrace only handles the so name inside the list 。 24 | * No file save occurs if os == nullptr 25 | */ 26 | static void startjnitrace(JNIEnv *env, 27 | bool hookAll, 28 | const std::list &forbid_list, 29 | const std::list &filter_list, 30 | std::ofstream * os); 31 | 32 | /** 33 | * stop jni trace 34 | */ 35 | [[maybe_unused]] static void stopjnitrace(); 36 | 37 | private: 38 | static void init(JNIEnv *env); 39 | }; 40 | 41 | 42 | #endif //QCONTAINER_PRO_APPUTILS_H 43 | -------------------------------------------------------------------------------- /app/src/main/cpp/includes/invokePrintf.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2022/2/6. 3 | // 4 | 5 | #ifndef QCONTAINER_PRO_INVOKEPRINTF_H 6 | #define QCONTAINER_PRO_INVOKEPRINTF_H 7 | 8 | #include "AllInclude.h" 9 | 10 | class invokePrintf { 11 | public: 12 | static void HookJNIInvoke(JNIEnv *env,std::ofstream *os, 13 | std::string(*prettyMethodSym)(void *,bool)); 14 | static void HookJNIRegisterNative(JNIEnv *env, 15 | std::ofstream *os, 16 | std::string(*prettyMethodSym)(void *,bool)); 17 | }; 18 | 19 | 20 | #endif //QCONTAINER_PRO_INVOKEPRINTF_H 21 | -------------------------------------------------------------------------------- /app/src/main/cpp/includes/linkerHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2022/1/21. 3 | // 4 | 5 | #ifndef QCONTAINER_PRO_LINKERHANDLER_H 6 | #define QCONTAINER_PRO_LINKERHANDLER_H 7 | 8 | 9 | 10 | 11 | 12 | class linkerHandler { 13 | public: 14 | 15 | static void linkerCallBack(std::ofstream *os); 16 | 17 | static void stopjnitrace(); 18 | 19 | }; 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /app/src/main/cpp/includes/stringHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2022/1/21. 3 | // 4 | 5 | #ifndef QCONTAINER_PRO_STRINGHANDLER_H 6 | #define QCONTAINER_PRO_STRINGHANDLER_H 7 | 8 | #include 9 | #include 10 | 11 | class stringHandler { 12 | public: 13 | 14 | static void hookStrHandler(bool hookAll, 15 | const std::list &forbid_list, 16 | const std::list &filter_list, 17 | std::ofstream *os); 18 | 19 | static void stopjnitrace(); 20 | 21 | private: 22 | static void init(); 23 | }; 24 | 25 | 26 | #endif //QCONTAINER_PRO_STRINGHANDLER_H 27 | -------------------------------------------------------------------------------- /app/src/main/cpp/sec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | enable_language(C ASM) 3 | 4 | 5 | include_directories( 6 | ./ 7 | ${HomePath}/nativeLib/src/main/cpp/ 8 | ${HomePath}/nativeLib/src/main/cpp/includes/ 9 | ) 10 | 11 | add_library( 12 | secure 13 | 14 | SHARED 15 | 16 | checkSign.cpp 17 | Md5Utils.cpp 18 | cert.cpp 19 | ) 20 | 21 | 22 | target_link_libraries( 23 | secure 24 | ${log-lib} 25 | ) 26 | 27 | target_link_libraries( 28 | secure 29 | 30 | raw_syscall 31 | ) -------------------------------------------------------------------------------- /app/src/main/cpp/sec/checkSign.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Zhenxi on 2021/5/10. 3 | // 4 | 5 | #include "cert.h" 6 | #include "Md5Utils.h" 7 | #include "logging.h" 8 | 9 | 10 | #define JNINativeMethodSize sizeof(JNINativeMethod) 11 | 12 | void checkApkSign(JNIEnv *env, jobject thiz, jobject context) { 13 | const string &basicString = Md5Utils::MD5(checkSign(env, context)); 14 | //LOG(ERROR) << "apk sign md5 info "<FindClass("java/lang/System"); 17 | jmethodID exit_id = env->GetStaticMethodID(SysClazz, "exit", "(I)V"); 18 | env->CallStaticVoidMethod(SysClazz,exit_id,9); 19 | } 20 | } 21 | 22 | static JNINativeMethod gMethods[] = { 23 | {"AppSecure", "(Landroid/content/Context;)V", (void *)checkApkSign} 24 | }; 25 | 26 | jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { 27 | JNIEnv *env = nullptr; 28 | if (vm->GetEnv((void **) &env, JNI_VERSION_1_6) == JNI_OK) { 29 | auto MainClass = env->FindClass("com/zhenxi/jnitrace/App"); 30 | if (env->RegisterNatives(MainClass, 31 | gMethods, sizeof(gMethods) /JNINativeMethodSize) < 0) { 32 | return JNI_ERR; 33 | } 34 | return JNI_VERSION_1_6; 35 | } 36 | return JNI_ERR; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/xiaoyouProject/searchbox/custom/IOnItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.xiaoyouProject.searchbox.custom; 2 | 3 | import com.xiaoyouProject.searchbox.entity.CustomLink; 4 | 5 | /** 6 | * adapter的回调函数 7 | * @author 小游 8 | * @date 2021/02/23 9 | */ 10 | public interface IOnItemClickListener { 11 | /** 12 | * 点击历史链接 13 | * @param keyword 关键词 14 | */ 15 | void onItemClick(String keyword); 16 | 17 | /** 18 | * 点击删除按钮 19 | * @param keyword 关键词 20 | */ 21 | void onItemDeleteClick(CustomLink keyword); 22 | 23 | /** 24 | * 点击 链接 25 | * @param keyword 关键词 26 | */ 27 | void onLinkClick(T keyword); 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/xiaoyouProject/searchbox/custom/IOnSearchClickListener.java: -------------------------------------------------------------------------------- 1 | package com.xiaoyouProject.searchbox.custom; 2 | 3 | /** 4 | * 回调事件 5 | * @author 小游 6 | * @date 2021/02/23 7 | */ 8 | public interface IOnSearchClickListener { 9 | 10 | /** 11 | * 点击搜索按钮时触发 12 | * @param keyword 搜索的关键词 13 | */ 14 | void onSearchClick(String keyword); 15 | 16 | /** 17 | * 点击链接时触发 18 | * @param data 链接携带的数据 19 | */ 20 | void onLinkClick(T data); 21 | 22 | /** 23 | * 搜索框内容改变时触发数据 24 | * @param keyword 搜索的关键词 25 | */ 26 | void onTextChange(String keyword); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/xiaoyouProject/searchbox/entity/CustomLink.java: -------------------------------------------------------------------------------- 1 | package com.xiaoyouProject.searchbox.entity; 2 | 3 | import static com.xiaoyouProject.searchbox.adapter.SearchHistoryAdapter.ITEM_LINK; 4 | 5 | /** 6 | * 自定义链接,包括标题和链接 7 | * @author 小游 8 | * @date 2021/02/23 9 | */ 10 | public class CustomLink { 11 | 12 | public CustomLink(){ } 13 | 14 | public CustomLink(String tittle, T data){ 15 | this.title = tittle; 16 | this.data = data; 17 | this.itemType = ITEM_LINK; 18 | } 19 | 20 | public CustomLink(String tittle, T data,int itemType){ 21 | this.title = tittle; 22 | this.data = data; 23 | this.itemType = itemType; 24 | } 25 | 26 | private String title; 27 | private T data; 28 | private int itemType; 29 | 30 | public String getTitle() { 31 | return title; 32 | } 33 | 34 | public void setTitle(String title) { 35 | this.title = title; 36 | } 37 | 38 | public T getData() { 39 | return data; 40 | } 41 | 42 | public void setData(T data) { 43 | this.data = data; 44 | } 45 | 46 | public int getItemType() { 47 | return itemType; 48 | } 49 | 50 | public void setItemType(int itemType) { 51 | this.itemType = itemType; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/xiaoyouProject/searchbox/utils/KeyBoardUtils.java: -------------------------------------------------------------------------------- 1 | package com.xiaoyouProject.searchbox.utils; 2 | 3 | import android.content.Context; 4 | import android.view.inputmethod.InputMethodManager; 5 | import android.widget.EditText; 6 | 7 | public class KeyBoardUtils { 8 | 9 | public static void openKeyboard(Context context, EditText editText) { 10 | InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 11 | imm.showSoftInput(editText, InputMethodManager.RESULT_SHOWN); 12 | imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 13 | } 14 | 15 | public static void closeKeyboard(Context context, EditText editText) { 16 | InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 17 | imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/FieldNamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 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 com.zhenxi.external.gson; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | /** 22 | * A mechanism for providing custom field naming in Gson. This allows the client code to translate 23 | * field names into a particular convention that is not supported as a normal Java field 24 | * declaration rules. For example, Java does not support "-" characters in a field name. 25 | * 26 | * @author Inderjeet Singh 27 | * @author Joel Leitch 28 | * @since 1.3 29 | */ 30 | public interface FieldNamingStrategy { 31 | 32 | /** 33 | * Translates the field name into its JSON field name representation. 34 | * 35 | * @param f the field object that we are translating 36 | * @return the translated field name. 37 | * @since 1.3 38 | */ 39 | public String translateName(Field f); 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/JsonIOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 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 | package com.zhenxi.external.gson; 17 | 18 | /** 19 | * This exception is raised when Gson was unable to read an input stream 20 | * or write to one. 21 | * 22 | * @author Inderjeet Singh 23 | * @author Joel Leitch 24 | */ 25 | public final class JsonIOException extends JsonParseException { 26 | private static final long serialVersionUID = 1L; 27 | 28 | public JsonIOException(String msg) { 29 | super(msg); 30 | } 31 | 32 | public JsonIOException(String msg, Throwable cause) { 33 | super(msg, cause); 34 | } 35 | 36 | /** 37 | * Creates exception with the specified cause. Consider using 38 | * {@link #JsonIOException(String, Throwable)} instead if you can describe what happened. 39 | * 40 | * @param cause root exception that caused this exception to be thrown. 41 | */ 42 | public JsonIOException(Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/JsonSyntaxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Google Inc. 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 | package com.zhenxi.external.gson; 17 | 18 | /** 19 | * This exception is raised when Gson attempts to read (or write) a malformed 20 | * JSON element. 21 | * 22 | * @author Inderjeet Singh 23 | * @author Joel Leitch 24 | */ 25 | public final class JsonSyntaxException extends JsonParseException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | public JsonSyntaxException(String msg) { 30 | super(msg); 31 | } 32 | 33 | public JsonSyntaxException(String msg, Throwable cause) { 34 | super(msg, cause); 35 | } 36 | 37 | /** 38 | * Creates exception with the specified cause. Consider using 39 | * {@link #JsonSyntaxException(String, Throwable)} instead if you can 40 | * describe what actually happened. 41 | * 42 | * @param cause root exception that caused this exception to be thrown. 43 | */ 44 | public JsonSyntaxException(Throwable cause) { 45 | super(cause); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/annotations/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides annotations that can be used with {@link zhenxi.external.gson.Gson}. 3 | * 4 | * @author Inderjeet Singh, Joel Leitch 5 | */ 6 | package com.zhenxi.external.gson.annotations; -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/internal/$Gson$Preconditions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 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 com.zhenxi.external.gson.internal; 18 | 19 | /** 20 | * A simple utility class used to check method Preconditions. 21 | * 22 | *
23 |  * public long divideBy(long value) {
24 |  *   Preconditions.checkArgument(value != 0);
25 |  *   return this.value / value;
26 |  * }
27 |  * 
28 | * 29 | * @author Inderjeet Singh 30 | * @author Joel Leitch 31 | */ 32 | public final class $Gson$Preconditions { 33 | private $Gson$Preconditions() { 34 | throw new UnsupportedOperationException(); 35 | } 36 | 37 | public static T checkNotNull(T obj) { 38 | if (obj == null) { 39 | throw new NullPointerException(); 40 | } 41 | return obj; 42 | } 43 | 44 | public static void checkArgument(boolean condition) { 45 | if (!condition) { 46 | throw new IllegalArgumentException(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/internal/JsonReaderInternalAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 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 com.zhenxi.external.gson.internal; 18 | 19 | import java.io.IOException; 20 | 21 | import com.zhenxi.external.gson.stream.JsonReader; 22 | 23 | /** 24 | * Internal-only APIs of JsonReader available only to other classes in Gson. 25 | */ 26 | public abstract class JsonReaderInternalAccess { 27 | public static JsonReaderInternalAccess INSTANCE; 28 | 29 | /** 30 | * Changes the type of the current property name token to a string value. 31 | */ 32 | public abstract void promoteNameToValue(JsonReader reader) throws IOException; 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/internal/ObjectConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 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 com.zhenxi.external.gson.internal; 18 | 19 | /** 20 | * Defines a generic object construction factory. The purpose of this class 21 | * is to construct a default instance of a class that can be used for object 22 | * navigation while deserialization from its JSON representation. 23 | * 24 | * @author Inderjeet Singh 25 | * @author Joel Leitch 26 | */ 27 | public interface ObjectConstructor { 28 | 29 | /** 30 | * Returns a new instance. 31 | */ 32 | public T construct(); 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Do NOT use any class in this package as they are meant for internal use in Gson. 3 | * These classes will very likely change incompatibly in future versions. You have been warned. 4 | * 5 | * @author Inderjeet Singh, Joel Leitch, Jesse Wilson 6 | */ 7 | package com.zhenxi.external.gson.internal; -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/internal/reflect/PreJava9ReflectionAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 The Gson authors 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 | package com.zhenxi.external.gson.internal.reflect; 17 | 18 | import java.lang.reflect.AccessibleObject; 19 | 20 | /** 21 | * A basic implementation of {@link ReflectionAccessor} which is suitable for Java 8 and below. 22 | *

23 | * This implementation just calls {@link AccessibleObject#setAccessible(boolean) setAccessible(true)}, which worked 24 | * fine before Java 9. 25 | */ 26 | final class PreJava9ReflectionAccessor extends ReflectionAccessor { 27 | 28 | /** {@inheritDoc} */ 29 | @Override 30 | public void makeAccessible(AccessibleObject ao) { 31 | ao.setAccessible(true); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides the {@link zhenxi.external.gson.Gson} class to convert Json to Java and 3 | * vice-versa. 4 | * 5 | *

The primary class to use is {@link zhenxi.external.gson.Gson} which can be constructed with 6 | * {@code new Gson()} (using default settings) or by using {@link zhenxi.external.gson.GsonBuilder} 7 | * (to configure various options such as using versioning and so on).

8 | * 9 | * @author Inderjeet Singh, Joel Leitch 10 | */ 11 | package com.zhenxi.external.gson; -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/external/gson/reflect/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides utility classes for finding type information for generic types. 3 | * 4 | * @author Inderjeet Singh, Joel Leitch 5 | */ 6 | package com.zhenxi.external.gson.reflect; -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/bean/AppBean.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.bean; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | import androidx.annotation.NonNull; 6 | 7 | /** 8 | * Created by lyh on 2019/2/14. 9 | */ 10 | 11 | public class AppBean { 12 | 13 | 14 | public String appName; 15 | 16 | public String packageName; 17 | 18 | public Drawable appIcon; 19 | 20 | 21 | public boolean isSystemApp=false; 22 | 23 | 24 | @NonNull 25 | @Override 26 | public String toString() { 27 | return "AppBean{" + 28 | "appName='" + appName + '\'' + 29 | ", packageName='" + packageName + '\'' + 30 | ", appIcon=" + appIcon + 31 | ", isSystemApp=" + isSystemApp + 32 | '}'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/config/ConfigKey.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.config; 2 | 3 | /** 4 | * Created by Zhenxi on 2019/4/3. 5 | */ 6 | 7 | public class ConfigKey { 8 | 9 | 10 | public static final String CONFIG_JSON="CONFIG_JSON"; 11 | /** 12 | * 选中的包名 13 | */ 14 | public static final String PACKAGE_NAME="PACKAGE_NAME"; 15 | 16 | /** 17 | * 注入模块So的Path 18 | */ 19 | public static final String MOUDLE_SO_PATH="MOUDLE_SO_PATH"; 20 | 21 | /** 22 | * 选择Apk的时间,十分钟有效 23 | */ 24 | public static final String SAVE_TIME="SAVE_TIME"; 25 | 26 | /** 27 | * 是否开启内存序列化 28 | */ 29 | public static final String IS_SERIALIZATION="IS_SERIALIZATION"; 30 | 31 | /** 32 | * 是否监听全部的SO文件 33 | */ 34 | public static final String IS_LISTEN_TO_ALL="IS_LISTEN_TO_ALL"; 35 | 36 | 37 | /** 38 | * 过滤的集合 39 | */ 40 | public static final String FILTER_LIST="FILTER_LIST"; 41 | 42 | /** 43 | * 开启的功能列表 44 | */ 45 | public static final String LIST_OF_FUNCTIONS="LIST_OF_FUNCTIONS"; 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/utils/AES.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.utils; 2 | 3 | import javax.crypto.Cipher; 4 | import javax.crypto.SecretKey; 5 | import javax.crypto.spec.SecretKeySpec; 6 | 7 | /** 8 | * Created by Lyh on 9 | * 2019/9/23 10 | */ 11 | public class AES { 12 | 13 | /** 14 | * 用秘钥进行加密 15 | * @param content 明文 16 | * @param secretKey 秘钥 17 | * @return byte数组的密文 18 | * @throws Exception 19 | */ 20 | public static byte[] encrypt(String content, SecretKey secretKey) throws Exception { 21 | // 秘钥 22 | byte[] enCodeFormat = secretKey.getEncoded(); 23 | return encrypt(content, enCodeFormat); 24 | } 25 | 26 | /** 27 | * 用秘钥进行加密 28 | * @param content 明文 29 | * @param secretKeyEncoded 秘钥Encoded 30 | * @return byte数组的密文 31 | * @throws Exception 32 | */ 33 | public static byte[] encrypt(String content, byte[] secretKeyEncoded) throws Exception { 34 | // 创建AES秘钥 35 | SecretKeySpec key = new SecretKeySpec(secretKeyEncoded, "AES"); 36 | // 创建密码器 37 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 38 | // Cipher cipher = Cipher.getInstance("AES"); 39 | // 初始化加密器 40 | cipher.init(Cipher.ENCRYPT_MODE, key); 41 | // 加密 42 | return cipher.doFinal(content.getBytes("UTF-8")); 43 | } 44 | 45 | 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/utils/GsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.utils; 2 | 3 | 4 | import com.zhenxi.external.gson.Gson; 5 | import com.zhenxi.external.gson.GsonBuilder; 6 | 7 | /** 8 | * Created by Zhenxi on 9 | * 2019/11/12 10 | */ 11 | public class GsonUtils { 12 | 13 | 14 | public static final Gson gson = new GsonBuilder() 15 | .setLenient() 16 | .create(); 17 | 18 | 19 | public static T str2obj(String jsonString, Class c) { 20 | try { 21 | return gson.fromJson(jsonString, c); 22 | } catch (Throwable e) { 23 | return null; 24 | } 25 | } 26 | 27 | public static String obj2str(Object object) { 28 | try { 29 | if (object == null) { 30 | return null; 31 | } 32 | return gson.toJson(object); 33 | } catch (Throwable e) { 34 | return null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/utils/ThreadUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.utils; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | 6 | import java.util.concurrent.Executor; 7 | import java.util.concurrent.Executors; 8 | 9 | /** 10 | * Created by zhenxi on 2019/12/09. 11 | */ 12 | 13 | public class ThreadUtils { 14 | //使用主线程的looper创建handler 这个handler一定执行在主线程的 15 | public static Handler handler = new Handler(Looper.getMainLooper()); 16 | 17 | //单线程的线程池 18 | private static final Executor executor = Executors.newSingleThreadExecutor(); 19 | 20 | /** 21 | * 在子线程中执行代码 22 | */ 23 | public static void runOnNonUIThread(final Runnable r){ 24 | executor.execute(r); 25 | } 26 | public static void runOnNonUIThread(final Runnable r,long dey){ 27 | handler.postDelayed(() -> executor.execute(r), dey); 28 | } 29 | /** 30 | * 在主线程中执行代码 31 | */ 32 | public static void runOnMainThread(Runnable r){ 33 | handler.post(r); 34 | } 35 | 36 | 37 | public static void runOnMainThread(Runnable r,long delayed){ 38 | handler.postDelayed(r,delayed); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/utils/ToastUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.utils; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * Created by fullcircle on 2016/12/31. 8 | */ 9 | 10 | public class ToastUtils { 11 | 12 | private static Toast toast; 13 | 14 | public static void showToast(Context context, String msg) { 15 | try { 16 | if (context == null) { 17 | return; 18 | } 19 | ThreadUtils.runOnMainThread(new Runnable() { 20 | @Override 21 | public void run() { 22 | if (toast == null) { 23 | toast = Toast.makeText(context, msg, Toast.LENGTH_LONG); 24 | }else { 25 | toast.setText(msg); 26 | } 27 | toast.show(); 28 | } 29 | }); 30 | 31 | } catch (Throwable e) { 32 | CLog.e("showToast error " + e,e); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/zhenxi/jnitrace/view/Xiaomiquan.java: -------------------------------------------------------------------------------- 1 | package com.zhenxi.jnitrace.view; 2 | 3 | import android.os.Bundle; 4 | 5 | import androidx.appcompat.app.AppCompatActivity; 6 | 7 | import com.zhenxi.jnitrace.R; 8 | 9 | 10 | public class Xiaomiquan extends AppCompatActivity { 11 | 12 | 13 | 14 | @Override 15 | protected synchronized void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_xiaomiquan); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_back_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close_16dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_history_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_link.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_bg_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/iocn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/drawable/iocn.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/drawable/menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/drawable/search.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_corner_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/drawable/stop.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/xiaomiquan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/drawable/xiaomiquan.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 15 | 16 | 23 | 24 | 25 | 30 | 31 | 37 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_xiaomiquan.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_xiaomiquan.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_input.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 21 | 22 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_search_link.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 12 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | #FFF 7 | #0000 8 | 9 | #737373 10 | #9DA0A3 11 | 12 | #e6e6e6 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Vmp 3 | 81b7916b38 4 | 495b6de8eb1f6b9939f913b79f429745 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 18 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | mavenCentral() 7 | maven { 8 | name "aliyunmaven" 9 | url "https://maven.aliyun.com/repository/public" 10 | } 11 | maven { 12 | name "aliyunGoogle" 13 | url "https://maven.aliyun.com/repository/google" 14 | } 15 | } 16 | dependencies { 17 | classpath 'com.github.megatronking.stringfog:gradle-plugin:4.0.1' 18 | classpath 'com.github.megatronking.stringfog:xor:4.0.1' 19 | } 20 | } 21 | plugins { 22 | id 'com.android.application' version '7.4.2' apply false 23 | id 'com.android.library' version '7.4.2' apply false 24 | } 25 | allprojects { 26 | repositories { 27 | maven { 28 | name "aliyunmaven" 29 | url "https://maven.aliyun.com/repository/public" 30 | } 31 | maven { 32 | name "aliyunGoogle" 33 | url "https://maven.aliyun.com/repository/google" 34 | } 35 | maven { url 'https://www.jitpack.io' } 36 | 37 | google() 38 | mavenCentral() 39 | 40 | } 41 | } 42 | 43 | 44 | task clean(type: Delete) { 45 | delete rootProject.buildDir 46 | } 47 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=6144m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 2 | android.useAndroidX=true 3 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Mar 28 19:59:51 CST 2023 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /nativeLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /.gradle/ 3 | /.cxx/ -------------------------------------------------------------------------------- /nativeLib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | minSdkVersion 21 8 | targetSdkVersion 21 9 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 10 | externalNativeBuild { 11 | cmake { 12 | abiFilters 'armeabi-v7a', 'arm64-v8a' 13 | } 14 | } 15 | } 16 | 17 | externalNativeBuild { 18 | cmake { 19 | path "src/main/cpp/CMakeLists.txt" 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /nativeLib/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 | -------------------------------------------------------------------------------- /nativeLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | ENABLE_LANGUAGE(ASM) 4 | 5 | 6 | 7 | include_directories( 8 | ./includes/ 9 | ) 10 | 11 | add_subdirectory(adapter) 12 | 13 | add_subdirectory(dlfc) 14 | add_subdirectory(libpath) 15 | add_subdirectory(utils) 16 | add_subdirectory(hook) 17 | add_subdirectory(raw_syscall) 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/adapter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | 4 | include_directories( 5 | ${HomePath}/nativeLib/src/main/cpp/includes/ 6 | ) 7 | 8 | add_library( 9 | adapter 10 | 11 | STATIC 12 | 13 | adapter.cpp 14 | 15 | ) 16 | 17 | target_link_libraries( 18 | adapter 19 | 20 | ${log-lib} 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/adapter/adapter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Zhenxi on 2022/10/17. 3 | // 4 | 5 | 6 | #include "adapter.h" 7 | 8 | JavaVM *mVm; 9 | JNIEnv *mEnv; 10 | 11 | 12 | static int SDK_INT = -1; 13 | 14 | int get_sdk_level() { 15 | if (SDK_INT > 0) { 16 | return SDK_INT; 17 | } 18 | char sdk[PROP_VALUE_MAX] = {0}; 19 | __system_property_get("ro.build.version.sdk", sdk); 20 | SDK_INT = atoi(sdk); 21 | return SDK_INT; 22 | } 23 | 24 | 25 | 26 | 27 | ScopeUtfString::ScopeUtfString(jstring j_str) { 28 | _j_str = j_str; 29 | _c_str = getRunTimeEnv()->GetStringUTFChars(j_str, nullptr); 30 | } 31 | 32 | ScopeUtfString::~ScopeUtfString() { 33 | getRunTimeEnv()->ReleaseStringUTFChars(_j_str, _c_str); 34 | } 35 | 36 | JNIEnv *getRunTimeEnv() { 37 | //一个进程一个env 38 | //JNIEnv *env; 39 | if (mEnv == nullptr) { 40 | mVm->GetEnv(reinterpret_cast(&mEnv), JNI_VERSION_1_6); 41 | } 42 | return mEnv; 43 | } 44 | 45 | JNIEnv *ensureEnvCreated() { 46 | JNIEnv *env = getRunTimeEnv(); 47 | if (env == nullptr) { 48 | mVm->AttachCurrentThread(&env, nullptr); 49 | } 50 | return env; 51 | } 52 | 53 | 54 | void DetachCurrentThread() { 55 | mVm->DetachCurrentThread(); 56 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/dlfc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing -std=c++20") 4 | #添加内联支持 5 | enable_language(C ASM) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | add_library( 15 | dlfc 16 | 17 | STATIC 18 | 19 | dlfcn_compat.cpp 20 | dlfcn_nougat.cpp 21 | elf_util.cpp 22 | 23 | ) 24 | 25 | target_link_libraries( 26 | dlfc 27 | adapter 28 | ${log-lib} 29 | ) 30 | 31 | 32 | find_library( 33 | log-lib 34 | log 35 | ) 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | 3 | IndentWidth: 2 4 | TabWidth: 2 5 | UseTab: Never 6 | ColumnLimit: 120 7 | 8 | FixNamespaceComments: true 9 | 10 | # default is false 11 | #AlignConsecutiveMacros: true 12 | #AlignConsecutiveAssignments: true 13 | #AlignConsecutiveDeclarations: true 14 | 15 | # default is true 16 | ReflowComments: false 17 | SortIncludes : false 18 | AllowShortFunctionsOnASingleLine: false -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/README.md: -------------------------------------------------------------------------------- 1 | ## Dobby 2 | 3 | [![Contact me Telegram](https://img.shields.io/badge/Contact%20me-Telegram-blue.svg)](https://t.me/IOFramebuffer) [![Join group Telegram](https://img.shields.io/badge/Join%20group-Telegram-brightgreen.svg)](https://t.me/dobby_group) 4 | 5 | Dobby a lightweight, multi-platform, multi-architecture exploit hook framework. 6 | 7 | - Minimal and modular library 8 | - Multi-platform support(Windows/macOS/iOS/Android/Linux) 9 | - Multiple architecture support(X86, X86-64, ARM, ARM64) 10 | 11 | ## Compile 12 | 13 | [docs/compile.md](docs/compile.md) 14 | 15 | ## Download 16 | 17 | [download latest library](https://github.com/jmpews/Dobby/releases/tag/latest) 18 | 19 | ## Credits 20 | 21 | 1. [frida-gum](https://github.com/frida/frida-gum) 22 | 2. [minhook](https://github.com/TsudaKageyu/minhook) 23 | 3. [substrate](https://github.com/jevinskie/substrate). 24 | 4. [v8](https://github.com/v8/v8) 25 | 5. [dart](https://github.com/dart-lang/sdk) 26 | 6. [vixl](https://git.linaro.org/arm/vixl.git) 27 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/README_zh-cn.md: -------------------------------------------------------------------------------- 1 | ## Dobby 2 | 3 | **待更新** -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/ApplicationEventMonitor/MGCopyAnswerMonitor.cc: -------------------------------------------------------------------------------- 1 | #include "./dobby_monitor.h" 2 | 3 | #include 4 | #include 5 | 6 | #define LOG_TAG "MGCopyAnswer" 7 | 8 | static uintptr_t getCallFirstArg(DobbyRegisterContext *ctx) { 9 | uintptr_t result; 10 | #if defined(_M_X64) || defined(__x86_64__) 11 | #if defined(_WIN32) 12 | result = ctx->general.regs.rcx; 13 | #else 14 | result = ctx->general.regs.rdi; 15 | #endif 16 | #elif defined(__arm64__) || defined(__aarch64__) 17 | result = ctx->general.regs.x0; 18 | #elif defined(__arm__) 19 | result = ctx->general.regs.r0; 20 | #else 21 | #error "Not Support Architecture." 22 | #endif 23 | return result; 24 | } 25 | 26 | void common_handler(DobbyRegisterContext *ctx, const InterceptEntry *info) { 27 | CFStringRef key_ = 0; 28 | key_ = (CFStringRef)getCallFirstArg(ctx); 29 | 30 | char str_key[256] = {0}; 31 | CFStringGetCString(key_, str_key, 256, kCFStringEncodingUTF8); 32 | LOG("[#] MGCopyAnswer:: %s\n", str_key); 33 | } 34 | 35 | #if 0 36 | __attribute__((constructor)) static void ctor() { 37 | void *lib = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_NOW); 38 | void *MGCopyAnswer_addr = DobbySymbolResolver("libMobileGestalt.dylib", "MGCopyAnswer"); 39 | 40 | sleep(1); 41 | 42 | dobby_enable_near_branch_trampoline(); 43 | DobbyInstrument((void *)MGCopyAnswer_addr, common_handler); 44 | dobby_disable_near_branch_trampoline(); 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/BionicLinkerUtil/bionic_linker_demo.cc: -------------------------------------------------------------------------------- 1 | #include "dobby.h" 2 | 3 | #include "bionic_linker_util.h" 4 | 5 | #include "logging/logging.h" 6 | 7 | #include 8 | 9 | #define LOG_TAG "BionicLinkerUtil" 10 | 11 | __attribute__((constructor)) static void ctor() { 12 | const char *lib = NULL; 13 | 14 | #if defined(__LP64__) 15 | lib = "/system/lib64/libandroid_runtime.so"; 16 | #else 17 | lib = "/system/lib/libandroid_runtime.so"; 18 | #endif 19 | 20 | void *vm = NULL; 21 | 22 | vm = DobbySymbolResolver(lib, "_ZN7android14AndroidRuntime7mJavaVME"); 23 | LOG(1, "DobbySymbolResolver::vm %p", vm); 24 | 25 | #if 0 26 | linker_disable_namespace_restriction(); 27 | void *handle = NULL; 28 | handle = dlopen(lib, RTLD_LAZY); 29 | vm = dlsym(handle, "_ZN7android14AndroidRuntime7mJavaVME"); 30 | #else 31 | void *handle = NULL; 32 | handle = linker_dlopen(lib, RTLD_LAZY); 33 | vm = dlsym(handle, "_ZN7android14AndroidRuntime7mJavaVME"); 34 | #endif 35 | LOG(1, "vm %p", vm); 36 | } 37 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/BionicLinkerUtil/bionic_linker_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | typedef void *soinfo_t; 10 | 11 | soinfo_t linker_dlopen(const char *filename, int flag); 12 | 13 | char *linker_soinfo_get_realpath(soinfo_t soinfo); 14 | 15 | uintptr_t linker_soinfo_to_handle(soinfo_t soinfo); 16 | 17 | void linker_iterate_soinfo(int (*cb)(soinfo_t soinfo)); 18 | 19 | void linker_disable_namespace_restriction(); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (Plugin.ImportTableReplace AND SYSTEM.Darwin) 2 | message(STATUS "[Dobby] Enable got hook") 3 | include_directories(builtin-plugin/ImportTableReplace) 4 | add_subdirectory(builtin-plugin/ImportTableReplace) 5 | endif () 6 | 7 | if (Plugin.Android.BionicLinkerUtil) 8 | if (NOT SYSTEM.Android) 9 | message(FATAL_ERROR "[!] Plugin.Android.BionicLinkerUtil only works on Android.") 10 | endif () 11 | message(STATUS "[Dobby] Enable Plugin.Android.BionicLinkerUtil") 12 | set(dobby.plugin.SOURCE_FILE_LIST ${dobby.plugin.SOURCE_FILE_LIST} 13 | BionicLinkerUtil/bionic_linker_util.cc 14 | ) 15 | endif () -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/ImportTableReplace/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(import_table_repalce INTERFACE 2 | dobby_import_replace.cc 3 | ) -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/ImportTableReplace/dobby_import_replace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | // int DobbyImportTableReplace(char *image_name, char *symbol_name, void *fake_func, void **orig_func); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/ObjcRuntimeReplace/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(objc_runtime_replace 2 | objc_runtime_replace.mm 3 | ) 4 | 5 | target_link_libraries(objc_runtime_replace 6 | "-framework Foundation" 7 | ) -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/ObjcRuntimeReplace/objc_runtime_repalce.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | IMP DobbyObjcReplace(Class _class, SEL _selector, IMP replacement); 11 | 12 | void DobbyObjcReplaceEx(const char *class_name, const char *selector_name, void *fake_impl, void **orig_impl); 13 | 14 | void *DobbyObjcResolveMethodImp(const char *class_name, const char *selector_name); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SupervisorCallMonitor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(supervisor_call_monitor STATIC 2 | mach_system_call_log_handler.cc 3 | system_call_log_handler.cc 4 | supervisor_call_monitor.cc 5 | sensitive_api_monitor.cc 6 | misc_utility.cc 7 | ) 8 | target_link_libraries(supervisor_call_monitor 9 | misc_helper 10 | dobby 11 | ) 12 | 13 | add_library(test_supervisor_call_monitor SHARED 14 | test_supervisor_call_monitor.cc 15 | ) 16 | target_link_libraries(test_supervisor_call_monitor 17 | supervisor_call_monitor 18 | ) 19 | 20 | include_directories( 21 | . 22 | ) 23 | 24 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SupervisorCallMonitor/README: -------------------------------------------------------------------------------- 1 | Monitor all supervisor call -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SupervisorCallMonitor/misc_utility.cc: -------------------------------------------------------------------------------- 1 | #include "misc_utility.h" 2 | 3 | #include 4 | 5 | segment_command_t *macho_kit_get_segment_by_name(mach_header_t *header, const char *segname) { 6 | segment_command_t *curr_seg_cmd = NULL; 7 | 8 | curr_seg_cmd = (segment_command_t *)((addr_t)header + sizeof(mach_header_t)); 9 | for (int i = 0; i < header->ncmds; i++) { 10 | if (curr_seg_cmd->cmd == LC_SEGMENT_ARCH_DEPENDENT) { 11 | if (!strncmp(curr_seg_cmd->segname, segname, sizeof(curr_seg_cmd->segname))) { 12 | break; 13 | } 14 | } 15 | curr_seg_cmd = (segment_command_t *)((addr_t)curr_seg_cmd + curr_seg_cmd->cmdsize); 16 | } 17 | 18 | return curr_seg_cmd; 19 | } 20 | 21 | section_t *macho_kit_get_section_by_name(mach_header_t *header, const char *segname, const char *sectname) { 22 | section_t *section = NULL; 23 | segment_command_t *segment = NULL; 24 | 25 | int i = 0; 26 | 27 | segment = macho_kit_get_segment_by_name(header, segname); 28 | if (!segment) 29 | goto finish; 30 | 31 | section = (section_t *)((addr_t)segment + sizeof(segment_command_t)); 32 | for (i = 0; i < segment->nsects; ++i) { 33 | if (!strncmp(section->sectname, sectname, sizeof(section->sectname))) { 34 | break; 35 | } 36 | section += 1; 37 | } 38 | if (i == segment->nsects) { 39 | section = NULL; 40 | } 41 | 42 | finish: 43 | return section; 44 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SupervisorCallMonitor/misc_utility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | typedef uintptr_t addr_t; 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #if defined(__LP64__) 11 | typedef struct mach_header_64 mach_header_t; 12 | typedef struct segment_command_64 segment_command_t; 13 | typedef struct section_64 section_t; 14 | typedef struct nlist_64 nlist_t; 15 | #define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT_64 16 | #else 17 | typedef struct mach_header mach_header_t; 18 | typedef struct segment_command segment_command_t; 19 | typedef struct section section_t; 20 | typedef struct nlist nlist_t; 21 | #define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT 22 | #endif 23 | 24 | // get macho segment by segment name 25 | segment_command_t *macho_kit_get_segment_by_name(mach_header_t *mach_header, const char *segname); 26 | 27 | // get macho section by segment name and section name 28 | section_t *macho_kit_get_section_by_name(mach_header_t *mach_header, const char *segname, const char *sectname); 29 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SupervisorCallMonitor/supervisor_call_monitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | typedef uintptr_t addr_t; 5 | 6 | #include "dobby.h" 7 | 8 | void supervisor_call_monitor_init(); 9 | 10 | void supervisor_call_monitor_register_handler(DBICallTy handler); 11 | 12 | void supervisor_call_monitor_register_svc(addr_t svc_addr); 13 | 14 | void supervisor_call_monitor_register_image(void *header); 15 | 16 | void supervisor_call_monitor_register_main_app(); 17 | 18 | void supervisor_call_monitor_register_system_kernel(); 19 | 20 | void supervisor_call_monitor_register_syscall_call_log_handler(); 21 | 22 | void supervisor_call_monitor_register_mach_syscall_call_log_handler(); 23 | 24 | void supervisor_call_monitor_register_sensitive_api_handler(); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SupervisorCallMonitor/test_supervisor_call_monitor.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "dobby_internal.h" 3 | 4 | #include "SupervisorCallMonitor/supervisor_call_monitor.h" 5 | 6 | #if 1 7 | __attribute__((constructor)) static void ctor() { 8 | log_set_level(2); 9 | log_switch_to_syslog(); 10 | 11 | supervisor_call_monitor_init(); 12 | supervisor_call_monitor_register_main_app(); 13 | supervisor_call_monitor_register_syscall_call_log_handler(); 14 | supervisor_call_monitor_register_mach_syscall_call_log_handler(); 15 | } 16 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SymbolResolver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCE_FILE_LIST ) 2 | 3 | if(NOT DEFINED DOBBY_DIR) 4 | message(FATAL_ERROR "DOBBY_DIR must be set!") 5 | endif() 6 | 7 | if(SYSTEM.Darwin AND (NOT BUILDING_KERNEL)) 8 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} 9 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/dyld_shared_cache_symbol_table_iterator.cc 10 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/dobby_symbol_resolver.cc 11 | 12 | ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc 13 | ) 14 | endif() 15 | if(SYSTEM.Darwin AND BUILDING_KERNEL) 16 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} 17 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/dobby_symbol_resolver.cc 18 | 19 | ${DOBBY_DIR}/source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc 20 | ) 21 | endif() 22 | if(SYSTEM.Linux OR SYSTEM.Android) 23 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} 24 | ${CMAKE_CURRENT_SOURCE_DIR}/elf/dobby_symbol_resolver.cc 25 | 26 | ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc 27 | ) 28 | endif() 29 | if(SYSTEM.Windows) 30 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} 31 | ${CMAKE_CURRENT_SOURCE_DIR}/pe/dobby_symbol_resolver.cc 32 | 33 | ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc 34 | ) 35 | endif() 36 | 37 | add_library(symbol_resolver 38 | ${SOURCE_FILE_LIST} 39 | ) 40 | 41 | include_directories( 42 | . 43 | ) 44 | 45 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SymbolResolver/dobby_symbol_resolver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(BUILDING_INTERNAL) 4 | #include "macho/dobby_symbol_resolver_priv.h" 5 | #endif 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | void *DobbySymbolResolver(const char *image_name, const char *symbol_name); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver_priv.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #if defined(__LP64__) 6 | typedef struct mach_header_64 mach_header_t; 7 | typedef struct segment_command_64 segment_command_t; 8 | typedef struct section_64 section_t; 9 | typedef struct nlist_64 nlist_t; 10 | #define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT_64 11 | #else 12 | typedef struct mach_header mach_header_t; 13 | typedef struct segment_command segment_command_t; 14 | typedef struct section section_t; 15 | typedef struct nlist nlist_t; 16 | #define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT 17 | #endif 18 | 19 | typedef struct macho_ctx { 20 | mach_header_t *header; 21 | 22 | uintptr_t slide; 23 | uintptr_t linkedit_base; 24 | 25 | segment_command_t *segments[64]; 26 | int segments_count; 27 | 28 | segment_command_t *text_seg; 29 | segment_command_t *data_seg; 30 | segment_command_t *text_exec_seg; 31 | segment_command_t *data_const_seg; 32 | segment_command_t *linkedit_seg; 33 | 34 | struct symtab_command *symtab_cmd; 35 | struct dysymtab_command *dysymtab_cmd; 36 | struct dyld_info_command *dyld_info_cmd; 37 | 38 | nlist_t *symtab; 39 | char *strtab; 40 | uint32_t *indirect_symtab; 41 | 42 | } macho_ctx_t; 43 | 44 | void macho_ctx_init(macho_ctx_t *ctx, mach_header_t *header); 45 | 46 | uintptr_t iterate_symbol_table(char *name_pattern, nlist_t *symtab, uint32_t symtab_count, char *strtab); 47 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/builtin-plugin/SymbolResolver/pe/dobby_symbol_resolver.cc: -------------------------------------------------------------------------------- 1 | #include "SymbolResolver/dobby_symbol_resolver.h" 2 | #include "common_header.h" 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "PlatformUtil/ProcessRuntimeUtility.h" 10 | 11 | #include 12 | 13 | #undef LOG_TAG 14 | #define LOG_TAG "DobbySymbolResolver" 15 | 16 | PUBLIC void *DobbySymbolResolver(const char *image_name, const char *symbol_name_pattern) { 17 | void *result = NULL; 18 | 19 | HMODULE hMod = LoadLibraryExA(image_name, NULL, DONT_RESOLVE_DLL_REFERENCES); 20 | result = GetProcAddress(hMod, symbol_name_pattern); 21 | if (result) 22 | return result; 23 | 24 | //result = resolve_elf_internal_symbol(image_name, symbol_name_pattern); 25 | return result; 26 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/cmake/Macros.cmake: -------------------------------------------------------------------------------- 1 | macro(SET_OPTION option value) 2 | set(${option} ${value} CACHE INTERNAL "" FORCE) 3 | endmacro() -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/cmake/Util.cmake: -------------------------------------------------------------------------------- 1 | # Check files list exist 2 | function(check_files_exist CHECK_FILES) 3 | foreach(file ${CHECK_FILES}) 4 | if(NOT EXISTS "${file}") 5 | message(FATAL_ERROR "${file} NOT EXISTS!") 6 | endif() 7 | endforeach() 8 | endfunction(check_files_exist CHECK_FILES) 9 | 10 | # Search suffix files 11 | function(search_suffix_files suffix INPUT_VARIABLE OUTPUT_VARIABLE) 12 | set(ResultFiles ) 13 | foreach(filePath ${${INPUT_VARIABLE}}) 14 | # message(STATUS "[*] searching *.${suffix} from ${filePath}") 15 | file(GLOB files ${filePath}/*.${suffix}) 16 | set(ResultFiles ${ResultFiles} ${files}) 17 | endforeach() 18 | set(${OUTPUT_VARIABLE} ${ResultFiles} PARENT_SCOPE) 19 | endfunction() 20 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/cmake/auto_source_group.cmake: -------------------------------------------------------------------------------- 1 | function (auto_source_group _folder _base _pattern) 2 | if (ARGC GREATER 3) 3 | set(_exclude ${ARGN}) 4 | else () 5 | set(_exclude) 6 | endif () 7 | file (GLOB _files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/ ${_folder}/*) 8 | set (folder_files) 9 | foreach (_fname ${_files}) 10 | if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_fname}) 11 | auto_source_group ("${_fname}" "${_base}" "${_pattern}" "${_exclude}") 12 | elseif (_fname MATCHES ${_pattern}) 13 | if(_exclude) 14 | if (NOT _fname MATCHES ${_exclude}) 15 | set(folder_files ${folder_files} ${_fname}) 16 | endif () 17 | else () 18 | set(folder_files ${folder_files} ${_fname}) 19 | endif () 20 | endif () 21 | endforeach () 22 | 23 | string(REPLACE "./" "" _folder2 ${_folder}) 24 | string(REPLACE "/" "\\" _folder2 ${_folder2}) 25 | if (_folder2 STREQUAL ".") 26 | source_group(${_base} FILES ${folder_files}) 27 | else () 28 | source_group(${_base}\\${_folder2} FILES ${folder_files}) 29 | endif () 30 | 31 | set(AUTO_FILES_RESULT ${AUTO_FILES_RESULT} ${folder_files} PARENT_SCOPE) 32 | endfunction () -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/cmake/platform/platform-darwin.cmake: -------------------------------------------------------------------------------- 1 | # set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE) 2 | set(CMAKE_INSTALL_NAME_DIR "@rpath") 3 | set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") 4 | add_library(DobbyX ${DOBBY_LIBRARY_TYPE} ${dobby.HEADER_FILE_LIST} ${dobby.SOURCE_FILE_LIST} ${logging.SOURCE_FILE_LIST} ${misc_helper.SOURCE_FILE_LIST} ${dobby.plugin.SOURCE_FILE_LIST}) 5 | 6 | set_target_properties(DobbyX 7 | PROPERTIES 8 | LINK_FLAGS "${linker_flags}" 9 | COMPILE_FLAGS "${compiler_flags}" 10 | ) 11 | 12 | # set framework property 13 | set_target_properties(DobbyX PROPERTIES 14 | FRAMEWORK TRUE 15 | FRAMEWORK_VERSION A 16 | MACOSX_FRAMEWORK_IDENTIFIER "com.dobby.dobby" 17 | # MACOSX_FRAMEWORK_INFO_PLIST Info.plist 18 | VERSION 1.0.0 # current version 19 | SOVERSION 1.0.0 # compatibility version 20 | PUBLIC_HEADER include/dobby.h 21 | XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" 22 | ) 23 | 24 | if ((SYSTEM.Darwin AND BUILDING_PLUGIN) AND (NOT BUILDING_KERNEL)) 25 | add_subdirectory(builtin-plugin/Dyld2HideLibrary) 26 | add_subdirectory(builtin-plugin/ObjcRuntimeHook) 27 | if (PROCESSOR.AARCH64) 28 | add_subdirectory(builtin-plugin/SupervisorCallMonitor) 29 | endif () 30 | endif() -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/cmake/xcode_generator_helper.cmake: -------------------------------------------------------------------------------- 1 | if(CMAKE_GENERATOR STREQUAL Xcode) 2 | message(STATUS "[*] Detect Xcode Project") 3 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug) 4 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release) 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug) 6 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release) 7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug) 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release) 9 | endif() -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(socket_example 2 | main.cc 3 | socket_example.cc 4 | ) 5 | 6 | target_link_libraries(socket_example 7 | dobby 8 | ) 9 | 10 | 11 | add_library(socket_example_x SHARED 12 | socket_example.cc 13 | ) 14 | 15 | target_link_libraries(socket_example_x 16 | dobby 17 | ) -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/examples/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char const *argv[]) { 9 | 10 | std::cout << "Start..." << std::endl; 11 | 12 | sleep(100); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/deprecated/misc-helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | if(NOT BUILDING_KERNEL) 4 | set(SOURCE_FILE_LIST 5 | ${CMAKE_CURRENT_SOURCE_DIR}/variable_cache.c 6 | ${CMAKE_CURRENT_SOURCE_DIR}/async_logger.cc 7 | ${CMAKE_CURRENT_SOURCE_DIR}/format_printer.cc 8 | ) 9 | else() 10 | set(SOURCE_FILE_LIST 11 | ${CMAKE_CURRENT_SOURCE_DIR}/format_printer.cc 12 | ) 13 | endif() 14 | 15 | add_library(misc_helper 16 | ${SOURCE_FILE_LIST} 17 | ${SOURCE_HEADER_LIST} 18 | ) -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/deprecated/misc-helper/deprecated/unistd_helper.h: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | 3 | #include 4 | #define open _open 5 | #define read _read 6 | #define O_RDONLY _O_RDONLY 7 | #define O_WRONLY _O_WRONLY 8 | #define O_CREAT _O_CREAT 9 | #define O_TRUNC _O_TRUNC 10 | 11 | #define ssize_t int 12 | 13 | #define STDIN_FILENO 0 14 | #define STDOUT_FILENO 1 15 | #define STDERR_FILENO 2 16 | /* should be in some equivalent to */ 17 | typedef __int8 int8_t; 18 | typedef __int16 int16_t; 19 | typedef __int32 int32_t; 20 | typedef __int64 int64_t; 21 | typedef unsigned __int8 uint8_t; 22 | typedef unsigned __int16 uint16_t; 23 | typedef unsigned __int32 uint32_t; 24 | typedef unsigned __int64 uint64_t; 25 | 26 | #else 27 | 28 | #include 29 | 30 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/deprecated/misc-helper/format_printer.cc: -------------------------------------------------------------------------------- 1 | #include "misc-helper/format_printer.h" 2 | 3 | void hexdump(const uint8_t *bytes, size_t len) { 4 | size_t ix; 5 | for (ix = 0; ix < len; ++ix) { 6 | if (ix != 0 && !(ix % 16)) 7 | LOG_FUNCTION_IMPL(0, "\n"); 8 | LOG_FUNCTION_IMPL(0, "%02X ", bytes[ix]); 9 | } 10 | LOG_FUNCTION_IMPL(0, "\n"); 11 | } 12 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/deprecated/misc-helper/misc-helper/async_logger.h: -------------------------------------------------------------------------------- 1 | #ifndef ASYNC_LOGGER_H 2 | #define ASYNC_LOGGER_H 3 | 4 | void async_logger_print(char *str); 5 | 6 | void async_logger_init(char *logger_path); 7 | 8 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/deprecated/misc-helper/misc-helper/format_printer.h: -------------------------------------------------------------------------------- 1 | #include "common_header.h" 2 | 3 | void hexdump(const uint8_t *bytes, size_t len); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/deprecated/misc-helper/misc-helper/variable_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIABLE_CACHE_H 2 | #define VARIABLE_CACHE_H 3 | 4 | #include 5 | 6 | #define cache_set stash 7 | void cache_set(const char *name, uint64_t value); 8 | 9 | #define cache_get(x) cache(x) 10 | #define assert_cache(x) (assert(cache(x)), cache(x)) 11 | uint64_t cache_get(const char *name); 12 | 13 | int serialized_to_file(const char *filepath); 14 | 15 | int unserialized_from_file(const char *filepath); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/logging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | if(NOT BUILDING_KERNEL) 4 | set(SOURCE_FILE_LIST 5 | ${CMAKE_CURRENT_SOURCE_DIR}/cxxlogging.cc 6 | ${CMAKE_CURRENT_SOURCE_DIR}/logging.c 7 | ) 8 | else() 9 | set(SOURCE_FILE_LIST 10 | ${CMAKE_CURRENT_SOURCE_DIR}/cxxlogging.cc 11 | ${CMAKE_CURRENT_SOURCE_DIR}/kernel_logging.c 12 | ) 13 | endif() 14 | add_library(logging 15 | ${SOURCE_FILE_LIST} 16 | ${SOURCE_HEADER_LIST} 17 | ) -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/logging/cxxlogging.cc: -------------------------------------------------------------------------------- 1 | #include "logging/cxxlogging.h" 2 | 3 | #if 1 || defined(BUILDING_KERNEL) 4 | void Logger::setLogLevel(LogLevel level) { 5 | log_level_ = level; 6 | } 7 | 8 | void Logger::log(LogLevel level, const char *tag, const char *fmt, ...) { 9 | 10 | } 11 | 12 | void Logger::LogFatal(const char *fmt, ...) { 13 | } 14 | #else 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void Logger::setLogLevel(LogLevel level) { 21 | log_level_ = level; 22 | } 23 | 24 | void Logger::log(LogLevel level, const char *tag, const char *fmt, ...) { 25 | if (level > log_level_) { 26 | va_list ap; 27 | 28 | va_start(ap, fmt); 29 | vprintf(fmt, ap); 30 | va_end(ap); 31 | } 32 | } 33 | 34 | void Logger::LogFatal(const char *fmt, ...) { 35 | } 36 | #endif 37 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/logging/kernel_logging.c: -------------------------------------------------------------------------------- 1 | #include "logging/logging.h" 2 | 3 | #include 4 | #include "utility_macro.h" 5 | 6 | #if defined(BUILDING_KERNEL) 7 | #define abort() 8 | #else 9 | #include 10 | #endif 11 | 12 | static int _log_level = 1; 13 | PUBLIC void log_set_level(int level) { 14 | _log_level = level; 15 | } 16 | 17 | PUBLIC int log_internal_impl(int level, const char *fmt, ...) { 18 | if (level < _log_level) 19 | return 0; 20 | 21 | va_list ap; 22 | va_start(ap, fmt); 23 | 24 | vprintf(fmt, ap); 25 | 26 | va_end(ap); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/logging/logging/cxxlogging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "logging.h" 4 | 5 | class Logger { 6 | public: 7 | void setLogLevel(LogLevel level); 8 | 9 | void log(LogLevel level, const char *tag, const char *fmt, ...); 10 | 11 | void LogFatal(const char *fmt, ...); 12 | 13 | private: 14 | LogLevel log_level_; 15 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/misc-helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | if(NOT BUILDING_KERNEL) 4 | set(SOURCE_FILE_LIST 5 | ${CMAKE_CURRENT_SOURCE_DIR}/variable_cache.c 6 | ${CMAKE_CURRENT_SOURCE_DIR}/async_logger.cc 7 | ${CMAKE_CURRENT_SOURCE_DIR}/format_printer.cc 8 | ) 9 | else() 10 | set(SOURCE_FILE_LIST 11 | ${CMAKE_CURRENT_SOURCE_DIR}/format_printer.cc 12 | ) 13 | endif() 14 | 15 | add_library(misc_helper 16 | ${SOURCE_FILE_LIST} 17 | ${SOURCE_HEADER_LIST} 18 | ) -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/misc-helper/deprecated/unistd_helper.h: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | 3 | #include 4 | #define open _open 5 | #define read _read 6 | #define O_RDONLY _O_RDONLY 7 | #define O_WRONLY _O_WRONLY 8 | #define O_CREAT _O_CREAT 9 | #define O_TRUNC _O_TRUNC 10 | 11 | #define ssize_t int 12 | 13 | #define STDIN_FILENO 0 14 | #define STDOUT_FILENO 1 15 | #define STDERR_FILENO 2 16 | /* should be in some equivalent to */ 17 | typedef __int8 int8_t; 18 | typedef __int16 int16_t; 19 | typedef __int32 int32_t; 20 | typedef __int64 int64_t; 21 | typedef unsigned __int8 uint8_t; 22 | typedef unsigned __int16 uint16_t; 23 | typedef unsigned __int32 uint32_t; 24 | typedef unsigned __int64 uint64_t; 25 | 26 | #else 27 | 28 | #include 29 | 30 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/misc-helper/format_printer.cc: -------------------------------------------------------------------------------- 1 | #include "misc-helper/format_printer.h" 2 | 3 | //void hexdump(const uint8_t *bytes, size_t len) { 4 | // size_t ix; 5 | // for (ix = 0; ix < len; ++ix) { 6 | // if (ix != 0 && !(ix % 16)) 7 | // RAW_LOG(0, "\n"); 8 | // RAW_LOG(0, "%02X ", bytes[ix]); 9 | // } 10 | // RAW_LOG(0, "\n"); 11 | //} 12 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/misc-helper/misc-helper/async_logger.h: -------------------------------------------------------------------------------- 1 | #ifndef ASYNC_LOGGER_H 2 | #define ASYNC_LOGGER_H 3 | 4 | void async_logger_print(char *str); 5 | 6 | void async_logger_init(char *logger_path); 7 | 8 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/misc-helper/misc-helper/format_printer.h: -------------------------------------------------------------------------------- 1 | #include "common_header.h" 2 | 3 | //void hexdump(const uint8_t *bytes, size_t len); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/external/misc-helper/misc-helper/variable_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIABLE_CACHE_H 2 | #define VARIABLE_CACHE_H 3 | 4 | #include 5 | 6 | #define cache_set stash 7 | void cache_set(const char *name, uint64_t value); 8 | 9 | #define cache_get(x) cache(x) 10 | #define assert_cache(x) (assert(cache(x)), cache(x)) 11 | uint64_t cache_get(const char *name); 12 | 13 | int serialized_to_file(const char *filepath); 14 | 15 | int unserialized_from_file(const char *filepath); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/scripts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:focal 2 | 3 | ARG DEBIAN_FRONTEND='noninteractive' 4 | 5 | RUN apt-key adv --keyserver 'keyserver.ubuntu.com' --recv-key 'C99B11DEB97541F0' && 6 | apt-add-repository -y -u 'https://cli.github.com/packages' && 7 | apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main' 8 | 9 | ADD setup_linux_cross_compile.sh /root/setup_linux_cross_compile.sh 10 | RUN sh /root/setup_linux_cross_compile.sh 11 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/scripts/setup_linux_cross_compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # if error, exit 4 | set - 5 | 6 | sudo apt update 7 | sudo apt-get install -y \ 8 | apt-utils \ 9 | build-essential \ 10 | curl \ 11 | wget \ 12 | unzip \ 13 | gcc-multilib \ 14 | make \ 15 | zsh 16 | 17 | mkdir -p ~/opt 18 | 19 | cd ~/opt 20 | CMAKE_VERSION=3.20.2 21 | CMAKE_DOWNLOAD_PACKAGE=cmake-$CMAKE_VERSION-linux-x86_64 22 | wget https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/$CMAKE_DOWNLOAD_PACKAGE.tar.gz && 23 | tar -zxf $CMAKE_DOWNLOAD_PACKAGE.tar.gz >/dev/null && 24 | mv $CMAKE_DOWNLOAD_PACKAGE cmake-$CMAKE_VERSION 25 | CMAKE_HOME=~/opt/cmake-$CMAKE_VERSION 26 | 27 | cd ~/opt 28 | LLVM_VERSION=14.0.0 29 | LLVM_DOWNLOAD_PACKAGE=clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-18.04 30 | wget https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_DOWNLOAD_PACKAGE.tar.xz && 31 | tar -xf $LLVM_DOWNLOAD_PACKAGE.tar.xz >/dev/null && 32 | mv $LLVM_DOWNLOAD_PACKAGE llvm-$LLVM_VERSION 33 | LLVM_HOME=~/opt/llvm-$LLVM_VERSION 34 | 35 | cd ~/opt 36 | NDK_VERSION=r25b 37 | NDK_DOWNLOAD_PACKAGE=android-ndk-$NDK_VERSION-linux 38 | NDK_DOWNLOAD_UNZIP_PACKAGE=android-ndk-$NDK_VERSION 39 | wget https://dl.google.com/android/repository/$NDK_DOWNLOAD_PACKAGE.zip && 40 | unzip -q $NDK_DOWNLOAD_PACKAGE.zip >/dev/null && 41 | mv $NDK_DOWNLOAD_UNZIP_PACKAGE ndk-$NDK_VERSION && 42 | rm $NDK_DOWNLOAD_PACKAGE.zip 43 | ANDROID_NDK_HOME=~/opt/android-ndk-$NDK_VERSION 44 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/scripts/setup_macos_cross_compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # if error, exit 4 | set - 5 | 6 | mkdir -p ~/opt 7 | 8 | cd ~/opt 9 | CMAKE_VERSION=3.20.2 10 | CMAKE_DOWNLOAD_PACKAGE=cmake-$CMAKE_VERSION-macos-universal 11 | wget https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/$CMAKE_DOWNLOAD_PACKAGE.tar.gz && 12 | tar -zxf $CMAKE_DOWNLOAD_PACKAGE.tar.gz >/dev/null && 13 | mv $CMAKE_DOWNLOAD_PACKAGE cmake-$CMAKE_VERSION 14 | CMAKE_HOME=~/opt/cmake-$CMAKE_VERSION 15 | 16 | cd ~/opt 17 | LLVM_VERSION=14.0.0 18 | LLVM_DOWNLOAD_PACKAGE=clang+llvm-$LLVM_VERSION-x86_64-apple-darwin 19 | wget https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_DOWNLOAD_PACKAGE.tar.xz && 20 | tar -xf $LLVM_DOWNLOAD_PACKAGE.tar.xz >/dev/null && 21 | mv $LLVM_DOWNLOAD_PACKAGE llvm-$LLVM_VERSION 22 | LLVM_HOME=~/opt/llvm-$LLVM_VERSION 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/KernelMode/ExecMemory/clear-cache-tool-all.c: -------------------------------------------------------------------------------- 1 | void ClearCache(void *start, void *end) { 2 | return; 3 | } 4 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/KernelMode/PlatformUtil/ProcessRuntimeUtility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "PlatformUnifiedInterface/MemoryAllocator.h" 4 | 5 | #include "UnifiedInterface/platform.h" 6 | 7 | typedef struct _RuntimeModule { 8 | char path[1024]; 9 | void *load_address; 10 | } RuntimeModule; 11 | 12 | struct MemRegion : MemRange { 13 | MemoryPermission permission; 14 | MemRegion(addr_t addr, size_t size, MemoryPermission perm): MemRange(addr, size), permission(perm) { 15 | 16 | } 17 | }; 18 | 19 | class ProcessRuntimeUtility { 20 | public: 21 | static const std::vector &GetProcessMemoryLayout(); 22 | 23 | static const std::vector *GetProcessModuleMap(); 24 | 25 | static RuntimeModule GetProcessModule(const char *name); 26 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/KernelMode/UnifiedInterface/exec_mem_placeholder.asm: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define PAGE_SHIFT 14 4 | .align PAGE_SHIFT 5 | 6 | .globl EXT(kernel_executable_memory_placeholder) 7 | EXT(kernel_executable_memory_placeholder): 8 | .rept 0x4000/4 9 | .long 0x41414141 10 | .endr -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/KernelMode/UnifiedInterface/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_INTERFACE_COMMON_PLATFORM_H 2 | #define PLATFORM_INTERFACE_COMMON_PLATFORM_H 3 | 4 | #include "common_header.h" 5 | 6 | // ================================================================ 7 | // base :: OSMemory 8 | 9 | enum MemoryPermission { kNoAccess, kRead, kReadWrite, kReadWriteExecute, kReadExecute }; 10 | 11 | class OSMemory { 12 | public: 13 | static int PageSize(); 14 | 15 | static void *Allocate(size_t size, MemoryPermission access); 16 | 17 | static void *Allocate(size_t size, MemoryPermission access, void *fixed_address); 18 | 19 | static bool Free(void *address, size_t size); 20 | 21 | static bool Release(void *address, size_t size); 22 | 23 | static bool SetPermission(void *address, size_t size, MemoryPermission access); 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/ExecMemory/code-patch-tool-posix.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "dobby_internal.h" 3 | #include "core/arch/Cpu.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #if !defined(__APPLE__) 10 | PUBLIC MemoryOperationError DobbyCodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) { 11 | #if defined(__ANDROID__) || defined(__linux__) 12 | int page_size = (int)sysconf(_SC_PAGESIZE); 13 | uintptr_t patch_page = ALIGN_FLOOR(address, page_size); 14 | uintptr_t patch_end_page = ALIGN_FLOOR((uintptr_t)address + buffer_size, page_size); 15 | 16 | // change page permission as rwx 17 | mprotect((void *)patch_page, page_size, PROT_READ | PROT_WRITE | PROT_EXEC); 18 | if (patch_page != patch_end_page) { 19 | mprotect((void *)patch_end_page, page_size, PROT_READ | PROT_WRITE | PROT_EXEC); 20 | } 21 | 22 | // patch buffer 23 | memcpy(address, buffer, buffer_size); 24 | 25 | // restore page permission 26 | mprotect((void *)patch_page, page_size, PROT_READ | PROT_EXEC); 27 | if (patch_page != patch_end_page) { 28 | mprotect((void *)patch_end_page, page_size, PROT_READ | PROT_EXEC); 29 | } 30 | 31 | addr_t clear_start_ = (addr_t)address; 32 | ClearCache((void *)clear_start_, (void *)(clear_start_ + buffer_size)); 33 | #endif 34 | return kMemoryOperationSuccess; 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/ExecMemory/code-patch-tool-windows.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include 4 | 5 | using namespace zz; 6 | 7 | PUBLIC MemoryOperationError DobbyCodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) { 8 | DWORD oldProtect; 9 | int page_size; 10 | 11 | // Get page size 12 | SYSTEM_INFO si; 13 | GetSystemInfo(&si); 14 | page_size = si.dwPageSize; 15 | 16 | void *addressPageAlign = (void *)ALIGN(address, page_size); 17 | 18 | if (!VirtualProtect(addressPageAlign, page_size, PAGE_EXECUTE_READWRITE, &oldProtect)) 19 | return kMemoryOperationError; 20 | 21 | memcpy(address, buffer, buffer_size); 22 | 23 | if (!VirtualProtect(addressPageAlign, page_size, oldProtect, &oldProtect)) 24 | return kMemoryOperationError; 25 | 26 | return kMemoryOperationSuccess; 27 | } 28 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/ExecMemory/substrated/mach_interface_support/substrated.defs: -------------------------------------------------------------------------------- 1 | /* 2 | * Regenerate with: 3 | * 4 | * $(xcrun --sdk macosx -f mig) \ 5 | * -isysroot $(xcrun --sdk macosx --show-sdk-path) \ 6 | * -sheader substratedserver.h \ 7 | * -server substratedserver.c \ 8 | * -header substratedclient.h \ 9 | * -user substratedclient.c \ 10 | * substrated.defs 11 | */ 12 | 13 | subsystem substrated 9000; 14 | 15 | #include 16 | #include 17 | 18 | routine substrated_mark ( 19 | server : mach_port_t; 20 | task : vm_task_entry_t; 21 | source_address : mach_vm_address_t; 22 | source_size : mach_vm_size_t; 23 | inout target_address : mach_vm_address_t 24 | ); 25 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.cpp: -------------------------------------------------------------------------------- 1 | #include "MultiThreadSupport/ThreadSupport.h" 2 | 3 | using namespace zz; 4 | 5 | OSThread::LocalStorageKey ThreadSupport::thread_callstack_key_ = 0; 6 | 7 | // Get current CallStack 8 | CallStack *ThreadSupport::CurrentThreadCallStack() { 9 | 10 | // TODO: __attribute__((destructor)) is better ? 11 | if (!thread_callstack_key_) { 12 | thread_callstack_key_ = OSThread::CreateThreadLocalKey(); 13 | } 14 | 15 | if (OSThread::HasThreadLocal(thread_callstack_key_)) { 16 | return static_cast(OSThread::GetThreadLocal(thread_callstack_key_)); 17 | } else { 18 | CallStack *callstack = new CallStack(); 19 | OSThread::SetThreadLocal(thread_callstack_key_, callstack); 20 | return callstack; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/PlatformUtil/ProcessRuntimeUtility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "PlatformUnifiedInterface/MemoryAllocator.h" 4 | 5 | #include "UnifiedInterface/platform.h" 6 | 7 | typedef struct _RuntimeModule { 8 | char path[1024]; 9 | void *load_address; 10 | } RuntimeModule; 11 | 12 | struct MemRegion : MemRange { 13 | MemoryPermission permission; 14 | 15 | MemRegion(addr_t addr, size_t size, MemoryPermission perm) : MemRange(addr, size), permission(perm) { 16 | } 17 | }; 18 | 19 | class ProcessRuntimeUtility { 20 | public: 21 | static const std::vector &GetProcessMemoryLayout(); 22 | 23 | static const std::vector &GetProcessModuleMap(); 24 | 25 | static RuntimeModule GetProcessModule(const char *name); 26 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/Thread/PlatformThread.cc: -------------------------------------------------------------------------------- 1 | #include "./PlatformThread.h" 2 | 3 | namespace zz { 4 | int OSThread::GetThreadLocalInt(LocalStorageKey key) { 5 | return static_cast(reinterpret_cast(GetThreadLocal(key))); 6 | } 7 | 8 | void OSThread::SetThreadLocalInt(LocalStorageKey key, int value) { 9 | SetThreadLocal(key, reinterpret_cast(static_cast(value))); 10 | } 11 | 12 | bool OSThread::HasThreadLocal(LocalStorageKey key) { 13 | return GetThreadLocal(key) != nullptr; 14 | } 15 | 16 | void *OSThread::GetExistingThreadLocal(LocalStorageKey key) { 17 | return GetThreadLocal(key); 18 | } 19 | } // namespace zz -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/Thread/PlatformThread.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_MODE_PLATFORM_THREAD_H 2 | #define USER_MODE_PLATFORM_THREAD_H 3 | 4 | #include "common_header.h" 5 | 6 | namespace zz { 7 | 8 | class OSThread { 9 | public: 10 | typedef int LocalStorageKey; 11 | 12 | static int GetCurrentProcessId(); 13 | 14 | static int GetCurrentThreadId(); 15 | 16 | // Thread-local storage. 17 | static LocalStorageKey CreateThreadLocalKey(); 18 | 19 | static void DeleteThreadLocalKey(LocalStorageKey key); 20 | 21 | static void *GetThreadLocal(LocalStorageKey key); 22 | 23 | static int GetThreadLocalInt(LocalStorageKey key); 24 | 25 | static void SetThreadLocal(LocalStorageKey key, void *value); 26 | 27 | static void SetThreadLocalInt(LocalStorageKey key, int value); 28 | 29 | static bool HasThreadLocal(LocalStorageKey key); 30 | 31 | static void *GetExistingThreadLocal(LocalStorageKey key); 32 | }; 33 | 34 | } // namespace zz 35 | 36 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Backend/UserMode/Thread/platform-thread-windows.cc: -------------------------------------------------------------------------------- 1 | #include "PlatformThread.h" 2 | 3 | using namespace zz; 4 | 5 | int OSThread::GetCurrentProcessId() { 6 | return 0; 7 | } 8 | 9 | int OSThread::GetCurrentThreadId() { 10 | return 0; 11 | } 12 | 13 | OSThread::LocalStorageKey OSThread::CreateThreadLocalKey() { 14 | return 0; 15 | } 16 | 17 | void OSThread::DeleteThreadLocalKey(LocalStorageKey key) { 18 | } 19 | 20 | void *OSThread::GetThreadLocal(LocalStorageKey key) { 21 | return NULL; 22 | } 23 | 24 | void OSThread::SetThreadLocal(LocalStorageKey key, void *value) { 25 | } 26 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InstructionRelocation/InstructionRelocation.h: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | void GenRelocateCode(void *buffer, CodeMemBlock *origin, CodeMemBlock *relocated, bool branch); 4 | 5 | void GenRelocateCodeAndBranch(void *buffer, CodeMemBlock *origin, CodeMemBlock *relocated); 6 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InstructionRelocation/arm64/InstructionRelocationARM64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "core/arch/arm64/constants-arm64.h" 6 | 7 | #if 0 8 | namespace zz { 9 | namespace arm64 { 10 | void GenRelocateCodeAndBranch(void *buffer, CodeMemBlock *origin, CodeMemBlock *relocated); 11 | } // namespace arm64 12 | } // namespace zz 13 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InstructionRelocation/arm64/inst_constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if 0 4 | enum LoadRegLiteralOp { 5 | LoadRegLiteralFixed = 0x18000000, 6 | LoadRegLiteralFixedMask = 0x3B000000, 7 | LoadRegLiteralMask = 0xFF000000, 8 | }; 9 | 10 | // PC relative addressing. 11 | enum PCRelAddressingOp { 12 | PCRelAddressingFixed = 0x10000000, 13 | PCRelAddressingFixedMask = 0x1F000000, 14 | PCRelAddressingMask = 0x9F000000, 15 | ADR = PCRelAddressingFixed | 0x00000000, 16 | ADRP = PCRelAddressingFixed | 0x80000000 17 | }; 18 | 19 | // Unconditional branch. 20 | enum UnconditionalBranchOp { 21 | UnconditionalBranchFixed = 0x14000000, 22 | UnconditionalBranchFixedMask = 0x7C000000, 23 | UnconditionalBranchMask = 0xFC000000, 24 | 25 | B = UnconditionalBranchFixed | 0x00000000, 26 | BL = UnconditionalBranchFixed | 0x80000000 27 | }; 28 | #endif 29 | 30 | // Compare and branch. 31 | enum CompareBranchOp { 32 | CompareBranchFixed = 0x34000000, 33 | CompareBranchFixedMask = 0x7E000000, 34 | CompareBranchMask = 0xFF000000, 35 | }; 36 | 37 | // Conditional branch. 38 | enum ConditionalBranchOp { 39 | ConditionalBranchFixed = 0x54000000, 40 | ConditionalBranchFixedMask = 0xFE000000, 41 | ConditionalBranchMask = 0xFF000010, 42 | }; 43 | 44 | // Test and branch. 45 | enum TestBranchOp { 46 | TestBranchFixed = 0x36000000, 47 | TestBranchFixedMask = 0x7E000000, 48 | TestBranchMask = 0x7F000000, 49 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InstructionRelocation/x64/InstructionRelocationX64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common_header.h" 4 | 5 | #include "core/arch/x64/constants-x64.h" 6 | 7 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 8 | 9 | #include "InstructionRelocation/x86/InstructionRelocationX86Shared.h" 10 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InstructionRelocation/x86/InstructionRelocationX86.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common_header.h" 4 | 5 | #include "core/arch/x86/constants-x86.h" 6 | 7 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 8 | 9 | #include "InstructionRelocation/x86/InstructionRelocationX86Shared.h" 10 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InstructionRelocation/x86/InstructionRelocationX86Shared.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common_header.h" 4 | 5 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 6 | 7 | #include "x86_insn_decode/x86_insn_decode.h" 8 | 9 | int GenRelocateCodeFixed(void *buffer, CodeMemBlock *origin, CodeMemBlock *relocated, bool branch); 10 | 11 | void GenRelocateCodeX86Shared(void *buffer, CodeMemBlock *origin, CodeMemBlock *relocated, bool branch); 12 | 13 | int GenRelocateSingleX86Insn(addr_t curr_orig_ip, addr_t curr_relo_ip, uint8_t *buffer_cursor, 14 | AssemblerBase *assembler, CodeBufferBase *code_buffer, x86_insn_decode_t &insn, int8_t mode); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptEntry.cpp: -------------------------------------------------------------------------------- 1 | #include "InterceptEntry.h" 2 | #include "Interceptor.h" 3 | 4 | InterceptEntry::InterceptEntry(InterceptEntryType type, addr_t address) { 5 | this->type = type; 6 | 7 | #if defined(TARGET_ARCH_ARM) 8 | if (address % 2) { 9 | address -= 1; 10 | this->thumb_mode = true; 11 | } 12 | #endif 13 | 14 | this->patched_addr = address; 15 | this->id = Interceptor::SharedInstance()->count(); 16 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptEntry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "common_header.h" 5 | 6 | typedef enum { kFunctionInlineHook, kInstructionInstrument } InterceptEntryType; 7 | 8 | class InterceptRouting; 9 | 10 | typedef struct InterceptEntry { 11 | uint32_t id; 12 | InterceptEntryType type; 13 | InterceptRouting *routing; 14 | 15 | union { 16 | addr_t addr; 17 | addr_t patched_addr; 18 | }; 19 | uint32_t patched_size; 20 | 21 | addr_t relocated_addr; 22 | uint32_t relocated_size; 23 | 24 | uint8_t origin_insns[256]; 25 | uint32_t origin_insn_size; 26 | 27 | bool thumb_mode; 28 | 29 | InterceptEntry(InterceptEntryType type, addr_t address); 30 | } InterceptEntry; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/InterceptRouting.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "InterceptEntry.h" 4 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 5 | #include "InstructionRelocation/InstructionRelocation.h" 6 | #include "TrampolineBridge/Trampoline/Trampoline.h" 7 | 8 | class InterceptRouting { 9 | public: 10 | explicit InterceptRouting(InterceptEntry *entry) : entry_(entry) { 11 | entry->routing = this; 12 | 13 | origin_ = nullptr; 14 | relocated_ = nullptr; 15 | 16 | trampoline_ = nullptr; 17 | trampoline_buffer_ = nullptr; 18 | trampoline_target_ = 0; 19 | } 20 | 21 | virtual void DispatchRouting() = 0; 22 | 23 | virtual void Prepare(); 24 | 25 | virtual void Active(); 26 | 27 | void Commit(); 28 | 29 | InterceptEntry *GetInterceptEntry(); 30 | 31 | void SetTrampolineBuffer(CodeBufferBase *buffer) { 32 | trampoline_buffer_ = buffer; 33 | } 34 | 35 | CodeBufferBase *GetTrampolineBuffer() { 36 | return trampoline_buffer_; 37 | } 38 | 39 | void SetTrampolineTarget(addr_t address) { 40 | trampoline_target_ = address; 41 | } 42 | 43 | addr_t GetTrampolineTarget() { 44 | return trampoline_target_; 45 | } 46 | 47 | protected: 48 | bool GenerateRelocatedCode(); 49 | 50 | bool GenerateTrampolineBuffer(addr_t src, addr_t dst); 51 | 52 | protected: 53 | InterceptEntry *entry_; 54 | 55 | CodeMemBlock *origin_; 56 | CodeMemBlock *relocated_; 57 | 58 | CodeMemBlock *trampoline_; 59 | // trampoline buffer before active 60 | CodeBufferBase *trampoline_buffer_; 61 | addr_t trampoline_target_; 62 | }; 63 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/FunctionInlineHook/FunctionInlineHookRouting.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "InterceptRouting/InterceptRouting.h" 6 | 7 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 8 | 9 | class FunctionInlineHookRouting : public InterceptRouting { 10 | public: 11 | FunctionInlineHookRouting(InterceptEntry *entry, dobby_dummy_func_t replace_func) : InterceptRouting(entry) { 12 | this->replace_func = replace_func; 13 | } 14 | 15 | void DispatchRouting() override; 16 | 17 | private: 18 | void BuildRouting(); 19 | 20 | private: 21 | dobby_dummy_func_t replace_func; 22 | }; 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/FunctionInlineHook/RoutingImpl.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | #include "InterceptRouting/Routing/FunctionInlineHook/FunctionInlineHookRouting.h" 3 | 4 | void FunctionInlineHookRouting::BuildRouting() { 5 | SetTrampolineTarget((addr_t)replace_func); 6 | 7 | // generate trampoline buffer, run before GenerateRelocatedCode 8 | addr_t from = entry_->patched_addr; 9 | #if defined(TARGET_ARCH_ARM) 10 | if (entry_->thumb_mode) 11 | from += 1; 12 | #endif 13 | addr_t to = GetTrampolineTarget(); 14 | GenerateTrampolineBuffer(from, to); 15 | } 16 | 17 | void FunctionInlineHookRouting::DispatchRouting() { 18 | BuildRouting(); 19 | 20 | // generate relocated code which size == trampoline size 21 | GenerateRelocatedCode(); 22 | } 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/FunctionWrapper/FunctionWrapperExport.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include "logging/logging.h" 4 | 5 | #include "Interceptor.h" 6 | #include "InterceptRouting/InterceptRouting.h" 7 | 8 | #include "function-wrapper.h" 9 | 10 | PUBLIC int DobbyWrap(void *function_address, PreCallTy pre_call, PostCallTy post_call) { 11 | DLOG(0, "Initialize 'DobbyWrap' hook at %p", function_address); 12 | 13 | Interceptor *interceptor = Interceptor::SharedInstance(); 14 | 15 | InterceptEntry *entry = new InterceptEntry(); 16 | entry->id = interceptor->entries->getCount(); 17 | entry->type = kFunctionWrapper; 18 | entry->function_address = function_address; 19 | 20 | FunctionWrapperRouting *routing = new FunctionWrapperRouting(entry); 21 | routing->DispatchRouting(); 22 | interceptor->addHookEntry(entry); 23 | routing->Commit(); 24 | 25 | DLOG(0, "Finalize %p", function_address); 26 | return RS_SUCCESS; 27 | } 28 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/FunctionWrapper/function-wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTION_WRAPPER_H 2 | #define FUNCTION_WRAPPER_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 7 | #include "InterceptRouting/InterceptRouting.h" 8 | #include "Interceptor.h" 9 | 10 | #if TARGET_ARCH_IA32 11 | #elif TARGET_ARCH_X64 12 | #include "InterceptRouting/x64/X64InterceptRouting.h" 13 | #elif TARGET_ARCH_ARM64 14 | #include "InterceptRouting/arm64/ARM64InterceptRouting.h" 15 | #elif TARGET_ARCH_ARM 16 | #else 17 | #error "unsupported architecture" 18 | #endif 19 | 20 | class FunctionWrapperRouting : public InterceptRouting { 21 | public: 22 | FunctionWrapperRouting(InterceptEntry *entry) : InterceptRouting(entry) { 23 | } 24 | 25 | void DispatchRouting(); 26 | 27 | void *GetTrampolineTarget(); 28 | 29 | private: 30 | void BuildPreCallRouting(); 31 | 32 | void BuildPostCallRouting(); 33 | 34 | private: 35 | void *prologue_dispatch_bridge; 36 | 37 | void *epilogue_dispatch_bridge; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/FunctionWrapper/intercept_routing_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTION_WRAPPER_INTERCEPT_ROUTING_HANDLER_H 2 | #define FUNCTION_WRAPPER_INTERCEPT_ROUTING_HANDLER_H 3 | 4 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 5 | #include "Interceptor.h" 6 | #include "dobby_internal.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif //__cplusplus 11 | 12 | // Dispatch the routing befor running the origin function 13 | void prologue_routing_dispatch(DobbyRegisterContext *ctx, ClosureTrampolineEntry *entry); 14 | 15 | // Dispatch the routing before the function return . (as it's implementation by relpace `return address` in the stack 16 | // ,or LR register) 17 | void epilogue_routing_dispatch(DobbyRegisterContext *ctx, ClosureTrampolineEntry *entry); 18 | 19 | void pre_call_forward_handler(DobbyRegisterContext *ctx, InterceptEntry *entry); 20 | 21 | void post_call_forward_handler(DobbyRegisterContext *ctx, InterceptEntry *entry); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif //__cplusplus 26 | 27 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/InstructionInstrument/InstructionInstrument.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include "Interceptor.h" 4 | #include "InterceptRouting/InterceptRouting.h" 5 | #include "InterceptRouting/Routing/InstructionInstrument/InstructionInstrumentRouting.h" 6 | 7 | PUBLIC int DobbyInstrument(void *address, dobby_instrument_callback_t pre_handler) { 8 | if (!address) { 9 | ERROR_LOG("address is 0x0.\n"); 10 | return RS_FAILED; 11 | } 12 | 13 | #if defined(__APPLE__) && defined(__arm64__) 14 | #if __has_feature(ptrauth_calls) 15 | address = ptrauth_strip(address, ptrauth_key_asia); 16 | #endif 17 | #endif 18 | 19 | #if defined(ANDROID) 20 | void *page_align_address = (void *)ALIGN_FLOOR(address, OSMemory::PageSize()); 21 | if (!OSMemory::SetPermission(page_align_address, OSMemory::PageSize(), kReadExecute)) { 22 | return RS_FAILED; 23 | } 24 | #endif 25 | 26 | DLOG(0, "\n\n----- [DobbyInstrument:%p] -----", address); 27 | 28 | auto entry = Interceptor::SharedInstance()->find((addr_t)address); 29 | if (entry) { 30 | ERROR_LOG("%s already been instrumented.", address); 31 | return RS_FAILED; 32 | } 33 | 34 | entry = new InterceptEntry(kInstructionInstrument, (addr_t)address); 35 | 36 | auto routing = new InstructionInstrumentRouting(entry, pre_handler, nullptr); 37 | routing->Prepare(); 38 | routing->DispatchRouting(); 39 | routing->Commit(); 40 | 41 | Interceptor::SharedInstance()->add(entry); 42 | 43 | return RS_SUCCESS; 44 | } 45 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/InstructionInstrument/InstructionInstrumentRouting.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "InterceptRouting/InterceptRouting.h" 6 | 7 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 8 | 9 | class InstructionInstrumentRouting : public InterceptRouting { 10 | public: 11 | InstructionInstrumentRouting(InterceptEntry *entry, dobby_instrument_callback_t pre_handler, 12 | dobby_instrument_callback_t post_handler) 13 | : InterceptRouting(entry) { 14 | this->prologue_dispatch_bridge = nullptr; 15 | this->pre_handler = pre_handler; 16 | this->post_handler = post_handler; 17 | } 18 | 19 | void DispatchRouting() override; 20 | 21 | private: 22 | void BuildRouting(); 23 | 24 | public: 25 | dobby_instrument_callback_t pre_handler; 26 | dobby_instrument_callback_t post_handler; 27 | 28 | private: 29 | void *prologue_dispatch_bridge; 30 | }; 31 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/InstructionInstrument/RoutingImpl.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "dobby_internal.h" 3 | 4 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 5 | 6 | #include "InterceptRouting/Routing/InstructionInstrument/InstructionInstrumentRouting.h" 7 | #include "InterceptRouting/Routing/InstructionInstrument/instrument_routing_handler.h" 8 | 9 | // create closure trampoline jump to prologue_routing_dispatch with the `entry_` data 10 | void InstructionInstrumentRouting::BuildRouting() { 11 | void *handler = (void *)instrument_routing_dispatch; 12 | #if defined(__APPLE__) && defined(__arm64__) 13 | #if __has_feature(ptrauth_calls) 14 | handler = ptrauth_strip(handler, ptrauth_key_asia); 15 | #endif 16 | #endif 17 | auto closure_trampoline = ClosureTrampoline::CreateClosureTrampoline(entry_, handler); 18 | this->SetTrampolineTarget((addr_t)closure_trampoline->address); 19 | DLOG(0, "[closure trampoline] closure trampoline: %p, data: %p", closure_trampoline->address, entry_); 20 | 21 | // generate trampoline buffer, before `GenerateRelocatedCode` 22 | addr_t from = entry_->patched_addr; 23 | #if defined(TARGET_ARCH_ARM) 24 | if (entry_->thumb_mode) 25 | from += 1; 26 | #endif 27 | addr_t to = GetTrampolineTarget(); 28 | GenerateTrampolineBuffer(from, to); 29 | } 30 | 31 | void InstructionInstrumentRouting::DispatchRouting() { 32 | BuildRouting(); 33 | 34 | // generate relocated code which size == trampoline size 35 | GenerateRelocatedCode(); 36 | } 37 | 38 | #if 0 39 | void *InstructionInstrumentRouting::GetTrampolineTarget() { 40 | return this->prologue_dispatch_bridge; 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/InstructionInstrument/instrument_routing_handler.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include "InterceptRouting/Routing/InstructionInstrument/InstructionInstrumentRouting.h" 4 | #include "InterceptRouting/Routing/InstructionInstrument/instrument_routing_handler.h" 5 | 6 | #include "TrampolineBridge/ClosureTrampolineBridge/common_bridge_handler.h" 7 | 8 | void instrument_forward_handler(InterceptEntry *entry, DobbyRegisterContext *ctx) { 9 | auto routing = static_cast(entry->routing); 10 | if (routing->pre_handler) { 11 | auto handler = (dobby_instrument_callback_t)routing->pre_handler; 12 | (*handler)((void *)entry->patched_addr, ctx); 13 | } 14 | 15 | // set prologue bridge next hop address as relocated instructions 16 | set_routing_bridge_next_hop(ctx, (void *)entry->relocated_addr); 17 | } 18 | 19 | void instrument_routing_dispatch(InterceptEntry *entry, DobbyRegisterContext *ctx) { 20 | instrument_forward_handler(entry, ctx); 21 | } 22 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/Routing/InstructionInstrument/instrument_routing_handler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | extern "C" { 6 | void instrument_routing_dispatch(InterceptEntry *entry, DobbyRegisterContext *ctx); 7 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/NearBranchTrampoline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 6 | 7 | class NearBranchTrampolinePlugin : public RoutingPluginInterface { 8 | bool Prepare(InterceptRouting *routing) { 9 | return false; 10 | }; 11 | 12 | bool Active(InterceptRouting *routing); 13 | 14 | bool GenerateTrampolineBuffer(InterceptRouting *routing, addr_t src, addr_t dst); 15 | }; 16 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc: -------------------------------------------------------------------------------- 1 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 2 | 3 | std::vector RoutingPluginManager::plugins; 4 | 5 | RoutingPluginInterface *RoutingPluginManager::near_branch_trampoline = NULL; 6 | 7 | void RoutingPluginManager::registerPlugin(const char *name, RoutingPluginInterface *plugin) { 8 | DLOG(0, "register %s plugin", name); 9 | 10 | RoutingPluginManager::plugins.push_back(plugin); 11 | } 12 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/InterceptRouting/RoutingPlugin/RoutingPlugin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "InterceptRouting/InterceptRouting.h" 6 | 7 | class RoutingPluginInterface { 8 | public: 9 | // @Return: if false will continue to iter next plugin 10 | virtual bool Prepare(InterceptRouting *routing) = 0; 11 | 12 | // @Return: if false will continue to iter next plugin 13 | virtual bool Active(InterceptRouting *routing) = 0; 14 | 15 | // @Return: if false will continue to iter next plugin 16 | virtual bool GenerateTrampolineBuffer(InterceptRouting *routing, addr_t src, addr_t dst) = 0; 17 | 18 | private: 19 | char name_[256]; 20 | }; 21 | 22 | class RoutingPluginManager { 23 | public: 24 | static void registerPlugin(const char *name, RoutingPluginInterface *plugin); 25 | 26 | public: 27 | static std::vector plugins; 28 | 29 | static RoutingPluginInterface *near_branch_trampoline; 30 | }; 31 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Interceptor.cpp: -------------------------------------------------------------------------------- 1 | #include "Interceptor.h" 2 | 3 | Interceptor *Interceptor::instance = nullptr; 4 | 5 | Interceptor *Interceptor::SharedInstance() { 6 | if (Interceptor::instance == nullptr) { 7 | Interceptor::instance = new Interceptor(); 8 | } 9 | return Interceptor::instance; 10 | } 11 | 12 | InterceptEntry *Interceptor::find(addr_t addr) { 13 | for (auto *entry : entries) { 14 | if (entry->patched_addr == addr) { 15 | return entry; 16 | } 17 | } 18 | return nullptr; 19 | } 20 | 21 | void Interceptor::add(InterceptEntry *entry) { 22 | entries.push_back(entry); 23 | } 24 | 25 | void Interceptor::remove(addr_t addr) { 26 | for (auto iter = entries.begin(); iter != entries.end(); iter++) { 27 | if ((*iter)->patched_addr == addr) { 28 | entries.erase(iter); 29 | break; 30 | } 31 | } 32 | } 33 | 34 | const InterceptEntry *Interceptor::getEntry(int i) { 35 | return entries[i]; 36 | } 37 | 38 | int Interceptor::count() { 39 | return entries.size(); 40 | } 41 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/Interceptor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | #include "InterceptEntry.h" 5 | 6 | class Interceptor { 7 | public: 8 | static Interceptor *SharedInstance(); 9 | 10 | public: 11 | InterceptEntry *find(addr_t addr); 12 | 13 | void remove(addr_t addr); 14 | 15 | void add(InterceptEntry *entry); 16 | 17 | const InterceptEntry *getEntry(int i); 18 | 19 | int count(); 20 | 21 | private: 22 | static Interceptor *instance; 23 | 24 | tinystl::vector entries; 25 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/AssemblyCodeBuilder.cc: -------------------------------------------------------------------------------- 1 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 2 | 3 | #include "dobby_internal.h" 4 | #include "PlatformUnifiedInterface/ExecMemory/CodePatchTool.h" 5 | 6 | AssemblyCode *AssemblyCodeBuilder::FinalizeFromTurboAssembler(AssemblerBase *assembler) { 7 | auto buffer = (CodeBufferBase *)assembler->GetCodeBuffer(); 8 | auto realized_addr = (addr_t)assembler->GetRealizedAddress(); 9 | #if defined(TEST_WITH_UNICORN) 10 | // impl: unicorn emulator map memory 11 | realized_addr = 0; 12 | #endif 13 | if (!realized_addr) { 14 | size_t buffer_size = 0; 15 | buffer_size = buffer->GetBufferSize(); 16 | #if TARGET_ARCH_ARM 17 | // extra bytes for align needed 18 | buffer_size += 4; 19 | #endif 20 | 21 | auto block = MemoryAllocator::SharedAllocator()->allocateExecBlock(buffer_size); 22 | if (block == nullptr) 23 | return nullptr; 24 | 25 | realized_addr = block->addr; 26 | assembler->SetRealizedAddress((void *)realized_addr); 27 | } 28 | 29 | // Realize the buffer code to the executable memory address, remove the external label, etc 30 | DobbyCodePatch((void *)realized_addr, buffer->GetBuffer(), buffer->GetBufferSize()); 31 | 32 | auto block = new AssemblyCode(realized_addr, buffer->GetBufferSize()); 33 | return block; 34 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/AssemblyCodeBuilder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "PlatformUnifiedInterface/MemoryAllocator.h" 4 | 5 | #include "core/assembler/assembler.h" 6 | 7 | using namespace zz; 8 | 9 | using AssemblyCode = CodeMemBlock; 10 | 11 | class AssemblyCodeBuilder { 12 | public: 13 | static AssemblyCode *FinalizeFromTurboAssembler(AssemblerBase *assembler); 14 | }; 15 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/CodeBufferBase.cc: -------------------------------------------------------------------------------- 1 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 2 | 3 | CodeBufferBase *CodeBufferBase::Copy() { 4 | CodeBufferBase *result = new CodeBufferBase(); 5 | result->EmitBuffer(GetBuffer(), GetBufferSize()); 6 | return result; 7 | } 8 | 9 | void CodeBufferBase::Emit8(uint8_t data) { 10 | Emit(data); 11 | } 12 | 13 | void CodeBufferBase::Emit16(uint16_t data) { 14 | Emit(data); 15 | } 16 | 17 | void CodeBufferBase::Emit32(uint32_t data) { 18 | Emit(data); 19 | } 20 | 21 | void CodeBufferBase::Emit64(uint64_t data) { 22 | Emit(data); 23 | } 24 | 25 | void CodeBufferBase::EmitBuffer(uint8_t *buffer, int buffer_size) { 26 | buffer_.insert(buffer_.end(), buffer, buffer + buffer_size); 27 | } 28 | 29 | uint8_t *CodeBufferBase::GetBuffer() { 30 | return buffer_.data(); 31 | } 32 | 33 | size_t CodeBufferBase::GetBufferSize() { 34 | return buffer_.size(); 35 | } 36 | 37 | #if 0 // Template Advanced won't enable even in userspace 38 | template T CodeBufferBase::Load(int offset) { 39 | return *reinterpret_cast(buffer + offset); 40 | } 41 | 42 | template void CodeBufferBase::Store(int offset, T value) { 43 | *reinterpret_cast(buffer + offset) = value; 44 | } 45 | 46 | template void CodeBufferBase::Emit(T value) { 47 | // Ensure the free space enough for the template T value 48 | ensureCapacity(sizeof(T) + GetBufferSize()); 49 | 50 | *reinterpret_cast(buffer_cursor) = value; 51 | buffer_cursor += sizeof(T); 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/CodeBufferBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common_header.h" 4 | 5 | class CodeBufferBase { 6 | public: 7 | CodeBufferBase() { 8 | } 9 | 10 | public: 11 | virtual CodeBufferBase *Copy(); 12 | 13 | void Emit8(uint8_t data); 14 | 15 | void Emit16(uint16_t data); 16 | 17 | void Emit32(uint32_t data); 18 | 19 | void Emit64(uint64_t data); 20 | 21 | template T Load(int offset) { 22 | return *(T *)(buffer_.data() + offset); 23 | } 24 | 25 | template void Store(int offset, T value) { 26 | *(T *)(buffer_.data() + offset) = value; 27 | } 28 | 29 | template void Emit(T value) { 30 | EmitBuffer((uint8_t *)&value, sizeof(value)); 31 | } 32 | 33 | void EmitBuffer(uint8_t *buffer, int len); 34 | 35 | uint8_t *GetBuffer(); 36 | size_t GetBufferSize(); 37 | 38 | private: 39 | tinystl::vector buffer_; 40 | }; 41 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-arm64.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_BUFFER_ARM64_H 2 | #define CODE_BUFFER_ARM64_H 3 | 4 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 5 | 6 | typedef int32_t arm64_inst_t; 7 | 8 | class CodeBuffer : public CodeBufferBase { 9 | 10 | public: 11 | CodeBuffer() : CodeBufferBase() { 12 | } 13 | 14 | public: 15 | arm64_inst_t LoadInst(uint32_t offset) { 16 | return *reinterpret_cast(GetBuffer() + offset); 17 | } 18 | 19 | void RewriteInst(uint32_t offset, arm64_inst_t instr) { 20 | *reinterpret_cast(GetBuffer() + offset) = instr; 21 | } 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-x64.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_BUFFER_X64_H 2 | #define CODE_BUFFER_X64_H 3 | 4 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 5 | 6 | class CodeBuffer : public CodeBufferBase { 7 | public: 8 | CodeBuffer() : CodeBufferBase() { 9 | } 10 | 11 | public: 12 | void FixBindLabel(int offset, int32_t disp) { 13 | Store(offset, disp); 14 | } 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-x86.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "MemoryAllocator/CodeBuffer/code-buffer-x86.h" 5 | 6 | void CodeBuffer::Emit32(int32_t data) { 7 | ensureCapacity(GetBufferSize() + sizeof(int32_t)); 8 | *reinterpret_cast(getCursor()) = data; 9 | buffer_cursor += sizeof(int32_t); 10 | return; 11 | } 12 | 13 | void CodeBuffer::FixBindLabel(int offset, int32_t disp) { 14 | *reinterpret_cast(buffer + offset) = disp; 15 | return; 16 | } 17 | 18 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-x86.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 4 | 5 | class CodeBuffer : public CodeBufferBase { 6 | public: 7 | CodeBuffer() : CodeBufferBase() { 8 | } 9 | public: 10 | void FixBindLabel(int offset, int32_t disp); 11 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code_buffer_arm64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 4 | 5 | typedef int32_t arm64_inst_t; 6 | 7 | class CodeBuffer : public CodeBufferBase { 8 | 9 | public: 10 | CodeBuffer() : CodeBufferBase() { 11 | } 12 | 13 | public: 14 | arm64_inst_t LoadInst(uint32_t offset) { 15 | return *reinterpret_cast(GetBuffer() + offset); 16 | } 17 | 18 | void RewriteInst(uint32_t offset, arm64_inst_t instr) { 19 | *reinterpret_cast(GetBuffer() + offset) = instr; 20 | } 21 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code_buffer_x64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 4 | 5 | class CodeBuffer : public CodeBufferBase { 6 | public: 7 | CodeBuffer() : CodeBufferBase() { 8 | } 9 | 10 | public: 11 | void FixBindLabel(int offset, int32_t disp) { 12 | Store(offset, disp); 13 | } 14 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/CodeBuffer/code_buffer_x86.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 4 | 5 | class CodeBuffer : public CodeBufferBase { 6 | public: 7 | CodeBuffer() : CodeBufferBase() { 8 | } 9 | public: 10 | void FixBindLabel(int offset, int32_t disp) { 11 | Store(offset, disp); 12 | } 13 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/MemoryAllocator/NearMemoryAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "PlatformUnifiedInterface/MemoryAllocator.h" 4 | 5 | #include "common_header.h" 6 | 7 | class NearMemoryAllocator { 8 | public: 9 | MemoryAllocator *default_allocator; 10 | NearMemoryAllocator() { 11 | default_allocator = MemoryAllocator::SharedAllocator(); 12 | } 13 | 14 | private: 15 | static NearMemoryAllocator *shared_allocator; 16 | 17 | public: 18 | static NearMemoryAllocator *SharedAllocator(); 19 | 20 | public: 21 | MemBlock *allocateNearBlock(uint32_t size, addr_t pos, size_t search_range, bool executable); 22 | MemBlock *allocateNearBlockFromDefaultAllocator(uint32_t size, addr_t pos, size_t search_range, bool executable); 23 | MemBlock *allocateNearBlockFromUnusedRegion(uint32_t size, addr_t pos, size_t search_range, bool executable); 24 | 25 | uint8_t *allocateNearExecMemory(uint32_t size, addr_t pos, size_t search_range); 26 | uint8_t *allocateNearExecMemory(uint8_t *buffer, uint32_t buffer_size, addr_t pos, size_t search_range); 27 | 28 | uint8_t *allocateNearDataMemory(uint32_t size, addr_t pos, size_t search_range); 29 | uint8_t *allocateNearDataMemory(uint8_t *buffer, uint32_t buffer_size, addr_t pos, size_t search_range); 30 | }; -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/PlatformUnifiedInterface/ExecMemory/ClearCacheTool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | void ClearCache(void *start, void *end); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/PlatformUnifiedInterface/ExecMemory/CodePatchTool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | MemoryOperationError DobbyCodePatch(void *address, uint8_t *buffer, uint32_t buffer_size); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dobby_internal.h" 4 | 5 | #ifdef ENABLE_CLOSURE_TRAMPOLINE_TEMPLATE 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif //__cplusplus 9 | void closure_trampoline_template(); 10 | void closure_bridge_template(); 11 | #ifdef __cplusplus 12 | } 13 | #endif //__cplusplus 14 | #endif 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif //__cplusplus 19 | 20 | typedef struct { 21 | void *address; 22 | int size; 23 | void *carry_handler; 24 | void *carry_data; 25 | } ClosureTrampolineEntry; 26 | 27 | asm_func_t get_closure_bridge(); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif //__cplusplus 32 | 33 | class ClosureTrampoline { 34 | private: 35 | static std::vector *trampolines_; 36 | 37 | public: 38 | static ClosureTrampolineEntry *CreateClosureTrampoline(void *carry_data, void *carry_handler); 39 | }; 40 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm/dummy/closure-trampoline-template-arm.S: -------------------------------------------------------------------------------- 1 | // .section __TEXT,__text,regular,pure_instructions 2 | 3 | #if defined(ENABLE_CLOSURE_BRIDGE_TEMPLATE) 4 | 5 | #if defined(__WIN32__) || defined(__APPLE__) 6 | #define cdecl(s) _##s 7 | #else 8 | #define cdecl(s) s 9 | #endif 10 | 11 | .align 4 12 | 13 | #if !defined(ENABLE_CLOSURE_TRAMPOLINE_CARRY_OBJECT_PTR) 14 | 15 | // closure trampoline carray the object pointer, and fetch required members at the runtime assembly code. 16 | // #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 17 | // #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) 18 | #define OFFSETOF_ClourseTrampolineEntry_carry_data 4 19 | #define OFFSETOF_ClourseTrampolineEntry_carry_handler 0 20 | .globl cdecl(closure_trampoline_template) 21 | cdecl(closure_trampoline_template): 22 | ldr r12, ClourseTrampolineEntryPtr 23 | ldr pc, [r12, #0] 24 | ClourseTrampolineEntryPtr: 25 | .long 0 26 | 27 | #else 28 | 29 | ; closure trampoline just carray the required members from the object. 30 | .globl cdecl(closure_trampoline_template) 31 | cdecl(closure_trampoline_template): 32 | ldr r12, =carry_data 33 | ldr pc, =carry_handler 34 | carry_data: 35 | .long 0 36 | carry_handler: 37 | .long 0 38 | #endif 39 | 40 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm/helper_arm.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM) 3 | 4 | #include "dobby_internal.h" 5 | 6 | void set_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 7 | *reinterpret_cast(&ctx->general.regs.r12) = address; 8 | } 9 | 10 | void get_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/dummy/closure-trampoline-template-arm64.S: -------------------------------------------------------------------------------- 1 | // .section __TEXT,__text,regular,pure_instructions 2 | 3 | #if defined(ENABLE_CLOSURE_BRIDGE_TEMPLATE) 4 | 5 | #if defined(__WIN32__) || defined(__APPLE__) 6 | #define cdecl(s) _##s 7 | #else 8 | #define cdecl(s) s 9 | #endif 10 | 11 | .align 4 12 | 13 | #if !defined(ENABLE_CLOSURE_TRAMPOLINE_CARRY_OBJECT_PTR) 14 | 15 | // closure trampoline carray the object pointer, and fetch required members at the runtime assembly code. 16 | // #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 17 | // #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) 18 | #define OFFSETOF_ClourseTrampolineEntry_carry_data 8 19 | #define OFFSETOF_ClourseTrampolineEntry_carry_handler 0 20 | .globl cdecl(closure_trampoline_template) 21 | cdecl(closure_trampoline_template): 22 | ldr x17, ClourseTrampolineEntryPtr 23 | ldr x16, OFFSETOF_ClourseTrampolineEntry_carry_data 24 | ldr x17, OFFSETOF_ClourseTrampolineEntry_carry_handler 25 | br x17 26 | ClourseTrampolineEntryPtr: 27 | .long 0 28 | .long 0 29 | 30 | #else 31 | 32 | ; closure trampoline just carray the required members from the object. 33 | .globl cdecl(closure_trampoline_template) 34 | cdecl(closure_trampoline_template): 35 | ldr x16, =carry_data 36 | ldr x17, =carry_handler 37 | br x17 38 | carry_data: 39 | .long 0 40 | .long 0 41 | carry_handler: 42 | .long 0 43 | .long 0 44 | 45 | #endif 46 | 47 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/dummy/dynamic-closure-trampoline-template-arm64.S: -------------------------------------------------------------------------------- 1 | // .section __TEXT,__text,regular,pure_instructions 2 | 3 | // For iOS, we can't allocate executable memory, but we can use `remap` doing some trick. 4 | // For details, please refer `libffi` 5 | 6 | #if defined(ENABLE_CLOSURE_BRIDGE_TEMPLATE) 7 | 8 | #if defined(__WIN32__) || defined(__APPLE__) 9 | #define cdecl(s) _##s 10 | #else 11 | #define cdecl(s) s 12 | #endif 13 | 14 | #define PAGE_MAX_SIZE 4096 15 | #define PAGE_MAX_SHIFT 14 16 | 17 | .align PAGE_MAX_SHIFT 18 | .globl cdecl(dynamic_closure_trampoline_table_page) 19 | cdecl(dynamic_closure_trampoline_table_page): 20 | .rept (PAGE_MAX_SIZE - 4 * 4) / 8 // sub dynamic_closure_trampoline_forward size 21 | adr x16, #0 22 | b cdecl(dynamic_closure_trampoline_forward) 23 | .endr 24 | 25 | cdecl(dynamic_closure_trampoline_forward): 26 | sub x16, x16, #0x4000 // [DynamicClosureTrampoline **] 27 | ldr x16, [x16, #0] // [DynamicClosureTrampoline *] 28 | ldr x17, [x16, #0] // trampolineTo 29 | br x17 30 | 31 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/helper_arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM64) 3 | 4 | #include "core/assembler/assembler-arm64.h" 5 | 6 | #include "dobby_internal.h" 7 | 8 | using namespace zz::arm64; 9 | 10 | void set_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 11 | *reinterpret_cast(&ctx->general.x[TMP_REG_0.code()]) = address; 12 | } 13 | 14 | void get_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/common_bridge_handler.cc: -------------------------------------------------------------------------------- 1 | #include "logging/logging.h" 2 | 3 | #include "TrampolineBridge/ClosureTrampolineBridge/common_bridge_handler.h" 4 | 5 | PUBLIC void common_closure_bridge_handler(DobbyRegisterContext *ctx, ClosureTrampolineEntry *entry) { 6 | DLOG(0, "common bridge handler: carry data: %p, carry handler: %p", (InterceptEntry *)entry->carry_data, 7 | entry->carry_handler); 8 | 9 | typedef void (*routing_handler_t)(InterceptEntry *, DobbyRegisterContext *); 10 | auto routing_handler = (routing_handler_t)entry->carry_handler; 11 | 12 | #if defined(__APPLE__) && __arm64e__ 13 | #if __has_feature(ptrauth_calls) 14 | uint64_t discriminator = 0; 15 | // discriminator = __builtin_ptrauth_type_discriminator(__typeof(routing_handler)); 16 | routing_handler = (__typeof(routing_handler))__builtin_ptrauth_sign_unauthenticated((void *)routing_handler, 17 | ptrauth_key_asia, discriminator); 18 | #endif 19 | #endif 20 | 21 | routing_handler((InterceptEntry *)entry->carry_data, ctx); 22 | } 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/common_bridge_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef CLOSURE_TRAMPOLINE_COMMON_HANDLER_H 2 | #define CLOSURE_TRAMPOLINE_COMMON_HANDLER_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "Interceptor.h" 7 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 8 | 9 | extern "C" { 10 | void common_closure_bridge_handler(DobbyRegisterContext *ctx, ClosureTrampolineEntry *entry); 11 | } 12 | 13 | void get_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address); 14 | 15 | void set_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address); 16 | 17 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x64/ClosureTrampolineX64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/assembler/assembler-x64.h" 7 | 8 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 9 | 10 | using namespace zz; 11 | using namespace zz::x64; 12 | 13 | ClosureTrampolineEntry *ClosureTrampoline::CreateClosureTrampoline(void *carry_data, void *carry_handler) { 14 | ClosureTrampolineEntry *tramp_entry = nullptr; 15 | tramp_entry = new ClosureTrampolineEntry; 16 | 17 | auto tramp_size = 32; 18 | auto tramp_mem = MemoryAllocator::SharedAllocator()->allocateExecMemory(tramp_size); 19 | if (tramp_mem == nullptr) { 20 | return nullptr; 21 | } 22 | #define _ turbo_assembler_. 23 | #define __ turbo_assembler_.GetCodeBuffer()-> 24 | TurboAssembler turbo_assembler_(0); 25 | 26 | uint8_t *push_rip_6 = (uint8_t *)"\xff\x35\x06\x00\x00\x00"; 27 | uint8_t *jmp_rip_8 = (uint8_t *)"\xff\x25\x08\x00\x00\x00"; 28 | 29 | __ EmitBuffer(push_rip_6, 6); 30 | __ EmitBuffer(jmp_rip_8, 6); 31 | __ Emit64((uint64_t)tramp_entry); 32 | __ Emit64((uint64_t)get_closure_bridge()); 33 | 34 | tramp_entry->address = tramp_mem; 35 | tramp_entry->size = tramp_size; 36 | tramp_entry->carry_data = carry_data; 37 | tramp_entry->carry_handler = carry_handler; 38 | 39 | auto closure_tramp_buffer = static_cast(turbo_assembler_.GetCodeBuffer()); 40 | DobbyCodePatch(tramp_mem, (uint8_t *)closure_tramp_buffer->GetBuffer(), closure_tramp_buffer->GetBufferSize()); 41 | 42 | return tramp_entry; 43 | } 44 | 45 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x64/dummy/closure-trampoline-template-x64.S: -------------------------------------------------------------------------------- 1 | #if defined(ENABLE_CLOSURE_BRIDGE_TEMPLATE) 2 | 3 | #if defined(__WIN32__) || defined(__APPLE__) 4 | #define cdecl(s) _##s 5 | #else 6 | #define cdecl(s) s 7 | #endif 8 | 9 | .align 4 10 | 11 | ; closure trampoline just carray the required members from the object. 12 | .globl cdecl(closure_trampoline_template) 13 | cdecl(closure_trampoline_template): 14 | push [rip+6+6] 15 | jmp [rip+6+8] 16 | carry_data: 17 | .long 0 18 | .long 0 19 | carry_handler: 20 | .long 0 21 | .long 0 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x64/helper_x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "dobby_internal.h" 5 | 6 | void set_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 7 | addr_t rsp = ctx->rsp; 8 | 9 | // ClosureTrampolineEntry reserved stack 10 | addr_t entry_placeholder_stack_addr = rsp - 8; 11 | *(addr_t *)entry_placeholder_stack_addr = (addr_t)address; 12 | } 13 | 14 | void get_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x86/ClosureTrampolineX86.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/assembler/assembler-ia32.h" 7 | 8 | #include "TrampolineBridge/ClosureTrampolineBridge/ClosureTrampoline.h" 9 | 10 | using namespace zz; 11 | using namespace zz::x86; 12 | 13 | ClosureTrampolineEntry *ClosureTrampoline::CreateClosureTrampoline(void *carry_data, void *carry_handler) { 14 | ClosureTrampolineEntry *tramp_entry = nullptr; 15 | tramp_entry = new ClosureTrampolineEntry; 16 | 17 | auto tramp_size = 32; 18 | auto tramp_mem = MemoryAllocator::SharedAllocator()->allocateExecMemory(tramp_size); 19 | if (tramp_mem == nullptr) { 20 | return nullptr; 21 | } 22 | 23 | #define _ turbo_assembler_. 24 | #define __ turbo_assembler_.GetCodeBuffer()-> 25 | TurboAssembler turbo_assembler_(tramp_mem); 26 | 27 | int32_t offset = (int32_t)((uintptr_t)get_closure_bridge() - ((uintptr_t)tramp_mem + 18)); 28 | 29 | _ sub(esp, Immediate(4, 32)); 30 | _ mov(Address(esp, 4 * 0), Immediate((int32_t)(uintptr_t)tramp_entry, 32)); 31 | _ jmp(Immediate(offset, 32)); 32 | 33 | tramp_entry->address = tramp_mem; 34 | tramp_entry->size = tramp_size; 35 | tramp_entry->carry_data = carry_data; 36 | tramp_entry->carry_handler = carry_handler; 37 | 38 | auto closure_tramp_buffer = static_cast(turbo_assembler_.GetCodeBuffer()); 39 | DobbyCodePatch(tramp_mem, (uint8_t *)closure_tramp_buffer->GetBuffer(), closure_tramp_buffer->GetBufferSize()); 40 | 41 | return tramp_entry; 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x86/helper_x86.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "dobby_internal.h" 5 | 6 | void set_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 7 | addr_t esp = ctx->esp; 8 | 9 | addr_t entry_placeholder_stack_addr = esp - 4; 10 | *(addr_t *)entry_placeholder_stack_addr = (addr_t)address; 11 | } 12 | 13 | void get_routing_bridge_next_hop(DobbyRegisterContext *ctx, void *address) { 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/Trampoline/Trampoline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 4 | 5 | CodeBufferBase *GenerateNormalTrampolineBuffer(addr_t from, addr_t to); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/Trampoline/arm64/trampoline_arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM64) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/assembler/assembler-arm64.h" 7 | #include "core/codegen/codegen-arm64.h" 8 | 9 | #include "MemoryAllocator/NearMemoryAllocator.h" 10 | #include "InstructionRelocation/arm64/InstructionRelocationARM64.h" 11 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 12 | 13 | using namespace zz::arm64; 14 | 15 | CodeBufferBase *GenerateNormalTrampolineBuffer(addr_t from, addr_t to) { 16 | TurboAssembler turbo_assembler_((void *)from); 17 | #define _ turbo_assembler_. 18 | 19 | uint64_t distance = llabs((int64_t)(from - to)); 20 | uint64_t adrp_range = ((uint64_t)1 << (2 + 19 + 12 - 1)); 21 | if (distance < adrp_range) { 22 | // adrp, add, br 23 | _ AdrpAdd(TMP_REG_0, from, to); 24 | _ br(TMP_REG_0); 25 | DLOG(0, "[trampoline] use [adrp, add, br]"); 26 | } else { 27 | // ldr, br, branch-address 28 | CodeGen codegen(&turbo_assembler_); 29 | codegen.LiteralLdrBranch((uint64_t)to); 30 | DLOG(0, "[trampoline] use [ldr, br, #label]"); 31 | } 32 | #undef _ 33 | 34 | // Bind all labels 35 | turbo_assembler_.RelocBind(); 36 | 37 | auto result = turbo_assembler_.GetCodeBuffer()->Copy(); 38 | return result; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/TrampolineBridge/Trampoline/x86/trampoline_x86.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/assembler/assembler-ia32.h" 7 | #include "core/codegen/codegen-ia32.h" 8 | 9 | #include "InstructionRelocation/x86/InstructionRelocationX86.h" 10 | 11 | #include "MemoryAllocator/NearMemoryAllocator.h" 12 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 13 | 14 | using namespace zz::x86; 15 | 16 | CodeBufferBase *GenerateNormalTrampolineBuffer(addr_t from, addr_t to) { 17 | TurboAssembler turbo_assembler_((void *)from); 18 | #define _ turbo_assembler_. 19 | 20 | CodeGen codegen(&turbo_assembler_); 21 | codegen.JmpNear((uint32_t)to); 22 | 23 | CodeBufferBase *result = NULL; 24 | result = turbo_assembler_.GetCodeBuffer()->Copy(); 25 | return result; 26 | } 27 | 28 | CodeBufferBase *GenerateNearTrampolineBuffer(InterceptRouting *routing, addr_t src, addr_t dst) { 29 | DLOG(0, "x86 near branch trampoline enable default"); 30 | return NULL; 31 | } 32 | 33 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/Cpu.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "core/arch/Cpu.h" 3 | #include "core/arch/CpuUtils.h" 4 | 5 | #include "xnucxx/LiteMemOpt.h" 6 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/Cpu.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARCH_CPU_H 2 | #define CORE_ARCH_CPU_H 3 | 4 | #include "CpuRegister.h" 5 | #include "CpuFeature.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/CpuFeature.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "core/arch/CpuFeature.h" 3 | #include "logging/logging.h" 4 | 5 | void CpuFeatures::ClearCache(void *start, void *end) { 6 | UNIMPLEMENTED(); 7 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/CpuFeature.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARCH_CPU_FEATURE_H 2 | #define CORE_ARCH_CPU_FEATURE_H 3 | 4 | #include "common_header.h" 5 | 6 | class CpuFeatures { 7 | private: 8 | static void FlushICache(void *start, size_t size) { 9 | ClearCache(start, (void *)((addr_t)start + size)); 10 | } 11 | 12 | static void FlushICache(void *start, void *end) { 13 | ClearCache(start, end); 14 | } 15 | 16 | static void ClearCache(void *start, void *end); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/CpuRegister.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "CpuRegister.h" 3 | 4 | constexpr RegisterBase RegisterBase::from_code(int code) { 5 | return RegisterBase{code}; 6 | } 7 | 8 | constexpr RegisterBase RegisterBase::no_reg() { 9 | return RegisterBase{0}; 10 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/CpuRegister.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARCH_CPU_REGISTER_H 2 | #define CORE_ARCH_CPU_REGISTER_H 3 | 4 | class RegisterBase { 5 | public: 6 | static constexpr RegisterBase from_code(int code); 7 | 8 | static constexpr RegisterBase no_reg(); 9 | 10 | virtual bool Is(const RegisterBase ®) const { 11 | return (reg.reg_code_ == this->reg_code_); 12 | } 13 | 14 | int code() const { 15 | return reg_code_; 16 | }; 17 | 18 | protected: 19 | explicit constexpr RegisterBase(int code) : reg_code_(code) { 20 | } 21 | 22 | int reg_code_; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/CpuUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef CPU_UTILITY_H 2 | #define CPU_UTILITY_H 3 | 4 | /* Define the default attributes for the functions in this file. */ 5 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) 6 | 7 | #if defined(__i386__) || defined(__x86_64__) 8 | static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) { 9 | __asm__("cpuid" : "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3]) : "a"(__level)); 10 | } 11 | 12 | static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level, int __ecx) { 13 | __asm__("cpuid" : "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3]) : "a"(__level), "c"(__ecx)); 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/arm/registers-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_ARM_REGISTERS 2 | #define ARCH_ARM_REGISTERS 3 | 4 | #include "core/arch/arm/constants-arm.h" 5 | #include "core/arch/Cpu.h" 6 | 7 | namespace zz { 8 | namespace arm { 9 | 10 | #define GENERAL_REGISTERS(V) \ 11 | V(r0) V(r1) V(r2) V(r3) V(r4) V(r5) V(r6) V(r7) V(r8) V(r9) V(r10) V(r11) V(r12) V(sp) V(lr) V(pc) 12 | 13 | enum RegisterCode { 14 | #define REGISTER_CODE(R) kRegCode_##R, 15 | GENERAL_REGISTERS(REGISTER_CODE) 16 | #undef REGISTER_CODE 17 | kRegAfterLast 18 | }; 19 | 20 | class Register : public RegisterBase { 21 | public: 22 | explicit constexpr Register(int code) : RegisterBase(code) { 23 | } 24 | 25 | static constexpr Register Create(int code) { 26 | return Register(code); 27 | } 28 | 29 | static constexpr Register R(int code) { 30 | return Register(code); 31 | } 32 | 33 | bool Is(const Register ®) const { 34 | return (reg.reg_code_ == this->reg_code_); 35 | } 36 | 37 | bool IsValid() const { 38 | return (reg_code_ != 0); 39 | } 40 | 41 | int code() const { 42 | return reg_code_; 43 | } 44 | 45 | private: 46 | }; 47 | 48 | typedef Register CPURegister; 49 | 50 | #define DECLARE_REGISTER(R) constexpr Register R = Register::Create(kRegCode_##R); 51 | GENERAL_REGISTERS(DECLARE_REGISTER) 52 | #undef DECLARE_REGISTER 53 | 54 | constexpr Register no_reg = Register::Create(0); 55 | 56 | } // namespace arm 57 | } // namespace zz 58 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/x64/constants-x64.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARCH_CONSTANTS_X64_H 2 | #define CORE_ARCH_CONSTANTS_X64_H 3 | 4 | namespace zz { 5 | namespace x64 { 6 | 7 | enum ScaleFactor { 8 | TIMES_1 = 0, 9 | TIMES_2 = 1, 10 | TIMES_4 = 2, 11 | TIMES_8 = 3, 12 | TIMES_16 = 4, 13 | TIMES_HALF_WORD_SIZE = sizeof(void *) / 2 - 1 14 | }; 15 | 16 | enum RexBits { REX_NONE = 0, REX_B = 1 << 0, REX_X = 1 << 1, REX_R = 1 << 2, REX_W = 1 << 3, REX_PREFIX = 1 << 6 }; 17 | 18 | } // namespace x64 19 | } // namespace zz 20 | 21 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/arch/x86/constants-x86.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARCH_CONSTANTS_X86_H 2 | #define CORE_ARCH_CONSTANTS_X86_H 3 | 4 | namespace zz { 5 | namespace x86 { 6 | 7 | enum ScaleFactor { 8 | TIMES_1 = 0, 9 | TIMES_2 = 1, 10 | TIMES_4 = 2, 11 | TIMES_8 = 3, 12 | TIMES_16 = 4, 13 | TIMES_HALF_WORD_SIZE = sizeof(void *) / 2 - 1 14 | }; 15 | 16 | } // namespace x86 17 | } // namespace zz 18 | 19 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/assembler/assembler-arch.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ASSEMBLER_ARCH_H 2 | #define CORE_ASSEMBLER_ARCH_H 3 | 4 | #include "src/assembler.h" 5 | 6 | #if 0 7 | #if TARGET_ARCH_IA32 8 | #include "src/ia32/assembler-ia32.h" 9 | #elif TARGET_ARCH_X64 10 | #include "src/x64/assembler-x64.h" 11 | #elif TARGET_ARCH_ARM64 12 | #include "src/arm64/assembler-arm64.h" 13 | #elif TARGET_ARCH_ARM 14 | #include "src/arm/assembler-arm.h" 15 | #elif TARGET_ARCH_PPC 16 | #include "src/ppc/assembler-ppc.h" 17 | #elif TARGET_ARCH_MIPS 18 | #include "src/mips/assembler-mips.h" 19 | #elif TARGET_ARCH_MIPS64 20 | #include "src/mips64/assembler-mips64.h" 21 | #elif TARGET_ARCH_S390 22 | #include "src/s390/assembler-s390.h" 23 | #else 24 | #error Unknown architecture. 25 | #endif 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/assembler/assembler-arm.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if TARGET_ARCH_ARM 3 | 4 | #include "core/assembler/assembler-arm.h" 5 | 6 | void AssemblerPseudoLabel::link_confused_instructions(CodeBufferBase *buffer) { 7 | CodeBuffer *_buffer = (CodeBuffer *)buffer; 8 | 9 | for (auto &ref_label_insn : ref_label_insns_) { 10 | arm_inst_t inst = _buffer->LoadARMInst(ref_label_insn.pc_offset); 11 | if (ref_label_insn.link_type == kLdrLiteral) { 12 | int64_t pc = ref_label_insn.pc_offset + ARM_PC_OFFSET; 13 | assert(pc % 4 == 0); 14 | int32_t imm12 = pos() - pc; 15 | if (imm12 > 0) { 16 | set_bit(inst, 23, 1); 17 | } else { 18 | set_bit(inst, 23, 0); 19 | imm12 = -imm12; 20 | } 21 | set_bits(inst, 0, 11, imm12); 22 | } 23 | _buffer->RewriteARMInst(ref_label_insn.pc_offset, inst); 24 | } 25 | } 26 | 27 | namespace zz { 28 | namespace arm { 29 | 30 | void Assembler::EmitARMInst(arm_inst_t instr) { 31 | buffer_->EmitARMInst(instr); 32 | } 33 | 34 | void Assembler::EmitAddress(uint32_t value) { 35 | buffer_->Emit32(value); 36 | } 37 | 38 | } // namespace arm 39 | } // namespace zz 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/assembler/assembler-arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if TARGET_ARCH_ARM64 3 | 4 | #include "core/assembler/assembler-arm64.h" 5 | 6 | void AssemblerPseudoLabel::link_confused_instructions(CodeBufferBase *buffer_) { 7 | auto buffer = (CodeBuffer *)buffer_; 8 | 9 | for (auto &ref_label_insn : ref_label_insns_) { 10 | int64_t fixup_offset = pos() - ref_label_insn.pc_offset; 11 | 12 | arm64_inst_t inst = buffer->LoadInst(ref_label_insn.pc_offset); 13 | arm64_inst_t new_inst = 0; 14 | 15 | if (ref_label_insn.link_type == kLabelImm19) { 16 | new_inst = encode_imm19_offset(inst, fixup_offset); 17 | } 18 | 19 | buffer->RewriteInst(ref_label_insn.pc_offset, new_inst); 20 | } 21 | } 22 | 23 | using namespace zz::arm64; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/assembler/assembler-ia32.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if TARGET_ARCH_IA32 3 | 4 | #include "core/assembler/assembler-ia32.h" 5 | 6 | using namespace zz::x86; 7 | 8 | void Assembler::jmp(Immediate imm) { 9 | buffer_->Emit8(0xE9); 10 | buffer_->Emit32((int)imm.value()); 11 | } 12 | 13 | addr32_t TurboAssembler::CurrentIP() { 14 | return pc_offset() + (addr_t)realized_addr_; 15 | } 16 | 17 | void AssemblerPseudoLabel::link_confused_instructions(CodeBufferBase *buffer) { 18 | auto _buffer = (CodeBuffer *)buffer; 19 | 20 | for (auto &ref_label_insn : ref_label_insns_) { 21 | int64_t new_offset = pos() - ref_label_insn.pc_offset; 22 | 23 | if (ref_label_insn.link_type == kDisp32_off_7) { 24 | // why 7 ? 25 | // use `call` and `pop` get the runtime ip register 26 | // but the ip register not the real call next insn 27 | // it need add two insn length == 7 28 | int disp32_fix_pos = ref_label_insn.pc_offset - sizeof(int32_t); 29 | _buffer->FixBindLabel(disp32_fix_pos, new_offset + 7); 30 | } 31 | } 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/assembler/assembler-x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "core/assembler/assembler-x64.h" 5 | 6 | using namespace zz::x64; 7 | 8 | void AssemblerPseudoLabel::link_confused_instructions(CodeBufferBase *buffer) { 9 | CodeBuffer *_buffer = (CodeBuffer *)buffer; 10 | 11 | for (auto &ref_label_insn : ref_label_insns_) { 12 | int64_t new_offset = pos() - ref_label_insn.pc_offset; 13 | 14 | if (ref_label_insn.link_type == kDisp32_off_9) { 15 | // why 9 ? 16 | // use `call` and `pop` get the runtime ip register 17 | // but the ip register not the real call next insn 18 | // it need add two insn length == 9 19 | int disp32_fix_pos = ref_label_insn.pc_offset - sizeof(int32_t); 20 | _buffer->FixBindLabel(disp32_fix_pos, new_offset + 9); 21 | } 22 | } 23 | } 24 | 25 | void Assembler::jmp(Immediate imm) { 26 | buffer_->Emit8(0xE9); 27 | buffer_->Emit32((int)imm.value()); 28 | } 29 | 30 | addr64_t TurboAssembler::CurrentIP() { 31 | return pc_offset() + (addr_t)realized_addr_; 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/assembler/assembler-x86-shared.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_IA32) 3 | 4 | #include "core/assembler/assembler-x86-shared.h" 5 | 6 | using namespace zz::x86shared; 7 | 8 | void Assembler::jmp(Immediate imm) { 9 | buffer_->Emit8(0xE9); 10 | buffer_->Emit32((int)imm.value()); 11 | } 12 | 13 | uint64_t TurboAssembler::CurrentIP() { 14 | return pc_offset() + (addr_t)realized_addr_; 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-arm.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM) 3 | 4 | #include "core/codegen/codegen-arm.h" 5 | 6 | namespace zz { 7 | namespace arm { 8 | 9 | void CodeGen::LiteralLdrBranch(uint32_t address) { 10 | TurboAssembler *turbo_assembler_ = reinterpret_cast(this->assembler_); 11 | #define _ turbo_assembler_-> 12 | _ ldr(pc, MemOperand(pc, -4)); 13 | turbo_assembler_->GetCodeBuffer()->Emit32((addr_t)address); 14 | } 15 | 16 | } // namespace arm 17 | } // namespace zz 18 | 19 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_ARM_H 2 | #define CORE_CODEGEN_ARM_H 3 | 4 | #include "core/codegen/codegen.h" 5 | #include "core/assembler/assembler.h" 6 | #include "core/assembler/assembler-arm.h" 7 | 8 | namespace zz { 9 | namespace arm { 10 | 11 | class CodeGen : public CodeGenBase { 12 | public: 13 | CodeGen(TurboAssembler *turbo_assembler) : CodeGenBase(turbo_assembler) { 14 | } 15 | 16 | void LiteralLdrBranch(uint32_t address); 17 | }; 18 | 19 | } // namespace arm 20 | } // namespace zz 21 | 22 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM64) 3 | 4 | #include "dobby_internal.h" 5 | #include "core/codegen/codegen-arm64.h" 6 | 7 | namespace zz { 8 | namespace arm64 { 9 | 10 | void CodeGen::LiteralLdrBranch(uint64_t address) { 11 | auto turbo_assembler_ = reinterpret_cast(this->assembler_); 12 | #define _ turbo_assembler_-> 13 | 14 | auto label = RelocLabel::withData(address); 15 | turbo_assembler_->AppendRelocLabel(label); 16 | 17 | _ Ldr(TMP_REG_0, label); 18 | _ br(TMP_REG_0); 19 | 20 | #undef _ 21 | } 22 | 23 | } // namespace arm64 24 | } // namespace zz 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-arm64.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_ARM64_H 2 | #define CORE_CODEGEN_ARM64_H 3 | 4 | #include "core/codegen/codegen.h" 5 | #include "core/assembler/assembler.h" 6 | #include "core/assembler/assembler-arm64.h" 7 | 8 | namespace zz { 9 | namespace arm64 { 10 | 11 | class CodeGen : public CodeGenBase { 12 | public: 13 | CodeGen(TurboAssembler *turbo_assembler) : CodeGenBase(turbo_assembler) { 14 | } 15 | void LiteralLdrBranch(uint64_t address); 16 | }; 17 | 18 | } // namespace arm64 19 | } // namespace zz 20 | 21 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-ia32.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "core/codegen/codegen-ia32.h" 5 | 6 | namespace zz { 7 | namespace x86 { 8 | 9 | void CodeGen::JmpNear(uint32_t address) { 10 | TurboAssembler *turbo_assembler_ = reinterpret_cast(this->assembler_); 11 | #define _ turbo_assembler_-> 12 | #define __ turbo_assembler_->GetCodeBuffer()-> 13 | uint32_t currIP = turbo_assembler_->CurrentIP() + 5; 14 | int32_t offset = (int32_t)(address - currIP); 15 | 16 | __ Emit8(0xe9); 17 | __ Emit32(offset); 18 | } 19 | 20 | } // namespace x86 21 | } // namespace zz 22 | 23 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-ia32.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_X86_H 2 | #define CORE_CODEGEN_X86_H 3 | 4 | #include "core/codegen/codegen.h" 5 | #include "core/assembler/assembler.h" 6 | #include "core/assembler/assembler-ia32.h" 7 | 8 | namespace zz { 9 | namespace x86 { 10 | 11 | class CodeGen : public CodeGenBase { 12 | public: 13 | CodeGen(TurboAssembler *turbo_assembler) : CodeGenBase(turbo_assembler) { 14 | } 15 | 16 | void JmpNear(uint32_t address); 17 | }; 18 | 19 | } // namespace x86 20 | } // namespace zz 21 | 22 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "core/codegen/codegen-x64.h" 5 | 6 | namespace zz { 7 | namespace x64 { 8 | 9 | void CodeGen::JmpNearIndirect(addr_t forward_stub_addr) { 10 | TurboAssembler *turbo_assembler_ = reinterpret_cast(this->assembler_); 11 | #define _ turbo_assembler_-> 12 | #define __ turbo_assembler_->GetCodeBuffer()-> 13 | uint64_t currIP = turbo_assembler_->CurrentIP() + 6; 14 | int32_t offset = (int32_t)(forward_stub_addr - currIP); 15 | 16 | // jmp *(rip + disp32) 17 | __ Emit8(0xFF); 18 | __ Emit8(0x25); // ModR/M: 00 100 101 19 | __ Emit32(offset); 20 | } 21 | 22 | } // namespace x64 23 | } // namespace zz 24 | 25 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen-x64.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_X64_H 2 | #define CORE_CODEGEN_X64_H 3 | 4 | #include "core/codegen/codegen.h" 5 | #include "core/assembler/assembler.h" 6 | #include "core/assembler/assembler-x64.h" 7 | 8 | namespace zz { 9 | namespace x64 { 10 | 11 | class CodeGen : public CodeGenBase { 12 | public: 13 | CodeGen(TurboAssembler *turbo_assembler) : CodeGenBase(turbo_assembler) { 14 | } 15 | 16 | void JmpNearIndirect(addr_t forward_stub_addr); 17 | }; 18 | 19 | } // namespace x64 20 | } // namespace zz 21 | 22 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/codegen/codegen.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_H 2 | #define CORE_CODEGEN_H 3 | 4 | #include "core/assembler/assembler.h" 5 | 6 | using namespace zz; 7 | 8 | class CodeGenBase { 9 | public: 10 | CodeGenBase(AssemblerBase *assembler) : assembler_(assembler) { 11 | } 12 | 13 | protected: 14 | AssemblerBase *assembler_; 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/core/emulator/dummy.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dalishen99/XposedJniTrace/287a810e3051f88e98d732871a94049022e21a15/nativeLib/src/main/cpp/hook/Dobby/source/core/emulator/dummy.cc -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/dobby.cpp: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | #include "Interceptor.h" 3 | 4 | __attribute__((constructor)) static void ctor() { 5 | DLOG(-1, "================================"); 6 | DLOG(-1, "Dobby"); 7 | DLOG(-1, "================================"); 8 | 9 | DLOG(-1, "dobby in debug log mode, disable with cmake flag \"-DDOBBY_DEBUG=OFF\""); 10 | } 11 | 12 | PUBLIC const char *DobbyGetVersion() { 13 | return __DOBBY_BUILD_VERSION__; 14 | } 15 | 16 | PUBLIC int DobbyDestroy(void *address) { 17 | #if defined(TARGET_ARCH_ARM) 18 | if ((addr_t)address % 2) { 19 | address = (void *)((addr_t)address - 1); 20 | } 21 | #endif 22 | auto entry = Interceptor::SharedInstance()->find((addr_t)address); 23 | if (entry) { 24 | uint8_t *buffer = entry->origin_insns; 25 | uint32_t buffer_size = entry->origin_insn_size; 26 | DobbyCodePatch(address, buffer, buffer_size); 27 | Interceptor::SharedInstance()->remove((addr_t)address); 28 | return RT_SUCCESS; 29 | } 30 | 31 | return RT_FAILED; 32 | } 33 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/dobby_internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common_header.h" 4 | 5 | #include "dobby.h" 6 | 7 | #include "logging/logging.h" 8 | #include "logging/check_logging.h" 9 | 10 | #include "UnifiedInterface/platform.h" 11 | 12 | #include "PlatformUnifiedInterface/MemoryAllocator.h" 13 | #include "PlatformUnifiedInterface/ExecMemory/CodePatchTool.h" 14 | #include "PlatformUnifiedInterface/ExecMemory/ClearCacheTool.h" 15 | 16 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 17 | 18 | #include "InterceptRouting/InterceptRouting.h" 19 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/include/common_header.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/type_header.h" 4 | #include "include/platform_header.h" 5 | #include "include/platform_macro.h" 6 | #include "include/utility_macro.h" 7 | 8 | #include "logging/logging.h" 9 | #include "logging/check_logging.h" -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/include/kernel_mode_header.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef void *vm_map_entry_t; 11 | extern vm_map_t kernel_map; 12 | 13 | typedef void *pmap_paddr_t; 14 | struct pmap; 15 | typedef struct pmap *pmap_t; 16 | extern pmap_t kernel_pmap; 17 | 18 | extern task_t kernel_task; 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | // ----- pmap ----- 25 | 26 | typedef void *pmap_paddr_t; 27 | struct pmap; 28 | typedef struct pmap *pmap_t; 29 | 30 | typedef uint64_t vaddr_t; 31 | typedef uint64_t paddr_t; 32 | 33 | struct pmap; 34 | typedef struct pmap *pmap_t; 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | extern pmap_t kernel_pmap; 41 | 42 | void pmap_kit_init(); 43 | 44 | paddr_t pmap_kit_kvtophys(pmap_t pmap, vaddr_t va); 45 | 46 | int pmap_kit_set_perm(pmap_t pmap, vaddr_t start, vaddr_t end, unsigned int prot); 47 | 48 | #define cppvPsnk 1 49 | #define cppvPsrc 2 50 | void pmap_kit_bcopy_phys(paddr_t src, paddr_t dst, size_t size, int flags); 51 | 52 | typedef uint64_t pt_entry_t; 53 | pt_entry_t pmap_kit_kva_to_pte(pmap_t pmap, vaddr_t va); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/include/platform_header.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__APPLE__) && __arm64e__ 4 | #if __has_feature(ptrauth_calls) 5 | #include 6 | #endif 7 | #endif 8 | 9 | #if defined(BUILDING_KERNEL) 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #else 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #if defined(__linux__) || defined(__APPLE__) 27 | #include 28 | #include 29 | #endif 30 | #endif 31 | 32 | #if defined(BUILDING_KERNEL) 33 | #include "kernel_mode_header.h" 34 | #endif 35 | 36 | #if defined(BUILDING_KERNEL) 37 | #define abs(a) ((a) < 0 ? -(a) : (a)) 38 | #define llabs(a) (((long long)a) < 0 ? -((long long)a) : ((long long)a)) 39 | #define min(a, b) (((a) < (b)) ? (a) : (b)) 40 | #define max(a, b) (((a) > (b)) ? (a) : (b)) 41 | #ifdef __cplusplus 42 | #define abs(a) ((a) < 0 ? -(a) : (a)) 43 | #endif 44 | #else 45 | #ifdef __cplusplus 46 | #include 47 | #include 48 | #include 49 | #include "TINYSTL/vector.h" 50 | #include "TINYSTL/unordered_map.h" 51 | #endif 52 | #endif -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/include/platform_macro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !defined(DISABLE_ARCH_DETECT) 4 | #if defined(__arm__) 5 | #define TARGET_ARCH_ARM 1 6 | #elif defined(__arm64__) || defined(__aarch64__) 7 | #define TARGET_ARCH_ARM64 1 8 | #elif defined(_M_IX86) || defined(__i386__) 9 | #define TARGET_ARCH_IA32 1 10 | #elif defined(_M_X64) || defined(__x86_64__) 11 | #define TARGET_ARCH_X64 1 12 | #else 13 | #error Target architecture was not detected as supported by Dobby 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/source/include/type_header.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "platform_header.h" 4 | 5 | typedef uintptr_t vmaddr_t; 6 | typedef uintptr_t addr_t; 7 | typedef uint32_t addr32_t; 8 | typedef uint64_t addr64_t; 9 | typedef unsigned char byte_t; 10 | typedef unsigned int uint; 11 | 12 | #ifndef NULL 13 | #define NULL 0 14 | #endif 15 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/tests/test_insn_relo_x64.cpp: -------------------------------------------------------------------------------- 1 | #include "InstructionRelocation/InstructionRelocation.h" 2 | 3 | #include "UniconEmulator.h" 4 | 5 | int main() { 6 | log_set_level(0); 7 | set_global_arch("x86_64"); 8 | 9 | 10 | // cmp eax, eax 11 | // jz -0x20 12 | check_insn_relo("\x39\xc0\x74\xdc", 4, false, UC_X86_REG_IP, nullptr); 13 | // cmp eax, eax 14 | // jz 0x20 15 | check_insn_relo("\x39\xc0\x74\x1c", 4, false, UC_X86_REG_IP, nullptr); 16 | 17 | // jmp -0x20 18 | check_insn_relo("\xeb\xde", 2, false, UC_X86_REG_IP, nullptr); 19 | // jmp 0x20 20 | check_insn_relo("\xeb\x1e", 2, false, UC_X86_REG_IP, nullptr); 21 | 22 | 23 | // jmp -0x4000 24 | check_insn_relo("\xe9\xfb\xbf\xff\xff", 4, false, UC_X86_REG_IP, nullptr); 25 | // jmp 0x4000 26 | check_insn_relo("\xe9\xfb\x3f\x00\x00", 4, false, UC_X86_REG_IP, nullptr); 27 | 28 | // lea rax, [rip] 29 | check_insn_relo("\x48\x8d\x05\x00\x00\x00\x00", 7, false, UC_X86_REG_RAX, nullptr); 30 | 31 | // lea rax, [rip + 0x4000] 32 | check_insn_relo("\x48\x8d\x05\x00\x40\x00\x00", 7, false, UC_X86_REG_RAX, nullptr); 33 | 34 | // mov rax, [rip + 0x4000] 35 | check_insn_relo("\x48\x8b\x05\x00\x40\x00\x00", 7, true, -1, nullptr); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/Dobby/tests/test_native.cpp: -------------------------------------------------------------------------------- 1 | #include "dobby.h" 2 | 3 | #include 4 | #include 5 | 6 | #define LOG(fmt, ...) printf("[test_native] " fmt, ##__VA_ARGS__) 7 | 8 | void test_execve() { 9 | char *argv[] = {NULL}; 10 | char *envp[] = {NULL}; 11 | 12 | LOG("test execve"); 13 | 14 | DobbyInstrument(DobbySymbolResolver(0, "_execve"), [](void *, DobbyRegisterContext *ctx) { 15 | LOG("execve: %s", (char *)ctx->general.regs.rdi); 16 | return; 17 | }); 18 | 19 | execve("ls", argv, envp); 20 | 21 | return; 22 | } 23 | 24 | int main(int argc, char *argv[]) { 25 | log_set_level(0); 26 | 27 | test_execve(); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/common/dlfcn_nougat.h: -------------------------------------------------------------------------------- 1 | #ifndef DLFCN_NOUGAT_H 2 | #define DLFCN_NOUGAT_H 3 | 4 | //see implementation in https://tech.meituan.com/2017/07/20/android-remote-debug.html 5 | extern "C" { 6 | int fake_dlclose(void *handle); 7 | 8 | void *fake_dlopen(const char *filename, int flags); 9 | 10 | void *fake_dlsym(void *handle, const char *name); 11 | 12 | const char *fake_dlerror(); 13 | } 14 | 15 | #endif //DLFCN_NOUGAT_H 16 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/common/log.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by swift on 3/12/21. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | 10 | #ifdef ZHENXI_BUILD_TYPE_NOLOG 11 | 12 | #define LOGE(...) ((void)0); 13 | #define LOGI(...) ((void)0); 14 | #define LOGD(...) ((void)0); 15 | #define LOGW(...) ((void)0); 16 | #define ALOGI(...) ((void)0); 17 | #define ALOGD(...) ((void)0); 18 | #define ALOGW(...) ((void)0); 19 | #define ALOGE(...) ((void)0); 20 | 21 | 22 | 23 | #else 24 | 25 | #define TAG "Sandhook" 26 | 27 | 28 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__); 29 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG ,__VA_ARGS__); 30 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG ,__VA_ARGS__); 31 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG ,__VA_ARGS__); 32 | 33 | //#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG ,__VA_ARGS__); 34 | //#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG ,__VA_ARGS__); 35 | //#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG ,__VA_ARGS__); 36 | //#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG ,__VA_ARGS__); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/common/types.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by swift on 2021/2/24. 3 | // 4 | 5 | #include "types.h" 6 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/distorm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | add_library(distorm STATIC 4 | decoder.c 5 | distorm.c 6 | instructions.c 7 | insts.c 8 | mnemonics.c 9 | operands.c 10 | prefix.c 11 | textdefs.c 12 | wstring.c) 13 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/distorm/decoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | decoder.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2011 Gil Dabah 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program. If not, see 21 | */ 22 | 23 | 24 | #ifndef DECODER_H 25 | #define DECODER_H 26 | 27 | #include "config.h" 28 | 29 | typedef unsigned int _iflags; 30 | 31 | _DecodeResult decode_internal(_CodeInfo* ci, int supportOldIntr, _DInst result[], unsigned int maxResultCount, unsigned int* usedInstructionsCount); 32 | 33 | #endif /* DECODER_H */ 34 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/distorm/operands.h: -------------------------------------------------------------------------------- 1 | /* 2 | operands.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2018 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef OPERANDS_H 13 | #define OPERANDS_H 14 | 15 | #include "config.h" 16 | #include "decoder.h" 17 | #include "prefix.h" 18 | #include "instructions.h" 19 | 20 | 21 | extern uint32_t _REGISTERTORCLASS[]; 22 | 23 | int operands_extract(_CodeInfo* ci, _DInst* di, _InstInfo* ii, 24 | _iflags instFlags, _OpType type, _OperandNumberType opNum, 25 | unsigned int modrm, _PrefixState* ps, _DecodeType effOpSz, 26 | _DecodeType effAdrSz, int* lockableInstruction); 27 | 28 | #endif /* OPERANDS_H */ 29 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/distorm/textdefs.h: -------------------------------------------------------------------------------- 1 | /* 2 | textdefs.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2018 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef TEXTDEFS_H 13 | #define TEXTDEFS_H 14 | 15 | #include "config.h" 16 | #include "wstring.h" 17 | 18 | #ifndef DISTORM_LIGHT 19 | 20 | #define PLUS_DISP_CHR '+' 21 | #define MINUS_DISP_CHR '-' 22 | #define OPEN_CHR '[' 23 | #define CLOSE_CHR ']' 24 | #define SP_CHR ' ' 25 | #define SEG_OFF_CHR ':' 26 | 27 | /* 28 | Naming Convention: 29 | 30 | * get - returns a pointer to a string. 31 | * str - concatenates to string. 32 | 33 | * hex - means the function is used for hex dump (number is padded to required size) - Little Endian output. 34 | * code - means the function is used for disassembled instruction - Big Endian output. 35 | * off - means the function is used for 64bit offset - Big Endian output. 36 | 37 | * h - '0x' in front of the string. 38 | 39 | * b - byte 40 | * dw - double word (can be used for word also) 41 | * qw - quad word 42 | 43 | * all numbers are in HEX. 44 | */ 45 | 46 | void _FASTCALL_ str_hex_b(_WString* s, unsigned int x); 47 | void _FASTCALL_ str_code_hb(_WString* s, unsigned int x); 48 | void _FASTCALL_ str_code_hdw(_WString* s, uint32_t x); 49 | void _FASTCALL_ str_code_hqw(_WString* s, uint8_t src[8]); 50 | 51 | #ifdef SUPPORT_64BIT_OFFSET 52 | void _FASTCALL_ str_off64(_WString* s, OFFSET_INTEGER x); 53 | #endif 54 | 55 | #endif /* DISTORM_LIGHT */ 56 | 57 | #endif /* TEXTDEFS_H */ 58 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/distorm/wstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | wstring.c 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2018 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #include "wstring.h" 13 | 14 | #ifndef DISTORM_LIGHT 15 | 16 | void strclear_WS(_WString* s) 17 | { 18 | s->p[0] = '\0'; 19 | s->length = 0; 20 | } 21 | 22 | void chrcat_WS(_WString* s, uint8_t ch) 23 | { 24 | s->p[s->length] = ch; 25 | s->p[s->length + 1] = '\0'; 26 | s->length += 1; 27 | } 28 | 29 | void strcpylen_WS(_WString* s, const int8_t* buf, unsigned int len) 30 | { 31 | s->length = len; 32 | memcpy((int8_t*)s->p, buf, len + 1); 33 | } 34 | 35 | void strcatlen_WS(_WString* s, const int8_t* buf, unsigned int len) 36 | { 37 | memcpy((int8_t*)&s->p[s->length], buf, len + 1); 38 | s->length += len; 39 | } 40 | 41 | void strcat_WS(_WString* s, const _WString* s2) 42 | { 43 | memcpy((int8_t*)&s->p[s->length], s2->p, s2->length + 1); 44 | s->length += s2->length; 45 | } 46 | 47 | #endif /* DISTORM_LIGHT */ 48 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/distorm/wstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | wstring.h 3 | 4 | diStorm3 - Powerful disassembler for X86/AMD64 5 | http://ragestorm.net/distorm/ 6 | distorm at gmail dot com 7 | Copyright (C) 2003-2018 Gil Dabah 8 | This library is licensed under the BSD license. See the file COPYING. 9 | */ 10 | 11 | 12 | #ifndef WSTRING_H 13 | #define WSTRING_H 14 | 15 | #include "config.h" 16 | 17 | #ifndef DISTORM_LIGHT 18 | 19 | void strclear_WS(_WString* s); 20 | void chrcat_WS(_WString* s, uint8_t ch); 21 | void strcpylen_WS(_WString* s, const int8_t* buf, unsigned int len); 22 | void strcatlen_WS(_WString* s, const int8_t* buf, unsigned int len); 23 | void strcat_WS(_WString* s, const _WString* s2); 24 | 25 | /* 26 | * Warning, this macro should be used only when the compiler knows the size of string in advance! 27 | * This macro is used in order to spare the call to strlen when the strings are known already. 28 | * Note: sizeof includes NULL terminated character. 29 | */ 30 | #define strcat_WSN(s, t) strcatlen_WS((s), ((const int8_t*)t), sizeof((t))-1) 31 | #define strcpy_WSN(s, t) strcpylen_WS((s), ((const int8_t*)t), sizeof((t))-1) 32 | 33 | #endif /* DISTORM_LIGHT */ 34 | 35 | #endif /* WSTRING_H */ 36 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD 14) 2 | 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -fdiagnostics-show-option -Wextra -Wredundant-decls -pedantic -Wwrite-strings -Wunused") 4 | include_directories(.) 5 | ENABLE_LANGUAGE(ASM) 6 | 7 | set(uccontext_src 8 | breakpad_getcontext.S) 9 | 10 | set(uccontext_src_32 11 | arm/getcontext.S 12 | arm/makecontext.c 13 | arm/setcontext.S 14 | arm/swapcontext.S 15 | ) 16 | 17 | set(uccontext_src_64 18 | aarch64/getcontext.S 19 | aarch64/makecontext.c 20 | aarch64/setcontext.S 21 | aarch64/sysdep.c) 22 | 23 | 24 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") 25 | set(uccontext_src ${uccontext_src} ${uccontext_src_32}) 26 | elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") 27 | set(uccontext_src ${uccontext_src} ${uccontext_src_64}) 28 | endif () 29 | 30 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)") 31 | add_library(uccontext ${uccontext_src}) 32 | target_link_libraries(uccontext android) 33 | endif () 34 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/aarch64/kernel_rt_sigframe.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2009-2014 Free Software Foundation, Inc. 2 | 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public License as 7 | published by the Free Software Foundation; either version 2.1 of the 8 | License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | /* This structure must have the same shape as the linux kernel 20 | equivalent. */ 21 | struct kernel_rt_sigframe 22 | { 23 | siginfo_t info; 24 | struct ucontext uc; 25 | }; 26 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/aarch64/sysdep.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011-2014 Free Software Foundation, Inc. 2 | 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library. If not, see 17 | . */ 18 | 19 | #include "sysdep.h" 20 | #include 21 | 22 | # define __set_errno(val) (errno = (val)) 23 | 24 | long __syscall_error (long err); 25 | hidden_proto (__syscall_error) 26 | 27 | /* This routine is jumped to by all the syscall handlers, to stash 28 | an error number into errno. */ 29 | long 30 | __syscall_error (long err) 31 | { 32 | __set_errno (- err); 33 | return -1; 34 | } 35 | hidden_def (__syscall_error) 36 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/aarch64/ucontext_i.h: -------------------------------------------------------------------------------- 1 | #define SIG_BLOCK 0 2 | #define SIG_SETMASK 2 3 | #define _NSIG8 8 4 | #define RT_SIGFRAME_UCONTEXT 128 5 | #define RT_SIGFRAME_SIZE 4688 6 | #define FPSIMD_CONTEXT_SIZE 528 7 | #define UCONTEXT_FLAGS 0 8 | #define UCONTEXT_LINK 8 9 | #define UCONTEXT_STACK 16 10 | #define UCONTEXT_MCONTEXT 176 11 | #define UCONTEXT_SIGMASK 40 12 | #define UCONTEXT_SIZE 4560 13 | #define STACK_SP 16 14 | #define STACK_SIZE 32 15 | #define STACK_FLAGS 24 16 | #define oX0 184 17 | #define oSP 432 18 | #define oPC 440 19 | #define oPSTATE 448 20 | #define oEXTENSION 464 21 | #define oHEAD 0 22 | #define oV0 16 23 | #define oFPSR 8 24 | #define oFPCR 12 25 | #define oMAGIC 0 26 | #define oSIZE 4 27 | #define FPSIMD_MAGIC 1179680769 28 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/arm/arm_bx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2013 Yann E. MORIN 2 | * 3 | * This file is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU Lesser General Public License as 5 | * published by the Free Software Foundation; either version 2.1 of 6 | * the License, or (at your option) any later version. 7 | * 8 | * This file is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * Lesser General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU Lesser General Public 14 | * License along with the GNU C Library; if not, see 15 | * . 16 | */ 17 | 18 | #ifndef _ARM_BX_H 19 | #define _ARM_BX_H 20 | 21 | #if __ARM_ARCH > 4 || defined (__ARM_ARCH_4T__) 22 | # define ARCH_HAS_BX 23 | #endif 24 | 25 | #if defined(ARCH_HAS_BX) 26 | # define BX(reg) bx reg 27 | # define BXC(cond, reg) bx##cond reg 28 | #else 29 | # define BX(reg) mov pc, reg 30 | # define BXC(cond, reg) mov##cond pc, reg 31 | #endif 32 | 33 | #endif /* _ARM_BX_H */ 34 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/arm/scripts/gen-as-const.awk: -------------------------------------------------------------------------------- 1 | # Script used in producing headers of assembly constants from C expressions. 2 | # The input to this script looks like: 3 | # #cpp-directive ... 4 | # NAME1 5 | # NAME2 expression ... 6 | # The output of this script is C code to be run through gcc -S and then 7 | # massaged to extract the integer constant values of the given C expressions. 8 | # A line giving just a name implies an expression consisting of just that name. 9 | 10 | BEGIN { started = 0 } 11 | 12 | # cpp directives go straight through. 13 | /^#/ { print; next } 14 | 15 | NF >= 1 && !started { 16 | printf "void dummy(void);\n"; 17 | print "void dummy(void) {"; 18 | started = 1; 19 | } 20 | 21 | # Separator. 22 | $1 == "--" { next } 23 | 24 | NF == 1 { sub(/^.*$/, "& &"); } 25 | 26 | NF > 1 { 27 | name = $1; 28 | sub(/^[^ ]+[ ]+/, ""); 29 | printf "__asm__ (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n", 30 | name, $0; 31 | } 32 | 33 | END { if (started) print "}" } 34 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/arm/ucontext.mk: -------------------------------------------------------------------------------- 1 | awk -f src/ucontext/arm/scripts/gen-as-const.awk src/ucontext/aarch64/ucontext_i.sym | /home/ubuntu/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc -std=gnu99 --sysroot="/home/ubuntu/android-ndk-r10e//platforms/android-21/arch-arm64" -march=armv8-a -Wall -Wextra -Wno-missing-field-initializers -O3 -g -D__ANDROID__=1 -Isrc/android/android-ifaddrs -Isrc/android/android-spin-lock -Isrc/ucontext/aarch64 -x c - -S -o - | sed -n "s/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*\$/#define \1 \2/p" > src/ucontext/aarch64/ucontext_i.h -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/arm/ucontext_i.h: -------------------------------------------------------------------------------- 1 | #define SIG_BLOCK 0 2 | #define SIG_SETMASK 2 3 | #define UCONTEXT_FLAGS 0 4 | #define UCONTEXT_LINK 4 5 | #define UCONTEXT_STACK 8 6 | #define UCONTEXT_MCONTEXT 20 7 | #define UCONTEXT_SIGMASK 104 8 | #define UCONTEXT_REGSPACE 232 9 | #define MCONTEXT_TRAP_NO 20 10 | #define MCONTEXT_ERROR_CODE 24 11 | #define MCONTEXT_OLDMASK 28 12 | #define MCONTEXT_ARM_R0 32 13 | #define MCONTEXT_ARM_R4 48 14 | #define MCONTEXT_ARM_SP 84 15 | #define MCONTEXT_ARM_LR 88 16 | #define MCONTEXT_ARM_PC 92 17 | #define MCONTEXT_ARM_CPSR 96 18 | #define MCONTEXT_FAULT_ADDRESS 100 19 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/exts/ucontext/arm/ucontext_i.sym: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | SIG_BLOCK 7 | SIG_SETMASK 8 | 9 | -- Offsets of the fields in the ucontext_t structure. 10 | #define ucontext(member) offsetof (ucontext_t, member) 11 | #define mcontext(member) ucontext (uc_mcontext.member) 12 | 13 | UCONTEXT_FLAGS ucontext (uc_flags) 14 | UCONTEXT_LINK ucontext (uc_link) 15 | UCONTEXT_STACK ucontext (uc_stack) 16 | UCONTEXT_MCONTEXT ucontext (uc_mcontext) 17 | UCONTEXT_SIGMASK ucontext (uc_sigmask) 18 | 19 | UCONTEXT_REGSPACE ucontext (uc_regspace) 20 | 21 | MCONTEXT_TRAP_NO mcontext (trap_no) 22 | MCONTEXT_ERROR_CODE mcontext (error_code) 23 | MCONTEXT_OLDMASK mcontext (oldmask) 24 | MCONTEXT_ARM_R0 mcontext (arm_r0) 25 | MCONTEXT_ARM_R4 mcontext (arm_r4) 26 | MCONTEXT_ARM_SP mcontext (arm_sp) 27 | MCONTEXT_ARM_LR mcontext (arm_lr) 28 | MCONTEXT_ARM_PC mcontext (arm_pc) 29 | MCONTEXT_ARM_CPSR mcontext (arm_cpsr) 30 | MCONTEXT_FAULT_ADDRESS mcontext (fault_address) 31 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/include/inline_hook.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by swift on 3/12/21. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "../common/types.h" 8 | 9 | namespace SandHook::Inline { 10 | 11 | bool InlineHookImpl(void *origin, void *replace, void **backup); 12 | 13 | bool InlineHookSymbol(char *bin, char *symbol, void *replace, void **backup); 14 | 15 | template 16 | bool InlineHook(Func origin, Func replace, Func* backup) { 17 | return InlineHookImpl(reinterpret_cast(origin), reinterpret_cast(replace), reinterpret_cast(backup)); 18 | } 19 | 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/inline/inline_hook.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 甘尧 on 2021/4/26. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace SandHook::Inline { 13 | 14 | bool InlineHookSymbol(char *bin, char *sym, void *replace, void **backup) { 15 | auto handle = fake_dlopen(bin, 0); 16 | if (!handle) { 17 | return false; 18 | } 19 | auto fun = fake_dlsym(handle, sym); 20 | fake_dlclose(handle); 21 | if (!fun) { 22 | ElfImg img{bin}; 23 | fun = reinterpret_cast(img.GetSymAddress(sym)); 24 | } 25 | if (!fun) { 26 | return false; 27 | } 28 | return InlineHookImpl(fun, replace, backup); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/instrcache/instr_cache.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by swift on 2021/2/24. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | namespace SandHook { 10 | 11 | class InstrCache { 12 | public: 13 | virtual std::vector GetPICInstrCache(void *src, size_t len) = 0; 14 | }; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/memory/code_buffer.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Created by SwiftGan on 2020/9/15. 3 | // 4 | 5 | #include "code_buffer.h" 6 | 7 | namespace SandHook::Cache { 8 | 9 | CodeBuffer::CodeBuffer(u32 max_size, u32 align) : buffer_size_{max_size}, align{align} { 10 | code_buffer_.Resize(max_size); 11 | } 12 | 13 | std::pair CodeBuffer::AcquireBuffer(size_t size) { 14 | LockGuard guard(lock_); 15 | auto offset_later = AlignUp(current_offset + size, align); 16 | if (current_offset + size > buffer_size_) { 17 | return {}; 18 | } 19 | auto rx = code_buffer_.DataRX() + current_offset; 20 | auto rw = code_buffer_.DataRW() + current_offset; 21 | current_offset = offset_later; 22 | return {rx, rw}; 23 | } 24 | 25 | void *CodeBuffer::GetRwBuffer(void *rx) { 26 | if (code_buffer_.DataRX() == code_buffer_.DataRW()) { 27 | return rx; 28 | } 29 | auto offset = reinterpret_cast(rx) - code_buffer_.DataRX(); 30 | return code_buffer_.DataRW() + offset; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/memory/code_buffer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by SwiftGan on 2020/9/15. 3 | // 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace SandHook::Cache { 12 | 13 | // simple impl 14 | // TODO 15 | class CodeBuffer { 16 | public: 17 | 18 | explicit CodeBuffer(u32 max_size, u32 align = 0); 19 | 20 | std::pair AcquireBuffer(size_t size); 21 | 22 | void* GetRwBuffer(void *rx); 23 | 24 | protected: 25 | u32 current_offset{0}; 26 | CowVector code_buffer_; 27 | u32 buffer_size_; 28 | u32 align; 29 | std::mutex lock_; 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/hook/signhook/platform/memory.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by SwiftGan on 2020/8/20. 3 | // 4 | 5 | #pragma once 6 | 7 | #include "common/types.h" 8 | 9 | namespace SandHook::Platform { 10 | 11 | void *MirrorRWMemory(void *base, size_t size); 12 | 13 | void *MapExecutableMemory(size_t size, VAddr addr = 0); 14 | 15 | void *MapCowMemory(size_t size, VAddr addr = 0); 16 | 17 | bool MakeRWX(VAddr addr, size_t size); 18 | 19 | void *MapFile(int fd, size_t size, size_t offset = 0); 20 | 21 | void UnMapMemory(VAddr addr, size_t size); 22 | 23 | void ClearICache(VAddr start, size_t size); 24 | 25 | void ClearDCache(VAddr start, size_t size); 26 | } 27 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/HookClassUtils.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #pragma once 4 | 5 | void HookClassloadAll(); -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/HookUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2021/5/16. 3 | // 4 | 5 | 6 | #include "logging.h" 7 | #include "dlfcn_compat.h" 8 | 9 | 10 | 11 | 12 | #ifndef VMP_HOOKUTILS_H 13 | #define VMP_HOOKUTILS_H 14 | 15 | #define HOOK_DEF(ret, func, ...) \ 16 | ret (*orig_##func)(__VA_ARGS__)=nullptr; \ 17 | ret new_##func(__VA_ARGS__) 18 | 19 | class HookUtils { 20 | public: 21 | 22 | static bool Hooker(void *dysym, void *repl, void **org); 23 | 24 | static bool Hooker(void *handler, const char *dysym, void *repl, void **org); 25 | 26 | static bool Hooker(void *dysym, void *repl, void **org, const char *dynSymName); 27 | 28 | static bool Hooker(const char *libName, const char *dysym, void *repl, void **org); 29 | 30 | static bool unHook(void *sym); 31 | 32 | }; 33 | 34 | void hook_libc_function(void *handle, const char *symbol, void *new_func, void **old_func) ; 35 | 36 | #endif //VMP_HOOKUTILS_H 37 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/MapItemInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Zhenxi on 2023/1/1. 3 | // 4 | 5 | #ifndef ZHENXIRUNTIME_MAPITEMINFO_H 6 | #define ZHENXIRUNTIME_MAPITEMINFO_H 7 | 8 | namespace ZhenxiRunTime { 9 | struct MapAddresInfo { 10 | /** 11 | * 函数的符号 12 | */ 13 | char *sym = nullptr; 14 | /** 15 | * 函数在文件路径 16 | */ 17 | char *fname = nullptr; 18 | 19 | /** 20 | * 所在函数的基地址 21 | */ 22 | size_t sym_base = 0; 23 | /** 24 | * 文件基地址 25 | */ 26 | size_t fbase = 0; 27 | 28 | /** 29 | * 传入地址,相对于so的偏移 30 | */ 31 | size_t offset = 0; 32 | }; 33 | 34 | struct MapItemInfo { 35 | /** 36 | * item开始位置 37 | */ 38 | size_t start; 39 | 40 | /** 41 | * item结束位置 42 | */ 43 | size_t end; 44 | }; 45 | } 46 | 47 | #endif //ZHENXIRUNTIME_MAPITEMINFO_H 48 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/adapter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Zhenxi on 2022/10/17. 3 | // 4 | #include 5 | #include 6 | #include 7 | 8 | #ifndef ZHENXIRUNTIME_ADAPTER_H 9 | #define ZHENXIRUNTIME_ADAPTER_H 10 | 11 | extern JavaVM *mVm; 12 | extern JNIEnv *mEnv; 13 | 14 | JNIEnv *getRunTimeEnv(); 15 | JNIEnv *ensureEnvCreated(); 16 | void DetachCurrentThread(); 17 | 18 | int get_sdk_level(); 19 | 20 | 21 | 22 | 23 | class ScopeUtfString { 24 | public: 25 | ScopeUtfString(jstring j_str); 26 | 27 | 28 | const char *c_str() { 29 | return _c_str; 30 | } 31 | 32 | ~ScopeUtfString(); 33 | 34 | private: 35 | jstring _j_str; 36 | const char *_c_str; 37 | }; 38 | 39 | 40 | #endif //ZHENXIRUNTIME_ADAPTER_H 41 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/arch.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by 甘尧 on 2019/1/12. 3 | // 4 | 5 | #ifndef SANDHOOK_ARCH_H 6 | #define SANDHOOK_ARCH_H 7 | 8 | #define BYTE_POINT sizeof(void*) 9 | 10 | typedef size_t Size; 11 | 12 | //32bit 13 | #if defined(__i386__) || defined(__arm__) 14 | //64bit 15 | #elif defined(__aarch64__) || defined(__x86_64__) 16 | #else 17 | #endif 18 | 19 | #if defined(__arm__) 20 | static void clearCacheArm32(char* begin, char *end) 21 | { 22 | const int syscall = 0xf0002; 23 | __asm __volatile ( 24 | "mov r0, %0\n" 25 | "mov r1, %1\n" 26 | "mov r3, %2\n" 27 | "mov r2, #0x0\n" 28 | "svc 0x00000000\n" 29 | : 30 | : "r" (begin), "r" (end), "r" (syscall) 31 | : "r0", "r1", "r3" 32 | ); 33 | } 34 | #endif 35 | 36 | 37 | 38 | 39 | #endif //SANDHOOK_ARCH_H -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/dlfcn_compat.h: -------------------------------------------------------------------------------- 1 | #include "elf_util.h" 2 | #include "dlfcn_nougat.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | #include "ZhenxiLog.h" 15 | #include "logging.h" 16 | 17 | 18 | 19 | #ifndef DLFCN_COMPAT_zhenxi_H 20 | 21 | #define DLFCN_COMPAT_zhenxi_H 22 | 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | void *dlopen_compat(const char *filename, int flags); 29 | 30 | void *dlsym_compat(void *handle, const char *symbol); 31 | 32 | int dlclose_compat(void *handle); 33 | 34 | const char *dlerror_compat(); 35 | 36 | void *getSymCompat(const char *filename, const char *symbol); 37 | 38 | void* getSymByELF(const char * filename, const char *symbol); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | 45 | #endif //DLFCN_COMPAT_zhenxi_H 46 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/dlfcn_nougat.h: -------------------------------------------------------------------------------- 1 | #ifndef DLFCN_NOUGAT_zhenxi_H 2 | #define DLFCN_NOUGAT_zhenxi_H 3 | 4 | //see implementation in https://tech.meituan.com/2017/07/20/android-remote-debug.html 5 | 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "elf_util.h" 19 | #include "adapter.h" 20 | 21 | 22 | 23 | 24 | using namespace std; 25 | 26 | extern "C" { 27 | 28 | 29 | int fake_dlclose(void *handle); 30 | 31 | void *fake_dlopen(const char *filename, int flags); 32 | 33 | void *fake_dlsym(void *handle, const char *name); 34 | 35 | const char *fake_dlerror(); 36 | 37 | 38 | } 39 | #endif //DLFCN_NOUGAT_H 40 | 41 | 42 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/fileUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2021/11/7. 3 | // 4 | 5 | 6 | #ifndef QCONTAINER_PRO_FILEUTILS_H 7 | #define QCONTAINER_PRO_FILEUTILS_H 8 | 9 | 10 | #include 11 | #include "AllInclude.h" 12 | 13 | class fileUtils { 14 | public: 15 | static int makeDir(const char* path); 16 | static string readText(string file); 17 | static string readText(FILE *file); 18 | static void writeText(string file,const string& str,bool isAppend); 19 | static bool savefile(const char* filePath,size_t size,size_t start,bool isDele); 20 | static string get_file_name(int fd,pid_t pid); 21 | static int copy_file(const char* SourceFile, const char* TargetFile); 22 | static bool isFileExists(string name); 23 | }; 24 | 25 | 26 | #endif //QCONTAINER_PRO_FILEUTILS_H 27 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/libpath.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2022/4/28. 3 | // 4 | 5 | #ifndef QCONTAINER_PRO_LIBPATH_H 6 | #define QCONTAINER_PRO_LIBPATH_H 7 | 8 | 9 | 10 | #include "dlfcn_compat.h" 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | char *getlibArtPath() ; 18 | 19 | char *getLinkerPath() ; 20 | //这里面包含了一些 对string操作的方法 21 | char *getlibcPlusPath() ; 22 | 23 | char *getlibcPath() ; 24 | 25 | char *getMediaPath() ; 26 | 27 | char *getJitPath(); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | 34 | #endif //QCONTAINER_PRO_LIBPATH_H 35 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/parse.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Administrator on 2020-09-14. 3 | // 4 | 5 | #ifndef INC_01_PARSE_H 6 | #define INC_01_PARSE_H 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | using namespace std; 34 | 35 | class parse { 36 | 37 | public: 38 | [[maybe_unused]] static jstring char2jstring(JNIEnv *env, const char *pat); 39 | 40 | static string jstring2str(JNIEnv *env, jstring jstr); 41 | 42 | static std::map jmap2cmap(JNIEnv *env,jobject jmap); 43 | 44 | 45 | static string get_process_name(); 46 | 47 | static string get_process_name_pid(pid_t pid); 48 | 49 | [[maybe_unused]] static bool jboolean2bool(jboolean value); 50 | 51 | }; 52 | 53 | 54 | #endif //INC_01_PARSE_H 55 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/raw_syscall.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Zhenxi on 2022/8/22. 3 | // 4 | 5 | #ifndef HUNTER_RAW_SYSCALL_H 6 | #define HUNTER_RAW_SYSCALL_H 7 | 8 | #include 9 | 10 | #define INLINE __always_inline 11 | extern "C" { 12 | INLINE extern long raw_syscall(long __number, ...); 13 | } 14 | #endif //HUNTER_RAW_SYSCALL_H 15 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/includes/version.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by zhenxi on 2022/4/30. 3 | // 4 | 5 | #ifndef QCONTAINER_PRO_VERSION_H 6 | #define QCONTAINER_PRO_VERSION_H 7 | 8 | #define ANDROID_K 19 9 | #define ANDROID_L 21 10 | #define ANDROID_L2 22 11 | #define ANDROID_M 23 12 | #define ANDROID_N 24 13 | #define ANDROID_N2 25 14 | //Android 8.0 15 | #define ANDROID_O 26 16 | //Android 8.1 17 | #define ANDROID_O2 27 18 | //Android 9.0 19 | #define ANDROID_P 28 20 | //Android 10.0 21 | #define ANDROID_Q 29 22 | //Android 11.0 23 | #define ANDROID_R 30 24 | //Android 12.0 25 | #define ANDROID_S 31 26 | 27 | 28 | #endif //QCONTAINER_PRO_VERSION_H 29 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/libpath/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | 4 | 5 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wwritable-strings") 6 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwritable-strings") 7 | 8 | 9 | 10 | 11 | add_library( 12 | libpath 13 | 14 | STATIC 15 | 16 | libpath.cpp 17 | 18 | ) 19 | 20 | target_link_libraries( 21 | libpath 22 | adapter 23 | 24 | ${log-lib} 25 | ) 26 | 27 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/raw_syscall/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | enable_language(C ASM) 3 | 4 | 5 | 6 | 7 | 8 | 9 | if (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a") 10 | set(RAW_SOURCE syscall64.S) 11 | elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a") 12 | set(RAW_SOURCE syscall32.S) 13 | endif () 14 | 15 | add_library( 16 | raw_syscall 17 | 18 | STATIC 19 | 20 | ${RAW_SOURCE} 21 | ) 22 | 23 | target_link_libraries( 24 | raw_syscall 25 | 26 | ${log-lib} 27 | ) 28 | 29 | 30 | find_library( 31 | log-lib 32 | log 33 | ) 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/raw_syscall/syscall32.S: -------------------------------------------------------------------------------- 1 | .text 2 | .global raw_syscall 3 | .type raw_syscall,%function 4 | 5 | raw_syscall: 6 | MOV R12, SP 7 | STMFD SP!, {R4-R7} 8 | MOV R7, R0 9 | MOV R0, R1 10 | MOV R1, R2 11 | MOV R2, R3 12 | LDMIA R12, {R3-R6} 13 | SVC 0 14 | LDMFD SP!, {R4-R7} 15 | mov pc, lr 16 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/raw_syscall/syscall64.S: -------------------------------------------------------------------------------- 1 | .text 2 | .global raw_syscall 3 | .type raw_syscall,@function 4 | 5 | raw_syscall: 6 | MOV X8, X0 7 | MOV X0, X1 8 | MOV X1, X2 9 | MOV X2, X3 10 | MOV X3, X4 11 | MOV X4, X5 12 | MOV X5, X6 13 | SVC 0 14 | RET 15 | -------------------------------------------------------------------------------- /nativeLib/src/main/cpp/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing -std=c++20") 3 | #添加内联支持 4 | enable_language(C ASM) 5 | 6 | 7 | 8 | 9 | 10 | 11 | #native基础类库路径 12 | include_directories( 13 | ./ 14 | ${HomePath}/nativeLib/src/main/cpp/ 15 | ${HomePath}/nativeLib/src/main/cpp/includes/ 16 | ) 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | #这个库主要是包含一些常用的工具类 26 | add_library( 27 | utils 28 | 29 | STATIC 30 | 31 | parse.cpp 32 | fileUtils.cpp 33 | stringUtils.cpp 34 | appUtils.cpp 35 | ) 36 | 37 | target_link_libraries( 38 | utils 39 | 40 | dlfc 41 | libpath 42 | runtimehook 43 | ${log-lib} 44 | ) 45 | 46 | 47 | 48 | 49 | find_library( 50 | log-lib 51 | log 52 | ) 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /nativeLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | nativehook 3 | 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name "aliyunmaven" 5 | url "https://maven.aliyun.com/repository/public" 6 | } 7 | maven { 8 | name "aliyunGoogle" 9 | url "https://maven.aliyun.com/repository/google" 10 | } 11 | gradlePluginPortal() 12 | google() 13 | mavenCentral() 14 | } 15 | } 16 | dependencyResolutionManagement { 17 | repositories { 18 | maven { url "https://jitpack.io" } 19 | google() 20 | mavenCentral() 21 | } 22 | } 23 | rootProject.name = "XposeJniTrace" 24 | include ':app' 25 | include ':nativeLib' 26 | --------------------------------------------------------------------------------