按以往资料解密iOS5应用软件会遇到两个问题:
下面以Douban.fm.ipa的解密为例,解决这两个问题,为了保持完整性,从头开始说明步骤。注意有的指令在Mac上运行,也有的指令在iOS上运行,根据命令提示符区分。在iOS上的默认路径是/var/mobile/Applications/79A81359-AD9D-4268-91FC-93D1E77F5208/Douban.fm.app/
1. 查看FAT信息
claud@Mac$ otool -f Douban.fm Fat headers fat_magic 0xcafebabe nfat_arch 2 architecture 0 cputype 12 cpusubtype 6 capabilities 0x0 offset 4096 size 1114560 align 2^12 (4096) architecture 1 cputype 12 cpusubtype 9 capabilities 0x0 offset 1122304 size 1121696 align 2^12 (4096)
2. 把ARMv7代码提取出来
claud@Mac$ lipo -thin armv7 Douban.fm -output Douban.fm.armv7
claud@Mac$ otool -l Douban.fm.armv7 | grep CRYPT -A 4 cmd LC_ENCRYPTION_INFO cmdsize 20 cryptoff 4096 cryptsize 876544 cryptid 1
claud@Mac$ otool -l Douban.fm.armv7 | grep __TEXT -A 3 -B 1 | head -12 cmdsize 600 segname __TEXT vmaddr 0x00001000 vmsize 0x000d7000 fileoff 0 -- sectname __text segname __TEXT addr 0x00002774 size 0x000aa9ec offset 6004 --
5. 安装兼容iOS 5的gdb调试器
cydia官方源的gdb目前与iOS 5的兼容性存在问题,遇到断点是断不下来并且报错,出错信息是:
../../gdb-1518/src/gdb/macosx/macosx-nat-mutils.c:772: internal-error: assertion failure in function "mach_xfer_memory": r_end >= cur_memaddr
iOS: root# gdb -q -e ./Douban.fm Reading symbols for shared libraries .. done (gdb) set sharedlibrary load-rules ".*" ".*" none (gdb) set inferior-auto-start-dyld off (gdb) set sharedlibrary preload-libraries off (gdb)
(gdb) rb doModInitFunctions Breakpoint 2 at 0x2fe0cece __dyld__ZN16ImageLoaderMachO18doModInitFunctionsERKN11ImageLoader11LinkContextE; (gdb)
(gdb) b *0x2774 Breakpoint 1 at 0x2774 (gdb)
(gdb) r Starting program: /private/var/mobile/Applications/79A81359-AD9D-4268-91FC-93D1E77F5208/Douban.fm.app/Douban.fm Breakpoint 1, 0x00002774 in ?? () (gdb)
(gdb) x /10i 0x2774 0x2774: 00 00 9d e5 ldr r0, [sp] 0x2778: 04 10 8d e2 add r1, sp, #4 ; 0x4 0x277c: 01 40 80 e2 add r4, r0, #1 ; 0x1 0x2780: 04 21 81 e0 add r2, r1, r4, lsl #2 0x2784: 07 d0 cd e3 bic sp, sp, #7 ; 0x7 0x2788: 02 30 a0 e1 mov r3, r2 0x278c: 04 40 93 e4 ldr r4, [r3], #4 0x2790: 00 00 54 e3 cmp r4, #0 ; 0x0 0x2794: fc ff ff 1a bne 0x278c 0x2798: 18 c0 9f e5 ldr r12, [pc, #24] ; 0x27b8 (gdb)
(gdb) dump memory Douban.fm.bin 0x2000 0xd8000 (gdb)
iOS: root# ls -l Douban.fm* -rwxr-xr-x 1 mobile mobile 2244000 Jun 1 20:06 Douban.fm* -rw-r--r-- 1 root mobile 876544 Jul 1 12:06 Douban.fm.bin
iOS: root# cp Douban.fm Douban.fm.dec iOS: root# dd bs=1 conv=notrunc if=Douban.fm.bin of=Douban.fm.dec skip=0 seek=1126400 count=876544