Skip to content

Commit 687ff82

Browse files
committed
Fixup logging, remove stl container, cleanup code
1 parent 6f065cf commit 687ff82

File tree

30 files changed

+461
-492
lines changed

30 files changed

+461
-492
lines changed

CMakeLists.txt

+60-37
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(CMAKE_C_STANDARD 11)
1414

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

17-
# ===== handle option =====
17+
# --- options
1818

1919
option(DOBBY_DEBUG "Enable debug logging" OFF)
2020

@@ -28,45 +28,54 @@ option(Plugin.ImportTableReplace "Enable import table replace " OFF)
2828

2929
option(Plugin.Android.BionicLinkerUtil "Enable android bionic linker util" OFF)
3030

31-
option(BUILD_EXAMPLE "Build example" OFF)
31+
option(DOBBY_BUILD_EXAMPLE "Build example" OFF)
3232

33-
option(BUILD_TEST "Build test" OFF)
33+
option(DOBBY_BUILD_TEST "Build test" OFF)
3434

35-
# private
36-
option(Obfuscation "Enable llvm obfuscation" OFF)
35+
# --- private
36+
option(DOBBY_BUILD_KERNEL_MODE "Build xnu kernel mode" OFF)
3737

38-
# private
39-
option(BUILD_KERNEL_MODE "Build xnu kernel mode" OFF)
38+
option(Private.Obfuscation "Enable llvm obfuscation" OFF)
4039

41-
# Enable debug will log more information
4240
if ((NOT DEFINED CMAKE_BUILD_TYPE) OR (CMAKE_BUILD_TYPE STREQUAL "Debug"))
4341
set(DOBBY_DEBUG ON)
4442
endif ()
4543

46-
if (DOBBY_DEBUG)
47-
add_definitions(-DDOBBY_DEBUG)
48-
add_definitions(-DLOGGING_DEBUG)
49-
message(STATUS "[Dobby] Enable debug logging")
50-
endif ()
5144

52-
# Enable full floating point register pack
45+
set(compile_definitions "")
46+
5347
# for arm64, allow access q8 - q31
5448
if (FullFloatingPointRegisterPack)
55-
add_definitions(-DFULL_FLOATING_POINT_REGISTER_PACK)
56-
message(STATUS "[Dobby] Save and pack all floating-point registers")
49+
set(compile_definitions "${compile_definitions} -DFULL_FLOATING_POINT_REGISTER_PACK")
5750
endif ()
5851

59-
if (BUILD_KERNEL_MODE)
60-
set(BUILDING_KERNEL ON)
61-
add_definitions(-DBUILDING_KERNEL)
62-
message(STATUS "[Dobby] Build xnu kernel mode")
52+
if (DOBBY_BUILD_KERNEL_MODE)
53+
set(compile_definitions "${compile_definitions} -DBUILDING_KERNEL")
54+
endif ()
55+
56+
if (DOBBY_DEBUG)
57+
set(compile_definitions "${compile_definitions} -DDOBBY_DEBUG")
58+
else ()
59+
set(compile_definitions "${compile_definitions} -DDOBBY_LOGGING_DISABLE")
6360
endif ()
6461

6562
if (CMAKE_GENERATOR STREQUAL Xcode)
6663
endif ()
6764

6865
include(cmake/compiler_and_linker.cmake)
6966

67+
message(STATUS "[Dobby] CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
68+
message(STATUS "[Dobby] DOBBY_DEBUG: ${DOBBY_DEBUG}")
69+
message(STATUS "[Dobby] NearBranch: ${NearBranch}")
70+
message(STATUS "[Dobby] FullFloatingPointRegisterPack: ${FullFloatingPointRegisterPack}")
71+
message(STATUS "[Dobby] Plugin.SymbolResolver: ${Plugin.SymbolResolver}")
72+
message(STATUS "[Dobby] Plugin.ImportTableReplace: ${Plugin.ImportTableReplace}")
73+
message(STATUS "[Dobby] Plugin.Android.BionicLinkerUtil: ${Plugin.Android.BionicLinkerUtil}")
74+
message(STATUS "[Dobby] DOBBY_BUILD_EXAMPLE: ${DOBBY_BUILD_EXAMPLE}")
75+
message(STATUS "[Dobby] DOBBY_BUILD_TEST: ${DOBBY_BUILD_TEST}")
76+
message(STATUS "[Dobby] DOBBY_BUILD_KERNEL_MODE: ${DOBBY_BUILD_KERNEL_MODE}")
77+
message(STATUS "[Dobby] Private.Obfuscation: ${Private.Obfuscation}")
78+
7079
# ---
7180

7281
include_directories(
@@ -81,7 +90,7 @@ include_directories(
8190
./builtin-plugin
8291
)
8392

84-
if (SYSTEM.Darwin AND BUILDING_KERNEL)
93+
if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE)
8594
include_directories(
8695
source/Backend/KernelMode
8796
)
@@ -168,7 +177,7 @@ set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
168177
source/InterceptEntry.cpp
169178
)
170179

