diff options
-rw-r--r-- | tools/creative.c | 46 | ||||
-rw-r--r-- | tools/creative.h | 15 | ||||
-rw-r--r-- | tools/iriver.c | 2 | ||||
-rw-r--r-- | tools/scramble.c | 22 |
4 files changed, 49 insertions, 36 deletions
diff --git a/tools/creative.c b/tools/creative.c index bcabc4fc2a..6e0e468411 100644 --- a/tools/creative.c +++ b/tools/creative.c | |||
@@ -17,40 +17,65 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "creative.h" | ||
21 | #include "hmac-sha1.h" | ||
22 | #include <stdio.h> | 20 | #include <stdio.h> |
23 | #include <stdbool.h> | 21 | #include <stdbool.h> |
24 | #include <stdlib.h> | 22 | #include <stdlib.h> |
25 | #include <string.h> | 23 | #include <string.h> |
26 | 24 | ||
25 | #include "creative.h" | ||
26 | #include "hmac-sha1.h" | ||
27 | |||
28 | static const char null_key_v1[] = "CTL:N0MAD|PDE0.SIGN."; | ||
29 | static const char null_key_v2[] = "CTL:N0MAD|PDE0.DPMP."; | ||
30 | static const char null_key_v3[] = "CTL:Z3N07|PDE0.DPMP."; | ||
31 | static const char null_key_v4[] = "CTL:N0MAD|PDE0.DPFP."; | ||
32 | |||
33 | static const struct device_info devices[] = | ||
34 | { | ||
35 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0:\0M", | ||
36 | 42, null_key_v2}, | ||
37 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0:\0M\0 \0G\0o\0!", | ||
38 | 50, null_key_v2}, | ||
39 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0 \0©\0T\0L", | ||
40 | 48, null_key_v2}, | ||
41 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0E\0N\0 \0V", 42, null_key_v4} | ||
42 | }; | ||
43 | |||
44 | |||
27 | /* | 45 | /* |
28 | Create a Zen Vision:M FRESCUE structure file | 46 | Create a Zen Vision:M FRESCUE structure file |
29 | */ | 47 | */ |
48 | extern void int2le(unsigned int val, unsigned char* addr); | ||
49 | extern unsigned int le2int(unsigned char* buf); | ||
30 | 50 | ||
31 | 51 | ||
32 | static int make_ciff_file(char *inbuf, int length, char *outbuf, int device) | 52 | static int make_ciff_file(unsigned char *inbuf, int length, |
53 | unsigned char *outbuf, int device) | ||
33 | { | 54 | { |
55 | char key[20]; | ||
34 | memcpy(outbuf, "FFIC", 4); | 56 | memcpy(outbuf, "FFIC", 4); |
35 | int2le(length+90, &outbuf[4]); | 57 | int2le(length+90, &outbuf[4]); |
36 | memcpy(&outbuf[8], "FNIC", 4); | 58 | memcpy(&outbuf[8], "FNIC", 4); |
37 | int2le(96, &outbuf[0xC]); | 59 | int2le(96, &outbuf[0xC]); |
38 | memcpy(&outbuf[0x10], devices[device].cinf, devices[device].cinf_size); | 60 | memcpy(&outbuf[0x10], devices[device].cinf, devices[device].cinf_size); |
39 | memset(&outbuf[0x10+devices[device].cinf_size], 0, 96 - devices[device].cinf_size); | 61 | memset(&outbuf[0x10+devices[device].cinf_size], 0, |
62 | 96 - devices[device].cinf_size); | ||
40 | memcpy(&outbuf[0x70], "ATAD", 4); | 63 | memcpy(&outbuf[0x70], "ATAD", 4); |
41 | int2le(length+32, &outbuf[0x74]); | 64 | int2le(length+32, &outbuf[0x74]); |
42 | memcpy(&outbuf[0x78], "H\0j\0u\0k\0e\0b\0o\0x\0\x32\0.\0j\0r\0m", 32); /*Unicode encoded*/ | 65 | memcpy(&outbuf[0x78], "H\0j\0u\0k\0e\0b\0o\0x\0\x32\0.\0j\0r\0m", |
66 | 32); /*Unicode encoded*/ | ||
43 | memcpy(&outbuf[0x98], inbuf, length); | 67 | memcpy(&outbuf[0x98], inbuf, length); |
44 | memcpy(&outbuf[0x98+length], "LLUN", 4); | 68 | memcpy(&outbuf[0x98+length], "LLUN", 4); |
45 | int2le(20, &outbuf[0x98+length+4]); | 69 | int2le(20, &outbuf[0x98+length+4]); |
46 | /* Do checksum */ | 70 | /* Do checksum */ |
47 | char key[20]; | 71 | hmac_sha((char *)devices[device].null, strlen(devices[device].null), |
48 | hmac_sha((char*)devices[device].null, strlen(devices[device].null), outbuf, 0x98+length, key, 20); | 72 | (char *)outbuf, 0x98+length, key, 20); |
49 | memcpy(&outbuf[0x98+length+8], key, 20); | 73 | memcpy(&outbuf[0x98+length+8], key, 20); |
50 | return length+0x90+0x1C+8; | 74 | return length+0x90+0x1C+8; |
51 | } | 75 | } |
52 | 76 | ||
53 | static int make_jrm_file(char *inbuf, int length, char *outbuf) | 77 | static int make_jrm_file(unsigned char *inbuf, int length, |
78 | unsigned char *outbuf) | ||
54 | { | 79 | { |
55 | int i; | 80 | int i; |
56 | unsigned int sum = 0; | 81 | unsigned int sum = 0; |
@@ -101,7 +126,6 @@ int zvm_encode(char *iname, char *oname, int device) | |||
101 | FILE *file; | 126 | FILE *file; |
102 | unsigned char *outbuf; | 127 | unsigned char *outbuf; |
103 | unsigned char *buf; | 128 | unsigned char *buf; |
104 | int i; | ||
105 | 129 | ||
106 | file = fopen(iname, "rb"); | 130 | file = fopen(iname, "rb"); |
107 | if (!file) { | 131 | if (!file) { |
@@ -120,7 +144,7 @@ int zvm_encode(char *iname, char *oname, int device) | |||
120 | } | 144 | } |
121 | 145 | ||
122 | len = fread(buf, 1, length, file); | 146 | len = fread(buf, 1, length, file); |
123 | if(len < length) { | 147 | if(len < (size_t)length) { |
124 | perror(iname); | 148 | perror(iname); |
125 | return -2; | 149 | return -2; |
126 | } | 150 | } |
@@ -147,7 +171,7 @@ int zvm_encode(char *iname, char *oname, int device) | |||
147 | } | 171 | } |
148 | 172 | ||
149 | len = fwrite(buf, 1, length, file); | 173 | len = fwrite(buf, 1, length, file); |
150 | if(len < length) { | 174 | if(len < (size_t)length) { |
151 | free(buf); | 175 | free(buf); |
152 | perror(oname); | 176 | perror(oname); |
153 | return -4; | 177 | return -4; |
diff --git a/tools/creative.h b/tools/creative.h index c28001a0e7..ff8b4a019d 100644 --- a/tools/creative.h +++ b/tools/creative.h | |||
@@ -28,26 +28,13 @@ enum | |||
28 | ZENV = 3 | 28 | ZENV = 3 |
29 | }; | 29 | }; |
30 | 30 | ||
31 | static struct device_info | 31 | struct device_info |
32 | { | 32 | { |
33 | const char* cinf; /*Must be Unicode encoded*/ | 33 | const char* cinf; /*Must be Unicode encoded*/ |
34 | const int cinf_size; | 34 | const int cinf_size; |
35 | const char* null; | 35 | const char* null; |
36 | } device_info; | 36 | } device_info; |
37 | 37 | ||
38 | static const char null_key_v1[] = "CTL:N0MAD|PDE0.SIGN."; | ||
39 | static const char null_key_v2[] = "CTL:N0MAD|PDE0.DPMP."; | ||
40 | static const char null_key_v3[] = "CTL:Z3N07|PDE0.DPMP."; | ||
41 | static const char null_key_v4[] = "CTL:N0MAD|PDE0.DPFP."; | ||
42 | |||
43 | static const struct device_info devices[] = | ||
44 | { | ||
45 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0:\0M", 42, null_key_v2}, | ||
46 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0:\0M\0 \0G\0o\0!", 50, null_key_v2}, | ||
47 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0e\0n\0 \0V\0i\0s\0i\0o\0n\0 \0©\0T\0L", 48, null_key_v2}, | ||
48 | {"C\0r\0e\0a\0t\0i\0v\0e\0 \0Z\0E\0N\0 \0V", 42, null_key_v4} | ||
49 | }; | ||
50 | |||
51 | int zvm_encode(char *iname, char *oname, int device); | 38 | int zvm_encode(char *iname, char *oname, int device); |
52 | 39 | ||
53 | #endif /*CREATIVE_H_*/ | 40 | #endif /*CREATIVE_H_*/ |
diff --git a/tools/iriver.c b/tools/iriver.c index 4d26b981aa..240f9e36a2 100644 --- a/tools/iriver.c +++ b/tools/iriver.c | |||
@@ -273,8 +273,6 @@ int iriver_encode(char *infile_name, char *outfile_name, BOOL modify ) | |||
273 | unsigned char * pChecksums, * ppChecksums; | 273 | unsigned char * pChecksums, * ppChecksums; |
274 | unsigned char ck; | 274 | unsigned char ck; |
275 | 275 | ||
276 | enum striptype stripmode = STRIP_NONE; | ||
277 | |||
278 | infile = openinfile(infile_name); | 276 | infile = openinfile(infile_name); |
279 | outfile = openoutfile(outfile_name); | 277 | outfile = openoutfile(outfile_name); |
280 | 278 | ||
diff --git a/tools/scramble.c b/tools/scramble.c index 91f46be816..7efade3419 100644 --- a/tools/scramble.c +++ b/tools/scramble.c | |||
@@ -41,7 +41,7 @@ enum | |||
41 | ARCHOS_ONDIO_FM | 41 | ARCHOS_ONDIO_FM |
42 | }; | 42 | }; |
43 | 43 | ||
44 | int size_limit[] = | 44 | static unsigned int size_limit[] = |
45 | { | 45 | { |
46 | 0x32000, /* ARCHOS_PLAYER */ | 46 | 0x32000, /* ARCHOS_PLAYER */ |
47 | 0x64000, /* ARCHOS_V2RECORDER */ | 47 | 0x64000, /* ARCHOS_V2RECORDER */ |
@@ -132,10 +132,10 @@ int main (int argc, char** argv) | |||
132 | unsigned char header[24]; | 132 | unsigned char header[24]; |
133 | char *iname = argv[1]; | 133 | char *iname = argv[1]; |
134 | char *oname = argv[2]; | 134 | char *oname = argv[2]; |
135 | char *xorstring; | 135 | char *xorstring=NULL; |
136 | int headerlen = 6; | 136 | int headerlen = 6; |
137 | FILE* file; | 137 | FILE* file; |
138 | int version; | 138 | int version=0; |
139 | unsigned long modelnum; | 139 | unsigned long modelnum; |
140 | char modelname[5]; | 140 | char modelname[5]; |
141 | int model_id; | 141 | int model_id; |
@@ -351,7 +351,6 @@ int main (int argc, char** argv) | |||
351 | } | 351 | } |
352 | else if(!strncmp(argv[1], "-mi4", 4)) { | 352 | else if(!strncmp(argv[1], "-mi4", 4)) { |
353 | int mi4magic; | 353 | int mi4magic; |
354 | int version; | ||
355 | char model[4] = ""; | 354 | char model[4] = ""; |
356 | char type[4] = ""; | 355 | char type[4] = ""; |
357 | 356 | ||
@@ -402,7 +401,7 @@ int main (int argc, char** argv) | |||
402 | 401 | ||
403 | if ((method == scramble) && | 402 | if ((method == scramble) && |
404 | ((length + headerlen) >= size_limit[model_id])) { | 403 | ((length + headerlen) >= size_limit[model_id])) { |
405 | printf("error: firmware image is %d bytes while max size is %d!\n", | 404 | printf("error: firmware image is %ld bytes while max size is %u!\n", |
406 | length + headerlen, | 405 | length + headerlen, |
407 | size_limit[model_id]); | 406 | size_limit[model_id]); |
408 | fclose(file); | 407 | fclose(file); |
@@ -462,6 +461,10 @@ int main (int argc, char** argv) | |||
462 | outbuf[slen++] = inbuf[i]; | 461 | outbuf[slen++] = inbuf[i]; |
463 | } | 462 | } |
464 | break; | 463 | break; |
464 | case none: | ||
465 | default: | ||
466 | /* dummy case just to silence picky compilers */ | ||
467 | break; | ||
465 | } | 468 | } |
466 | 469 | ||
467 | if((method == none) || (method == scramble) || (method == xor)) { | 470 | if((method == none) || (method == scramble) || (method == xor)) { |
@@ -598,7 +601,7 @@ int iaudio_encode(char *iname, char *oname, char *idstring) | |||
598 | } | 601 | } |
599 | 602 | ||
600 | len = fread(outbuf+0x1030, 1, length, file); | 603 | len = fread(outbuf+0x1030, 1, length, file); |
601 | if(len < length) { | 604 | if(len < (size_t) length) { |
602 | perror(iname); | 605 | perror(iname); |
603 | return -2; | 606 | return -2; |
604 | } | 607 | } |
@@ -626,12 +629,13 @@ int iaudio_encode(char *iname, char *oname, char *idstring) | |||
626 | } | 629 | } |
627 | 630 | ||
628 | len = fwrite(outbuf, 1, length+0x1030, file); | 631 | len = fwrite(outbuf, 1, length+0x1030, file); |
629 | if(len < length) { | 632 | if(len < (size_t)length) { |
630 | perror(oname); | 633 | perror(oname); |
631 | return -4; | 634 | return -4; |
632 | } | 635 | } |
633 | 636 | ||
634 | fclose(file); | 637 | fclose(file); |
638 | return 0; | ||
635 | } | 639 | } |
636 | 640 | ||
637 | 641 | ||
@@ -697,7 +701,7 @@ int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc) | |||
697 | } | 701 | } |
698 | 702 | ||
699 | len = fread(outbuf+0x4600, 1, length, file); | 703 | len = fread(outbuf+0x4600, 1, length, file); |
700 | if(len < length) { | 704 | if(len < (size_t)length) { |
701 | perror(iname); | 705 | perror(iname); |
702 | return -2; | 706 | return -2; |
703 | } | 707 | } |
@@ -754,7 +758,7 @@ int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc) | |||
754 | } | 758 | } |
755 | 759 | ||
756 | len = fwrite(outbuf, 1, length+0x4600, file); | 760 | len = fwrite(outbuf, 1, length+0x4600, file); |
757 | if(len < length) { | 761 | if(len < (size_t)length) { |
758 | perror(oname); | 762 | perror(oname); |
759 | return -4; | 763 | return -4; |
760 | } | 764 | } |