Monday, April 18, 2011

Retrieve Data from iPhone

The story starts from a jailbreaked iPhone 3G that was left in a jacket pocket and had a long swim in the washing machine.
I was asked to help recover the contact numbers right after it.
After some searches, I found it is quite to achieve easy by knowing where the backup file is and with sqlite installed.

In windows7, you can find the backup files under:
C:\Documents and Settings\USERNAME\Application Data\Apple Computer\MobileSync\Backup
Then all you need to do is to download sqlite, query on the file that has the extension of *.mdbackup and save the output to a file and you are done. You can find detailed
steps here.

A few months later, this iPhone finished his trip to the other side of the world and back alive again. Sounds like a good ending huh?
BUT, one day his owner decided to upgrade it to the latest OS without having a second thought that it is already jailbreaked...

Right, this time it is locked. Everytime you switched on the phone, it tells you there's no sim card and you can make emergency call only. So he is back to my hand again. But crap I am not an iPhone expert, I failed to unlock it.

There is a video on youtube shows you how to unlock an iPhone 3G, I followed that but soon I find out it is not possible to do so since the iTunes is now updated to version 10.2 and they've locked that trick shown in the video.
Obviously you can downgrade your iTunes by remove the new one and install an old version, but it keeps saying a *.dll file that is created by a new version. If you've already have files backuped, you don't want to delete that...
So then I tried to install an old version (9.2) on an old laptop that has nothing important on there to have a go. This time I get a bit further to the point to restore the OS to 4.0. But if failed on verification... did some googling, there is a method to change your host file but it no longer works.
OK, so later on I find that you can downgrade it to a previous OS, so again I tried that, it restores fine but failed again when it tries to restart and verify, this time it is because it figured out the iPhone has already been updated to a later OS. Oh Christ! At this point I would rather go to the store and pay some money to unlock and un-jailbreak it. So, back to the original topic, retrieve data...

This time I found the *.mdbackup is missing! How awesome is that!? But thanks to Google, I found the solution again.
Obviously, the contact list is stored in this file under backup folder:
31bb7ba8914766d4ba40d6dfb6113c8b614be442.mddata


Refer to this tricks page for more information as well as some iPhone backup file schema.

Great! Now all I need to do is open up the windows command line tool, cd to where the backup file is and do:
"select ABPerson.first, ABPerson.last, ABMultiValue.value from ABPerson, ABMultiValu
e where ABMultiValue.record_id = ABPerson.ROWID" > ../contact.csv

Open the contact.csv file in the folder up a level and you will find all your contacts are there. I haven't figured out how to deal with the UTF-8 codings yet, but it is good enough for now. Of course there are softwares available on the internet but requires an expensive licence fee (from my point of view, a small software like this does not deserve $25 USD).

This time I also need to retrieve the photos if possible, I found a useful post but sorry I forgot where I keep the link. Apparently, iPhone does not backup your photos to a particular folder, simply renaming the *.mddata to *.jpg you can retrieve some of your photos!!! Some of the photos are still corrupted, but I got most of the photos that I want so it is good to me. You can find tools to retrieve corrupted jpg online with a price though.

So firstly copy all your *.mddata files (those that have a reasonable size to be a photo) to a place and in the windows command line tool, do:
ren *.mddata *.jpg

Try open them up in an image review tool to make sure they are the images that you want.

0 comments: