diff options
Diffstat (limited to 'tools/scramble.c')
-rw-r--r-- | tools/scramble.c | 65 |
1 files changed, 65 insertions, 0 deletions
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 @@ | |||
22 | #include <string.h> | 22 | #include <string.h> |
23 | #include "iriver.h" | 23 | #include "iriver.h" |
24 | 24 | ||
25 | int iaudio_encode(char *iname, char *oname); | ||
26 | |||
25 | enum | 27 | enum |
26 | { | 28 | { |
27 | ARCHOS_PLAYER, /* and V1 recorder */ | 29 | ARCHOS_PLAYER, /* and V1 recorder */ |
@@ -67,6 +69,7 @@ void usage(void) | |||
67 | "\t-neo SSI Neo format\n" | 69 | "\t-neo SSI Neo format\n" |
68 | "\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n" | 70 | "\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n" |
69 | "\t-iriver iRiver format\n" | 71 | "\t-iriver iRiver format\n" |
72 | "\t-iaudio iAudio format\n" | ||
70 | "\t-add=X Rockbox generic \"add-up\" checksum format\n" | 73 | "\t-add=X Rockbox generic \"add-up\" checksum format\n" |
71 | "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd)\n" | 74 | "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd)\n" |
72 | "\nNo option results in Archos standard player/recorder format.\n"); | 75 | "\nNo option results in Archos standard player/recorder format.\n"); |
@@ -184,6 +187,11 @@ int main (int argc, char** argv) | |||
184 | iriver_encode(iname, oname, FALSE); | 187 | iriver_encode(iname, oname, FALSE); |
185 | return 0; | 188 | return 0; |
186 | } | 189 | } |
190 | else if(!strcmp(argv[1], "-iaudio")) { | ||
191 | iname = argv[2]; | ||
192 | oname = argv[3]; | ||
193 | return iaudio_encode(iname, oname); | ||
194 | } | ||
187 | 195 | ||
188 | /* open file */ | 196 | /* open file */ |
189 | file = fopen(iname,"rb"); | 197 | file = fopen(iname,"rb"); |
@@ -353,3 +361,60 @@ int main (int argc, char** argv) | |||
353 | 361 | ||
354 | return 0; | 362 | return 0; |
355 | } | 363 | } |
364 | |||
365 | int iaudio_encode(char *iname, char *oname) | ||
366 | { | ||
367 | size_t len; | ||
368 | int length; | ||
369 | FILE *file; | ||
370 | unsigned char *outbuf; | ||
371 | int i; | ||
372 | unsigned char sum = 0; | ||
373 | |||
374 | file = fopen(iname, "rb"); | ||
375 | if (!file) { | ||
376 | perror(iname); | ||
377 | return -1; | ||
378 | } | ||
379 | fseek(file,0,SEEK_END); | ||
380 | length = ftell(file); | ||
381 | |||
382 | fseek(file,0,SEEK_SET); | ||
383 | outbuf = malloc(length+0x1030); | ||
384 | |||
385 | if ( !outbuf ) { | ||
386 | printf("out of memory!\n"); | ||
387 | return -1; | ||
388 | } | ||
389 | |||
390 | len = fread(outbuf+0x1030, 1, length, file); | ||
391 | if(len < length) { | ||
392 | perror(iname); | ||
393 | return -2; | ||
394 | } | ||
395 | |||
396 | memset(outbuf, 0, 0x1030); | ||
397 | strcpy((char *)outbuf, "COWON_X5_FW"); | ||
398 | |||
399 | for(i = 0; i < length;i++) | ||
400 | sum += outbuf[0x1030 + i]; | ||
401 | |||
402 | int2be(length, &outbuf[0x1024]); | ||
403 | outbuf[0x102b] = sum; | ||
404 | |||
405 | fclose(file); | ||
406 | |||
407 | file = fopen(oname, "wb"); | ||
408 | if (!file) { | ||
409 | perror(oname); | ||
410 | return -3; | ||
411 | } | ||
412 | |||
413 | len = fwrite(outbuf, 1, length+0x1030, file); | ||
414 | if(len < length) { | ||
415 | perror(oname); | ||
416 | return -4; | ||
417 | } | ||
418 | |||
419 | fclose(file); | ||
420 | } | ||