From 2f92d5555302a00a5a10154d8413235888d27c7f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 8 Jul 2016 20:49:53 +0200 Subject: mbn: Updated file parsing to newer file version to suppresss warning Note: the parsed data is not actually used. The personalization just involves replacing the last N bytes of the file with the blob data (of size N) returned by the signing server. However this at least suppresses a warning message and helps identifying newer format versions. --- src/mbn.c | 13 ++++++++++--- src/mbn.h | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/mbn.c b/src/mbn.c index a01e3cb..a4f514e 100644 --- a/src/mbn.c +++ b/src/mbn.c @@ -36,10 +36,17 @@ mbn_file* mbn_parse(unsigned char* data, unsigned int size) mbn->size = size; memcpy(mbn->data, data, size); /* FIXME: header parsing is not big endian safe */ - memcpy(&mbn->header, data, sizeof(mbn_header)); - mbn->parsed_size = mbn->header.data_size + sizeof(mbn_header); + if (memcmp(data, MBN_V2_MAGIC, MBN_V2_MAGIC_SIZE) == 0) { + mbn->version = 2; + memcpy(&mbn->header.v2, data, sizeof(mbn_header_v2)); + mbn->parsed_size = mbn->header.v2.data_size + sizeof(mbn_header_v2); + } else if (memcmp(data, MBN_V1_MAGIC, MBN_V1_MAGIC_SIZE) == 0) { + mbn->version = 1; + memcpy(&mbn->header.v1, data, sizeof(mbn_header_v1)); + mbn->parsed_size = mbn->header.v1.data_size + sizeof(mbn_header_v1); + } if (mbn->parsed_size != mbn->size) { - debug("WARNING: size mismatch when parsing MBN file.\n"); + info("WARNING: size mismatch when parsing MBN file. Continuing anyway.\n"); } return mbn; } diff --git a/src/mbn.h b/src/mbn.h index a42a45b..f8f138d 100644 --- a/src/mbn.h +++ b/src/mbn.h @@ -23,7 +23,10 @@ #include -struct _mbn_header { +#define MBN_V1_MAGIC "\x0A\x00\x00\x00" +#define MBN_V1_MAGIC_SIZE 4 + +struct _mbn_header_v1 { uint32_t type; // the signed .mbn files have 0xA as value. uint32_t unk_0x04; uint32_t unk_0x08; @@ -35,10 +38,40 @@ struct _mbn_header { uint32_t unk_0x20; uint32_t unk_0x24; } __attribute__((packed)); -typedef struct _mbn_header mbn_header; +typedef struct _mbn_header_v1 mbn_header_v1; + +#define MBN_V2_MAGIC "\xD1\xDC\x4B\x84\x34\x10\xD7\x73" +#define MBN_V2_MAGIC_SIZE 8 + +struct _mbn_header_v2 { + unsigned char magic1[8]; + uint32_t unk_0x08; + uint32_t unk_0x0c; // 0xFFFFFFFF + uint32_t unk_0x10; // 0xFFFFFFFF + uint32_t header_size; + uint32_t unk_0x18; + uint32_t data_size; // data_size = total_size - sizeof(mbn_header_v2) + uint32_t sig_offset; + uint32_t unk_0x24; + uint32_t unk_0x28; + uint32_t unk_0x2c; + uint32_t unk_0x30; + uint32_t unk_0x34; // 0x1 + uint32_t unk_0x38; // 0x1 + uint32_t unk_0x3c; // 0xFFFFFFFF + uint32_t unk_0x40; // 0xFFFFFFFF + uint32_t unk_0x44; // 0xFFFFFFFF + uint32_t unk_0x48; // 0xFFFFFFFF + uint32_t unk_0x4c; // 0xFFFFFFFF +} __attribute__((packed)); +typedef struct _mbn_header_v2 mbn_header_v2; typedef struct { - mbn_header header; + uint32_t version; + union { + mbn_header_v1 v1; + mbn_header_v2 v2; + } header; uint32_t parsed_size; uint32_t parsed_sig_offset; void* data; -- cgit v1.1-32-gdbae