Skip to content

Commit

Permalink
Refactor? Yes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmpews committed Apr 25, 2023
1 parent e9fe7fb commit a588a0d
Show file tree
Hide file tree
Showing 129 changed files with 1,944 additions and 2,668 deletions.
125 changes: 30 additions & 95 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,121 +1,56 @@
{
"files.autoSave": "onFocusChange",
"files.autoSaveDelay": 3000,
"editor.formatOnSave": true,
"cmake.environment": {
"ANDROID_NDK": "/Users/jmpews/Library/Android/sdk/ndk-bundle"
},
"cmake.configureArgs": [
"-DCMAKE_SYSTEM_NAME=Android",
"-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a",
"-DCMAKE_ANDROID_NDK=/Users/jmpews/Library/Android/sdk/ndk/21.3.6528147",
"-DCMAKE_SYSTEM_VERSION=16",
"-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang"
"-DCMAKE_OSX_ARCHITECTURES=arm64",
"-DCMAKE_SYSTEM_PROCESSOR=arm64",
"-DDOBBY_BUILD_SILICON=ON",
"-DCMAKE_VERBOSE_MAKEFILE=ON"

],
"cmake.buildArgs": [],
"cmake.buildToolArgs": [],
"cmake.parallelJobs": 1,
"cmake.generator": "Ninja",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
"stack": "cpp",
"regex": "cpp",
"bitset": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"*.d": "c",
"filesystem": "cpp",
"ios": "c",
"__bit_reference": "cpp",
"__functional_base": "cpp",
"algorithm": "cpp",
"__node_handle": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"cstddef": "cpp",
"deque": "cpp",
"optional": "cpp",
"__memory": "cpp",
"limits": "cpp",
"locale": "cpp",
"optional": "cpp",
"ratio": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"vector": "cpp",
"utility": "cpp",
"__functional_03": "cpp",
"variant": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"__locale": "cpp",
"__hash_table": "cpp",
"__split_buffer": "cpp",
"__tree": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"array": "cpp",
"initializer_list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"stack": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"initializer_list": "cpp",
"hashtable": "cpp",
"__config": "cpp",
"__nullptr": "cpp",
"cstddef": "cpp",
"exception": "cpp",
"new": "cpp",
"stdexcept": "cpp",
"typeinfo": "cpp",
"*.tcc": "cpp",
"xstring": "cpp",
"xlocmon": "cpp",
"xtr1common": "cpp",
"list": "cpp",
"xhash": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"iosfwd": "cpp",
"__debug": "cpp",
"__mutex_base": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tuple": "cpp",
"cctype": "cpp",
"cstdarg": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"ios": "cpp",
"iostream": "cpp",
"istream": "cpp",
"mutex": "cpp",
"ostream": "cpp",
"streambuf": "cpp",
"cmath": "cpp",
"array": "cpp",
"fstream": "cpp",
"stdio.h": "c",
"__functional_base_03": "cpp",
"filesystem": "cpp",
"queue": "cpp",
"random": "cpp",
"__errc": "cpp",
"__node_handle": "cpp",
"bit": "cpp",
"complex": "cpp",
"iomanip": "cpp",
"sstream": "cpp",
"stdarg.h": "c",
"clocale": "cpp",
"codecvt": "cpp",
"condition_variable": "cpp",
"numeric": "cpp",
"shared_mutex": "cpp",
"thread": "cpp",
"memory_resource": "cpp",
"cinttypes": "cpp",
"shared_cache_internal.h": "c",
"coroutine": "cpp",
"__bits": "cpp"
"string": "cpp",
"string_view": "cpp"
},
"C_Cpp.configurationWarnings": "Disabled",
"cSpell.words": [
"ringbuffer",
"sysent"
],
"lldb.verboseLogging": true,
"lldb.showDisassembly": "auto",
"lldb.dereferencePointers": true,
"lldb.consoleMode": "commands",
"debug.toolBarLocation": "docked"
}
48 changes: 19 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ include(cmake/build_environment_check.cmake)
include(cmake/auto_source_group.cmake)
include(cmake/xcode_generator_helper.cmake)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD 17)

