diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-07-18 00:27:12 +0200 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-07-18 00:27:12 +0200 |
commit | 1c8c24183ed9d89519de2924997593cc81f6f33d (patch) | |
tree | ba4a7babace41a249c44467982d5e6a70b8d7796 /utils/imxtools/sbtools | |
parent | 3c5ee9ac57cbac4050df1729a28ec39c60d303ff (diff) | |
download | rockbox-1c8c24183ed9d89519de2924997593cc81f6f33d.tar.gz rockbox-1c8c24183ed9d89519de2924997593cc81f6f33d.zip |
sbtools: refactor and cleanup
Factor common elf/sb read/write/printf routines. Factor sb zero
key, move sb version guess.
Change-Id: I5ae1885587456736e782e623610281bbee545039
Diffstat (limited to 'utils/imxtools/sbtools')
-rw-r--r-- | utils/imxtools/sbtools/elf.c | 26 | ||||
-rw-r--r-- | utils/imxtools/sbtools/elf.h | 6 | ||||
-rw-r--r-- | utils/imxtools/sbtools/elftosb.c | 30 | ||||
-rw-r--r-- | utils/imxtools/sbtools/misc.c | 41 | ||||
-rw-r--r-- | utils/imxtools/sbtools/misc.h | 10 | ||||
-rw-r--r-- | utils/imxtools/sbtools/rsrctool.c | 2 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sb.c | 18 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sb.h | 4 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sb1.c | 4 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sbloader.c | 1 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 110 | ||||
-rw-r--r-- | utils/imxtools/sbtools/xorcrypt.c | 2 |
12 files changed, 131 insertions, 123 deletions
diff --git a/utils/imxtools/sbtools/elf.c b/utils/imxtools/sbtools/elf.c index 5626c0f58c..76f29c6db7 100644 --- a/utils/imxtools/sbtools/elf.c +++ b/utils/imxtools/sbtools/elf.c | |||
@@ -20,6 +20,7 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "elf.h" | 21 | #include "elf.h" |
22 | #include "misc.h" | 22 | #include "misc.h" |
23 | #include <stdarg.h> | ||
23 | 24 | ||
24 | /** | 25 | /** |
25 | * Definitions | 26 | * Definitions |
@@ -723,3 +724,28 @@ void elf_release(struct elf_params_t *params) | |||
723 | seg = next_seg; | 724 | seg = next_seg; |
724 | } | 725 | } |
725 | } | 726 | } |
727 | |||
728 | void elf_std_printf(void *user, bool error, const char *fmt, ...) | ||
729 | { | ||
730 | if(!g_debug && !error) | ||
731 | return; | ||
732 | (void) user; | ||
733 | va_list args; | ||
734 | va_start(args, fmt); | ||
735 | vprintf(fmt, args); | ||
736 | va_end(args); | ||
737 | } | ||
738 | |||
739 | void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count) | ||
740 | { | ||
741 | FILE *f = user; | ||
742 | fseek(f, addr, SEEK_SET); | ||
743 | fwrite(buf, count, 1, f); | ||
744 | } | ||
745 | |||
746 | bool elf_std_read(void *user, uint32_t addr, void *buf, size_t count) | ||
747 | { | ||
748 | if(fseek((FILE *)user, addr, SEEK_SET) == -1) | ||
749 | return false; | ||
750 | return fread(buf, 1, count, (FILE *)user) == count; | ||
751 | } | ||
diff --git a/utils/imxtools/sbtools/elf.h b/utils/imxtools/sbtools/elf.h index 2e14e66fd3..91e160152c 100644 --- a/utils/imxtools/sbtools/elf.h +++ b/utils/imxtools/sbtools/elf.h | |||
@@ -93,4 +93,10 @@ bool elf_get_start_addr(struct elf_params_t *params, uint32_t *addr); | |||
93 | int elf_get_nr_sections(struct elf_params_t *params); | 93 | int elf_get_nr_sections(struct elf_params_t *params); |
94 | void elf_release(struct elf_params_t *params); | 94 | void elf_release(struct elf_params_t *params); |
95 | 95 | ||
96 | /* standard implementation of read/write/printf functions | ||
97 | * with user being a FILE* pointer */ | ||
98 | void elf_std_printf(void *user, bool error, const char *fmt, ...); | ||
99 | void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count); | ||
100 | bool elf_std_read(void *user, uint32_t addr, void *buf, size_t count); | ||
101 | |||
96 | #endif /* __ELF_H__ */ | 102 | #endif /* __ELF_H__ */ |
diff --git a/utils/imxtools/sbtools/elftosb.c b/utils/imxtools/sbtools/elftosb.c index fd44693a94..a18bad6437 100644 --- a/utils/imxtools/sbtools/elftosb.c +++ b/utils/imxtools/sbtools/elftosb.c | |||
@@ -52,24 +52,6 @@ int g_extern_count; | |||
52 | * command file to sb conversion | 52 | * command file to sb conversion |
53 | */ | 53 | */ |
54 | 54 | ||
55 | static bool elf_read(void *user, uint32_t addr, void *buf, size_t count) | ||
56 | { | ||
57 | if(fseek((FILE *)user, addr, SEEK_SET) == -1) | ||
58 | return false; | ||
59 | return fread(buf, 1, count, (FILE *)user) == count; | ||
60 | } | ||
61 | |||
62 | static void elf_printf(void *user, bool error, const char *fmt, ...) | ||
63 | { | ||
64 | if(!g_debug && !error) | ||
65 | return; | ||
66 | (void) user; | ||
67 | va_list args; | ||
68 | va_start(args, fmt); | ||
69 | vprintf(fmt, args); | ||
70 | va_end(args); | ||
71 | } | ||
72 | |||
73 | static void resolve_extern(struct cmd_source_t *src) | 55 | static void resolve_extern(struct cmd_source_t *src) |
74 | { | 56 | { |
75 | if(!src->is_extern) | 57 | if(!src->is_extern) |
@@ -102,7 +84,7 @@ static void load_elf_by_id(struct cmd_file_t *cmd_file, const char *id) | |||
102 | if(g_debug) | 84 | if(g_debug) |
103 | printf("Loading ELF file '%s'...\n", src->filename); | 85 | printf("Loading ELF file '%s'...\n", src->filename); |
104 | elf_init(&src->elf); | 86 | elf_init(&src->elf); |
105 | src->loaded = elf_read_file(&src->elf, elf_read, elf_printf, fd); | 87 | src->loaded = elf_read_file(&src->elf, elf_std_read, elf_std_printf, fd); |
106 | fclose(fd); | 88 | fclose(fd); |
107 | if(!src->loaded) | 89 | if(!src->loaded) |
108 | bug("error loading elf file '%s' (id '%s')\n", src->filename, id); | 90 | bug("error loading elf file '%s' (id '%s')\n", src->filename, id); |
@@ -333,12 +315,6 @@ static void usage(void) | |||
333 | exit(1); | 315 | exit(1); |
334 | } | 316 | } |
335 | 317 | ||
336 | static struct crypto_key_t g_zero_key = | ||
337 | { | ||
338 | .method = CRYPTO_KEY, | ||
339 | .u.key = {0} | ||
340 | }; | ||
341 | |||
342 | int main(int argc, char **argv) | 318 | int main(int argc, char **argv) |
343 | { | 319 | { |
344 | char *cmd_filename = NULL; | 320 | char *cmd_filename = NULL; |
@@ -385,6 +361,8 @@ int main(int argc, char **argv) | |||
385 | } | 361 | } |
386 | case 'z': | 362 | case 'z': |
387 | { | 363 | { |
364 | struct crypto_key_t g_zero_key; | ||
365 | sb_get_zero_key(&g_zero_key); | ||
388 | add_keys(&g_zero_key, 1); | 366 | add_keys(&g_zero_key, 1); |
389 | break; | 367 | break; |
390 | } | 368 | } |
@@ -407,7 +385,7 @@ int main(int argc, char **argv) | |||
407 | break; | 385 | break; |
408 | } | 386 | } |
409 | default: | 387 | default: |
410 | abort(); | 388 | bug("Internal error: unknown option '%c'\n", c); |
411 | } | 389 | } |
412 | } | 390 | } |
413 | 391 | ||
diff --git a/utils/imxtools/sbtools/misc.c b/utils/imxtools/sbtools/misc.c index b9f5d21f7e..68c769808b 100644 --- a/utils/imxtools/sbtools/misc.c +++ b/utils/imxtools/sbtools/misc.c | |||
@@ -305,3 +305,44 @@ void color(color_t c) | |||
305 | if(g_color_enable) | 305 | if(g_color_enable) |
306 | printf("%s", (char *)c); | 306 | printf("%s", (char *)c); |
307 | } | 307 | } |
308 | |||
309 | enum sb_version_guess_t guess_sb_version(const char *filename) | ||
310 | { | ||
311 | #define ret(x) do { fclose(f); return x; } while(0) | ||
312 | FILE *f = fopen(filename, "rb"); | ||
313 | if(f == NULL) | ||
314 | ret(SB_VERSION_ERR); | ||
315 | // check signature | ||
316 | uint8_t sig[4]; | ||
317 | if(fseek(f, 20, SEEK_SET)) | ||
318 | ret(SB_VERSION_UNK); | ||
319 | if(fread(sig, 4, 1, f) != 1) | ||
320 | ret(SB_VERSION_UNK); | ||
321 | if(memcmp(sig, "STMP", 4) != 0) | ||
322 | ret(SB_VERSION_UNK); | ||
323 | // check header size (v1) | ||
324 | uint32_t hdr_size; | ||
325 | if(fseek(f, 8, SEEK_SET)) | ||
326 | ret(SB_VERSION_UNK); | ||
327 | if(fread(&hdr_size, 4, 1, f) != 1) | ||
328 | ret(SB_VERSION_UNK); | ||
329 | if(hdr_size == 0x34) | ||
330 | ret(SB_VERSION_1); | ||
331 | // check header params relationship | ||
332 | struct | ||
333 | { | ||
334 | uint16_t nr_keys; /* Number of encryption keys */ | ||
335 | uint16_t key_dict_off; /* Offset to key dictionary (in blocks) */ | ||
336 | uint16_t header_size; /* In blocks */ | ||
337 | uint16_t nr_sections; /* Number of sections */ | ||
338 | uint16_t sec_hdr_size; /* Section header size (in blocks) */ | ||
339 | } __attribute__((packed)) u; | ||
340 | if(fseek(f, 0x28, SEEK_SET)) | ||
341 | ret(SB_VERSION_UNK); | ||
342 | if(fread(&u, sizeof(u), 1, f) != 1) | ||
343 | ret(SB_VERSION_UNK); | ||
344 | if(u.sec_hdr_size == 1 && u.header_size == 6 && u.key_dict_off == u.header_size + u.nr_sections) | ||
345 | ret(SB_VERSION_2); | ||
346 | ret(SB_VERSION_UNK); | ||
347 | #undef ret | ||
348 | } | ||
diff --git a/utils/imxtools/sbtools/misc.h b/utils/imxtools/sbtools/misc.h index 06e8166c09..8429e84faf 100644 --- a/utils/imxtools/sbtools/misc.h +++ b/utils/imxtools/sbtools/misc.h | |||
@@ -63,4 +63,14 @@ extern color_t OFF, GREY, RED, GREEN, YELLOW, BLUE; | |||
63 | void color(color_t c); | 63 | void color(color_t c); |
64 | void enable_color(bool enable); | 64 | void enable_color(bool enable); |
65 | 65 | ||
66 | enum sb_version_guess_t | ||
67 | { | ||
68 | SB_VERSION_1, | ||
69 | SB_VERSION_2, | ||
70 | SB_VERSION_UNK, | ||
71 | SB_VERSION_ERR, | ||
72 | }; | ||
73 | |||
74 | enum sb_version_guess_t guess_sb_version(const char *filename); | ||
75 | |||
66 | #endif /* __MISC_H__ */ | 76 | #endif /* __MISC_H__ */ |
diff --git a/utils/imxtools/sbtools/rsrctool.c b/utils/imxtools/sbtools/rsrctool.c index f95542fc49..43482d5626 100644 --- a/utils/imxtools/sbtools/rsrctool.c +++ b/utils/imxtools/sbtools/rsrctool.c | |||
@@ -158,7 +158,7 @@ int main(int argc, char **argv) | |||
158 | break; | 158 | break; |
159 | } | 159 | } |
160 | default: | 160 | default: |
161 | abort(); | 161 | bug("Internal error: unknown option '%c'\n", c); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | 164 | ||
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c index f64da8ff84..83ed9184ea 100644 --- a/utils/imxtools/sbtools/sb.c +++ b/utils/imxtools/sbtools/sb.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <time.h> | 22 | #include <time.h> |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <ctype.h> | 24 | #include <ctype.h> |
25 | #include <stdarg.h> | ||
25 | #include "misc.h" | 26 | #include "misc.h" |
26 | #include "crypto.h" | 27 | #include "crypto.h" |
27 | #include "sb.h" | 28 | #include "sb.h" |
@@ -1245,3 +1246,20 @@ void sb_dump(struct sb_file_t *file, void *u, sb_color_printf cprintf) | |||
1245 | #undef printf | 1246 | #undef printf |
1246 | #undef print_hex | 1247 | #undef print_hex |
1247 | } | 1248 | } |
1249 | |||
1250 | void sb_get_zero_key(struct crypto_key_t *key) | ||
1251 | { | ||
1252 | key->method = CRYPTO_KEY; | ||
1253 | memset(key->u.key, 0, sizeof(key->u.key)); | ||
1254 | } | ||
1255 | |||
1256 | void sb_std_printf(void *user, bool error, color_t c, const char *fmt, ...) | ||
1257 | { | ||
1258 | (void) user; | ||
1259 | (void) error; | ||
1260 | va_list args; | ||
1261 | va_start(args, fmt); | ||
1262 | color(c); | ||
1263 | vprintf(fmt, args); | ||
1264 | va_end(args); | ||
1265 | } | ||
diff --git a/utils/imxtools/sbtools/sb.h b/utils/imxtools/sbtools/sb.h index 4873195a61..02150aa2fb 100644 --- a/utils/imxtools/sbtools/sb.h +++ b/utils/imxtools/sbtools/sb.h | |||
@@ -239,5 +239,9 @@ void sb_dump(struct sb_file_t *file, void *u, sb_color_printf printf); | |||
239 | void sb_free_instruction(struct sb_inst_t inst); | 239 | void sb_free_instruction(struct sb_inst_t inst); |
240 | void sb_free_section(struct sb_section_t file); | 240 | void sb_free_section(struct sb_section_t file); |
241 | void sb_free(struct sb_file_t *file); | 241 | void sb_free(struct sb_file_t *file); |
242 | void sb_get_zero_key(struct crypto_key_t *key); | ||
243 | |||
244 | /* standard implementation: user is unused*/ | ||
245 | void sb_std_printf(void *user, bool error, color_t c, const char *fmt, ...); | ||
242 | 246 | ||
243 | #endif /* __SB_H__ */ | 247 | #endif /* __SB_H__ */ |
diff --git a/utils/imxtools/sbtools/sb1.c b/utils/imxtools/sbtools/sb1.c index cbd3185103..ca7b7fdc8c 100644 --- a/utils/imxtools/sbtools/sb1.c +++ b/utils/imxtools/sbtools/sb1.c | |||
@@ -81,7 +81,7 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename) | |||
81 | image_size += 8; | 81 | image_size += 8; |
82 | break; | 82 | break; |
83 | default: | 83 | default: |
84 | bugp("Unknown SB instruction: %#x\n", sb->insts[i].cmd); | 84 | bugp("Internal error: unknown SB instruction: %#x\n", sb->insts[i].cmd); |
85 | } | 85 | } |
86 | } | 86 | } |
87 | // now take crypto marks and sector size into account: | 87 | // now take crypto marks and sector size into account: |
@@ -140,7 +140,7 @@ enum sb1_error_t sb1_write_file(struct sb1_file_t *sb, const char *filename) | |||
140 | sb->insts[i].sdram.size_index); | 140 | sb->insts[i].sdram.size_index); |
141 | break; | 141 | break; |
142 | default: | 142 | default: |
143 | bugp("Unknown SB instruction: %#x\n", sb->insts[i].cmd); | 143 | bugp("Internal error: unknown SB instruction: %#x\n", sb->insts[i].cmd); |
144 | } | 144 | } |
145 | 145 | ||
146 | /* handle most common cases */ | 146 | /* handle most common cases */ |
diff --git a/utils/imxtools/sbtools/sbloader.c b/utils/imxtools/sbtools/sbloader.c index 91c01785f9..1a241ba551 100644 --- a/utils/imxtools/sbtools/sbloader.c +++ b/utils/imxtools/sbtools/sbloader.c | |||
@@ -445,6 +445,7 @@ int main(int argc, char **argv) | |||
445 | } | 445 | } |
446 | break; | 446 | break; |
447 | default: | 447 | default: |
448 | printf("Internal error: unknown option '%c'\n", c); | ||
448 | abort(); | 449 | abort(); |
449 | } | 450 | } |
450 | } | 451 | } |
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index 69ab59e44d..a13e18b81d 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c | |||
@@ -60,24 +60,6 @@ | |||
60 | static char *g_out_prefix; | 60 | static char *g_out_prefix; |
61 | static bool g_elf_simplify = true; | 61 | static bool g_elf_simplify = true; |
62 | 62 | ||
63 | static void elf_printf(void *user, bool error, const char *fmt, ...) | ||
64 | { | ||
65 | if(!g_debug && !error) | ||
66 | return; | ||
67 | (void) user; | ||
68 | va_list args; | ||
69 | va_start(args, fmt); | ||
70 | vprintf(fmt, args); | ||
71 | va_end(args); | ||
72 | } | ||
73 | |||
74 | static void elf_write(void *user, uint32_t addr, const void *buf, size_t count) | ||
75 | { | ||
76 | FILE *f = user; | ||
77 | fseek(f, addr, SEEK_SET); | ||
78 | fwrite(buf, count, 1, f); | ||
79 | } | ||
80 | |||
81 | static void extract_elf_section(struct elf_params_t *elf, int count, uint32_t id) | 63 | static void extract_elf_section(struct elf_params_t *elf, int count, uint32_t id) |
82 | { | 64 | { |
83 | char name[5]; | 65 | char name[5]; |
@@ -94,7 +76,7 @@ static void extract_elf_section(struct elf_params_t *elf, int count, uint32_t id | |||
94 | return; | 76 | return; |
95 | if(g_elf_simplify) | 77 | if(g_elf_simplify) |
96 | elf_simplify(elf); | 78 | elf_simplify(elf); |
97 | elf_write_file(elf, elf_write, elf_printf, fd); | 79 | elf_write_file(elf, elf_std_write, elf_std_printf, fd); |
98 | fclose(fd); | 80 | fclose(fd); |
99 | } | 81 | } |
100 | 82 | ||
@@ -174,7 +156,7 @@ static void extract_elf(struct elf_params_t *elf, int count) | |||
174 | return; | 156 | return; |
175 | if(g_elf_simplify) | 157 | if(g_elf_simplify) |
176 | elf_simplify(elf); | 158 | elf_simplify(elf); |
177 | elf_write_file(elf, elf_write, elf_printf, fd); | 159 | elf_write_file(elf, elf_std_write, elf_std_printf, fd); |
178 | fclose(fd); | 160 | fclose(fd); |
179 | } | 161 | } |
180 | 162 | ||
@@ -236,73 +218,6 @@ static void usage(void) | |||
236 | exit(1); | 218 | exit(1); |
237 | } | 219 | } |
238 | 220 | ||
239 | static void sb_printf(void *user, bool error, color_t c, const char *fmt, ...) | ||
240 | { | ||
241 | (void) user; | ||
242 | (void) error; | ||
243 | va_list args; | ||
244 | va_start(args, fmt); | ||
245 | color(c); | ||
246 | vprintf(fmt, args); | ||
247 | va_end(args); | ||
248 | } | ||
249 | |||
250 | static struct crypto_key_t g_zero_key = | ||
251 | { | ||
252 | .method = CRYPTO_KEY, | ||
253 | .u.key = {0} | ||
254 | }; | ||
255 | |||
256 | |||
257 | |||
258 | enum sb_version_guess_t | ||
259 | { | ||
260 | SB_VERSION_1, | ||
261 | SB_VERSION_2, | ||
262 | SB_VERSION_UNK, | ||
263 | }; | ||
264 | |||
265 | enum sb_version_guess_t guess_sb_version(const char *filename) | ||
266 | { | ||
267 | #define ret(x) do { fclose(f); return x; } while(0) | ||
268 | FILE *f = fopen(filename, "rb"); | ||
269 | if(f == NULL) | ||
270 | bugp("Cannot open file for reading\n"); | ||
271 | // check signature | ||
272 | uint8_t sig[4]; | ||
273 | if(fseek(f, 20, SEEK_SET)) | ||
274 | ret(SB_VERSION_UNK); | ||
275 | if(fread(sig, 4, 1, f) != 1) | ||
276 | ret(SB_VERSION_UNK); | ||
277 | if(memcmp(sig, "STMP", 4) != 0) | ||
278 | ret(SB_VERSION_UNK); | ||
279 | // check header size (v1) | ||
280 | uint32_t hdr_size; | ||
281 | if(fseek(f, 8, SEEK_SET)) | ||
282 | ret(SB_VERSION_UNK); | ||
283 | if(fread(&hdr_size, 4, 1, f) != 1) | ||
284 | ret(SB_VERSION_UNK); | ||
285 | if(hdr_size == 0x34) | ||
286 | ret(SB_VERSION_1); | ||
287 | // check header params relationship | ||
288 | struct | ||
289 | { | ||
290 | uint16_t nr_keys; /* Number of encryption keys */ | ||
291 | uint16_t key_dict_off; /* Offset to key dictionary (in blocks) */ | ||
292 | uint16_t header_size; /* In blocks */ | ||
293 | uint16_t nr_sections; /* Number of sections */ | ||
294 | uint16_t sec_hdr_size; /* Section header size (in blocks) */ | ||
295 | } __attribute__((packed)) u; | ||
296 | if(fseek(f, 0x28, SEEK_SET)) | ||
297 | ret(SB_VERSION_UNK); | ||
298 | if(fread(&u, sizeof(u), 1, f) != 1) | ||
299 | ret(SB_VERSION_UNK); | ||
300 | if(u.sec_hdr_size == 1 && u.header_size == 6 && u.key_dict_off == u.header_size + u.nr_sections) | ||
301 | ret(SB_VERSION_2); | ||
302 | ret(SB_VERSION_UNK); | ||
303 | #undef ret | ||
304 | } | ||
305 | |||
306 | int main(int argc, char **argv) | 221 | int main(int argc, char **argv) |
307 | { | 222 | { |
308 | bool raw_mode = false; | 223 | bool raw_mode = false; |
@@ -361,8 +276,12 @@ int main(int argc, char **argv) | |||
361 | break; | 276 | break; |
362 | } | 277 | } |
363 | case 'z': | 278 | case 'z': |
279 | { | ||
280 | struct crypto_key_t g_zero_key; | ||
281 | sb_get_zero_key(&g_zero_key); | ||
364 | add_keys(&g_zero_key, 1); | 282 | add_keys(&g_zero_key, 1); |
365 | break; | 283 | break; |
284 | } | ||
366 | case 'x': | 285 | case 'x': |
367 | { | 286 | { |
368 | struct crypto_key_t key; | 287 | struct crypto_key_t key; |
@@ -397,7 +316,7 @@ int main(int argc, char **argv) | |||
397 | brute_force = true; | 316 | brute_force = true; |
398 | break; | 317 | break; |
399 | default: | 318 | default: |
400 | abort(); | 319 | bug("Internal error: unknown option '%c'\n", c); |
401 | } | 320 | } |
402 | } | 321 | } |
403 | 322 | ||
@@ -413,11 +332,16 @@ int main(int argc, char **argv) | |||
413 | const char *sb_filename = argv[optind]; | 332 | const char *sb_filename = argv[optind]; |
414 | 333 | ||
415 | enum sb_version_guess_t ver = guess_sb_version(sb_filename); | 334 | enum sb_version_guess_t ver = guess_sb_version(sb_filename); |
335 | if(ver == SB_VERSION_ERR) | ||
336 | { | ||
337 | printf("Cannot open/read SB file: %m\n"); | ||
338 | return 1; | ||
339 | } | ||
416 | 340 | ||
417 | if(force_sb2 || ver == SB_VERSION_2) | 341 | if(force_sb2 || ver == SB_VERSION_2) |
418 | { | 342 | { |
419 | enum sb_error_t err; | 343 | enum sb_error_t err; |
420 | struct sb_file_t *file = sb_read_file(sb_filename, raw_mode, NULL, sb_printf, &err); | 344 | struct sb_file_t *file = sb_read_file(sb_filename, raw_mode, NULL, sb_std_printf, &err); |
421 | if(file == NULL) | 345 | if(file == NULL) |
422 | { | 346 | { |
423 | color(OFF); | 347 | color(OFF); |
@@ -432,7 +356,7 @@ int main(int argc, char **argv) | |||
432 | { | 356 | { |
433 | color(GREY); | 357 | color(GREY); |
434 | printf("[Debug output]\n"); | 358 | printf("[Debug output]\n"); |
435 | sb_dump(file, NULL, sb_printf); | 359 | sb_dump(file, NULL, sb_std_printf); |
436 | } | 360 | } |
437 | if(loopback) | 361 | if(loopback) |
438 | { | 362 | { |
@@ -451,7 +375,7 @@ int main(int argc, char **argv) | |||
451 | { | 375 | { |
452 | struct crypto_key_t key; | 376 | struct crypto_key_t key; |
453 | enum sb1_error_t err; | 377 | enum sb1_error_t err; |
454 | if(!sb1_brute_force(sb_filename, NULL, sb_printf, &err, &key)) | 378 | if(!sb1_brute_force(sb_filename, NULL, sb_std_printf, &err, &key)) |
455 | { | 379 | { |
456 | color(OFF); | 380 | color(OFF); |
457 | printf("Brute force failed: %d\n", err); | 381 | printf("Brute force failed: %d\n", err); |
@@ -475,7 +399,7 @@ int main(int argc, char **argv) | |||
475 | } | 399 | } |
476 | 400 | ||
477 | enum sb1_error_t err; | 401 | enum sb1_error_t err; |
478 | struct sb1_file_t *file = sb1_read_file(sb_filename, NULL, sb_printf, &err); | 402 | struct sb1_file_t *file = sb1_read_file(sb_filename, NULL, sb_std_printf, &err); |
479 | if(file == NULL) | 403 | if(file == NULL) |
480 | { | 404 | { |
481 | color(OFF); | 405 | color(OFF); |
@@ -490,7 +414,7 @@ int main(int argc, char **argv) | |||
490 | { | 414 | { |
491 | color(GREY); | 415 | color(GREY); |
492 | printf("[Debug output]\n"); | 416 | printf("[Debug output]\n"); |
493 | sb1_dump(file, NULL, sb_printf); | 417 | sb1_dump(file, NULL, sb_std_printf); |
494 | } | 418 | } |
495 | if(loopback) | 419 | if(loopback) |
496 | sb1_write_file(file, loopback); | 420 | sb1_write_file(file, loopback); |
diff --git a/utils/imxtools/sbtools/xorcrypt.c b/utils/imxtools/sbtools/xorcrypt.c index 32f2b6b875..63a8232117 100644 --- a/utils/imxtools/sbtools/xorcrypt.c +++ b/utils/imxtools/sbtools/xorcrypt.c | |||
@@ -115,7 +115,7 @@ static uint32_t do_unround(union xorcrypt_key_t *key) | |||
115 | return 0; | 115 | return 0; |
116 | } | 116 | } |
117 | 117 | ||
118 | static void test_round(union xorcrypt_key_t keys[2]) | 118 | static void __attribute__((unused)) test_round(union xorcrypt_key_t keys[2]) |
119 | { | 119 | { |
120 | union xorcrypt_key_t save[2]; | 120 | union xorcrypt_key_t save[2]; |
121 | memcpy(save, keys, sizeof(save)); | 121 | memcpy(save, keys, sizeof(save)); |