Archive for category iPhone

Library Persistent ID in iTunes 10.0

Apple must have realized of what we are doing by messing about with the Persistent ID and have introduced some changes in iTunes 10.0 to prevent this.

Among other changes (including an arguably worse application icon) they must have added some extra checking of the Library ID stored in the binary file of the iTunes Library (Tunes Library.itl on Windows). It now contains some CRC or similar mechanism, which is used to verify that the Persistent ID stored in the file is actually the one generated when the library was created. This explains why if you change just the bytes that contain the ID, iTunes detects that the ID has been tampered and is capable of SILENTLY restoring the previous ID.

I did not have time to check where else in the binary file iTunes checks if the Persistent ID is what it claims to be… but I found a quick and dirty way to overcome this new security measure.
iTunes has a feature that allows rebuilding the binary version of the library in case it gets corrupted… and guess what, it does so by reading the data in the XML version.

So all that you have to do is edit the XML library, corrupt the binary version, and start iTunes … Et voilà! iTunes rebuilds a perfect 10.0 library for you using your new Persistent ID.

iTunes DB Cloner is a free Windows utility that does all this for you.

iTunes DB Cloner 0.9.1.0

I would love to think that Apple will leave this feature in future releases. You can imagine the disaster it would be if your library gets corrupted by normal usage (i.e.: The computer unexpectedly powers off in the middle of an update) and you lost months of work classifying music :)

But who knows, Apple is becoming the figure of the Big Brother (IBM) they depicted in their 1984 commercial, so I would not hope this to last too long.

In the meantime, let’s enjoy some freedom to manage our iPhones in our different computers.

How to retrieve the iTunes Persistent ID from your iPhone

What if there is no way to recover your last iTunes Persistent ID from your PC/Mac? i.e. You have formatted your computer, have no longer access to it, or even worse, it’s been stolen.

In order to avoid erasing your iPhone/iPodTouch and starting all over again, there is still a chance to retrieve this magic ID, so you can then use it to make your computer’s iTunes library to match it.

Since a couple of guys have already asked about this, I though it might be of some help to describe how to do this.

I am aware that this method may seem fairly discouraging to most users, but I would also add that it’s not as complex at it may seem at first sight.

First of all, you will need to have access to your iPhone’s operating system (i.e. be able to browse through its files). The only way I know so far is to have the iPhone jailbroken. If you don’t know yet what this is,  iClarified has probably the best tutorials I have seen about this.

If you already have your iPhone jailbroken read on.

The idea is to get the iTunes Persistent ID directly from the very same file where it is stored inside your iPhone. This file is binary (and there is no XML equivalent pair as in the PC/Mac version of the iTunes library). The persistent ID is stored here, in a very similar way as Andrew found out for the PC/Mac versions of the library.

The Persistent ID is 8 byte long and spans exactly from byte 37-44. Bear in mind that the iPhone platform is little-endian, while PC and Intel Macs are big-endian. This means that the bytes are stored in a different order on the iPhone and on the computer (either PC or Intel Mac).

Probably I may be getting a bit too technical, so the best way to illustrate this method is to actually describe a sample process to read this ID.

I have chosen a very simple approach where you only need to log on your iPhone via ssh and type a couple of commands.

Get network access from your computer to your iPhone

1) Make sure your iPhone is jailbroken and has the SSH package installed. If not, you can use Cydia or Installer to get it on your device.
2) Connect your iPhone to the same Wi-Fi network your computer has access to. In the example below, my WiFi network is named LUCERO.

wifi1

3) Take note of the IP address of your device. This can be easily retrieved by touching the blue > sign at the right of your WLAN’s name. A new screen with some connection’s details appear. In the screenshot below, the IP address of the iPhone is 192.168.1.101.

wifi2

4) I will highly recommend to turn off momentarily the Auto-Lock feature of the phone, since the SSH connection will be guillotined if the iPhone enters in standby mode (blank screen). Go to Settings, General, Auto-Lock and select Never. You can turn this option on again once you are done reading the ID.

autolock-off

5) Connect via ssh to your phone, using the IP address you have written before (192.168.1.101 in my example). MacOS has a nice SSH client built in, and you only need to type ssh and the address in a command line window (i.e: ssh 192.168.1.101). On Windows, I would recommend downloading and installing putty, a really nice and free ssh protocol client.

putty

6) Once you have your ssh connected to your iPhone you will be prompted to enter a user and a password. User is “root” and password is “alpine” (without the quotes!).

login as: root
root@192.168.1.101's password:
localhost:~ root#

View the contents of the iTunes database file

7) Don’t take my word for it and locate the actual location of the iTunes library file on your iPhone.

localhost:~ root# find / -name iTunesDB
/private/var/mobile/Media/iTunes_Control/iTunes/iTunesDB
localhost:~ root#

8 ) This is the file that contains your lost Persistent ID. You can choose to view its contents as you want, but I think good old vi editor is an easy choice for this purpose. Don’t worry about what you may have heard about the toughness of this editor. We are only going to use it very briefly, so you don’t need to be a unix geek.

