summaryrefslogtreecommitdiff
path: root/tools/creative.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/creative.c')
-rw-r--r--tools/creative.c46
1 files changed, 35 insertions, 11 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
28static const char null_key_v1[] = "CTL:N0MAD|PDE0.SIGN.";
29static const char null_key_v2[] = "CTL:N0MAD|PDE0.DPMP.";
30static const char null_key_v3[] = "CTL:Z3N07|PDE0.DPMP.";
31static const char null_key_v4[] = "CTL:N0MAD|PDE0.DPFP.";
32
33static 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/*
28Create a Zen Vision:M FRESCUE structure file 46Create a Zen Vision:M FRESCUE structure file
29*/ 47*/
48extern void int2le(unsigned int val, unsigned char* addr);
49extern unsigned int le2int(unsigned char* buf);
30 50
31 51
32static int make_ciff_file(char *inbuf, int length, char *outbuf, int device) 52static 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
53static int make_jrm_file(char *inbuf, int length, char *outbuf) 77static 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;