先說說爲何要分析應用吧,若是你想從一個ios應用中獲取有用的信息,或者你想修改該應用的一些功能,前提固然是要先知道該app的邏輯和結構了。php
動態分享工具比較少,咱們先分析個簡單的,全民工具Cycriptios
Cycriptxcode
參考資料:http://www.cycript.org/app
http://iphonedevwiki.net/index.php/Cycriptssh
cycript是一個腳本語言,你們都說能夠看作Objective-JavaScript,形容的很是貼切。Cycript在Cydia自帶源Cydia/Telesphoreo中就有,安裝完之後用ssh登錄ios設備iphone
1
|
ssh root@192.168.1.152
|
驅動你要分析的應用,查看PID,這裏就拿自動啓動的桌面SpringBoard作例子好了ide
1
2
|
ps aux | grep SpringBoard
mobile 1514 0.7 10.6 577300 54720 ?? Ss 3:46PM 1:19.28 /System/Library/CoreServices/SpringBoard.app/SpringBoard
|
找到PID(1514)後,用Cycript勾上應用 函數
1
2
|
cycript -p 1514
cycript -p SpringBoard
|
上面兩句均可以勾上應用,勾上之後你就能夠隨心所欲了,先彈個窗口吧工具
1
2
3
|
cy# var alert = [[UIAlertView alloc] initWithTitle:@
"asd"
message:nil delegate:nil cancelButtonTitle:@
"ok"
otherButtonTitles:nil];
#"<UIAlertView: 0x19c200f0; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x19c8e730>>"
cy# [alert show]
|
能夠看到,凡是賦值出來的數據,cycript都會打印出信息來。在截個屏吧,這時候你會想,截屏怎麼調呢。。。。這也難倒我了,這樣咱們先用靜態工具class-dump導出頭文件來,而後搜索shot,哈哈,出來了spa
1
2
3
|
cy# var shot = [SBScreenShotter sharedInstance]
#"<SBScreenShotter: 0x19ccda20>"
cy# [shot saveScreenshot:YES]
|
Ctrl+D 退出
2.GDB
cycript功能強大,語法相似oc,很是好用,可是就是有有一個致命缺點,就是不能斷點,沒法停留在具體位置查看結果,這時候GDB就出來了,固然GDB早就出來了,GDB是強大的調試工具,怎麼用GDB調試ios應用呢
GDB全名the GNU Project Debugger在cydia(數據源http://cydia.radare.org)中能夠下到 .
GDB勾上應用,作法跟Cycript是同樣的,能夠經過PID,也可使用應用名
1
2
|
gdb -p SpringBoard
gdb -p 1514
|
或者能夠先調用gdb ,後使用attach勾上應用也是同樣的,取消勾使用detach
2. 斷點break
1
2
|
b -[SpringBoard menuButtonDown:]
b *(0xc41e)
|
b斷點能夠斷在函數上(但不是每次都能成功),也能夠直接斷在內存地址上,你們會問我怎麼知道函數的內存地址是多少呢,這時候就請查看IDA吧
因爲ASLR的緣由,通常在IDA中得到的內存地址是不許確的,由於每次運行程序,內存地址都會有必定的偏移,在GDB中使用info sh得到偏移地址
1
2
3
4
5
|
gdb$ info sh
The DYLD shared library state has not yet been initialized.
Requested State Current State
Num Basename Type Address Reason | | Source
| | | | | | | |
|
你妹啊,什麼都沒有!!!!!!(OK,就此打住)
因而我找到了SpringBoard應用的目錄文件,用file 命令導入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
yuchenghaide-iPod:~ root# ps aux | grep SpringBorad
root 1915 0.0 0.1 338564 520 s000 S+ 11:02AM 0:00.01 grep SpringBorad
yuchenghaide-iPod:~ root# ps aux | grep SpringBoard
mobile 1514 0.0 11.3 588168 58320 ?? Ss 3:46PM 1:39.55 /System/Library/CoreServices/SpringBoard.app/SpringBoard
root 1917 0.0 0.1 338608 512 s000 S+ 11:02AM 0:00.01 grep SpringBoard
root 1877 0.0 0.4 349304 2124 s000 S 10:18AM 0:00.29 cycript -p SpringBoard
yuchenghaide-iPod:~ root# cd /System/Library/CoreServices/SpringBoard.app/
yuchenghaide-iPod:/System/Library/CoreServices/SpringBoard.app root# gdb
GNU gdb 6.3.50.20050815-cvs (Fri May 20 08:08:42 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is
free
software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type
"show copying"
to see the conditions.
There is absolutely no warranty
for
GDB. Type
"show warranty"
for
details.
This GDB was configured as
"--host=arm-apple-darwin9 --target="
.
gdb$ file SpringBoard
unable to read unknown load command 0x80000028
Reading symbols
for
shared libraries .. done
unable to read unknown load command 0x80000028
gdb$ attach SpringBoard
Attaching to program: `/System/Library/CoreServices/SpringBoard.app/SpringBoard', process 1514.
0x3877aa58 in ?? ()
Error
while
running hook_stop:
Invalid type combination in equality test.
gdb$ info sh
The DYLD shared library state has been initialized from the executable's shared library information. All symbols should be present, but the addresses of some symbols may move when the program is executed, as DYLD may relocate library load addresses
if
necessary.
Requested State Current State
Num Basename Type Address Reason | | Source
| | | | | | | |
1 SpringBoard - - exec Y Y /System/Library/CoreServices/SpringBoard.app/SpringBoard (offset 0x0)
2 dyld - - init Y Y /usr/lib/dyld at 0x2be00000 with prefix
"__dyld_"
3 StoreServices F - init Y ! /System/Library/PrivateFrameworks/StoreServices.framework/StoreServices
4 AirTraffic F - init Y ! /System/Library/PrivateFrameworks/AirTraffic.framework/AirTraffic
5 IOSurface F - init Y ! /System/Library/PrivateFrameworks/IOSurface.framework/IOSurface
6 MultitouchSupport F - init Y ! /System/Library/PrivateFrameworks/MultitouchSupport.framework/MultitouchSupport
7 MobileWiFi F - init Y ! /System/Library/PrivateFrameworks/MobileWiFi.framework/MobileWiFi
8 libIOAccessoryManager.dylib - - init Y ! /usr/lib/libIOAccessoryManager.dylib
9 IOMobileFramebuffer F - init Y ! /System/Library/PrivateFrameworks/IOMobileFramebuffer.framework/IOMobileFramebuffer
10 CoreSurface F - init Y ! /System/Library/PrivateFrameworks/CoreSurface.framework/CoreSurface
11 BluetoothManager F - init Y ! /System/Library/PrivateFrameworks/BluetoothManager.framework/BluetoothManager
12 CrashReporterSupport F - init Y ! /System/Library/PrivateFrameworks/CrashReporterSupport.framework/CrashReporterSupport
13 EAP8021X F - init Y ! /System/Library/PrivateFrameworks/EAP8021X.framework/EAP8021X
14 libmis.dylib - - init Y Y /usr/lib/libmis.dylib at 0xa3e000 (offset -0xff5c2000)
|
你妹!offset = 0x0 ,這怎麼回事!難倒真的是0嗎?我試了一下
1
2
3
4
5
6
7
8
|
gdb$ b -[SpringBoard menuButtonDown:]
Function
"-[SpringBoard menuButtonDown:]"
not defined.
gdb$ b *(0xc41e)
Breakpoint 1 at 0xc41e
gdb$ info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000c41e <_mh_execute_header+46110>
gdb$ c
|
info b是打印出全部的斷點,刪除斷點可使用d 斷點編號
c 表示繼續程序,按home鍵-結果斷點根本沒有斷下來。好吧,打住,GDB的命令你們能夠到網上隨意查詢!
通過《ios應用逆向工程》做者之一snakeninny的解答,終於瞭解到在ios7.x以後gdb可能被捨棄了,代替它的是lldb
關於lldb的使用方法: http://bbs.iosre.com/forum.php?mod=viewthread&tid=52
總結:
恩,下節爲你們分享lldb的具體使用,另外值得一提的是xcode調試工具就是lldb,全部學會使用lldb是很是重要的。
另外,假設咱們在不斷的努力下找到了咱們想要的邏輯,咱們應該怎麼攻擊或修改它呢。嘿嘿,仍是等下回分解吧。
慢慢來!少年!