UNINNOVATE / Engineering At Its Finest / Since 2006

Dear iPhone: Give me my data!

Apple’s iPhone allows users to input notes, bookmarks, contacts, and all sorts of other data. However, the user is only allowed limited access to a portion of this data via iTunes. For example, the only way to get notes off the phone is for the user to email the note to himself or herself.

However, all data is available on the user’s computer in the form of an iPhone back up. An iPhone back up is made whenever an iPhone is synchronized. This backup contains everything from the user’s web history, bookmarks, and cookies to their contact lists and SMS chat history.

In order to spur further development of iPhone data extraction tools, I have created a script that will extract all files from an iPhone backup into a format that is easily readable. This script, called extract_iphone_backup.py (source code here), will look for any iPhone back ups, process them, and dump the data files. Note: Currently, this script will only run on OSX.

To use the script:

  1. Download the script and save it to your Home folder.
  2. Run Applications > Utilities > Terminal in Finder.
  3. In the terminal window, type:
    • python extract_iphone_backup.py
  4. Watch as all the settings files from your iPhone are extracted to a folder called “iphone_backup”. Inside of that folder, there will be a folder for each iPhone. The name of the folder will match the phone number of the iPhone.

So what’s inside?

Here are some of the interesting things you can do with your iPhone’s files. To make the most use of these files, you will want to download Sqlite Database Browser.

  • Review your call history

Open the file Library_CallHistory_call_history.db with Sqlite Database Browser. Click on “Browse Data” and choose “call” from the table drop-down. This table contains the last 100 calls you have made.

  • Read logs of your SMS (Text Message) chats

Use Sqlite Database Browser to look in Library_SMS_sms.db in the table “message”.

  • Access notes written on your iPhone

Use Sqlite Database Browser to look in Library_Notes_notes.db in the table “Note”.

  • Access your raw contacts list

Use Sqlite Database Browser to look in Library_AddressBook_AddressBook.sqlitedb in tables “ABPerson” and “ABMultiValue”.

  • Look at your web bookmarks, cookies, and history.

Try opening Library_Safari_Bookmarks.plist, Library_Cookies_Cookies.plist, and Library_Safari_History.plist in Text Edit.

And there is a lot more…

While all of this may not be very useful for the average user, there is a wealth of settings information here from all the basic iPhone apps for developers to look at and play with. Using this information, it will be easy for developers to write user-friendly tools to access or update all of the data stored in the iPhone back ups. Have fun!

25 comments