vi /private/var/mobile/Media/iTunes_Control/iTunes/iTunesDB

If the above command fails, you need to install the vi package (again, use Cydia or Installer).
The result is an scrambled window with some funny characters. Remember iTunesDB is a binary file, so we need to turn on the hexadecimal editor mode of vi.
Press [escape] to enter in the command mode and type

:%!xxd

Now the window should look like this:

vi-hex

9) Now take note of the bytes 37 to 44 and write them somewhere or copy them to a text file. In the screenshot below, these bytes are  2e94 2b95 87f2 8cde.

10) Hurray you are a genius and have extracted the Persistent ID! The hardest part is now done. Give yourself a kiss and keep on reading. We are almost there.

Re-write the Persistent ID value in the appropriate (byte) order

10) Now write these value again in reverse order (remember the big endianness of the PC/Intel Macs); bearing in mind that a byte is shown as 2 hexadecimal characters, so you have to take them in pairs. I would also remove any white space in between so you can copy and paste the result in iTunes DB Cloner. Lost? Don’t worry, check the sample value: 2e94 2b95 87f2 8cde converted to big endian is DE8CF287952B942E.

Update your computer’s iTunes library to match the Persistent ID on your device

11) Now use this value in iTunes DB Cloner to alter your PC’s iTunes library, so it matches the persistent ID already stored in your iPhone. If you are using a Mac, update the value following Andrew’s instructions.

itdbc-update

12) You can now logoff from your iPhone’s unix shell. Type q! in your vi window. and then logout or press CONTROL+D to end your terminal session. Remember to turn on again the Auto-Lock feature to some value or your iPhone will remain on if you don’t send it to sleep manually by pressing the power button.

… and that’s all folks. Hope it was of some help to those of you as desperate to save your iTunes library as to have read all this.

This post was written in bit of a hurry, so I might have not been clear enough. Any comments or requests for clarifications will be welcomed.

iPhone FAQ

Updated: This is from when I had an iPhone “2G” with firmware 1.1.4. I guess that this error is long fixed now in current versions. I just keep this here for my records.

Quick solutions to annoying problems I found with my iPhone. Note that it needs to be jailbroken in order for you to logon into it by ssh.

1.- Mail application crashes (starts, shows white screen for a couple of seconds and then goes back to the home screen).
You have probably wrong file permissions for the directory /private/var/mobile. Use any method of your choice to reset them to user mobile, group mobile. If you can get a command shell easily (install Term vt100 for instance); issue this:

chown -R mobile:mobile /private/var/mobile
2.- I can’t login as root using Term vt100 or similar terminal emulation apps.
Password is either dottie or alpine. If you keep receiving that the password is incorrect, check connecting to the iPhone from another computer in the same WiFi with user root and one of the 2 possible passwords. If you can logon from outside the phone, this is probably due by wrong file attributes in the executable terminal app.

Check file properties for your installed app executable.

# ls -al /Applications/Term-vt100.app
total 296
drwxr-xr-x 2 root admin 238 Apr 20 02:58 .
drwxrwxr-x 49 root admin 1666 Apr 20 03:10 ..
-rw-r--r-- 1 root admin 5131 Apr 20 02:58 Default.png
-rw-r--r-- 1 root admin 633 Apr 20 02:58 Info.plist
-rw-r-xr-x 1 root admin 97976 Apr 20 02:58 Term-vt100
-rw-r--r-- 1 root admin 2514 Apr 20 02:58 icon.png
-rw-r--r-- 1 root admin 34673 Apr 20 02:58 pie.png

The executable program should be su-rooted.

chmod +s /Applications/Term-vt100.app/Term-vt100

Upload your own iPhone ringtones

3iphones.png

How come that I have a $299 state-of-the-art mobile phone and can’t do simply things available in $80 Nokias?

I have a pretty capacious MP3 player and can not select any of its thousands songs as a ringtone!?

Of course, Apple provides a method por uploading new ringtones to the iPhone, but most of them either involves money or are quite discouraging.

I finally found my own way to upload any song as a ringtone. Nothing big, I just took a look to iPhone’s internal folders.

You need to be able to upload files to your iPhone by some means (Samba, SCP, etc).

  1. Edit your ringtone with your sound editing tool of preference and store it in a format like mp3.
  2. Convert the audio file to AAC. I use iTunes to convert files from MP3 to AAC (.m4a). For this to be possible make sure you have iTunes set to import files with AAC Encoder.
  3. Add your ringtone mp3 to iTunes Library. Right click on it and select “Convert Selection to AAC”. When the process finishes, check the generated file under your iTunes folder (somewhere like C:\Documents and Settings\<your user name>\My Music\iTunes\iTunes Music\).
  4. Copy your converted AAC file into the Library\Ringtone folder under your iPhone root directory.
  5. Rename its extension from .m4a to .m4r.

The next time you try to change the ringtone, your uploaded file will appear in the list.