summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/descramble.c69
-rw-r--r--tools/scramble.c65
2 files changed, 134 insertions, 0 deletions
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 @@
23 23
24#include "iriver.h" 24#include "iriver.h"
25 25
26int iaudio_decode(char *iname, char *oname);
27
26void usage(void) 28void usage(void)
27{ 29{
28 printf("usage: descramble [options] <input file> <output file>\n"); 30 printf("usage: descramble [options] <input file> <output file>\n");
@@ -31,6 +33,7 @@ void usage(void)
31 "\t-v2 Archos V2 recorder format\n" 33 "\t-v2 Archos V2 recorder format\n"
32 "\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n" 34 "\t-mm=X Archos Multimedia format (X values: A=JBMM, B=AV1xx, C=AV3xx)\n"
33 "\t-iriver iRiver format\n" 35 "\t-iriver iRiver format\n"
36 "\t-iaudio iAudio format\n"
34 "\nNo option assumes Archos standard player/recorder format.\n"); 37 "\nNo option assumes Archos standard player/recorder format.\n");
35 exit(1); 38 exit(1);
36} 39}
@@ -71,6 +74,12 @@ int main (int argc, char** argv)
71 return 0; 74 return 0;
72 } 75 }
73 76
77 if(!strcmp(argv[1], "-iaudio")) {
78 iname = argv[2];
79 oname = argv[3];
80 return iaudio_decode(iname, oname);
81 }
82
74 /* open file and check size */ 83 /* open file and check size */
75 file = fopen(iname,"rb"); 84 file = fopen(iname,"rb");
76 if (!file) { 85 if (!file) {
@@ -199,3 +208,63 @@ int main (int argc, char** argv)
199 208
200 return 0; 209 return 0;
201} 210}
211
212int iaudio_decode(char *iname, char *oname)
213{
214 size_t len;
215 int length;
216 FILE *file;
217 char *outbuf;
218 int i;
219 unsigned char sum = 0;
220 unsigned char filesum;
221
222 file = fopen(iname, "rb");
223 if (!file) {
224 perror(iname);
225 return -1;
226 }
227 fseek(file,0,SEEK_END);
228 length = ftell(file);
229
230 fseek(file,0,SEEK_SET);
231 outbuf = malloc(length);
232
233 if ( !outbuf ) {
234 printf("out of memory!\n");
235 return -1;
236 }
237
238 len = fread(outbuf, 1, length, file);
239 if(len < length) {
240 perror(iname);
241 return -2;
242 }
243
244 fclose(file);
245
246 for(i = 0; i < length-0x1030;i++)
247 sum += outbuf[0x1030 + i];
248
249 filesum = outbuf[0x102b];
250
251 if(filesum != sum) {
252 printf("Checksum mismatch!\n");
253 return -1;
254 }
255
256 file = fopen(oname, "wb");
257 if (!file) {
258 perror(oname);
259 return -3;
260 }
261
262 len = fwrite(outbuf+0x1030, 1, length-0x1030, file);
263 if(len < length-0x1030) {
264 perror(oname);
265 return -4;
266 }
267
268 fclose(file);
269 return 0;
270}
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
25int iaudio_encode(char *iname, char *oname);
26
25enum 27enum
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
365int 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}