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
This commit is contained in:
Linus Nielsen Feltzing 2005-12-27 23:14:49 +00:00
parent 64fe299d70
commit 074999ded3
2 changed files with 134 additions and 0 deletions

View File

@ -23,6 +23,8 @@
#include "iriver.h"
int iaudio_decode(char *iname, char *oname);
void usage(void)
{
printf("usage: descramble [options] <input file> <output file>\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;
}

View File

@ -22,6 +22,8 @@
#include <string.h>
#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);
}