标签:style blog http io color ar os 使用 java
上节分享了用静态工具分析应用-额,我找找链接 ios逆向工程-静态分析
先说说为什么要分析应用吧,如果你想从一个ios应用中获取有用的信息,或者你想修改该应用的一些功能,前提当然是要先知道该app的逻辑和结构了。
动态分享工具比较少,我们先分析个简单的,全民工具Cycript
Cycript
http://iphonedevwiki.net/index.php/Cycript
cycript是一个脚本语言,大家都说可以看做Objective-JavaScript,形容的非常贴切。Cycript在Cydia自带源Cydia/Telesphoreo中就有,安装完以后用ssh登陆ios设备
ssh root@192.168.1.152
驱动你要分析的应用,查看PID,这里就拿自动启动的桌面SpringBoard做例子好了
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勾上应用
cycript -p 1514 cycript -p SpringBoard
上面两句都可以勾上应用,勾上以后你就可以为所欲为了,先弹个窗口吧
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,哈哈,出来了
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,也可以使用应用名
gdb -p SpringBoard gdb -p 1514
或者可以先调用gdb ,后使用attach勾上应用也是一样的,取消勾使用detach
2. 断点break
b -[SpringBoard menuButtonDown:] b *(0xc41e)
b断点可以断在函数上(但不是每次都能成功),也可以直接断在内存地址上,大家会问我怎么知道函数的内存地址是多少呢,这时候就请查看IDA吧
由于ASLR的原因,一般在IDA中获得的内存地址是不准确的,因为每次运行程序,内存地址都会有一定的偏移,在GDB中使用info sh获得偏移地址
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 命令导入
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吗?我试了一下
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的命令大家可以到网上随意查询!
标签:style blog http io color ar os 使用 java
原文地址:http://my.oschina.net/iq19900204/blog/340462