Reading iPhone GPS data from backup (with Java)

Reading iPhone GPS data from backup (with Java)

Today I noticed the following post on Slashdot: Apple Logging Locations of All iPhone Users

And the article they are referring to can be found here

First I was amazed, how can Apple do this? But on second thought, they aren’t sending it yet to anybody, it is just something on the phone (and also on the phone’s backup). My next reaction was: I want to see my own map! But to my disappointment it only works on Apple Mac’s, not Windows/Linux.

(Re-)building it in Java

Because their code is open source and well explained on the website I decided to make my own version, in Java (cross platform!). Now, just a couple of hours since I read the article, I’ve got it working and it can be used as a base for extention. So I’d like to share the code!

Step 1: Getting the correct file

This step was the hardest part, technically. The backup Apple makes doesn’t just have all the files as they are on your iPhone. Instead they all have names like: “b4d1c79c2f5fc1da044c18d1066b80b39b575590”. They do however store the information in two files: Manifest.mbdb and Manifest.mbdx.

The MBDB file only contains information about the original files, and the MBDX file contains pointers into the MBDB file with the Hex-filenames used in the backup. So we need to parse both files to be able to connect the original filename to the Hex-filename.

Luckely somebody already did this in Python and posted it on stackoverflow. I took their idea and translated it into Java code.

When this was fully translated it could resolve all the filenames. This meant I could map the target file “Library/Caches/locationd/consolidated.db” to the hex-filename “4096c9ec676f2847dc283405900e284a7c815836”.

Step 2: Reading the SQLLite file

The contents of “4096c9ec676f2847dc283405900e284a7c815836” is just a SQLLite file. For this I decided to use SQLJet, a framework that can read(/and write) SQLLite files. Using just a couple of lines of code I had all the data I need: timestamp, latitude, longitude (and more! speed, course, confidence, altitude etc).

Step 3: What to do with the geo data?

The implementation created by Pete Warden has a nice map and timeline. But at this time I wanted to have results as fast as possible. That is why chose to just output a KML file. KML is a file format used by Google Earth and other applications.

The results are far from nice (just plain ugly) but fun: click here for a screenshot

Running the code

The above code is mainly created for developers, the resulting JAR can’t be executed. But I’m aware people will want to just have the KML file, and not go through the code. That is why I’ve uploaded an executable JAR. You can get it here: runnableiPhoneJTrack.zip (813 KB)

To run the program, extract the three JAR-files and type:

Usage:
java -jar iPhoneJTrack.jar "<location of backup directory>"

For example:
java -jar iPhoneTracker.jar "C:\Users\roy\AppData\Roaming\Apple Computer\MobileSync\Backup\b4d1c79c2f5fc1da044c18d1066b80b39b575590"

This outputs a file named iPhoneData.kml, which can be loaded for example in Google Earth.

Playing with the code

I’ve pushed my code onto GitHub: https://github.com/royvanrijn/iPhoneJTrack

Feel free to add features and send me pull requests!