基於Theos越獄開發

前言:
       theos是國外大牛開發的越獄編譯平臺,經過命令行能夠快速的生成例子,其最有意思的當屬tweak插件的開發,其Logus的語法簡潔明瞭,是越獄中HOOK的絕佳神器,下面就來一步步揭開這些東西的神祕面紗!
1、環境準備ios

一、安裝theosgit

;新建theos安裝目錄
$cd ~
$mkdir -r work/theos

;下載theos
$export THEOS=~/work/theos
$svn co http://svn.howett.net/svn/theos/trunk $THEOS


二、 安裝簽名工具ldidgithub

$git clone git://git.saurik.com/ldid.git
$cd ldid
$git submodule update --init
$./make.sh
$cp -f ./ldid $THEOS/bin/ldid

三、設置環境變量spring

$touch ~/.bash_profile

;設置環境變量(THEOS_DEVICE_IP爲要安裝app的真機IP)
$vi ~/.bash_profile
export THEOS=~/work/theos
export PATH=$THEOS/bin:$PATH
export THEOS_DEVICE_IP=10.60.113.36 THEOS_DEVICE_PORT=22

四、安裝substrate庫ruby

;安裝brew 包安裝工具
$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

;安裝wget
$brew install wget

;安裝dpkg
$brew install dpkg

;下載substrate
$wget http://apt.saurik.com/debs/mobilesubstrate_0.9.6011_iphoneos-arm.deb

;解包
$mkdir substrate
$dpkg-deb -x mobilesubstrate_*_iphoneos-arm.deb substrate

;拷貝到theos目錄
$mv substrate/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate $THEOS/lib/libsubstrate.dylib
$mv substrate/Library/Frameworks/CydiaSubstrate.framework/Headers/ \
    CydiaSubstrate.h $THEOS/include/substrate.h

五、更新iphone開發頭bash

$mkdir iphoneheaders

;下載頭文件
$git clone https://github.com/nanotech/iphoneheaders.git

;拷貝到theos目錄下
$mv iphoneheaders/* $THEOS/include/

;ps
$cp /System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceAPI.h .

2、真槍實戰服務器

一、第一個application程序app

;應用環境變量
$. ~/.bash_profile 

;新建項目
$ $THEOS/bin/nic.pl
NIC 1.0 - New Instance Creator
------------------------------
  [1.] iphone/application
  [2.] iphone/library
  [3.] iphone/preference_bundle
  [4.] iphone/tool
  [5.] iphone/tweak
Choose a Template (required): 1
Project Name (required): iPhoneDevWiki
Package Name [com.yourcompany.iphonedevwiki]: net.howett.iphonedevwiki
Authour/Maintainer Name [Dustin L. Howett]:              
Instantiating iphone/application in iphonedevwiki/...
Done.

;切換到生成的項目目錄下 make 生成deb
$cd iphonedevwiki
$make package

;安裝deb到cydia中
$make install

在真機的cydia已安裝列表中會有iphonedevwiki的包名,須要respring手機才能在桌面看到安裝的app。respring能夠在cydia上安裝個插件Respring,方便調試!框架

二、第一個tweak程序curl

;應用環境變量
$. ~/.bash_profile 

;新建項目
$ $THEOS/bin/nic.pl
NIC 1.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): iPhoneDevWiki
Package Name [com.yourcompany.iphonedevwiki]: net.howett.iphonedevwiki
Authour/Maintainer Name [Dustin L. Howett]:              
Instantiating iphone/tweak iphonedevwiki/...
Done.

;生成的文件目錄
Makefile
Tweak.xm
control
theos
tweak.plist

;Makefile中增長編譯框架
iPhoneDevWiki_FRAMEWORKS = UIKit

;Tweak.xm中增長alert

#import <SpringBoard/SpringBoard.h>

%hook SpringBoard

-(void)applicationDidFinishLaunching:(id)application {
%orig;

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome"
message:@"Welcome to your iOS Device Ted!"
delegate:nil
cancelButtonTitle:@"security.ios-wiki.com" otherButtonTitles:nil];

[alert show];
[alert release];

}

%end


;切換到生成的項目目錄下 make 生成deb
$cd iphonedevwiki
$make package

;安裝deb到cydia中
$make install

1、deb patch

一、獲取cydia安裝包

    老版本的cydia會將經過源安裝的deb刪除掉,以致找不到deb包。當前可以使用apt來獲取安裝包。

$cd var/cache/apt/archives

#更新源
$apt-get update

#下載包
$apt-get -d install app.weiphone.nx

#查看包安裝信息
$dpkg-dbg -I xx.deb

#安裝deb
$dpkg -i xx.deb

#卸載應用
$dpkg -r app.weiphone.nx

二、經過theos編譯的deb文件裏面包含debian_binary、control.tar.gz、data.tar.gz等文件,能夠使用命令顯示

#列出deb中文件
$ar vt com.cm.tweak_0.0.1-1_iphoneos-arm.deb   
rw-r--r--       0/0             4 Aug  9 00:53 2016 debian-binary
rw-r--r--       0/0           293 Aug  9 00:53 2016 control.tar.gz
rw-r--r--       0/0          1708 Aug  9 00:53 2016 data.tar.gz

#提取文件
$ar vx xxx.deb debian-binary
$ar vx xxx.deb control.tar.gz
$ar vx xxx.deb data.tar.gz

#刪除文件
$ar d xxx.deb data.tar.gz

#更新文件
$ar r xxx.deb data.tar.gz

#解壓tar.gz
$tar -tzvf control.tar.gz

#打包
$tar -zvcf control1.tar.gz control postinst

#製做deb包
$ar -rc xx.deb debian-binary control.tar.gz data.tar.gz

#特殊狀況碰到lzma
#安裝lzma
$sudo apt-get install lzma

#查看lzma狀況
$ lzmainfo data.tar.lzma

#解壓lzma
$unlzma data.tar.lzma
$tar -xvf data.tar

#壓縮lzma
$tar -cvf data.tar file1 file2
$lzma -z data.tar

三、scp操做

一、從服務器下載文件
  scp username@servername:/path/filename /tmp/local_destination

二、上傳本地文件到服務器
  scp /path/local_filename username@servername:/path  
  
三、從服務器下載整個目錄
  scp -r username@servername:remote_dir/ /tmp/local_dir 
  
四、上傳目錄到服務器
  scp  -r /tmp/local_dir username@servername:remote_dir

四、重啓springboard,刷新桌面

$killall SpringBoard

ps:

syslogd to /var/log/syslog

tail -f /var/log/syslog

相關文章
相關標籤/搜索