├── .gitignore
├── .idea
├── .gitignore
├── .name
├── compiler.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
├── migrations.xml
├── misc.xml
└── vcs.xml
├── app
├── .gitignore
├── build.gradle.kts
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── pareto
│ │ └── bypasskeyattestation
│ │ └── ExampleInstrumentedTest.kt
│ └── main
│ ├── AndroidManifest.xml
│ ├── cpp
│ ├── CMakeLists.txt
│ ├── Dobby
│ │ ├── .clang-format
│ │ ├── CMakeLists.txt
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── README_zh-cn.md
│ │ ├── builtin-plugin
│ │ │ ├── ApplicationEventMonitor
│ │ │ │ ├── MGCopyAnswerMonitor.cc
│ │ │ │ ├── dynamic_loader_monitor.cc
│ │ │ │ ├── file_operation_monitor.cc
│ │ │ │ ├── memory_operation_instrument.cc
│ │ │ │ ├── posix_file_descriptor_operation_monitor.cc
│ │ │ │ └── posix_socket_network_monitor.cc
│ │ │ ├── BionicLinkerUtil
│ │ │ │ ├── bionic_linker_demo.cc
│ │ │ │ ├── bionic_linker_util.cc
│ │ │ │ └── bionic_linker_util.h
│ │ │ ├── CMakeLists.txt
│ │ │ ├── ImportTableReplace
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── dobby_import_replace.cc
│ │ │ │ └── dobby_import_replace.h
│ │ │ ├── ObjcRuntimeReplace
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── dobby_objc_runtime_repalce.h
│ │ │ │ └── dobby_objc_runtime_replace.mm
│ │ │ ├── SupervisorCallMonitor
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── README
│ │ │ │ ├── mach_system_call_log_handler.cc
│ │ │ │ ├── misc_utility.cc
│ │ │ │ ├── misc_utility.h
│ │ │ │ ├── sensitive_api_monitor.cc
│ │ │ │ ├── supervisor_call_monitor.cc
│ │ │ │ ├── supervisor_call_monitor.h
│ │ │ │ ├── system_call_log_handler.cc
│ │ │ │ └── test_supervisor_call_monitor.cc
│ │ │ └── SymbolResolver
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── dobby_symbol_resolver.h
│ │ │ │ ├── elf
│ │ │ │ └── dobby_symbol_resolver.cc
│ │ │ │ ├── macho
│ │ │ │ ├── dobby_symbol_resolver.cc
│ │ │ │ ├── dobby_symbol_resolver_priv.h
│ │ │ │ ├── macho_ctx.cc
│ │ │ │ ├── macho_ctx.h
│ │ │ │ ├── shared-cache
│ │ │ │ │ └── dyld_cache_format.h
│ │ │ │ ├── shared_cache_ctx.cpp
│ │ │ │ └── shared_cache_ctx.h
│ │ │ │ ├── mmap_file_util.h
│ │ │ │ └── pe
│ │ │ │ └── dobby_symbol_resolver.cc
│ │ ├── cmake
│ │ │ ├── Macros.cmake
│ │ │ ├── Util.cmake
│ │ │ ├── auto_source_group.cmake
│ │ │ ├── build_environment_check.cmake
│ │ │ ├── compiler_and_linker.cmake
│ │ │ ├── dobby.xcode.source.cmake
│ │ │ ├── platform
│ │ │ │ └── platform-darwin.cmake
│ │ │ └── xcode_generator_helper.cmake
│ │ ├── docs
│ │ │ └── compile.md
│ │ ├── examples
│ │ │ ├── CMakeLists.txt
│ │ │ ├── main.cc
│ │ │ └── socket_example.cc
│ │ ├── external
│ │ │ ├── TINYSTL
│ │ │ │ ├── README
│ │ │ │ ├── algorithm.h
│ │ │ │ ├── allocator.h
│ │ │ │ ├── buffer.h
│ │ │ │ ├── hash.h
│ │ │ │ ├── hash_base.h
│ │ │ │ ├── new.h
│ │ │ │ ├── stddef.h
│ │ │ │ ├── string.h
│ │ │ │ ├── string_view.h
│ │ │ │ ├── traits.h
│ │ │ │ ├── unordered_map.h
│ │ │ │ ├── unordered_set.h
│ │ │ │ └── vector.h
│ │ │ ├── deprecated
│ │ │ │ └── misc-helper
│ │ │ │ │ ├── CMakeLists.txt
│ │ │ │ │ ├── async_logger.cc
│ │ │ │ │ ├── deprecated
│ │ │ │ │ ├── pthread_helper.cc
│ │ │ │ │ ├── pthread_helper.h
│ │ │ │ │ └── unistd_helper.h
│ │ │ │ │ ├── format_printer.cc
│ │ │ │ │ ├── misc-helper
│ │ │ │ │ ├── async_logger.h
│ │ │ │ │ ├── format_printer.h
│ │ │ │ │ └── variable_cache.h
│ │ │ │ │ └── variable_cache.c
│ │ │ ├── logging
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── kernel_logging.cc
│ │ │ │ ├── logging.cc
│ │ │ │ ├── logging
│ │ │ │ │ ├── check_logging.h
│ │ │ │ │ └── logging.h
│ │ │ │ └── priv_headers
│ │ │ │ │ └── _simple.h
│ │ │ └── osbase
│ │ │ │ └── CMakeLists.txt
│ │ ├── include
│ │ │ └── dobby.h
│ │ ├── scripts
│ │ │ ├── Dockerfile
│ │ │ ├── platform_builder.py
│ │ │ ├── setup_linux_cross_compile.sh
│ │ │ └── setup_macos_cross_compile.sh
│ │ ├── source
│ │ │ ├── Backend
│ │ │ │ ├── KernelMode
│ │ │ │ │ ├── ExecMemory
│ │ │ │ │ │ ├── clear-cache-tool-all.c
│ │ │ │ │ │ └── code-patch-tool-darwin.cc
│ │ │ │ │ ├── PlatformUtil
│ │ │ │ │ │ ├── Darwin
│ │ │ │ │ │ │ └── ProcessRuntimeUtility.cc
│ │ │ │ │ │ └── ProcessRuntimeUtility.h
│ │ │ │ │ └── UnifiedInterface
│ │ │ │ │ │ ├── exec_mem_placeholder.asm
│ │ │ │ │ │ ├── platform-darwin.cc
│ │ │ │ │ │ └── platform.h
│ │ │ │ └── UserMode
│ │ │ │ │ ├── ExecMemory
│ │ │ │ │ ├── clear-cache-tool-all.c
│ │ │ │ │ ├── clear-cache-tool
│ │ │ │ │ │ ├── clear-cache-tool-arm-dummy.cc
│ │ │ │ │ │ └── clear-cache-tool-arm64-dummy.cc
│ │ │ │ │ ├── code-patch-tool-darwin.cc
│ │ │ │ │ ├── code-patch-tool-posix.cc
│ │ │ │ │ ├── code-patch-tool-windows.cc
│ │ │ │ │ └── substrated
│ │ │ │ │ │ └── mach_interface_support
│ │ │ │ │ │ └── substrated.defs
│ │ │ │ │ ├── MultiThreadSupport
│ │ │ │ │ ├── ThreadSupport.cpp
│ │ │ │ │ └── ThreadSupport.h
│ │ │ │ │ ├── PlatformUtil
│ │ │ │ │ ├── Darwin
│ │ │ │ │ │ └── ProcessRuntimeUtility.cc
│ │ │ │ │ ├── Linux
│ │ │ │ │ │ └── ProcessRuntimeUtility.cc
│ │ │ │ │ ├── ProcessRuntimeUtility.h
│ │ │ │ │ └── Windows
│ │ │ │ │ │ └── ProcessRuntimeUtility.cc
│ │ │ │ │ ├── Thread
│ │ │ │ │ ├── PlatformThread.cc
│ │ │ │ │ ├── PlatformThread.h
│ │ │ │ │ ├── platform-thread-posix.cc
│ │ │ │ │ └── platform-thread-windows.cc
│ │ │ │ │ └── UnifiedInterface
│ │ │ │ │ ├── platform-darwin
│ │ │ │ │ └── mach_vm.h
│ │ │ │ │ ├── platform-posix.cc
│ │ │ │ │ ├── platform-windows.cc
│ │ │ │ │ ├── platform.h
│ │ │ │ │ ├── semaphore.cc
│ │ │ │ │ └── semaphore.h
│ │ │ ├── InstructionRelocation
│ │ │ │ ├── InstructionRelocation.h
│ │ │ │ ├── arm
│ │ │ │ │ ├── InstructionRelocationARM.cc
│ │ │ │ │ └── InstructionRelocationARM.h
│ │ │ │ ├── arm64
│ │ │ │ │ ├── InstructionRelocationARM64.cc
│ │ │ │ │ ├── InstructionRelocationARM64.h
│ │ │ │ │ ├── inst_constants.h
│ │ │ │ │ └── inst_decode_encode_kit.h
│ │ │ │ ├── x64
│ │ │ │ │ ├── InstructionRelocationX64.cc
│ │ │ │ │ └── InstructionRelocationX64.h
│ │ │ │ └── x86
│ │ │ │ │ ├── InstructionRelocationX86.cc
│ │ │ │ │ ├── InstructionRelocationX86.h
│ │ │ │ │ ├── InstructionRelocationX86Shared.cc
│ │ │ │ │ ├── InstructionRelocationX86Shared.h
│ │ │ │ │ ├── deprecated
│ │ │ │ │ ├── Ia32Disassembler.cc
│ │ │ │ │ ├── X86OpcodoDecodeTable.cc
│ │ │ │ │ └── X86OpcodoDecodeTable.h
│ │ │ │ │ └── x86_insn_decode
│ │ │ │ │ ├── build_config.h
│ │ │ │ │ ├── x86_insn_decode.c
│ │ │ │ │ ├── x86_insn_decode.h
│ │ │ │ │ ├── x86_insn_reader.c
│ │ │ │ │ ├── x86_opcode_modrm_reg_group.c
│ │ │ │ │ ├── x86_opcode_one_byte.c
│ │ │ │ │ ├── x86_opcode_sse_group.c
│ │ │ │ │ └── x86_opcode_two_byte.c
│ │ │ ├── InterceptEntry.cpp
│ │ │ ├── InterceptEntry.h
│ │ │ ├── InterceptRouting
│ │ │ │ ├── InterceptRouting.cpp
│ │ │ │ ├── InterceptRouting.h
│ │ │ │ ├── Routing
│ │ │ │ │ ├── FunctionInlineHook
│ │ │ │ │ │ ├── FunctionInlineHook.cc
│ │ │ │ │ │ ├── FunctionInlineHookRouting.h
│ │ │ │ │ │ └── RoutingImpl.cc
│ │ │ │ │ ├── FunctionWrapper
│ │ │ │ │ │ ├── FunctionWrapperExport.cc
│ │ │ │ │ │ ├── function-wrapper.cc
│ │ │ │ │ │ ├── function-wrapper.h
│ │ │ │ │ │ ├── intercept_routing_handler.cc
│ │ │ │ │ │ └── intercept_routing_handler.h
│ │ │ │ │ └── InstructionInstrument
│ │ │ │ │ │ ├── InstructionInstrument.cc
│ │ │ │ │ │ ├── InstructionInstrumentRouting.h
│ │ │ │ │ │ ├── RoutingImpl.cc
│ │ │ │ │ │ ├── instrument_routing_handler.cc
│ │ │ │ │ │ └── instrument_routing_handler.h
│ │ │ │ └── RoutingPlugin
│ │ │ │ │ ├── NearBranchTrampoline
│ │ │ │ │ ├── NearBranchTrampoline.cc
│ │ │ │ │ ├── NearBranchTrampoline.h
│ │ │ │ │ └── near_trampoline_arm64.cc
│ │ │ │ │ ├── RoutingPlugin.cc
│ │ │ │ │ └── RoutingPlugin.h
│ │ │ ├── Interceptor.cpp
│ │ │ ├── Interceptor.h
│ │ │ ├── MemoryAllocator
│ │ │ │ ├── AssemblyCodeBuilder.cc
│ │ │ │ ├── AssemblyCodeBuilder.h
│ │ │ │ ├── CodeBuffer
│ │ │ │ │ ├── CodeBufferBase.cc
│ │ │ │ │ ├── CodeBufferBase.h
│ │ │ │ │ ├── code-buffer-arm.h
│ │ │ │ │ ├── code-buffer-arm64.h
│ │ │ │ │ ├── code-buffer-x64.h
│ │ │ │ │ ├── code-buffer-x86.cc
│ │ │ │ │ ├── code-buffer-x86.h
│ │ │ │ │ ├── code_buffer_arm.h
│ │ │ │ │ ├── code_buffer_arm64.h
│ │ │ │ │ ├── code_buffer_x64.h
│ │ │ │ │ └── code_buffer_x86.h
│ │ │ │ ├── MemoryAllocator.cc
│ │ │ │ ├── NearMemoryAllocator.cc
│ │ │ │ └── NearMemoryAllocator.h
│ │ │ ├── PlatformUnifiedInterface
│ │ │ │ ├── ExecMemory
│ │ │ │ │ ├── ClearCacheTool.h
│ │ │ │ │ └── CodePatchTool.h
│ │ │ │ └── MemoryAllocator.h
│ │ │ ├── TrampolineBridge
│ │ │ │ ├── ClosureTrampolineBridge
│ │ │ │ │ ├── ClosureTrampoline.h
│ │ │ │ │ ├── arm
│ │ │ │ │ │ ├── ClosureTrampolineARM.cc
│ │ │ │ │ │ ├── closure_bridge_arm.cc
│ │ │ │ │ │ ├── dummy
│ │ │ │ │ │ │ ├── closure-bridge-template-arm.cc
│ │ │ │ │ │ │ └── closure-trampoline-template-arm.S
│ │ │ │ │ │ └── helper_arm.cc
│ │ │ │ │ ├── arm64
│ │ │ │ │ │ ├── ClosureTrampolineARM64.cc
│ │ │ │ │ │ ├── closure_bridge_arm64.cc
│ │ │ │ │ │ ├── dummy
│ │ │ │ │ │ │ ├── closure-bridge-template-arm64.c
│ │ │ │ │ │ │ ├── closure-trampoline-template-arm64.S
│ │ │ │ │ │ │ └── dynamic-closure-trampoline-template-arm64.S
│ │ │ │ │ │ └── helper_arm64.cc
│ │ │ │ │ ├── common_bridge_handler.cc
│ │ │ │ │ ├── common_bridge_handler.h
│ │ │ │ │ ├── x64
│ │ │ │ │ │ ├── ClosureTrampolineX64.cc
│ │ │ │ │ │ ├── closure_bridge_x64.cc
│ │ │ │ │ │ ├── dummy
│ │ │ │ │ │ │ ├── closure-bridge-template-x64.c
│ │ │ │ │ │ │ └── closure-trampoline-template-x64.S
│ │ │ │ │ │ └── helper_x64.cc
│ │ │ │ │ └── x86
│ │ │ │ │ │ ├── ClosureTrampolineX86.cc
│ │ │ │ │ │ ├── closure_bridge_x86.cc
│ │ │ │ │ │ └── helper_x86.cc
│ │ │ │ └── Trampoline
│ │ │ │ │ ├── Trampoline.h
│ │ │ │ │ ├── arm
│ │ │ │ │ └── trampoline_arm.cc
│ │ │ │ │ ├── arm64
│ │ │ │ │ └── trampoline_arm64.cc
│ │ │ │ │ ├── x64
│ │ │ │ │ └── trampoline_x64.cc
│ │ │ │ │ └── x86
│ │ │ │ │ └── trampoline_x86.cc
│ │ │ ├── core
│ │ │ │ ├── arch
│ │ │ │ │ ├── Cpu.cc
│ │ │ │ │ ├── Cpu.h
│ │ │ │ │ ├── CpuFeature.cc
│ │ │ │ │ ├── CpuFeature.h
│ │ │ │ │ ├── CpuRegister.cc
│ │ │ │ │ ├── CpuRegister.h
│ │ │ │ │ ├── CpuUtils.h
│ │ │ │ │ ├── arm
│ │ │ │ │ │ ├── constants-arm.h
│ │ │ │ │ │ └── registers-arm.h
│ │ │ │ │ ├── arm64
│ │ │ │ │ │ ├── constants-arm64.h
│ │ │ │ │ │ └── registers-arm64.h
│ │ │ │ │ ├── x64
│ │ │ │ │ │ ├── constants-x64.h
│ │ │ │ │ │ └── registers-x64.h
│ │ │ │ │ └── x86
│ │ │ │ │ │ ├── constants-x86.h
│ │ │ │ │ │ ├── cpu-x86.cc
│ │ │ │ │ │ ├── cpu-x86.h
│ │ │ │ │ │ └── registers-x86.h
│ │ │ │ ├── assembler
│ │ │ │ │ ├── AssemblerPseudoLabel.h
│ │ │ │ │ ├── assembler-arch.h
│ │ │ │ │ ├── assembler-arm.cc
│ │ │ │ │ ├── assembler-arm.h
│ │ │ │ │ ├── assembler-arm64.cc
│ │ │ │ │ ├── assembler-arm64.h
│ │ │ │ │ ├── assembler-ia32.cc
│ │ │ │ │ ├── assembler-ia32.h
│ │ │ │ │ ├── assembler-x64.cc
│ │ │ │ │ ├── assembler-x64.h
│ │ │ │ │ ├── assembler-x86-shared.cc
│ │ │ │ │ ├── assembler-x86-shared.h
│ │ │ │ │ ├── assembler.cc
│ │ │ │ │ └── assembler.h
│ │ │ │ ├── codegen
│ │ │ │ │ ├── codegen-arm.cc
│ │ │ │ │ ├── codegen-arm.h
│ │ │ │ │ ├── codegen-arm64.cc
│ │ │ │ │ ├── codegen-arm64.h
│ │ │ │ │ ├── codegen-ia32.cc
│ │ │ │ │ ├── codegen-ia32.h
│ │ │ │ │ ├── codegen-x64.cc
│ │ │ │ │ ├── codegen-x64.h
│ │ │ │ │ └── codegen.h
│ │ │ │ └── emulator
│ │ │ │ │ └── dummy.cc
│ │ │ ├── dobby.cpp
│ │ │ └── dobby
│ │ │ │ ├── common.h
│ │ │ │ ├── dobby_internal.h
│ │ │ │ ├── kernel_mode_header.h
│ │ │ │ ├── pac_kit.h
│ │ │ │ ├── platform_detect_macro.h
│ │ │ │ ├── platform_features.h
│ │ │ │ ├── types.h
│ │ │ │ └── utility_macro.h
│ │ └── tests
│ │ │ ├── CMakeLists.txt
│ │ │ ├── UniconEmulator.cpp
│ │ │ ├── UniconEmulator.h
│ │ │ ├── test_insn_decoder_x86.cpp
│ │ │ ├── test_insn_relo_arm.cpp
│ │ │ ├── test_insn_relo_arm64.cpp
│ │ │ ├── test_insn_relo_x64.cpp
│ │ │ └── test_native.cpp
│ ├── json.hpp
│ ├── main.cpp
│ └── zygisk.hpp
│ └── java
│ └── com
│ └── pareto
│ └── bypasskeyattestation
│ ├── CustomKeyStoreSpi.java
│ ├── CustomProvider.java
│ └── EntryPoint.java
├── build.gradle.kts
├── docs
├── assets
│ ├── image-20231206194441375.png
│ ├── image-20231206194902623.png
│ ├── image-20231206204532183.png
│ ├── image-20231206204618107.png
│ ├── image-20231206204803506.png
│ ├── image-20231206205018254.png
│ ├── image-20231206205854947.png
│ ├── image-20231206210013858.png
│ ├── image-20231206210101742.png
│ ├── image-20231206210143247.png
│ ├── image-20231206210320245.png
│ ├── image-20231206210430273.png
│ ├── image-20231206210517186.png
│ ├── image-20231206210830493.png
│ ├── image-20231207102813599.png
│ ├── image-20231207102826652.png
│ ├── image-20231208191506535.png
│ ├── image-20231208192239640.png
│ ├── image-20231208192355224.png
│ ├── image-20231222202803391.png
│ └── image-20231222202915406.png
├── intro.md
└── other.md
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── module
├── 0.txt
├── 1.txt
├── 2.txt
├── 3.txt
├── META-INF
│ └── com
│ │ └── google
│ │ └── android
│ │ ├── update-binary
│ │ └── updater-script
├── classes.dex
├── customize.sh
├── module.prop
├── pif.json
├── post-fs-data.sh
├── service.sh
└── zygisk
│ ├── arm64-v8a.so
│ ├── armeabi-v7a.so
│ ├── x86.so
│ └── x86_64.so
├── module_resetprop
├── 0.txt
├── 1.txt
├── 2.txt
├── 3.txt
├── META-INF
│ └── com
│ │ └── google
│ │ └── android
│ │ ├── update-binary
│ │ └── updater-script
├── bin
│ ├── arm64-v8a
│ │ └── resetprop
│ ├── armeabi-v7a
│ │ └── resetprop
│ ├── x86
│ │ └── resetprop
│ └── x86_64
│ │ └── resetprop
├── classes.dex
├── customize.sh
├── module.prop
├── pif.json
├── post-fs-data.sh
├── service.sh
└── zygisk
│ ├── arm64-v8a.so
│ ├── armeabi-v7a.so
│ ├── x86.so
│ └── x86_64.so
├── readme.md
└── settings.gradle.kts
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | bypassKeyAttestation
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/migrations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 | -keep class com.pareto.bypasskeyattestation.EntryPoint {public ;}
23 | -keep class com.pareto.bypasskeyattestation.CustomProvider
24 | -keep class com.pareto.bypasskeyattestation.CustomKeyStoreSpi
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/pareto/bypasskeyattestation/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.pareto.bypasskeyattestation
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.pareto.bypasskeyattestation", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.22.1)
2 |
3 | project("bypassKeyAttestation")
4 |
5 | find_package(cxx REQUIRED CONFIG)
6 |
7 | link_libraries(cxx::cxx)
8 |
9 | add_library(${CMAKE_PROJECT_NAME} SHARED main.cpp)
10 |
11 | add_subdirectory(Dobby)
12 |
13 | SET_OPTION(Plugin.Android.BionicLinkerUtil ON)
14 |
15 | target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE log dobby_static)
--------------------------------------------------------------------------------
/app/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
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/README.md:
--------------------------------------------------------------------------------
1 | ## Dobby
2 |
3 | [](https://t.me/IOFramebuffer) [](https://t.me/dobby_group)
4 |
5 | Dobby a lightweight, multi-platform, multi-architecture exploit hook framework.
6 |
7 | - Minimal and modular library
8 | - Multi-platform support(Windows/macOS/iOS/Android/Linux)
9 | - Multiple architecture support(X86, X86-64, ARM, ARM64)
10 |
11 | ## Compile
12 |
13 | [docs/compile.md](docs/compile.md)
14 |
15 | ## Download
16 |
17 | [download latest library](https://github.com/jmpews/Dobby/releases/tag/latest)
18 |
19 | ## Credits
20 |
21 | 1. [frida-gum](https://github.com/frida/frida-gum)
22 | 2. [minhook](https://github.com/TsudaKageyu/minhook)
23 | 3. [substrate](https://github.com/jevinskie/substrate).
24 | 4. [v8](https://github.com/v8/v8)
25 | 5. [dart](https://github.com/dart-lang/sdk)
26 | 6. [vixl](https://git.linaro.org/arm/vixl.git)
27 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/README_zh-cn.md:
--------------------------------------------------------------------------------
1 | ## Dobby
2 |
3 | **待更新**
--------------------------------------------------------------------------------
/app/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(DobbyRegisterContext *ctx) {
9 | uintptr_t result;
10 | #if defined(_M_X64) || defined(__x86_64__)
11 | #if defined(_WIN32)
12 | result = ctx->general.regs.rcx;
13 | #else
14 | result = ctx->general.regs.rdi;
15 | #endif
16 | #elif defined(__arm64__) || defined(__aarch64__)
17 | result = ctx->general.regs.x0;
18 | #elif defined(__arm__)
19 | result = ctx->general.regs.r0;
20 | #else
21 | #error "Not Support Architecture."
22 | #endif
23 | return result;
24 | }
25 |
26 | void common_handler(DobbyRegisterContext *ctx, const InterceptEntry *info) {
27 | CFStringRef key_ = 0;
28 | key_ = (CFStringRef)getCallFirstArg(ctx);
29 |
30 | char str_key[256] = {0};
31 | CFStringGetCString(key_, str_key, 256, kCFStringEncodingUTF8);
32 | LOG("[#] MGCopyAnswer:: %s\n", str_key);
33 | }
34 |
35 | #if 0
36 | __attribute__((constructor)) static void ctor() {
37 | void *lib = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_NOW);
38 | void *MGCopyAnswer_addr = DobbySymbolResolver("libMobileGestalt.dylib", "MGCopyAnswer");
39 |
40 | sleep(1);
41 |
42 | dobby_enable_near_branch_trampoline();
43 | DobbyInstrument((void *)MGCopyAnswer_addr, common_handler);
44 | dobby_disable_near_branch_trampoline();
45 | }
46 | #endif
47 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ApplicationEventMonitor/memory_operation_instrument.cc:
--------------------------------------------------------------------------------
1 | #include "./dobby_monitor.h"
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | static uintptr_t getCallFirstArg(DobbyRegisterContext *ctx) {
8 | uintptr_t result;
9 | #if defined(_M_X64) || defined(__x86_64__)
10 | #if defined(_WIN32)
11 | result = ctx->general.regs.rcx;
12 | #else
13 | result = ctx->general.regs.rdi;
14 | #endif
15 | #elif defined(__arm64__) || defined(__aarch64__)
16 | result = ctx->general.regs.x0;
17 | #elif defined(__arm__)
18 | result = ctx->general.regs.r0;
19 | #else
20 | #error "Not Support Architecture."
21 | #endif
22 | return result;
23 | }
24 |
25 | void format_integer_manually(char *buf, uint64_t integer) {
26 | int tmp = 0;
27 | for (tmp = (int)integer; tmp > 0; tmp = (tmp >> 4)) {
28 | buf += (tmp % 16);
29 | buf--;
30 | }
31 | }
32 |
33 | // [ATTENTION]:
34 | // printf will call 'malloc' internally, and will crash in a loop.
35 | // so, use 'puts' is a better choice.
36 | void malloc_handler(DobbyRegisterContext *ctx, const InterceptEntry *info) {
37 | size_t size_ = 0;
38 | size_ = getCallFirstArg(ctx);
39 | char *buffer_ = (char *)"[-] function malloc first arg: 0x00000000.\n";
40 | format_integer_manually(strchr(buffer_, '.') - 1, size_);
41 | puts(buffer_);
42 | }
43 |
44 | void free_handler(DobbyRegisterContext *ctx, const InterceptEntry *info) {
45 | uintptr_t mem_ptr;
46 |
47 | mem_ptr = getCallFirstArg(ctx);
48 |
49 | char *buffer = (char *)"[-] function free first arg: 0x00000000.\n";
50 | format_integer_manually(strchr(buffer, '.') - 1, mem_ptr);
51 | puts(buffer);
52 | }
53 |
54 | __attribute__((constructor)) static void ctor() {
55 | // DobbyInstrument((void *)mmap, malloc_handler);
56 | // DobbyInstrument((void *)free, free_handler);
57 | return;
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ApplicationEventMonitor/posix_socket_network_monitor.cc:
--------------------------------------------------------------------------------
1 | #include /* getenv */
2 | #include
3 | #include
4 |
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | std::unordered_map posix_socket_file_descriptors;
16 |
17 | int (*orig_bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
18 | int fake_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
19 | }
20 |
21 | static const char *get_traced_socket(int fd, bool removed) {
22 | std::unordered_map::iterator it;
23 | it = posix_socket_file_descriptors.find(fd);
24 | if (it != posix_socket_file_descriptors.end()) {
25 | if (removed)
26 | posix_socket_file_descriptors.erase(it);
27 | return it->second;
28 | }
29 | return NULL;
30 | }
31 |
32 | int (*orig_connect)(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
33 | int fake_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
34 | const char *traced_socket = get_traced_socket(sockfd, false);
35 | if (traced_socket) {
36 | INFO_LOG("[-] connect: %s\n", traced_socket);
37 | }
38 | return orig_connect(sockfd, addr, addrlen);
39 | }
40 |
41 | ssize_t (*orig_send)(int sockfd, const void *buf, size_t len, int flags);
42 | ssize_t fake_send(int sockfd, const void *buf, size_t len, int flags) {
43 | const char *traced_socket = get_traced_socket(sockfd, false);
44 | if (traced_socket) {
45 | INFO_LOG("[-] send: %s, buf: %p, len: %zu\n", traced_socket, buf, len);
46 | }
47 | return orig_send(sockfd, buf, len, flags);
48 | }
49 |
50 | ssize_t (*orig_recv)(int sockfd, void *buf, size_t len, int flags);
51 | ssize_t fake_recv(int sockfd, void *buf, size_t len, int flags) {
52 | const char *traced_socket = get_traced_socket(sockfd, false);
53 | if (traced_socket) {
54 | INFO_LOG("[-] recv: %s, buf: %p, len: %zu\n", traced_socket, buf, len);
55 | }
56 | return orig_recv(sockfd, buf, len, flags);
57 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/BionicLinkerUtil/bionic_linker_demo.cc:
--------------------------------------------------------------------------------
1 | #include "dobby.h"
2 |
3 | #include "bionic_linker_util.h"
4 |
5 | #include "logging/logging.h"
6 |
7 | #include
8 |
9 | #define LOG_TAG "BionicLinkerUtil"
10 |
11 | __attribute__((constructor)) static void ctor() {
12 | const char *lib = NULL;
13 |
14 | #if defined(__LP64__)
15 | lib = "/system/lib64/libandroid_runtime.so";
16 | #else
17 | lib = "/system/lib/libandroid_runtime.so";
18 | #endif
19 |
20 | void *vm = NULL;
21 |
22 | vm = DobbySymbolResolver(lib, "_ZN7android14AndroidRuntime7mJavaVME");
23 | INFO_LOG("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 | INFO_LOG("vm %p", vm);
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/BionicLinkerUtil/bionic_linker_util.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #endif
8 |
9 | typedef void *soinfo_t;
10 |
11 | soinfo_t linker_dlopen(const char *filename, int flag);
12 |
13 | char *linker_soinfo_get_realpath(soinfo_t soinfo);
14 |
15 | uintptr_t linker_soinfo_to_handle(soinfo_t soinfo);
16 |
17 | void linker_iterate_soinfo(int (*cb)(soinfo_t soinfo));
18 |
19 | void linker_disable_namespace_restriction();
20 |
21 | #ifdef __cplusplus
22 | }
23 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | if (Plugin.ImportTableReplace AND SYSTEM.Darwin)
2 | message(STATUS "[Dobby] Enable got hook")
3 | include_directories(builtin-plugin/ImportTableReplace)
4 | add_subdirectory(builtin-plugin/ImportTableReplace)
5 | endif ()
6 |
7 | if (Plugin.Android.BionicLinkerUtil)
8 | if (NOT SYSTEM.Android)
9 | message(FATAL_ERROR "[!] Plugin.Android.BionicLinkerUtil only works on Android.")
10 | endif ()
11 | message(STATUS "[Dobby] Enable Plugin.Android.BionicLinkerUtil")
12 | set(dobby.plugin.SOURCE_FILE_LIST ${dobby.plugin.SOURCE_FILE_LIST}
13 | BionicLinkerUtil/bionic_linker_util.cc
14 | )
15 | endif ()
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ImportTableReplace/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(dobby_import_replace INTERFACE
2 | dobby_import_replace.cc
3 | )
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ImportTableReplace/dobby_import_replace.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef __cplusplus
4 | extern "C" {
5 | #endif
6 |
7 | // int DobbyImportTableReplace(char *image_name, char *symbol_name, void *fake_func, void **orig_func);
8 |
9 | #ifdef __cplusplus
10 | }
11 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ObjcRuntimeReplace/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(objc_runtime_replace
2 | dobby_objc_runtime_replace.mm
3 | )
4 |
5 | target_link_libraries(objc_runtime_replace
6 | "-framework Foundation"
7 | )
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ObjcRuntimeReplace/dobby_objc_runtime_repalce.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | IMP DobbyObjcReplace(Class _class, SEL _selector, IMP replacement);
11 |
12 | void DobbyObjcReplaceEx(const char *class_name, const char *selector_name, void *fake_impl, void **orig_impl);
13 |
14 | void *DobbyObjcResolveMethodImp(const char *class_name, const char *selector_name);
15 |
16 | #ifdef __cplusplus
17 | }
18 | #endif
19 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/ObjcRuntimeReplace/dobby_objc_runtime_replace.mm:
--------------------------------------------------------------------------------
1 | #include "dobby_objc_runtime_repalce.h"
2 |
3 | #include
4 | #include
5 |
6 | /* clang -rewrite-objc main.m */
7 |
8 | IMP DobbyObjcReplace(Class class_, SEL sel_, IMP fake_impl) {
9 | Method method_ = class_getInstanceMethod(class_, sel_);
10 | if (!method_)
11 | method_ = class_getClassMethod(class_, sel_);
12 |
13 | if (!method_) {
14 | // DEBUG_LOG("Not found class: %s, selector: %s method\n", class_getName(class_), sel_getName(sel_));
15 | return NULL;
16 | }
17 |
18 | return method_setImplementation(method_, (IMP)fake_impl);
19 | }
20 |
21 | void DobbyObjcReplaceEx(const char *class_name, const char *selector_name, void *fake_impl, void **out_orig_impl) {
22 | Class class_ = objc_getClass(class_name);
23 | SEL sel_ = sel_registerName(selector_name);
24 |
25 | Method method_ = class_getInstanceMethod(class_, sel_);
26 | if (!method_) {
27 | method_ = class_getClassMethod(class_, sel_);
28 | if (!method_) {
29 | // ERROR_LOG("Not found class: %s, selector: %s method\n", class_name, selector_name);
30 | return;
31 | }
32 | }
33 |
34 | auto orig_impl = (void *)method_setImplementation(method_, (IMP)fake_impl);
35 | if (out_orig_impl) {
36 | *out_orig_impl = orig_impl;
37 | }
38 | return;
39 | }
40 |
41 | void *DobbyObjcResolveMethodImp(const char *class_name, const char *selector_name) {
42 | Class class_ = objc_getClass(class_name);
43 | SEL sel_ = sel_registerName(selector_name);
44 |
45 | Method method_ = class_getInstanceMethod(class_, sel_);
46 | if (!method_)
47 | method_ = class_getClassMethod(class_, sel_);
48 |
49 | if (!method_) {
50 | // DEBUG_LOG("Not found class: %s, selector: %s method\n", class_name, selector_name);
51 | return NULL;
52 | }
53 | return (void *)method_getImplementation(method_);
54 | }
55 |
--------------------------------------------------------------------------------
/app/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 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/README:
--------------------------------------------------------------------------------
1 | Monitor all supervisor call
--------------------------------------------------------------------------------
/app/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 | }
--------------------------------------------------------------------------------
/app/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 |
--------------------------------------------------------------------------------
/app/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();
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SupervisorCallMonitor/test_supervisor_call_monitor.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "dobby/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
--------------------------------------------------------------------------------
/app/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 AND (NOT DOBBY_BUILD_KERNEL_MODE))
8 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST}
9 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/macho_ctx.cc
10 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/shared_cache_ctx.cpp
11 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/dobby_symbol_resolver.cc
12 |
13 |
14 | ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc
15 | )
16 | endif ()
17 | if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE)
18 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST}
19 | ${CMAKE_CURRENT_SOURCE_DIR}/macho/dobby_symbol_resolver.cc
20 |
21 | ${DOBBY_DIR}/source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc
22 | )
23 | endif ()
24 | if (SYSTEM.Linux OR SYSTEM.Android)
25 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST}
26 | ${CMAKE_CURRENT_SOURCE_DIR}/elf/dobby_symbol_resolver.cc
27 |
28 | ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Linux/ProcessRuntimeUtility.cc
29 | )
30 | endif ()
31 | if (SYSTEM.Windows)
32 | set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST}
33 | ${CMAKE_CURRENT_SOURCE_DIR}/pe/dobby_symbol_resolver.cc
34 |
35 | ${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Windows/ProcessRuntimeUtility.cc
36 | )
37 | endif ()
38 |
39 | add_library(macho_ctx_kit
40 | macho/macho_ctx.h
41 | macho/macho_ctx.cc
42 | )
43 |
44 | add_library(shared_cache_ctx_kit
45 | macho/shared_cache_ctx.h
46 | macho/shared_cache_ctx.cpp
47 | )
48 |
49 | add_library(dobby_symbol_resolver
50 | ${SOURCE_FILE_LIST}
51 | )
52 |
53 |
54 | include_directories(
55 | .
56 | )
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SymbolResolver/dobby_symbol_resolver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if defined(BUILDING_INTERNAL)
4 | #include "macho/dobby_symbol_resolver_priv.h"
5 | #endif
6 |
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 |
11 | void *DobbySymbolResolver(const char *image_name, const char *symbol_name);
12 |
13 | #ifdef __cplusplus
14 | }
15 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver_priv.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "macho_ctx.h"
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SymbolResolver/macho/shared_cache_ctx.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "shared-cache/dyld_cache_format.h"
6 |
7 | #if defined(__LP64__)
8 | typedef struct mach_header_64 mach_header_t;
9 | typedef struct segment_command_64 segment_command_t;
10 | typedef struct section_64 section_t;
11 | typedef struct nlist_64 nlist_t;
12 | #define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT_64
13 | #else
14 | typedef struct mach_header mach_header_t;
15 | typedef struct segment_command segment_command_t;
16 | typedef struct section section_t;
17 | typedef struct nlist nlist_t;
18 | #define LC_SEGMENT_ARCH_DEPENDENT LC_SEGMENT
19 | #endif
20 |
21 | typedef uintptr_t addr_t;
22 |
23 | typedef struct shared_cache_ctx {
24 | struct dyld_cache_header *runtime_shared_cache;
25 | struct dyld_cache_header *mmap_shared_cache;
26 |
27 | uintptr_t runtime_slide;
28 |
29 | bool latest_shared_cache_format;
30 | struct dyld_cache_local_symbols_info *local_symbols_info;
31 | struct dyld_cache_local_symbols_entry *local_symbols_entries;
32 | struct dyld_cache_local_symbols_entry_64 *local_symbols_entries_64;
33 |
34 | nlist_t *symtab;
35 | char *strtab;
36 | } shared_cache_ctx_t;
37 |
38 | int shared_cache_ctx_init(shared_cache_ctx_t *ctx);
39 |
40 | int shared_cache_load_symbols(shared_cache_ctx_t *ctx);
41 |
42 | bool shared_cache_is_contain(shared_cache_ctx_t *ctx, addr_t addr, size_t length);
43 |
44 | int shared_cache_get_symbol_table(shared_cache_ctx_t *ctx, mach_header_t *image_header, nlist_t **out_symtab,
45 | uint32_t *out_symtab_count, char **out_strtab);
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SymbolResolver/mmap_file_util.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | class MmapFileManager {
13 | const char *file_;
14 | uint8_t *mmap_buffer_;
15 | size_t mmap_buffer_size_;
16 |
17 | public:
18 | explicit MmapFileManager(const char *file) : file_(file), mmap_buffer_(nullptr) {
19 | }
20 |
21 | ~MmapFileManager() {
22 | if (mmap_buffer_) {
23 | munmap((void *)mmap_buffer_, mmap_buffer_size_);
24 | }
25 | }
26 |
27 | uint8_t *map() {
28 | size_t file_size = 0;
29 | {
30 | struct stat s;
31 | int rt = stat(file_, &s);
32 | if (rt != 0) {
33 | // printf("mmap %s failed\n", file_);
34 | return NULL;
35 | }
36 | file_size = s.st_size;
37 | }
38 |
39 | return map_options(file_size, 0);
40 | }
41 |
42 | uint8_t *map_options(size_t _size, off_t _off) {
43 | if (!mmap_buffer_) {
44 | int fd = open(file_, O_RDONLY, 0);
45 | if (fd < 0) {
46 | // printf("%s open failed\n", file_);
47 | return NULL;
48 | }
49 |
50 | // auto align
51 | auto mmap_buffer = (uint8_t *)mmap(0, _size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, fd, _off);
52 | if (mmap_buffer == MAP_FAILED) {
53 | // printf("mmap %s failed\n", file_);
54 | return NULL;
55 | }
56 |
57 | close(fd);
58 |
59 | mmap_buffer_ = mmap_buffer;
60 | mmap_buffer_size_ = _size;
61 | }
62 | return mmap_buffer_;
63 | }
64 | };
65 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/builtin-plugin/SymbolResolver/pe/dobby_symbol_resolver.cc:
--------------------------------------------------------------------------------
1 | #include "SymbolResolver/dobby_symbol_resolver.h"
2 | #include "dobby/common.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 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/cmake/Macros.cmake:
--------------------------------------------------------------------------------
1 | macro(SET_OPTION option value)
2 | set(${option} ${value} CACHE INTERNAL "" FORCE)
3 | endmacro()
--------------------------------------------------------------------------------
/app/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 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/cmake/auto_source_group.cmake:
--------------------------------------------------------------------------------
1 | function (auto_source_group _folder _base _pattern)
2 | if (ARGC GREATER 3)
3 | set(_exclude ${ARGN})
4 | else ()
5 | set(_exclude)
6 | endif ()
7 | file (GLOB _files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/ ${_folder}/*)
8 | set (folder_files)
9 | foreach (_fname ${_files})
10 | if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_fname})
11 | auto_source_group ("${_fname}" "${_base}" "${_pattern}" "${_exclude}")
12 | elseif (_fname MATCHES ${_pattern})
13 | if(_exclude)
14 | if (NOT _fname MATCHES ${_exclude})
15 | set(folder_files ${folder_files} ${_fname})
16 | endif ()
17 | else ()
18 | set(folder_files ${folder_files} ${_fname})
19 | endif ()
20 | endif ()
21 | endforeach ()
22 |
23 | string(REPLACE "./" "" _folder2 ${_folder})
24 | string(REPLACE "/" "\\" _folder2 ${_folder2})
25 | if (_folder2 STREQUAL ".")
26 | source_group(${_base} FILES ${folder_files})
27 | else ()
28 | source_group(${_base}\\${_folder2} FILES ${folder_files})
29 | endif ()
30 |
31 | set(AUTO_FILES_RESULT ${AUTO_FILES_RESULT} ${folder_files} PARENT_SCOPE)
32 | endfunction ()
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/cmake/compiler_and_linker.cmake:
--------------------------------------------------------------------------------
1 | # :< You Shall Not Pass!
2 | if (0)
3 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
4 | endif ()
5 |
6 | set(linker_flags "")
7 | if (NOT DOBBY_DEBUG)
8 | set(linker_flags "${linker_flags} -Wl,-x -Wl,-S")
9 | endif ()
10 |
11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions")
12 |
13 | if (SYSTEM.Darwin)
14 | # set(compiler_flags "${compiler_flags} -nostdinc++")
15 | elseif (SYSTEM.Android)
16 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
17 | if (NOT DOBBY_DEBUG)
18 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
19 | set(linker_flags "${linker_flags} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
20 | endif ()
21 | elseif (SYSTEM.Linux)
22 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
23 | if (COMPILER.Clang)
24 | if (PROCESSOR.ARM)
25 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=armv7-unknown-linux-gnueabihf")
26 | elseif (PROCESSOR.ARM64)
27 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=aarch64-unknown-linux-gnu")
28 | elseif (PROCESSOR.X86)
29 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=i686-unknown-linux-gnu")
30 | elseif (PROCESSOR.X86_64)
31 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=x86_64-unknown-linux-gnu")
32 | endif ()
33 | endif ()
34 | elseif (SYSTEM.Windows)
35 | endif ()
36 |
37 | if (NOT DOBBY_DEBUG)
38 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
39 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden")
40 | endif ()
41 |
42 | if (PROCESSOR.ARM)
43 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch armv7 -x assembler-with-cpp")
44 | elseif (PROCESSOR.AARCH64)
45 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch arm64 -x assembler-with-cpp")
46 | endif ()
47 |
48 | # sync cxx with c flags
49 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
50 |
51 | message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
52 | message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
53 | message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
54 | message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
55 | message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")
56 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/cmake/platform/platform-darwin.cmake:
--------------------------------------------------------------------------------
1 | # set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
2 | set(CMAKE_INSTALL_NAME_DIR "@rpath")
3 | set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
4 | add_library(DobbyX ${DOBBY_LIBRARY_TYPE} ${dobby.HEADER_FILE_LIST} ${dobby.SOURCE_FILE_LIST} ${logging.SOURCE_FILE_LIST} ${misc_helper.SOURCE_FILE_LIST} ${dobby.plugin.SOURCE_FILE_LIST})
5 |
6 | set_target_properties(DobbyX
7 | PROPERTIES
8 | LINK_FLAGS "${linker_flags}"
9 | COMPILE_FLAGS "${compiler_flags}"
10 | )
11 |
12 | # set framework property
13 | set_target_properties(DobbyX PROPERTIES
14 | FRAMEWORK TRUE
15 | FRAMEWORK_VERSION A
16 | MACOSX_FRAMEWORK_IDENTIFIER "com.dobby.dobby"
17 | # MACOSX_FRAMEWORK_INFO_PLIST Info.plist
18 | VERSION 1.0.0 # current version
19 | SOVERSION 1.0.0 # compatibility version
20 | PUBLIC_HEADER include/dobby.h
21 | XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development"
22 | )
23 |
24 | if ((SYSTEM.Darwin AND BUILDING_PLUGIN) AND (NOT DOBBY_BUILD_KERNEL_MODE))
25 | add_subdirectory(builtin-plugin/Dyld2HideLibrary)
26 | add_subdirectory(builtin-plugin/ObjcRuntimeHook)
27 | if (PROCESSOR.AARCH64)
28 | add_subdirectory(builtin-plugin/SupervisorCallMonitor)
29 | endif ()
30 | endif()
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/cmake/xcode_generator_helper.cmake:
--------------------------------------------------------------------------------
1 | if(CMAKE_GENERATOR STREQUAL Xcode)
2 | message(STATUS "[*] Detect Xcode Project")
3 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
4 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
6 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/build/Debug)
8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/build/Release)
9 | endif()
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/docs/compile.md:
--------------------------------------------------------------------------------
1 | # Build
2 |
3 | ## CMake build options
4 |
5 | ```
6 | option(DOBBY_GENERATE_SHARED "Build shared library" ON)
7 |
8 | option(DOBBY_DEBUG "Enable debug logging" OFF)
9 |
10 | option(NearBranch "Enable near branch trampoline" ON)
11 |
12 | option(FullFloatingPointRegisterPack "Save and pack all floating-point registers" OFF)
13 |
14 | option(Plugin.SymbolResolver "Enable symbol resolver" ON)
15 |
16 | option(Plugin.ImportTableReplace "Enable import table replace " OFF)
17 |
18 | option(Plugin.Android.BionicLinkerUtil "Enable android bionic linker util" OFF)
19 |
20 | option(DOBBY_BUILD_EXAMPLE "Build example" OFF)
21 |
22 | option(DOBBY_BUILD_TEST "Build test" OFF)
23 | ```
24 |
25 | ## Build with `scripts/platform_builder.py`
26 |
27 | #### Build for iphoneos
28 |
29 | ```shell
30 | python3 scripts/platform_builder.py --platform=iphoneos --arch=all
31 | ```
32 |
33 | #### Build for macos
34 |
35 | ```
36 | python3 scripts/platform_builder.py --platform=macos --arch=all
37 | ```
38 |
39 | #### Build for linux
40 |
41 | ```
42 | # prepare and download cmake/llvm
43 | sh scripts/setup_linux_cross_compile.sh
44 | python3 scripts/platform_builder.py --platform=linux --arch=all --cmake_dir=$HOME/opt/cmake-3.25.2 --llvm_dir=$HOME/opt/llvm-15.0.6
45 | ```
46 |
47 | #### Build for android
48 |
49 | ```
50 | # prepare and download cmake/llvm/ndk
51 | sh scripts/setup_linux_cross_compile.sh
52 | python3 scripts/platform_builder.py --platform=android --arch=all --cmake_dir=$HOME/opt/cmake-3.25.2 --llvm_dir=$HOME/opt/llvm-15.0.6 --android_ndk_dir=$HOME/opt/ndk-r25b
53 | ```
54 |
55 | ## Build with CMake
56 |
57 | #### Build for host
58 |
59 | ```shell
60 | cd Dobby && mkdir cmake-build-host && cd cmake-build-host
61 | cmake ..
62 | make -j4
63 | ```
64 |
65 | ## Build with Android Studio CMake
66 |
67 | ```
68 | if(NOT TARGET dobby)
69 | set(DOBBY_DIR /Users/jmpews/Workspace/Project.wrk/Dobby)
70 | macro(SET_OPTION option value)
71 | set(${option} ${value} CACHE INTERNAL "" FORCE)
72 | endmacro()
73 | SET_OPTION(DOBBY_DEBUG OFF)
74 | SET_OPTION(DOBBY_GENERATE_SHARED OFF)
75 | add_subdirectory(${DOBBY_DIR} dobby)
76 | get_property(DOBBY_INCLUDE_DIRECTORIES
77 | TARGET dobby
78 | PROPERTY INCLUDE_DIRECTORIES)
79 | include_directories(
80 | .
81 | ${DOBBY_INCLUDE_DIRECTORIES}
82 | $
83 | )
84 | endif()
85 |
86 | add_library(native-lib SHARED
87 | ${DOBBY_DIR}/examples/socket_example.cc
88 | native-lib.cpp)
89 | ```
90 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_executable(socket_example
2 | main.cc
3 | socket_example.cc
4 | )
5 |
6 | target_link_libraries(socket_example
7 | dobby
8 | logging
9 | )
10 |
11 |
12 | add_library(socket_example_lib SHARED
13 | socket_example.cc
14 | )
15 |
16 | target_link_libraries(socket_example_lib
17 | dobby
18 | )
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/examples/main.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | int main(int argc, char const *argv[]) {
9 |
10 | std::cout << "Start..." << std::endl;
11 |
12 | sleep(100);
13 | return 0;
14 | }
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/TINYSTL/README:
--------------------------------------------------------------------------------
1 | ref: https://github.com/mendsley/tinystl
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/TINYSTL/algorithm.h:
--------------------------------------------------------------------------------
1 | #pragma once
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/TINYSTL/allocator.h:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright 2012-2018 Matthew Endsley
3 | * All rights reserved
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted providing that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef TINYSTL_ALLOCATOR_H
28 | #define TINYSTL_ALLOCATOR_H
29 |
30 | #include
31 |
32 | namespace tinystl {
33 |
34 | struct allocator {
35 | static void* static_allocate(size_t bytes) {
36 | return operator new(bytes);
37 | }
38 |
39 | static void static_deallocate(void* ptr, size_t /*bytes*/) {
40 | operator delete(ptr);
41 | }
42 | };
43 | }
44 |
45 | #ifndef TINYSTL_ALLOCATOR
46 | # define TINYSTL_ALLOCATOR ::tinystl::allocator
47 | #endif
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/TINYSTL/hash.h:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright 2012-2018 Matthew Endsley
3 | * All rights reserved
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted providing that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef TINYSTL_STRINGHASH_H
28 | #define TINYSTL_STRINGHASH_H
29 |
30 | #include
31 |
32 | namespace tinystl {
33 |
34 | static inline size_t hash_string(const char* str, size_t len) {
35 | // Implementation of sdbm a public domain string hash from Ozan Yigit
36 | // see: http://www.eecs.harvard.edu/margo/papers/usenix91/paper.ps
37 |
38 | size_t hash = 0;
39 | typedef const char* pointer;
40 | for (pointer it = str, end = str + len; it != end; ++it)
41 | hash = *it + (hash << 6) + (hash << 16) - hash;
42 |
43 | return hash;
44 | }
45 |
46 | template
47 | inline size_t hash(const T& value) {
48 | const size_t asint = (size_t)value;
49 | return hash_string((const char*)&asint, sizeof(asint));
50 | }
51 | }
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/TINYSTL/new.h:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright 2012-2018 Matthew Endsley
3 | * All rights reserved
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted providing that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef TINYSTL_NEW_H
28 | #define TINYSTL_NEW_H
29 |
30 | #include
31 |
32 | namespace tinystl {
33 |
34 | struct placeholder {};
35 | }
36 |
37 | inline void* operator new(size_t, tinystl::placeholder, void* ptr) {
38 | return ptr;
39 | }
40 |
41 | inline void operator delete(void*, tinystl::placeholder, void*) throw() {}
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/TINYSTL/stddef.h:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright 2012-2018 Matthew Endsley
3 | * All rights reserved
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted providing that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #ifndef TINYSTL_STDDEF_H
28 | #define TINYSTL_STDDEF_H
29 |
30 | #if defined(_WIN64)
31 | typedef long long unsigned int size_t;
32 | typedef long long int ptrdiff_t;
33 | #elif defined(_WIN32)
34 | typedef unsigned int size_t;
35 | typedef int ptrdiff_t;
36 | #elif defined (__linux__) && defined(__SIZE_TYPE__) && defined(__PTRDIFF_TYPE__)
37 | typedef __SIZE_TYPE__ size_t;
38 | typedef __PTRDIFF_TYPE__ ptrdiff_t;
39 | #else
40 | # include
41 | #endif
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(.)
2 |
3 | if(NOT DOBBY_BUILD_KERNEL_MODE)
4 | set(SOURCE_FILE_LIST
5 | ${CMAKE_CURRENT_SOURCE_DIR}/variable_cache.c
6 | ${CMAKE_CURRENT_SOURCE_DIR}/async_logger.cc
7 | ${CMAKE_CURRENT_SOURCE_DIR}/format_printer.cc
8 | )
9 | else()
10 | set(SOURCE_FILE_LIST
11 | ${CMAKE_CURRENT_SOURCE_DIR}/format_printer.cc
12 | )
13 | endif()
14 |
15 | add_library(misc_helper
16 | ${SOURCE_FILE_LIST}
17 | ${SOURCE_HEADER_LIST}
18 | )
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/async_logger.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | #define aync_logger_buffer_size (20 * 1024 * 1024)
13 | int async_logger_buffer_cursor = 0;
14 | char async_logger_buffer[aync_logger_buffer_size];
15 |
16 | static pthread_mutex_t async_logger_mutex = PTHREAD_MUTEX_INITIALIZER;
17 |
18 | static int output_fd = -1;
19 |
20 | void async_logger_print(char *str) {
21 | pthread_mutex_lock(&async_logger_mutex);
22 | #if 0
23 | {
24 | write(STDOUT_FILENO, str, strlen(str) + 1);
25 | }
26 | #endif
27 | memcpy(async_logger_buffer + async_logger_buffer_cursor, str, strlen(str));
28 | async_logger_buffer_cursor += strlen(str);
29 | pthread_mutex_unlock(&async_logger_mutex);
30 | return;
31 | }
32 |
33 | static void *async_logger_print_impl(void *ctx) {
34 | while (1) {
35 | pthread_mutex_lock(&async_logger_mutex);
36 | if (async_logger_buffer_cursor > 0) {
37 | write(output_fd, async_logger_buffer, async_logger_buffer_cursor);
38 | async_logger_buffer_cursor = 0;
39 | }
40 | pthread_mutex_unlock(&async_logger_mutex);
41 | sleep(1);
42 | }
43 | }
44 |
45 | void async_logger_init(char *logger_path) {
46 | static int async_logger_initialized = 0;
47 | if (async_logger_initialized)
48 | return;
49 | async_logger_initialized = 1;
50 |
51 | // init stdout write lock
52 | pthread_mutex_t write_mutex;
53 | pthread_mutex_init(&write_mutex, NULL);
54 |
55 | output_fd = STDOUT_FILENO;
56 | if (logger_path) {
57 | int fd = open(logger_path, O_CREAT | O_WRONLY | O_TRUNC, 0644);
58 | output_fd = fd;
59 | }
60 |
61 | // init async logger
62 | pthread_mutex_init(&async_logger_mutex, NULL);
63 | pthread_t async_logger_thread;
64 | int ret = pthread_create(&async_logger_thread, NULL, async_logger_print_impl, NULL);
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/deprecated/pthread_helper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * light weight pthread compatible library for Windows
3 | * (C) 2009 Okamura Yasunobu
4 | *
5 | * WARNING This library does NOT support all future of pthread
6 | *
7 | */
8 |
9 | #ifndef CROSS_THREAD_H
10 | #define CROSS_THREAD_H
11 |
12 | #ifdef _WIN32
13 |
14 | #ifdef __cplusplus
15 | extern "C" {
16 | #endif
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | typedef struct pthread_tag {
23 | HANDLE handle;
24 | } pthread_t;
25 |
26 | typedef struct pthread_mutex_tag {
27 | HANDLE handle;
28 | } pthread_mutex_t;
29 |
30 | /* stub */
31 | typedef struct pthread_attr_tag {
32 | int attr;
33 | } pthread_attr_t;
34 |
35 | typedef struct pthread_mutexattr_tag {
36 | int attr;
37 | } pthread_mutexattr_t;
38 |
39 | typedef DWORD pthread_key_t;
40 |
41 | /* ignore attribute */
42 | int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
43 |
44 | /* ignore value_ptr */
45 | void pthread_exit(void *value_ptr);
46 |
47 | /* ignore value_ptr */
48 | int pthread_join(pthread_t thread, void **value_ptr);
49 |
50 | pthread_t pthread_self(void);
51 |
52 | /* do nothing */
53 | int pthread_detach(pthread_t thread);
54 |
55 | /* DO NOT USE */
56 | int pthread_cancel(pthread_t thread);
57 |
58 | int pthread_mutexattr_destroy(pthread_mutexattr_t *attr); /* do nothing */
59 | int pthread_mutexattr_init(pthread_mutexattr_t *attr); /* do nothing */
60 |
61 | int pthread_mutex_destroy(pthread_mutex_t *mutex);
62 | int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
63 | int pthread_mutex_lock(pthread_mutex_t *mutex);
64 | int pthread_mutex_trylock(pthread_mutex_t *mutex);
65 | int pthread_mutex_unlock(pthread_mutex_t *mutex);
66 |
67 | /* ignore deconstructor */
68 | int pthread_key_create(pthread_key_t *key, void (*destr_function)(void *));
69 | int pthread_key_delete(pthread_key_t key);
70 | int pthread_setspecific(pthread_key_t key, const void *pointer);
71 | void *pthread_getspecific(pthread_key_t key);
72 |
73 | #define sleep(num) Sleep(1000 * (num))
74 |
75 | #ifdef __cplusplus
76 | }
77 | #endif
78 |
79 | #else
80 | #include
81 | #include
82 | #define Sleep(num) usleep(num * 1000)
83 | #endif
84 |
85 | #endif /* CROSS_THREAD_H */
86 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/deprecated/unistd_helper.h:
--------------------------------------------------------------------------------
1 | #ifdef _WIN32
2 |
3 | #include
4 | #define open _open
5 | #define read _read
6 | #define O_RDONLY _O_RDONLY
7 | #define O_WRONLY _O_WRONLY
8 | #define O_CREAT _O_CREAT
9 | #define O_TRUNC _O_TRUNC
10 |
11 | #define ssize_t int
12 |
13 | #define STDIN_FILENO 0
14 | #define STDOUT_FILENO 1
15 | #define STDERR_FILENO 2
16 | /* should be in some equivalent to */
17 | typedef __int8 int8_t;
18 | typedef __int16 int16_t;
19 | typedef __int32 int32_t;
20 | typedef __int64 int64_t;
21 | typedef unsigned __int8 uint8_t;
22 | typedef unsigned __int16 uint16_t;
23 | typedef unsigned __int32 uint32_t;
24 | typedef unsigned __int64 uint64_t;
25 |
26 | #else
27 |
28 | #include
29 |
30 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/format_printer.cc:
--------------------------------------------------------------------------------
1 | #include "misc-helper/format_printer.h"
2 |
3 | void hexdump(const uint8_t *bytes, size_t len) {
4 | size_t ix;
5 | for (ix = 0; ix < len; ++ix) {
6 | if (ix != 0 && !(ix % 16))
7 | LOG_FUNCTION_IMPL(0, "\n");
8 | LOG_FUNCTION_IMPL(0, "%02X ", bytes[ix]);
9 | }
10 | LOG_FUNCTION_IMPL(0, "\n");
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/misc-helper/async_logger.h:
--------------------------------------------------------------------------------
1 | #ifndef ASYNC_LOGGER_H
2 | #define ASYNC_LOGGER_H
3 |
4 | void async_logger_print(char *str);
5 |
6 | void async_logger_init(char *logger_path);
7 |
8 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/misc-helper/format_printer.h:
--------------------------------------------------------------------------------
1 | #include "dobby/common.h"
2 |
3 | void hexdump(const uint8_t *bytes, size_t len);
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/deprecated/misc-helper/misc-helper/variable_cache.h:
--------------------------------------------------------------------------------
1 | #ifndef VARIABLE_CACHE_H
2 | #define VARIABLE_CACHE_H
3 |
4 | #include
5 |
6 | #define cache_set stash
7 | void cache_set(const char *name, uint64_t value);
8 |
9 | #define cache_get(x) cache(x)
10 | #define assert_cache(x) (assert(cache(x)), cache(x))
11 | uint64_t cache_get(const char *name);
12 |
13 | int serialized_to_file(const char *filepath);
14 |
15 | int unserialized_from_file(const char *filepath);
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/logging/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | include_directories(.)
2 |
3 | if(NOT DOBBY_BUILD_KERNEL_MODE)
4 | set(SOURCE_FILE_LIST
5 | ${CMAKE_CURRENT_SOURCE_DIR}/logging.cc
6 | )
7 | else()
8 | set(SOURCE_FILE_LIST
9 | ${CMAKE_CURRENT_SOURCE_DIR}/kernel_logging.cc
10 | )
11 | endif()
12 | add_library(logging
13 | ${SOURCE_FILE_LIST}
14 | ${SOURCE_HEADER_LIST}
15 | )
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/logging/kernel_logging.cc:
--------------------------------------------------------------------------------
1 | #include "logging/logging.h"
2 |
3 | #include
4 | #include "utility_macro.h"
5 |
6 | #if defined(BUILDING_KERNEL)
7 | #define abort()
8 | #else
9 | #include
10 | #endif
11 |
12 | static int _log_level = 1;
13 | PUBLIC void log_set_level(int level) {
14 | _log_level = level;
15 | }
16 |
17 | PUBLIC int log_internal_impl(int level, const char *fmt, ...) {
18 | if (level < _log_level)
19 | return 0;
20 |
21 | va_list ap;
22 | va_start(ap, fmt);
23 |
24 | vprintf(fmt, ap);
25 |
26 | va_end(ap);
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/external/osbase/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(osbase STATIC
2 | ${PROJECT_SOURCE_DIR}/source/Backend/UserMode/UnifiedInterface/platform-posix.cc
3 | )
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/scripts/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:focal
2 |
3 | ARG DEBIAN_FRONTEND='noninteractive'
4 |
5 | RUN apt-key adv --keyserver 'keyserver.ubuntu.com' --recv-key 'C99B11DEB97541F0' &&
6 | apt-add-repository -y -u 'https://cli.github.com/packages' &&
7 | apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
8 |
9 | ADD setup_linux_cross_compile.sh /root/setup_linux_cross_compile.sh
10 | RUN sh /root/setup_linux_cross_compile.sh
11 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/scripts/setup_linux_cross_compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -x
4 | set -e
5 |
6 | # sudo dpkg --add-architecture armhf
7 | # sudo dpkg --add-architecture i386
8 | # sudo dpkg --add-architecture arm64
9 | # sudo apt-get -y update
10 | # sudo apt-get -y dist-upgrade
11 | # sudo apt-get -y install git build-essential libssl-dev pkg-config unzip gcc-multilib
12 | # sudo apt-get -y install libc6-armhf-cross libc6-dev-armhf-cross gcc-arm-linux-gnueabihf libssl-dev:armhf
13 | # sudo apt-get -y install libc6-i386-cross libc6-dev-i386-cross gcc-i686-linux-gnu libssl-dev:i386
14 | # sudo apt-get -y install libc6-arm64-cross libc6-dev-arm64-cross gcc-aarch64-linux-gnu libssl-dev:arm64
15 |
16 | sudo apt-get -y update
17 | sudo apt-get -y install aptitude
18 | sudo apt-get -f -y install \
19 | apt-utils \
20 | binutils \
21 | build-essential \
22 | curl \
23 | wget \
24 | unzip \
25 | gcc-multilib \
26 | g++-multilib \
27 | make \
28 | zsh
29 |
30 | sudo apt-get -f -y install gcc g++ libc6-dev
31 | sudo apt-get -f -y install gcc-i686-linux-gnu g++-i686-linux-gnu
32 | sudo apt-get -f -y install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
33 | sudo apt-get -f -y install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
34 |
35 | mkdir -p ~/opt
36 |
37 | cd ~/opt
38 | CMAKE_VERSION=3.25.2
39 | CMAKE_DOWNLOAD_PACKAGE=cmake-$CMAKE_VERSION-linux-x86_64
40 | wget https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/$CMAKE_DOWNLOAD_PACKAGE.tar.gz &&
41 | tar -zxf $CMAKE_DOWNLOAD_PACKAGE.tar.gz >/dev/null &&
42 | mv $CMAKE_DOWNLOAD_PACKAGE cmake-$CMAKE_VERSION
43 | CMAKE_HOME=~/opt/cmake-$CMAKE_VERSION
44 |
45 | cd ~/opt
46 | LLVM_VERSION=15.0.6
47 | LLVM_DOWNLOAD_PACKAGE=clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-18.04
48 | wget https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_DOWNLOAD_PACKAGE.tar.xz &&
49 | tar -xf $LLVM_DOWNLOAD_PACKAGE.tar.xz >/dev/null &&
50 | mv $LLVM_DOWNLOAD_PACKAGE llvm-$LLVM_VERSION
51 | LLVM_HOME=~/opt/llvm-$LLVM_VERSION
52 |
53 | cd ~/opt
54 | NDK_VERSION=r25b
55 | NDK_DOWNLOAD_PACKAGE=android-ndk-$NDK_VERSION-linux
56 | NDK_DOWNLOAD_UNZIP_PACKAGE=android-ndk-$NDK_VERSION
57 | wget https://dl.google.com/android/repository/$NDK_DOWNLOAD_PACKAGE.zip &&
58 | unzip -q $NDK_DOWNLOAD_PACKAGE.zip >/dev/null &&
59 | mv $NDK_DOWNLOAD_UNZIP_PACKAGE ndk-$NDK_VERSION &&
60 | rm $NDK_DOWNLOAD_PACKAGE.zip
61 | ANDROID_NDK_HOME=~/opt/android-ndk-$NDK_VERSION
62 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/scripts/setup_macos_cross_compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | set -x
4 | set -e
5 |
6 | mkdir -p ~/opt
7 |
8 | cd ~/opt
9 | CMAKE_VERSION=3.25.2
10 | CMAKE_DOWNLOAD_PACKAGE=cmake-$CMAKE_VERSION-macos-universal
11 | wget https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/$CMAKE_DOWNLOAD_PACKAGE.tar.gz &&
12 | tar -zxf $CMAKE_DOWNLOAD_PACKAGE.tar.gz >/dev/null &&
13 | mv $CMAKE_DOWNLOAD_PACKAGE cmake-$CMAKE_VERSION
14 | CMAKE_HOME=~/opt/cmake-$CMAKE_VERSION
15 |
16 | cd ~/opt
17 | LLVM_VERSION=15.0.6
18 | LLVM_DOWNLOAD_PACKAGE=clang+llvm-$LLVM_VERSION-x86_64-apple-darwin
19 | wget https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_DOWNLOAD_PACKAGE.tar.xz &&
20 | tar -xf $LLVM_DOWNLOAD_PACKAGE.tar.xz >/dev/null &&
21 | mv $LLVM_DOWNLOAD_PACKAGE llvm-$LLVM_VERSION
22 | LLVM_HOME=~/opt/llvm-$LLVM_VERSION
23 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/KernelMode/ExecMemory/clear-cache-tool-all.c:
--------------------------------------------------------------------------------
1 | void ClearCache(void *start, void *end) {
2 | return;
3 | }
4 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/KernelMode/PlatformUtil/ProcessRuntimeUtility.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "PlatformUnifiedInterface/MemoryAllocator.h"
4 |
5 | #include "UnifiedInterface/platform.h"
6 |
7 | typedef struct _RuntimeModule {
8 | char path[1024];
9 | void *load_address;
10 | } RuntimeModule;
11 |
12 | struct MemRegion : MemRange {
13 | MemoryPermission permission;
14 | MemRegion(addr_t addr, size_t size, MemoryPermission perm) : MemRange(addr, size), permission(perm) {
15 | }
16 | };
17 |
18 | class ProcessRuntimeUtility {
19 | public:
20 | static const tinystl::vector &GetProcessMemoryLayout();
21 |
22 | static const tinystl::vector *GetProcessModuleMap();
23 |
24 | static RuntimeModule GetProcessModule(const char *name);
25 | };
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/KernelMode/UnifiedInterface/exec_mem_placeholder.asm:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define PAGE_SHIFT 14
4 | .align PAGE_SHIFT
5 |
6 | .globl EXT(kernel_executable_memory_placeholder)
7 | EXT(kernel_executable_memory_placeholder):
8 | .rept 0x4000/4
9 | .long 0x41414141
10 | .endr
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/KernelMode/UnifiedInterface/platform.h:
--------------------------------------------------------------------------------
1 | #ifndef PLATFORM_INTERFACE_COMMON_PLATFORM_H
2 | #define PLATFORM_INTERFACE_COMMON_PLATFORM_H
3 |
4 | #include "dobby/common.h"
5 |
6 | // ================================================================
7 | // base :: OSMemory
8 |
9 | enum MemoryPermission { kNoAccess, kRead, kReadWrite, kReadWriteExecute, kReadExecute };
10 |
11 | class OSMemory {
12 | public:
13 | static int PageSize();
14 |
15 | static void *Allocate(size_t size, MemoryPermission access);
16 |
17 | static void *Allocate(size_t size, MemoryPermission access, void *fixed_address);
18 |
19 | static bool Free(void *address, size_t size);
20 |
21 | static bool Release(void *address, size_t size);
22 |
23 | static bool SetPermission(void *address, size_t size, MemoryPermission access);
24 | };
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/UserMode/ExecMemory/clear-cache-tool/clear-cache-tool-arm-dummy.cc:
--------------------------------------------------------------------------------
1 | #ifndef USER_MODE_CLEAR_CACHE_TOOL_H
2 | #define USER_MODE_CLEAR_CACHE_TOOL_H
3 |
4 | #include "core/arch/Cpu.h"
5 |
6 | #include "PlatformInterface/globals.h"
7 |
8 | #if !HOST_OS_IOS
9 | #include // for cache flushing.
10 | #endif
11 |
12 | void CpuFeatures::FlushICache(void *startp, void *endp) {
13 |
14 | #if HOST_OS_IOS
15 | // Precompilation never patches code so there should be no I cache flushes.
16 | CpuFeatures::ClearCache(startp, endp);
17 |
18 | #else
19 |
20 | register uint32_t beg asm("r0") = reinterpret_cast(startp);
21 | register uint32_t end asm("r1") = reinterpret_cast(endp);
22 | register uint32_t flg asm("r2") = 0;
23 |
24 | #ifdef __clang__
25 | // This variant of the asm avoids a constant pool entry, which can be
26 | // problematic when LTO'ing. It is also slightly shorter.
27 | register uint32_t scno asm("r7") = __ARM_NR_cacheflush;
28 |
29 | asm volatile("svc 0\n" : : "r"(beg), "r"(end), "r"(flg), "r"(scno) : "memory");
30 | #else
31 | // Use a different variant of the asm with GCC because some versions doesn't
32 | // support r7 as an asm input.
33 | asm volatile(
34 | // This assembly works for both ARM and Thumb targets.
35 |
36 | // Preserve r7; it is callee-saved, and GCC uses it as a frame pointer for
37 | // Thumb targets.
38 | " push {r7}\n"
39 | // r0 = beg
40 | // r1 = end
41 | // r2 = flags (0)
42 | " ldr r7, =%c[scno]\n" // r7 = syscall number
43 | " svc 0\n"
44 |
45 | " pop {r7}\n"
46 | :
47 | : "r"(beg), "r"(end), "r"(flg), [scno] "i"(__ARM_NR_cacheflush)
48 | : "memory");
49 | #endif
50 | #endif
51 | }
52 |
53 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/UserMode/ExecMemory/code-patch-tool-posix.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "dobby/dobby_internal.h"
3 | #include "core/arch/Cpu.h"
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | #if !defined(__APPLE__)
10 | PUBLIC int DobbyCodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) {
11 | #if defined(__ANDROID__) || defined(__linux__)
12 | int page_size = (int)sysconf(_SC_PAGESIZE);
13 | uintptr_t patch_page = ALIGN_FLOOR(address, page_size);
14 | uintptr_t patch_end_page = ALIGN_FLOOR((uintptr_t)address + buffer_size, page_size);
15 |
16 | // change page permission as rwx
17 | mprotect((void *)patch_page, page_size, PROT_READ | PROT_WRITE | PROT_EXEC);
18 | if (patch_page != patch_end_page) {
19 | mprotect((void *)patch_end_page, page_size, PROT_READ | PROT_WRITE | PROT_EXEC);
20 | }
21 |
22 | // patch buffer
23 | memcpy(address, buffer, buffer_size);
24 |
25 | // restore page permission
26 | mprotect((void *)patch_page, page_size, PROT_READ | PROT_EXEC);
27 | if (patch_page != patch_end_page) {
28 | mprotect((void *)patch_end_page, page_size, PROT_READ | PROT_EXEC);
29 | }
30 |
31 | addr_t clear_start_ = (addr_t)address;
32 | ClearCache((void *)clear_start_, (void *)(clear_start_ + buffer_size));
33 | #endif
34 | return 0;
35 | }
36 |
37 | #endif
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/UserMode/ExecMemory/code-patch-tool-windows.cc:
--------------------------------------------------------------------------------
1 | #include "dobby/dobby_internal.h"
2 |
3 | #include
4 |
5 | using namespace zz;
6 |
7 | PUBLIC int DobbyCodePatch(void *address, uint8_t *buffer, uint32_t buffer_size) {
8 | DWORD oldProtect;
9 | int page_size;
10 |
11 | // Get page size
12 | SYSTEM_INFO si;
13 | GetSystemInfo(&si);
14 | page_size = si.dwPageSize;
15 |
16 | void *addressPageAlign = (void *)ALIGN(address, page_size);
17 |
18 | if (!VirtualProtect(addressPageAlign, page_size, PAGE_EXECUTE_READWRITE, &oldProtect))
19 | return kMemoryOperationError;
20 |
21 | memcpy(address, buffer, buffer_size);
22 |
23 | if (!VirtualProtect(addressPageAlign, page_size, oldProtect, &oldProtect))
24 | return kMemoryOperationError;
25 |
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/UserMode/ExecMemory/substrated/mach_interface_support/substrated.defs:
--------------------------------------------------------------------------------
1 | /*
2 | * Regenerate with:
3 | *
4 | * $(xcrun --sdk macosx -f mig) \
5 | * -isysroot $(xcrun --sdk macosx --show-sdk-path) \
6 | * -sheader substratedserver.h \
7 | * -server substratedserver.c \
8 | * -header substratedclient.h \
9 | * -user substratedclient.c \
10 | * substrated.defs
11 | */
12 |
13 | subsystem substrated 9000;
14 |
15 | #include
16 | #include
17 |
18 | routine substrated_mark(server
19 | : mach_port_t;
20 | task
21 | : vm_task_entry_t;
22 | source_address
23 | : mach_vm_address_t;
24 | source_size
25 | : mach_vm_size_t;
26 | inout target_address
27 | : mach_vm_address_t);
28 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.cpp:
--------------------------------------------------------------------------------
1 | #include "MultiThreadSupport/ThreadSupport.h"
2 |
3 | using namespace zz;
4 |
5 | OSThread::LocalStorageKey ThreadSupport::thread_callstack_key_ = 0;
6 |
7 | // Get current CallStack
8 | CallStack *ThreadSupport::CurrentThreadCallStack() {
9 |
10 | // TODO: __attribute__((destructor)) is better ?
11 | if (!thread_callstack_key_) {
12 | thread_callstack_key_ = OSThread::CreateThreadLocalKey();
13 | }
14 |
15 | if (OSThread::HasThreadLocal(thread_callstack_key_)) {
16 | return static_cast(OSThread::GetThreadLocal(thread_callstack_key_));
17 | } else {
18 | CallStack *callstack = new CallStack();
19 | OSThread::SetThreadLocal(thread_callstack_key_, callstack);
20 | return callstack;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/cpp/Dobby/source/Backend/UserMode/MultiThreadSupport/ThreadSupport.h:
--------------------------------------------------------------------------------
1 | #ifndef USER_MODE_MULTI_THREAD_SUPPORT_H
2 | #define USER_MODE_MULTI_THREAD_SUPPORT_H
3 |
4 | #include
5 | #include