diff options
| author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-01-26 16:50:50 +0000 |
|---|---|---|
| committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-01-26 18:24:50 +0000 |
| commit | 5b00e59614f584cc6dc440cc064097a2fb7321f7 (patch) | |
| tree | 2719e449a312351649f73c1cdf00322fe33beb2d /utils/imxtools | |
| parent | 75df5c2684ea146e2cdb923b2ef8f92309a1a3e1 (diff) | |
| download | rockbox-5b00e59614f584cc6dc440cc064097a2fb7321f7.zip rockbox-5b00e59614f584cc6dc440cc064097a2fb7321f7.tar.gz rockbox-5b00e59614f584cc6dc440cc064097a2fb7321f7.tar.bz2 rockbox-5b00e59614f584cc6dc440cc064097a2fb7321f7.tar.xz | |
imxtools/sbtools: fix file type detection
Change-Id: I872e98f5810df3ecc975e025385f9c5ca7b47a44
Diffstat (limited to 'utils/imxtools')
| -rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index c61650d..98bb2dc 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c @@ -267,6 +267,9 @@ 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)) @@ -283,12 +286,13 @@ enum sb_version_guess_t guess_sb_version(const char *filename) ret(SB_VERSION_UNK); if(hdr_size == 0x34) ret(SB_VERSION_1); - // check header size (v2) - if(fseek(f, 32, SEEK_SET)) + // check image size (v2) + uint32_t img_size; + if(fseek(f, 28, SEEK_SET)) ret(SB_VERSION_UNK); - if(fread(&hdr_size, 4, 1, f) != 1) + if(fread(&img_size, 4, 1, f) != 1) ret(SB_VERSION_UNK); - if(hdr_size == 0xc) + if(img_size * 16 == (uint32_t)file_size) ret(SB_VERSION_2); ret(SB_VERSION_UNK); #undef ret |