Journal: 2009-01-31

So, today's challenge: Michelle desperately wanted one of the photos from my iPhone address book. Of course, that's not possible in the iPhone. Here's my work around:

Step 1. Make sure your iPhone is backed up.

Step 2. Check out mobilesync-inspect. Download a zip file of the command line tool and extract to a folder.

Step 3. Download and install Safari.

Step 4. Copy the necesarry DLLs (CoreFoundation.dll, icudt36.dll, icuin36.dll, icuuc36.dll) from Safari into the mobilesync-inspect folder

Step 5. Run mobilesync-inspect list to find out the contents of the iPhone backup directory. Pipe it to a file. Load the file into Excel. Use "Text to Columns" to separate out the colums. Sort by file name. Find the file that looks like it has address book photos: Library\AddressBook\AddressBookImages.sqlitedb

Step 6. Run mobilesync-inspect extract xxxx\xxxx.mdbackup AddressBookImages.sqlitedb to extract the SQLite database to a file.

Step 7. Run sqlite3 AddressBookImages.sqlitedb to inspect the file. Execute .tables to get the list of tables, and then .schema ABImage to find out the columns.

sqlite> .tables
ABImage                    _SqliteDatabaseProperties
sqlite> .schema ABImage
CREATE TABLE ABImage (record_id INTEGER, format INTEGER, crop_x INTEGER, crop_y INTEGER, crop_width INTEGER, crop_height INTEGER, data TEXT);
Run select record_id, format, crop_x, crop_y, crop_width, crop_height from ABImage order by record_id, format; to get an idea what the contents look like.
1|0|0|0|0|0
1|1|0|0|0|0
1|2|77|392|885|885
2|0|0|0|0|0
2|1|0|0|0|0
2|2|3|198|1201|1201
3|0|0|0|0|0
3|1|0|0|0|0
3|2|15|63|350|350
...

Step 8. Write a Ruby script to use the sqlite-ruby library to extract the images, like so:

# getphotos.rb
# Created by Louis Thomas on Jan 31, 2009

require 'sqlite3'

# CREATE TABLE ABImage (
#  record_id INTEGER, format INTEGER,
#  crop_x INTEGER, crop_y INTEGER, crop_width INTEGER, crop_height INTEGER,
#  data TEXT);
db=SQLite3::Database.new("AddressBookImages.sqlitedb");
db.execute("select record_id, format, data from ABImage order by record_id, format") do
  |row|
  record_id, format, data = row;
  file=File.new("img_#{record_id}_#{format}.jpg", "wb");
  file.print data;
  file.close;
  print "Wrote img_#{record_id}_#{format}.jpg";
end

Et Viola! All of the photos from your address book are now JPGs sitting in your directory. Of course, I did all this on Windows, but it should be pretty much the same on a Mac.

[ < Prev | Calendar | Next > ]
C o m m e n t s :    
(nothing yet)
Edit