tylerpierce (tylerpierce) wrote,

Look up the number

I've accepted for a while that I am going to need a new phone in the near future, or possibly have to fall back to my emergency backup phone. In the worst case, my phone is lost or stolen or destroyed, and I lose the information stored in it.

This is no longer much of a risk.

A couple years ago I bought a SIM backup device while having my phone unlocked. It's a nice little unit, but does require the phone to be powered off with the SIM removed to operate. There's also no way to get at the information once it's backed up besides restoring it to another SIM. When a new SIM is detected by my phone, all data stored in the memory is deleted. Lastly, my phone doesn't store SMS messages to the SIM, so I lose those entirely, along with the handful of pictures. Clearly this is a sub-optimal answer.

The Hayes AT command set has, over the decades, been extended beyond what small original goals it had. So much so that the GSM standard defines even more commands to access a phone's memory and status.

From there it got easy. I've put together a couple hundred lines of python that retrieve all stored phone numbers from both the SIM and phone memory, and all SMS messages, and either print them to the screen or insert them into a small mysql database.

mysql> describe phonebook;
| Field     | Type        | Null | Key | Default           | Extra |
| imei      | bigint(20)  | YES  |     | NULL              |       | 
| slot      | int(11)     | YES  |     | NULL              |       | 
| type      | int(11)     | YES  |     | NULL              |       | 
| number    | varchar(64) | YES  |     | NULL              |       | 
| name      | varchar(64) | YES  |     | NULL              |       | 
| entry     | varchar(64) | YES  |     | NULL              |       | 
| timestamp | timestamp   | NO   |     | CURRENT_TIMESTAMP |       | 

A couple of items worth noting:

  • the IMEI is a unique identifier to the hardware of the phone. By including it, I can back up multiple phones to the same database.
  • all backups are INSERTs. This seems vaguely wasteful until the tiny amount of data is made clear; even a full phone has approximately 200 phone numbers. It requires under 256 bytes to back up each record; if it was backed up every day for a year, the amount of space required is less than the size of promotional thumbdrives being given away.
  • "number" is a normalized North American 10 digit number in my software. This is differentiated from "entry" which could contain pauses or DTMF information.

I don't pretend that this is something groundbreaking. It was just a neat way to spend a day solving one of my own problems.
  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.