Recently, i bought a brand new iPhone 3G. After the first funny week, i decided to sync the new toy
with my office mac. However, i've already previously synced it with my home iMac for mp3 files. This
gave me the infamous syncing error:

"The information on the iPhone is synced with another user account. Do you want to sync this iPhone
with the information from this user account instead? Merge Info merges the information on this
iPhone with the information from this user account. Replace Info replaces the information on this
iPhone with the information from this user account."


Googling around i realized that every shipped iTunes has a personal identification number (ID).
It's an alpha numeric 16byte string, as follow:

AA:BB:CC:DD:EE:FF:00:11 (without ':')

This number is transferred into your iPhone first time you make a connection with iTunes. Every
time you'll try to make a sync iTunes will compare it's personal ID with the one stored into iPhone.
If they match, the sync is done properly. Otherwise, you'll obtain the message above.

You can follow two methods, in order to bypass the problem:

METHOD#1
patch the iPhone stored ID to match the one provided with iTunes. To accomplish this, you've to
locate the file $FILE, stored in $PATH.

However, you still need to know the personalID stored into your firstly synced iTunes. To obtain
this info you've to read the method #2.

METHOD#2
the attached ansiC code is a proof of concept in order to get ( option 'g' ) and set ( option 's' )
the personalID into your iTunes. The way in which it works is straightforward:

first time you've to run it with the get option into your iTunes first-sync machine. The code will
return some output lines as follow:

$ ./unlockiTunes2 g Music/iTunes/iTunes\ Music\ Library.xml
searching your personal magic key...OK!

your ID is: 4RF458VHSH3HAHA3

copy it in a secure place!
$



yeah! you've obtained your personalID. Now, all you've to do is to use it in all your installed
iTunes. To achieve this goal, you've to use the second option, as follow:

$./unlockiTunes s Music/iTunes/iTunes\ Music\ Library.xml Music/iTunes/iTunes\ Library

your iTunes was unlocked! Enjoy!
$



This time you've to specify two distincts file to complete the process successfully. The reason is
that the ID is stored distinctly in the above files. Respectively, the first one has the plain form
stored as XML string key. The second one, has it in hexadecimal form. The reason why the information
is stored twice is not clear for me. However, i suspect that the most important one is the hex form.
Tracing an iTunes instance, in fact, i noticed that the .xml file is properly generated if it does
not exist. The relevant informations (ID and other personal infos) are extracted and parsed in order
to obtain a valid XML file.

I've planned to make a fully enabled COCOA version of the code presented here, in order to obtain
a CLICK&GO bundle from Finder. However, the time is money...and i have no money...:-)


/*
iTunes Unlocker - Copyright (C) 2009 Costantino Pistagna - valvoline@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

This program comes with ABSOLUTELY NO WARRANTY; This is free software,
and you are welcome to redistribute it under certain conditions.

--
happy 'tuning!
valv0
*/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv) {
FILE *fp;
int i;
char buffer[1024];
char *buf;
char *ptr;
char *ptr2;
char ID[128];
long pos;


if((argc == 3 && strcmp(argv[1], "g") != 0) || (argc == 4 && strcmp(argv[1], "s") != 0) || argc < 3) {
printf("\niTunes Library Unlocker v0.1 - (c) 2009 valv0 - valvoline@gmail.com\n-------------------------------------------------------------------\nusage:\n\tto obtain your current iTunes ID, type:\n\tunlockiTunes g <iTunes Music Library.xml>\n\n\tto unlock your iTunes library with a provided ID, type:\n\tunlockiTunes s ID <iTunes Music Library.xml> <iTunes Library>\n\n");
exit(1);
}
if(argc == 3) {
if ( (fp=fopen(argv[2], "r+")) == NULL ) {
printf("something goes wrong with your XML Library file!...aborting!\n\n");
exit(1);
}
printf("searching your personal magic key...");
while(!feof(fp)) {
pos=ftell(fp);
fgets(buffer, 1024, fp);
if( (ptr=strstr(buffer, "<key>Library Persistent ID</key><string>")) != NULL) {
bzero(ID, 128);
memcpy(ID, ptr+40, 16);
printf("OK!\n\nyour ID is: %s\n\ncopy it in a secure place!\n", ID);
break;
}

}
fclose(fp);
}
if(argc == 5) {
if ( (fp=fopen(argv[3], "r+")) == NULL ) {
printf("something goes wrong with your XML Library file!...aborting!\n\n");
exit(1);
}
fseek(fp, 0, SEEK_END);
pos = ftell(fp);
fseek(fp, 0, SEEK_SET);
buf = calloc(1, sizeof(char)*pos);
fread(buf, sizeof(unsigned char), pos, fp);
fclose(fp);
ptr = strstr(buf, "<key>Library Persistent ID</key><string>");
if(ptr == NULL) {
printf("something goes wrong with substituting...aborting!\n");
exit(1);
}
strncpy(ptr+40, argv[2], 16);
if ( (fp=fopen(argv[3], "w")) == NULL ) {
printf("something goes wrong with your XML Library file!...aborting!\n\n");
exit(1);
}
fwrite(buf, sizeof(unsigned char), pos, fp);
fclose(fp);
free(buf);
if ( (fp=fopen(argv[4], "r+")) == NULL ) {
printf("something goes wrong with your Library file!...aborting!\n\n");
exit(1);
}
fseek(fp, 0, SEEK_END);
pos = ftell(fp);
fseek(fp, 0, SEEK_SET);
buf = calloc(1, sizeof(char)*pos);
fread(buf, sizeof(unsigned char), pos, fp);
fclose(fp);
ptr2 = calloc(1, 2*sizeof(char));
for(i=0;i<8;i++) {
bzero(ptr2, 2);
strncpy(ptr2, argv[2]+(i*2), 2);
buf[52+i] = strtoul(ptr2, NULL, 16);
}
if ( (fp=fopen(argv[4], "w")) == NULL ) {
printf("something goes wrong with your Library file!...aborting!\n\n");
exit(1);
}
fwrite(buf, sizeof(unsigned char), pos, fp);
fclose(fp);
free(buf);
printf("your iTunes was unlocked! Enjoy!\n");
}
return 0;
}



    genius