Log

Theos入門

1.Summary

  • Theosとは??

  • 環境構築

  • ModMenuのTemplateを利用して、テストTweakアプリケーションを作成してみる

2.Detail

2-1. Theosとは??
  • Theosは脱獄ソフトウェアの開発ツール

  • Tweakの開発とTweakのビルドをすることができる

  • テーマなど色々脱獄系のアプリケーションを開発することができる

2-2.開発環境

iPhone8(iOS12.2 with jailbroken) MacBookPro(Catalina version 10.15.7)

2-3.環境構築(Mac編)

Theosを使う方法としてiOS上で作成する方法と、MacなどのOS上で作成したものをiOSに入れる方法の2種類ある。 今回はMaciOSで2種類での環境構築を行う

まずはTheosをMacにインストールする、いくつか必要なものをMacへインストール

yotti ->brew install ldid xz
yotti ->echo "export THEOS=~/theos" >> ~/.bash_profile
yotti ->source ~/.bash_profile

~/theosにpathが通ったら, gitからtheosを~/theosへコピーする

yotti -> git clone --recursive https://github.com/theos/theos.git $THEOS

必要なSDKなどをgitから持ってくる

curl -LO https://github.com/theos/sdks/archive/master.zip
TMP=$(mktemp -d)
unzip master.zip -d $TMP
mv $TMP/sdks-master/*.sdk $THEOS/sdks
rm -r master.zip $TMP
2-3.環境構築(iOS編)

基本的には上記の手順で十分だが、theosの良い点としてiOS単体で開発できるということが挙げられる。 なのでwindowsのみしか持っていない人でも Tweakの開発が行える。前提のとして端末の脱獄とOpenSSHなど入れる必要があるがそこは割愛する cydiaに以下のレポジトリを追加する http://repo.bingner.com/

iOStoolcahinとTheos Dependenciesを追加する。これはTheosを使うためのclangやビルドするためのllvm環境のインストールする必要ためである

f:id:yottiii:20201215230058j:plain:w300

f:id:yottiii:20201215233022j:plain:w300

必要であればswiftToolchainmo追加しておく

f:id:yottiii:20201215233112j:plain:w300

先ほど同様、gitからファイルを持ってきたりSDKを入れたりする

git clone --recursive https://github.com/theos/theos.git $THEOS
curl -LO https://github.com/theos/sdks/archive/master.zip
TMP=$(mktemp -d)
unzip master.zip -d $TMP
mv $TMP/sdks-master/*.sdk $THEOS/sdks
rm -r master.zip $TMP

ここで僕の環境だとビルドの過程で以下のようなエラーが出てたので解決法などを書いておきます

yoshikis-iPhone:~/test root# make clean
===> Setting SYSROOT to /var/root/theos/sdks/iPhoneOS11.2.sdk/...
==> Cleaning…
yoshikis-iPhone:~/test root# make
===> Setting SYSROOT to /var/root/theos/sdks/iPhoneOS11.2.sdk/...
> Making all for tweak test…
===> Setting SYSROOT to /var/root/theos/sdks/iPhoneOS11.2.sdk/...
===> Setting SYSROOT to /var/root/theos/sdks/iPhoneOS11.2.sdk/...
===> Setting SYSROOT to /var/root/theos/sdks/iPhoneOS11.2.sdk/...
==> Compiling KittyMemory/MemoryBackup.cpp (armv7)…
==> Compiling KittyMemory/KittyMemory.cpp (armv7)…
==> Compiling KittyMemory/MemoryPatch.cpp (armv7)…
==> Compiling KittyMemory/KittyUtils.cpp (armv7)…
==> Preprocessing Tweak.xm…
==> Compiling KittyMemory/writeData.cpp (armv7)…
==> Compiling SCLAlertView/SCLButton.m (armv7)…
==> Compiling SCLAlertView/SCLAlertViewStyleKit.m (armv7)…
==> Compiling Menu.mm (armv7)…
==> Compiling SCLAlertView/SCLAlertViewResponder.m (armv7)…
==> Compiling Tweak.xm (armv7)…
==> Compiling SCLAlertView/UIImage+ImageEffects.m (armv7)…
==> Compiling SCLAlertView/SCLTimerDisplay.m (armv7)…
==> Compiling SCLAlertView/SCLSwitchView.m (armv7)…
==> Compiling SCLAlertView/SCLTextView.m (armv7)…
==> Compiling SCLAlertView/SCLAlertView.m (armv7)…
==> Linking tweak test (armv7)…
ld: malformed file
/var/root/theos/vendor/lib/libsubstrate.tbd:2:42: error: unknown bit value
archs:           [ armv7, armv7s, arm64, arm64e, i386, x86_64 ]
                                         ^~~~~~
 file '/var/root/theos/vendor/lib/libsubstrate.tbd'
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/var/root/theos/makefiles/instance/library.mk:52: /var/root/test/.theos/obj/armv7/test.dylib] Error 1
rm /var/root/test/.theos/obj/armv7/Tweak.xm.mm
make[2]: *** [/var/root/theos/makefiles/instance/library.mk:52: /var/root/test/.theos/obj/armv7/test.dylib] Error 2
make[1]: *** [/var/root/theos/makefiles/instance/library.mk:37: internal-library-all_] Error 2
make: *** [/var/root/theos/makefiles/master/rules.mk:116: test.all.tweak.variables] Error 2
yoshikis-iPhone:~/test root# cd /var/root/theos/vendor/lib/libsubstrate.tbd
sh: cd: /var/root/theos/vendor/lib/libsubstrate.tbd: Not a directory

エラーの内容としては以上のようにsubstarateのarm64eのコンパイルでエラーが発生している感じだったので、/var/root/theos/vendor/lib/libsubstrate.tbdにあるファイルのarm64eをコンパイルから外す。 余談だがこれはiPhone10以降で使用されているアーキテクチャーなのでiPhone8ははずしても良いですー(確かXS以降、間違ってたらすいませんm( )m)

/var/root/theos/vendor/lib/libsubstrate.tbd

archs: [ armv7, armv7s, arm64, i386, x86_64]
platform: ios
install-name: /Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate
current-version: 0.0.0
compatibility-version: 0.0.0
exports:
- archs: [ armv7, armv7s, arm64, i386, x86_64, #arm64e ]
symbols: [ _MSCloseImage, _MSDebug, _MSFindAddress, _MSFindSymbol,
_MSGetImageByName, _MSHookClassPair, _MSHookFunction,
_MSHookMemory, _MSHookMessageEx, _MSImageAddress,
_MSMapImage ]

これで上手くいくはずですー

2-5.Tweakを使ってみる

$THEOS/bin/nic.plを実行するとある程度テンプレートがあり、それに従いtweakなど様々な用途に合わせてツールを作成できます。 基本的にTweakで良いと思います、またこれらのtemplateは追加することもできます。

yotti -> $THEOS/bin/nic.pl
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/activator_listener
  [3.] iphone/application_modern
  [4.] iphone/application_swift
  [5.] iphone/cydget
  [6.] iphone/flipswitch_switch
  [7.] iphone/framework
  [8.] iphone/library
  [9.] iphone/notification_center_widget
  [10.] iphone/notification_center_widget-7up
  [11.] iphone/preference_bundle_modern
  [12.] iphone/theme
  [13.] iphone/tool
  [14.] iphone/tool_swift
  [15.] iphone/tweak
  [16.] iphone/tweak_with_simple_preferences
  [17.] iphone/xpc_service

今回はModMenuを追加してみたいのでiOSGodsにtemplateがあったのでそれを使います https://github.com/joeyjurjens/iOS-Mod-Menu-Template-for-Theos https://github.com/joeyjurjens/iOS-Mod-Menu-Template-for-Theos/releases/tag/0.7.1

上記のgithubからTed2-Mod-Menu-Template.nic.tarをダウンロードします ~/theos/templateにdownloadしたファイルを配置します。

yotti -> $THEOS/bin/nic.pl
NIC 2.0 - New Instance Creator
------------------------------
  [1.] Ted2's Mod Menu Template
  [2.] iphone/activator_event
  [3.] iphone/activator_listener
  [4.] iphone/application_modern
  [5.] iphone/application_swift
  [6.] iphone/cydget
  [7.] iphone/flipswitch_switch
  [8.] iphone/framework
  [9.] iphone/library
  [10.] iphone/notification_center_widget
  [11.] iphone/notification_center_widget-7up
  [12.] iphone/preference_bundle_modern
  [13.] iphone/theme
  [14.] iphone/tool
  [15.] iphone/tool_swift
  [16.] iphone/tweak
  [17.] iphone/tweak_with_simple_preferences
  [18.] iphone/xpc_service

今回は何もせずにbuildを行います、本来はTweak.xファイルにHookするコードなどを記述したりします。 またテストアプリに Bundleしました

yotti ->make package
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: https://github.com/theos/theos/wiki/Parallel-Building
> Making all for tweak comyotticampanytest…
==> Preprocessing Tweak.x…
==> Compiling Tweak.x (armv7)…
==> Linking tweak comyotticampanytest (armv7)…
ld: warning: building for iOS, but linking in .tbd file (/Users/yotti/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for comyotticampanytest…
warning: no debug symbols in executable (-arch armv7)
rm /Users/yotti/Downloads/comyotticampanytest/.theos/obj/debug/armv7/Tweak.x.m
==> Preprocessing Tweak.x…
==> Compiling Tweak.x (arm64)…
==> Linking tweak comyotticampanytest (arm64)…
ld: warning: building for iOS, but linking in .tbd file (/Users/yotti/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for comyotticampanytest…
warning: no debug symbols in executable (-arch arm64)
rm /Users/yotti/Downloads/comyotticampanytest/.theos/obj/debug/arm64/Tweak.x.m
==> Preprocessing Tweak.x…
==> Compiling Tweak.x (arm64e)…
==> Linking tweak comyotticampanytest (arm64e)…
ld: warning: building for iOS, but linking in .tbd file (/Users/yotti/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for comyotticampanytest…
warning: no debug symbols in executable (-arch arm64e)
rm /Users/yotti/Downloads/comyotticampanytest/.theos/obj/debug/arm64e/Tweak.x.m
==> Merging tweak comyotticampanytest…
==> Signing comyotticampanytest…

makeでビルドします、ビルドが終わったらpackageというフォルダができており、そのディレクトリ化に*.debファイルができています Macで作成した場合は、これをiOSに移動してtweakのインストールを行いますscpコマンドでiOSdebファイルを移動してFilzaからインストールします

yotti -> scp com.yourcompany.com.yotticampany.test_0.0.1-3+debug_iphoneos-arm.deb root@192.168.11.7:/var/mobile/Downloads

f:id:yottiii:20201215232632j:plain:w300

ModMenuga表示されているようです

f:id:yottiii:20201215232008j:plain:w300

上手く実行されているようです。

3.Reference

github.com

iosgods.com

https://github.com/theos/theos/wiki/Installation-iOS