diff options
Diffstat (limited to 'utils/imxtools/sbtools')
-rw-r--r-- | utils/imxtools/sbtools/misc.c | 1 | ||||
-rw-r--r-- | utils/imxtools/sbtools/misc.h | 1 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sb.c | 31 | ||||
-rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 11 |
4 files changed, 37 insertions, 7 deletions
diff --git a/utils/imxtools/sbtools/misc.c b/utils/imxtools/sbtools/misc.c index fce71ae0cd..ec9b8c2a27 100644 --- a/utils/imxtools/sbtools/misc.c +++ b/utils/imxtools/sbtools/misc.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "misc.h" | 25 | #include "misc.h" |
26 | 26 | ||
27 | bool g_debug = false; | 27 | bool g_debug = false; |
28 | bool g_force = false; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Misc | 31 | * Misc |
diff --git a/utils/imxtools/sbtools/misc.h b/utils/imxtools/sbtools/misc.h index 4df9bbe957..f5bba9164f 100644 --- a/utils/imxtools/sbtools/misc.h +++ b/utils/imxtools/sbtools/misc.h | |||
@@ -33,6 +33,7 @@ | |||
33 | #define ROUND_UP(val, round) ((((val) + (round) - 1) / (round)) * (round)) | 33 | #define ROUND_UP(val, round) ((((val) + (round) - 1) / (round)) * (round)) |
34 | 34 | ||
35 | extern bool g_debug; | 35 | extern bool g_debug; |
36 | extern bool g_force; | ||
36 | 37 | ||
37 | typedef struct crypto_key_t *key_array_t; | 38 | typedef struct crypto_key_t *key_array_t; |
38 | int g_nr_keys; | 39 | int g_nr_keys; |
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c index 9b97509491..78f98b5985 100644 --- a/utils/imxtools/sbtools/sb.c +++ b/utils/imxtools/sbtools/sb.c | |||
@@ -503,7 +503,7 @@ static struct sb_section_t *read_section(bool data_sec, uint32_t id, byte *buf, | |||
503 | printf(OFF, "%s", indent); | 503 | printf(OFF, "%s", indent); |
504 | uint8_t checksum = instruction_checksum(hdr); | 504 | uint8_t checksum = instruction_checksum(hdr); |
505 | if(checksum != hdr->checksum) | 505 | if(checksum != hdr->checksum) |
506 | fatal(SB_CHECKSUM_ERROR, "Bad instruction checksum"); | 506 | fatal(SB_CHECKSUM_ERROR, "Bad instruction checksum\n"); |
507 | if(hdr->flags != 0) | 507 | if(hdr->flags != 0) |
508 | { | 508 | { |
509 | printf(GREY, "["); | 509 | printf(GREY, "["); |
@@ -788,7 +788,8 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi | |||
788 | printf(BLUE, "Encryption keys\n"); | 788 | printf(BLUE, "Encryption keys\n"); |
789 | for(int i = 0; i < g_nr_keys; i++) | 789 | for(int i = 0; i < g_nr_keys; i++) |
790 | { | 790 | { |
791 | printf(RED, " Key %d: ", i); | 791 | printf(RED, " Key %d\n", i), |
792 | printf(GREEN, " Key: "); | ||
792 | printf(YELLOW, ""); | 793 | printf(YELLOW, ""); |
793 | print_key(&g_key_array[i], true); | 794 | print_key(&g_key_array[i], true); |
794 | printf(GREEN, " CBC-MAC: "); | 795 | printf(GREEN, " CBC-MAC: "); |
@@ -859,7 +860,12 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi | |||
859 | free(cbcmacs); | 860 | free(cbcmacs); |
860 | 861 | ||
861 | if(!valid_key) | 862 | if(!valid_key) |
862 | fatal(SB_NO_VALID_KEY, "No valid key found\n"); | 863 | { |
864 | if(g_force) | ||
865 | printf(GREY, " No valid key found\n"); | ||
866 | else | ||
867 | fatal(SB_NO_VALID_KEY, "No valid key found\n"); | ||
868 | } | ||
863 | 869 | ||
864 | if(getenv("SB_REAL_KEY") != 0) | 870 | if(getenv("SB_REAL_KEY") != 0) |
865 | { | 871 | { |
@@ -868,6 +874,12 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi | |||
868 | if(!parse_key(&env, &k) || *env) | 874 | if(!parse_key(&env, &k) || *env) |
869 | fatal(SB_ERROR, "Invalid SB_REAL_KEY\n"); | 875 | fatal(SB_ERROR, "Invalid SB_REAL_KEY\n"); |
870 | memcpy(real_key, k.u.key, 16); | 876 | memcpy(real_key, k.u.key, 16); |
877 | /* assume the key is valid */ | ||
878 | if(valid_key) | ||
879 | printf(GREY, " Overriding real key\n"); | ||
880 | else | ||
881 | printf(GREY, " Assuming real key is ok\n"); | ||
882 | valid_key = true; | ||
871 | } | 883 | } |
872 | 884 | ||
873 | printf(RED, " Summary:\n"); | 885 | printf(RED, " Summary:\n"); |
@@ -916,6 +928,13 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi | |||
916 | if(encrypted) | 928 | if(encrypted) |
917 | printf(RED, " (Encrypted)"); | 929 | printf(RED, " (Encrypted)"); |
918 | printf(OFF, "\n"); | 930 | printf(OFF, "\n"); |
931 | |||
932 | /* skip it if we cannot decrypt it */ | ||
933 | if(encrypted && !valid_key) | ||
934 | { | ||
935 | printf(GREY, " Skipping section content (no valid key)\n"); | ||
936 | continue; | ||
937 | } | ||
919 | 938 | ||
920 | /* save it */ | 939 | /* save it */ |
921 | byte *sec = xmalloc(size); | 940 | byte *sec = xmalloc(size); |
@@ -939,7 +958,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi | |||
939 | free(sec); | 958 | free(sec); |
940 | } | 959 | } |
941 | } | 960 | } |
942 | else | 961 | else if(valid_key) |
943 | { | 962 | { |
944 | /* advanced raw mode */ | 963 | /* advanced raw mode */ |
945 | printf(BLUE, "Commands\n"); | 964 | printf(BLUE, "Commands\n"); |
@@ -1041,6 +1060,10 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi | |||
1041 | } | 1060 | } |
1042 | } | 1061 | } |
1043 | } | 1062 | } |
1063 | else | ||
1064 | { | ||
1065 | printf(GREY, "Cannot read content in raw mode without a valid key\n"); | ||
1066 | } | ||
1044 | 1067 | ||
1045 | /* final signature */ | 1068 | /* final signature */ |
1046 | printf(BLUE, "Final signature:\n"); | 1069 | printf(BLUE, "Final signature:\n"); |
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index c1d1e9aa34..0170ea1836 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c | |||
@@ -169,6 +169,7 @@ static void usage(void) | |||
169 | printf(" -a/--add-key <key>\tAdd single key (hex or usbotp)\n"); | 169 | printf(" -a/--add-key <key>\tAdd single key (hex or usbotp)\n"); |
170 | printf(" -n/--no-color\tDisable output colors\n"); | 170 | printf(" -n/--no-color\tDisable output colors\n"); |
171 | printf(" -l/--loopback <file>\tProduce sb file out of extracted description*\n"); | 171 | printf(" -l/--loopback <file>\tProduce sb file out of extracted description*\n"); |
172 | printf(" -f/--force\tForce reading even without a key*\n"); | ||
172 | printf("Options marked with a * are for debug purpose only\n"); | 173 | printf("Options marked with a * are for debug purpose only\n"); |
173 | exit(1); | 174 | exit(1); |
174 | } | 175 | } |
@@ -204,10 +205,11 @@ int main(int argc, char **argv) | |||
204 | {"add-key", required_argument, 0, 'a'}, | 205 | {"add-key", required_argument, 0, 'a'}, |
205 | {"no-color", no_argument, 0, 'n'}, | 206 | {"no-color", no_argument, 0, 'n'}, |
206 | {"loopback", required_argument, 0, 'l'}, | 207 | {"loopback", required_argument, 0, 'l'}, |
208 | {"force", no_argument, 0, 'f' }, | ||
207 | {0, 0, 0, 0} | 209 | {0, 0, 0, 0} |
208 | }; | 210 | }; |
209 | 211 | ||
210 | int c = getopt_long(argc, argv, "?do:k:zra:nl:", long_options, NULL); | 212 | int c = getopt_long(argc, argv, "?do:k:zra:nl:f", long_options, NULL); |
211 | if(c == -1) | 213 | if(c == -1) |
212 | break; | 214 | break; |
213 | switch(c) | 215 | switch(c) |
@@ -231,6 +233,9 @@ int main(int argc, char **argv) | |||
231 | case 'o': | 233 | case 'o': |
232 | g_out_prefix = optarg; | 234 | g_out_prefix = optarg; |
233 | break; | 235 | break; |
236 | case 'f': | ||
237 | g_force = true; | ||
238 | break; | ||
234 | case 'k': | 239 | case 'k': |
235 | { | 240 | { |
236 | if(!add_keys_from_file(optarg)) | 241 | if(!add_keys_from_file(optarg)) |
@@ -250,9 +255,9 @@ int main(int argc, char **argv) | |||
250 | struct crypto_key_t key; | 255 | struct crypto_key_t key; |
251 | char *s = optarg; | 256 | char *s = optarg; |
252 | if(!parse_key(&s, &key)) | 257 | if(!parse_key(&s, &key)) |
253 | bug("Invalid key specified as argument"); | 258 | bug("Invalid key specified as argument\n"); |
254 | if(*s != 0) | 259 | if(*s != 0) |
255 | bug("Trailing characters after key specified as argument"); | 260 | bug("Trailing characters after key specified as argument\n"); |
256 | add_keys(&key, 1); | 261 | add_keys(&key, 1); |
257 | break; | 262 | break; |
258 | } | 263 | } |