summaryrefslogtreecommitdiffstats
path: root/utils/imxtools/sbtools
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-01-29 20:46:28 +0000
committerAmaury Pouly <amaury.pouly@gmail.com>2013-01-29 20:46:28 +0000
commit6d5b1b2448043f34ba0bbafce7ea1768cc5a79a7 (patch)
tree7f12edbf2619132684baf3aa5360e54454d495d6 /utils/imxtools/sbtools
parent42a725f7ecd1e6779d24f1a66eb13652de467de9 (diff)
downloadrockbox-6d5b1b2448043f34ba0bbafce7ea1768cc5a79a7.tar.gz
rockbox-6d5b1b2448043f34ba0bbafce7ea1768cc5a79a7.tar.bz2
rockbox-6d5b1b2448043f34ba0bbafce7ea1768cc5a79a7.zip
imxtools/sbtoelf: add more robust version guess
Change-Id: I41ce1005d997cf35153e085b19294bb7d418e968
Diffstat (limited to 'utils/imxtools/sbtools')
-rw-r--r--utils/imxtools/sbtools/sbtoelf.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c
index 98bb2dcc45..540d55acc1 100644
--- a/utils/imxtools/sbtools/sbtoelf.c
+++ b/utils/imxtools/sbtools/sbtoelf.c
@@ -267,9 +267,6 @@ enum sb_version_guess_t guess_sb_version(const char *filename)
FILE *f = fopen(filename, "rb");
if(f == NULL)
bugp("Cannot open file for reading\n");
- fseek(f, 0, SEEK_END);
- long file_size = ftell(f);
- fseek(f, 0, SEEK_SET);
// check signature
uint8_t sig[4];
if(fseek(f, 20, SEEK_SET))
@@ -286,13 +283,20 @@ enum sb_version_guess_t guess_sb_version(const char *filename)
ret(SB_VERSION_UNK);
if(hdr_size == 0x34)
ret(SB_VERSION_1);
- // check image size (v2)
- uint32_t img_size;
- if(fseek(f, 28, SEEK_SET))
+ // check header params relationship
+ struct
+ {
+ uint16_t nr_keys; /* Number of encryption keys */
+ uint16_t key_dict_off; /* Offset to key dictionary (in blocks) */
+ uint16_t header_size; /* In blocks */
+ uint16_t nr_sections; /* Number of sections */
+ uint16_t sec_hdr_size; /* Section header size (in blocks) */
+ } __attribute__((packed)) u;
+ if(fseek(f, 0x28, SEEK_SET))
ret(SB_VERSION_UNK);
- if(fread(&img_size, 4, 1, f) != 1)
+ if(fread(&u, sizeof(u), 1, f) != 1)
ret(SB_VERSION_UNK);
- if(img_size * 16 == (uint32_t)file_size)
+ if(u.sec_hdr_size == 1 && u.header_size == 6 && u.key_dict_off == u.header_size + u.nr_sections)
ret(SB_VERSION_2);
ret(SB_VERSION_UNK);
#undef ret