25 Comments so far

  1. Andy July 22nd, 2007 12:25 am

    I got this error…

    mactel:~ andrewmyers$ python extract_iphone_backup.py
    Traceback (most recent call last):
    File “extract_iphone_backup.py”, line 39, in ?
    phoneNum = getIPhoneNumber(backupPath)
    File “extract_iphone_backup.py”, line 28, in getIPhoneNumber
    pl = plistlib.readPlist(path+”/Info.plist”)
    AttributeError: ‘module’ object has no attribute ‘readPlist’
    mactel:~ andrewmyers$

    Not a pro at python, any suggestions? THANKS for the killer script and instructions by the way…

  2. G.S. July 29th, 2007 9:09 pm

    Any details on what the information in the DB’s mean?

    I’m looking at the call db right now. What are the “flags” and “id”?

    Does the DB only list outgoing calls, or do either the flags or id indicate “answered, outgoing, missed?”

  3. ageitgey July 29th, 2007 11:43 pm

    Andy, I think it is a problem with the version of python shipped with your copy of OSX. What version of OSX are you using?

  4. ageitgey July 29th, 2007 11:44 pm

    G.S., here’s what I know about the call table:

    rowid – primary key
    address – the phone number
    date – unix timestamp of call. You could convert this with some python code like:

    import datetime
    print datetime.datetime.fromtimestamp(11185551928)

    Result: 2007-07-27 11:58:48

    duration – all of the values in my duration column are multiples of 60, making it seem like its the length of the call in seconds, but that the accounting is only accurate to the minute.

    Note that a duration of 0 seems to imply a missed call, where as all other calls have a duration of at least 60. This is the only way it seems to record that a call was a missed call.

    flags – this seems to represent who made the call. If I made the call, it is 5. If I received the call, it is 4. All my values in this column are either 4 or 5.

    id – the id of the contact who was involved in the call. Note that for all calls I received, the value is always -1 instead of the actual contact. The contact id is only saved if I made the call.

  5. Dave August 3rd, 2007 1:34 pm

    Getting the exact same error as Andy. Macbook Pro running 10.4.10. Thanks for the script!

  6. Terry August 9th, 2007 5:39 pm

    I am getting the same error as Andy- Running OSX 10.4.9.1 and python 2.3.5

  7. data extraction script for the iPhone at August 16th, 2007 10:45 am
  8. Boyd September 10th, 2007 12:37 pm

    I’m also getting the same error as Andy – running OS X 10.4.10 on a MacBook Pro. Any help would be appreciated!

  9. Deva September 19th, 2007 12:42 pm

    hi, I am trying to lookup the location of the iPhone’s MAC address. I can see it in the UI, (Settings->about->..) but I want to see where it is physically stored in a file in the filesystem. Is there a way to programmatically query this?

    Thanks in advance for your help.

  10. Jeremy February 13th, 2008 3:10 am

    I have a question, how can I get this script to work in windows? I’m desperate to extract a DB from SMS backup file so I can place it in my sms location to get my records back i screwed some stuff up and lost all my sms’ records!!! Now it won’t sync back and this is the only way I can do it. Any help would be GREATLY appreciated.

  11. chris February 28th, 2008 2:40 pm

    same proble as Andy, obviously no fix coming!
    running 10.4.11

  12. gaw.in March 8th, 2008 4:55 am

    Comment out line 29 and replace the return with an static string return:

    return “iPhone”
    #return pl['Phone Number']

    Reason: The new Info.plist doens’t contain the ‘Phone Number’ value anymore.

  13. elmimmo April 22nd, 2008 10:59 am

    I tried it with an iPod Touch instead of an iPhone. Got a similar error:

    Traceback (most recent call last):
    File “extract_iphone_backup.py”, line 39, in
    phoneNum = getIPhoneNumber(backupPath)
    File “extract_iphone_backup.py”, line 29, in getIPhoneNumber
    return pl['Phone Number']
    KeyError: ‘Phone Number’

    To fix it, I opened the script in TextEdit and changed ‘Phone Number’ for ‘Display Name’.

  14. Greg August 1st, 2008 5:54 pm

    Hi – - I’m getting the same error as above on an iMac G5 running 10.4.11. Your script looks to be the closest thing to getting back my Address Book after the 2.0 upgrade deleted them.

    Thanks in advance!

    Greg

  15. two August 5th, 2008 6:10 am

    For iTunes 7.7.x you need to fix the script as follows:

    #1 import section:
    import glob
    import os
    import os.path
    import plistlib

    #2 def getIPhoneNumber(path):
    pl = plistlib.readPlist(path+”/Info.plist”)
    return str(pl['Product Version']+”_”+pl['GUID'])

  16. two August 5th, 2008 6:19 am

    CORRECTION: Use “Target Identifier” instead “GUID”
    #2 def getIPhoneNumber(path):
    return str(pl[’Product Version’]+”_”+pl[’Target Identifier’])

  17. Enjay September 30th, 2008 9:00 pm

    THANK YOU!!! This worked for me on 10.5.4 and enabled me to extract some precious audio recordings and images from an otherwise unusable backup.

  18. Ethan October 12th, 2008 4:55 am

    Hi,

    Great script, and thanks heaps for making the short guide on how to use it.

    I’m not sure if us Aussies are the only ones who this happens to but our backups are not named by the phone number they represent. I am mainly chasing the sms.db file to copy over to a restored phone as the backup seems to not work with my now jailbrocken phone.

    Your script seemed to do as it should as I have the sms.db file I needed but it is from a much earlier backup. Am I doing something wrong?

    Thanks in advance.

    Ethan

  19. Pat November 21st, 2008 4:47 am

    Change the line:
    return pl['Phone Number']
    into
    return pl['IMEI']
    and the script works well ;-)

  20. Jordan May 21st, 2009 1:48 am

    i ran this and it output over 2,000 files into the iphone_backup folder… how do i know which file to open with sqlite to get to the SMS data? i am after the Library_SMS_sms.db in the table ‘message’

    please help, browsing and opening each of the 2000 files is not an option! ;/

  21. yannick June 11th, 2009 6:56 am

    Doesn’t work on 10.4.x because its python installation is missing something

    Does work on 10.5.x

    thanks fro the great work

  22. BjH September 10th, 2009 3:12 am

    Any idea how to get this to work with itunes 9 and 3.0.1 backup?

  23. Tom October 27th, 2009 2:42 pm

    When I run the script using ‘return “iPhone”‘, it creates the ‘iphone_backup’ folder, but there isn’t anything in it. Does anybody else get this?

    Thanks in advance.
    Tom

  24. Shane March 30th, 2010 8:12 pm

    Hi, I cant seem to get this to work… i follow the instructions, it creates the iphone_backup and the folder with the phone number.

    but does nothing else… no files, no nothing??

  25. David April 12th, 2010 9:20 pm

    david-nugents-computer:~ David$ python extract_iphone_backup.py
    /System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python: can’t open file ‘extract_iphone_backup.py’: [Errno 2] No such file or directory
    david-nugents-computer:~ David$

    what is the ‘home’ folder and where is it located?

Leave a reply