Skip to content

Commit eb215f7

Browse files
committed
ios support
1 parent f6f229b commit eb215f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1172
-317
lines changed

CMakeLists.txt

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,26 @@ set(LINK_OPTION
4545
-Xlinker
4646
-x
4747
)
48+
# Set the target OS (mac or ios), can be overridden with -DTARGET_OS=...
49+
if(NOT DEFINED TARGET_OS)
50+
set(TARGET_OS "mac")
51+
endif()
52+
53+
message(STATUS "🎯 Target OS: ${TARGET_OS}")
54+
55+
if(TARGET_OS STREQUAL "mac")
56+
message(STATUS "Configuring for macOS")
57+
# x86_64;arm64;arm64e
58+
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
59+
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.2")
60+
else()
61+
message(STATUS "Configuring for iOS")
62+
set(CMAKE_SYSTEM_NAME "iOS")
63+
set(CMAKE_OSX_ARCHITECTURES "arm64;arm64e")
64+
set(CMAKE_OSX_DEPLOYMENT_TARGET "18.5")
65+
# set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_SDKROOT "iphoneos")
66+
endif()
4867

49-
# x86_64;arm64;arm64e
50-
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
51-
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.2")
5268

5369
file(GLOB Main ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/*.m)
5470
file(GLOB MainHeader ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/*.h)
@@ -59,19 +75,19 @@ file(GLOB Utils
5975
)
6076
file(GLOB UtilsHeader ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/utils/*.h)
6177

62-
file(GLOB Apps ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/apps/*.m)
63-
file(GLOB AppsHeader ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/apps/*.h)
78+
file(GLOB Apps ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/${TARGET_OS}/apps/*.m)
79+
file(GLOB AppsHeader ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/${TARGET_OS}/apps/*.h)
6480

65-
file(GLOB Helpers ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/helpers/*.m)
66-
file(GLOB HelpersHeader ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/helpers/*.h)
81+
file(GLOB Helpers ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/${TARGET_OS}/helpers/*.m)
82+
file(GLOB HelpersHeader ${CMAKE_SOURCE_DIR}/dylib_dobby_hook/${TARGET_OS}/helpers/*.h)
6783

68-
file(GLOB StaticLibs ${CMAKE_SOURCE_DIR}/libs/*.a)
84+
file(GLOB StaticLibs ${CMAKE_SOURCE_DIR}/libs/${TARGET_OS}/*.a)
6985

7086
include_directories(
7187
${CMAKE_SOURCE_DIR}/dylib_dobby_hook
72-
${CMAKE_SOURCE_DIR}/dylib_dobby_hook/apps
73-
${CMAKE_SOURCE_DIR}/dylib_dobby_hook/helpers
7488
${CMAKE_SOURCE_DIR}/dylib_dobby_hook/utils
89+
${CMAKE_SOURCE_DIR}/dylib_dobby_hook/${TARGET_OS}/apps
90+
${CMAKE_SOURCE_DIR}/dylib_dobby_hook/${TARGET_OS}/helpers
7591
)
7692

7793
add_library(${PROJECT_NAME} SHARED
@@ -180,7 +196,11 @@ target_compile_options(${PROJECT_NAME} PRIVATE ${COMPILE_OPTION})
180196
target_link_options(${PROJECT_NAME} PRIVATE ${LINK_OPTION})
181197

182198
# Xcode 在引入这些库的头文件时会自动加入编译,但是CLion不会,所以需要手动设置一下这个库。
183-
target_link_libraries(${PROJECT_NAME} PUBLIC
199+
200+
201+
if(TARGET_OS STREQUAL "mac")
202+
# Link macOS-specific frameworks
203+
target_link_libraries(${PROJECT_NAME} PUBLIC
184204
"-framework Foundation"
185205
"-framework CoreFoundation"
186206
"-framework AppKit"
@@ -196,7 +216,21 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
196216
c++
197217
c
198218
${StaticLibs}
199-
)
219+
)
220+
else()
221+
# Link iOS-specific frameworks
222+
target_link_libraries(${PROJECT_NAME} PUBLIC
223+
"-framework Foundation"
224+
"-framework CoreFoundation"
225+
"-framework UIKit"
226+
"-framework IOKit"
227+
"-framework CloudKit"
228+
"-framework Security"
229+
c++
230+
c
231+
${StaticLibs}
232+
)
233+
endif()
200234

201235
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
202236
add_definitions(-DDEBUG)

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[English](https://github.com/marlkiller/dylib_dobby_hook/blob/master/README.md) | [中文](https://github.com/marlkiller/dylib_dobby_hook/blob/master/README.zh-CN.md) |[Others..TODO]()
55

66

7-
This project is a macOS dylib project, aiming to enhance software through the use of the Hook framework.
7+
This project is a macOS/IOS dylib project, aiming to enhance software through the use of the Hook framework.
88

99
Development Environment:
1010

@@ -92,11 +92,30 @@ return YES;
9292
9393
### 0x2 Build & Inject
9494
95-
After compilation, we will get our dylib patch.
96-
Then write a shell script to inject.
95+
#### Build
96+
We provide a unified build script that supports both **cmake** and **xcode** build systems, with configurable build type, Hikari support, and target OS.
9797
9898
```shell
99+
# ./build.sh -s xcode -t Debug -h OFF -o mac
100+
usage() {
101+
echo "Usage: $0 [-s cmake|xcode] [-t Debug|Release] [-h ON|OFF] [-o mac|ios]"
102+
echo " -s Build system: cmake (default) or xcode"
103+
echo " -t Build type: Debug or Release (default: Release)"
104+
echo " -h Enable Hikari: ON or OFF (default: OFF)"
105+
echo " -o Target OS: mac (default) or ios"
106+
exit 1
107+
}
108+
```
109+
110+
After compilation, you will obtain the patched dylib output under your specified build path.
111+
112+
113+
#### Inject
99114

115+
Injection is separated into **macOS** and **iOS**.
116+
117+
```shell
118+
# macOS
100119
## Static Injection
101120
cp -f source_bin source_bin_backup
102121
"${insert_dylib}" --weak --all-yes "${YOUR_BUILD_PATH}/libdylib_dobby_hook.dylib" "source_bin_backup" "source_bin"
@@ -108,6 +127,10 @@ cp -f source_bin source_bin_backup
108127
./process_inject "$pid" "${YOUR_BUILD_PATH}/libdylib_dobby_hook.dylib"
109128
```
110129

130+
```shell
131+
# IOS
132+
TODO
133+
```
111134

112135
## Powered by
113136

README.zh-CN.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[English](https://github.com/marlkiller/dylib_dobby_hook/blob/master/README.md) | [中文](https://github.com/marlkiller/dylib_dobby_hook/blob/master/README.zh-CN.md) |[Others..TODO]()
55

66

7-
该项目是一个 macOS dylib 项目,旨在通过 Hook 对软件进行辅助增强。
7+
该项目是一个 macOS/IOS dylib 项目,旨在通过 Hook 对软件进行辅助增强。
88

99
开发环境:
1010

@@ -93,11 +93,29 @@ return YES;
9393
9494
### 0x2 Build & 注入
9595
96-
编译后, 会得到一个我们的 dylib 补丁
97-
然后编写 shell 脚本,来注入
96+
#### Build
97+
我们提供了一个统一的构建脚本,支持 cmake 和 xcode 两种构建系统,并可灵活配置构建类型、是否启用 Hikari 混淆,以及目标操作系统。
9898
9999
```shell
100+
# ./build.sh -s xcode -t Debug -h OFF -o mac
101+
usage() {
102+
echo "Usage: $0 [-s cmake|xcode] [-t Debug|Release] [-h ON|OFF] [-o mac|ios]"
103+
echo " -s Build system: cmake (default) or xcode"
104+
echo " -t Build type: Debug or Release (default: Release)"
105+
echo " -h Enable Hikari: ON or OFF (default: OFF)"
106+
echo " -o Target OS: mac (default) or ios"
107+
exit 1
108+
}
109+
```
110+
111+
完成编译后,你将在指定的构建路径下获得生成的补丁 dylib。
112+
113+
#### Inject
100114

115+
注入分别支持 **macOS****iOS**.
116+
117+
```shell
118+
# macOS
101119
## 静态注入
102120
cp -f source_bin source_bin_backup
103121
"${insert_dylib}" --weak --all-yes "${YOUR_BUILD_PATH}/libdylib_dobby_hook.dylib" "source_bin_backup" "source_bin"
@@ -109,10 +127,14 @@ cp -f source_bin source_bin_backup
109127
./process_inject "$pid" "${YOUR_BUILD_PATH}/libdylib_dobby_hook.dylib"
110128
```
111129

130+
```shell
131+
# IOS
132+
TODO
133+
```
112134

113-
## Sponsor
135+
## Powered by
114136

115-
[![JetBrains](jetbrains.svg)](https://www.jetbrains.com/?from=dylib_dobby_hook "JetBrains")
137+
[![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://jb.gg/OpenSource)
116138

117139
## WARN
118140

build.sh

100644100755
Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,57 @@ set -e
66
BUILD_TYPE="Release"
77
BUILD_SYSTEM="cmake"
88
ENABLE_HIKARI="OFF"
9+
TARGET_OS="mac"
910

11+
# ./build.sh -s xcode -t Debug -h OFF -o ios
1012
usage() {
11-
echo "Usage: $0 [-s cmake|xcode] [-t Debug|Release] [-h ON|OFF]"
13+
echo "Usage: $0 [-s cmake|xcode] [-t Debug|Release] [-h ON|OFF] [-o mac|ios]"
1214
echo " -s Build system: cmake (default) or xcode"
1315
echo " -t Build type: Debug or Release (default: Release)"
1416
echo " -h Enable Hikari: ON or OFF (default: OFF)"
17+
echo " -o Target OS: mac (default) or ios"
1518
exit 1
1619
}
1720

1821
# Parse arguments
19-
while getopts "s:t:h:" opt; do
22+
while getopts "s:t:h:o:" opt; do
2023
case $opt in
2124
s) BUILD_SYSTEM="$OPTARG" ;;
2225
t) BUILD_TYPE="$OPTARG" ;;
2326
h) ENABLE_HIKARI="$OPTARG" ;;
27+
o) TARGET_OS="$OPTARG" ;;
2428
*) usage ;;
2529
esac
2630
done
2731

2832
PROJECT_ROOT=$(pwd)
33+
if [ "$TARGET_OS" = "mac" ]; then
34+
SDK_NAME="macosx"
35+
ARCM_PARAM="-arch arm64 -arch x86_64"
36+
elif [ "$TARGET_OS" = "ios" ]; then
37+
ARCM_PARAM="-arch arm64 -arch arm64e"
38+
SDK_NAME="iphoneos"
39+
else
40+
echo "Unsupported TARGET_OS: $TARGET_OS (must be 'mac' or 'ios')"
41+
exit 1
42+
fi
2943

44+
45+
# xcodebuild -showsdks
46+
# xcrun --sdk iphoneos --show-sdk-path
3047
if [ "$BUILD_SYSTEM" = "xcode" ]; then
31-
echo "🔨 Building with Xcode ($BUILD_TYPE)..."
48+
echo "🔨 Building with Xcode ($BUILD_TYPE) for $TARGET_OS..."
3249
DERIVED_DATA_PATH="$PROJECT_ROOT/xcode-build"
3350
XCODE_ARGS=(
34-
-scheme dylib_dobby_hook
35-
-configuration "$BUILD_TYPE"
36-
-derivedDataPath "$DERIVED_DATA_PATH"
51+
# -scheme "dylib_dobby_hook_$TARGET_OS"
52+
-target "dylib_dobby_hook_$TARGET_OS"
53+
$ARCM_PARAM
54+
# -derivedDataPath "$DERIVED_DATA_PATH"
55+
SYMROOT="$DERIVED_DATA_PATH"
56+
ONLY_ACTIVE_ARCH=NO
57+
CODE_SIGN_IDENTITY=""
58+
CODE_SIGNING_REQUIRED=NO
59+
CODE_SIGNING_ALLOWED=NO
3760
COMPILER_INDEX_STORE_ENABLE=NO
3861
ENABLE_BITCODE=NO
3962
GCC_OPTIMIZATION_LEVEL=0
@@ -57,21 +80,23 @@ if [ "$BUILD_SYSTEM" = "xcode" ]; then
5780
else
5881
echo "ℹ️ Hikari disabled for Xcode."
5982
fi
60-
xcodebuild clean -scheme dylib_dobby_hook -configuration "$BUILD_TYPE" -derivedDataPath "$DERIVED_DATA_PATH"
83+
rm -rf "$$DERIVED_DATA_PATH"
84+
xcodebuild clean -target "dylib_dobby_hook_$TARGET_OS" -configuration "$BUILD_TYPE" SYMROOT="$DERIVED_DATA_PATH"
6185
xcodebuild "${XCODE_ARGS[@]}"
6286
PRODUCT_DYLIB="$DERIVED_DATA_PATH/Build/Products/$BUILD_TYPE/libdylib_dobby_hook.dylib"
6387
echo "✅ Build completed. Product located at: $PRODUCT_DYLIB"
6488

6589
else
66-
echo "🔨 Building with CMake ($BUILD_TYPE)..."
67-
BUILD_DIR="$PROJECT_ROOT/cmake-build-$BUILD_TYPE"
68-
SDK_PATH=$(xcrun --sdk macosx --show-sdk-path)
90+
echo "🔨 Building with CMake ($BUILD_TYPE) for $TARGET_OS..."
91+
BUILD_DIR="$PROJECT_ROOT/cmake-build-$BUILD_TYPE"
92+
SDK_PATH=$(xcrun --sdk "$SDK_NAME" --show-sdk-path)
6993
if [ -z "$SDK_PATH" ]; then
70-
echo "Error: Could not determine macOS SDK path. Is Xcode or Command Line Tools installed correctly?"
94+
echo "Error: Could not determine $SDK_NAME SDK path. Is Xcode or Command Line Tools installed correctly?"
7195
echo "Please ensure Xcode is installed or run 'xcode-select --install'."
7296
exit 1
7397
fi
74-
export MACOS_SDK_ROOT="$SDK_PATH"
98+
export CMAKE_OSX_SYSROOT="$SDK_PATH"
99+
75100
if [ "$ENABLE_HIKARI" = "ON" ]; then
76101
# https://github.com/Aethereux/Hikari-LLVM19/releases/tag/Hikari-LLVM20
77102
#export hikari_llvm_bin="/Applications/Xcode.app/Contents/Developer/Toolchains/Hikari_LLVM20.1.5.xctoolchain/usr/bin"
@@ -83,8 +108,8 @@ else
83108
export hikari_llvm_bin="$PATH_Hikari_XCODE"
84109
echo "Using Hikari LLVM from Xcode path: $hikari_llvm_bin"
85110
# Otherwise, check if the user's Library path exists
86-
elif [ -d "$(eval echo "$PATH_Hikari_USER_LIBRARY")" ]; then # 'eval echo' is needed to expand '~'
87-
export hikari_llvm_bin="$(eval echo "$PATH_Hikari_USER_LIBRARY")"
111+
elif [ -d "$(eval echo \"$PATH_Hikari_USER_LIBRARY\")" ]; then # 'eval echo' is needed to expand '~'
112+
export hikari_llvm_bin="$(eval echo \"$PATH_Hikari_USER_LIBRARY\")"
88113
echo "Using Hikari LLVM from user Library path: $hikari_llvm_bin"
89114
else
90115
echo "Error: No valid path found for Hikari LLVM toolchain."
@@ -107,7 +132,7 @@ else
107132
rm -rf "$BUILD_DIR"
108133
mkdir -p "$BUILD_DIR"
109134
cd "$BUILD_DIR"
110-
cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -DENABLE_HIKARI="$ENABLE_HIKARI" -DCMAKE_OSX_SYSROOT="${MACOS_SDK_ROOT}" "$PROJECT_ROOT"
135+
cmake -DTARGET_OS="$TARGET_OS" -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -DENABLE_HIKARI="$ENABLE_HIKARI" -DCMAKE_OSX_SYSROOT="${CMAKE_OSX_SYSROOT}" "$PROJECT_ROOT"
111136
make -j4
112137
make install
113138
cd "$PROJECT_ROOT"
@@ -141,3 +166,5 @@ echo "✅ The following files have been packed into $ARCHIVE_NAME:"
141166
for file in "${FILES[@]}"; do
142167
echo "- $file"
143168
done
169+
170+
file release/libdylib_dobby_hook.dylib

0 commit comments

Comments
 (0)