构建越狱插件开发环境

1.安装Xcode环境. AppStore直接安装.不多表述.

2.安装THEOS

#打开终端,设置目录
export THEOS=/opt/theos
#安装 THEOS
sudo svn co http://svn.howett.net/svn/theos/trunk $THEOS

3.下载ldid.

#下载到tmp
sudo curl -s http://dl.dropbox.com/u/3157793/ldid > /tmp/ldid
#复制
sudo cp /tmp/ldid $THEOS/bin/
#权限
sudo chmod +x $THEOS/bin/ldid
#删除
rm /tmp/ldid

4.dpkg,打包用

#安装Xcode Command Tools
xcode-select --install
#安装Macport 选择自己的系统版本
#https://guide.macports.org/chunked/installing.macports.html
#设置下Port的环境 不然一直报
command not found: port
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
#安装dpkg
sudo port install dpkg

5.建立新工程

直接使用终端在你需要建立新工程的目录里

#如果之前的command已经关闭,重新输入运行 export THEOS=/opt/theos 设置环境变量
$THEOS/bin/nic.pl

如下,一般都是选5...

➜  ~ $THEOS/bin/nic.pl      
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/application 
  [2.] iphone/library
  [3.] iphone/preference_bundle
  [4.] iphone/tool
  [5.] iphone/tweak
Choose a Template (required): 5
Project Name (required): NewTest
Package Name [com.yourcompany.newtest]: com.m1989.newtest
Author/Maintainer Name [KayCM]: 
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: 
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: 
Instantiating iphone/tweak in newtest/...
Done.

之后为了方便开发还是安装iOSOpenDev

XCode 8 使用如下命令修复后安装. 

地址 https://github.com/everettjf/iOSOpenDevInstallFix

安装过程不表.如有错误,请对照 https://github.com/kokoabim/iOSOpenDev/wiki/Troubleshoot

建立tweak后,在相应的*.xm文件写入如下代码

#import <UIKit/UIKit.h>

%hook SBLockScreenDateViewController

-(void)setCustomSubtitleText:(id)arg1 withColor:(id)arg2
{
    %orig(@"测试", arg2);
}

%end

%hook SpringBoard

- (void)applicationDidFinishLaunching:(id)application {
    
    %orig;
    
    
    NSLog(@"====================");
    NSLog(@"hook SpringBoard:这是测试log输出。");
    NSLog(@"====================");
          
    CGFloat Width = [UIScreen mainScreen].bounds.size.width;

    dispatch_after(0.1, dispatch_get_main_queue(), ^{
        
        UIWindow *Win = [[UIWindow alloc] initWithFrame:CGRectMake(Width-Width/4, 0, Width/4, 20)];
        
        Win.windowLevel = UIWindowLevelStatusBar+1;
        
        Win.backgroundColor = [UIColor clearColor];
        
        [Win makeKeyAndVisible];
        
        UIButton *Btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width/4, 20)];
        
        Btn.backgroundColor = [UIColor whiteColor];
        
        [Btn addTarget:self action:@selector(alertTips) forControlEvents:UIControlEventTouchUpInside];
        
        [Win addSubview:Btn];
        
    });
    
    
}


%new
-(void)alertTips{
    
    NSLog(@"======log");
    
    UIAlertView *alert =
    [[UIAlertView alloc]initWithTitle:@"Tips" message:@"这是测试log输出." delegate:nil cancelButtonTitle:@"done" otherButtonTitles:nil];
    
    [alert show];
 
}

%end

 

 设置真机测试.在终端里输入如下,建立ssh通道 192.168.1.106 为你iPhone的IP,Mac和iPhone 需为同一局域网内.

iosod sshkey -h 192.168.1.106

设置XCode -> build settings -> user-defined -> iOSOpenDevDevice 为你iPhoneIP

最后product->build for->profiling,之后所写的tweak会通过ssh 传输到你的iPhone,然后自动重启运行.

记一个小坑,当你的真机系统为7.x 而 XCode8 最低只能支持到 8,只需直接 General -> Deployment -> Deployment Target 直接输入 7.x就行.

posted @ 2016-11-14 16:36  NGI.  阅读(1495)  评论(0编辑  收藏  举报
GitHub | M1989