From 074999ded3b7f41ef25167b06b0c618306ed9d5e Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Tue, 27 Dec 2005 23:14:49 +0000 Subject: Added basic iAudio X5 support for the scramble and descramble tools git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8290 a1c6a512-1295-4272-9138-f99709370657 --- tools/descramble.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/scramble.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) diff --git a/tools/descramble.c b/tools/descramble.c index 925d7c279f..9b76eaa0d9 100644 --- a/tools/descramble.c +++ b/tools/descramble.c @@ -23,6 +23,8 @@ #include "iriver.h" +int iaudio_decode(char *iname, char *oname); + void usage(void) { printf("usage: descramble [options] \n"); @@ -31,6 +33,7 @@ void usage(void) "\t-v2 Archos V2 recorder format\n" "\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n" "\t-iriver iRiver format\n" + "\t-iaudio iAudio format\n" "\nNo option assumes Archos standard player/recorder format.\n"); exit(1); } @@ -71,6 +74,12 @@ int main (int argc, char** argv) return 0; } + if(!strcmp(argv[1], "-iaudio")) { + iname = argv[2]; + oname = argv[3]; + return iaudio_decode(iname, oname); + } + /* open file and check size */ file = fopen(iname,"rb"); if (!file) { @@ -199,3 +208,63 @@ int main (int argc, char** argv) return 0; } + +int iaudio_decode(char *iname, char *oname) +{ + size_t len; + int length; + FILE *file; + char *outbuf; + int i; + unsigned char sum = 0; + unsigned char filesum; + + file = fopen(iname, "rb"); + if (!file) { + perror(iname); + return -1; + } + fseek(file,0,SEEK_END); + length = ftell(file); + + fseek(file,0,SEEK_SET); + outbuf = malloc(length); + + if ( !outbuf ) { + printf("out of memory!\n"); + return -1; + } + + len = fread(outbuf, 1, length, file); + if(len < length) { + perror(iname); + return -2; + } + + fclose(file); + + for(i = 0; i < length-0x1030;i++) + sum += outbuf[0x1030 + i]; + + filesum = outbuf[0x102b]; + + if(filesum != sum) { + printf("Checksum mismatch!\n"); + return -1; + } + + file = fopen(oname, "wb"); + if (!file) { + perror(oname); + return -3; + } + + len = fwrite(outbuf+0x1030, 1, length-0x1030, file); + if(len < length-0x1030) { + perror(oname); + return -4; + } + + fclose(file); + return 0; +} diff --git a/tools/scramble.c b/tools/scramble.c index 73e4925e48..d19ef89173 100644 --- a/tools/scramble.c +++ b/tools/scramble.c @@ -22,6 +22,8 @@ #include #include "iriver.h" +int iaudio_encode(char *iname, char *oname); + enum { ARCHOS_PLAYER, /* and V1 recorder */ @@ -67,6 +69,7 @@ void usage(void) "\t-neo SSI Neo format\n" "\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n" "\t-iriver iRiver format\n" + "\t-iaudio iAudio format\n" "\t-add=X Rockbox generic \"add-up\" checksum format\n" "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd)\n" "\nNo option results in Archos standard player/recorder format.\n"); @@ -184,6 +187,11 @@ int main (int argc, char** argv) iriver_encode(iname, oname, FALSE); return 0; } + else if(!strcmp(argv[1], "-iaudio")) { + iname = argv[2]; + oname = argv[3]; + return iaudio_encode(iname, oname); + } /* open file */ file = fopen(iname,"rb"); @@ -353,3 +361,60 @@ int main (int argc, char** argv) return 0; } + +int iaudio_encode(char *iname, char *oname) +{ + size_t len; + int length; + FILE *file; + unsigned char *outbuf; + int i; + unsigned char sum = 0; + + file = fopen(iname, "rb"); + if (!file) { + perror(iname); + return -1; + } + fseek(file,0,SEEK_END); + length = ftell(file); + + fseek(file,0,SEEK_SET); + outbuf = malloc(length+0x1030); + + if ( !outbuf ) { + printf("out of memory!\n"); + return -1; + } + + len = fread(outbuf+0x1030, 1, length, file); + if(len < length) { + perror(iname); + return -2; + } + + memset(outbuf, 0, 0x1030); + strcpy((char *)outbuf, "COWON_X5_FW"); + + for(i = 0; i < length;i++) + sum += outbuf[0x1030 + i]; + + int2be(length, &outbuf[0x1024]); + outbuf[0x102b] = sum; + + fclose(file); + + file = fopen(oname, "wb"); + if (!file) { + perror(oname); + return -3; + } + + len = fwrite(outbuf, 1, length+0x1030, file); + if(len < length) { + perror(oname); + return -4; + } + + fclose(file); +} -- cgit v1.2.3