From 0df5b4e72c7f81883ef1a64f32aff3aa512dc0bc Mon Sep 17 00:00:00 2001 From: Thatchapon Unprasert Date: Sat, 25 Jan 2025 12:42:14 +0700 Subject: [PATCH] Add simulator version of CydiaSubstrate.tbd --- CydiaSubstrate.tbd | 11 +++++++++++ README.md | 2 ++ installsubstrate.sh | 23 +++++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 CydiaSubstrate.tbd diff --git a/CydiaSubstrate.tbd b/CydiaSubstrate.tbd new file mode 100644 index 0000000..9510dca --- /dev/null +++ b/CydiaSubstrate.tbd @@ -0,0 +1,11 @@ +--- !tapi-tbd +tbd-version: 4 +targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios, i386-ios-simulator, x86_64-ios-simulator, arm64-ios-simulator ] +install-name: '/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate' +exports: + - targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios, i386-ios-simulator, x86_64-ios-simulator, arm64-ios-simulator ] + symbols: [ _MSCloseImage, _MSDebug, _MSFindAddress, _MSFindSymbol, + _MSGetImageByName, _MSHookClassPair, _MSHookFunction, + _MSHookMemory, _MSHookMessageEx, _MSImageAddress, + _MSMapImage ] +... diff --git a/README.md b/README.md index defbb5b..ec0aa59 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ rm -rfv /tmp/simject_cycript /tmp/simject_cycript.zip 2. Note that, from the step 1, you can symlink instead of copying `CydiaSubstrate.framework` to multiple places. This is what `installsubstrate.sh` does to ease your life. +3. By default, tweaks built for simulator will not use CydiaSubstrate as logos is configured to generate hooking code using only internal Objective-C runtime methods. While hooking via `%hook` works regardless of generators, hooking via `%hookf` is not supported unless you explicitly specify the logos generator to be `MobileSubstrate` (or `libhooker`) by using [%config](https://theos.dev/docs/logos-syntax). For example, if you want to use CydiaSubstrate for hooking, add `%config(generator=MobileSubstrate)` to your `Tweak.x(m)`. Lastly, to build simulator tweaks successfully, copy `CydiaSubstrate.tbd` from this project to `$THEOS/vendor/lib/CydiaSubstrate.framework` and replace the existing one. Make a backup if necessary. + ### simject usage 1. Place your dynamic libraries and accompanying property lists inside `/opt/simject` to load them in the iOS Simulator. Do not delete `simject.plist` and `simject.dylib`. diff --git a/installsubstrate.sh b/installsubstrate.sh index 1ed2c51..a41425e 100755 --- a/installsubstrate.sh +++ b/installsubstrate.sh @@ -13,6 +13,8 @@ then echo -e "This will install cycript's CydiaSubstrate\n" echo -e "If you only want to symlink CydiaSubstrate.framework to new iOS runtimes, you can run:\n" echo -e "\t./installsubstrate.sh link\n" + echo -e "If you are developing simulator tweaks that utilize MSHookFunction, you can install the simulator-supported version of CydiaSubstrate.tbd (tbd v4) by running:\n" + echo -e "\t./installsubstrate.sh theos\n" exit 1 fi @@ -29,9 +31,26 @@ SJ_RUNTIME_ROOT_11_BETA=/Applications/Xcode-beta.app/Contents/Developer/Platform SJ_PATH=/opt/simject SJ_FW_PATH=${SJ_PATH}/Frameworks mkdir -p ${SJ_FW_PATH} -cd ${SJ_FW_PATH} -if [[ $1 = "link" ]] +if [[ $1 = "theos" ]] +then + CS_FW_PATH="$THEOS/vendor/lib/CydiaSubstrate.framework" + if [[ ! -d $CS_FW_PATH ]] + then + echo "Error: CydiaSubstrate.framework not found in ${CS_FW_PATH}" + exit 1 + fi + if [[ -f $CS_FW_PATH/CydiaSubstrate.tbd.bak ]] + then + echo "Notice: CydiaSubstrate.tbd has already been backed up, skipping" + exit 0 + fi + echo "Backing up CydiaSubstrate.tbd..." + mv $CS_FW_PATH/CydiaSubstrate.tbd $CS_FW_PATH/CydiaSubstrate.tbd.bak + echo "Copying the new CydiaSubstrate.tbd to $CS_FW_PATH..." + cp $SELF_DIR/CydiaSubstrate.tbd $CS_FW_PATH/ + exit 0 +elif [[ $1 = "link" ]] then if [[ ! -d CydiaSubstrate.framework ]] then