iPhone SMS read from sms.db

  • Comments Off

(I’m referring to an iPhone which isn’t jailbroken)

I was wondering how to read SMS content programmatically (Objective-c) from my iPhone.
But something is wrong on new FW 4.3.5
Let me explain …

What we need :
Step #1 : explore sms.db structure
Step #2 : find on iPhone the location sms store
Step #3 : try to read

Step #1 : explore sms.db structure

In order to explore and understand sms.db we will use the backup file made by iTunes when we backup our iPhone.
Since  sms.db (such as any other storage db on iPhone) is a sqlite file we need to have a sqllite browser : sqlitebrowser200b1osx.zip
from here :
http://sourceforge.net/projects/sqlitebrowser/files/sqlitebrowser/2.0%20beta1/sqlitebrowser
200b1osx.zip/download

Now explore sms.db using local backup … so open Terminal and follow below steps :

  • cd ~/Library/Application Support/MobileSync/Backup
  • find . -iname 3d0d7e5fb2ce288813306e4d4636395e047a3d28
    • (you obtain a list of directory which contains that file … so you have to chose one)
  • Run “SQLite Database Browser 2.0 b1.app” then open file 3d0d7e5fb2ce288813306e4d4636395e047a3d28

You can easily browse this file using sqlite so that discover :
-  table name : message (select * from message)
-  columns of table :

ROWID
address
date
text
flags
replace
svc_center
group_id
association_id
height
UIFlags
version
subject
country
headers
recipients
read

Where:

address : phone number from
date :
timestamp
Flags : 2 = received / 3 = sent / 33 = ? / 129 = deleted
group_id : it indicates the conversation

Step #2 : find on iPhone the location

From google a possible location on iPhone filesystem is :
-> /private/var/mobile/Library/SMS/sms.db

(on OLD FW : /var/mobile/Library/SMS/sms.db)
(and other places…)

Since I wasn’t able to load from location that I found I decided to explore myself the iPhone contents with following lines :

Output of above snippet is :

LOG: 2011-08-02 16:36:00.713 ******[975:707] Directory '/var/mobile/Library' has content : '(
".localized",
AddressBook,
Caches,
Calendar,
...
SMS,<=========!!!!
Safari,
SafeHarbor,
...
)'

So directory is present but the problem is when we try to get content of SMS.
Using above code changing NSString* path = @”/var/mobile/Library/SMS“; 

Output is now : 

/var/mobile/Library/SMS/
2011-08-02 16:39:52.281 *******[994:707] Directory '/var/mobile/Library/SMS/' has content : '(null)'

The same result if we try with : /private/var/mobile/Library/SMS -> has content ‘(null)’
… maybe  new FW has permissions changed on this location
… or location is wrong…

I’ll try to investigate but it seems that SMS isn’t readable (schreenhot by a my filebrowser-test app)
img 0585 copy iPhone SMS read from sms.db iphone Fail

Step #3 : try to read

I tryed to read some .db (such as sms.db) with below code  the only which working was: callhistory.db
placed here : /private/var/wireless/Library/CallHistory/callhistory.db

Other location that I found (but not all checked yet) :

/private/var/mobile/Library/CallHistory/call_history.db:
/private/var/mobile/Library/SMS/sms.db
/private/var/mobile/Library/AddressBook/AddressBook.sqlitedb
/private/var/mobile/Library/AddressBook/AddressBookImages.sqlitedb
/private/var/mobile/Library/Calendar/Calendar.sqlitedb
/private/var/mobile/Library/Notes/notes.db
/private/var/mobile/Library/Safari/Bookmarks.plist
/private/var/mobile/Library/Safari/History.plist
/private/var/mobile/Library/Safari/SuspendState.plist
/private/var/mobile/Library/YouTube/Bookmarks.plist
/private/var/mobile/Library/Mail/Accounts.plist
/private/var/preferences/SystemConfiguration/com.apple.network.identification.plist
/private/var/preferences/SystemConfiguration/com.apple.wifi.plist
/private/var/Keychains/keychain-2.db

I’ll update this post if I’ll find something else.

Incoming search terms: