summaryrefslogtreecommitdiff
path: root/utils/imxtools/sbtools/sb.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-06-27 14:50:39 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-06-27 14:55:58 +0200
commit7c9e7ec707b9aa9e40c8e7ebdbbf1138cef85bb1 (patch)
tree3510851ae8276a11aead54702cf3cc245e787ec3 /utils/imxtools/sbtools/sb.c
parentfa17cb904c270e8227c0446bee4b51789eb5bb8c (diff)
downloadrockbox-7c9e7ec707b9aa9e40c8e7ebdbbf1138cef85bb1.zip
rockbox-7c9e7ec707b9aa9e40c8e7ebdbbf1138cef85bb1.tar.gz
rockbox-7c9e7ec707b9aa9e40c8e7ebdbbf1138cef85bb1.tar.bz2
rockbox-7c9e7ec707b9aa9e40c8e7ebdbbf1138cef85bb1.tar.xz
sbtools: add option to force sb dump
In the case of encrypted SB files without any key match, it is still possible to dump the section headers. The force option allows one to do so. It also allows to dump unencrypted sections of encrypted files if there are some. Change-Id: I36280230679ac5903f9c451c68c276f5c6959536
Diffstat (limited to 'utils/imxtools/sbtools/sb.c')
-rw-r--r--utils/imxtools/sbtools/sb.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/utils/imxtools/sbtools/sb.c b/utils/imxtools/sbtools/sb.c
index 9b97509..78f98b5 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,
printf(OFF, "%s", indent);
uint8_t checksum = instruction_checksum(hdr);
if(checksum != hdr->checksum)
- fatal(SB_CHECKSUM_ERROR, "Bad instruction checksum");
+ fatal(SB_CHECKSUM_ERROR, "Bad instruction checksum\n");
if(hdr->flags != 0)
{
printf(GREY, "[");
@@ -788,7 +788,8 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
printf(BLUE, "Encryption keys\n");
for(int i = 0; i < g_nr_keys; i++)
{
- printf(RED, " Key %d: ", i);
+ printf(RED, " Key %d\n", i),
+ printf(GREEN, " Key: ");
printf(YELLOW, "");
print_key(&g_key_array[i], true);
printf(GREEN, " CBC-MAC: ");
@@ -859,7 +860,12 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
free(cbcmacs);
if(!valid_key)
- fatal(SB_NO_VALID_KEY, "No valid key found\n");
+ {
+ if(g_force)
+ printf(GREY, " No valid key found\n");
+ else
+ fatal(SB_NO_VALID_KEY, "No valid key found\n");
+ }
if(getenv("SB_REAL_KEY") != 0)
{
@@ -868,6 +874,12 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
if(!parse_key(&env, &k) || *env)
fatal(SB_ERROR, "Invalid SB_REAL_KEY\n");
memcpy(real_key, k.u.key, 16);
+ /* assume the key is valid */
+ if(valid_key)
+ printf(GREY, " Overriding real key\n");
+ else
+ printf(GREY, " Assuming real key is ok\n");
+ valid_key = true;
}
printf(RED, " Summary:\n");
@@ -916,6 +928,13 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
if(encrypted)
printf(RED, " (Encrypted)");
printf(OFF, "\n");
+
+ /* skip it if we cannot decrypt it */
+ if(encrypted && !valid_key)
+ {
+ printf(GREY, " Skipping section content (no valid key)\n");
+ continue;
+ }
/* save it */
byte *sec = xmalloc(size);
@@ -939,7 +958,7 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
free(sec);
}
}
- else
+ else if(valid_key)
{
/* advanced raw mode */
printf(BLUE, "Commands\n");
@@ -1041,6 +1060,10 @@ struct sb_file_t *sb_read_memory(void *_buf, size_t filesize, bool raw_mode, voi
}
}
}
+ else
+ {
+ printf(GREY, "Cannot read content in raw mode without a valid key\n");
+ }
/* final signature */
printf(BLUE, "Final signature:\n");