diff options
author | Amaury Pouly <pamaury@rockbox.org> | 2011-04-17 22:30:09 +0000 |
---|---|---|
committer | Amaury Pouly <pamaury@rockbox.org> | 2011-04-17 22:30:09 +0000 |
commit | b2c59541b47e98fe69ab973ca4ab2688d70aac23 (patch) | |
tree | bb2384b6c844ce9f77ccc2227920a053b5ee33cd /utils/sbtools/sbtoelf.c | |
parent | e3fe3956f6c9c244ccbc57d1ddce7b2202b373f4 (diff) | |
download | rockbox-b2c59541b47e98fe69ab973ca4ab2688d70aac23.tar.gz rockbox-b2c59541b47e98fe69ab973ca4ab2688d70aac23.zip |
sbtoelf: fix to handle unencrypted files (minor tweak)
elftosb: properly generate sb file (encryption not implemented yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29742 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/sbtools/sbtoelf.c')
-rw-r--r-- | utils/sbtools/sbtoelf.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c index 54daf7bc1f..be719c6a5f 100644 --- a/utils/sbtools/sbtoelf.c +++ b/utils/sbtools/sbtoelf.c | |||
@@ -421,6 +421,14 @@ static void extract(unsigned long filesize) | |||
421 | printf(" Drive tag = "); | 421 | printf(" Drive tag = "); |
422 | color(YELLOW); | 422 | color(YELLOW); |
423 | printf("%x\n", sb_header->drive_tag); | 423 | printf("%x\n", sb_header->drive_tag); |
424 | color(GREEN); | ||
425 | printf(" First boot tag offset = "); | ||
426 | color(YELLOW); | ||
427 | printf("%x\n", sb_header->first_boot_tag_off); | ||
428 | color(GREEN); | ||
429 | printf(" First boot section ID = "); | ||
430 | color(YELLOW); | ||
431 | printf("0x%08x\n", sb_header->first_boot_sec_id); | ||
424 | 432 | ||
425 | /* encryption cbc-mac */ | 433 | /* encryption cbc-mac */ |
426 | key_array_t keys = NULL; /* array of 16-bytes keys */ | 434 | key_array_t keys = NULL; /* array of 16-bytes keys */ |
@@ -504,7 +512,7 @@ static void extract(unsigned long filesize) | |||
504 | int pos = sec_hdr->offset * BLOCK_SIZE; | 512 | int pos = sec_hdr->offset * BLOCK_SIZE; |
505 | int size = sec_hdr->size * BLOCK_SIZE; | 513 | int size = sec_hdr->size * BLOCK_SIZE; |
506 | int data_sec = !(sec_hdr->flags & SECTION_BOOTABLE); | 514 | int data_sec = !(sec_hdr->flags & SECTION_BOOTABLE); |
507 | int encrypted = !(sec_hdr->flags & SECTION_CLEARTEXT); | 515 | int encrypted = !(sec_hdr->flags & SECTION_CLEARTEXT) && sb_header->nr_keys > 0; |
508 | 516 | ||
509 | color(GREEN); | 517 | color(GREEN); |
510 | printf(" Section "); | 518 | printf(" Section "); |
@@ -547,9 +555,7 @@ static void extract(unsigned long filesize) | |||
547 | /* advanced raw mode */ | 555 | /* advanced raw mode */ |
548 | color(BLUE); | 556 | color(BLUE); |
549 | printf("Commands\n"); | 557 | printf("Commands\n"); |
550 | uint32_t offset = sizeof(struct sb_header_t) | 558 | uint32_t offset = sb_header->first_boot_tag_off * BLOCK_SIZE; |
551 | + sizeof(struct sb_section_header_t) * sb_header->nr_sections | ||
552 | + sizeof(struct sb_key_dictionary_entry_t) * sb_header->nr_keys; | ||
553 | byte iv[16]; | 559 | byte iv[16]; |
554 | memcpy(iv, g_buf, 16); | 560 | memcpy(iv, g_buf, 16); |
555 | const char *indent = " "; | 561 | const char *indent = " "; |
@@ -597,7 +603,7 @@ static void extract(unsigned long filesize) | |||
597 | int pos = offset; | 603 | int pos = offset; |
598 | int size = tag->len * BLOCK_SIZE; | 604 | int size = tag->len * BLOCK_SIZE; |
599 | int data_sec = !(tag->flags & SECTION_BOOTABLE); | 605 | int data_sec = !(tag->flags & SECTION_BOOTABLE); |
600 | int encrypted = !(tag->flags & SECTION_CLEARTEXT); | 606 | int encrypted = !(tag->flags & SECTION_CLEARTEXT) && sb_header->nr_keys > 0; |
601 | 607 | ||
602 | color(GREEN); | 608 | color(GREEN); |
603 | printf("%sSection ", indent); | 609 | printf("%sSection ", indent); |
@@ -653,19 +659,24 @@ static void extract(unsigned long filesize) | |||
653 | /* final signature */ | 659 | /* final signature */ |
654 | color(BLUE); | 660 | color(BLUE); |
655 | printf("Final signature:\n"); | 661 | printf("Final signature:\n"); |
656 | color(GREEN); | ||
657 | printf(" Encrypted signature:\n"); | ||
658 | color(YELLOW); | ||
659 | byte *encrypted_block = &g_buf[filesize - 32]; | ||
660 | printf(" "); | ||
661 | print_hex(encrypted_block, 16, true); | ||
662 | printf(" "); | ||
663 | print_hex(encrypted_block + 16, 16, true); | ||
664 | /* decrypt it */ | ||
665 | byte decrypted_block[32]; | 662 | byte decrypted_block[32]; |
666 | cbc_mac(encrypted_block, decrypted_block, 2, real_key, g_buf, NULL, 0); | 663 | if(sb_header->nr_keys > 0) |
664 | { | ||
665 | color(GREEN); | ||
666 | printf(" Encrypted SHA-1:\n"); | ||
667 | color(YELLOW); | ||
668 | byte *encrypted_block = &g_buf[filesize - 32]; | ||
669 | printf(" "); | ||
670 | print_hex(encrypted_block, 16, true); | ||
671 | printf(" "); | ||
672 | print_hex(encrypted_block + 16, 16, true); | ||
673 | /* decrypt it */ | ||
674 | cbc_mac(encrypted_block, decrypted_block, 2, real_key, g_buf, NULL, 0); | ||
675 | } | ||
676 | else | ||
677 | memcpy(decrypted_block, &g_buf[filesize - 32], 32); | ||
667 | color(GREEN); | 678 | color(GREEN); |
668 | printf(" Decrypted SHA-1:\n "); | 679 | printf(" File SHA-1:\n "); |
669 | color(YELLOW); | 680 | color(YELLOW); |
670 | print_hex(decrypted_block, 20, false); | 681 | print_hex(decrypted_block, 20, false); |
671 | /* check it */ | 682 | /* check it */ |