$ ls -lrt
total 32-rw-r--r--1 devzkn staff 51 Aug 1017:07 testTweakDemo.plist
-rw-r--r--1 devzkn staff 223 Aug 1017:07 control
-rw-r--r--1 devzkn staff 1045 Aug 1017:07 Tweak.xm
-rw-r--r--1 devzkn staff 189 Aug 1017:07 Makefile
① control 文件
control 文件存儲(chǔ)項(xiàng)目有關(guān)的信息:名稱、版本、開發(fā)者:
IMP MSHookMessage(Class class, SEL selector, IMP replacement,constchar* prefix);// prefix should be NULL.voidMSHookMessageEx(Class class, SEL selector, IMP replacement, IMP *result);voidMSHookFunction(void* function,void* replacement,void** p_original);
Tweak.xm 的文件名后綴 x 代表的含義:
Tweak.xm 的文件名后綴 x 代表支持 Logos 語法, 如果只有一個(gè) x 代表源文件支持 Logos 和 C 語法;如果是 xm,說明源文件支持 Logos 和 C/C++ 語法;
其中的 %hook,%orig,%log 等都是 Logos 語法支持的內(nèi)容。
$ more Tweak.xm
/* How to Hook with Logos
Hooks are written with syntax similar to that of an Objective-C @implementation.
You don't need to #include <substrate.h>, it will be done automatically, as will
the generation of a class list and an automatic constructor.%hook ClassName// Hooking a class method
+ (id)sharedInstance {return %orig;
}// Hooking an instance method with an argument.
- (void)messageName:(int)argument {%log; // Write a message about this call, including its class, name and arguments, to the system log.%orig; // Call through to the original function with its original arguments.%orig(nil); // Call through to the original function with a custom argument.// If you use %orig(), you MUST supply all arguments (except for self and _cmd, the automatically generated ones.)
}// Hooking an instance method with no arguments.
- (id)noArguments {%log;id awesome = %orig;[awesome doSomethingElse];return awesome;
}// Always make sure you clean up after yourself; Not doing so could have grave consequences!
%end
*/
⑤ 編譯和安裝deb
使用命令 make package 編譯,其中 packages 文件夾下保留的是每一次編譯成功產(chǎn)生的 deb 安裝包文件。theos 編譯之后,會(huì)生成一個(gè) deb 包,deb 安裝到手機(jī)上面,有多種方式:
通過 iFile 進(jìn)行安裝:使用 iTools 等工具將這個(gè) deb 包拷貝到手機(jī)中,利用 iFile 瀏覽進(jìn)行安裝;
ssh-copy-id 指定認(rèn)證文件$ ssh-copy-id -i id_rsa_Theos125 root@192.168.2.131
$ ssh-copy-id root@192.168.2.212/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:"/Users/devzkn/.ssh/id_rsa_Theos.pub"/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO:1key(s) remain to be installed --if you are prompted now it is to install the new keys
root@192.168.2.212's password: Number of key(s) added:1Now try logging into the machine, with:"ssh 'root@192.168.2.212'"
and check to make sure that only the key(s) you wanted were added.
三、常見問題
① 壓縮方式不被支持
原因是 dpkg 有兩個(gè)不同的版本,最新版本不支持 lzma:
$ make package
> Making all for tweak testTweakDemo…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm(armv7)…
==> Linking tweak testTweakDemo(armv7)…
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of iOS 7[-Wdeprecated]==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm(arm64)…
==> Linking tweak testTweakDemo(arm64)…
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of iOS 7[-Wdeprecated]==> Merging tweak testTweakDemo…
==> Signing testTweakDemo…
> Making stage for tweak testTweakDemo…
dpkg-deb: error: obsolete compression type 'lzma'; use xz insteadType dpkg-deb --help for help about manipulating *.deb files;
Type dpkg --help for help about installing and deinstalling packages.
make:***[internal-package] Error 2
Debian 'dpkg' package management program version 1.18.24(darwin-amd64)
brew switch dpkg 1.18.10
brew link dpkg
brew pin dpkg 1.18.10
驗(yàn)證是否修復(fù):
$ make package
> Making all for tweak testTweakDemo…
make[2]: Nothing to be done for `internal-library-compile'.> Making stage for tweak testTweakDemo…
dpkg-deb: building package 'com.yourcompany.testtweakdemo'in'./packages/com.yourcompany.testtweakdemo_0.0.1-2+debug_iphoneos-arm.deb'.
root@192.168.2.212's password:
Selecting previously unselected package com.yourcompany.testtweakdemo.(Reading database ...1848 files and directories currently installed.)
Preparing to unpack /tmp/_theos_install.deb ...
Unpacking com.yourcompany.testtweakdemo(0.0.1-8+debug)...
dpkg-deb(subprocess): unable to execute decompressing archive member(xz): No such file or directory
dpkg-deb(subprocess): subprocess decompressing archive member returned error exit status 2
dpkg-deb: error: subprocess <decompress> returned error exit status 2
dpkg: error processing archive /tmp/_theos_install.deb(--install):subprocess dpkg-deb --fsys-tarfile returned error exit status 2
Errors were encountered while processing:/tmp/_theos_install.deb
make:***[internal-install] Error 1
$ make package install
> Making all for tweak testTweakDemo…
make[2]: Nothing to be done for `internal-library-compile'.> Making stage for tweak testTweakDemo…
dpkg-deb: building package 'com.yourcompany.testtweakdemo'in'./packages/com.yourcompany.testtweakdemo_0.0.1-9+debug_iphoneos-arm.deb'.==> Installing…
root@192.168.2.212's password:(Reading database ...1848 files and directories currently installed.)
Preparing to unpack /tmp/_theos_install.deb ...
Unpacking com.yourcompany.testtweakdemo(0.0.1-9+debug)...
Setting up com.yourcompany.testtweakdemo(0.0.1-9+debug)...
install.exec "killall -9 SpringBoard"
root@192.168.2.212's password:
② THEOS_DEVICE_IP 設(shè)置錯(cuò)誤
$ make package install
> Making all for tweak testTweakDemo…
make[2]: Nothing to be done for `internal-library-compile'.> Making stage for tweak testTweakDemo…
dpkg-deb: building package 'com.yourcompany.testtweakdemo'in'./packages/com.yourcompany.testtweakdemo_0.0.1-3+debug_iphoneos-arm.deb'.==> Error:/Applications/Xcode.app/Contents/Developer/usr/bin/make install requires that you set THEOS_DEVICE_IP in your environment.==> Notice: It is also recommended that you have public-key authentication set up for root over SSH, or you will be entering your password a lot.
$ ping 192.168.2.212
PING 192.168.2.212(192.168.2.212):56 data bytes
64 bytes from 192.168.2.212: icmp_seq=0 ttl=64 time=34.303 ms
64 bytes from 192.168.2.212: icmp_seq=1 ttl=64 time=28.949 ms
64 bytes from 192.168.2.212: icmp_seq=2 ttl=64 time=25.753 ms
64 bytes from 192.168.2.212: icmp_seq=3 ttl=64 time=5.306 ms
64 bytes from 192.168.2.212: icmp_seq=4 ttl=64 time=106.028 ms
64 bytes from 192.168.2.212: icmp_seq=5 ttl=64 time=84.643 ms
64 bytes from 192.168.2.212: icmp_seq=6 ttl=64 time=44.845 ms
^C
---192.168.2.212 ping statistics ---7 packets transmitted,7 packets received,0.0% packet loss
round-trip min/avg/max/stddev =5.306/47.118/106.028/32.913 ms
devzkndeMacBook-Pro:testtweakdemo devzkn$ ssh root@192.168.2.212
The authenticity of host '192.168.2.212 (192.168.2.212)' can't be established.
RSA key fingerprint is SHA256:/.
Are you sure you want to continueconnecting(yes/no)? yes
Warning: Permanently added '192.168.2.212'(RSA) to the list of known hosts.
root@192.168.2.212's password:
Permission denied, please try again.
root@192.168.2.212's password:
iPhone:~ root#