├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── README.md ├── README.zh-CN.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── module.gradle ├── module ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── cpp │ ├── ByNameModding │ │ ├── BNM.cpp │ │ ├── BNM.hpp │ │ ├── BNM_data │ │ │ ├── BasicStructs.h │ │ │ ├── BasicStructs │ │ │ │ ├── Color.h │ │ │ │ ├── Quaternion.h │ │ │ │ ├── Ray.h │ │ │ │ ├── RaycastHit.h │ │ │ │ ├── Rect.h │ │ │ │ ├── Vector2.h │ │ │ │ └── Vector3.h │ │ │ ├── Il2CppHeaders │ │ │ │ ├── 2017.1.h │ │ │ │ ├── 2017.4.h │ │ │ │ ├── 2018.1.h │ │ │ │ ├── 2018.2.h │ │ │ │ ├── 2018.4.h │ │ │ │ ├── 2019.2.h │ │ │ │ ├── 2019.3.h │ │ │ │ ├── 2019.4.h │ │ │ │ ├── 2020.1.h │ │ │ │ ├── 2020.3.h │ │ │ │ ├── 2021.1.h │ │ │ │ ├── 2021.2.h │ │ │ │ └── 2021.3.h │ │ │ ├── utf8.h │ │ │ └── utf8 │ │ │ │ ├── core.h │ │ │ │ └── unchecked.h │ │ └── BNM_settings.hpp │ ├── CMakeLists.txt │ ├── Data │ │ └── Fonts │ │ │ └── Roboto-Regular.h │ ├── Dobby │ │ ├── .clang-format │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── LICENSE │ │ ├── README.md │ │ ├── README_zh-cn.md │ │ ├── build-workspace │ │ │ ├── auto-build.sh │ │ │ └── prefab │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── modules │ │ │ │ └── dobby │ │ │ │ │ ├── libs │ │ │ │ │ ├── android.arm64-v8a │ │ │ │ │ │ └── abi.json │ │ │ │ │ ├── android.armeabi-v7a │ │ │ │ │ │ └── abi.json │ │ │ │ │ ├── android.x86 │ │ │ │ │ │ └── abi.json │ │ │ │ │ └── android.x86_64 │ │ │ │ │ │ └── abi.json │ │ │ │ │ └── module.json │ │ │ │ └── prefab.json │ │ ├── builtin-plugin │ │ │ ├── ApplicationEventMonitor │ │ │ │ ├── MGCopyAnswerMonitor.cc │ │ │ │ ├── dobby_monitor.h │ │ │ │ ├── dynamic_loader_monitor.cc │ │ │ │ ├── file_operation_monitor.cc │ │ │ │ ├── memory_operation_instrument.cc │ │ │ │ ├── posix_file_descriptor_operation_monitor.cc │ │ │ │ └── posix_socket_network_monitor.cc │ │ │ ├── BionicLinkerRestriction │ │ │ │ ├── bionic_linker_restriction.cc │ │ │ │ ├── bionic_linker_restriction.h │ │ │ │ └── linker_restriction_demo.cc │ │ │ ├── Dyld2HideLibrary │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── dyld2_hide_library.cc │ │ │ │ └── dyld2_hide_library.h │ │ │ ├── GlobalOffsetTableHook │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── global_offset_table_hook.cc │ │ │ │ └── global_offset_table_hook.h │ │ │ ├── HideSystemCall │ │ │ │ └── README │ │ │ ├── IntegrityReadCallback │ │ │ │ └── README │ │ │ ├── LinkerImageLoadCallback │ │ │ │ └── linker_load_callback.cc │ │ │ ├── MemoryRemapHook │ │ │ │ └── README │ │ │ ├── ObjcRuntimeHook │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── objc_runtime_hook.h │ │ │ │ └── objc_runtime_hook.mm │ │ │ ├── SupervisorCallMonitor │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── README │ │ │ │ ├── XnuInternal │ │ │ │ │ ├── README │ │ │ │ │ ├── mach │ │ │ │ │ │ ├── audit_triggers.defs │ │ │ │ │ │ ├── boolean.h │ │ │ │ │ │ ├── bootstrap.h │ │ │ │ │ │ ├── clock.defs │ │ │ │ │ │ ├── clock.h │ │ │ │ │ │ ├── clock_priv.defs │ │ │ │ │ │ ├── clock_priv.h │ │ │ │ │ │ ├── clock_reply.defs │ │ │ │ │ │ ├── clock_reply.h │ │ │ │ │ │ ├── clock_types.defs │ │ │ │ │ │ ├── clock_types.h │ │ │ │ │ │ ├── dyld_kernel.h │ │ │ │ │ │ ├── error.h │ │ │ │ │ │ ├── exc.defs │ │ │ │ │ │ ├── exc.h │ │ │ │ │ │ ├── exception.h │ │ │ │ │ │ ├── exception_types.h │ │ │ │ │ │ ├── host_info.h │ │ │ │ │ │ ├── host_notify.h │ │ │ │ │ │ ├── host_notify_reply.defs │ │ │ │ │ │ ├── host_priv.defs │ │ │ │ │ │ ├── host_priv.h │ │ │ │ │ │ ├── host_reboot.h │ │ │ │ │ │ ├── host_security.defs │ │ │ │ │ │ ├── host_security.h │ │ │ │ │ │ ├── host_special_ports.h │ │ │ │ │ │ ├── i386 │ │ │ │ │ │ │ ├── _structs.h │ │ │ │ │ │ │ ├── asm.h │ │ │ │ │ │ │ ├── boolean.h │ │ │ │ │ │ │ ├── exception.h │ │ │ │ │ │ │ ├── fp_reg.h │ │ │ │ │ │ │ ├── kern_return.h │ │ │ │ │ │ │ ├── ndr_def.h │ │ │ │ │ │ │ ├── processor_info.h │ │ │ │ │ │ │ ├── rpc.h │ │ │ │ │ │ │ ├── sdt_isa.h │ │ │ │ │ │ │ ├── thread_state.h │ │ │ │ │ │ │ ├── thread_status.h │ │ │ │ │ │ │ ├── vm_param.h │ │ │ │ │ │ │ └── vm_types.h │ │ │ │ │ │ ├── kern_return.h │ │ │ │ │ │ ├── kmod.h │ │ │ │ │ │ ├── lock_set.defs │ │ │ │ │ │ ├── lock_set.h │ │ │ │ │ │ ├── mach.h │ │ │ │ │ │ ├── mach_error.h │ │ │ │ │ │ ├── mach_exc.defs │ │ │ │ │ │ ├── mach_host.defs │ │ │ │ │ │ ├── mach_host.h │ │ │ │ │ │ ├── mach_init.h │ │ │ │ │ │ ├── mach_interface.h │ │ │ │ │ │ ├── mach_param.h │ │ │ │ │ │ ├── mach_port.defs │ │ │ │ │ │ ├── mach_port.h │ │ │ │ │ │ ├── mach_right.h │ │ │ │ │ │ ├── mach_syscalls.h │ │ │ │ │ │ ├── mach_time.h │ │ │ │ │ │ ├── mach_traps.h │ │ │ │ │ │ ├── mach_types.defs │ │ │ │ │ │ ├── mach_types.h │ │ │ │ │ │ ├── mach_vm.defs │ │ │ │ │ │ ├── mach_vm.h │ │ │ │ │ │ ├── mach_voucher.defs │ │ │ │ │ │ ├── mach_voucher.h │ │ │ │ │ │ ├── mach_voucher_attr_control.defs │ │ │ │ │ │ ├── mach_voucher_types.h │ │ │ │ │ │ ├── machine.h │ │ │ │ │ │ ├── machine │ │ │ │ │ │ │ ├── _structs.h │ │ │ │ │ │ │ ├── asm.h │ │ │ │ │ │ │ ├── boolean.h │ │ │ │ │ │ │ ├── exception.h │ │ │ │ │ │ │ ├── kern_return.h │ │ │ │ │ │ │ ├── machine_types.defs │ │ │ │ │ │ │ ├── ndr_def.h │ │ │ │ │ │ │ ├── processor_info.h │ │ │ │ │ │ │ ├── rpc.h │ │ │ │ │ │ │ ├── sdt.h │ │ │ │ │ │ │ ├── sdt_isa.h │ │ │ │ │ │ │ ├── thread_state.h │ │ │ │ │ │ │ ├── thread_status.h │ │ │ │ │ │ │ ├── vm_param.h │ │ │ │ │ │ │ └── vm_types.h │ │ │ │ │ │ ├── memory_entry.defs │ │ │ │ │ │ ├── memory_entry.h │ │ │ │ │ │ ├── memory_object_types.h │ │ │ │ │ │ ├── message.h │ │ │ │ │ │ ├── mig.h │ │ │ │ │ │ ├── mig_errors.h │ │ │ │ │ │ ├── mig_strncpy_zerofill_support.h │ │ │ │ │ │ ├── mig_voucher_support.h │ │ │ │ │ │ ├── ndr.h │ │ │ │ │ │ ├── notify.defs │ │ │ │ │ │ ├── notify.h │ │ │ │ │ │ ├── policy.h │ │ │ │ │ │ ├── port.h │ │ │ │ │ │ ├── port_obj.h │ │ │ │ │ │ ├── processor.defs │ │ │ │ │ │ ├── processor.h │ │ │ │ │ │ ├── processor_info.h │ │ │ │ │ │ ├── processor_set.defs │ │ │ │ │ │ ├── processor_set.h │ │ │ │ │ │ ├── rpc.h │ │ │ │ │ │ ├── sdt.h │ │ │ │ │ │ ├── semaphore.h │ │ │ │ │ │ ├── shared_memory_server.h │ │ │ │ │ │ ├── shared_region.h │ │ │ │ │ │ ├── std_types.defs │ │ │ │ │ │ ├── std_types.h │ │ │ │ │ │ ├── sync.h │ │ │ │ │ │ ├── sync_policy.h │ │ │ │ │ │ ├── task.defs │ │ │ │ │ │ ├── task.h │ │ │ │ │ │ ├── task_access.defs │ │ │ │ │ │ ├── task_info.h │ │ │ │ │ │ ├── task_inspect.h │ │ │ │ │ │ ├── task_policy.h │ │ │ │ │ │ ├── task_special_ports.h │ │ │ │ │ │ ├── telemetry_notification.defs │ │ │ │ │ │ ├── thread_act.defs │ │ │ │ │ │ ├── thread_act.h │ │ │ │ │ │ ├── thread_info.h │ │ │ │ │ │ ├── thread_policy.h │ │ │ │ │ │ ├── thread_special_ports.h │ │ │ │ │ │ ├── thread_state.h │ │ │ │ │ │ ├── thread_status.h │ │ │ │ │ │ ├── thread_switch.h │ │ │ │ │ │ ├── time_value.h │ │ │ │ │ │ ├── vm_attributes.h │ │ │ │ │ │ ├── vm_behavior.h │ │ │ │ │ │ ├── vm_inherit.h │ │ │ │ │ │ ├── vm_map.defs │ │ │ │ │ │ ├── vm_map.h │ │ │ │ │ │ ├── vm_page_size.h │ │ │ │ │ │ ├── vm_param.h │ │ │ │ │ │ ├── vm_prot.h │ │ │ │ │ │ ├── vm_purgable.h │ │ │ │ │ │ ├── vm_region.h │ │ │ │ │ │ ├── vm_statistics.h │ │ │ │ │ │ ├── vm_sync.h │ │ │ │ │ │ ├── vm_task.h │ │ │ │ │ │ └── vm_types.h │ │ │ │ │ ├── syscall_sw.c │ │ │ │ │ └── syscalls.c │ │ │ │ ├── deprecated │ │ │ │ │ ├── mach_system_call.cc │ │ │ │ │ └── system_call.cc │ │ │ │ ├── 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 │ │ │ │ ├── dyld_shared_cache_symbol_table_iterator.cc │ │ │ │ ├── shared-cache │ │ │ │ │ └── dyld_cache_format.h │ │ │ │ └── shared_cache_internal.h │ │ │ │ └── pe │ │ │ │ └── dobby_symbol_resolver.cc │ │ ├── cmake │ │ │ ├── AutoFiles.cmake │ │ │ ├── Globals.cmake │ │ │ ├── Macros.cmake │ │ │ ├── Util.cmake │ │ │ ├── XcodeGenerator.cmake │ │ │ ├── dobby.xcode.source.cmake │ │ │ └── ios.toolchain.cmake │ │ ├── docs │ │ │ ├── .nojekyll │ │ │ ├── _cover_page.md │ │ │ ├── _nav_bar.md │ │ │ ├── _side_bar.md │ │ │ ├── build-documentation.md │ │ │ ├── get-started-android.md │ │ │ ├── get-started-ios.md │ │ │ ├── get-started.md │ │ │ ├── images │ │ │ │ └── vue-logo.png │ │ │ ├── index.html │ │ │ ├── intro-board.md │ │ │ ├── scripts │ │ │ │ ├── imagesloaded.pkgd.min.js │ │ │ │ ├── palettify.min.js │ │ │ │ └── palettify.styles.min.js │ │ │ └── styles │ │ │ │ ├── grid.min.css │ │ │ │ ├── palettify.min.css │ │ │ │ └── style.css │ │ ├── example │ │ │ ├── CMakeLists.txt │ │ │ ├── android_common_api.cc │ │ │ ├── darwin_common_api.cc │ │ │ └── main.cc │ │ ├── external │ │ │ ├── logging │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── cxxlogging.cc │ │ │ │ ├── logging.c │ │ │ │ └── logging │ │ │ │ │ ├── check_logging.h │ │ │ │ │ ├── cxxlogging.h │ │ │ │ │ └── logging.h │ │ │ ├── misc-helper │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── async_logger.cc │ │ │ │ ├── misc-helper │ │ │ │ │ ├── async_logger.h │ │ │ │ │ └── variable_cache.h │ │ │ │ ├── pthread_helper.cc │ │ │ │ ├── pthread_helper.h │ │ │ │ ├── unistd_helper.h │ │ │ │ └── variable_cache.c │ │ │ └── xnucxx │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── LiteCollection.cc │ │ │ │ ├── LiteIterator.cc │ │ │ │ ├── LiteMemOpt.cc │ │ │ │ ├── LiteMutableArray.cc │ │ │ │ ├── LiteMutableBuffer.cc │ │ │ │ ├── LiteObject.cc │ │ │ │ └── xnucxx │ │ │ │ ├── LiteCollection.h │ │ │ │ ├── LiteIterator.h │ │ │ │ ├── LiteMemOpt.h │ │ │ │ ├── LiteMutableArray.h │ │ │ │ ├── LiteMutableBuffer.h │ │ │ │ └── LiteObject.h │ │ ├── include │ │ │ └── dobby.h │ │ ├── source │ │ │ ├── InstructionRelocation │ │ │ │ ├── InstructionRelocation.h │ │ │ │ ├── arm │ │ │ │ │ ├── ARMInstructionRelocation.cc │ │ │ │ │ └── ARMInstructionRelocation.h │ │ │ │ ├── arm64 │ │ │ │ │ ├── ARM64InstructionRelocation.cc │ │ │ │ │ ├── ARM64InstructionRelocation.h │ │ │ │ │ └── ARM64PCLiteralInstructionTable.h │ │ │ │ ├── x64 │ │ │ │ │ ├── X64InstructionRelocation.cc │ │ │ │ │ └── X64InstructionRelocation.h │ │ │ │ └── x86 │ │ │ │ │ ├── X86InstructionRelocation.cc │ │ │ │ │ ├── X86InstructionRelocation.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 │ │ │ ├── InterceptRouting │ │ │ │ ├── InterceptRouting.cpp │ │ │ │ ├── InterceptRouting.h │ │ │ │ ├── Routing │ │ │ │ │ ├── DynamicBinaryInstrument │ │ │ │ │ │ ├── DynamicBinaryInstrumentExport.cc │ │ │ │ │ │ ├── dynamic-binary-instrument.cc │ │ │ │ │ │ ├── dynamic-binary-instrument.h │ │ │ │ │ │ ├── intercept_routing_handler.cc │ │ │ │ │ │ └── intercept_routing_handler.h │ │ │ │ │ ├── FunctionInlineReplace │ │ │ │ │ │ ├── FunctionInlineReplaceExport.cc │ │ │ │ │ │ ├── function-inline-replace.cc │ │ │ │ │ │ └── function-inline-replace.h │ │ │ │ │ └── FunctionWrapper │ │ │ │ │ │ ├── FunctionWrapperExport.cc │ │ │ │ │ │ ├── function-wrapper.cc │ │ │ │ │ │ ├── function-wrapper.h │ │ │ │ │ │ ├── intercept_routing_handler.cc │ │ │ │ │ │ └── intercept_routing_handler.h │ │ │ │ └── RoutingPlugin │ │ │ │ │ ├── NearBranchTrampoline │ │ │ │ │ ├── NeaBranchTrampoline.cc │ │ │ │ │ └── NearBranchTrampoline.h │ │ │ │ │ ├── RoutingPlugin.cc │ │ │ │ │ └── RoutingPlugin.h │ │ │ ├── Interceptor.cpp │ │ │ ├── Interceptor.h │ │ │ ├── MemoryAllocator │ │ │ │ ├── AssemblyCodeBuilder.cc │ │ │ │ ├── AssemblyCodeBuilder.h │ │ │ │ ├── CodeBuffer │ │ │ │ │ ├── CodeBufferBase.cc │ │ │ │ │ ├── CodeBufferBase.h │ │ │ │ │ ├── code-buffer-arm.cc │ │ │ │ │ ├── code-buffer-arm.h │ │ │ │ │ ├── code-buffer-arm64.cc │ │ │ │ │ ├── code-buffer-arm64.h │ │ │ │ │ ├── code-buffer-x64.cc │ │ │ │ │ ├── code-buffer-x64.h │ │ │ │ │ ├── code-buffer-x86.cc │ │ │ │ │ └── code-buffer-x86.h │ │ │ │ ├── MemoryArena.cc │ │ │ │ ├── MemoryArena.h │ │ │ │ ├── NearMemoryArena.cc │ │ │ │ └── NearMemoryArena.h │ │ │ ├── PlatformUnifiedInterface │ │ │ │ ├── ExecMemory │ │ │ │ │ ├── ClearCacheTool.h │ │ │ │ │ └── CodePatchTool.h │ │ │ │ └── StdMemory.h │ │ │ ├── TrampolineBridge │ │ │ │ ├── ClosureTrampolineBridge │ │ │ │ │ ├── AssemblyClosureTrampoline.h │ │ │ │ │ ├── arm │ │ │ │ │ │ ├── ARMAssemblyClosureTrampoline.cc │ │ │ │ │ │ ├── closure-bridge-arm.cc │ │ │ │ │ │ ├── dummy │ │ │ │ │ │ │ ├── closure-bridge-template-arm.cc │ │ │ │ │ │ │ └── closure-trampoline-template-arm.S │ │ │ │ │ │ └── helper-arm.cc │ │ │ │ │ ├── arm64 │ │ │ │ │ │ ├── ARM64AssemblyClosureTrampoline.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 │ │ │ │ │ │ ├── X64AssemblyClosureTrampoline.cc │ │ │ │ │ │ ├── closure-bridge-x64.cc │ │ │ │ │ │ ├── dummy │ │ │ │ │ │ │ ├── closure-bridge-template-x64.c │ │ │ │ │ │ │ └── closure-trampoline-template-x64.S │ │ │ │ │ │ └── helper-x64.cc │ │ │ │ │ └── x86 │ │ │ │ │ │ ├── X86AssemblyClosureTrampoline.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 │ │ │ ├── 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 │ │ │ ├── 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 │ │ │ │ └── modules │ │ │ │ │ ├── assembler │ │ │ │ │ ├── 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 │ │ │ │ ├── list_structure.h │ │ │ │ ├── platform_macro.h │ │ │ │ ├── type_macro.h │ │ │ │ └── utility_macro.h │ │ └── tests │ │ │ ├── CMakelists.txt │ │ │ ├── InstructionRelocation │ │ │ ├── aarch64 │ │ │ │ └── test_aarch64_instruction_relocation.cc │ │ │ └── x64 │ │ │ │ └── test_x64_instruction_relocation.cc │ │ │ └── catch.hpp │ ├── Hooking │ │ ├── Hooks.h │ │ ├── JNIHooks.h │ │ └── dobby.h │ ├── ImGui │ │ ├── ImGui_mod.h │ │ ├── imconfig.h │ │ ├── imgui.cpp │ │ ├── imgui.h │ │ ├── imgui_demo.cpp │ │ ├── imgui_draw.cpp │ │ ├── imgui_impl_android.cpp │ │ ├── imgui_impl_android.h │ │ ├── imgui_impl_opengl2.cpp │ │ ├── imgui_impl_opengl2.h │ │ ├── imgui_impl_opengl3.cpp │ │ ├── imgui_impl_opengl3.h │ │ ├── imgui_impl_opengl3_loader.h │ │ ├── imgui_internal.h │ │ ├── imgui_tables.cpp │ │ ├── imgui_widgets.cpp │ │ ├── imstb_rectpack.h │ │ ├── imstb_textedit.h │ │ └── imstb_truetype.h │ ├── Memory │ │ ├── KittyArm64.cpp │ │ ├── KittyArm64.h │ │ ├── KittyMemory.cpp │ │ ├── KittyMemory.h │ │ ├── KittyScanner.cpp │ │ ├── KittyScanner.h │ │ ├── KittyUtils.cpp │ │ ├── KittyUtils.h │ │ ├── MemoryBackup.cpp │ │ ├── MemoryBackup.h │ │ ├── MemoryPatch.cpp │ │ └── MemoryPatch.h │ ├── Menu.h │ ├── Misc │ │ ├── ESP.h │ │ ├── FileWrapper.h │ │ ├── FunctionPointers.h │ │ ├── ImGuiStuff.h │ │ ├── JNIStuff.h │ │ ├── Logging.h │ │ └── Utils.h │ ├── Obfuscation │ │ ├── Custom_Obfuscate.h │ │ ├── Obfuscate.h │ │ ├── instr.cpp │ │ └── instr.h │ ├── Unity │ │ └── Unity.h │ ├── game.h │ ├── hook.cpp │ ├── hook.h │ ├── http │ │ └── cpr │ │ │ ├── api.h │ │ │ ├── async.cpp │ │ │ ├── async.h │ │ │ ├── auth.cpp │ │ │ ├── auth.h │ │ │ ├── bearer.cpp │ │ │ ├── bearer.h │ │ │ ├── body.h │ │ │ ├── callback.h │ │ │ ├── connect_timeout.h │ │ │ ├── cookies.cpp │ │ │ ├── cookies.h │ │ │ ├── cpr.h │ │ │ ├── cprtypes.cpp │ │ │ ├── cprtypes.h │ │ │ ├── cprver.h │ │ │ ├── curl_container.cpp │ │ │ ├── curl_container.h │ │ │ ├── curlholder.cpp │ │ │ ├── curlholder.h │ │ │ ├── error.cpp │ │ │ ├── error.h │ │ │ ├── http_version.h │ │ │ ├── interceptor.cpp │ │ │ ├── interceptor.h │ │ │ ├── interface.h │ │ │ ├── limit_rate.h │ │ │ ├── low_speed.h │ │ │ ├── multipart.cpp │ │ │ ├── multipart.h │ │ │ ├── parameters.cpp │ │ │ ├── parameters.h │ │ │ ├── payload.cpp │ │ │ ├── payload.h │ │ │ ├── proxies.cpp │ │ │ ├── proxies.h │ │ │ ├── proxyauth.cpp │ │ │ ├── proxyauth.h │ │ │ ├── range.h │ │ │ ├── redirect.cpp │ │ │ ├── redirect.h │ │ │ ├── reserve_size.h │ │ │ ├── response.cpp │ │ │ ├── response.h │ │ │ ├── session.cpp │ │ │ ├── session.h │ │ │ ├── singleton.h │ │ │ ├── ssl_options.h │ │ │ ├── status_codes.h │ │ │ ├── threadpool.cpp │ │ │ ├── threadpool.h │ │ │ ├── timeout.cpp │ │ │ ├── timeout.h │ │ │ ├── unix_socket.cpp │ │ │ ├── unix_socket.h │ │ │ ├── user_agent.h │ │ │ ├── util.cpp │ │ │ ├── util.h │ │ │ └── verbose.h │ ├── il2cpp-api-functions.h │ ├── il2cpp-class.h │ ├── il2cpp-tabledefs.h │ ├── il2cpp_dump.cpp │ ├── il2cpp_dump.h │ ├── libs │ │ ├── arm64-v8a │ │ │ └── libdobby.a │ │ └── armeabi-v7a │ │ │ └── libdobby.a │ ├── log.h │ ├── main.cpp │ ├── nlohmann │ │ └── json.hpp │ └── zygisk.hpp │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.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 ├── settings.gradle └── template └── magisk_module ├── META-INF └── com │ └── google │ └── android │ ├── update-binary │ └── updater-script └── module.prop /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | workflow_dispatch: 4 | inputs: 5 | package_name: 6 | description: "Package name of the game:" 7 | required: true 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-java@v3 15 | with: 16 | distribution: temurin 17 | java-version: 11 18 | - run: | 19 | chmod +x ./gradlew 20 | sed -i 's/moduleDescription = "/moduleDescription = "(${{ github.event.inputs.package_name }}) /g' module.gradle 21 | sed -i "s/com.game.packagename/${{ github.event.inputs.package_name }}/g" module/src/main/cpp/game.h 22 | ./gradlew :module:assembleRelease 23 | - uses: actions/upload-artifact@v3 24 | with: 25 | name: zygisk-il2cppdumper 26 | path: out/magisk_module_release/ 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | /.idea/caches/build_file_checksums.ser 6 | /.idea/libraries 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | .DS_Store 10 | /build 11 | /captures 12 | /out 13 | .externalNativeBuild 14 | .cxx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OUTDATED AND BROKEN, HERE'S A FIXED VERSION INSTEAD [Zygisk-Menu-Template](https://github.com/fedes1to/Zygisk-Menu-Template) 2 | 3 | ## ImGUI-Zygisk-Unity 4 | 5 | to clarify, this isn't working code, but a proof of concept, i will try to fix it though as its gaining quite a bit of attention 6 | 7 | actually usable thing epic ITS A POC THO DONT KILL ME THANK 8 | 9 | Used to inject into game using zygote thingy 10 | 11 | Uses [PolarImGui](https://github.com/Polarmods/PolarImGui) and [Zygisk-Il2CppDumper](https://github.com/Perfare/Zygisk-Il2CppDumper) 12 | -------------------------------------------------------------------------------- /README.zh-CN.md: -------------------------------------------------------------------------------- 1 | # Zygisk-Il2CppDumper 2 | Zygisk版Il2CppDumper,在游戏运行时dump il2cpp数据,可以绕过保护,加密以及混淆。 3 | 4 | ## 如何食用 5 | 1. 安装[Magisk](https://github.com/topjohnwu/Magisk) v24以上版本并开启Zygisk 6 | 2. 生成模块 7 | - GitHub Actions 8 | 1. Fork这个项目 9 | 2. 在你fork的项目中选择**Actions**选项卡 10 | 3. 在左边的侧边栏中,单击**Build** 11 | 4. 选择**Run workflow** 12 | 5. 输入游戏包名并点击**Run workflow** 13 | 6. 等待操作完成并下载 14 | - Android Studio 15 | 1. 下载源码 16 | 2. 编辑`game.h`, 修改`GamePackageName`为游戏包名 17 | 3. 使用Android Studio运行gradle任务`:module:assembleRelease`编译,zip包会生成在`out`文件夹下 18 | 3. 在Magisk里安装模块 19 | 4. 启动游戏,会在`/data/data/GamePackageName/files/`目录下生成`dump.cs` -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | buildToolsVersion = '32.0.0' 3 | } 4 | 5 | apply plugin: 'idea' 6 | 7 | idea.module { 8 | excludeDirs += file('out') 9 | resourceDirs += file('template') 10 | resourceDirs += file('scripts') 11 | } 12 | 13 | buildscript { 14 | repositories { 15 | mavenCentral() 16 | google() 17 | } 18 | dependencies { 19 | classpath 'com.android.tools.build:gradle:7.2.1' 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | mavenCentral() 26 | google() 27 | } 28 | } 29 | 30 | ext { 31 | minSdkVersion = 23 32 | targetSdkVersion = 30 33 | 34 | outDir = file("$rootDir/out") 35 | } 36 | 37 | task clean(type: Delete) { 38 | delete rootProject.buildDir, outDir 39 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jul 12 21:05:17 CST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /module.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | moduleLibraryName = "il2cppdumper" 3 | magiskModuleId = "zygisk_il2cppdumper" 4 | moduleName = "Il2CppDumper" 5 | moduleAuthor = "Perfare" 6 | moduleDescription = "Il2CppDumper Zygisk version." 7 | moduleVersion = "v1.0.0" 8 | moduleVersionCode = 1 9 | } 10 | -------------------------------------------------------------------------------- /module/.gitignore: -------------------------------------------------------------------------------- 1 | /.externalNativeBuild 2 | /build 3 | /release -------------------------------------------------------------------------------- /module/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /module/src/main/cpp/ByNameModding/BNM_data/BasicStructs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BasicStructs/Color.h" 3 | #include "BasicStructs/Quaternion.h" 4 | #include "BasicStructs/Ray.h" 5 | #include "BasicStructs/RaycastHit.h" 6 | #include "BasicStructs/Rect.h" 7 | #include "BasicStructs/Vector2.h" 8 | #include "BasicStructs/Vector3.h" -------------------------------------------------------------------------------- /module/src/main/cpp/ByNameModding/BNM_data/BasicStructs/Ray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vector3.h" 3 | struct Ray { 4 | Vector3 m_Origin, m_Direction; 5 | std::string str() { return OBFUSCATES_BNM("m_Origin: ") + m_Origin.str() + OBFUSCATES_BNM(", m_Direction: ") + m_Direction.str(); } 6 | inline const char *c_str() { return str().c_str(); } 7 | }; -------------------------------------------------------------------------------- /module/src/main/cpp/ByNameModding/BNM_data/BasicStructs/RaycastHit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vector3.h" 3 | #include "Vector2.h" 4 | struct RaycastHit { 5 | Vector3 Point, Normal; 6 | unsigned int FaceID; 7 | float Distance; 8 | Vector2 UV; 9 | int m_Collider; 10 | void *get_Collider() const; 11 | std::string str() { return OBFUSCATES_BNM("Point: ") + Point.str() + OBFUSCATES_BNM(", Normal: ") + Normal.str() + OBFUSCATES_BNM(", FaceID: ") + std::to_string(FaceID) + OBFUSCATES_BNM(", Distance: ") + std::to_string(Distance) + OBFUSCATES_BNM(", UV: ") + UV.str() + OBFUSCATES_BNM(", m_Collider: ") + std::to_string(m_Collider); } 12 | inline const char *c_str() { return str().c_str(); } 13 | }; -------------------------------------------------------------------------------- /module/src/main/cpp/ByNameModding/BNM_data/BasicStructs/Rect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Rect { 3 | public: 4 | union { 5 | struct { float x, y, w, h; }; 6 | float data[4]; 7 | }; 8 | Rect(): x(0), y(0), w(0), h(0) {} 9 | Rect(float x1, float y1, float w1, float h1): x(x1), y(y1), w(w1), h(h1) {} 10 | std::string str() { return OBFUSCATES_BNM("x: ") + std::to_string(x) + OBFUSCATES_BNM(", y: ") + std::to_string(y) + OBFUSCATES_BNM(", w: ") + std::to_string(w) + OBFUSCATES_BNM(", h: ") + std::to_string(h); } 11 | inline const char *c_str() { return str().c_str(); } 12 | }; -------------------------------------------------------------------------------- /module/src/main/cpp/ByNameModding/BNM_data/utf8.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006 Nemanja Trifunovic 2 | 3 | /* 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 29 | #define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 30 | 31 | #include "utf8/unchecked.h" 32 | 33 | #endif // header guard 34 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea/ 3 | *-build*/ 4 | build-output/ 5 | 6 | CMakeLists.txt.user 7 | CMakeCache.txt 8 | CMakeFiles 9 | CMakeScripts 10 | Testing 11 | Makefile 12 | cmake_install.cmake 13 | install_manifest.txt 14 | compile_commands.json 15 | CTestTestfile.cmake 16 | _deps 17 | 18 | ## Build generated 19 | build/ 20 | DerivedData/ 21 | 22 | ## Various settings 23 | *.pbxuser 24 | !default.pbxuser 25 | *.mode1v3 26 | !default.mode1v3 27 | *.mode2v3 28 | !default.mode2v3 29 | *.perspectivev3 30 | !default.perspectivev3 31 | xcuserdata/ 32 | 33 | ## Other 34 | *.moved-aside 35 | *.xccheckout 36 | *.xcscmblueprint 37 | 38 | ## Obj-C/Swift specific 39 | *.hmap 40 | *.ipa 41 | *.dSYM.zip 42 | *.dSYM 43 | 44 | # Prerequisites 45 | *.d 46 | 47 | # Compiled Object files 48 | *.slo 49 | *.lo 50 | *.o 51 | *.obj 52 | 53 | # Precompiled Headers 54 | *.gch 55 | *.pch 56 | 57 | # Compiled Dynamic libraries 58 | *.so 59 | *.dylib 60 | *.dll 61 | 62 | # Fortran module files 63 | *.mod 64 | *.smod 65 | 66 | # Compiled Static libraries 67 | *.lai 68 | *.la 69 | *.a 70 | *.lib 71 | 72 | # Executables 73 | *.exe 74 | *.out 75 | *.app 76 | 77 | # Prefab 78 | /prefab/**/*.a 79 | /prefab/**/*.h 80 | /AndroidManifest.xml 81 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | - Clean code without STL(port to kernel easily) 11 | - Plugin support(SymbolResolver, SupervisorCallMonitor) 12 | - iOS kernel exploit support(Gollum ?) 13 | 14 | ## Getting started 15 | 16 | ``` 17 | git clone https://github.com/jmpews/Dobby.git --depth=1 18 | cd Dobby/example/ 19 | mkdir build; cd build; cmake .. 20 | ``` 21 | 22 | Or download [latest release](https://github.com/jmpews/Dobby/releases/tag/latest) 23 | 24 | #### [Build Installation](docs/build-documentation.md) 25 | 26 | #### [Getting Started with iOS](docs/get-started-ios.md) 27 | 28 | #### [Getting Started with Android](docs/get-started-android.md) 29 | 30 | ## Documentation 31 | 32 | [full Installation documentation site](https://jmpews.github.io/Dobby/#/) 33 | 34 | ## Download 35 | 36 | [download static library](https://github.com/jmpews/Dobby/releases/tag/latest) 37 | 38 | ## Credits 39 | 40 | 1. [frida-gum](https://github.com/frida/frida-gum) 41 | 2. [minhook](https://github.com/TsudaKageyu/minhook) 42 | 3. [substrate](https://github.com/jevinskie/substrate). 43 | 4. [v8](https://github.com/v8/v8) 44 | 5. [dart](https://github.com/dart-lang/sdk) 45 | 6. [vixl](https://git.linaro.org/arm/vixl.git) 46 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/README_zh-cn.md: -------------------------------------------------------------------------------- 1 | ## Dobby 2 | 3 | **待更新** -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/modules/dobby/libs/android.arm64-v8a/abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi": "arm64-v8a", 3 | "api": 21, 4 | "ndk": 21, 5 | "stl": "c++_static" 6 | } 7 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/modules/dobby/libs/android.armeabi-v7a/abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi": "armeabi-v7a", 3 | "api": 16, 4 | "ndk": 21, 5 | "stl": "c++_static" 6 | } 7 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/modules/dobby/libs/android.x86/abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi": "x86", 3 | "api": 16, 4 | "ndk": 21, 5 | "stl": "c++_static" 6 | } 7 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/modules/dobby/libs/android.x86_64/abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "abi": "x86_64", 3 | "api": 21, 4 | "ndk": 21, 5 | "stl": "c++_static" 6 | } 7 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/modules/dobby/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "export_libraries": [], 3 | "android": {} 4 | } 5 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/build-workspace/prefab/prefab.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dobby", 3 | "schema_version": 1, 4 | "dependencies": [] 5 | } 6 | -------------------------------------------------------------------------------- /module/src/main/cpp/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(RegisterContext *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(RegisterContext *ctx, const HookEntryInfo *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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/ApplicationEventMonitor/dobby_monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef DOBBY_MONITOR_H 2 | #define DOBBY_MONITOR_H 3 | 4 | #include /* getenv */ 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "dobby.h" 15 | 16 | #define LOG printf 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | int DobbyHook(void *function_address, void *replace_call, void **origin_call); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif // !1DOBBY_MONITOR 29 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/BionicLinkerRestriction/bionic_linker_restriction.h: -------------------------------------------------------------------------------- 1 | #ifndef LINKER_RESTRICTION_H 2 | #define LINKER_RESTRICTION_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | typedef void *soinfo_t; 11 | 12 | soinfo_t linker_dlopen(const char *filename, int flag); 13 | 14 | char *linker_soinfo_get_realpath(soinfo_t soinfo); 15 | 16 | uintptr_t linker_soinfo_to_handle(soinfo_t soinfo); 17 | 18 | void linker_iterate_soinfo(int (*cb)(soinfo_t soinfo)); 19 | 20 | void linker_disable_namespace_restriction(); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/BionicLinkerRestriction/linker_restriction_demo.cc: -------------------------------------------------------------------------------- 1 | #include "dobby.h" 2 | 3 | #include "bionic_linker_restriction.h" 4 | 5 | #include "logging/logging.h" 6 | 7 | #include 8 | 9 | #define LOG_TAG "AndroidLinkerRestriction" 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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/Dyld2HideLibrary/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(dyld2_hide_library 2 | dyld2_hide_library.cc 3 | ) -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/Dyld2HideLibrary/dyld2_hide_library.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | int dyld2_hide_library(const char *library_name); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/GlobalOffsetTableHook/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(SYSTEM.Darwin) 2 | set(SOURCE_FILE_LIST 3 | ${CMAKE_CURRENT_SOURCE_DIR}/global_offset_table_hook.cc 4 | ) 5 | endif() 6 | 7 | add_library(global_offset_table_hook STATIC 8 | ${SOURCE_FILE_LIST} 9 | ) 10 | 11 | include_directories( 12 | . 13 | ) 14 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/GlobalOffsetTableHook/global_offset_table_hook.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | int DobbyGlobalOffsetTableReplace(char *image_name, char *symbol_name, void *fake_func, void **orig_func); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/HideSystemCall/README: -------------------------------------------------------------------------------- 1 | private -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/IntegrityReadCallback/README: -------------------------------------------------------------------------------- 1 | private -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/MemoryRemapHook/README: -------------------------------------------------------------------------------- 1 | private -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/ObjcRuntimeHook/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(objc_runtime_hook 2 | objc_runtime_hook.mm 3 | ) -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/ObjcRuntimeHook/objc_runtime_hook.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | IMP DobbyObjcReplace(Class _class, SEL _selector, IMP replacement); 12 | 13 | void DobbyObjcReplaceEx(const char *class_name, const char *selector_name, void *fake_impl, void **orig_impl); 14 | 15 | void *DobbyObjcResolveMethodImp(const char *class_name, const char *selector_name); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/README: -------------------------------------------------------------------------------- 1 | Monitor all supervisor call -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/README: -------------------------------------------------------------------------------- 1 | syscalls.c is automatically generated -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/bootstrap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * Mach bootstrap interfaces (obsolete: header included only for compatibility) 30 | */ 31 | #ifndef _MACH_BOOTSTRAP_H_ 32 | #define _MACH_BOOTSTRAP_H_ 33 | 34 | #endif /* _MACH_BOOTSTRAP_H_ */ 35 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/i386/rpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002,2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_I386_RPC_H_ 33 | #define _MACH_I386_RPC_H_ 34 | 35 | #endif /* _MACH_I386_RPC_H_ */ 36 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/mach_right.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef __MACH_RIGHT_H 29 | #define __MACH_RIGHT_H 30 | 31 | #include 32 | 33 | #if __has_include() 34 | #include 35 | #endif 36 | 37 | #endif // __MACH_RIGHT_H 38 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/mach_syscalls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_MACH_SYSCALLS_H_ 33 | #define _MACH_MACH_SYSCALLS_H_ 34 | 35 | #include 36 | 37 | #endif /* _MACH_MACH_SYSCALLS_H_ */ 38 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/machine/asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_ASM_H 30 | #define _MACH_MACHINE_ASM_H 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/asm.h" 34 | #else 35 | #error architecture not supported 36 | #endif 37 | 38 | #endif /* _MACH_MACHINE_ASM_H */ 39 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/machine/rpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_RPC_H_ 30 | #define _MACH_MACHINE_RPC_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/rpc.h" 34 | #else 35 | #error architecture not supported 36 | #endif 37 | 38 | #endif /* _MACH_MACHINE_RPC_H_ */ 39 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/machine/sdt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2019 Apple Inc. All rights reserved. 3 | */ 4 | /* 5 | * CDDL HEADER START 6 | * 7 | * The contents of this file are subject to the terms of the 8 | * Common Development and Distribution License, Version 1.0 only 9 | * (the "License"). You may not use this file except in compliance 10 | * with the License. 11 | * 12 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 13 | * or http://www.opensolaris.org/os/licensing. 14 | * See the License for the specific language governing permissions 15 | * and limitations under the License. 16 | * 17 | * When distributing Covered Code, include this CDDL HEADER in each 18 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 19 | * If applicable, add the following below this CDDL HEADER, with the 20 | * fields enclosed by brackets "[]" replaced with your own identifying 21 | * information: Portions Copyright [yyyy] [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | /* 26 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 27 | * Use is subject to license terms. 28 | */ 29 | 30 | #ifndef _MACH_MACHINE_SYS_SDT_H 31 | #define _MACH_MACHINE_SYS_SDT_H 32 | 33 | #include 34 | 35 | 36 | #endif /* _MACH_MACHINE_SYS_SDT_H */ 37 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/sdt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms of the 5 | * Common Development and Distribution License, Version 1.0 only 6 | * (the "License"). You may not use this file except in compliance 7 | * with the License. 8 | * 9 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 | * or http://www.opensolaris.org/os/licensing. 11 | * See the License for the specific language governing permissions 12 | * and limitations under the License. 13 | * 14 | * When distributing Covered Code, include this CDDL HEADER in each 15 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 | * If applicable, add the following below this CDDL HEADER, with the 17 | * fields enclosed by brackets "[]" replaced with your own identifying 18 | * information: Portions Copyright [yyyy] [name of copyright owner] 19 | * 20 | * CDDL HEADER END 21 | */ 22 | /* 23 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 | * Use is subject to license terms. 25 | */ 26 | 27 | #ifndef _MACH_SDT_H 28 | #define _MACH_SDT_H 29 | 30 | #include 31 | 32 | #endif /* _MACH_SDT_H */ 33 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/telemetry_notification.defs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, Apple Inc. All rights reserved. 3 | */ 4 | 5 | /* 6 | * Interface definition for the telemetry facility. 7 | */ 8 | 9 | subsystem 10 | #if KERNEL_USER 11 | KernelUser 12 | #endif /* KERNEL_USER */ 13 | telemetry_notification 5100; 14 | 15 | #include 16 | #include 17 | 18 | simpleroutine telemetry_notification( 19 | RequestPort telemetry_port : mach_port_t; 20 | in flags : uint32_t); 21 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/XnuInternal/mach/vm_task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | ** This file contains compatibilty wrapper header for things that are 30 | ** generated from mach/vm_map.defs into mach/vm_map.h. 31 | ** 32 | ** This file will go away eventually - please switch. 33 | */ 34 | #include 35 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | } -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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(); -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/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) 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/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc 13 | ) 14 | endif() 15 | if(SYSTEM.Linux OR SYSTEM.Android) 16 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} 17 | ${CMAKE_CURRENT_SOURCE_DIR}/elf/dobby_symbol_resolver.cc 18 | 19 | ${DOBBY_DIR}/source/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc 20 | ) 21 | endif() 22 | if(SYSTEM.Windows) 23 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST} 24 | ${CMAKE_CURRENT_SOURCE_DIR}/pe/dobby_symbol_resolver.cc 25 | 26 | ${DOBBY_DIR}/source/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc 27 | ) 28 | endif() 29 | 30 | add_library(symbol_resolver STATIC 31 | ${SOURCE_FILE_LIST} 32 | ) 33 | 34 | include_directories( 35 | . 36 | ) 37 | 38 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/builtin-plugin/SymbolResolver/dobby_symbol_resolver.h: -------------------------------------------------------------------------------- 1 | #ifndef DOBBY_SYMBOL_RESOLVER_H 2 | #define DOBBY_SYMBOL_RESOLVER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | void *DobbySymbolResolver(const char *image_name, const char *symbol_name); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/cmake/AutoFiles.cmake: -------------------------------------------------------------------------------- 1 | function (AutoFiles _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 (folderFiles) 9 | foreach (_fname ${_files}) 10 | if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_fname}) 11 | AutoFiles ("${_fname}" "${_base}" "${_pattern}" "${_exclude}") 12 | elseif (_fname MATCHES ${_pattern}) 13 | if(_exclude) 14 | if (NOT _fname MATCHES ${_exclude}) 15 | set(folderFiles ${folderFiles} ${_fname}) 16 | endif () 17 | else () 18 | set(folderFiles ${folderFiles} ${_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 ${folderFiles}) 27 | else () 28 | source_group(${_base}\\${_folder2} FILES ${folderFiles}) 29 | endif () 30 | 31 | set(AUTO_FILES_RESULT ${AUTO_FILES_RESULT} ${folderFiles} PARENT_SCOPE) 32 | endfunction () -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/cmake/Macros.cmake: -------------------------------------------------------------------------------- 1 | macro(SET_OPTION option value) 2 | set(${option} ${value} CACHE INTERNAL "" FORCE) 3 | endmacro() -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/cmake/XcodeGenerator.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() -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/cpp/Dobby/docs/.nojekyll -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/_cover_page.md: -------------------------------------------------------------------------------- 1 | # Dobby beta 2 | 3 | > An exploit hook framework 4 | 5 | [GitHub](https://github.com/jmpews/dobby) 6 | [Get Started](#intro) 7 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/_nav_bar.md: -------------------------------------------------------------------------------- 1 | * [Release Note](https://github.com/jmpews/Dobby/commits/master) 2 | * [Download](https://github.com/jmpews/Dobby/releases/tag/latest) -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/_side_bar.md: -------------------------------------------------------------------------------- 1 | - [Home](/) 2 | - [Installation](build-documentation.md) 3 | - [Getting Started](get-started.md) 4 | - [Getting Started Within iOS](get-started-ios.md) 5 | - [Getting Started Within Android](get-started-android.md) 6 | - Setup 7 | - [Installation](build-documentation.md) 8 | - [Getting Started](get-started.md) 9 | - [Getting Started Within iOS](get-started-ios.md) 10 | - [Getting Started Within Android](get-started-android.md) 11 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/get-started-ios.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | ## add DobbyX.framework to your project 4 | 5 | ``` 6 | cmake .. -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_SYSTEM_PROCESSOR=arm64 -DCMAKE_OSX_DEPLOYMENT_TARGET=9.3 7 | 8 | ``` 9 | 10 | **drag the `DobbyX.xcodeproj` to your project** 11 | 12 | 13 | ## replace hook function 14 | 15 | ref source `builtin-plugin/ApplicationEventMonitor/dynamic_loader_monitor.cc` 16 | 17 | ref source `builtin-plugin/ApplicationEventMonitor/posix_file_descriptor_operation_monitor.cc` 18 | 19 | ## instrument function 20 | 21 | ref source `builtin-plugin/ApplicationEventMonitor/MGCopyAnswerMonitor.cc` 22 | 23 | ## replace pac function 24 | 25 | ``` 26 | void *posix_spawn_ptr = __builtin_ptrauth_strip((void *)posix_spawn, ptrauth_key_asia); 27 | void *fake_posix_spawn_ptr = __builtin_ptrauth_strip((void *)fake_posix_spawn, ptrauth_key_asia); 28 | 29 | DobbyHook((void *)posix_spawn_ptr, (void *)fake_posix_spawn_ptr, (void **)&orig_posix_spawn); 30 | 31 | *(void **)&orig_posix_spawn = (void *)ptrauth_sign_unauthenticated((void *)orig_posix_spawn, ptrauth_key_asia, 0); 32 | ``` 33 | 34 | 35 | ## objective-c toolkit 36 | 37 | invoke `DobbyOCReturnConstant("XXClass", "isVip", true);` will hook the objective-c instance/class method, and return the constant 1 automatically. 38 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/images/vue-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/cpp/Dobby/docs/images/vue-logo.png -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/intro-board.md: -------------------------------------------------------------------------------- 1 | # Intro 2 | 3 | a lightweight, multi-platform, multi-architecture exploit hook framework. 4 | 5 | **tips: any question [go to Telegram](https://t.me/dobby_group)** 6 | 7 | - Minimal and modular library 8 | - Multi-platform support(Windows/macOS/iOS/Android/Linux) 9 | - Multiple architecture support(X86-64, ARM, ARM64) 10 | - Clean code without STL(port to kernel easily) 11 | - Plugin support(DobbyDrill ?) 12 | - iOS kernel exploit support(Gollum ?) 13 | 14 | **[CHANGELOG]()** 15 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/scripts/palettify.styles.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * palettify v1.0.3 3 | * (c) 2018 Dobromir Hristov 4 | * Released under the MIT License. 5 | */ 6 | !function(o,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(o.palettifyStyles=o.palettifyStyles||{})}(this,function(o){"use strict";const t={opacities:[.2,.2],dynamic:{boxShadow:"0 2px 2px {{rgba.0}}, 0 4px 4px {{rgba.0}}, 0 8px 8px {{rgba.0}}, 0 16px 16px {{rgba.0}}, 0 32px 32px {{rgba.1}}, 0 64px 64px {{rgba.1}}"}},e={static:{border:"10px solid {{rgb.0}}",borderWidth:"10px"},dynamic:{borderWidth:"0px"}},r={opacities:[],static:{color:"{{rgb.0}}"}},i={opacities:[],static:{backgroundColor:"{{rgb.0}}",color:"{{ contrastColors.0 }}"}};o.boxShadow=t,o.border=e,o.diagonalBackground=r,o.zoomOutRight=i,Object.defineProperty(o,"__esModule",{value:!0})}); -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/docs/styles/style.css: -------------------------------------------------------------------------------- 1 | .image-list { 2 | list-style: none; 3 | display: flex; 4 | flex-flow: row wrap; 5 | margin: auto -15px !important; 6 | } 7 | 8 | .image-list .hoverTarget { 9 | flex: 0 0 33%; 10 | padding: 15px; 11 | } 12 | 13 | .image-list .imageTarget { 14 | transition: .3s linear 0s; 15 | display: block; 16 | height: auto; 17 | } 18 | 19 | .imageTarget { 20 | transition: .3s; 21 | } 22 | 23 | .attachTo { 24 | transition: .3s; 25 | display: block; 26 | } 27 | 28 | .image-on-background { 29 | height: 200px; 30 | background-size: cover; 31 | } 32 | 33 | .grid-margin-x-bottom > .cell { 34 | margin-bottom: 30px; 35 | } 36 | 37 | /* Docsify styles */ 38 | .sidebar-toggle { 39 | top: 0; 40 | bottom: auto; 41 | } 42 | 43 | .sidebar-toggle, body.close .sidebar-toggle span { 44 | background: #42b983; 45 | } 46 | 47 | .sidebar-toggle span { 48 | background: #ffffff; 49 | transition: .3s; 50 | } 51 | 52 | body.close .sidebar-toggle { 53 | transition: none; 54 | } 55 | 56 | body.close .sidebar-toggle span:first-of-type { 57 | transform: translate(0px, 4px) rotateZ(45deg); 58 | } 59 | 60 | body.close .sidebar-toggle span:nth-of-type(2) { 61 | transform: translate(0px, -2px) rotateZ(-45deg); 62 | } 63 | 64 | body.close .sidebar-toggle span:last-of-type { 65 | opacity: 0; 66 | transform: translateY(-8px); 67 | } 68 | 69 | @media screen and (max-width: 768px) { 70 | .hoverTarget { 71 | flex: 1 1 50%; 72 | } 73 | } 74 | 75 | @media screen and (min-width: 769px) { 76 | .sidebar-toggle { 77 | display: none; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(SYSTEM.Darwin) 2 | add_executable(darwin_example 3 | main.cc 4 | darwin_common_api.cc 5 | ) 6 | 7 | target_link_libraries(darwin_example 8 | DobbyX 9 | ) 10 | endif() 11 | 12 | if(SYSTEM.Android) 13 | add_executable(android_example 14 | main.cc 15 | android_common_api.cc 16 | ) 17 | 18 | target_link_libraries(android_example 19 | dobby 20 | ) 21 | endif() -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/example/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char const *argv[]) { 5 | 6 | std::cout << "Start..." << std::endl; 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/logging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | set(SOURCE_FILE_LIST 4 | ${CMAKE_CURRENT_SOURCE_DIR}/cxxlogging.cc 5 | ${CMAKE_CURRENT_SOURCE_DIR}/logging.c 6 | ) 7 | 8 | add_library(logging STATIC 9 | ${SOURCE_FILE_LIST} 10 | ${SOURCE_HEADER_LIST} 11 | ) -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/logging/cxxlogging.cc: -------------------------------------------------------------------------------- 1 | #include "logging/cxxlogging.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void Logger::setLogLevel(LogLevel level) { 9 | log_level_ = level; 10 | } 11 | 12 | void Logger::log(LogLevel level, const char *tag, const char *fmt, ...) { 13 | if (level > log_level_) { 14 | va_list ap; 15 | 16 | va_start(ap, fmt); 17 | vprintf(fmt, ap); 18 | va_end(ap); 19 | } 20 | } 21 | 22 | void Logger::LogFatal(const char *fmt, ...) { 23 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/logging/logging/cxxlogging.h: -------------------------------------------------------------------------------- 1 | #ifndef CXXLOGGING_H_ 2 | #define CXXLOGGING_H_ 3 | 4 | #include "logging.h" 5 | 6 | typedef enum { 7 | LOG_LEVEL_FATAL = 0, 8 | LOG_LEVEL_ERROR = 1, 9 | LOG_LEVEL_WARNING = 2, 10 | LOG_LEVEL_DEBUG = 3, 11 | LOG_LEVEL_VERBOSE = 4 12 | } LogLevel; 13 | 14 | class Logger { 15 | public: 16 | void setLogLevel(LogLevel level); 17 | 18 | void log(LogLevel level, const char *tag, const char *fmt, ...); 19 | 20 | void LogFatal(const char *fmt, ...); 21 | 22 | private: 23 | LogLevel log_level_; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/misc-helper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(.) 2 | 3 | set(SOURCE_FILE_LIST 4 | # memory cache database 5 | ${CMAKE_CURRENT_SOURCE_DIR}/variable_cache.c 6 | 7 | # async logger 8 | ${CMAKE_CURRENT_SOURCE_DIR}/async_logger.cc 9 | 10 | ${CMAKE_CURRENT_SOURCE_DIR}/pthread_helper.cc 11 | ) 12 | 13 | add_library(misc_helper STATIC 14 | ${SOURCE_FILE_LIST} 15 | ${SOURCE_HEADER_LIST} 16 | ) -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/misc-helper/misc-helper/variable_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIABLE_CACHE_H 2 | #define VARIABLE_CACHE_H 3 | 4 | #include 5 | #include 6 | 7 | #define cache_set stash 8 | void cache_set(const char *name, uint64_t value); 9 | 10 | #define cache_get(x) cache(x) 11 | #define assert_cache(x) (assert(cache(x)), cache(x)) 12 | uint64_t cache_get(const char *name); 13 | 14 | int serialized_to_file(const char *filepath); 15 | 16 | int unserialized_from_file(const char *filepath); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/misc-helper/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 | 12 | 13 | #define ssize_t int 14 | 15 | #define STDIN_FILENO 0 16 | #define STDOUT_FILENO 1 17 | #define STDERR_FILENO 2 18 | /* should be in some equivalent to */ 19 | typedef __int8 int8_t; 20 | typedef __int16 int16_t; 21 | typedef __int32 int32_t; 22 | typedef __int64 int64_t; 23 | typedef unsigned __int8 uint8_t; 24 | typedef unsigned __int16 uint16_t; 25 | typedef unsigned __int32 uint32_t; 26 | typedef unsigned __int64 uint64_t; 27 | 28 | #else 29 | 30 | #include 31 | 32 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(.) 3 | 4 | if(KERNELMODE) 5 | add_definitions(-DKERNELMODE) 6 | endif() 7 | 8 | set(xnucxx.SOURCE_FILE_LIST 9 | ${CMAKE_CURRENT_SOURCE_DIR}/LiteMemOpt.cc 10 | ${CMAKE_CURRENT_SOURCE_DIR}/LiteObject.cc 11 | ${CMAKE_CURRENT_SOURCE_DIR}/LiteIterator.cc 12 | ${CMAKE_CURRENT_SOURCE_DIR}/LiteCollection.cc 13 | ${CMAKE_CURRENT_SOURCE_DIR}/LiteMutableBuffer.cc 14 | ${CMAKE_CURRENT_SOURCE_DIR}/LiteMutableArray.cc 15 | ) 16 | 17 | add_library(xnucxx STATIC 18 | ${xnucxx.SOURCE_FILE_LIST} 19 | ) -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/LiteCollection.cc: -------------------------------------------------------------------------------- 1 | #include "xnucxx/LiteCollection.h" 2 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/LiteIterator.cc: -------------------------------------------------------------------------------- 1 | #include "xnucxx/LiteIterator.h" 2 | #include "xnucxx/LiteCollection.h" 3 | #include "xnucxx/LiteMemOpt.h" 4 | 5 | void LiteCollectionIterator::reset() { 6 | collection->initIterator(innerIterator); 7 | } 8 | 9 | bool LiteCollectionIterator::initWithCollection(const LiteCollectionInterface *inCollection) { 10 | int *ndxPtr = (int *)LiteMemOpt::alloc(sizeof(int)); 11 | innerIterator = (void *)ndxPtr; 12 | 13 | inCollection->initIterator(this->innerIterator); 14 | collection = inCollection; 15 | 16 | return true; 17 | } 18 | 19 | LiteObject *LiteCollectionIterator::getNextObject() { 20 | LiteObject *retObj; 21 | collection->getNextObjectForIterator(this->innerIterator, &retObj); 22 | return retObj; 23 | } 24 | 25 | void LiteCollectionIterator::release() { 26 | if (innerIterator) { 27 | LiteMemOpt::free(innerIterator, sizeof(int)); 28 | 29 | innerIterator = NULL; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/LiteMemOpt.cc: -------------------------------------------------------------------------------- 1 | #include "xnucxx/LiteMemOpt.h" 2 | #include 3 | #include 4 | 5 | #if 1 6 | void *_memcpy(void *dest, const void *src, int len) { 7 | return memcpy(dest, src, len); 8 | } 9 | 10 | void *_memset(void *dest, int ch, int count) { 11 | return memset(dest, ch, count); 12 | } 13 | #endif 14 | 15 | void *LiteMemOpt::alloc(int size) { 16 | void *result = malloc(size); 17 | return result; 18 | } 19 | 20 | void LiteMemOpt::free(void *address, int size) { 21 | return ::free(address); 22 | } 23 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/LiteMutableBuffer.cc: -------------------------------------------------------------------------------- 1 | #include "xnucxx/LiteMutableBuffer.h" 2 | #include "xnucxx/LiteMemOpt.h" 3 | 4 | bool LiteMutableBuffer::initWithCapacity(uint32_t initCapacity) { 5 | if (initCapacity <= 0) 6 | return false; 7 | 8 | this->buffer = (uint8_t *)LiteMemOpt::alloc(initCapacity); 9 | this->buffer_cursor = buffer; 10 | this->buffer_capacity = initCapacity; 11 | return true; 12 | } 13 | 14 | uint32_t LiteMutableBuffer::ensureCapacity(uint32_t newCapacity) { 15 | if (newCapacity <= buffer_capacity) 16 | return buffer_capacity; 17 | 18 | // or use step 19 | newCapacity = newCapacity + (uint32_t)newCapacity / 2; 20 | 21 | // alloc new buffer 22 | uint8_t *newBuffer; 23 | newBuffer = (uint8_t *)LiteMemOpt::alloc(newCapacity); 24 | if (newBuffer == nullptr) { 25 | return 0; 26 | } 27 | 28 | // clear buffer content 29 | _memset(newBuffer, 'A', newCapacity); 30 | 31 | // copy the origin content 32 | uint32_t originContentSize = (uint32_t)(buffer_cursor - buffer); 33 | _memcpy(newBuffer, buffer, originContentSize); 34 | 35 | // free the origin 36 | uint32_t originBufferSize = buffer_capacity; 37 | LiteMemOpt::free(buffer, originBufferSize); 38 | 39 | // update info 40 | this->buffer = newBuffer; 41 | this->buffer_cursor = newBuffer + originContentSize; 42 | this->buffer_capacity = newCapacity; 43 | 44 | return newCapacity; 45 | } 46 | 47 | void LiteMutableBuffer::release() { 48 | if (buffer != NULL) { 49 | uint32_t originBufferSize = buffer_capacity; 50 | LiteMemOpt::free(buffer, originBufferSize); 51 | 52 | buffer = NULL; 53 | } 54 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/LiteObject.cc: -------------------------------------------------------------------------------- 1 | #include "xnucxx/LiteObject.h" 2 | 3 | void LiteObject::free() { 4 | return; 5 | } 6 | 7 | void LiteObject::release() { 8 | return; 9 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/xnucxx/LiteCollection.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_COLLECTION_H 2 | #define LITE_COLLECTION_H 3 | 4 | #include "xnucxx/LiteObject.h" 5 | #include "xnucxx/LiteIterator.h" 6 | 7 | class LiteCollectionInterface : public LiteObject, public LiteIteratorInterface::Delegate { 8 | public: 9 | virtual unsigned int getCount() = 0; 10 | 11 | virtual unsigned int getCapacity() = 0; 12 | 13 | virtual unsigned int ensureCapacity(unsigned int newCapacity) = 0; 14 | 15 | virtual bool initIterator(void *iterator) const = 0; 16 | 17 | virtual bool getNextObjectForIterator(void *iterator, LiteObject **ret) const = 0; 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/xnucxx/LiteIterator.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_ITERATOR_H 2 | #define LITE_ITERATOR_H 3 | 4 | #include "xnucxx/LiteObject.h" 5 | 6 | class LiteIteratorInterface : public LiteObject { 7 | public: 8 | class Delegate { 9 | public: 10 | virtual bool initIterator(void *iterationContext) const = 0; 11 | 12 | virtual bool getNextObjectForIterator(void *iterationContext, LiteObject **nextObject) const = 0; 13 | }; 14 | 15 | public: 16 | virtual void reset() = 0; 17 | 18 | virtual LiteObject *getNextObject() = 0; 19 | }; 20 | 21 | class LiteCollectionInterface; 22 | class LiteCollectionIterator : public LiteIteratorInterface { 23 | protected: 24 | const LiteCollectionInterface *collection; 25 | 26 | void *innerIterator; 27 | 28 | public: 29 | explicit LiteCollectionIterator(const LiteCollectionInterface *collection) { 30 | initWithCollection(collection); 31 | } 32 | 33 | ~LiteCollectionIterator() { 34 | release(); 35 | } 36 | 37 | // === LiteObject override === 38 | void release() override; 39 | 40 | // === LiteIteratorInterface override === 41 | void reset() override; 42 | 43 | LiteObject *getNextObject() override; 44 | 45 | bool initWithCollection(const LiteCollectionInterface *collection); 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/xnucxx/LiteMemOpt.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_MEM_OPT_H 2 | #define LITE_MEM_OPT_H 3 | 4 | extern void *_memcpy(void *, const void *, int); 5 | 6 | extern void _bzero(void *, int); 7 | 8 | extern void *_memset(void *, int, int); 9 | 10 | class LiteMemOpt { 11 | public: 12 | static void *alloc(int size); 13 | 14 | static void free(void *address, int size); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/xnucxx/LiteMutableArray.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_MUTABLE_ARRAY_H 2 | #define LITE_MUTABLE_ARRAY_H 3 | 4 | #include "xnucxx/LiteCollection.h" 5 | #include "xnucxx/LiteIterator.h" 6 | 7 | class LiteMutableArray : public LiteCollectionInterface { 8 | protected: 9 | const LiteObject **array; 10 | 11 | unsigned int array_count; 12 | 13 | unsigned int array_capacity; 14 | 15 | public: 16 | explicit LiteMutableArray(int count); 17 | 18 | ~LiteMutableArray(); 19 | 20 | // === LiteObject override == 21 | void release() override; 22 | 23 | // === LiteCollectionInterface override == 24 | unsigned int getCount() override; 25 | 26 | unsigned int getCapacity() override; 27 | 28 | unsigned int ensureCapacity(unsigned int newCapacity) override; 29 | 30 | // === LiteIteratorInterface::Delegate override == 31 | bool initIterator(void *iterator) const override; 32 | 33 | bool getNextObjectForIterator(void *iterator, LiteObject **ret) const override; 34 | 35 | virtual LiteObject *getObject(unsigned int index); 36 | 37 | virtual bool pushObject(const LiteObject *object); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/xnucxx/LiteMutableBuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_MUTABLE_BUFFER_H 2 | #define LITE_MUTABLE_BUFFER_H 3 | 4 | #include "xnucxx/LiteObject.h" 5 | 6 | class LiteMutableBuffer : public LiteObject { 7 | protected: 8 | uint8_t *buffer; 9 | 10 | uint8_t *buffer_cursor; 11 | 12 | uint32_t buffer_capacity; 13 | 14 | public: 15 | LiteMutableBuffer() { 16 | initWithCapacity(8); 17 | } 18 | 19 | LiteMutableBuffer(uint32_t size) { 20 | initWithCapacity(size); 21 | } 22 | 23 | ~LiteMutableBuffer() { 24 | release(); 25 | } 26 | 27 | // === LiteObject override == 28 | void release() override; 29 | 30 | virtual bool initWithCapacity(uint32_t initCapacity); 31 | 32 | virtual uint32_t ensureCapacity(uint32_t newCapacity); 33 | 34 | virtual inline uint32_t getSize() { 35 | return (uint32_t)(buffer_cursor - buffer); 36 | } 37 | 38 | virtual inline uint32_t getCapacity() { 39 | return buffer_capacity; 40 | } 41 | 42 | virtual inline void *getCursor() { 43 | return buffer_cursor; 44 | } 45 | 46 | virtual inline void *getRawBuffer() { 47 | return buffer; 48 | } 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/external/xnucxx/xnucxx/LiteObject.h: -------------------------------------------------------------------------------- 1 | #ifndef LITE_OBJECT_H 2 | #define LITE_OBJECT_H 3 | 4 | #include "common_header.h" 5 | 6 | class LiteObject { 7 | public: 8 | virtual void free(); 9 | 10 | virtual void release(); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InstructionRelocation/InstructionRelocation.h: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | void GenRelocateCodeAndBranch(void *buffer, AssemblyCodeChunk *origin, AssemblyCodeChunk *relocated); 4 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InstructionRelocation/arm64/ARM64InstructionRelocation.h: -------------------------------------------------------------------------------- 1 | #ifndef INSTRUCTION_RELOCATION_ARM64_H 2 | #define INSTRUCTION_RELOCATION_ARM64_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/arch/arm64/constants-arm64.h" 7 | 8 | #if 0 9 | namespace zz { 10 | namespace arm64 { 11 | void GenRelocateCodeAndBranch(void *buffer, AssemblyCodeChunk *origin, AssemblyCodeChunk *relocated); 12 | } // namespace arm64 13 | } // namespace zz 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InstructionRelocation/arm64/ARM64PCLiteralInstructionTable.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by jmpews on 2019/1/26. 3 | // 4 | 5 | #ifndef ARM64_PC_LITERAL_INSTRUCTION_TABLE_H 6 | #define ARM64_PC_LITERAL_INSTRUCTION_TABLE_H 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InstructionRelocation/x64/X64InstructionRelocation.h: -------------------------------------------------------------------------------- 1 | #ifndef INSTRUCTION_RELOCATION_X64_H 2 | #define INSTRUCTION_RELOCATION_X64_H 3 | 4 | #include "common_header.h" 5 | 6 | #include "core/arch/x64/constants-x64.h" 7 | 8 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 9 | 10 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InstructionRelocation/x86/X86InstructionRelocation.h: -------------------------------------------------------------------------------- 1 | #ifndef INSTRUCTION_RELOCATION_X64_H 2 | #define INSTRUCTION_RELOCATION_X64_H 3 | 4 | #include "common_header.h" 5 | 6 | #include "core/arch/x86/constants-x86.h" 7 | 8 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 9 | 10 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/InterceptRouting.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERCEPT_ROUTING_H 2 | #define INTERCEPT_ROUTING_H 3 | 4 | #include "Interceptor.h" 5 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 6 | #include "InstructionRelocation/InstructionRelocation.h" 7 | #include "TrampolineBridge/Trampoline/Trampoline.h" 8 | 9 | class InterceptRouting { 10 | public: 11 | InterceptRouting(HookEntry *entry) : entry_(entry) { 12 | entry->route = this; 13 | 14 | trampoline_ = NULL; 15 | trampoline_buffer_ = NULL; 16 | trampoline_target_ = NULL; 17 | } 18 | 19 | virtual void DispatchRouting() = 0; 20 | 21 | virtual void Prepare(); 22 | 23 | virtual void Active(); 24 | 25 | void Commit(); 26 | 27 | HookEntry *GetHookEntry(); 28 | 29 | void SetTrampolineBuffer(CodeBufferBase *buffer) { 30 | trampoline_buffer_ = buffer; 31 | } 32 | 33 | CodeBufferBase *GetTrampolineBuffer() { 34 | return trampoline_buffer_; 35 | } 36 | 37 | void SetTrampolineTarget(void *address) { 38 | trampoline_target_ = address; 39 | } 40 | 41 | void *GetTrampolineTarget() { 42 | return trampoline_target_; 43 | } 44 | 45 | protected: 46 | bool GenerateRelocatedCode(int tramp_size); 47 | 48 | bool GenerateTrampolineBuffer(void *src, void *dst); 49 | 50 | protected: 51 | HookEntry *entry_; 52 | 53 | AssemblyCodeChunk *origin_; 54 | 55 | AssemblyCodeChunk *relocated_; 56 | 57 | AssemblyCodeChunk *trampoline_; 58 | 59 | // trampoline buffer before active 60 | CodeBufferBase *trampoline_buffer_; 61 | 62 | void *trampoline_target_; 63 | }; 64 | #endif 65 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/DynamicBinaryInstrument/DynamicBinaryInstrumentExport.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include "InterceptRouting/InterceptRouting.h" 4 | #include "InterceptRouting/Routing/DynamicBinaryInstrument/dynamic-binary-instrument.h" 5 | 6 | PUBLIC int DobbyInstrument(void *address, DBICallTy handler) { 7 | if (!address) { 8 | ERROR_LOG("the function address is 0x0.\n"); 9 | return RS_FAILED; 10 | } 11 | 12 | RAW_LOG(1, "\n\n"); 13 | DLOG(0, "[DobbyInstrument] Initialize at %p", address); 14 | 15 | // check if we already instruemnt 16 | HookEntry *entry = Interceptor::SharedInstance()->FindHookEntry(address); 17 | if (entry) { 18 | DynamicBinaryInstrumentRouting *route = (DynamicBinaryInstrumentRouting *)entry->route; 19 | if (route->handler == handler) { 20 | ERROR_LOG("instruction %s already been instrumented.", address); 21 | return RS_FAILED; 22 | } 23 | } 24 | 25 | entry = new HookEntry(); 26 | entry->id = Interceptor::SharedInstance()->GetHookEntryCount(); 27 | entry->type = kDynamicBinaryInstrument; 28 | entry->instruction_address = address; 29 | 30 | DynamicBinaryInstrumentRouting *route = new DynamicBinaryInstrumentRouting(entry, (void *)handler); 31 | route->Prepare(); 32 | route->DispatchRouting(); 33 | Interceptor::SharedInstance()->AddHookEntry(entry); 34 | route->Commit(); 35 | 36 | return RS_SUCCESS; 37 | } 38 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/DynamicBinaryInstrument/dynamic-binary-instrument.cc: -------------------------------------------------------------------------------- 1 | #include "InterceptRouting/Routing/DynamicBinaryInstrument/dynamic-binary-instrument.h" 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h" 6 | 7 | #include "InterceptRouting/Routing/DynamicBinaryInstrument/intercept_routing_handler.h" 8 | 9 | void DynamicBinaryInstrumentRouting::DispatchRouting() { 10 | BuildDynamicBinaryInstrumentRouting(); 11 | 12 | // generate relocated code which size == trampoline size 13 | GenerateRelocatedCode(trampoline_buffer_->getSize()); 14 | } 15 | 16 | // Add dbi_call handler before running the origin instructions 17 | void DynamicBinaryInstrumentRouting::BuildDynamicBinaryInstrumentRouting() { 18 | // create closure trampoline jump to prologue_routing_dispath with the `entry_` data 19 | ClosureTrampolineEntry *closure_trampoline; 20 | 21 | void *handler = (void *)instrument_routing_dispatch; 22 | #if __APPLE__ 23 | #if __has_feature(ptrauth_calls) 24 | handler = __builtin_ptrauth_strip(handler, ptrauth_key_asia); 25 | #endif 26 | #endif 27 | 28 | closure_trampoline = ClosureTrampoline::CreateClosureTrampoline(entry_, handler); 29 | this->SetTrampolineTarget(closure_trampoline->address); 30 | DLOG(0, "[closure bridge] Carry data %p ", entry_); 31 | DLOG(0, "[closure bridge] Create prologue_dispatch_bridge %p", closure_trampoline->address); 32 | 33 | // generate trampoline buffer, run before `GenerateRelocatedCode` 34 | GenerateTrampolineBuffer(entry_->target_address, GetTrampolineTarget()); 35 | } 36 | 37 | #if 0 38 | void *DynamicBinaryInstrumentRouting::GetTrampolineTarget() { 39 | return this->prologue_dispatch_bridge; 40 | } 41 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/DynamicBinaryInstrument/dynamic-binary-instrument.h: -------------------------------------------------------------------------------- 1 | #ifndef DYNAMIC_BINARY_INSTRUMENT_H 2 | #define DYNAMIC_BINARY_INSTRUMENT_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "Interceptor.h" 7 | 8 | #include "InterceptRouting/InterceptRouting.h" 9 | 10 | #include "TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h" 11 | 12 | #define X64InterceptRouting InterceptRouting 13 | #define ARM64InterceptRouting InterceptRouting 14 | 15 | class DynamicBinaryInstrumentRouting : public X64InterceptRouting { 16 | public: 17 | DynamicBinaryInstrumentRouting(HookEntry *entry, void *handler) : X64InterceptRouting(entry) { 18 | this->handler = handler; 19 | } 20 | 21 | void DispatchRouting(); 22 | 23 | public: 24 | void *handler; 25 | 26 | private: 27 | virtual void BuildDynamicBinaryInstrumentRouting(); 28 | 29 | private: 30 | void *prologue_dispatch_bridge; 31 | 32 | ; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/DynamicBinaryInstrument/intercept_routing_handler.cc: -------------------------------------------------------------------------------- 1 | #include "InterceptRouting/Routing/DynamicBinaryInstrument/intercept_routing_handler.h" 2 | 3 | #include "dobby_internal.h" 4 | 5 | #include "InterceptRouting/Routing/DynamicBinaryInstrument/dynamic-binary-instrument.h" 6 | 7 | #include "TrampolineBridge/ClosureTrampolineBridge/common-bridge-handler.h" 8 | 9 | void instrument_call_forward_handler(RegisterContext *ctx, HookEntry *entry) { 10 | DynamicBinaryInstrumentRouting *route = (DynamicBinaryInstrumentRouting *)entry->route; 11 | if (route->handler) { 12 | DBICallTy handler; 13 | HookEntryInfo entry_info; 14 | entry_info.hook_id = entry->id; 15 | entry_info.instruction_address = entry->instruction_address; 16 | handler = (DBICallTy)route->handler; 17 | (*handler)(ctx, (const HookEntryInfo *)&entry_info); 18 | } 19 | 20 | // set prologue bridge next hop address with origin instructions that have been relocated(patched) 21 | set_routing_bridge_next_hop(ctx, entry->relocated_origin_instructions); 22 | } 23 | 24 | void instrument_routing_dispatch(RegisterContext *ctx, ClosureTrampolineEntry *closure_trampoline_entry) { 25 | HookEntry *entry = (HookEntry *)closure_trampoline_entry->carry_data; 26 | instrument_call_forward_handler(ctx, entry); 27 | } 28 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/DynamicBinaryInstrument/intercept_routing_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERCEPT_ROUTING_HANDLER_H 2 | #define INTERCEPT_ROUTING_HANDLER_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h" 7 | 8 | extern "C" { 9 | void instrument_routing_dispatch(RegisterContext *ctx, ClosureTrampolineEntry *entry); 10 | } 11 | 12 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/FunctionInlineReplace/FunctionInlineReplaceExport.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include "Interceptor.h" 4 | #include "InterceptRouting/InterceptRouting.h" 5 | #include "InterceptRouting/Routing/FunctionInlineReplace/function-inline-replace.h" 6 | 7 | PUBLIC int DobbyHook(void *address, void *replace_call, void **origin_call) { 8 | if (!address) { 9 | ERROR_LOG("function address is 0x0"); 10 | return RS_FAILED; 11 | } 12 | 13 | DLOG(0, "[DobbyHook] Initialize at %p", address); 14 | 15 | // check if already hooked 16 | HookEntry *entry = Interceptor::SharedInstance()->FindHookEntry(address); 17 | if (entry) { 18 | FunctionInlineReplaceRouting *route = (FunctionInlineReplaceRouting *)entry->route; 19 | if (route->GetTrampolineTarget() == replace_call) { 20 | ERROR_LOG("function %p already been hooked.", address); 21 | return RS_FAILED; 22 | } 23 | } 24 | 25 | entry = new HookEntry(); 26 | entry->id = Interceptor::SharedInstance()->GetHookEntryCount(); 27 | entry->type = kFunctionInlineHook; 28 | entry->function_address = address; 29 | 30 | FunctionInlineReplaceRouting *route = new FunctionInlineReplaceRouting(entry, replace_call); 31 | route->Prepare(); 32 | route->DispatchRouting(); 33 | Interceptor::SharedInstance()->AddHookEntry(entry); 34 | 35 | // set origin call with relocated function 36 | *origin_call = entry->relocated_origin_function; 37 | 38 | // code patch & hijack original control flow entry 39 | route->Commit(); 40 | 41 | return RS_SUCCESS; 42 | } 43 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/FunctionInlineReplace/function-inline-replace.cc: -------------------------------------------------------------------------------- 1 | #include "InterceptRouting/Routing/FunctionInlineReplace/function-inline-replace.h" 2 | 3 | #include "dobby_internal.h" 4 | 5 | void FunctionInlineReplaceRouting::DispatchRouting() { 6 | BuildReplaceRouting(); 7 | 8 | // generate relocated code which size == trampoline size 9 | GenerateRelocatedCode(trampoline_buffer_->getSize()); 10 | } 11 | 12 | void FunctionInlineReplaceRouting::BuildReplaceRouting() { 13 | this->SetTrampolineTarget(this->replace_call); 14 | DLOG(0, "[inline] Set trampoline target => %p", GetTrampolineTarget()); 15 | 16 | // generate trampoline buffer, run before `GenerateRelocatedCode` 17 | GenerateTrampolineBuffer(entry_->target_address, GetTrampolineTarget()); 18 | } 19 | 20 | #if 0 21 | void *FunctionInlineReplaceRouting::GetTrampolineTarget() { 22 | return this->replace_call; 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/Routing/FunctionInlineReplace/function-inline-replace.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTION_INLINE_REPLACE_H 2 | #define FUNCTION_INLINE_REPLACE_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "InterceptRouting/InterceptRouting.h" 7 | #include "Interceptor.h" 8 | 9 | #include "TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h" 10 | 11 | class FunctionInlineReplaceRouting : public InterceptRouting { 12 | public: 13 | FunctionInlineReplaceRouting(HookEntry *entry, void *replace_call) : InterceptRouting(entry) { 14 | this->replace_call = replace_call; 15 | } 16 | 17 | void DispatchRouting() override; 18 | 19 | private: 20 | virtual void BuildReplaceRouting(); 21 | 22 | private: 23 | void *replace_call; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | HookEntry *entry = new HookEntry(); 16 | entry->id = interceptor->entries->getCount(); 17 | entry->type = kFunctionWrapper; 18 | entry->function_address = function_address; 19 | 20 | FunctionWrapperRouting *route = new FunctionWrapperRouting(entry); 21 | route->DispatchRouting(); 22 | interceptor->AddHookEntry(entry); 23 | route->Commit(); 24 | 25 | DLOG(0, "Finalize %p", function_address); 26 | return RS_SUCCESS; 27 | } 28 | -------------------------------------------------------------------------------- /module/src/main/cpp/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/AssemblyClosureTrampoline.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(HookEntry *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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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/AssemblyClosureTrampoline.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(RegisterContext *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(RegisterContext *ctx, ClosureTrampolineEntry *entry); 18 | 19 | void pre_call_forward_handler(RegisterContext *ctx, HookEntry *entry); 20 | 21 | void post_call_forward_handler(RegisterContext *ctx, HookEntry *entry); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif //__cplusplus 26 | 27 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/NearBranchTrampoline.h: -------------------------------------------------------------------------------- 1 | #ifndef PLUGIN_NEAR_BRANCH_TRAMPOLINE_H 2 | #define PLUGIN_NEAR_BRANCH_TRAMPOLINE_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 7 | 8 | class NearBranchTrampolinePlugin : public RoutingPluginInterface { 9 | // @Return: if false will continue to iter next plugin 10 | bool Prepare(InterceptRouting *routing) { 11 | return false; 12 | }; 13 | 14 | bool Active(InterceptRouting *routing); 15 | 16 | bool GenerateTrampolineBuffer(InterceptRouting *routing, void *src, void *dst); 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc: -------------------------------------------------------------------------------- 1 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 2 | 3 | LiteMutableArray *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 | if (RoutingPluginManager::plugins == NULL) { 11 | RoutingPluginManager::plugins = new LiteMutableArray(8); 12 | } 13 | 14 | RoutingPluginManager::plugins->pushObject(reinterpret_cast(plugin)); 15 | } 16 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/InterceptRouting/RoutingPlugin/RoutingPlugin.h: -------------------------------------------------------------------------------- 1 | #ifndef EXTRA_INTERNAL_PLUGIN_H 2 | #define EXTRA_INTERNAL_PLUGIN_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "InterceptRouting/InterceptRouting.h" 7 | 8 | class RoutingPluginInterface { 9 | public: 10 | // @Return: if false will continue to iter next plugin 11 | virtual bool Prepare(InterceptRouting *routing) = 0; 12 | 13 | // @Return: if false will continue to iter next plugin 14 | virtual bool Active(InterceptRouting *routing) = 0; 15 | 16 | // @Return: if false will continue to iter next plugin 17 | virtual bool GenerateTrampolineBuffer(InterceptRouting *routing, void *src, void *dst) = 0; 18 | 19 | private: 20 | char name_[256]; 21 | }; 22 | 23 | class RoutingPluginManager { 24 | public: 25 | static void registerPlugin(const char *name, RoutingPluginInterface *plugin); 26 | 27 | public: 28 | // global plugin array 29 | static LiteMutableArray *plugins; 30 | 31 | static RoutingPluginInterface *near_branch_trampoline; 32 | }; 33 | 34 | 35 | 36 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/Interceptor.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERCEPTOR_H 2 | #define INTERCEPTOR_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "include/list_structure.h" 7 | 8 | typedef struct { 9 | struct list_head list_node; 10 | HookEntry *entry; 11 | } HookEntryNode; 12 | 13 | class Interceptor { 14 | public: 15 | static Interceptor *SharedInstance(); 16 | 17 | HookEntry *FindHookEntry(void *address); 18 | 19 | void AddHookEntry(HookEntry *entry); 20 | 21 | void RemoveHookEntry(void *address); 22 | 23 | int GetHookEntryCount(); 24 | 25 | private: 26 | Interceptor() { 27 | } 28 | 29 | HookEntryNode *find_hook_entry_node(void *address); 30 | 31 | private: 32 | struct list_head hook_entry_list_; 33 | 34 | static Interceptor *priv_interceptor_; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/AssemblyCodeBuilder.h: -------------------------------------------------------------------------------- 1 | #ifndef MemoryAllocator_AssemblyCodeBuilder_h 2 | #define MemoryAllocator_AssemblyCodeBuilder_h 3 | 4 | #include "MemoryAllocator/MemoryArena.h" 5 | 6 | #include "core/modules/assembler/assembler.h" 7 | 8 | using namespace zz; 9 | 10 | class AssemblyCodeBuilder { 11 | public: 12 | // realize the buffer address to runtime code, and create a corresponding Code Object 13 | static AssemblyCodeChunk *FinalizeFromAddress(addr_t address, int size); 14 | 15 | // realize the buffer address to runtime code, and create a corresponding Code Object 16 | static AssemblyCodeChunk *FinalizeFromTurboAssembler(AssemblerBase *assembler); 17 | 18 | // inline void init_region_range(addr_t address, int size) { 19 | // code_range_.address = (void *)address; 20 | // code_range_.length = size; 21 | // } 22 | 23 | // inline void re_init_region_range(addr_t address, int size) { 24 | // this->init_region_range(address, size); 25 | // } 26 | 27 | // inline addr_t raw_instruction_start() { 28 | // return (addr_t)code_range_.address; 29 | // }; 30 | 31 | // inline int raw_instruction_size() { 32 | // return (int)code_range_.length; 33 | // }; 34 | 35 | private: 36 | // AssemblyCodeChunk code_range_; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/CodeBuffer/CodeBufferBase.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_BUFFER_BASE_H 2 | #define CODE_BUFFER_BASE_H 3 | 4 | #include "xnucxx/LiteMutableBuffer.h" 5 | 6 | class CodeBufferBase : public LiteMutableBuffer { 7 | public: 8 | CodeBufferBase() : LiteMutableBuffer() { 9 | } 10 | 11 | CodeBufferBase(int size) : LiteMutableBuffer(size) { 12 | } 13 | 14 | public: 15 | virtual CodeBufferBase *Copy(); 16 | 17 | void Emit8(uint8_t data); 18 | 19 | void Emit16(uint16_t data); 20 | 21 | void Emit32(uint32_t data); 22 | 23 | void Emit64(uint64_t data); 24 | 25 | void EmitBuffer(void *buffer, int len); 26 | 27 | void EmitObject(LiteObject *object); 28 | 29 | #if 0 // Template Advanced won't enable even in userspace 30 | template T Load(int offset); 31 | 32 | template void Store(int offset, T value); 33 | 34 | template void Emit(T value); 35 | #endif 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_BUFFER_ARM_H 2 | #define CODE_BUFFER_ARM_H 3 | 4 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 5 | 6 | typedef int32_t arm_inst_t; 7 | typedef int16_t thumb1_inst_t; 8 | typedef int32_t thumb2_inst_t; 9 | 10 | class CodeBuffer : public CodeBufferBase { 11 | enum ExecuteState { ARMExecuteState, ThumbExecuteState }; 12 | 13 | public: 14 | CodeBuffer() : CodeBufferBase() { 15 | } 16 | 17 | CodeBuffer(int size) : CodeBufferBase(size) { 18 | } 19 | 20 | public: 21 | arm_inst_t LoadARMInst(int offset); 22 | 23 | thumb1_inst_t LoadThumb1Inst(int offset); 24 | 25 | thumb2_inst_t LoadThumb2Inst(int offset); 26 | 27 | void RewriteAddr(int offset, addr32_t addr); 28 | 29 | void RewriteARMInst(int offset, arm_inst_t instr); 30 | 31 | void RewriteThumb1Inst(int offset, thumb1_inst_t instr); 32 | 33 | void RewriteThumb2Inst(int offset, thumb2_inst_t instr); 34 | 35 | void EmitARMInst(arm_inst_t instr); 36 | 37 | void EmitThumb1Inst(thumb1_inst_t instr); 38 | 39 | void EmitThumb2Inst(thumb2_inst_t instr); 40 | 41 | void Emit32(int32_t data); 42 | }; 43 | 44 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM64) 3 | 4 | #include "MemoryAllocator/CodeBuffer/code-buffer-arm64.h" 5 | 6 | arm64_inst_t CodeBuffer::LoadInst(int offset) { 7 | return *reinterpret_cast(buffer + offset); 8 | } 9 | 10 | void CodeBuffer::FixBindLabel(int offset, arm64_inst_t instr) { 11 | *reinterpret_cast(buffer + offset) = instr; 12 | return; 13 | } 14 | 15 | void CodeBuffer::EmitInst(arm64_inst_t instr) { 16 | ensureCapacity(getSize() + sizeof(arm64_inst_t)); 17 | *reinterpret_cast(getCursor()) = instr; 18 | buffer_cursor += sizeof(arm64_inst_t); 19 | return; 20 | } 21 | 22 | void CodeBuffer::Emit64(int64_t data) { 23 | ensureCapacity(getSize() + sizeof(int64_t)); 24 | *reinterpret_cast(getCursor()) = data; 25 | buffer_cursor += sizeof(int64_t); 26 | return; 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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 | CodeBuffer(int size) : CodeBufferBase(size) { 15 | } 16 | 17 | public: 18 | arm64_inst_t LoadInst(int offset); 19 | 20 | void FixBindLabel(int offset, arm64_inst_t instr); 21 | 22 | void EmitInst(arm64_inst_t instr); 23 | 24 | void Emit64(int64_t data); 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "MemoryAllocator/CodeBuffer/code-buffer-x64.h" 5 | 6 | void CodeBuffer::Emit32(int32_t data) { 7 | ensureCapacity(getSize() + sizeof(int32_t)); 8 | *reinterpret_cast(getCursor()) = data; 9 | buffer_cursor += sizeof(int32_t); 10 | return; 11 | } 12 | 13 | void CodeBuffer::Emit64(int64_t data) { 14 | ensureCapacity(getSize() + sizeof(int64_t)); 15 | *reinterpret_cast(getCursor()) = data; 16 | buffer_cursor += sizeof(int64_t); 17 | return; 18 | } 19 | 20 | void CodeBuffer::FixBindLabel(int offset, int32_t disp) { 21 | *reinterpret_cast(buffer + offset) = disp; 22 | return; 23 | } 24 | 25 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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 | CodeBuffer(int size) : CodeBufferBase(size) { 12 | } 13 | 14 | public: 15 | void FixBindLabel(int offset, int32_t disp); 16 | 17 | void Emit32(int32_t data); 18 | 19 | void Emit64(int64_t data); 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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(getSize() + 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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/CodeBuffer/code-buffer-x86.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_BUFFER_X86_H 2 | #define CODE_BUFFER_X86_H 3 | 4 | #include "MemoryAllocator/CodeBuffer/CodeBufferBase.h" 5 | 6 | class CodeBuffer : public CodeBufferBase { 7 | public: 8 | CodeBuffer() : CodeBufferBase() { 9 | } 10 | 11 | CodeBuffer(int size) : CodeBufferBase(size) { 12 | } 13 | 14 | public: 15 | void FixBindLabel(int offset, int32_t disp); 16 | 17 | void Emit32(int32_t data); 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/MemoryArena.h: -------------------------------------------------------------------------------- 1 | #ifndef MemoryAllocator_MemoryArena_h 2 | #define MemoryAllocator_MemoryArena_h 3 | 4 | #include "xnucxx/LiteMutableArray.h" 5 | 6 | #include "PlatformUnifiedInterface/StdMemory.h" 7 | 8 | struct MemoryChunk : MemoryRange { 9 | inline void init_region_range(addr_t address, size_t size) { 10 | this->address = (void *)address; 11 | this->length = size; 12 | } 13 | 14 | inline void re_init_region_range(addr_t address, int size) { 15 | init_region_range(address, size); 16 | } 17 | 18 | inline void re_init_region_range(MemoryChunk *chunk) { 19 | init_region_range((addr_t)chunk->address, chunk->length); 20 | } 21 | 22 | inline addr_t raw_instruction_start() { 23 | return (addr_t)address; 24 | }; 25 | 26 | inline size_t raw_instruction_size() { 27 | return length; 28 | }; 29 | }; 30 | 31 | typedef MemoryChunk AssemblyCodeChunk, WritableDataChunk; 32 | 33 | typedef struct { 34 | MemoryChunk page; 35 | addr_t page_cursor; 36 | MemoryPermission permission; 37 | LiteMutableArray *chunks; 38 | } PageChunk; 39 | 40 | class MemoryArena { 41 | public: 42 | static MemoryChunk *AllocateChunk(int alloc_size, MemoryPermission permission); 43 | 44 | static WritableDataChunk *AllocateDataChunk(int alloc_size); 45 | 46 | static AssemblyCodeChunk *AllocateCodeChunk(int alloc_size); 47 | 48 | static void Destroy(MemoryChunk *chunk); 49 | 50 | public: 51 | static LiteMutableArray *page_chunks; 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/MemoryAllocator/NearMemoryArena.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MemoryAllocator_NearMemoryArena_h 3 | #define MemoryAllocator_NearMemoryArena_h 4 | 5 | #include "MemoryAllocator/MemoryArena.h" 6 | 7 | class NearMemoryArena : public MemoryArena { 8 | public: 9 | NearMemoryArena(); 10 | 11 | static MemoryChunk *AllocateChunk(addr_t position, size_t alloc_range, int alloc_size, MemoryPermission permission); 12 | 13 | static WritableDataChunk *AllocateDataChunk(addr_t position, size_t alloc_range, int alloc_size); 14 | 15 | static AssemblyCodeChunk *AllocateCodeChunk(addr_t position, size_t alloc_range, int alloc_size); 16 | 17 | static int PushPage(addr_t page_addr, MemoryPermission permission); 18 | 19 | static void Destroy(MemoryChunk *chunk); 20 | 21 | private: 22 | static LiteMutableArray *page_chunks; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/PlatformUnifiedInterface/ExecMemory/CodePatchTool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef PLATFORM_INTERFACE_CODE_PATCH_TOOL_H 3 | #define PLATFORM_INTERFACE_CODE_PATCH_TOOL_H 4 | 5 | #include "PlatformUnifiedInterface/StdMemory.h" 6 | 7 | MemoryOperationError CodePatch(void *address, uint8_t *buffer, uint32_t buffer_size); 8 | 9 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/PlatformUnifiedInterface/StdMemory.h: -------------------------------------------------------------------------------- 1 | #ifndef UNIFIED_INTERFACE_STD_MEMORY_H 2 | #define UNIFIED_INTERFACE_STD_MEMORY_H 3 | 4 | #include "common_header.h" 5 | 6 | enum MemoryPermission { kNoAccess, kRead, kReadWrite, kReadWriteExecute, kReadExecute }; 7 | 8 | typedef struct _MemoryRange { 9 | void *address; 10 | size_t length; 11 | } MemoryRange; 12 | 13 | typedef struct _MemoryRegion { 14 | void *address; 15 | size_t length; 16 | MemoryPermission permission; 17 | } MemoryRegion; 18 | 19 | typedef MemoryRegion MemoryPage; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h: -------------------------------------------------------------------------------- 1 | #ifndef ASSEMBLY_CLOSURE_TRAMPOLINE_H 2 | #define ASSEMBLY_CLOSURE_TRAMPOLINE_H 3 | 4 | #include "dobby_internal.h" 5 | 6 | #ifdef ENABLE_CLOSURE_TRAMPOLINE_TEMPLATE 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif //__cplusplus 10 | void closure_trampoline_template(); 11 | void closure_bridge_template(); 12 | #ifdef __cplusplus 13 | } 14 | #endif //__cplusplus 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif //__cplusplus 20 | 21 | typedef struct _ClosureTrampolineEntry { 22 | void *address; 23 | int size; 24 | void *carry_handler; 25 | void *carry_data; 26 | } ClosureTrampolineEntry; 27 | 28 | void *get_closure_bridge(); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif //__cplusplus 33 | 34 | class ClosureTrampoline { 35 | private: 36 | static LiteMutableArray *trampolines_; 37 | 38 | public: 39 | static ClosureTrampolineEntry *CreateClosureTrampoline(void *carry_data, void *carry_handler); 40 | }; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /module/src/main/cpp/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/AssemblyClosureTrampoline.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 -------------------------------------------------------------------------------- /module/src/main/cpp/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(RegisterContext *ctx, void *address) { 7 | *reinterpret_cast(&ctx->general.regs.r12) = address; 8 | } 9 | 10 | void get_routing_bridge_next_hop(RegisterContext *ctx, void *address) { 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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/AssemblyClosureTrampoline.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 -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/helper-arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM64) 3 | 4 | #include "core/modules/assembler/assembler-arm64.h" 5 | 6 | #include "dobby_internal.h" 7 | 8 | using namespace zz::arm64; 9 | 10 | void set_routing_bridge_next_hop(RegisterContext *ctx, void *address) { 11 | *reinterpret_cast(&ctx->general.x[TMP_REG_0.code()]) = address; 12 | } 13 | 14 | void get_routing_bridge_next_hop(RegisterContext *ctx, void *address) { 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/common-bridge-handler.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "logging/logging.h" 3 | 4 | #include "TrampolineBridge/ClosureTrampolineBridge/common-bridge-handler.h" 5 | 6 | PUBLIC void intercept_routing_common_bridge_handler(RegisterContext *ctx, ClosureTrampolineEntry *entry) { 7 | DLOG(0, "Catch common bridge handler, carry data: %p, carry handler: %p", (HookEntry *)entry->carry_data, 8 | entry->carry_handler); 9 | 10 | typedef void (*intercept_routing_handler_t)(RegisterContext * ctx, ClosureTrampolineEntry * entry); 11 | intercept_routing_handler_t routing_handler = (intercept_routing_handler_t)entry->carry_handler; 12 | 13 | #if __APPLE__ 14 | #if __has_feature(ptrauth_calls) 15 | routing_handler = 16 | (typeof(routing_handler))__builtin_ptrauth_sign_unauthenticated((void *)routing_handler, ptrauth_key_asia, 0); 17 | #endif 18 | #endif 19 | 20 | routing_handler(ctx, entry); 21 | return; 22 | } 23 | -------------------------------------------------------------------------------- /module/src/main/cpp/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/AssemblyClosureTrampoline.h" 8 | 9 | extern "C" { 10 | void intercept_routing_common_bridge_handler(RegisterContext *ctx, ClosureTrampolineEntry *entry); 11 | } 12 | 13 | void get_routing_bridge_next_hop(RegisterContext *ctx, void *address); 14 | 15 | void set_routing_bridge_next_hop(RegisterContext *ctx, void *address); 16 | 17 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x64/X64AssemblyClosureTrampoline.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/modules/assembler/assembler-x64.h" 7 | 8 | #include "TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h" 9 | 10 | using namespace zz; 11 | using namespace zz::x64; 12 | 13 | ClosureTrampolineEntry *ClosureTrampoline::CreateClosureTrampoline(void *carry_data, void *carry_handler) { 14 | ClosureTrampolineEntry *entry = nullptr; 15 | entry = new ClosureTrampolineEntry; 16 | 17 | AssemblyCodeChunk *cchunk = MemoryArena::AllocateCodeChunk(32); 18 | if (cchunk == nullptr) { 19 | return NULL; 20 | } 21 | #define _ turbo_assembler_. 22 | #define __ turbo_assembler_.GetCodeBuffer()-> 23 | TurboAssembler turbo_assembler_(0); 24 | 25 | char *push_rip_6 = (char *)"\xff\x35\x06\x00\x00\x00"; 26 | char *jmp_rip_8 = (char *)"\xff\x25\x08\x00\x00\x00"; 27 | 28 | __ EmitBuffer(push_rip_6, 6); 29 | __ EmitBuffer(jmp_rip_8, 6); 30 | __ Emit64((uint64_t)entry); 31 | __ Emit64((uint64_t)get_closure_bridge()); 32 | 33 | entry->address = (void *)cchunk->raw_instruction_start(); 34 | entry->size = cchunk->raw_instruction_size(); 35 | entry->carry_data = carry_data; 36 | entry->carry_handler = carry_handler; 37 | 38 | CodeBufferBase *buffer = reinterpret_cast(turbo_assembler_.GetCodeBuffer()); 39 | CodePatch(cchunk->address, (uint8_t *)buffer->getRawBuffer(), buffer->getSize()); 40 | 41 | return entry; 42 | } 43 | 44 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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(RegisterContext *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(RegisterContext *ctx, void *address) { 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/TrampolineBridge/ClosureTrampolineBridge/x86/X86AssemblyClosureTrampoline.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/modules/assembler/assembler-ia32.h" 7 | 8 | #include "TrampolineBridge/ClosureTrampolineBridge/AssemblyClosureTrampoline.h" 9 | 10 | using namespace zz; 11 | using namespace zz::x86; 12 | 13 | ClosureTrampolineEntry *ClosureTrampoline::CreateClosureTrampoline(void *carry_data, void *carry_handler) { 14 | ClosureTrampolineEntry *entry = nullptr; 15 | entry = new ClosureTrampolineEntry; 16 | 17 | AssemblyCodeChunk *cchunk = MemoryArena::AllocateCodeChunk(32); 18 | if (cchunk == nullptr) { 19 | return NULL; 20 | } 21 | 22 | #define _ turbo_assembler_. 23 | #define __ turbo_assembler_.GetCodeBuffer()-> 24 | TurboAssembler turbo_assembler_(cchunk->address); 25 | 26 | int32_t offset = (int32_t)get_closure_bridge() - ((int32_t)cchunk->address + 18); 27 | 28 | _ sub(esp, Immediate(4, 32)); 29 | _ mov(Address(esp, 4 * 0), Immediate((int32_t)entry, 32)); 30 | _ jmp(Immediate(offset, 32)); 31 | 32 | entry->address = (void *)cchunk->raw_instruction_start(); 33 | entry->size = cchunk->raw_instruction_size(); 34 | entry->carry_data = carry_data; 35 | entry->carry_handler = carry_handler; 36 | 37 | CodeBufferBase *buffer = reinterpret_cast(turbo_assembler_.GetCodeBuffer()); 38 | CodePatch(cchunk->address, (uint8_t *)buffer->getRawBuffer(), buffer->getSize()); 39 | 40 | return entry; 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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(RegisterContext *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(RegisterContext *ctx, void *address) { 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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); -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/TrampolineBridge/Trampoline/x64/trampoline-x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "dobby_internal.h" 5 | 6 | #include "core/modules/assembler/assembler-x64.h" 7 | #include "core/modules/codegen/codegen-x64.h" 8 | 9 | #include "InstructionRelocation/x64/X64InstructionRelocation.h" 10 | 11 | #include "MemoryAllocator/NearMemoryArena.h" 12 | #include "InterceptRouting/RoutingPlugin/RoutingPlugin.h" 13 | 14 | using namespace zz::x64; 15 | 16 | static void **AllocIndirectStub(addr_t branch_address) { 17 | WritableDataChunk *forwardStub = NULL; 18 | 19 | forwardStub = 20 | NearMemoryArena::AllocateDataChunk((addr_t)branch_address, (size_t)2 * 1024 * 1024 * 1024, (int)sizeof(void *)); 21 | if (forwardStub == nullptr) { 22 | ERROR_LOG("Not found near forward stub"); 23 | return NULL; 24 | } 25 | 26 | return (void **)forwardStub->address; 27 | } 28 | 29 | CodeBufferBase *GenerateNormalTrampolineBuffer(addr_t from, addr_t to) { 30 | TurboAssembler turbo_assembler_((void *)from); 31 | #define _ turbo_assembler_. 32 | 33 | // branch 34 | void **branch_stub = AllocIndirectStub(from); 35 | *branch_stub = (void *)to; 36 | 37 | CodeGen codegen(&turbo_assembler_); 38 | codegen.JmpNearIndirect((uint64_t)branch_stub); 39 | 40 | CodeBufferBase *result = NULL; 41 | result = turbo_assembler_.GetCodeBuffer()->Copy(); 42 | return result; 43 | } 44 | 45 | CodeBufferBase *GenerateNearTrampolineBuffer(InterceptRouting *routing, addr_t src, addr_t dst) { 46 | DLOG(0, "x64 near branch trampoline enable default"); 47 | return NULL; 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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/modules/assembler/assembler-ia32.h" 7 | #include "core/modules/codegen/codegen-ia32.h" 8 | 9 | #include "InstructionRelocation/x86/X86InstructionRelocation.h" 10 | 11 | #include "MemoryAllocator/NearMemoryArena.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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/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 CodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) { 11 | 12 | int page_size = (int)sysconf(_SC_PAGESIZE); 13 | uintptr_t page_align_address = ALIGN_FLOOR(address, page_size); 14 | int offset = (uintptr_t)address - page_align_address; 15 | 16 | #if defined(__ANDROID__) || defined(__linux__) 17 | 18 | // change page permission as rwx 19 | mprotect((void *)page_align_address, page_size, PROT_READ | PROT_WRITE | PROT_EXEC); 20 | 21 | // patch buffer 22 | memcpy((void *)((addr_t)page_align_address + offset), buffer, buffer_size); 23 | 24 | // restore page permission 25 | mprotect((void *)page_align_address, page_size, PROT_READ | PROT_EXEC); 26 | #endif 27 | 28 | addr_t clear_start_ = (addr_t)page_align_address + offset; 29 | ClearCache((void *)clear_start_, (void *)(clear_start_ + buffer_size)); 30 | 31 | return kMemoryOperationSuccess; 32 | } 33 | 34 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/UserMode/ExecMemory/code-patch-tool-windows.cc: -------------------------------------------------------------------------------- 1 | #include "dobby_internal.h" 2 | 3 | #include 4 | 5 | using namespace zz; 6 | 7 | PUBLIC MemoryOperationError CodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) { 8 | DWORD oldProtect; 9 | int pageSize; 10 | 11 | // Get page size 12 | SYSTEM_INFO si; 13 | GetSystemInfo(&si); 14 | pageSize = si.dwPageSize; 15 | 16 | void *addressPageAlign = (void *)ALIGN(address, pageSize); 17 | 18 | if (!VirtualProtect(addressPageAlign, pageSize, PAGE_EXECUTE_READWRITE, &oldProtect)) 19 | return kMemoryOperationError; 20 | 21 | memcpy(address, buffer, buffer_size); 22 | 23 | if (!VirtualProtect(addressPageAlign, pageSize, oldProtect, &oldProtect)) 24 | return kMemoryOperationError; 25 | 26 | return kMemoryOperationSuccess; 27 | } 28 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/UserMode/PlatformUtil/ProcessRuntimeUtility.h: -------------------------------------------------------------------------------- 1 | #ifndef GET_PROCESS_MODULE_MAP_H 2 | #define GET_PROCESS_MODULE_MAP_H 3 | 4 | #include "PlatformUnifiedInterface/StdMemory.h" 5 | 6 | #include 7 | #include 8 | 9 | typedef struct _RuntimeModule { 10 | char path[1024]; 11 | void *load_address; 12 | } RuntimeModule; 13 | 14 | class ProcessRuntimeUtility { 15 | public: 16 | // ================================================================ 17 | // Process Memory 18 | 19 | static std::vector GetProcessMemoryLayout(); 20 | 21 | // ================================================================ 22 | // Process Module 23 | 24 | static std::vector GetProcessModuleMap(); 25 | 26 | static RuntimeModule GetProcessModule(const char *name); 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | } -------------------------------------------------------------------------------- /module/src/main/cpp/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, int 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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | } -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/arch/arm/constants-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_ARCH_CONSTANTS_ARM_H 2 | #define CORE_ARCH_CONSTANTS_ARM_H 3 | 4 | enum AddrMode { Offset = 0, PreIndex = 1, PostIndex = 2 }; 5 | 6 | enum Condition { 7 | EQ = 0, // equal 8 | NE = 1, // not equal 9 | CS = 2, // carry set/unsigned higher or same 10 | CC = 3, // carry clear/unsigned lower 11 | MI = 4, // minus/negative 12 | PL = 5, // plus/positive or zero 13 | VS = 6, // overflow 14 | VC = 7, // no overflow 15 | HI = 8, // unsigned higher 16 | LS = 9, // unsigned lower or same 17 | GE = 10, // signed greater than or equal 18 | LT = 11, // signed less than 19 | GT = 12, // signed greater than 20 | LE = 13, // signed less than or equal 21 | AL = 14, // always (unconditional) 22 | 23 | }; 24 | 25 | enum Shift { 26 | LSL = 0, // Logical shift left 27 | LSR = 1, // Logical shift right 28 | ASR = 2, // Arithmetic shift right 29 | ROR = 3, // Rotate right 30 | }; 31 | 32 | enum { 33 | B0 = 1 << 0, 34 | B4 = 1 << 4, 35 | B5 = 1 << 5, 36 | B6 = 1 << 6, 37 | B7 = 1 << 7, 38 | B8 = 1 << 8, 39 | B9 = 1 << 9, 40 | B10 = 1 << 10, 41 | B12 = 1 << 12, 42 | B14 = 1 << 14, 43 | B15 = 1 << 15, 44 | B16 = 1 << 16, 45 | B17 = 1 << 17, 46 | B18 = 1 << 18, 47 | B19 = 1 << 19, 48 | B20 = 1 << 20, 49 | B21 = 1 << 21, 50 | B22 = 1 << 22, 51 | B23 = 1 << 23, 52 | B24 = 1 << 24, 53 | B25 = 1 << 25, 54 | B26 = 1 << 26, 55 | B27 = 1 << 27, 56 | B28 = 1 << 28, 57 | }; 58 | 59 | enum InstructionFields { 60 | // Registers. 61 | kRdShift = 12, 62 | kRtShift = 12, 63 | kRmShift = 10, 64 | kRnShift = 16, 65 | 66 | // Condition 67 | kConditionShift = 28, 68 | }; 69 | 70 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/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 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/assembler/assembler-arm.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if TARGET_ARCH_ARM 3 | 4 | #include "core/modules/assembler/assembler-arm.h" 5 | 6 | namespace zz { 7 | namespace arm { 8 | 9 | void Assembler::EmitARMInst(arm_inst_t instr) { 10 | buffer_->EmitARMInst(instr); 11 | } 12 | 13 | void Assembler::EmitAddress(uint32_t value) { 14 | buffer_->Emit32(value); 15 | } 16 | 17 | } // namespace arm 18 | } // namespace zz 19 | 20 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/assembler/assembler-ia32.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if TARGET_ARCH_IA32 3 | 4 | #include "core/modules/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_address_; 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/assembler/assembler-x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "core/modules/assembler/assembler-x64.h" 5 | 6 | using namespace zz::x64; 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_address_; 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/assembler/assembler-x86-shared.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_IA32) 3 | 4 | #include "core/modules/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_address_; 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-arm.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM) 3 | 4 | #include "core/modules/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-arm.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_ARM_H 2 | #define CORE_CODEGEN_ARM_H 3 | 4 | #include "core/modules/codegen/codegen.h" 5 | #include "core/modules/assembler/assembler.h" 6 | #include "core/modules/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-arm64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_ARM64) 3 | 4 | #include "dobby_internal.h" 5 | #include "core/modules/codegen/codegen-arm64.h" 6 | 7 | namespace zz { 8 | namespace arm64 { 9 | 10 | void CodeGen::LiteralLdrBranch(uint64_t address) { 11 | TurboAssembler *turbo_assembler_ = reinterpret_cast(this->assembler_); 12 | #define _ turbo_assembler_-> 13 | PseudoLabel address_ptr; 14 | 15 | _ Ldr(TMP_REG_0, &address_ptr); 16 | _ br(TMP_REG_0); 17 | _ PseudoBind(&address_ptr); 18 | _ EmitInt64(address); 19 | } 20 | 21 | } // namespace arm64 22 | } // namespace zz 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-arm64.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_ARM64_H 2 | #define CORE_CODEGEN_ARM64_H 3 | 4 | #include "core/modules/codegen/codegen.h" 5 | #include "core/modules/assembler/assembler.h" 6 | #include "core/modules/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-ia32.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_IA32) 3 | 4 | #include "core/modules/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 | dword offset = (dword)(address - currIP); 15 | 16 | __ Emit8(0xe9); 17 | __ Emit32(offset); 18 | } 19 | 20 | } // namespace x86 21 | } // namespace zz 22 | 23 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-ia32.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_X86_H 2 | #define CORE_CODEGEN_X86_H 3 | 4 | #include "core/modules/codegen/codegen.h" 5 | #include "core/modules/assembler/assembler.h" 6 | #include "core/modules/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-x64.cc: -------------------------------------------------------------------------------- 1 | #include "platform_macro.h" 2 | #if defined(TARGET_ARCH_X64) 3 | 4 | #include "core/modules/codegen/codegen-x64.h" 5 | 6 | namespace zz { 7 | namespace x64 { 8 | 9 | void CodeGen::JmpNearIndirect(uint64_t address) { 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 | dword offset = (dword)(address - currIP); 15 | 16 | // RIP-relative addressing 17 | __ Emit8(0xFF); 18 | __ Emit8(0x25); 19 | __ Emit32(offset); 20 | } 21 | 22 | } // namespace x64 23 | } // namespace zz 24 | 25 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen-x64.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_X64_H 2 | #define CORE_CODEGEN_X64_H 3 | 4 | #include "core/modules/codegen/codegen.h" 5 | #include "core/modules/assembler/assembler.h" 6 | #include "core/modules/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(uint64_t address); 17 | }; 18 | 19 | } // namespace x64 20 | } // namespace zz 21 | 22 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/codegen/codegen.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_CODEGEN_H 2 | #define CORE_CODEGEN_H 3 | 4 | #include "core/modules/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 -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/core/modules/emulator/dummy.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/cpp/Dobby/source/core/modules/emulator/dummy.cc -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/dobby.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__linux__) || defined(__APPLE__) 2 | #include 3 | #include 4 | 5 | #include "dobby_internal.h" 6 | 7 | #include "Interceptor.h" 8 | 9 | __attribute__((constructor)) static void ctor() { 10 | DLOG(-1, "================================"); 11 | DLOG(-1, "Dobby"); 12 | DLOG(-1, "================================"); 13 | 14 | DLOG(-1, "dobby in debug log mode, disable with cmake flag \"-DDOBBY_DEBUG=OFF\""); 15 | } 16 | 17 | PUBLIC const char *DobbyBuildVersion() { 18 | return __DOBBY_BUILD_VERSION__; 19 | } 20 | 21 | PUBLIC int DobbyDestroy(void *address) { 22 | // check if we already hook 23 | HookEntry *entry = Interceptor::SharedInstance()->FindHookEntry(address); 24 | if (entry) { 25 | uint8_t *buffer = entry->origin_chunk_.chunk_buffer; 26 | uint32_t buffer_size = entry->origin_chunk_.chunk.length; 27 | #if defined(TARGET_ARCH_ARM) 28 | address = (void *)((addr_t)address - 1); 29 | #endif 30 | CodePatch(address, buffer, buffer_size); 31 | Interceptor::SharedInstance()->RemoveHookEntry(address); 32 | return RT_SUCCESS; 33 | } 34 | 35 | return RT_FAILED; 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/dobby_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef DOBBY_INTERNAL_H 2 | #define DOBBY_INTERNAL_H 3 | 4 | #include "dobby.h" 5 | 6 | #include "logging/logging.h" 7 | #include "logging/check_logging.h" 8 | 9 | #include "xnucxx/LiteMemOpt.h" 10 | #include "xnucxx/LiteMutableArray.h" 11 | #include "xnucxx/LiteMutableBuffer.h" 12 | #include "xnucxx/LiteIterator.h" 13 | 14 | #include "UnifiedInterface/platform.h" 15 | 16 | #include "PlatformUnifiedInterface/StdMemory.h" 17 | #include "PlatformUnifiedInterface/ExecMemory/CodePatchTool.h" 18 | #include "PlatformUnifiedInterface/ExecMemory/ClearCacheTool.h" 19 | 20 | #include "MemoryAllocator/MemoryArena.h" 21 | #include "MemoryAllocator/AssemblyCodeBuilder.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | typedef struct _AssemblyCodeChunkBuffer { 30 | AssemblyCodeChunk chunk; 31 | uint8_t chunk_buffer[64]; 32 | } AssemblyCodeChunkBuffer; 33 | 34 | typedef enum { kFunctionWrapper, kFunctionInlineHook, kDynamicBinaryInstrument } HookEntryType; 35 | 36 | typedef struct { 37 | int id; 38 | int type; 39 | 40 | union { 41 | void *target_address; 42 | void *function_address; 43 | void *instruction_address; 44 | }; 45 | 46 | void *route; 47 | 48 | // fixed-instructions which we relocated(patched) 49 | union { 50 | void *relocated_origin_instructions; 51 | void *relocated_origin_function; 52 | }; 53 | 54 | AssemblyCodeChunkBuffer origin_chunk_; 55 | } HookEntry; 56 | 57 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/include/common_header.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_HEADER_H 2 | #define COMMON_HEADER_H 3 | 4 | #include "include/type_macro.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" 10 | 11 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/include/platform_macro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_M_X64) || defined(__x86_64__) 4 | #define TARGET_ARCH_X64 1 5 | #elif defined(_M_IX86) || defined(__i386__) 6 | #define TARGET_ARCH_IA32 1 7 | #elif defined(__AARCH64EL__) 8 | #define TARGET_ARCH_ARM64 1 9 | #elif defined(__ARMEL__) 10 | #define TARGET_ARCH_ARM 1 11 | #elif defined(__mips64) 12 | #define TARGET_ARCH_MIPS64 1 13 | #elif defined(__MIPSEB__) || defined(__MIPSEL__) 14 | #define TARGET_ARCH_MIPS 1 15 | #elif defined(_ARCH_PPC) 16 | #define TARGET_ARCH_PPC 1 17 | #else 18 | #error Target architecture was not detected as supported by Dobby 19 | #endif 20 | -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/source/include/type_macro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifndef __addr_32_64_t_defined 6 | #define __addr_32_64_t_defined 7 | typedef uint32_t addr32_t; 8 | typedef uint64_t addr64_t; 9 | #endif 10 | 11 | #ifndef __addr_t_defined 12 | #define __addr_t_defined 13 | typedef uintptr_t addr_t; 14 | #endif 15 | 16 | #ifndef __byte_defined 17 | #define __byte_defined 18 | typedef unsigned char byte_t; 19 | #endif 20 | 21 | #ifndef __uint_defined 22 | #define __uint_defined 23 | typedef unsigned int uint; 24 | #endif 25 | 26 | #ifndef __word_defined 27 | #define __word_defined 28 | typedef short word; 29 | #endif 30 | 31 | #ifndef __dword_defined 32 | #define __dword_defined 33 | typedef int dword; 34 | #endif 35 | 36 | #ifndef NULL 37 | #define NULL 0 38 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/tests/CMakelists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(test_dobby) 3 | 4 | set(PrimaryPath ..) 5 | 6 | include(${PrimaryPath}/cmake/Globals.cmake) 7 | include(${PrimaryPath}/cmake/Macros.cmake) 8 | 9 | set(CMAKE_CXX_STANDARD 11) 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 11 | set(CMAKE_C_STANDARD 11) 12 | enable_language(ASM) 13 | 14 | 15 | include_directories( 16 | ${PrimaryPath}/tests 17 | ${PrimaryPath}/source 18 | ) 19 | 20 | include_directories( 21 | ${PrimaryPath}/source 22 | ${PrimaryPath}/source/UserMode 23 | ${PrimaryPath}/external 24 | ${PrimaryPath}/external/logging 25 | ${PrimaryPath}/external/xnucxx 26 | ) 27 | 28 | add_subdirectory(${PrimaryPath} dobby.out) 29 | 30 | add_executable(tests_instr_relo_x64 31 | ${PrimaryPath}/source/InstructionRelocation/x64/X64IPRelativeOpcodeTable.cc 32 | ${PrimaryPath}/tests/InstructionRelocation/x64/test_x64_instruction_relocation.cc 33 | ) 34 | 35 | add_executable(tests_instr_relo_aarch64 36 | ${PrimaryPath}/tests/InstructionRelocation/aarch64/test_aarch64_instruction_relocation.cc 37 | ) 38 | target_link_libraries(tests_instr_relo_aarch64 39 | dobby 40 | ) -------------------------------------------------------------------------------- /module/src/main/cpp/Dobby/tests/InstructionRelocation/aarch64/test_aarch64_instruction_relocation.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #if defined(__WIN32__) || defined(__APPLE__) 5 | #define xcdecl(s) "_" s 6 | #else 7 | #define xcdecl(s) s 8 | #endif 9 | 10 | #define xASM(x) __asm(x) 11 | 12 | __attribute__((naked)) void pc_relative_instructions() { 13 | xASM("ldr x0, #4"); 14 | xASM("nop"); 15 | xASM("nop"); 16 | 17 | xASM("nop"); 18 | xASM("nop"); 19 | xASM("ldr x0, #-4"); 20 | 21 | xASM("adr x0, #4"); 22 | 23 | xASM("adrp x0, #0x1000"); 24 | 25 | xASM("tbz x0, #8, #4"); 26 | 27 | xASM("tbz x0, #27, #-4"); 28 | 29 | xASM("cbz x0, #4"); 30 | 31 | xASM("cbz x0, #-4"); 32 | 33 | xASM("cmp x0, x0"); 34 | xASM("b.eq #-4"); 35 | } 36 | 37 | __attribute__((naked)) void pc_relative_instructions_end() { 38 | } 39 | 40 | #include "InstructionRelocation/arm64/ARM64InstructionRelocation.h" 41 | 42 | extern zz::AssemblyCode *GenRelocateCodeAndBranch(void *buffer, int *relocate_size, addr_t from_pc, addr_t to_pc); 43 | 44 | extern "C" { 45 | int _main(int argc, const char **argv); 46 | } 47 | 48 | int _main(int argc, const char **argv) { 49 | LOG(1, "pc_relative_instructions: %p", pc_relative_instructions); 50 | 51 | char *relo_buffer = (char *)malloc(0x1000); 52 | 53 | int relo_size = (uint64_t)pc_relative_instructions_end - (uint64_t)pc_relative_instructions; 54 | zz::AssemblyCode *code = GenRelocateCodeAndBranch((void *)pc_relative_instructions, &relo_size, 0, 0); 55 | 56 | unsigned char *instruction_bytes = (unsigned char *)code->raw_instruction_start(); 57 | for (int i = 0; i < code->raw_instruction_size(); i += 1) { 58 | printf("%.2x ", instruction_bytes[i]); 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /module/src/main/cpp/Hooking/Hooks.h: -------------------------------------------------------------------------------- 1 | #ifndef HOOKS 2 | #define HOOKS 3 | namespace Hooks // place your hooks in this file to keep everything neat and tidy 4 | { 5 | 6 | } 7 | #endif HOOKS -------------------------------------------------------------------------------- /module/src/main/cpp/ImGui/ImGui_mod.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | void displayKeyboard(bool pShow); -------------------------------------------------------------------------------- /module/src/main/cpp/Memory/KittyArm64.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace KittyArm64 8 | { 9 | 10 | int32_t bit_from(uint32_t insn, int pos); 11 | 12 | int32_t bits_from(uint32_t insn, int pos, int l); 13 | 14 | bool is_insn_adr(uint32_t insn); 15 | 16 | bool is_insn_adrp(uint32_t insn); 17 | 18 | bool decode_adr_imm(uint32_t insn, int64_t *imm); 19 | 20 | int32_t decode_addsub_imm(uint32_t insn); 21 | 22 | bool is_insn_ld(uint32_t insn); 23 | 24 | bool is_insn_ldst(uint32_t insn); 25 | 26 | bool is_insn_ldst_uimm(uint32_t insn); 27 | 28 | bool decode_ldrstr_uimm(uint32_t insn, int32_t *offset); 29 | 30 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Memory/KittyScanner.cpp: -------------------------------------------------------------------------------- 1 | #include "KittyScanner.h" 2 | 3 | #include "KittyMemory.h" 4 | 5 | using KittyMemory::ProcMap; 6 | 7 | // refs 8 | // https://github.com/learn-more/findpattern-bench 9 | 10 | namespace KittyScanner 11 | { 12 | 13 | bool compare(const char *data, const char *pattern, const char *mask) 14 | { 15 | for (; *mask; ++mask, ++data, ++pattern) 16 | { 17 | if (*mask == 'x' && *data != *pattern) 18 | return false; 19 | } 20 | 21 | return !*mask; 22 | } 23 | 24 | uintptr_t find(const uintptr_t start, const size_t size, const char *pattern, const char *mask) 25 | { 26 | for (size_t i = 0; i < size; ++i) 27 | { 28 | if (!compare(reinterpret_cast(start + i), pattern, mask)) 29 | continue; 30 | 31 | return start + i; 32 | } 33 | return 0; 34 | } 35 | 36 | uintptr_t find_from_lib(const char *name, const char *pattern, const char *mask) 37 | { 38 | if (!name || !pattern || !mask) 39 | return 0; 40 | 41 | ProcMap libMap = KittyMemory::getLibraryMap(name); 42 | if(!libMap.isValid()) return 0; 43 | 44 | return find((uintptr_t)libMap.startAddr, (size_t)libMap.length, pattern, mask); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Memory/KittyScanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace KittyScanner 7 | { 8 | 9 | bool compare(const char *data, const char *pattern, const char *mask); 10 | 11 | uintptr_t find(const uintptr_t start, const size_t size, const char *pattern, const char *mask); 12 | 13 | uintptr_t find_from_lib(const char *name, const char *pattern, const char *mask); 14 | 15 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Memory/KittyUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace KittyUtils { 7 | 8 | bool validateHexString(std::string &xstr); 9 | void toHex(void *const data, const size_t dataLength, std::string &dest); 10 | void fromHex(const std::string &in, void *const data); 11 | 12 | } -------------------------------------------------------------------------------- /module/src/main/cpp/Memory/MemoryBackup.h: -------------------------------------------------------------------------------- 1 | // 2 | // MemoryBackup.h 3 | // 4 | // Created by MJ (Ruit) on 4/19/20. 5 | // 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #include "KittyMemory.h" 12 | 13 | class MemoryBackup 14 | { 15 | private: 16 | uintptr_t _address; 17 | size_t _size; 18 | 19 | std::vector _orig_code; 20 | 21 | std::string _hexString; 22 | 23 | public: 24 | MemoryBackup(); 25 | 26 | /* 27 | * expects library name and relative address 28 | */ 29 | MemoryBackup(const char *libraryName, uintptr_t address, size_t backup_size, bool useMapCache = true); 30 | 31 | /* 32 | * expects absolute address 33 | */ 34 | MemoryBackup(uintptr_t absolute_address, size_t backup_size); 35 | 36 | ~MemoryBackup(); 37 | 38 | /* 39 | * Validate patch 40 | */ 41 | bool isValid() const; 42 | 43 | size_t get_BackupSize() const; 44 | 45 | /* 46 | * Returns pointer to the target address 47 | */ 48 | uintptr_t get_TargetAddress() const; 49 | 50 | /* 51 | * Restores backup code 52 | */ 53 | bool Restore(); 54 | 55 | /* 56 | * Returns current target address bytes as hex string 57 | */ 58 | std::string get_CurrBytes(); 59 | }; 60 | -------------------------------------------------------------------------------- /module/src/main/cpp/Misc/ESP.h: -------------------------------------------------------------------------------- 1 | #ifndef ImGuiAndroid_ESP 2 | #define ImGuiAndroid_ESP 3 | 4 | #include "../ImGui/imgui_internal.h" 5 | 6 | namespace ESP { 7 | void DrawLine(ImVec2 start, ImVec2 end, ImVec4 color) { 8 | auto background = ImGui::GetBackgroundDrawList(); 9 | if(background) { 10 | background->AddLine(start, end, ImColor(color.x,color.y,color.z,color.w)); 11 | } 12 | } 13 | void DrawBox(ImVec4 rect, ImVec4 color) { 14 | ImVec2 v1(rect.x, rect.y); 15 | ImVec2 v2(rect.x + rect.z, rect.y); 16 | ImVec2 v3(rect.x + rect.z, rect.y + rect.w); 17 | ImVec2 v4(rect.x, rect.y + rect.w); 18 | 19 | DrawLine(v1, v2, color); 20 | DrawLine(v2, v3, color); 21 | DrawLine(v3, v4, color); 22 | DrawLine(v4, v1, color); 23 | } 24 | void DrawCircle(float X, float Y, float radius, bool filled, ImVec4 color) { 25 | auto background = ImGui::GetBackgroundDrawList(); 26 | if(background) { 27 | if(filled) { 28 | background->AddCircleFilled(ImVec2(X, Y), radius, ImColor(color.x,color.y,color.z,color.w)); 29 | } else { 30 | background->AddCircle(ImVec2(X, Y), radius, ImColor(color.x,color.y,color.z,color.w)); 31 | } 32 | } 33 | } 34 | void DrawText(ImVec2 position, ImVec4 color, const char *text) { 35 | auto background = ImGui::GetBackgroundDrawList(); 36 | if(background) { 37 | background->AddText(NULL, 25.0f, position, ImColor(color.x,color.y,color.z,color.w), text); 38 | } 39 | } 40 | } 41 | 42 | #endif ImGuiAndroid_ESP -------------------------------------------------------------------------------- /module/src/main/cpp/Misc/FunctionPointers.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by letha on 9/4/2021. 3 | // 4 | 5 | #ifndef IMGUIANDROID_FUNCTIONPOINTERS_H 6 | #define IMGUIANDROID_FUNCTIONPOINTERS_H 7 | using namespace BNM::UNITY_STRUCTS; 8 | namespace Pointers 9 | { 10 | 11 | void * (*GameObject_get_transform)(void *instance); 12 | 13 | Vector3 (*Transform_get_position)(void *instance); 14 | 15 | Vector3 (*Camera_WorldToScreenPoint)(void *instance, Vector3 worldPosition); 16 | 17 | void *(*Camera_get_main)(); 18 | 19 | //DWORD PlayerScript_correctPlayerPos; 20 | void LoadPointers() 21 | { 22 | GameObject_get_transform = 23 | *(void *(*)(void *)) OBFUSCATE_BYNAME_METHOD("UnityEngine", "GameObject", 24 | "get_transform", 0); 25 | Transform_get_position = 26 | *(Vector3 (*)(void *)) OBFUSCATE_BYNAME_METHOD("UnityEngine", "Transform", 27 | "get_position", 0); 28 | Camera_WorldToScreenPoint = 29 | *(Vector3 (*)(void *, Vector3)) OBFUSCATE_BYNAME_METHOD("UnityEngine", "Camera", 30 | "WorldToScreenPoint", 1); 31 | Camera_get_main = 32 | *(void *(*)()) OBFUSCATE_BYNAME_METHOD("UnityEngine", "Camera", 33 | "get_main", 0); 34 | 35 | //PlayerScript_correctPlayerPos = OBFUSCATE_BYNAME_FIELD("", "PlayerScript", "position"); 36 | } 37 | } 38 | #endif IMGUIANDROID_FUNCTIONPOINTERS_H 39 | -------------------------------------------------------------------------------- /module/src/main/cpp/Misc/Logging.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by letha on 8/13/2021. 3 | // 4 | 5 | #ifndef IMGUIANDROID_LOGGING_H 6 | #define IMGUIANDROID_LOGGING_H 7 | 8 | #include "android/log.h" 9 | enum LogType { 10 | DEBUG = 3, 11 | ERROR = 6, 12 | INFO = 4, 13 | WARN = 5 14 | }; 15 | 16 | #define TAG "ImGUI" 17 | 18 | #define LOGD(...) ((void)__android_log_print(DEBUG, TAG, __VA_ARGS__)) 19 | #define LOGE(...) ((void)__android_log_print(ERROR, TAG, __VA_ARGS__)) 20 | #define LOGI(...) ((void)__android_log_print(INFO, TAG, __VA_ARGS__)) 21 | #define LOGW(...) ((void)__android_log_print(WARN, TAG, __VA_ARGS__)) 22 | 23 | #endif //IMGUIANDROID_LOGGING_H 24 | -------------------------------------------------------------------------------- /module/src/main/cpp/Obfuscation/Custom_Obfuscate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Admin on 19.08.2021. 3 | // 4 | 5 | #ifndef IMGUIANDROID_CUSTOM_OBFUSCATE_H 6 | #define IMGUIANDROID_CUSTOM_OBFUSCATE_H 7 | // remember to use the macros to protect offsets from static analysis 8 | #include "instr.h" 9 | #define OBFUSCATE_OFFSET(data) getRealOffset(string2Offset(STRING_OBFUSCATE_KEY(data, STRING_OBFUSCATE_DEFAULT_KEY))) 10 | 11 | #define OBFUSCATE_BYNAME_METHOD(namespaze, classname, methodname, paramcount) \ 12 | LoadClass(STRING_OBFUSCATE_KEY(namespaze, STRING_OBFUSCATE_DEFAULT_KEY).operator char *(), STRING_OBFUSCATE_KEY(classname, STRING_OBFUSCATE_DEFAULT_KEY).operator char *()).GetMethodOffsetByName(STRING_OBFUSCATE_KEY(methodname, STRING_OBFUSCATE_DEFAULT_KEY).operator char *(), N(paramcount)) 13 | #define OBFUSCATE_BYNAME_CLASS(namespaze, classname) \ 14 | LoadClass(STRING_OBFUSCATE_KEY(namespaze, STRING_OBFUSCATE_DEFAULT_KEY).operator char *(), STRING_OBFUSCATE_KEY(classname, STRING_OBFUSCATE_DEFAULT_KEY).operator char *()) 15 | #define OBFUSCATE_BYNAME_FIELD(namespaze, classname, fieldname) \ 16 | LoadClass(STRING_OBFUSCATE_KEY(namespaze, STRING_OBFUSCATE_DEFAULT_KEY).operator char *(), STRING_OBFUSCATE_KEY(classname, STRING_OBFUSCATE_DEFAULT_KEY).operator char *()).GetFieldOffset(STRING_OBFUSCATE_KEY(fieldname, STRING_OBFUSCATE_DEFAULT_KEY).operator char *()) 17 | #endif //IMGUIANDROID_CUSTOM_OBFUSCATE_H 18 | -------------------------------------------------------------------------------- /module/src/main/cpp/Obfuscation/instr.cpp: -------------------------------------------------------------------------------- 1 | #include "instr.h" // this was from fritzones obfy I have no idea why its empty but include it in cmake anyway -------------------------------------------------------------------------------- /module/src/main/cpp/game.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Perfare on 2020/7/4. 3 | // 4 | 5 | #ifndef RIRU_IL2CPPDUMPER_GAME_H 6 | #define RIRU_IL2CPPDUMPER_GAME_H 7 | 8 | #define GamePackageName "com.pixel.gun3d" 9 | 10 | #endif //RIRU_IL2CPPDUMPER_GAME_H 11 | -------------------------------------------------------------------------------- /module/src/main/cpp/hook.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Perfare on 2020/7/4. 3 | // 4 | 5 | #ifndef RIRU_IL2CPPDUMPER_HOOK_H 6 | #define RIRU_IL2CPPDUMPER_HOOK_H 7 | 8 | #include 9 | #include "log.h" 10 | 11 | static int enable_hack; 12 | static void *il2cpp_handle = NULL; 13 | static char *game_data_dir = NULL; 14 | 15 | int isGame(JNIEnv *env, jstring appDataDir); 16 | 17 | void *hack_thread(void *arg); 18 | 19 | #define HOOK_DEF(ret, func, ...) \ 20 | ret (*orig_##func)(__VA_ARGS__); \ 21 | ret new_##func(__VA_ARGS__) 22 | 23 | #endif //RIRU_IL2CPPDUMPER_HOOK_H 24 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/async.cpp: -------------------------------------------------------------------------------- 1 | #include "async.h" 2 | 3 | namespace cpr { 4 | 5 | CPR_SINGLETON_IMPL(GlobalThreadPool) 6 | 7 | } // namespace cpr 8 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/async.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_ASYNC_H 2 | #define CPR_ASYNC_H 3 | 4 | #include "singleton.h" 5 | #include "threadpool.h" 6 | 7 | namespace cpr { 8 | 9 | class GlobalThreadPool : public ThreadPool { 10 | CPR_SINGLETON_DECL(GlobalThreadPool) 11 | protected: 12 | GlobalThreadPool() : ThreadPool() {} 13 | ~GlobalThreadPool() {} 14 | }; 15 | 16 | /** 17 | * Return a future, calling future.get() will wait task done and return RetType. 18 | * async(fn, args...) 19 | * async(std::bind(&Class::mem_fn, &obj)) 20 | * async(std::mem_fn(&Class::mem_fn, &obj)) 21 | **/ 22 | template 23 | auto async(Fn&& fn, Args&&... args) -> std::future { 24 | return GlobalThreadPool::GetInstance()->Submit(std::forward(fn), std::forward(args)...); 25 | } 26 | 27 | class async { 28 | public: 29 | static void startup(size_t min_threads = CPR_DEFAULT_THREAD_POOL_MIN_THREAD_NUM, 30 | size_t max_threads = CPR_DEFAULT_THREAD_POOL_MAX_THREAD_NUM, 31 | std::chrono::milliseconds max_idle_ms = CPR_DEFAULT_THREAD_POOL_MAX_IDLE_TIME) { 32 | GlobalThreadPool* gtp = GlobalThreadPool::GetInstance(); 33 | if (gtp->IsStarted()) return; 34 | gtp->SetMinThreadNum(min_threads); 35 | gtp->SetMaxThreadNum(max_threads); 36 | gtp->SetMaxIdleTime(max_idle_ms); 37 | gtp->Start(); 38 | } 39 | 40 | static void cleanup() { 41 | GlobalThreadPool::ExitInstance(); 42 | } 43 | }; 44 | 45 | } // namespace cpr 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/auth.cpp: -------------------------------------------------------------------------------- 1 | #include "auth.h" 2 | 3 | namespace cpr { 4 | const char* Authentication::GetAuthString() const noexcept { 5 | return auth_string_.c_str(); 6 | } 7 | 8 | AuthMode Authentication::GetAuthMode() const noexcept { 9 | return auth_mode_; 10 | } 11 | } // namespace cpr 12 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/auth.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_AUTH_H 2 | #define CPR_AUTH_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace cpr { 9 | 10 | enum class AuthMode { BASIC, DIGEST, NTLM }; 11 | 12 | class Authentication { 13 | public: 14 | Authentication(const std::string& username, const std::string& password, const AuthMode& auth_mode) : auth_string_{username + ":" + password}, auth_mode_{auth_mode} {} 15 | Authentication(std::string&& username, std::string&& password, const AuthMode&& auth_mode) : auth_string_{std::move(username) + ":" + std::move(password)}, auth_mode_{std::move(auth_mode)} {} 16 | Authentication(const Authentication& other) = default; 17 | Authentication(Authentication&& old) noexcept = default; 18 | ~Authentication() noexcept = default; 19 | 20 | Authentication& operator=(Authentication&& old) noexcept = default; 21 | Authentication& operator=(const Authentication& other) = default; 22 | 23 | const char* GetAuthString() const noexcept; 24 | AuthMode GetAuthMode() const noexcept; 25 | 26 | private: 27 | std::string auth_string_; 28 | AuthMode auth_mode_; 29 | }; 30 | 31 | } // namespace cpr 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/bearer.cpp: -------------------------------------------------------------------------------- 1 | #include "bearer.h" 2 | 3 | namespace cpr { 4 | // Only supported with libcurl >= 7.61.0. 5 | // As an alternative use SetHeader and add the token manually. 6 | #if LIBCURL_VERSION_NUM >= 0x073D00 7 | const char* Bearer::GetToken() const noexcept { 8 | return token_string_.c_str(); 9 | } 10 | #endif 11 | } // namespace cpr 12 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/bearer.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_BEARER_H 2 | #define CPR_BEARER_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace cpr { 9 | 10 | // Only supported with libcurl >= 7.61.0. 11 | // As an alternative use SetHeader and add the token manually. 12 | #if LIBCURL_VERSION_NUM >= 0x073D00 13 | class Bearer { 14 | public: 15 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 16 | Bearer(const std::string& token) : token_string_{token} {} 17 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 18 | Bearer(std::string&& token) : token_string_{std::move(token)} {} 19 | Bearer(const Bearer& other) = default; 20 | Bearer(Bearer&& old) noexcept = default; 21 | virtual ~Bearer() noexcept = default; 22 | 23 | Bearer& operator=(Bearer&& old) noexcept = default; 24 | Bearer& operator=(const Bearer& other) = default; 25 | 26 | virtual const char* GetToken() const noexcept; 27 | 28 | protected: 29 | std::string token_string_; 30 | }; 31 | #endif 32 | 33 | } // namespace cpr 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/body.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_BODY_H 2 | #define CPR_BODY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "cprtypes.h" 8 | 9 | namespace cpr { 10 | 11 | class Body : public StringHolder { 12 | public: 13 | Body() : StringHolder() {} 14 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 15 | Body(const std::string& body) : StringHolder(body) {} 16 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 17 | Body(std::string&& body) : StringHolder(std::move(body)) {} 18 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 19 | Body(const char* body) : StringHolder(body) {} 20 | Body(const char* str, size_t len) : StringHolder(str, len) {} 21 | Body(const std::initializer_list args) : StringHolder(args) {} 22 | Body(const Body& other) = default; 23 | Body(Body&& old) noexcept = default; 24 | ~Body() override = default; 25 | 26 | Body& operator=(Body&& old) noexcept = default; 27 | Body& operator=(const Body& other) = default; 28 | }; 29 | 30 | } // namespace cpr 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/connect_timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_CONNECT_TIMEOUT_H 2 | #define CPR_CONNECT_TIMEOUT_H 3 | 4 | #include "timeout.h" 5 | 6 | namespace cpr { 7 | 8 | class ConnectTimeout : public Timeout { 9 | public: 10 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 11 | ConnectTimeout(const std::chrono::milliseconds& duration) : Timeout{duration} {} 12 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 13 | ConnectTimeout(const std::int32_t& milliseconds) : Timeout{milliseconds} {} 14 | }; 15 | 16 | } // namespace cpr 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/cookies.cpp: -------------------------------------------------------------------------------- 1 | #include "cookies.h" 2 | 3 | namespace cpr { 4 | std::string Cookies::GetEncoded(const CurlHolder& holder) const { 5 | std::stringstream stream; 6 | for (const std::pair& item : map_) { 7 | // Depending on if encoding is set to "true", we will URL-encode cookies 8 | stream << (encode ? holder.urlEncode(item.first) : item.first) << "="; 9 | 10 | // special case version 1 cookies, which can be distinguished by 11 | // beginning and trailing quotes 12 | if (!item.second.empty() && item.second.front() == '"' && item.second.back() == '"') { 13 | stream << item.second; 14 | } else { 15 | // Depending on if encoding is set to "true", we will URL-encode cookies 16 | stream << (encode ? holder.urlEncode(item.second) : item.second); 17 | } 18 | stream << "; "; 19 | } 20 | return stream.str(); 21 | } 22 | 23 | std::string& Cookies::operator[](const std::string& key) { 24 | return map_[key]; 25 | } 26 | 27 | Cookies::iterator Cookies::begin() { 28 | return map_.begin(); 29 | } 30 | 31 | Cookies::iterator Cookies::end() { 32 | return map_.end(); 33 | } 34 | 35 | Cookies::const_iterator Cookies::begin() const { 36 | return map_.begin(); 37 | } 38 | 39 | Cookies::const_iterator Cookies::end() const { 40 | return map_.end(); 41 | } 42 | 43 | Cookies::const_iterator Cookies::cbegin() const { 44 | return map_.cbegin(); 45 | } 46 | 47 | Cookies::const_iterator Cookies::cend() const { 48 | return map_.cend(); 49 | } 50 | 51 | } // namespace cpr 52 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/cpr.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_CPR_H 2 | #define CPR_CPR_H 3 | 4 | #include "api.h" 5 | #include "auth.h" 6 | #include "bearer.h" 7 | #include "callback.h" 8 | #include "connect_timeout.h" 9 | #include "cookies.h" 10 | #include "cprtypes.h" 11 | #include "cprver.h" 12 | #include "curl_container.h" 13 | #include "curlholder.h" 14 | #include "error.h" 15 | #include "http_version.h" 16 | #include "interceptor.h" 17 | #include "interface.h" 18 | #include "limit_rate.h" 19 | #include "low_speed.h" 20 | #include "multipart.h" 21 | #include "parameters.h" 22 | #include "payload.h" 23 | #include "proxies.h" 24 | #include "proxyauth.h" 25 | #include "range.h" 26 | #include "redirect.h" 27 | #include "reserve_size.h" 28 | #include "response.h" 29 | #include "session.h" 30 | #include "ssl_options.h" 31 | #include "status_codes.h" 32 | #include "timeout.h" 33 | #include "unix_socket.h" 34 | #include "user_agent.h" 35 | #include "util.h" 36 | #include "verbose.h" 37 | 38 | #define CPR_LIBCURL_VERSION_NUM LIBCURL_VERSION_NUM 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/cprtypes.cpp: -------------------------------------------------------------------------------- 1 | #include "cprtypes.h" 2 | 3 | #include 4 | #include 5 | 6 | namespace cpr { 7 | bool CaseInsensitiveCompare::operator()(const std::string& a, const std::string& b) const noexcept { 8 | return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](unsigned char ac, unsigned char bc) { return std::tolower(ac) < std::tolower(bc); }); 9 | } 10 | } // namespace cpr 11 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/cprver.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_CPRVER_H 2 | #define CPR_CPRVER_H 3 | 4 | /** 5 | * CPR version as a string. 6 | **/ 7 | #define CPR_VERSION "1.8.3" 8 | 9 | /** 10 | * CPR version split up into parts. 11 | **/ 12 | #define CPR_VERSION_MAJOR 1 13 | #define CPR_VERSION_MINOR 8 14 | #define CPR_VERSION_PATCH 3 15 | 16 | /** 17 | * CPR version as a single hex digit. 18 | * it can be split up into three parts: 19 | * 0xAABBCC 20 | * AA: The current CPR major version number in a hex format. 21 | * BB: The current CPR minor version number in a hex format. 22 | * CC: The current CPR patch version number in a hex format. 23 | * 24 | * Examples: 25 | * '0x010702' -> 01.07.02 -> CPR_VERSION: 1.7.2 26 | * '0xA13722' -> A1.37.22 -> CPR_VERSION: 161.55.34 27 | **/ 28 | #define CPR_VERSION_NUM 0x080103 29 | 30 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/curl_container.h: -------------------------------------------------------------------------------- 1 | #ifndef CURL_CONTAINER_H 2 | #define CURL_CONTAINER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "curlholder.h" 10 | 11 | 12 | namespace cpr { 13 | 14 | struct Parameter { 15 | Parameter(const std::string& p_key, const std::string& p_value) : key{p_key}, value{p_value} {} 16 | Parameter(std::string&& p_key, std::string&& p_value) : key{std::move(p_key)}, value{std::move(p_value)} {} 17 | 18 | std::string key; 19 | std::string value; 20 | }; 21 | 22 | struct Pair { 23 | Pair(const std::string& p_key, const std::string& p_value) : key(p_key), value(p_value) {} 24 | Pair(std::string&& p_key, std::string&& p_value) : key(std::move(p_key)), value(std::move(p_value)) {} 25 | 26 | std::string key; 27 | std::string value; 28 | }; 29 | 30 | 31 | template 32 | class CurlContainer { 33 | public: 34 | /** 35 | * Enables or disables URL encoding for keys and values when calling GetContent(...). 36 | **/ 37 | bool encode = true; 38 | 39 | CurlContainer() = default; 40 | CurlContainer(const std::initializer_list&); 41 | 42 | void Add(const std::initializer_list&); 43 | void Add(const T&); 44 | 45 | const std::string GetContent(const CurlHolder&) const; 46 | 47 | protected: 48 | std::vector containerList_; 49 | }; 50 | 51 | } // namespace cpr 52 | 53 | #endif // 54 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/curlholder.cpp: -------------------------------------------------------------------------------- 1 | #include "curlholder.h" 2 | #include 3 | 4 | namespace cpr { 5 | CurlHolder::CurlHolder() { 6 | /** 7 | * Allow multithreaded access to CPR by locking curl_easy_init(). 8 | * curl_easy_init() is not thread safe. 9 | * References: 10 | * https://curl.haxx.se/libcurl/c/curl_easy_init.html 11 | * https://curl.haxx.se/libcurl/c/threadsafe.html 12 | **/ 13 | curl_easy_init_mutex_().lock(); 14 | handle = curl_easy_init(); 15 | curl_easy_init_mutex_().unlock(); 16 | 17 | assert(handle); 18 | } // namespace cpr 19 | 20 | CurlHolder::~CurlHolder() { 21 | curl_slist_free_all(chunk); 22 | curl_formfree(formpost); 23 | curl_easy_cleanup(handle); 24 | } 25 | 26 | std::string CurlHolder::urlEncode(const std::string& s) const { 27 | assert(handle); 28 | char* output = curl_easy_escape(handle, s.c_str(), static_cast(s.length())); 29 | if (output) { 30 | std::string result = output; 31 | curl_free(output); 32 | return result; 33 | } 34 | return ""; 35 | } 36 | 37 | std::string CurlHolder::urlDecode(const std::string& s) const { 38 | assert(handle); 39 | char* output = curl_easy_unescape(handle, s.c_str(), static_cast(s.length()), nullptr); 40 | if (output) { 41 | std::string result = output; 42 | curl_free(output); 43 | return result; 44 | } 45 | return ""; 46 | } 47 | } // namespace cpr 48 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/curlholder.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_CURL_HOLDER_H 2 | #define CPR_CURL_HOLDER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace cpr { 11 | struct CurlHolder { 12 | private: 13 | /** 14 | * Mutex for curl_easy_init(). 15 | * curl_easy_init() is not thread save. 16 | * References: 17 | * https://curl.haxx.se/libcurl/c/curl_easy_init.html 18 | * https://curl.haxx.se/libcurl/c/threadsafe.html 19 | **/ 20 | 21 | // Avoids initalization order problems in a static build 22 | static std::mutex& curl_easy_init_mutex_() { 23 | static std::mutex curl_easy_init_mutex_; 24 | return curl_easy_init_mutex_; 25 | } 26 | 27 | public: 28 | CURL* handle{nullptr}; 29 | struct curl_slist* chunk{nullptr}; 30 | struct curl_httppost* formpost{nullptr}; 31 | std::array error{}; 32 | 33 | CurlHolder(); 34 | CurlHolder(const CurlHolder& other) = default; 35 | CurlHolder(CurlHolder&& old) noexcept = default; 36 | ~CurlHolder(); 37 | 38 | CurlHolder& operator=(CurlHolder&& old) noexcept = default; 39 | CurlHolder& operator=(const CurlHolder& other) = default; 40 | 41 | /** 42 | * Uses curl_easy_escape(...) for escaping the given string. 43 | **/ 44 | std::string urlEncode(const std::string& s) const; 45 | 46 | /** 47 | * Uses curl_easy_unescape(...) for unescaping the given string. 48 | **/ 49 | std::string urlDecode(const std::string& s) const; 50 | }; 51 | } // namespace cpr 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/error.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_ERROR_H 2 | #define CPR_ERROR_H 3 | 4 | #include 5 | #include 6 | 7 | #include "cprtypes.h" 8 | #include 9 | 10 | namespace cpr { 11 | 12 | enum class ErrorCode { 13 | OK = 0, 14 | CONNECTION_FAILURE, 15 | EMPTY_RESPONSE, 16 | HOST_RESOLUTION_FAILURE, 17 | INTERNAL_ERROR, 18 | INVALID_URL_FORMAT, 19 | NETWORK_RECEIVE_ERROR, 20 | NETWORK_SEND_FAILURE, 21 | OPERATION_TIMEDOUT, 22 | PROXY_RESOLUTION_FAILURE, 23 | SSL_CONNECT_ERROR, 24 | SSL_LOCAL_CERTIFICATE_ERROR, 25 | SSL_REMOTE_CERTIFICATE_ERROR, 26 | SSL_CACERT_ERROR, 27 | GENERIC_SSL_ERROR, 28 | UNSUPPORTED_PROTOCOL, 29 | REQUEST_CANCELLED, 30 | TOO_MANY_REDIRECTS, 31 | UNKNOWN_ERROR = 1000, 32 | }; 33 | 34 | class Error { 35 | public: 36 | ErrorCode code = ErrorCode::OK; 37 | std::string message{}; 38 | 39 | Error() = default; 40 | 41 | Error(const std::int32_t& curl_code, std::string&& p_error_message) : code{getErrorCodeForCurlError(curl_code)}, message(std::move(p_error_message)) {} 42 | 43 | explicit operator bool() const { 44 | return code != ErrorCode::OK; 45 | } 46 | 47 | private: 48 | static ErrorCode getErrorCodeForCurlError(std::int32_t curl_code); 49 | }; 50 | 51 | } // namespace cpr 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/interceptor.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_INTERCEPTOR_H 2 | #define CPR_INTERCEPTOR_H 3 | 4 | #include "response.h" 5 | #include "session.h" 6 | 7 | namespace cpr { 8 | 9 | class Interceptor { 10 | public: 11 | enum class ProceedHttpMethod { 12 | GET_REQUEST = 0, 13 | POST_REQUEST, 14 | PUT_REQUEST, 15 | DELETE_REQUEST, 16 | PATCH_REQUEST, 17 | HEAD_REQUEST, 18 | OPTIONS_REQUEST, 19 | DOWNLOAD_CALLBACK_REQUEST, 20 | DOWNLOAD_FILE_REQUEST, 21 | }; 22 | 23 | virtual ~Interceptor() = default; 24 | virtual Response intercept(Session& session) = 0; 25 | 26 | protected: 27 | static Response proceed(Session& session); 28 | static Response proceed(Session& session, ProceedHttpMethod httpMethod); 29 | static Response proceed(Session& session, ProceedHttpMethod httpMethod, std::ofstream& file); 30 | static Response proceed(Session& session, ProceedHttpMethod httpMethod, const WriteCallback& write); 31 | }; 32 | 33 | } // namespace cpr 34 | 35 | 36 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/interface.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_INTERFACE_H 2 | #define CPR_INTERFACE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "cprtypes.h" 8 | 9 | namespace cpr { 10 | 11 | class Interface : public StringHolder { 12 | public: 13 | Interface() : StringHolder() {} 14 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 15 | Interface(const std::string& iface) : StringHolder(iface) {} 16 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 17 | Interface(std::string&& iface) : StringHolder(std::move(iface)) {} 18 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 19 | Interface(const char* iface) : StringHolder(iface) {} 20 | Interface(const char* str, size_t len) : StringHolder(str, len) {} 21 | Interface(const std::initializer_list args) : StringHolder(args) {} 22 | Interface(const Interface& other) = default; 23 | Interface(Interface&& old) noexcept = default; 24 | ~Interface() override = default; 25 | 26 | Interface& operator=(Interface&& old) noexcept = default; 27 | Interface& operator=(const Interface& other) = default; 28 | }; 29 | 30 | } // namespace cpr 31 | 32 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/limit_rate.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_SPEED_LIMIT_H 2 | #define CPR_SPEED_LIMIT_H 3 | 4 | #include 5 | 6 | namespace cpr { 7 | 8 | class LimitRate { 9 | public: 10 | LimitRate(const std::int64_t p_downrate, const std::int64_t p_uprate) : downrate(p_downrate), uprate(p_uprate) {} 11 | 12 | std::int64_t downrate = 0; 13 | std::int64_t uprate = 0; 14 | }; 15 | 16 | } // namespace cpr 17 | 18 | #endif -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/low_speed.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_LOW_SPEED_H 2 | #define CPR_LOW_SPEED_H 3 | 4 | #include 5 | 6 | namespace cpr { 7 | 8 | class LowSpeed { 9 | public: 10 | LowSpeed(const std::int32_t p_limit, const std::int32_t p_time) : limit(p_limit), time(p_time) {} 11 | 12 | std::int32_t limit; 13 | std::int32_t time; 14 | }; 15 | 16 | } // namespace cpr 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/multipart.cpp: -------------------------------------------------------------------------------- 1 | #include "multipart.h" 2 | 3 | namespace cpr { 4 | Multipart::Multipart(const std::initializer_list& p_parts) : parts{p_parts} {} 5 | } // namespace cpr 6 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/parameters.cpp: -------------------------------------------------------------------------------- 1 | #include "parameters.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "util.h" 7 | 8 | namespace cpr { 9 | Parameters::Parameters(const std::initializer_list& parameters) : CurlContainer(parameters) {} 10 | } // namespace cpr 11 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/parameters.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_PARAMETERS_H 2 | #define CPR_PARAMETERS_H 3 | 4 | #include 5 | 6 | #include "curl_container.h" 7 | 8 | namespace cpr { 9 | 10 | class Parameters : public CurlContainer { 11 | public: 12 | Parameters() = default; 13 | Parameters(const std::initializer_list& parameters); 14 | }; 15 | 16 | } // namespace cpr 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/payload.cpp: -------------------------------------------------------------------------------- 1 | #include "payload.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "util.h" 7 | 8 | namespace cpr { 9 | Payload::Payload(const std::initializer_list& pairs) : CurlContainer(pairs) {} 10 | } // namespace cpr 11 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/payload.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_PAYLOAD_H 2 | #define CPR_PAYLOAD_H 3 | 4 | #include 5 | 6 | #include "curl_container.h" 7 | 8 | 9 | namespace cpr { 10 | class Payload : public CurlContainer { 11 | public: 12 | template 13 | Payload(const It begin, const It end) { 14 | for (It pair = begin; pair != end; ++pair) { 15 | Add(*pair); 16 | } 17 | } 18 | Payload(const std::initializer_list& pairs); 19 | }; 20 | 21 | } // namespace cpr 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/proxies.cpp: -------------------------------------------------------------------------------- 1 | #include "proxies.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace cpr { 9 | 10 | Proxies::Proxies(const std::initializer_list>& hosts) : hosts_{hosts} {} 11 | 12 | bool Proxies::has(const std::string& protocol) const { 13 | return hosts_.count(protocol) > 0; 14 | } 15 | 16 | const std::string& Proxies::operator[](const std::string& protocol) { 17 | return hosts_[protocol]; 18 | } 19 | 20 | } // namespace cpr 21 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/proxies.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_PROXIES_H 2 | #define CPR_PROXIES_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace cpr { 9 | class Proxies { 10 | public: 11 | Proxies() = default; 12 | Proxies(const std::initializer_list>& hosts); 13 | 14 | bool has(const std::string& protocol) const; 15 | const std::string& operator[](const std::string& protocol); 16 | 17 | private: 18 | std::map hosts_; 19 | }; 20 | } // namespace cpr 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/proxyauth.cpp: -------------------------------------------------------------------------------- 1 | #include "proxyauth.h" 2 | 3 | namespace cpr { 4 | const char* EncodedAuthentication::GetAuthString() const noexcept { 5 | return auth_string_.c_str(); 6 | } 7 | 8 | bool ProxyAuthentication::has(const std::string& protocol) const { 9 | return proxyAuth_.count(protocol) > 0; 10 | } 11 | 12 | const char* ProxyAuthentication::operator[](const std::string& protocol) { 13 | return proxyAuth_[protocol].GetAuthString(); 14 | } 15 | 16 | } // namespace cpr 17 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/proxyauth.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_PROXYAUTH_H 2 | #define CPR_PROXYAUTH_H 3 | 4 | #include 5 | #include 6 | 7 | #include "auth.h" 8 | #include "util.h" 9 | 10 | namespace cpr { 11 | class EncodedAuthentication { 12 | public: 13 | EncodedAuthentication() : auth_string_{""} {} 14 | EncodedAuthentication(const std::string& username, const std::string& password) : auth_string_{cpr::util::urlEncode(username) + ":" + cpr::util::urlEncode(password)} {} 15 | EncodedAuthentication(std::string&& username, std::string&& password) : auth_string_{cpr::util::urlEncode(std::move(username)) + ":" + cpr::util::urlEncode(std::move(password))} {} 16 | EncodedAuthentication(const EncodedAuthentication& other) = default; 17 | EncodedAuthentication(EncodedAuthentication&& old) noexcept = default; 18 | virtual ~EncodedAuthentication() noexcept = default; 19 | 20 | EncodedAuthentication& operator=(EncodedAuthentication&& old) noexcept = default; 21 | EncodedAuthentication& operator=(const EncodedAuthentication& other) = default; 22 | 23 | const char* GetAuthString() const noexcept; 24 | 25 | protected: 26 | std::string auth_string_; 27 | }; 28 | 29 | class ProxyAuthentication { 30 | public: 31 | ProxyAuthentication() = default; 32 | ProxyAuthentication(const std::initializer_list>& auths) : proxyAuth_{auths} {} 33 | 34 | bool has(const std::string& protocol) const; 35 | const char* operator[](const std::string& protocol); 36 | 37 | private: 38 | std::map proxyAuth_; 39 | }; 40 | 41 | } // namespace cpr 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/range.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_RANGE_H 2 | #define CPR_RANGE_H 3 | 4 | #include 5 | 6 | namespace cpr { 7 | 8 | class Range { 9 | public: 10 | Range(const std::int64_t p_resume_from, const std::int64_t p_finish_at) : resume_from(p_resume_from), finish_at(p_finish_at) {} 11 | 12 | std::int64_t resume_from = 0; 13 | std::int64_t finish_at = 0; 14 | 15 | const std::string str() const { 16 | std::string from_str = (resume_from < (std::int64_t) 0) ? "" : std::to_string(resume_from); 17 | std::string to_str = (finish_at < (std::int64_t) 0) ? "" : std::to_string(finish_at); 18 | return from_str + "-" + to_str; 19 | } 20 | }; 21 | 22 | class MultiRange { 23 | public: 24 | MultiRange(std::initializer_list rs) : ranges{rs} {} 25 | 26 | const std::string str() const { 27 | std::string multi_range_string{}; 28 | for (Range range : ranges) { 29 | multi_range_string += ((multi_range_string.empty()) ? "" : ", ") + range.str(); 30 | } 31 | return multi_range_string; 32 | } 33 | 34 | private: 35 | std::vector ranges; 36 | }; // namespace cpr 37 | 38 | } // namespace cpr 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/redirect.cpp: -------------------------------------------------------------------------------- 1 | #include "redirect.h" 2 | 3 | namespace cpr { 4 | PostRedirectFlags operator|(PostRedirectFlags lhs, PostRedirectFlags rhs) { 5 | return static_cast(static_cast(lhs) | static_cast(rhs)); 6 | } 7 | 8 | PostRedirectFlags operator&(PostRedirectFlags lhs, PostRedirectFlags rhs) { 9 | return static_cast(static_cast(lhs) & static_cast(rhs)); 10 | } 11 | 12 | PostRedirectFlags operator^(PostRedirectFlags lhs, PostRedirectFlags rhs) { 13 | return static_cast(static_cast(lhs) ^ static_cast(rhs)); 14 | } 15 | 16 | PostRedirectFlags operator~(PostRedirectFlags flag) { 17 | return static_cast(~static_cast(flag)); 18 | } 19 | 20 | PostRedirectFlags& operator|=(PostRedirectFlags& lhs, PostRedirectFlags rhs) { 21 | lhs = static_cast(static_cast(lhs) | static_cast(rhs)); 22 | uint8_t tmp = static_cast(lhs); 23 | lhs = static_cast(tmp); 24 | return lhs; 25 | } 26 | 27 | PostRedirectFlags& operator&=(PostRedirectFlags& lhs, PostRedirectFlags rhs) { 28 | lhs = static_cast(static_cast(lhs) & static_cast(rhs)); 29 | return lhs; 30 | } 31 | 32 | PostRedirectFlags& operator^=(PostRedirectFlags& lhs, PostRedirectFlags rhs) { 33 | lhs = static_cast(static_cast(lhs) ^ static_cast(rhs)); 34 | return lhs; 35 | } 36 | 37 | bool any(PostRedirectFlags flag) { 38 | return flag != PostRedirectFlags::NONE; 39 | } 40 | } // namespace cpr 41 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/reserve_size.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_RESERVE_SIZE_H 2 | #define CPR_RESERVE_SIZE_H 3 | 4 | #include 5 | 6 | namespace cpr { 7 | 8 | class ReserveSize { 9 | public: 10 | ReserveSize(const size_t _size) : size(_size) {} 11 | 12 | size_t size = 0; 13 | }; 14 | 15 | } // namespace cpr 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/response.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_RESPONSE_H 2 | #define CPR_RESPONSE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "cookies.h" 12 | #include "cprtypes.h" 13 | #include "error.h" 14 | #include "ssl_options.h" 15 | #include "util.h" 16 | 17 | namespace cpr { 18 | 19 | class Response { 20 | private: 21 | std::shared_ptr curl_{nullptr}; 22 | 23 | public: 24 | // Ignored here since libcurl uses a long for this. 25 | // NOLINTNEXTLINE(google-runtime-int) 26 | long status_code{}; 27 | std::string text{}; 28 | Header header{}; 29 | Url url{}; 30 | double elapsed{}; 31 | Cookies cookies{}; 32 | Error error{}; 33 | std::string raw_header{}; 34 | std::string status_line{}; 35 | std::string reason{}; 36 | cpr_off_t uploaded_bytes{}; 37 | cpr_off_t downloaded_bytes{}; 38 | // Ignored here since libcurl uses a long for this. 39 | // NOLINTNEXTLINE(google-runtime-int) 40 | long redirect_count{}; 41 | 42 | Response() = default; 43 | Response(std::shared_ptr curl, std::string&& p_text, std::string&& p_header_string, Cookies&& p_cookies, Error&& p_error); 44 | std::vector GetCertInfo(); 45 | Response(const Response& other) = default; 46 | Response(Response&& old) noexcept = default; 47 | ~Response() noexcept = default; 48 | 49 | Response& operator=(Response&& old) noexcept = default; 50 | Response& operator=(const Response& other) = default; 51 | }; 52 | } // namespace cpr 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/singleton.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_SINGLETON_H 2 | #define CPR_SINGLETON_H 3 | 4 | #include 5 | 6 | #ifndef CPR_DISABLE_COPY 7 | #define CPR_DISABLE_COPY(Class) \ 8 | Class(const Class&) = delete; \ 9 | Class& operator=(const Class&) = delete; 10 | #endif 11 | 12 | #ifndef CPR_SINGLETON_DECL 13 | #define CPR_SINGLETON_DECL(Class) \ 14 | public: \ 15 | static Class* GetInstance(); \ 16 | static void ExitInstance(); \ 17 | private: \ 18 | CPR_DISABLE_COPY(Class) \ 19 | static Class* s_pInstance; \ 20 | static std::mutex s_mutex; 21 | #endif 22 | 23 | #ifndef CPR_SINGLETON_IMPL 24 | #define CPR_SINGLETON_IMPL(Class) \ 25 | Class* Class::s_pInstance = nullptr; \ 26 | std::mutex Class::s_mutex; \ 27 | Class* Class::GetInstance() { \ 28 | if (s_pInstance == nullptr) { \ 29 | s_mutex.lock(); \ 30 | if (s_pInstance == nullptr) { \ 31 | s_pInstance = new Class; \ 32 | } \ 33 | s_mutex.unlock(); \ 34 | } \ 35 | return s_pInstance; \ 36 | } \ 37 | void Class::ExitInstance() { \ 38 | s_mutex.lock(); \ 39 | if (s_pInstance) { \ 40 | delete s_pInstance; \ 41 | s_pInstance = nullptr; \ 42 | } \ 43 | s_mutex.unlock(); \ 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/timeout.cpp: -------------------------------------------------------------------------------- 1 | #include "timeout.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace cpr { 9 | 10 | // No way around since curl uses a long here. 11 | // NOLINTNEXTLINE(google-runtime-int) 12 | long Timeout::Milliseconds() const { 13 | static_assert(std::is_same::value, "Following casting expects milliseconds."); 14 | 15 | // No way around since curl uses a long here. 16 | // NOLINTNEXTLINE(google-runtime-int) 17 | if (ms.count() > static_cast(std::numeric_limits::max())) { 18 | throw std::overflow_error("cpr::Timeout: timeout value overflow: " + std::to_string(ms.count()) + " ms."); 19 | } 20 | // No way around since curl uses a long here. 21 | // NOLINTNEXTLINE(google-runtime-int) 22 | if (ms.count() < static_cast(std::numeric_limits::min())) { 23 | throw std::underflow_error("cpr::Timeout: timeout value underflow: " + std::to_string(ms.count()) + " ms."); 24 | } 25 | 26 | // No way around since curl uses a long here. 27 | // NOLINTNEXTLINE(google-runtime-int) 28 | return static_cast(ms.count()); 29 | } 30 | 31 | } // namespace cpr 32 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/timeout.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_TIMEOUT_H 2 | #define CPR_TIMEOUT_H 3 | 4 | #include 5 | #include 6 | 7 | namespace cpr { 8 | 9 | class Timeout { 10 | public: 11 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 12 | Timeout(const std::chrono::milliseconds& duration) : ms{duration} {} 13 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 14 | Timeout(const std::int32_t& milliseconds) : Timeout{std::chrono::milliseconds(milliseconds)} {} 15 | 16 | // No way around since curl uses a long here. 17 | // NOLINTNEXTLINE(google-runtime-int) 18 | long Milliseconds() const; 19 | 20 | std::chrono::milliseconds ms; 21 | }; 22 | 23 | } // namespace cpr 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/unix_socket.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "unix_socket.h" 3 | 4 | namespace cpr { 5 | const char* UnixSocket::GetUnixSocketString() const noexcept { 6 | return unix_socket_.data(); 7 | } 8 | } // namespace cpr 9 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/unix_socket.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_UNIX_SOCKET_H 2 | #define CPR_UNIX_SOCKET_H 3 | 4 | #include 5 | 6 | namespace cpr { 7 | 8 | class UnixSocket { 9 | public: 10 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 11 | UnixSocket(std::string&& unix_socket) : unix_socket_(std::move(unix_socket)) {} 12 | 13 | const char* GetUnixSocketString() const noexcept; 14 | 15 | private: 16 | const std::string unix_socket_; 17 | }; 18 | 19 | } // namespace cpr 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/user_agent.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_USERAGENT_H 2 | #define CPR_USERAGENT_H 3 | 4 | #include 5 | #include 6 | 7 | #include "cprtypes.h" 8 | 9 | namespace cpr { 10 | class UserAgent : public StringHolder { 11 | public: 12 | UserAgent() : StringHolder() {} 13 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 14 | UserAgent(const std::string& useragent) : StringHolder(useragent) {} 15 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 16 | UserAgent(std::string&& useragent) : StringHolder(std::move(useragent)) {} 17 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 18 | UserAgent(const char* useragent) : StringHolder(useragent) {} 19 | UserAgent(const char* str, size_t len) : StringHolder(str, len) {} 20 | UserAgent(const std::initializer_list args) : StringHolder(args) {} 21 | UserAgent(const UserAgent& other) = default; 22 | UserAgent(UserAgent&& old) noexcept = default; 23 | ~UserAgent() override = default; 24 | 25 | UserAgent& operator=(UserAgent&& old) noexcept = default; 26 | UserAgent& operator=(const UserAgent& other) = default; 27 | }; 28 | 29 | } // namespace cpr 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/util.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_UTIL_H 2 | #define CPR_UTIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "callback.h" 9 | #include "cookies.h" 10 | #include "cprtypes.h" 11 | #include "curlholder.h" 12 | 13 | namespace cpr { 14 | namespace util { 15 | 16 | Header parseHeader(const std::string& headers, std::string* status_line = nullptr, std::string* reason = nullptr); 17 | Cookies parseCookies(curl_slist* raw_cookies); 18 | size_t readUserFunction(char* ptr, size_t size, size_t nitems, const ReadCallback* read); 19 | size_t headerUserFunction(char* ptr, size_t size, size_t nmemb, const HeaderCallback* header); 20 | size_t writeFunction(char* ptr, size_t size, size_t nmemb, std::string* data); 21 | size_t writeFileFunction(char* ptr, size_t size, size_t nmemb, std::ofstream* file); 22 | size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallback* write); 23 | #if LIBCURL_VERSION_NUM < 0x072000 24 | int progressUserFunction(const ProgressCallback* progress, double dltotal, double dlnow, double ultotal, double ulnow); 25 | #else 26 | int progressUserFunction(const ProgressCallback* progress, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); 27 | #endif 28 | int debugUserFunction(CURL* handle, curl_infotype type, char* data, size_t size, const DebugCallback* debug); 29 | std::vector split(const std::string& to_split, char delimiter); 30 | std::string urlEncode(const std::string& s); 31 | std::string urlDecode(const std::string& s); 32 | 33 | } // namespace util 34 | } // namespace cpr 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /module/src/main/cpp/http/cpr/verbose.h: -------------------------------------------------------------------------------- 1 | #ifndef CPR_VERBOSE_H_ 2 | #define CPR_VERBOSE_H_ 3 | 4 | namespace cpr { 5 | 6 | class Verbose { 7 | public: 8 | Verbose() = default; 9 | // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) 10 | Verbose(const bool p_verbose) : verbose{p_verbose} {} 11 | 12 | bool verbose = true; 13 | }; 14 | 15 | } // namespace cpr 16 | 17 | 18 | #endif /* CPR_VERBOSE_H_ */ 19 | -------------------------------------------------------------------------------- /module/src/main/cpp/il2cpp_dump.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Perfare on 2020/7/4. 3 | // 4 | 5 | #ifndef RIRU_IL2CPPDUMPER_IL2CPP_H 6 | #define RIRU_IL2CPPDUMPER_IL2CPP_H 7 | 8 | #include "game.h" 9 | 10 | void il2cpp_dump(void *handle, char *outDir); 11 | 12 | #endif //RIRU_IL2CPPDUMPER_IL2CPP_H 13 | -------------------------------------------------------------------------------- /module/src/main/cpp/libs/arm64-v8a/libdobby.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/cpp/libs/arm64-v8a/libdobby.a -------------------------------------------------------------------------------- /module/src/main/cpp/libs/armeabi-v7a/libdobby.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/cpp/libs/armeabi-v7a/libdobby.a -------------------------------------------------------------------------------- /module/src/main/cpp/log.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Perfare on 2020/7/4. 3 | // 4 | 5 | #ifndef RIRU_IL2CPPDUMPER_LOG_H 6 | #define RIRU_IL2CPPDUMPER_LOG_H 7 | 8 | #include 9 | 10 | #define LOG_TAG "Perfare" 11 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) 12 | #define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) 13 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) 14 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) 15 | 16 | #endif //RIRU_IL2CPPDUMPER_LOG_H 17 | -------------------------------------------------------------------------------- /module/src/main/cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "hook.h" 5 | #include "zygisk.hpp" 6 | 7 | using zygisk::Api; 8 | using zygisk::AppSpecializeArgs; 9 | using zygisk::ServerSpecializeArgs; 10 | 11 | class MyModule : public zygisk::ModuleBase { 12 | public: 13 | void onLoad(Api *api, JNIEnv *env) override { 14 | env_ = env; 15 | } 16 | 17 | void preAppSpecialize(AppSpecializeArgs *args) override { 18 | if (!args || !args->nice_name) { 19 | LOGE("Skip unknown process"); 20 | return; 21 | } 22 | enable_hack = isGame(env_, args->app_data_dir); 23 | } 24 | 25 | void postAppSpecialize(const AppSpecializeArgs *) override { 26 | LOGE("called something"); 27 | if (enable_hack) { 28 | LOGE("enebel_hack is tru"); 29 | int ret; 30 | pthread_t ntid; 31 | if ((ret = pthread_create(&ntid, nullptr, hack_thread, nullptr))) { 32 | LOGE("can't create thread: %s\n", strerror(ret)); 33 | } 34 | } 35 | } 36 | 37 | private: 38 | JNIEnv *env_{}; 39 | }; 40 | 41 | REGISTER_ZYGISK_MODULE(MyModule) -------------------------------------------------------------------------------- /module/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | -------------------------------------------------------------------------------- /module/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /module/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /module/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /module/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fedes1to/ImGUI-Zygisk-Unity/30027093befcfe1c558b626abe6c237ebe4bffb3/module/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /module/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | 7 | -------------------------------------------------------------------------------- /module/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ImguiAndroid 3 | 4 | -------------------------------------------------------------------------------- /module/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':module' 2 | 3 | import org.apache.tools.ant.DirectoryScanner 4 | 5 | DirectoryScanner.removeDefaultExclude('**/.gitattributes') 6 | -------------------------------------------------------------------------------- /template/magisk_module/META-INF/com/google/android/update-binary: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | 3 | ################# 4 | # Initialization 5 | ################# 6 | 7 | umask 022 8 | 9 | # echo before loading util_functions 10 | ui_print() { echo "$1"; } 11 | 12 | require_new_magisk() { 13 | ui_print "*******************************" 14 | ui_print " Please install Magisk v20.4+! " 15 | ui_print "*******************************" 16 | exit 1 17 | } 18 | 19 | ######################### 20 | # Load util_functions.sh 21 | ######################### 22 | 23 | OUTFD=$2 24 | ZIPFILE=$3 25 | 26 | mount /data 2>/dev/null 27 | 28 | [ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk 29 | . /data/adb/magisk/util_functions.sh 30 | [ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk 31 | 32 | install_module 33 | exit 0 34 | -------------------------------------------------------------------------------- /template/magisk_module/META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | #MAGISK 2 | -------------------------------------------------------------------------------- /template/magisk_module/module.prop: -------------------------------------------------------------------------------- 1 | id=${id} 2 | name=${name} 3 | version=${version} 4 | versionCode=${versionCode} 5 | author=${author} 6 | description=${description} 7 | --------------------------------------------------------------------------------