auto_source_group("." "auto-source-group" "\\.(cc|cpp|c|h)$")

Expand Down Expand Up @@ -59,6 +59,8 @@ else ()
set(compile_definitions "${compile_definitions} -DDOBBY_LOGGING_DISABLE")
endif ()

set(compile_definitions "${compile_definitions} -DBUILD_WITH_TRAMPOLINE_ASM")

if (CMAKE_GENERATOR STREQUAL Xcode)
endif ()

Expand Down Expand Up @@ -101,26 +103,18 @@ endif ()
set(DOBBY_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
# cpu
source/core/arch/CpuFeature.cc
source/core/arch/CpuRegister.cc

# assembler
source/core/assembler/assembler.cc
source/core/assembler/assembler-arm.cc
source/core/assembler/assembler-arm64.cc
source/core/assembler/assembler-ia32.cc
source/core/assembler/assembler-x64.cc

# codegen
source/core/codegen/codegen-arm.cc
source/core/codegen/codegen-arm64.cc
source/core/codegen/codegen-ia32.cc
source/core/codegen/codegen-x64.cc

# memory kit
source/MemoryAllocator/CodeBuffer/CodeBufferBase.cc
source/MemoryAllocator/AssemblyCodeBuilder.cc
source/MemoryAllocator/MemoryAllocator.cc

# instruction relocation
source/InstructionRelocation/arm/InstructionRelocationARM.cc
Expand All @@ -131,23 +125,29 @@ set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
source/InstructionRelocation/x86/x86_insn_decode/x86_insn_decode.c

# intercept routing
source/InterceptRouting/InterceptRouting.cpp
source/InterceptRouting/InterceptRouting.h
source/InterceptRouting/InlineHookRouting.h
source/InterceptRouting/InstrumentRouting.h
source/InterceptRouting/RoutingPlugin.h
source/InterceptRouting/InstrumentRouting/instrument_routing_handler.cpp
source/InterceptRouting/NearBranchTrampoline/NearBranchTrampoline.h

# intercept routing trampoline
source/TrampolineBridge/Trampoline/arm/trampoline_arm.cc
source/TrampolineBridge/Trampoline/arm64/trampoline_arm64.cc
source/TrampolineBridge/Trampoline/x86/trampoline_x86.cc
source/TrampolineBridge/Trampoline/x64/trampoline_x64.cc
source/TrampolineBridge/Trampoline/trampoline_arm.cc
source/TrampolineBridge/Trampoline/trampoline_arm64.cc
source/TrampolineBridge/Trampoline/trampoline_x86.cc
source/TrampolineBridge/Trampoline/trampoline_x64.cc

# closure trampoline bridge - arm
source/TrampolineBridge/ClosureTrampolineBridge/common_bridge_handler.cc
source/TrampolineBridge/ClosureTrampolineBridge/arm/helper_arm.cc
source/TrampolineBridge/ClosureTrampolineBridge/arm/closure_bridge_arm.cc
source/TrampolineBridge/ClosureTrampolineBridge/arm/ClosureTrampolineARM.cc
# closure trampoline bridge - arm64
source/TrampolineBridge/ClosureTrampolineBridge/arm64/helper_arm64.cc
source/TrampolineBridge/ClosureTrampolineBridge/arm64/closure_bridge_arm64.cc
source/TrampolineBridge/ClosureTrampolineBridge/arm64/ClosureTrampolineARM64.cc
source/TrampolineBridge/ClosureTrampolineBridge/arm64/closure_bridge_arm64.asm
source/TrampolineBridge/ClosureTrampolineBridge/arm64/closure_trampoline_arm64.asm
# closure trampoline bridge - x86
source/TrampolineBridge/ClosureTrampolineBridge/x86/helper_x86.cc
source/TrampolineBridge/ClosureTrampolineBridge/x86/closure_bridge_x86.cc
Expand All @@ -157,20 +157,10 @@ set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
source/TrampolineBridge/ClosureTrampolineBridge/x64/closure_bridge_x64.cc
source/TrampolineBridge/ClosureTrampolineBridge/x64/ClosureTrampolineX64.cc

source/InterceptRouting/Routing/InstructionInstrument/InstructionInstrument.cc
source/InterceptRouting/Routing/InstructionInstrument/RoutingImpl.cc
source/InterceptRouting/Routing/InstructionInstrument/instrument_routing_handler.cc

source/InterceptRouting/Routing/FunctionInlineHook/FunctionInlineHook.cc
source/InterceptRouting/Routing/FunctionInlineHook/RoutingImpl.cc

# plugin register
source/InterceptRouting/RoutingPlugin/RoutingPlugin.cc

# main
source/dobby.cpp
source/Interceptor.cpp
source/InterceptEntry.cpp
)


