iOS Theos简单实战

2018-06-08  本文已影响52人  突刺刺

一. 需求

iPhone 锁屏时,弹出一个UIAlertView提示

二. 准备工作

三.开干

1. 创建一个Theos工程
skylinedeiMac:~ skyline$ pwd
/Users/skyline
skylinedeiMac:~ skyline$ cd /Users/skyline/Documents/
skylinedeiMac:Documents skyline$ /opt/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): 11
Project Name (required): tweakTest
Package Name [com.yourcompany.tweaktest]: com.myself.tweakTest
Author/Maintainer Name [skyline]: tucici
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.apple.sprignboard
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: SpringBoard
Instantiating iphone/tweak in tweaktest/...
Done.
skylinedeiMac:Documents skyline$ 
skylinedeiMac:Documents skyline$ cd /Users/skyline/Documents/tweaktest 
skylinedeiMac:tweaktest skyline$ ls
Makefile    Tweak.xm    control     tweakTest.plist
2. 在Theos工程文件里写代码
//%hook 是Logos语法,%hook与%end首尾成双出现
//SBLockScreenManager这个类是iOS锁屏的管理类,如果要实现其他目的,要找到OC层面对应的类,hook进去后,写入相应的代码
%hook SBLockScreenManager
- (void)lockUIFromSource:(NSUInteger)source withOptions:(id)options
{
%orig;// %orig是Logos语法,先调用上一层的代码,跟oc的 [super xxxx]差不多的意思
//创建UIAlertView
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"注意" message:@"你好,这是一个锁屏弹框提示" delegate:nil
                     cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];

//创建一个UILabel,显示当前iOS系统的版本
   CGFloat systemversion = [[[UIDevice currentDevice] systemVersion] floatValue];

   UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 300)];
    label.numberOfLines = 0;   
    label.text = [NSString stringWithFormat:@"注意!!!\n\n current systemVersion == > %f",systemversion]; 
    label.textColor = [UIColor purpleColor];
    label.backgroundColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
 
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window makeKeyAndVisible];
    [window addSubview:label];
}
%end
export THEOS_DEVICE_IP = 192.xxx.1.xxx//填入越狱手机IP,必须在第一行
include $(THEOS)/makefiles/common.mk//THEOS是一个全局变量,没有初始化export THEOS="/opt/theos"会报错

TWEAK_NAME = tweakTest
tucici_FILES = Tweak.xm
tucici_FRAMEWORKS = UIKit

include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
    install.exec "killall -9 SpringBoard"
3. 获取iPhone的root密码

安装deb包时候,需要两次输入iPhone的root密码,方法如下:

4. 配置SSH
5. 安装
6. 成功
0000000000000.png

四. 安装deb插件的三种方法

scp /Users/Desktop/xxxx.deb root@192.xxx.x.xxx:/mnt //把deb文件copy到iOS设备上
sudo ssh 192.xxx.x.xxx //通过ssh连接到设备上,手机默认密码alpine
dpkg -i xxx.deb//找到xxx.deb 安装
reboot 重启

五.问题

上一篇 下一篇

猜你喜欢

热点阅读