iPhone App 수정을 위한 메모리덤프 화일 만들기
카테고리 없음 / 2010. 11. 15. 10:28
iPhone App의 암호화된 실행화일을 수정할 일이 생겼을때 1차적으로 해야할 작업은 iPhone App메모리 덤프화일을 만드는 작업을 해야합니다.
일단은 탈옥폰이어야 겠죠.
또한 Cydia의 GDB Debugger가 설치되어 있어야 합니다.(gdb, otool 실행이 필요합니다)
openSSH도 설치및 가동이 되어야 하고요.
beyouriphone이 사라져서 GDB Debugger를 구하기 어려우신분들은..
http://leejoshua.tistory.com/44 <- 이곳에 가시면 구하실수 있습니다.
PC에서 iPhone으로 ssh접속을 합니다.
터미널(Windows SecureCRT)
ssh -2 root@192.168.X.X
접속할때 password는 변경하신분도 계시겠지만..변경을 하지 않았다면 "alpine" 입니다.
왠만하면 변경을 하시는것이 좋을뜻합니다.
변경방법은..iPhone이 접속된 터미널에서 passwd 엔터치시면 패스워드 물어보고 새로운 패스워드 입력합니다.
root뿐만 아니라..기본 유저아이디 mobile도 변경을 해주시는것이 좋습니다.
터미널 상태에서
su mobile 엔터하시면 전환이 됩니다.
똑같이
passwd 엔터하셔서..변경후에..
exit 엔터하시면 root로 돌아옵니다.
자~ 이제 gdb유뮤확인을 해시죠.
NUTTone:~ root# gdb <- 터미널에서 "gdb"를 실행시켜본다.
GNU gdb 6.3.50.20050815-cvs (Sat Sep 19 05:37:57 UTC 2009)
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)...
위와같이 gdb에 shell로 들어갑니다.
빠져 나올때는 quit로~
NUTTone:~ root# otool <- "otool"를 실행시켜본다.
Usage: otool [-fahlLDtdorSTMRIHvVcXm] <object file> ...
-f print the fat headers
-a print the archive header
-h print the mach header
-l print the load commands
-L print shared libraries used
-D print shared library id name
-t print the text section (disassemble with -v)
-p <routine name> start dissassemble from routine name
-s <segname> <sectname> print contents of section
-d print the data section
-o print the Objective-C segment
-r print the relocation entries
-S print the table of contents of a library
-T print the table of contents of a dynamic shared library
-M print the module table of a dynamic shared library
-R print the reference table of a dynamic shared library
-I print the indirect symbol table
-H print the two-level hints table
-v print verbosely (symbolicly) when possible
-V print disassembled operands symbolicly
-c print argument strings of a core file
-X print no leading addresses or headers
-m don't use archive(member) syntax
-B force Thumb disassembly (ARM objects only)
이제 덤프메모리를 만들준비는 끝났습니다.
수정할 App이 있는 디렉토리를 찾아야 합니다~
방법은 두가지가 있습니다.
SBSetting, iFile를 이용하는 방법이죠.
먼저 SBSetting을 이용한 방법입니다.

설정아이콘을 클릭합니다.

맨 하단에 있는 App Folders를 클릭.

앱들 리스트가 뜹니다. 그중에서 덤프화일을 만들 앱을 선택하여 클릭하면.

위의 그림과 같이 디렉토리 정보가 뜹니다.
뒷부분에 코드화되어있는것을 메모해 두십시요.
이번에는 iFile을 이용한 디렉토리정보를 얻어보겠습니다.

먼저 왼쪽하단에 있는 설정아이콘을 클릭합니다.

먼저 왼쪽하단에 있는 설정아이콘을 클릭합니다.

Application Names부분을 체크합니다.
이 부분을 체크하면 코드화되어있는 앱디렉토리로 보이지 않고 원래 앱이름으로 순차적으로 나열됩니다.

이상태로도 앱디렉토리명을 볼수있고.
오른쪽 화살표아이콘을 클릭하시면. 좀더 자세한 정보를 얻을수있습니다.

