diff options
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/jz4740_tools/HXFmerge.c | 291 | ||||
-rwxr-xr-x | utils/jz4740_tools/HXFreplace.c | 225 | ||||
-rwxr-xr-x | utils/jz4740_tools/HXFsplit.c | 304 | ||||
-rwxr-xr-x | utils/jz4740_tools/Makefile (renamed from utils/jz4740_usbtool/Makefile) | 0 | ||||
-rwxr-xr-x | utils/jz4740_tools/jz4740.h (renamed from utils/jz4740_usbtool/jz4740.h) | 0 | ||||
-rwxr-xr-x | utils/jz4740_tools/jz4740_usbtool.c (renamed from utils/jz4740_usbtool/jz4740_usbtool.c) | 0 | ||||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/jz4740_usbtool.cat (renamed from utils/jz4740_usbtool/windows_driver/jz4740_usbtool.cat) | 0 | ||||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/jz4740_usbtool.inf (renamed from utils/jz4740_usbtool/windows_driver/jz4740_usbtool.inf) | 0 | ||||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/jz4740_usbtool_x64.cat (renamed from utils/jz4740_usbtool/windows_driver/jz4740_usbtool_x64.cat) | 0 | ||||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/libusb0.dll (renamed from utils/jz4740_usbtool/windows_driver/libusb0.dll) | bin | 43520 -> 43520 bytes | |||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/libusb0.sys (renamed from utils/jz4740_usbtool/windows_driver/libusb0.sys) | bin | 28672 -> 28672 bytes | |||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/libusb0_x64.dll (renamed from utils/jz4740_usbtool/windows_driver/libusb0_x64.dll) | bin | 43008 -> 43008 bytes | |||
-rwxr-xr-x | utils/jz4740_tools/windows_driver/libusb0_x64.sys (renamed from utils/jz4740_usbtool/windows_driver/libusb0_x64.sys) | bin | 16896 -> 16896 bytes |
13 files changed, 820 insertions, 0 deletions
diff --git a/utils/jz4740_tools/HXFmerge.c b/utils/jz4740_tools/HXFmerge.c new file mode 100755 index 0000000000..40c36e7bc7 --- /dev/null +++ b/utils/jz4740_tools/HXFmerge.c | |||
@@ -0,0 +1,291 @@ | |||
1 | /* | ||
2 | Made by Maurus Cuelenaere | ||
3 | */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <unistd.h> | ||
11 | #include <sys/stat.h> | ||
12 | #include <stdbool.h> | ||
13 | #include <dirent.h> | ||
14 | |||
15 | #define VERSION "0.2" | ||
16 | |||
17 | static unsigned char* int2le(unsigned int val) | ||
18 | { | ||
19 | static unsigned char addr[4]; | ||
20 | addr[0] = val & 0xff; | ||
21 | addr[1] = (val >> 8) & 0xff; | ||
22 | addr[2] = (val >> 16) & 0xff; | ||
23 | addr[3] = (val >> 24) & 0xff; | ||
24 | return addr; | ||
25 | } | ||
26 | |||
27 | static unsigned int le2int(unsigned char* buf) | ||
28 | { | ||
29 | unsigned int res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | ||
30 | |||
31 | return res; | ||
32 | } | ||
33 | |||
34 | #ifdef _WIN32 | ||
35 | #define PATH_SEPARATOR "\\" | ||
36 | #else | ||
37 | #define PATH_SEPARATOR "/" | ||
38 | #endif | ||
39 | |||
40 | #ifndef _WIN32 | ||
41 | |||
42 | #define MIN(a, b) (a > b ? b : a) | ||
43 | static char* replace(char* str) | ||
44 | { | ||
45 | char tmp[255]; | ||
46 | memcpy(tmp, str, MIN(strlen(str), 255); | ||
47 | char *ptr = tmp; | ||
48 | while(*ptr != 0) | ||
49 | { | ||
50 | if(*ptr == 0x2F) /* /*/ | ||
51 | *ptr = 0x5C; /* \ */ | ||
52 | ptr++; | ||
53 | } | ||
54 | return tmp; | ||
55 | } | ||
56 | #endif | ||
57 | |||
58 | static bool is_dir(const char* name1, const char* name2) | ||
59 | { | ||
60 | char *name; | ||
61 | DIR *directory; | ||
62 | name = (char*)malloc(strlen(name1)+strlen(name2)+1); | ||
63 | strcpy(name, name1); | ||
64 | strcat(name, name2); | ||
65 | directory = opendir(name); | ||
66 | free(name); | ||
67 | if(directory) | ||
68 | { | ||
69 | closedir(directory); | ||
70 | return true; | ||
71 | } | ||
72 | else | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | unsigned int _filesize(FILE* fd) | ||
77 | { | ||
78 | unsigned int tmp, oldpos; | ||
79 | oldpos = ftell(fd); | ||
80 | fseek(fd, 0, SEEK_END); | ||
81 | tmp = ftell(fd); | ||
82 | fseek(fd, oldpos, SEEK_SET); | ||
83 | return tmp; | ||
84 | } | ||
85 | #define WRITE(x, len) if(fwrite(x, len, 1, outfile) != 1) \ | ||
86 | { \ | ||
87 | closedir(indir_handle); \ | ||
88 | if(filesize > 0) \ | ||
89 | free(buffer); \ | ||
90 | fprintf(stderr, "[ERR] Error writing to file\n"); \ | ||
91 | return; \ | ||
92 | } | ||
93 | static void merge_hxf(const char* indir, FILE* outfile, const char* add) | ||
94 | { | ||
95 | DIR *indir_handle; | ||
96 | struct dirent *dirs; | ||
97 | char dir[255]; | ||
98 | strcpy(dir, indir); | ||
99 | strcat(dir, add); | ||
100 | |||
101 | if((indir_handle = opendir(dir)) == NULL) | ||
102 | { | ||
103 | fprintf(stderr, "[ERR] Error opening dir %s\n", indir); | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | while((dirs = readdir(indir_handle)) != NULL) | ||
108 | { | ||
109 | if(strcmp(dirs->d_name, "..") != 0 && | ||
110 | strcmp(dirs->d_name, ".") != 0) | ||
111 | { | ||
112 | fprintf(stderr, "[INFO] %s\%s\n", add, dirs->d_name); | ||
113 | if(is_dir(dir, dirs->d_name)) | ||
114 | { | ||
115 | char dir2[255]; | ||
116 | strcpy(dir2, add); | ||
117 | strcat(dir2, dirs->d_name); | ||
118 | strcat(dir2, PATH_SEPARATOR); | ||
119 | merge_hxf(indir, outfile, dir2); | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | FILE *filehandle; | ||
124 | unsigned char *buffer; | ||
125 | char file[255]; | ||
126 | unsigned int filesize; | ||
127 | strcpy(file, dir); | ||
128 | strcat(file, dirs->d_name); | ||
129 | if((filehandle = fopen(file, "rb")) == NULL) | ||
130 | { | ||
131 | fprintf(stderr, "[ERR] Cannot open %s\n", file); | ||
132 | closedir(indir_handle); | ||
133 | return; | ||
134 | } | ||
135 | filesize = _filesize(filehandle); | ||
136 | if(filesize > 0) | ||
137 | { | ||
138 | buffer = (unsigned char*)malloc(filesize); | ||
139 | if(buffer == NULL) | ||
140 | { | ||
141 | fclose(filehandle); | ||
142 | closedir(indir_handle); | ||
143 | fprintf(stderr, "[ERR] Cannot allocate memory\n"); | ||
144 | return; | ||
145 | } | ||
146 | if(fread(buffer, filesize, 1, filehandle) != 1) | ||
147 | { | ||
148 | fclose(filehandle); | ||
149 | closedir(indir_handle); | ||
150 | free(buffer); | ||
151 | fprintf(stderr, "[ERR] Cannot read from %s%s%s\n", add, PATH_SEPARATOR, dirs->d_name); | ||
152 | return; | ||
153 | } | ||
154 | } | ||
155 | fclose(filehandle); | ||
156 | |||
157 | if(strlen(add)>0) | ||
158 | { | ||
159 | WRITE(int2le(dirs->d_namlen+strlen(add)), 4); | ||
160 | #ifndef _WIN32 | ||
161 | WRITE(replace(add), strlen(add)-1); | ||
162 | #else | ||
163 | WRITE(add, strlen(add)-1); | ||
164 | #endif | ||
165 | WRITE(PATH_SEPARATOR, 1); | ||
166 | WRITE(dirs->d_name, dirs->d_namlen); | ||
167 | } | ||
168 | else | ||
169 | { | ||
170 | WRITE(int2le(dirs->d_namlen), 4); | ||
171 | WRITE(dirs->d_name, dirs->d_namlen); | ||
172 | } | ||
173 | WRITE(int2le(filesize), 4); | ||
174 | if(filesize>0) | ||
175 | { | ||
176 | WRITE(buffer, filesize); | ||
177 | free(buffer); | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | closedir(indir_handle); | ||
183 | } | ||
184 | |||
185 | static void print_usage(void) | ||
186 | { | ||
187 | #ifdef _WIN32 | ||
188 | fprintf(stderr, "Usage: hxfmerge.exe [INPUT_DIR] [FW]\n\n"); | ||
189 | fprintf(stderr, "Example: hxfmerge.exe VX747_extracted\\ VX747.HXF\n\n"); | ||
190 | #else | ||
191 | fprintf(stderr, "Usage: HXFmerge [INPUT_DIR] [FW]\n\n"); | ||
192 | fprintf(stderr, "Example: HXFmerge VX747_extracted/ VX747.HXF\n\n"); | ||
193 | #endif | ||
194 | } | ||
195 | |||
196 | static unsigned int checksum(FILE *file) | ||
197 | { | ||
198 | int oldpos = ftell(file); | ||
199 | unsigned int ret, i, filesize = _filesize(file)-0x40; | ||
200 | unsigned char *buf; | ||
201 | |||
202 | buf = (unsigned char*)malloc(filesize); | ||
203 | |||
204 | if(buf == NULL) | ||
205 | { | ||
206 | fseek(file, oldpos, SEEK_SET); | ||
207 | fprintf(stderr, "[ERR] Error while allocating memory\n"); | ||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | fseek(file, 0x40, SEEK_SET); | ||
212 | if(fread(buf, filesize, 1, file) != 1) | ||
213 | { | ||
214 | free(buf); | ||
215 | fseek(file, oldpos, SEEK_SET); | ||
216 | fprintf(stderr, "[ERR] Error while reading from file\n"); | ||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | fprintf(stderr, "[INFO] Computing checksum..."); | ||
221 | |||
222 | for(i = 0; i < filesize; i+=4) | ||
223 | ret += le2int(&buf[i]); | ||
224 | |||
225 | free(buf); | ||
226 | fseek(file, oldpos, SEEK_SET); | ||
227 | |||
228 | fprintf(stderr, " Done!\n"); | ||
229 | return ret; | ||
230 | } | ||
231 | |||
232 | int main(int argc, char *argv[]) | ||
233 | { | ||
234 | FILE *outfile; | ||
235 | |||
236 | fprintf(stderr, "HXFmerge v" VERSION " - (C) 2008 Maurus Cuelenaere\n"); | ||
237 | fprintf(stderr, "This is free software; see the source for copying conditions. There is NO\n"); | ||
238 | fprintf(stderr, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); | ||
239 | |||
240 | if(argc != 3) | ||
241 | { | ||
242 | print_usage(); | ||
243 | return 1; | ||
244 | } | ||
245 | |||
246 | #ifdef _WIN32 | ||
247 | if(strcmp((char*)(argv[1]+strlen(argv[1])-1), "\\") != 0) | ||
248 | { | ||
249 | fprintf(stderr, "[ERR] Input path must end with a \\\n"); | ||
250 | #else | ||
251 | if(strcmp((char*)(argv[1]+strlen(argv[1])-1), "/") != 0) | ||
252 | { | ||
253 | fprintf(stderr, "[ERR] Input path must end with a /\n"); | ||
254 | #endif | ||
255 | return 2; | ||
256 | } | ||
257 | |||
258 | if((outfile = fopen(argv[2], "wb+")) == NULL) | ||
259 | { | ||
260 | fprintf(stderr, "[ERR] Cannot open %s\n", argv[2]); | ||
261 | return 3; | ||
262 | } | ||
263 | |||
264 | fseek(outfile, 0x40, SEEK_SET); | ||
265 | |||
266 | merge_hxf(argv[1], outfile, ""); | ||
267 | |||
268 | fflush(outfile); | ||
269 | |||
270 | fprintf(stderr, "[INFO] Filling header...\n"); | ||
271 | |||
272 | #undef WRITE | ||
273 | #define WRITE(x, len) if(fwrite(x, len, 1, outfile) != 1) \ | ||
274 | { \ | ||
275 | fprintf(stderr, "[ERR] Cannot write to %s\n", argv[1]); \ | ||
276 | fclose(outfile); \ | ||
277 | return 4; \ | ||
278 | } | ||
279 | fflush(outfile); | ||
280 | fseek(outfile, 0, SEEK_SET); | ||
281 | WRITE("WADF0100200804111437", 20); | ||
282 | WRITE(int2le(_filesize(outfile)), 4); | ||
283 | WRITE(int2le(checksum(outfile)), 4); | ||
284 | WRITE(int2le(0), 4); | ||
285 | WRITE("Chinachip PMP firmware V1.0\0\0\0\0\0", 32); | ||
286 | fclose(outfile); | ||
287 | |||
288 | fprintf(stderr, "[INFO] Done!\n"); | ||
289 | |||
290 | return 0; | ||
291 | } | ||
diff --git a/utils/jz4740_tools/HXFreplace.c b/utils/jz4740_tools/HXFreplace.c new file mode 100755 index 0000000000..a33a729a1c --- /dev/null +++ b/utils/jz4740_tools/HXFreplace.c | |||
@@ -0,0 +1,225 @@ | |||
1 | /* | ||
2 | Made by Maurus Cuelenaere | ||
3 | */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <unistd.h> | ||
11 | #include <sys/stat.h> | ||
12 | #include <stdbool.h> | ||
13 | #include <dirent.h> | ||
14 | |||
15 | #define VERSION "0.1" | ||
16 | |||
17 | static unsigned char* int2le(unsigned int val) | ||
18 | { | ||
19 | static unsigned char addr[4]; | ||
20 | addr[0] = val & 0xff; | ||
21 | addr[1] = (val >> 8) & 0xff; | ||
22 | addr[2] = (val >> 16) & 0xff; | ||
23 | addr[3] = (val >> 24) & 0xff; | ||
24 | return addr; | ||
25 | } | ||
26 | |||
27 | static unsigned int le2int(unsigned char* buf) | ||
28 | { | ||
29 | unsigned int res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | ||
30 | |||
31 | return res; | ||
32 | } | ||
33 | |||
34 | unsigned int _filesize(FILE* fd) | ||
35 | { | ||
36 | unsigned int tmp, oldpos; | ||
37 | oldpos = ftell(fd); | ||
38 | fseek(fd, 0, SEEK_END); | ||
39 | tmp = ftell(fd); | ||
40 | fseek(fd, oldpos, SEEK_SET); | ||
41 | return tmp; | ||
42 | } | ||
43 | |||
44 | static void print_usage(void) | ||
45 | { | ||
46 | #ifdef _WIN32 | ||
47 | fprintf(stderr, "Usage: hxfreplace.exe [IN_FW] [OUT_FW] [BIN_FILE]\n\n"); | ||
48 | fprintf(stderr, "Example: hxfreplace.exe VX747.HXF out.hxf ccpmp.bin\n\n"); | ||
49 | #else | ||
50 | fprintf(stderr, "Usage: HXFreplace [IN_FW] [OUT_FW] [BIN_FILE]\n\n"); | ||
51 | fprintf(stderr, "Example: HXFreplace VX747.HXF out.hxf ccpmp.bin\n\n"); | ||
52 | #endif | ||
53 | } | ||
54 | |||
55 | static unsigned int checksum(FILE *file) | ||
56 | { | ||
57 | int oldpos = ftell(file); | ||
58 | unsigned int ret, i, filesize = _filesize(file)-0x40; | ||
59 | unsigned char *buf; | ||
60 | |||
61 | buf = (unsigned char*)malloc(filesize); | ||
62 | |||
63 | if(buf == NULL) | ||
64 | { | ||
65 | fseek(file, oldpos, SEEK_SET); | ||
66 | fprintf(stderr, "[ERR] Error while allocating memory\n"); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | fseek(file, 0x40, SEEK_SET); | ||
71 | if(fread(buf, filesize, 1, file) != 1) | ||
72 | { | ||
73 | free(buf); | ||
74 | fseek(file, oldpos, SEEK_SET); | ||
75 | fprintf(stderr, "[ERR] Error while reading from file\n"); | ||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | fprintf(stderr, "[INFO] Computing checksum..."); | ||
80 | |||
81 | for(i = 0; i < filesize; i+=4) | ||
82 | ret += le2int(&buf[i]); | ||
83 | |||
84 | free(buf); | ||
85 | fseek(file, oldpos, SEEK_SET); | ||
86 | |||
87 | fprintf(stderr, " Done!\n"); | ||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | int main(int argc, char *argv[]) | ||
92 | { | ||
93 | FILE *infile, *outfile, *fw; | ||
94 | |||
95 | fprintf(stderr, "HXFreplace v" VERSION " - (C) 2008 Maurus Cuelenaere\n"); | ||
96 | fprintf(stderr, "This is free software; see the source for copying conditions. There is NO\n"); | ||
97 | fprintf(stderr, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); | ||
98 | |||
99 | if(argc != 4) | ||
100 | { | ||
101 | print_usage(); | ||
102 | return 1; | ||
103 | } | ||
104 | |||
105 | if((infile = fopen(argv[1], "rb")) == NULL) | ||
106 | { | ||
107 | fprintf(stderr, "[ERR] Cannot open %s\n", argv[1]); | ||
108 | return 2; | ||
109 | } | ||
110 | |||
111 | if(fseek(infile, 0x40, SEEK_SET) != 0) | ||
112 | { | ||
113 | fprintf(stderr, "[ERR] Cannot seek to 0x40\n"); | ||
114 | fclose(infile); | ||
115 | return 3; | ||
116 | } | ||
117 | |||
118 | fprintf(stderr, "[INFO] Searching for ccpmp.bin...\n"); | ||
119 | |||
120 | int found = -1; | ||
121 | int filenamesize; | ||
122 | char *filename; | ||
123 | unsigned char tmp[4]; | ||
124 | |||
125 | #define READ(x, len) if(fread(x, len, 1, infile) != 1) \ | ||
126 | { \ | ||
127 | fprintf(stderr, "[ERR] Cannot read from %s\n", argv[1]); \ | ||
128 | fclose(infile); \ | ||
129 | return 4; \ | ||
130 | } | ||
131 | while(found < 0) | ||
132 | { | ||
133 | READ(&tmp[0], 4); | ||
134 | filenamesize = le2int(tmp); | ||
135 | filename = (char*)malloc(filenamesize); | ||
136 | READ(filename, filenamesize); | ||
137 | if(strcmp(filename, "ccpmp.bin") == 0) | ||
138 | found = ftell(infile); | ||
139 | else | ||
140 | { | ||
141 | READ(&tmp[0], 4); | ||
142 | fseek(infile, le2int(tmp), SEEK_CUR); | ||
143 | } | ||
144 | free(filename); | ||
145 | } | ||
146 | |||
147 | fprintf(stderr, "[INFO] Found ccpmp.bin at 0x%x\n", found); | ||
148 | |||
149 | if((outfile = fopen(argv[2], "wb+")) == NULL) | ||
150 | { | ||
151 | fclose(infile); | ||
152 | fprintf(stderr, "[ERR] Cannot open %s\n", argv[2]); | ||
153 | return 5; | ||
154 | } | ||
155 | |||
156 | #define WRITE(x, len) if(fwrite(x, len, 1, outfile) != 1) \ | ||
157 | { \ | ||
158 | fprintf(stderr, "[ERR] Cannot write to %s\n", argv[2]); \ | ||
159 | fclose(outfile); \ | ||
160 | if(fw != NULL) \ | ||
161 | fclose(fw); \ | ||
162 | return 5; \ | ||
163 | } | ||
164 | |||
165 | unsigned char* buffer; | ||
166 | |||
167 | buffer = (unsigned char*)malloc(found); | ||
168 | fseek(infile, 0, SEEK_SET); | ||
169 | READ(buffer, found); | ||
170 | WRITE(buffer, found); | ||
171 | free(buffer); | ||
172 | |||
173 | if((fw = fopen(argv[3], "rb")) == NULL) | ||
174 | { | ||
175 | fclose(infile); | ||
176 | fclose(outfile); | ||
177 | fprintf(stderr, "[ERR] Cannot open %s\n", argv[3]); | ||
178 | } | ||
179 | |||
180 | int fw_filesize = _filesize(fw); | ||
181 | |||
182 | #define READ2(x, len) if(fread(x, len, 1, fw) != 1) \ | ||
183 | { \ | ||
184 | fprintf(stderr, "[ERR] Cannot read from %s\n", argv[3]); \ | ||
185 | fclose(infile); \ | ||
186 | fclose(outfile); \ | ||
187 | return 6; \ | ||
188 | } | ||
189 | buffer = (unsigned char*)malloc(fw_filesize); | ||
190 | READ2(buffer, fw_filesize); | ||
191 | fputc(0x20, outfile); /* Padding */ | ||
192 | WRITE(int2le(fw_filesize), 4); | ||
193 | WRITE(buffer, fw_filesize); | ||
194 | free(buffer); | ||
195 | fclose(fw); | ||
196 | fw = NULL; | ||
197 | |||
198 | fseek(infile, found+1, SEEK_SET); | ||
199 | READ(&tmp, 4); | ||
200 | if(fseek(infile, le2int(&tmp[0]), SEEK_CUR) != 0) | ||
201 | { | ||
202 | fprintf(stderr, "[INFO] Cannot seek into %s\n", argv[1]); | ||
203 | fclose(infile); | ||
204 | fclose(outfile); | ||
205 | return 7; | ||
206 | } | ||
207 | found = ftell(infile); | ||
208 | |||
209 | int other_size = _filesize(infile) - found; | ||
210 | buffer = (unsigned char*)malloc(other_size); | ||
211 | READ(buffer, other_size); | ||
212 | WRITE(buffer, other_size); | ||
213 | free(buffer); | ||
214 | fclose(infile); | ||
215 | |||
216 | fflush(outfile); | ||
217 | fseek(outfile, 0x14, SEEK_SET); | ||
218 | WRITE(int2le(_filesize(outfile)), 4); | ||
219 | WRITE(int2le(checksum(outfile)), 4); | ||
220 | fclose(outfile); | ||
221 | |||
222 | fprintf(stderr, "[INFO] Done!\n"); | ||
223 | |||
224 | return 0; | ||
225 | } | ||
diff --git a/utils/jz4740_tools/HXFsplit.c b/utils/jz4740_tools/HXFsplit.c new file mode 100755 index 0000000000..ede22170e4 --- /dev/null +++ b/utils/jz4740_tools/HXFsplit.c | |||
@@ -0,0 +1,304 @@ | |||
1 | /* | ||
2 | Made by Maurus Cuelenaere | ||
3 | */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <fcntl.h> | ||
10 | #include <unistd.h> | ||
11 | #include <sys/stat.h> | ||
12 | #include <stdbool.h> | ||
13 | |||
14 | #define VERSION "0.2" | ||
15 | |||
16 | struct header{ | ||
17 | char main_header[20]; | ||
18 | unsigned int size; | ||
19 | unsigned int checksum; | ||
20 | unsigned int unknown; | ||
21 | char other_header[32]; | ||
22 | }; | ||
23 | |||
24 | static char* basepath(char* path) | ||
25 | { | ||
26 | static char tmp[255]; | ||
27 | char *ptr, *ptr2, *ptr3; | ||
28 | ptr = path; | ||
29 | ptr2 = (char*)tmp; | ||
30 | #ifdef _WIN32 | ||
31 | ptr3 = strrchr(path, 0x5C); | ||
32 | #else | ||
33 | ptr3 = strrchr(path, 0x2F); | ||
34 | #endif | ||
35 | while((int)ptr < (int)ptr3) | ||
36 | { | ||
37 | *ptr2 = *ptr; | ||
38 | ptr++; | ||
39 | ptr2++; | ||
40 | } | ||
41 | #ifdef _WIN32 | ||
42 | *ptr2 = 0x5C; | ||
43 | #else | ||
44 | *ptr2 = 0x2F; | ||
45 | #endif | ||
46 | *ptr2++; | ||
47 | *ptr2 = 0; | ||
48 | return (char*)tmp; | ||
49 | } | ||
50 | |||
51 | #ifndef _WIN32 | ||
52 | static void replace(char* str) | ||
53 | { | ||
54 | char *ptr = str; | ||
55 | while(*ptr != 0) | ||
56 | { | ||
57 | if(*ptr == 0x5C) /* \ */ | ||
58 | *ptr = 0x2F; /* / */ | ||
59 | ptr++; | ||
60 | } | ||
61 | } | ||
62 | #endif | ||
63 | |||
64 | static unsigned int le2int(unsigned char* buf) | ||
65 | { | ||
66 | unsigned int res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | ||
67 | |||
68 | return res; | ||
69 | } | ||
70 | |||
71 | #ifdef _WIN32 | ||
72 | #define PATH_SEPARATOR '\\' | ||
73 | #else | ||
74 | #define PATH_SEPARATOR '/' | ||
75 | #endif | ||
76 | |||
77 | static unsigned int __mkdir(const char *path) | ||
78 | { | ||
79 | char opath[256]; | ||
80 | char *p; | ||
81 | size_t len; | ||
82 | |||
83 | strncpy(opath, path, sizeof(opath)); | ||
84 | len = strlen(opath); | ||
85 | if(opath[len - 1] == PATH_SEPARATOR) | ||
86 | opath[len - 1] = '\0'; | ||
87 | for(p = opath; *p; p++) | ||
88 | if(*p == PATH_SEPARATOR) | ||
89 | { | ||
90 | *p = '\0'; | ||
91 | if(access(opath, F_OK)) | ||
92 | #ifdef _WIN32 | ||
93 | mkdir(opath); | ||
94 | #else | ||
95 | mkdir(opath, S_IRWXU); | ||
96 | #endif | ||
97 | *p = PATH_SEPARATOR; | ||
98 | } | ||
99 | if(access(opath, F_OK)) | ||
100 | #ifdef _WIN32 | ||
101 | return mkdir(opath); | ||
102 | #else | ||
103 | return mkdir(opath, S_IRWXU); | ||
104 | #endif | ||
105 | else | ||
106 | return -1; | ||
107 | } | ||
108 | |||
109 | #if 0 | ||
110 | static bool dir_exists(const char *dir) | ||
111 | { | ||
112 | struct stat buf; | ||
113 | memset(&buf, 0, sizeof(struct stat)); | ||
114 | printf("start: %s\n", dir); | ||
115 | char *dir_cpy = (char*)malloc(strlen(dir)); | ||
116 | strcpy(dir_cpy, dir); | ||
117 | printf("%s\n", dir_cpy); | ||
118 | int tmp = (int)dir_cpy; | ||
119 | while(*dir_cpy != 0) | ||
120 | { | ||
121 | dir_cpy++; | ||
122 | if(*dir_cpy == PATH_SEPARATOR && *(dir_cpy+1) == 0) | ||
123 | *dir_cpy = 0; | ||
124 | } | ||
125 | printf("while_done\n"); | ||
126 | dir_cpy = (char*)tmp; | ||
127 | printf("statting %s...\n", dir_cpy); | ||
128 | tmp = stat(dir_cpy, &buf); | ||
129 | printf("chk_dir(%s) = %d\n", dir_cpy, tmp); | ||
130 | free(dir_cpy); | ||
131 | return tmp == 0; | ||
132 | } | ||
133 | #endif | ||
134 | |||
135 | static bool file_exists(const char *file) | ||
136 | { | ||
137 | struct stat buf; | ||
138 | return stat(file, &buf) == 0; | ||
139 | } | ||
140 | |||
141 | |||
142 | static int split_hxf(const unsigned char* infile, unsigned int size, const char* outpath) | ||
143 | { | ||
144 | FILE *outfile; | ||
145 | char *filename; | ||
146 | unsigned int filenamesize, filesize; | ||
147 | while(size > 0) | ||
148 | { | ||
149 | filenamesize = le2int((unsigned char*)infile); | ||
150 | infile += 4; | ||
151 | size -= 4; | ||
152 | if(size > 0) | ||
153 | { | ||
154 | filename = (char*)calloc(1, filenamesize+1+strlen(outpath)); | ||
155 | memcpy(filename, outpath, strlen(outpath)); | ||
156 | memcpy(&filename[strlen(outpath)], infile, filenamesize); | ||
157 | #ifndef _WIN32 | ||
158 | replace(filename); | ||
159 | #endif | ||
160 | infile += filenamesize + 1; /* + padding */ | ||
161 | size -= filenamesize + 1; | ||
162 | |||
163 | filesize = le2int((unsigned char*)infile); | ||
164 | infile += 4; | ||
165 | size -= 4; | ||
166 | #if 0 | ||
167 | if(!dir_exists(basepath(filename))) | ||
168 | #endif | ||
169 | { | ||
170 | printf("[INFO] %s\n", basepath(filename)); | ||
171 | if(__mkdir(basepath(filename)) != 0) | ||
172 | { | ||
173 | #if 0 | ||
174 | fprintf(stderr, "[ERR] Error creating directory %s\n", basepath(filename)); | ||
175 | return -3; | ||
176 | #endif | ||
177 | } | ||
178 | } | ||
179 | |||
180 | if(!file_exists(filename)) | ||
181 | { | ||
182 | printf("[INFO] %s: %d bytes\n", filename, filesize); | ||
183 | if((outfile = fopen(filename, "wb")) == NULL) | ||
184 | { | ||
185 | fprintf(stderr, "[ERR] Error opening file %s\n", filename); | ||
186 | return -1; | ||
187 | } | ||
188 | if(filesize>0) | ||
189 | { | ||
190 | if(fwrite(infile, filesize, 1, outfile) != 1) | ||
191 | { | ||
192 | fclose(outfile); | ||
193 | fprintf(stderr, "[ERR] Error writing to file %s\n", filename); | ||
194 | return -2; | ||
195 | } | ||
196 | } | ||
197 | fclose(outfile); | ||
198 | } | ||
199 | |||
200 | infile += filesize; | ||
201 | size -= filesize; | ||
202 | } | ||
203 | } | ||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | static void print_usage(void) | ||
208 | { | ||
209 | #ifdef _WIN32 | ||
210 | fprintf(stderr, "Usage: hxfsplit.exe [FW] [OUTPUT_DIR]\n\n"); | ||
211 | fprintf(stderr, "Example: hxfsplit.exe VX747.HXF VX747_extracted\\\n\n"); | ||
212 | #else | ||
213 | fprintf(stderr, "Usage: HXFsplit [FW] [OUTPUT_DIR]\n\n"); | ||
214 | fprintf(stderr, "Example: HXFsplit VX747.HXF VX747_extracted/\n\n"); | ||
215 | #endif | ||
216 | } | ||
217 | |||
218 | int main(int argc, char *argv[]) | ||
219 | { | ||
220 | FILE *infile; | ||
221 | struct header hdr; | ||
222 | unsigned char *inbuffer; | ||
223 | |||
224 | fprintf(stderr, "HXFsplit v" VERSION " - (C) 2008 Maurus Cuelenaere\n"); | ||
225 | fprintf(stderr, "This is free software; see the source for copying conditions. There is NO\n"); | ||
226 | fprintf(stderr, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); | ||
227 | |||
228 | if(argc != 3) | ||
229 | { | ||
230 | print_usage(); | ||
231 | return 1; | ||
232 | } | ||
233 | |||
234 | #ifdef _WIN32 | ||
235 | if(strcmp((char*)(argv[2]+strlen(argv[2])-1), "\\") != 0) | ||
236 | { | ||
237 | fprintf(stderr, "[ERR] Output path must end with a \\\n"); | ||
238 | #else | ||
239 | if(strcmp((char*)(argv[2]+strlen(argv[2])-1), "/") != 0) | ||
240 | { | ||
241 | fprintf(stderr, "[ERR] Output path must end with a /\n"); | ||
242 | #endif | ||
243 | return 2; | ||
244 | } | ||
245 | |||
246 | if((infile = fopen(argv[1], "rb")) == NULL) | ||
247 | { | ||
248 | fprintf(stderr, "[ERR] Cannot open %s\n", argv[1]); | ||
249 | return 3; | ||
250 | } | ||
251 | |||
252 | if((inbuffer = (unsigned char*)malloc(sizeof(struct header))) == NULL) | ||
253 | { | ||
254 | fclose(infile); | ||
255 | fprintf(stderr, "[ERR] Error allocating %d bytes buffer\n", sizeof(struct header)); | ||
256 | return 4; | ||
257 | } | ||
258 | |||
259 | if(fread(inbuffer, sizeof(struct header), 1, infile) != 1) | ||
260 | { | ||
261 | fclose(infile); | ||
262 | fprintf(stderr, "Cannot read header of %s\n", argv[1]); | ||
263 | return 5; | ||
264 | } | ||
265 | |||
266 | memcpy(hdr.main_header, inbuffer, 20); | ||
267 | hdr.size = le2int(&inbuffer[20]); | ||
268 | hdr.checksum = le2int(&inbuffer[24]); | ||
269 | hdr.unknown = le2int(&inbuffer[28]); | ||
270 | memcpy(hdr.other_header, &inbuffer[32], 32); | ||
271 | free(inbuffer); | ||
272 | |||
273 | if(strcmp(hdr.other_header, "Chinachip PMP firmware V1.0") != 0) | ||
274 | { | ||
275 | fclose(infile); | ||
276 | fprintf(stderr, "[ERR] Header doesn't match\n"); | ||
277 | return 6; | ||
278 | } | ||
279 | |||
280 | if((inbuffer = (unsigned char*)malloc(hdr.size)) == NULL) | ||
281 | { | ||
282 | fclose(infile); | ||
283 | fprintf(stderr, "[ERR] Error allocating %d bytes buffer\n", hdr.size); | ||
284 | return 7; | ||
285 | } | ||
286 | |||
287 | fseek(infile, sizeof(struct header), SEEK_SET); | ||
288 | |||
289 | if(fread(inbuffer, hdr.size-sizeof(struct header), 1, infile) != 1) | ||
290 | { | ||
291 | fclose(infile); | ||
292 | free(inbuffer); | ||
293 | fprintf(stderr, "[ERR] Cannot read file in buffer\n"); | ||
294 | return 8; | ||
295 | } | ||
296 | |||
297 | fclose(infile); | ||
298 | |||
299 | split_hxf(inbuffer, hdr.size-sizeof(struct header), argv[2]); | ||
300 | |||
301 | free(inbuffer); | ||
302 | |||
303 | return 0; | ||
304 | } | ||
diff --git a/utils/jz4740_usbtool/Makefile b/utils/jz4740_tools/Makefile index e61b837d99..e61b837d99 100755 --- a/utils/jz4740_usbtool/Makefile +++ b/utils/jz4740_tools/Makefile | |||
diff --git a/utils/jz4740_usbtool/jz4740.h b/utils/jz4740_tools/jz4740.h index 87b400e3b9..87b400e3b9 100755 --- a/utils/jz4740_usbtool/jz4740.h +++ b/utils/jz4740_tools/jz4740.h | |||
diff --git a/utils/jz4740_usbtool/jz4740_usbtool.c b/utils/jz4740_tools/jz4740_usbtool.c index 4437f63675..4437f63675 100755 --- a/utils/jz4740_usbtool/jz4740_usbtool.c +++ b/utils/jz4740_tools/jz4740_usbtool.c | |||
diff --git a/utils/jz4740_usbtool/windows_driver/jz4740_usbtool.cat b/utils/jz4740_tools/windows_driver/jz4740_usbtool.cat index 2ef39c526e..2ef39c526e 100755 --- a/utils/jz4740_usbtool/windows_driver/jz4740_usbtool.cat +++ b/utils/jz4740_tools/windows_driver/jz4740_usbtool.cat | |||
diff --git a/utils/jz4740_usbtool/windows_driver/jz4740_usbtool.inf b/utils/jz4740_tools/windows_driver/jz4740_usbtool.inf index 1ccae7d0e2..1ccae7d0e2 100755 --- a/utils/jz4740_usbtool/windows_driver/jz4740_usbtool.inf +++ b/utils/jz4740_tools/windows_driver/jz4740_usbtool.inf | |||
diff --git a/utils/jz4740_usbtool/windows_driver/jz4740_usbtool_x64.cat b/utils/jz4740_tools/windows_driver/jz4740_usbtool_x64.cat index 2ef39c526e..2ef39c526e 100755 --- a/utils/jz4740_usbtool/windows_driver/jz4740_usbtool_x64.cat +++ b/utils/jz4740_tools/windows_driver/jz4740_usbtool_x64.cat | |||
diff --git a/utils/jz4740_usbtool/windows_driver/libusb0.dll b/utils/jz4740_tools/windows_driver/libusb0.dll index 9387bedad1..9387bedad1 100755 --- a/utils/jz4740_usbtool/windows_driver/libusb0.dll +++ b/utils/jz4740_tools/windows_driver/libusb0.dll | |||
Binary files differ | |||
diff --git a/utils/jz4740_usbtool/windows_driver/libusb0.sys b/utils/jz4740_tools/windows_driver/libusb0.sys index 0a02d3ee33..0a02d3ee33 100755 --- a/utils/jz4740_usbtool/windows_driver/libusb0.sys +++ b/utils/jz4740_tools/windows_driver/libusb0.sys | |||
Binary files differ | |||
diff --git a/utils/jz4740_usbtool/windows_driver/libusb0_x64.dll b/utils/jz4740_tools/windows_driver/libusb0_x64.dll index c89a59fe38..c89a59fe38 100755 --- a/utils/jz4740_usbtool/windows_driver/libusb0_x64.dll +++ b/utils/jz4740_tools/windows_driver/libusb0_x64.dll | |||
Binary files differ | |||
diff --git a/utils/jz4740_usbtool/windows_driver/libusb0_x64.sys b/utils/jz4740_tools/windows_driver/libusb0_x64.sys index 07cf0858ae..07cf0858ae 100755 --- a/utils/jz4740_usbtool/windows_driver/libusb0_x64.sys +++ b/utils/jz4740_tools/windows_driver/libusb0_x64.sys | |||
Binary files differ | |||