Expand Down Expand Up @@ -236,9 +226,8 @@ endif ()

if (NearBranch)
set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/near_trampoline_arm64.cc
source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/NearBranchTrampoline.cc
source/MemoryAllocator/NearMemoryAllocator.cc)
source/InterceptRouting/NearBranchTrampoline/near_trampoline_arm64.cc
)
endif ()

# ---
Expand Down Expand Up @@ -336,6 +325,7 @@ set_target_properties(dobby_static

target_compile_definitions(dobby PRIVATE
"COMPILE_DEFINITIONS ${compile_definitions}"
-DBUILD_WITH_TRAMPOLINE_ASM
)
target_compile_definitions(dobby_static PRIVATE
"COMPILE_DEFINITIONS ${compile_definitions}"
Expand Down
4 changes: 2 additions & 2 deletions builtin-plugin/ApplicationEventMonitor/MGCopyAnswerMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ __attribute__((constructor)) static void ctor() {

sleep(1);

dobby_enable_near_branch_trampoline();
dobby_enable_near_trampoline();
DobbyInstrument((void *)MGCopyAnswer_addr, common_handler);
dobby_disable_near_branch_trampoline();
dobby_disable_near_trampoline();
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ void supervisor_call_monitor_init() {
INFO_LOG("HOME: %s", logger_path);
async_logger_init(logger_path);

dobby_enable_near_branch_trampoline();
dobby_enable_near_trampoline();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PUBLIC void *DobbySymbolResolver(const char *image_name, const char *symbol_name
if (!image_name && strstr(module.path, "dyld"))
continue;

auto header = (mach_header_t *)module.load_address;
auto header = (mach_header_t *)module.base;
if (header == nullptr)
continue;

Expand Down
2 changes: 1 addition & 1 deletion cmake/compiler_and_linker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (NOT DOBBY_DEBUG)
set(linker_flags "${linker_flags} -Wl,-x -Wl,-S")
endif ()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-stack-protector")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fPIC -fno-stack-check -fno-stack-protector -fno-exceptions -fno-rtti -fno-common -fno-zero-initialized-in-bss")

if (SYSTEM.Darwin)
# set(compiler_flags "${compiler_flags} -nostdinc++")
Expand Down
11 changes: 11 additions & 0 deletions common/hex_log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "logging/logging.h"
#include <string.h>

inline void debug_hex_log_buffer(const uint8_t *buffer, uint32_t buffer_size) {
char print_buf[1024] = {0};
for (int i = 0; i < buffer_size && i < sizeof(print_buf); i++) {
snprintf(print_buf + strlen(print_buf), sizeof(print_buf) - strlen(print_buf), "%02x ", *((uint8_t *)buffer + i));
}
print_buf[sizeof(print_buf) - 1] = 0;
DEBUG_LOG("%s", print_buf);
};
Loading

0 comments on commit a588a0d

Please sign in to comment.