NiceGuyUK Blog

NiceGuyUK's blog

Monday, September 17, 2007

Making the new iPods work with Linux

Here is a quick howto on using wtbw’s code in linux to use a new generation iPod.

  1. Download the code.

  2. Plug your ipod in and make sure it is mounted and run:
    sudo lsusb -v | grep -i Serial

    Look for your iPod device, and the firewireID should be the 16 character long hex string shown.
    It should look something like this:
    00A1234567891231

    This number should be broken up into 2-letter chunks for input into the file, so the above would
    look like so:
    0×00, 0xA1, 0×23, 0×45, 0×67, 0×89, 0×12, 0×31

  3. Edit main.cpp in the hash_crack directory and read the commetns at the top. You should insert your firewire ID where the comments specify, then run make to compile the hash program.

  4. Next, sync your ipod with gtkpod, rhythmbox, banshee or Amarok, or whatever ur used to just like normal. Once this is complete, you should have an ipod with songs on it, that refuses to view the songs. To make it “see” the songs, u need to run the hash program we just compiled on the iTunesDB file. This should happen something like this:
    ./gethash /path/to/iPod/iPod_Control/iTunes/iTunesDB

    This should output the proper hash for the current state of the iTunesDB, as well as the old hash for the previous state of the iTunesDB. We just need the first value.

  5. Write this new hash value to the proper location in the iTunesDB where the hash is stored at address 0×58 of the iTunesDB file. This can be done with a program such as bvi.

    Note: You will need to do the process of getting the hash on your iTunesDB every time you even so much as change a song name, or upload new music or video files.

6 Comments:

  • At 11:36 PM , Blogger Jamil said...

    This method works quite well!
    I have used it with my iPod Touch.

    I have also created a perl script that automates the processes 4 and 5(when you want to use a client like amarok or whatever)

    If you have any questions on how to work it, send me a mail: jbenalluch [at] gmail.com


    #!/usr/bin/perl
    #
    # Created by Jamil Ben Alluch
    # use/change/update/modify/whatever the hell you want at will
    #
    # usage: iTunesDBFix
    #
    # notes: must be in the same directory as program gethash
    #

    $ipoddir = "/mnt/ipod"; #**** change here to ipod mount point *****#
    $gethashdir = "/scripts/ipod";
    $file = "$ipoddir/iPod_Control/iTunes/iTunesDB";
    #$file = "iTunesDB"; #debug
    $filesize = -s $file;
    $numargs = $#ARGV+1;
    $buffer = "";
    $hash = "";


    #verification method, displays what is at position 0x58 to +0x14
    sub gridDsp
    {
    printf "----------------\n";

    $count = 0;
    foreach (split(//,$buffer))
    {

    #printf("%02x ", ord($_));
    if($count >= 0x50 && $count < 0x70)
    {
    if($count % 0x10 eq 0x0)
    {
    printf ("%05x - ", $count);
    }

    if($count >= 0x58 && $count < (0x58+0x15-0x1))
    {
    printf("\33[32m%02x\33[0m ", ord($_));
    }
    else
    {
    printf("%02x ", ord($_));
    }

    if(($count + 1) % 0x10 eq 0x0)
    {
    printf "\n";
    }
    #$count = 0;
    }

    $count++;
    }
    printf "\n-----------------\n";
    }

    #replaces hash value
    sub replaceHash
    {
    for($i=0x0; $i<0x14; $i+= 0x1)
    {
    $hex = substr($hash, $i*2, 0x2);
    substr($buffer, $i+0x58, 0x1, chr(hex $hex));
    }
    }

    #write file
    sub writeFile
    {
    $newfile = $file; #v2
    #$newfile = "iTunesDB.new"; #v1
    open(FILE, ">$newfile");
    binmode(FILE);
    printf FILE $buffer;
    close(FILE);
    }

    #gets hash
    sub getHash
    {
    $hash = qx($gethashdir/gethash $file | tail -1);
    chomp $hash;
    $hash =~ s/\s//g;
    #printf "$hash\n";#debug
    }

    #read iTunesDB contents
    $fh = open(FILE, $file);
    if($fh)
    {
    binmode(FILE);
    read(FILE, $buffer, $filesize, 0);
    close(FILE);

    &getHash(); #gets new hash to be inserted in iTunesDB
    #&gridDsp(); #verification/debug
    &replaceHash(); #replaces hash with new hash
    #&gridDsp(); #verification/debug
    &writeFile(); #writes iTunesDB on ipod
    }
    else
    {
    printf "Could not open file <$file>.\n";
    }

    # Unmount for iPod touch ** Delete this line if you don't use fusermount
    system("fusermount -u $ipoddir");

     
  • At 3:15 PM , Blogger NiceGuyUK said...

    Thanks for your contribution there Jamil! :-)

     
  • At 3:31 PM , Blogger Jamil said...

    No prob, glad to be usefully contributing! (got to admit, doing this by hand would have been a pain in the butt when trying to sync...)

    I forgot to mention,
    in step 2, mounting the device is not necessary (I couldn't manage to get the iPod Touch mounted through USB...)
    lsusb will work without mounting and give you the iSerial #.

    Also, in the case of the iPod Touch (and probably the iPhone too), the string is longer than 16 characters, but only the first 16 are necessary for gethash to work; teh rest can be safely ignored.

    I think that covers it :D

     
  • At 10:26 PM , Blogger Alexxagainstcity said...

    Not sure if this blog is still alive, but can you help me?

    I can't see my iPod touch via lsusb at all, so the command after "Download the code" doesn't work.

    Help?

     
  • At 2:43 PM , Blogger NiceGuyUK said...

    Alex,

    Sorry for the delay in responding, didn't spot your comment at first!

    Unfortunately the notes I originally posted were from somewhere else - I've yet to get an iPod Touch (waiting for them to make the capacity match my old 3rd Gen 30gb iPod).

    You could try opening a console and running tail -f /var/log/messages then connecting your iPod and see if there is any signs of it recognising a device is attached at all. It might even give some error messages you could use to investigate further.

     
  • At 7:32 PM , Blogger James Hardt said...

    The two hashes I get from gethash are identical, and are actually the same hash already in iTunesDB at 0x58. Any idea why?

    I have one album uploaded with itunes and one album uploaded with gtkpod version 0.99.12. The itunes album is visible, while the gtkpod uploaded album is not visible.

    Thanks in advance if you end up seeing this and getting back to me.

     

Post a Comment

Links to this post:

Create a Link

<< Home