Name을 클릭하시면 선택하여 카피를 하실수있습니다.
절대 수정을 하시면 안됩니다.
실수를 하실수도 있으니 전단계에서 앱디렉토리정보를 메모해 두십시요.
자~ 이제 dump할 앱으로 이동해 봅시다.
NUTTone:~ root# cd /User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A/
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root# ls -l
total 32
drwxr-xr-x 4 mobile mobile 136 May 8 20:34 Documents/
drwxr-xr-x 12 mobile mobile 748 May 8 02:05 HancomViewer.app/
drwxr-xr-x 4 mobile mobile 136 May 8 02:06 Library/
-rwxr-xr-x 1 mobile mobile 22490 May 8 01:52 iTunesArtwork*
-rwxr-xr-x 1 mobile mobile 2210 May 8 01:52 iTunesMetadata.plist*
drwxr-xr-x 2 mobile mobile 68 May 10 12:25 tmp/
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root#
HancomViewer.app/ <- 안에 HancomViewer 이란 실행화일이 있습니다.
그 안까지는 들어가지 마십시요.
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root# otool -l ./HancomViewer.app/HancomViewer | grep crypt
cryptoff 4096
cryptsize 6463488
cryptid 1
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root#
otool 명령어로 암호화된 화일크기를 구합니다.
중간에 cryptsize가 화일크기입니다. 이 값을 메모하십시요.
이제 memory dump를 본격적으로 시작해 봅니다.
이해하기 쉽게 설명을 드리자면~
화일이 암호화되어 있기때문에 화일자체로 dump를 뜨는것은 소용이 없습니다.
하지만 앱이 실행이 된후에는 memory상에 암호화가 풀려 상주하기 때문에 memory상에 있는 코드를 캡쳐해서 저장하는 방식입니다.
그래서 memory dump라고 이해하시면 되겠습니다.
먼저 아이폰에서 앱을 실행시킵니다.
제일 중요한것은 openSSH를 통해 PC와 계속 연결이 되어 있어야 합니다.
자동으로 슬림모드가 되는것을 꺼놓아야 끊기지 않고 유지가 잘됩니다.
혹시나 끊겼으면 다시 연결하시면 됩니다.
아이폰에서 앱을 실행시켰으면..
터미널에서..
다음과 같은 명령을 실행시킵니다.
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root# ps ax | grep HancomViewer
1126 ?? Ss 0:01.32 /var/mobile/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A/HancomViewer.app/HancomViewer
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root#
아이폰에서 실행중인 앱의 프로세스ID를 찾아주는겁니다.
1126번이 현재 아이폰에서 실행되는 앱의 프로세스ID입니다.
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root# gdb -p 1126
GNU gdb 6.3.50.20050815-cvs (Sat Sep 19 05:37:57 UTC 2009)
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=".
/private/var/mobile/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A/1126: No such file or directory
Attaching to process 1126.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ............................................................................................ done
0x328c17f8 in mach_msg_trap ()
(gdb)
프로세서아이디의 앱을 디버깅합니다.
메모리상에 상주하고 있는 앱을 gdb합니다.
gdb SHELL로 입장했습니다.
바로 dump하는 방법으로 넘어가겠습니다.
dump memory dump.bin 0x2000 {app total address}
memory dump해서 dump.bin이란 화일로 저장합니다. 저장되는곳은 앱폴더입니다.
메모리시작주소는 0x2000이고 제일 중요한 메모리끝주소는..아까 암호화된 앱화일크기로 계산해서 산출하면 됩니다.
계산방식은 cryptsize + 8192 = HEX전환
OSX에 기본적으로 있는 계산기를 이용해 보겠습니다.

먼저 프로그래머 계산기로 전환합니다.

프로그래머 16진수모드입니다.

그림과 같이 8/10/16중에 10을 클릭하시면 10진수로 바뀝니다.
10진수모드가 되면~
cryptsize + 8192를 대입해서 계산하십시요.
6463488 + 8192 = 6471680

위와같이 값이 나오며..10진수값을 16진수로 변환을 해야합니다.

위와같이 값이 나오며..10진수값을 16진수로 변환을 해야합니다.

간단하게 16버튼을 클릭하면 전환이 됩니다.
0x62C000 <- 이것이 메모리덤프를 위한 끝주소입니다.
자 그럼 실행시켜보죠.
dump memory dump.bin 0x2000 0x62C000
아무런 메세지도 없습니다.
quit <- 엔터를 쳐서 빠져나옵니다.
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root# ls -l
total 6344
drwxr-xr-x 4 mobile mobile 136 May 8 20:34 Documents/
drwxr-xr-x 12 mobile mobile 748 May 8 02:05 HancomViewer.app/
drwxr-xr-x 4 mobile mobile 136 May 8 02:06 Library/
-rw-r--r-- 1 root mobile 6463488 May 31 17:46 dump.bin
-rwxr-xr-x 1 mobile mobile 22490 May 8 01:52 iTunesArtwork*
-rwxr-xr-x 1 mobile mobile 2210 May 8 01:52 iTunesMetadata.plist*
drwxr-xr-x 2 mobile mobile 68 May 10 12:25 tmp/
NUTTone:/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A root#
빠져나와서 파일을 리스트해보면 위와같이 dump.bin이란 화일이 생성이 되었습니다.
dump.bin화일을 PC로 가져가면 memory dump 화일 생성은 끝입니다.
가져가는 방법은 여러가지 입니다.
iFile을 이용한 방법도 있고..DiskAid..PhoneView..Transmit..등등..
iFile를 이용한 방법을 설명하겠습니다.

오른쪽 화일표아이콘을 클릭하지 마시고..그냥 "한컴뷰어"를 클릭하여 디렉토리로 이동합니다.

이동하시면 dump.bin화일이 보일껍니다.
하단에 왼쪽편에 있는 Wifi아이콘을 클릭하세요~

웹서버가 시동이 됩니다.
주소는 http://192.168.10.2:10000(집이나 회사의 사설네트워크의 주소에 따라 다르게나옴)

앱디렉토리까지 이동을 한 상태입니다.
/User/Applications/249E009F-E7B4-4CCA-8F86-2A8773A3DE5A
