forked from jmpews/Dobby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
335 lines (286 loc) · 14.9 KB
/
CMakeLists.txt
File metadata and controls
335 lines (286 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
cmake_minimum_required(VERSION 3.5)
project(HookZz)
include(cmake/Util.cmake)
include(cmake/Globals.cmake)
include(cmake/Macros.cmake)
include(cmake/XcodeGenerator.cmake)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
# ===== Handle Option =====
option(SHARED "Build shared library" OFF)
option(HOOKZZ_DLOG "Enable debug log" OFF)
option(Plugin.DynamicBinaryInstrument "Enable Dynamic Binary Instrument" OFF)
option(Plugin.FunctionWrapper "Enable Function Wrapper, Add PreCall and PostCall for the origin function" OFF)
option(ExtraPlugin.NearBranchTrampoline "Use Near Branch Instead of Ldr Branch in the ARM or ARM64 Architecture, and use Jmp Immediate in the X86_64" OFF)
option(MultiThreadSupport "Enable MultiThreadSupport(For FunctionWrapper Routing Plugin Must be ON)" OFF)
option(CLOSURE_BRIDGE_TEMPLATE "Enable closure bridge assembly template" OFF)
# include(cmake/XcodeGenerator.cmake)
# Use native assembly bridge to replace the runtime codegen
if(CLOSURE_BRIDGE_TEMPLATE)
SET(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
enable_language(ASM)
add_definitions(-DENABLE_CLOSURE_BRIDGE_TEMPLATE)
endif()
# Enable debug will log more infomation
if(HOOKZZ_DEBUG)
add_definitions(-DHOOKZZ_DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
# iOS Simulator Platform
if(HOOKZZ_PLATFORM STREQUAL "SIMULATOR64")
set(SYSTEM.iOS 1)
set(PROCESSOR.X86_64 1)
set(CMAKE_SYSTEM_PROCESSOR X86_64)
endif()
if(SYSTEM.iOS)
# -lstdc++
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
elseif(SYSTEM.Android)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s -Wl,--gc-sections")
elseif(SYSTEM.Linux)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
# if(!PROCESSOR.Detected)
# if(ARCH STREQUAL "arm" OR ARCH STREQUAL "armv7")
# set(CMAKE_SYSTEM_PROCESSOR arm)
# set(PROCESSOR.ARM 1)
# elseif(ARCH STREQUAL "aarch64" OR ARCH STREQUAL "arm64" OR ARCH STREQUAL "armv8")
# set(CMAKE_SYSTEM_PROCESSOR aarch64)
# set(PROCESSOR.AARCH64 1)
# elseif(ARCH STREQUAL "X64" OR ARCH STREQUAL "X86_64" OR ARCH STREQUAL "x64")
# set(CMAKE_SYSTEM_PROCESSOR X86_64)
# set(PROCESSOR.X86_64 1)
# endif()
# endif()
if(COMPILER.Clang)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
if(PROCESSOR.ARM)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch armv7")
elseif(PROCESSOR.AARCH64)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch arm64")
endif()
endif()
# Set Prefix
if(PROCESSOR.ARM)
set(arch1 arm)
set(ARCH1 ARM)
set(arch2 arm)
set(ARCH2 ARM)
elseif(PROCESSOR.AARCH64)
set(ARCH1 ARM64)
set(arch1 arm64)
set(arch2 arm)
set(ARCH2 ARM)
elseif(PROCESSOR.X86)
set(ARCH1 IA32)
set(arch1 ia32)
set(arch2 x86)
set(ARCH2 X86)
elseif(PROCESSOR.X86_64)
set(ARCH1 X64)
set(arch1 x64)
set(arch2 x86)
set(ARCH2 X86)
endif()
set(Target.path .)
set(Target.SOURCE_FILES ${Target.SOURCE_FILES})
# srcxx.core
file(GLOB Target.srcxx.core.arch.FILES ${Target.path}/srcxx/core/arch/*.cc)
source_group(srcxx.core.arch FILES ${Target.srcxx.core.arch.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.core.arch.FILES})
# srcxx.core.arch
file(GLOB Target.srcxx.core.arch.${arch1}.FILES ${Target.path}/srcxx/core/arch/${arch1}/*.cc)
source_group(srcxx.core.arch.${arch1} FILES ${Target.srcxx.core.arch.${arch1}.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.core.arch.${arch1}.FILES})
# srcxx.core.modules.assembler
set(Target.srcxx.core.modules.assembler.FILES
${Target.path}/srcxx/core/modules/assembler/assembler.cc
${Target.path}/srcxx/core/modules/assembler/assembler-${arch1}.cc
)
source_group(srcxx.core.modules.assembler FILES ${Target.srcxx.core.modules.assembler.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.core.modules.assembler.FILES})
# srcxx.core.modules.codegen
set(Target.srcxx.core.modules.codegen.FILES
${Target.path}/srcxx/core/modules/codegen/codegen-${arch1}.cc
)
source_group(srcxx.core.modules.codegen FILES ${Target.srcxx.core.modules.codegen.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.core.modules.codegen.FILES})
# srcxx.ExecMemory
file(GLOB Target.srcxx.ExecMemory.FILES ${Target.path}/srcxx/ExecMemory/*.cc)
source_group(srcxx.ExecMemory FILES ${Target.srcxx.ExecMemory.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.ExecMemory.FILES})
# srcxx.ExecMemory.CodeBuffer
set(Target.srcxx.ExecMemory.CodeBuffer.FILES
${Target.path}/srcxx/ExecMemory/CodeBuffer/CodeBufferBase.cc
${Target.path}/srcxx/ExecMemory/CodeBuffer/code-buffer-${arch1}.cc
)
source_group(srcxx.ExecMemory.CodeBuffer FILES ${Target.srcxx.ExecMemory.CodeBuffer.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.ExecMemory.CodeBuffer.FILES})
#srcxx.ExtraInternalPlugin
if(ExtraPlugin.NearBranchTrampoline)
if(SYSTEM.Linux OR SYSTEM.Android)
set(Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.PlatformUtil.FILES
${Target.path}/srcxx/ExtraInternalPlugin/NearBranchTrampoline/PlatformUtil/Linux/GetProcessMemoryLayout.cc
)
elseif(SYSTEM.Darwin OR SYSTEM.iOS OR SYSTEM.macOS)
set(Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.PlatformUtil.FILES
${Target.path}/srcxx/ExtraInternalPlugin/NearBranchTrampoline/PlatformUtil/Darwin/GetProcessMemoryLayout.cc
)
endif()
if(PROCESSOR.ARM OR PROCESSOR.AARCH64)
set(Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.FILES
${Target.path}/srcxx/ExtraInternalPlugin/NearBranchTrampoline/BxxxBranch/${ARCH1}/BxxxBranchTrampoline.cc
${Target.path}/srcxx/ExtraInternalPlugin/NearBranchTrampoline/SearchCodeChunk.cc
)
elseif(PROCESSOR.X86_64)
set(Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.FILES
${Target.path}/srcxx/ExtraInternalPlugin/NearBranchTrampoline/JmpImmediate32/${ARCH1}/JmpImm32Trampoline.cc
${Target.path}/srcxx/ExtraInternalPlugin/NearBranchTrampoline/SearchCodeChunk.cc
)
endif()
endif()
source_group(ExtraPlugin.NearBranchTrampoline FILES ${Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.FILES})
source_group(ExtraPlugin.NearBranchTrampoline.PlatformUtil FILES ${Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.PlatformUtil.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.ExtraInternalPlugin.NearBranchTrampoline.PlatformUtil.FILES})
# srcxx.InstructionRelocation
file(GLOB Target.srcxx.InstructionRelocation.${arch1}.FILES ${Target.path}/srcxx/InstructionRelocation/${arch1}/*.cc)
source_group(srcxx.InstructionRelocation.${arch1} FILES ${Target.srcxx.InstructionRelocation.${arch1}.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InstructionRelocation.${arch1}.FILES})
if(PROCESSOR.X86 OR PROCESSOR.X86_64)
file(GLOB Target.srcxx.InstructionRelocation.${arch2}.FILES ${Target.path}/srcxx/InstructionRelocation/${arch2}/*.cc)
source_group(srcxx.InstructionRelocation.${arch2} FILES ${Target.srcxx.InstructionRelocation.${arch2}.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InstructionRelocation.${arch2}.FILES})
endif()
# srcxx.InterceptRouting
file(GLOB Target.srcxx.InterceptRouting.FILES ${Target.path}/srcxx/InterceptRouting/*.cpp)
source_group(srcxx.InterceptRouting FILES ${Target.srcxx.InterceptRouting.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InterceptRouting.FILES})
# srcxx.InterceptRoutingTrampoline.arch
file(GLOB Target.srcxx.InterceptRoutingTrampoline.${arch1}.FILES ${Target.path}/srcxx/InterceptRoutingTrampoline/${arch1}/*.cc)
source_group(srcxx.InterceptRoutingTrampoline.${arch1} FILES ${Target.srcxx.InterceptRoutingTrampoline.${arch1}.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InterceptRoutingTrampoline.${arch1}.FILES})
# srcxx.InterceptRoutingPlugin.DynamicBinaryInstrument
if(Plugin.DynamicBinaryInstrument)
set(Target.srcxx.InterceptRoutingPlugin.DynamicBinaryInstrument.FILES
${Target.path}/srcxx/InterceptRoutingPlugin/DynamicBinaryInstrument/helper-arch/helper-${arch1}.cc
${Target.path}/srcxx/InterceptRoutingPlugin/DynamicBinaryInstrument/dynamic-binary-instrument.cc
${Target.path}/srcxx/InterceptRoutingPlugin/DynamicBinaryInstrument/DynamicBinaryInstrumentExport.cc
${Target.path}/srcxx/InterceptRoutingPlugin/DynamicBinaryInstrument/intercept_routing_handler.cc
)
source_group(srcxx.InterceptRoutingPlugin.DynamicBinaryInstrument FILES ${Target.srcxx.InterceptRoutingPlugin.DynamicBinaryInstrument.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InterceptRoutingPlugin.DynamicBinaryInstrument.FILES})
endif()
# srcxx.InterceptRoutingPlugin.FunctionInlineReplace
set(Target.srcxx.InterceptRoutingPlugin.FunctionInlineReplace.FILES
${Target.path}/srcxx/InterceptRoutingPlugin/FunctionInlineReplace/function-inline-replace.cc
${Target.path}/srcxx/InterceptRoutingPlugin/FunctionInlineReplace/FunctionInlineReplaceExport.cc
)
source_group(srcxx.InterceptRoutingPlugin.FunctionInlineReplace FILES ${Target.srcxx.InterceptRoutingPlugin.FunctionInlineReplace.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InterceptRoutingPlugin.FunctionInlineReplace.FILES})
# srcxx.InterceptRoutingPlugin.FunctionWrapper
if(Plugin.FunctionWrapper)
set(Target.srcxx.InterceptRoutingPlugin.FunctionWrapper.FILES
${Target.path}/srcxx/InterceptRoutingPlugin/FunctionWrapper/function-wrapper-${arch1}.cc
${Target.path}/srcxx/InterceptRoutingPlugin/FunctionWrapper/FunctionWrapperExport.cc
${Target.path}/srcxx/InterceptRoutingPlugin/FunctionWrapper/intercept_routing_handler.cc
)
source_group(srcxx.InterceptRoutingPlugin.FunctionWrapper FILES ${Target.srcxx.InterceptRoutingPlugin.FunctionWrapper.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.InterceptRoutingPlugin.FunctionWrapper.FILES})
endif()
# srcxx.InterceptRoutingPlugin.intercept-routing-handler
if(Plugin.FunctionWrapper OR Plugin.DynamicBinaryInstrument)
# srcxx.ClosureTrampolineBridge.closure-trampoline-common-handler
file(GLOB Target.srcxx.ClosureTrampolineBridge.closure-trampoline-common-handler.FILES ${Target.path}/srcxx/ClosureTrampolineBridge/closure-trampoline-common-handler/*.cc)
source_group(srcxx.ClosureTrampolineBridge.closure-trampoline-common-handler FILES ${Target.srcxx.ClosureTrampolineBridge.closure-trampoline-common-handler.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.ClosureTrampolineBridge.closure-trampoline-common-handler.FILES})
# srcxx.ClosureTrampolineBridge.arch
file(GLOB Target.srcxx.ClosureTrampolineBridge.${arch1}.FILES ${Target.path}/srcxx/ClosureTrampolineBridge/${arch1}/*.cc)
source_group(srcxx.ClosureTrampolineBridge.${arch1} FILES ${Target.srcxx.ClosureTrampolineBridge.${arch1}.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.ClosureTrampolineBridge.${arch1}.FILES})
endif()
# srcxx.UserMode.PlatformInterface.Common
if(SYSTEM.Android OR SYSTEM.Linux)
set(Target.srcxx.UserMode.PlatformInterface.Common.FILES
${Target.path}/srcxx/UserMode/PlatformInterface/Common/platform-posix.cc
${Target.path}/srcxx/UserMode/PlatformInterface/Common/platform-posix/extensions-posix.cc
)
set(Target.srcxx.UserMode.ExecMemory.FILES
${Target.path}/srcxx/UserMode/ExecMemory/code-patch-tool-posix.cc
)
if(MultiThreadSupport)
set(Target.srcxx.UserMode.PlatformInterface.Thread.FILES
${Target.path}/srcxx/UserMode/PlatformInterface/Thread/platform-thread-posix.cc
${Target.path}/srcxx/UserMode/PlatformInterface/Thread/PlaformThread.cc
)
endif()
endif()
if(SYSTEM.Darwin OR SYSTEM.iOS OR SYSTEM.macOS)
set(Target.srcxx.UserMode.PlatformInterface.Common.FILES
${Target.path}/srcxx/UserMode/PlatformInterface/Common/platform-posix.cc
${Target.path}/srcxx/UserMode/PlatformInterface/Common/platform-posix/extensions-posix.cc
)
set(Target.srcxx.UserMode.ExecMemory.FILES
${Target.path}/srcxx/UserMode/ExecMemory/code-patch-tool-darwin.cc
)
if(MultiThreadSupport)
set(Target.srcxx.UserMode.PlatformInterface.Thread.FILES
${Target.path}/srcxx/UserMode/PlatformInterface/Thread/platform-thread-posix.cc
${Target.path}/srcxx/UserMode/PlatformInterface/Thread/PlaformThread.cc
)
endif()
endif()
if(SYSTEM.Windows)
set(Target.srcxx.UserMode.PlatformInterface.Common.FILES ${Target.srcxx.UserMode.PlatformInterface.FILES}
${Target.path}/srcxx/UserMode/PlatformInterface/Common/platform-windows.cc
)
set(Target.srcxx.UserMode.ExecMemory.FILES
${Target.path}/srcxx/UserMode/ExecMemory/code-patch-tool-windows.cc
)
if(MultiThreadSupport)
set(Target.srcxx.UserMode.PlatformInterface.Thread.FILES
${Target.path}/srcxx/UserMode/PlatformInterface/Thread/platform-thread-windows.cc
)
endif()
endif()
set(Target.srcxx.UserMode.ExecMemory.FILES ${Target.srcxx.UserMode.ExecMemory.FILES}
${Target.path}/srcxx/UserMode/ExecMemory/clear-cache-tool-all.cc
)
source_group(srcxx.UserMode.ExecMemory FILES ${Target.srcxx.UserMode.ExecMemory.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.UserMode.ExecMemory.FILES})
source_group(srcxx.UserMode.PlatformInterface.Common FILES ${Target.srcxx.UserMode.PlatformInterface.Common.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.UserMode.PlatformInterface.Common.FILES})
source_group(srcxx.UserMode.PlatformInterface.Thread FILES ${Target.srcxx.UserMode.PlatformInterface.Thread.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.UserMode.PlatformInterface.Thread.FILES})
#srcxx
file(GLOB Target.srcxx.FILES ${Target.path}/srcxx/*.cpp)
source_group(srcxx FILES ${Target.srcxx.FILES})
set(Target.SOURCE_FILES ${Target.SOURCE_FILES} ${Target.srcxx.FILES})
include_directories(
${Target.path}
${Target.path}/include
${Target.path}/srcxx
${Target.path}/srcxx/UserMode
${Target.path}/OneLib/logging
${Target.path}/OneLib/stdcxx
${Target.path}/OneLib/include
)
if(SHARED)
# build shared library
add_library(hookzz SHARED ${Target.SOURCE_FILES})
else()
# build static library
add_library(hookzz STATIC ${Target.SOURCE_FILES})
endif()
add_subdirectory(${Target.path}/OneLib)
target_link_libraries(hookzz logging stdcxx)
target_include_directories(hookzz PUBLIC ./include)
if(CMAKE_SYSTEM_NAME MATCHES "^Android")
target_link_libraries(hookzz log)
endif()