171-
if (SYSTEM.Darwin AND BUILDING_KERNEL)
180+
if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE)
172181
set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
173182
# platform util
174183
source/Backend/KernelMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc
@@ -226,11 +235,11 @@ endif ()
226235

227236
# ---
228237

229-
if (0 AND SYSTEM.iOS AND (NOT BUILDING_KERNEL))
238+
if (0 AND SYSTEM.iOS AND (NOT DOBBY_BUILD_KERNEL_MODE))
230239
include_directories(
231240
source/Backend/UserMode/ExecMemory/substrated
232241
)
233-
add_definitions(-DCODE_PATCH_WITH_SUBSTRATED)
242+
set(compile_definitions "${compile_definitions} -DCODE_PATCH_WITH_SUBSTRATED")
234243
set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
235244
source/Backend/UserMode/ExecMemory/substrated/mach_interface_support
236245
)
@@ -251,7 +260,6 @@ endif ()
251260
# ---
252261

253262
if (NearBranch)
254-
message(STATUS "[Dobby] Enable near branch trampoline")
255263
set(dobby.SOURCE_FILE_LIST ${dobby.SOURCE_FILE_LIST}
256264
source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/near_trampoline_arm64.cc
257265
source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/NearBranchTrampoline.cc
@@ -266,10 +274,10 @@ get_target_property(logging.SOURCE_FILE_LIST logging SOURCES)
266274

267275
# add osbase library
268276
add_subdirectory(external/osbase)
277+
269278
# ---
270279

271280
if (Plugin.SymbolResolver)
272-
message(STATUS "[Dobby] Enable symbol resolver")
273281
include_directories(builtin-plugin/SymbolResolver)
274282
add_subdirectory(builtin-plugin/SymbolResolver)
275283
get_target_property(symbol_resolver.SOURCE_FILE_LIST dobby_symbol_resolver SOURCES)
@@ -301,7 +309,7 @@ if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
301309
endif ()
302310
endif ()
303311
set(DOBBY_BUILD_VERSION "Dobby${VERSION_REVISION}")
304-
add_definitions(-D__DOBBY_BUILD_VERSION__="${DOBBY_BUILD_VERSION}")
312+
set(compile_definitions "${compile_definitions} -D__DOBBY_BUILD_VERSION__=\"${DOBBY_BUILD_VERSION}\"")
305313
message(STATUS "[Dobby] ${DOBBY_BUILD_VERSION}")
306314

307315
# ---
@@ -314,7 +322,9 @@ add_library(dobby SHARED
314322
${dobby.plugin.SOURCE_FILE_LIST}
315323
)
316324

317-
target_include_directories(dobby PUBLIC include)
325+
target_include_directories(dobby PUBLIC
326+
include
327+
)
318328

319329
# ---
320330

@@ -326,16 +336,16 @@ add_library(dobby_static STATIC
326336
${dobby.plugin.SOURCE_FILE_LIST}
327337
)
328338

329-
target_include_directories(dobby_static PUBLIC include)
339+
target_include_directories(dobby_static PUBLIC
340+
include
341+
)
330342

331-
set_target_properties(dobby_static PROPERTIES OUTPUT_NAME "dobby")
343+
set_target_properties(dobby_static
344+
PROPERTIES OUTPUT_NAME "dobby"
345+
)
332346

333347
# ---
334348

335-
if (Obfuscation)
336-
set(linker_flags "${linker_flags} -Wl,-mllvm -Wl,-obfuscator-conf=all")
337-
endif ()
338-
339349
set_target_properties(dobby
340350
PROPERTIES
341351
LINK_FLAGS "${linker_flags}"
@@ -347,6 +357,19 @@ set_target_properties(dobby_static
347357
COMPILE_FLAGS "${compiler_flags}"
348358
)
349359

360+
target_compile_definitions(dobby PRIVATE
361+
"COMPILE_DEFINITIONS ${compile_definitions}"
362+
)
363+
target_compile_definitions(dobby_static PRIVATE
364+
"COMPILE_DEFINITIONS ${compile_definitions}"
365+
)
366+
367+
# ---
368+
369+
if (Private.Obfuscation)
370+
set(linker_flags "${linker_flags} -Wl,-mllvm -Wl,-obfuscator-conf=all")
371+
endif ()
372+
350373
# ---
351374

352375
if (SYSTEM.Android)
@@ -369,16 +392,16 @@ endif ()
369392

370393
# ---
371394

372-
if (BUILD_EXAMPLE AND (NOT BUILDING_KERNEL))
395+
if (DOBBY_BUILD_EXAMPLE AND (NOT DOBBY_BUILD_KERNEL_MODE))
373396
add_subdirectory(examples)
374397
endif ()
375398

376-
if (BUILD_TEST AND (NOT BUILDING_KERNEL))
399+
if (DOBBY_BUILD_TEST AND (NOT DOBBY_BUILD_KERNEL_MODE))
377400
add_subdirectory(tests)
378401
endif ()
379402

380403
# ---
381404

382-
if (SYSTEM.Darwin AND (NOT BUILDING_KERNEL))
405+
if (SYSTEM.Darwin AND (NOT DOBBY_BUILD_KERNEL_MODE))
383406
include(cmake/platform/platform-darwin.cmake)
384407
endif ()

builtin-plugin/SymbolResolver/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (NOT DEFINED DOBBY_DIR)
44
message(FATAL_ERROR "DOBBY_DIR must be set!")
55
endif ()
66

7-
if (SYSTEM.Darwin AND (NOT BUILDING_KERNEL))
7+
if (SYSTEM.Darwin AND (NOT DOBBY_BUILD_KERNEL_MODE))
88
set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST}
99
${CMAKE_CURRENT_SOURCE_DIR}/macho/macho_ctx.cc
1010
${CMAKE_CURRENT_SOURCE_DIR}/macho/shared_cache_ctx.cpp
@@ -14,7 +14,7 @@ if (SYSTEM.Darwin AND (NOT BUILDING_KERNEL))
1414
${DOBBY_DIR}/source/Backend/UserMode/PlatformUtil/Darwin/ProcessRuntimeUtility.cc
1515
)
1616
endif ()
17-
if (SYSTEM.Darwin AND BUILDING_KERNEL)
17+
if (SYSTEM.Darwin AND DOBBY_BUILD_KERNEL_MODE)
1818
set(SOURCE_FILE_LIST ${SOURCE_FILE_LIST}
1919
${CMAKE_CURRENT_SOURCE_DIR}/macho/dobby_symbol_resolver.cc
2020

builtin-plugin/SymbolResolver/macho/dobby_symbol_resolver.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@
2424

2525
PUBLIC void *DobbySymbolResolver(const char *image_name, const char *symbol_name_pattern) {
2626
uintptr_t result = 0;
27-
const std::vector<RuntimeModule> modules = ProcessRuntimeUtility::GetProcessModuleMap();
27+
auto modules = ProcessRuntimeUtility::GetProcessModuleMap();
2828

2929
for (auto iter = modules.begin(); iter != modules.end(); iter++) {
3030
auto module = *iter;
31-
if (image_name != NULL && strnstr(module.path, image_name, strlen(module.path)) == NULL)
31+
32+
// image filter
33+
if (image_name && !strstr(module.path, image_name))
34+
continue;
35+
36+
// dyld in shared cached at new os version
37+
// ignore dyld, as some functions as own implementation in dyld
38+
if (!image_name && strstr(module.path, "dyld"))
3239
continue;
3340

3441
auto header = (mach_header_t *)module.load_address;
@@ -102,7 +109,7 @@ PUBLIC void *DobbySymbolResolver(const char *image_name, const char *symbol_name
102109
#endif
103110

104111
if (result == 0) {
105-
LOG(LOG_LEVEL_DEBUG, "symbol resolver failed: %s", symbol_name_pattern);
112+
DEBUG_LOG("symbol resolver failed: %s", symbol_name_pattern);
106113
}
107114

108115
return (void *)result;

cmake/compiler_and_linker.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ if (NOT DOBBY_DEBUG)
88
set(linker_flags "${linker_flags} -Wl,-x -Wl,-S")
99
endif ()
1010

11+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions")
12+
1113
if (SYSTEM.Darwin)
1214
# set(compiler_flags "${compiler_flags} -nostdinc++")
1315
elseif (SYSTEM.Android)

cmake/platform/platform-darwin.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set_target_properties(DobbyX PROPERTIES
2121
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development"
2222
)
2323

24-
if ((SYSTEM.Darwin AND BUILDING_PLUGIN) AND (NOT BUILDING_KERNEL))
24+
if ((SYSTEM.Darwin AND BUILDING_PLUGIN) AND (NOT DOBBY_BUILD_KERNEL_MODE))
2525
add_subdirectory(builtin-plugin/Dyld2HideLibrary)
2626
add_subdirectory(builtin-plugin/ObjcRuntimeHook)
2727
if (PROCESSOR.AARCH64)

docs/compile.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ option(Plugin.ImportTableReplace "Enable import table replace " OFF)
1717
1818
option(Plugin.Android.BionicLinkerUtil "Enable android bionic linker util" OFF)
1919
20-
option(BUILD_EXAMPLE "Build example" OFF)
20+
option(DOBBY_BUILD_EXAMPLE "Build example" OFF)
2121
22-
option(BUILD_TEST "Build test" OFF)
22+
option(DOBBY_BUILD_TEST "Build test" OFF)
2323
```
2424

2525
## Build with `scripts/platform_builder.py`

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_executable(socket_example
55

66
target_link_libraries(socket_example
77
dobby
8+
logging
89
)
910

1011

external/TINYSTL/algorithm.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#pragma once

0 commit comments

Comments
 (0)