From 699c44cf1533ce5c1774f5856f6a648f8120f36e Mon Sep 17 00:00:00 2001 From: ksherlock Date: Wed, 9 Mar 2011 04:10:33 +0000 Subject: [PATCH] check for SDK with binary II header. git-svn-id: https://profuse.googlecode.com/svn/branches/profuse_interim@379 aa027e90-d47c-11dd-86d7-074df07e0730 --- Device/SDKImage.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Device/SDKImage.cpp b/Device/SDKImage.cpp index 58c7772..4667589 100644 --- a/Device/SDKImage.cpp +++ b/Device/SDKImage.cpp @@ -208,16 +208,29 @@ BlockDevicePointer SDKImage::Open(const char *name) bool SDKImage::Validate(MappedFile * f, const std::nothrow_t &) { + // NuFile, alternating ASCII. static const char IdentityCheck[6] = { 0x4E, 0xF5, 0x46, 0xE9, 0x6C, 0xE5 }; + static const char BXYIdentityCheck[3] = { 0x0A, 0x47, 0x4C }; - if (f->length() < sizeof(IdentityCheck)) - return false; + uint8_t *address = (uint8_t *)f->address(); + size_t length = f->length(); - if (std::memcmp(f->address(), IdentityCheck, sizeof(IdentityCheck))) - return false; + // check for a BXY header + if (length >= 128 + && std::memcmp(address, BXYIdentityCheck, sizeof(BXYIdentityCheck)) == 0) + { + length -= 128; + address += 128; + } - return true; + + if (length > sizeof(IdentityCheck) + && std::memcmp(address, IdentityCheck, sizeof(IdentityCheck)) == 0) + return true; + + + return false; }