Skip to content

Instantly share code, notes, and snippets.

@John07
Last active March 16, 2024 22:38
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save John07/5240878 to your computer and use it in GitHub Desktop.
Save John07/5240878 to your computer and use it in GitHub Desktop.
Get all your messages (SMS and iMessage) from your iOS device without jailbreak or proprietary tools. Assumes you have an encrypted backup of your iOS device on your Mac.
# Note: this is not a fully functioning script! You will need to edit paths and other variables manually and it's adviced to run each command manually one after another
# install dependencies
# http://www.securitylearn.net/tag/deep-analysis-of-itunes-backup/
sudo ARCHFLAGS='-arch i386 -arch x86_64' easy_install pycrypto
sudo easy_install M2crypto construct progressbar
# clone the decrypt tool source code
# hg stands for mercurial
hg clone https://code.google.com/p/iphone-dataprotection/
# run decrypt tool. Note that this will decyrpt your backup on your Mac and you should be aware of the security implications
# http://stackoverflow.com/questions/1498342/how-to-decrypt-an-encrypted-apple-itunes-iphone-backup
python iphone-dataprotection/python_scripts/backup_tool.py /Users/<user>/Library/Application\ Support/MobileSync/Backup/<long_hex_string> ~/<outdir path>
# search for sms.db or manually look for it in ~/<outdir path>/HomeDomain/Library/SMS
# copy sms.db to some other place
# http://apple.stackexchange.com/questions/6900/how-can-i-export-sms-text-messages-from-my-iphone
# export your messages neatly formatted
# http://linuxsleuthing.blogspot.de/2012/10/whos-texting-ios6-smsdb.html
sqlite3 sms.db
.output messageslog.txt
SELECT m.rowid as RowID, DATETIME(date + 978307200, 'unixepoch', 'localtime') as Date, h.id as "Phone Number", m.service as Service, CASE is_from_me WHEN 0 THEN "Received" WHEN 1 THEN "Sent" ELSE "Unknown" END as Type, CASE WHEN date_read > 0 THEN DATETIME(date_read + 978307200, 'unixepoch', 'utc') WHEN date_delivered > 0 THEN DATETIME(date_delivered + 978307200, 'unixepoch', 'utc') ELSE NULL END as "Date Read/Sent", text as Text FROM message m, handle h WHERE h.rowid = m.handle_id ORDER BY m.rowid ASC;
# you can also use https://github.com/toffer/iphone-sms-backup/pull/8 for even nicer formatting
# delete your unencrypted backup!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment