前言
可以使用makefile的after-install
来修改tweak的可执行文件及配置文件的权限
after-install:: install.exec "echo '' > /var/log/syslog" ## install.exec "killall -9 taokeTool" install.exec "chown root:wheel /usr/bin/taokeTool" install.exec "chown root:wheel /Library/LaunchDaemons/com.wl.tktool.plist" install.exec "reboot"
编写iphone/tool
devzkndeMacBook-Pro:taokeTool devzkn$ export THEOS=/opt/theos devzkndeMacBook-Pro:taokeTool devzkn$ $THEOS/bin/nic.pl NIC 2.0 - New Instance Creator ------------------------------ [1.] iphone/activator_event [2.] iphone/application_modern [3.] iphone/cydget [4.] iphone/flipswitch_switch [5.] iphone/framework [6.] iphone/ios7_notification_center_widget [7.] iphone/library [8.] iphone/notification_center_widget [9.] iphone/preference_bundle_modern [10.] iphone/tool [11.] iphone/tweak [12.] iphone/xpc_service Choose a Template (required): 10
创建Theos 的软链接
ls -l
lrwxr-xr-x 1 devzkn staff 10 Oct 16 15:09 theos -> /opt/theos
devzkndeMacBook-Pro:taoketool devzkn$ sudo ln -s /opt/theos ./theos devzkndeMacBook-Pro:taoketool devzkn$ ls -l total 40 -rw-r--r-- 1 devzkn staff 249 Oct 16 15:38 Makefile -rw-r--r-- 1 devzkn staff 200 Oct 16 14:59 control -rwxr-xr-x 1 devzkn staff 95 Aug 20 18:42 deploy -rw-r--r-- 1 devzkn staff 76 Oct 16 14:59 main.mm lrwxr-xr-x 1 root staff 10 Oct 16 15:44 theos -> /opt/theos
设置tool.mk 的路径
THEOS_DEVICE_IP=iphone #5C9 ARCHS = armv7 armv7s arm64 TARGET = iphone:latest:8.0 THEOS=/opt/theos THEOS_MAKE_PATH=$(THEOS)/makefiles include $(THEOS_MAKE_PATH)/common.mk TOOL_NAME = taokeTool taokeTool_FILES = main.mm taokeTool_FRAMEWORKS = UIKit include $(THEOS_MAKE_PATH)/tool.mk
I app执行shell 命令
开发步骤及代码示例:OC利用#include "NSTask.h"
执行shell 命令
- killall
//杀掉微信的进程 doShellCmd(@"killall WeChat"); NSLog(@"killall WeChat"); //杀掉Moon的进程 doShellCmd(@"killall Moon"); NSLog(@"killall Moon");
- 执行shell脚本
//执行shell脚本 NSString *doShellCmd(NSString *cmd) { NSTask *task; task = [[NSTask alloc ]init]; [task setLaunchPath:@"/bin/bash"]; NSArray *arguments = [NSArray arrayWithObjects:@"-c",cmd, nil]; [task setArguments:arguments]; NSPipe *pipe = [NSPipe pipe]; [task setStandardOutput:pipe]; NSFileHandle *file = [pipe fileHandleForReading]; [task launch]; NSData *data = [file readDataToEndOfFile]; NSString *string = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; return string; }
- 部署之后,脚本在/usr/bin 目录
iPhone:/usr/bin root# which taokeTool /usr/bin/taokeTool
-rwxr-xr-x 1 mobile staff 200512 Oct 18 18:01 taokeTool
because daemons are loaded by launchd, which is owned by root:wheel,
iPhone:~ root# ps -e PID TTY TIME CMD 1 ?? 0:04.13 /sbin/launchd
iPhone:/sbin root# ls -l /sbin/launchd -rwxr-xr-x 1 root wheel 239536 Nov 19 2014 /sbin/launchd so both a daemon and its config file must be owned by root:wheel too, it borns and runs as root.
II 修改taokeTool owned 的 两种方式
2.1、直接手动修改
iPhone:/usr/bin root# chown root:wheel taokeTool
-rwxr-xr-x 1 root wheel 200512 Oct 18 18:01 taokeTool
iPhone:/Library/LaunchDaemons root# chown root:wheel com.wl.tktool.plist
这种方式,每次安装要修改chwon,从deb的List contents 可以看出这点:
dpkg-deb -c **.deb drwxr-xr-x devzkn/staff 0 2017-10-26 17:57 ./ drwxr-xr-x devzkn/staff 0 2017-10-26 17:57 ./usr/ drwxr-xr-x devzkn/staff 0 2017-10-26 17:57 ./usr/bin/ -rwxr-xr-x devzkn/staff 200512 2017-10-26 17:57 ./usr/bin/taokeTool
2.2、 借助 fauxsu
- 借助a tool called fauxsu116 by DHowett
更彻底的解决方案使用方式二
编辑plist
devzkndeMacBook-Pro:taoketool devzkn$ mkdir -p ./Layout/Library/LaunchDaemons/ devzkndeMacBook-Pro:LaunchDaemons devzkn$ touch com.wl.tktool.plist
具体操作步骤,请看原文:https://kunnan.blog.csdn.net/article/details/78249848
III reboot
- 手动reboot
iPhone:/Library/LaunchDaemons root# reboot Connection to 192.168.2.134 closed by remote host. Connection to 192.168.2.134 closed.
- 自动reboot
static void Reboot(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { NSLog(@"iOSRE: reboot"); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" system("reboot"); #pragma GCC diagnostic pop }
但是"system" is removed in iOS 11。
执行效果
iPhone:/Library/LaunchDaemons root# reboot Connection to 192.168.2.134 closed by remote host. Connection to 192.168.2.134 closed. devzkndeMacBook-Pro:.ssh devzkn$ ssh iphone150 iPhone:~ root# ps -e |grep taokeTool 88 ?? 0:00.25 /usr/bin/taokeTool 590 ttys000 0:00.01 grep taokeTool
- Makefile 进行定义执行reboot的时机
after-install:: install.exec "echo '' > /var/log/syslog" install.exec "killall -9 taokeTool" install.exec "reboot"
IV 配置 .gitignore
devzkndeMacBook-Pro:taoketool devzkn$ less .gitignore
/.theos/ /debs/ /obj/ /packages/ /.vscode/
V 、常见问题
5.1taokeTool_FILES 变量写成了其他的工程名
Undefined symbols for architecture armv7s: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture armv7s clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [/Users/devzkn/code/taokeTool/taoketool/.theos/obj/debug/armv7s/taokeTool] Error 1 make[2]: *** [/Users/devzkn/code/taokeTool/taoketool/.theos/obj/debug/armv7s/taokeTool] Error 2
因为taokeTool_FILES 这个变量写成了其他的工程名+_FILES
5.2 问题:没有找到system方法
- main.mm:14:5: error: call to unavailable function 'system': not available on iOS https://github.com/cocos2d/cocos2d-x/pull/17921
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.1.sdk/usr/include/stdlib.h:195:6: note: candidate function has been explicitly made unavailable
解决方法:执行reboot的命令 可以放到Makefile 进行定义
- 具体的内容如下
after-install:: install.exec "echo '' > /var/log/syslog" install.exec "killall -9 taokeTool" install.exec "reboot"
- 查看 SIP的命令:
csrutil status
devzkndeMacBook-Pro:taoketool devzkn$ csrutil status System Integrity Protection status: enabled.