Skip to content

Instantly share code, notes, and snippets.

@atr000
Created August 20, 2010 14:59
Show Gist options
  • Select an option

  • Save atr000/540492 to your computer and use it in GitHub Desktop.

Select an option

Save atr000/540492 to your computer and use it in GitHub Desktop.
/*
Opposite of the easy way:
http://aladino.dmi.unict.it/?a=unlocker
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment