| 25 | } |
| 26 | |
| 27 | bool SdOsImageReader::Open() |
| 28 | { |
| 29 | if (!m_sd->OpenForReading()) |
| 30 | { |
| 31 | g_err.Set(stringformat("Could not open %s for reading: %s", m_sd->GetFriendlyName().c_str(), LastError().c_str())); |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | ByteVector buffer; |
| 36 | if (!m_sd->ReadData(0, m_sd->GetBlockSize(), buffer)) |
| 37 | { |
| 38 | g_err.Set(stringformat("Could not read from %s : %s", m_sd->GetFriendlyName().c_str(), LastError().c_str())); |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | if (memcmp(vectorptr(buffer), "HTC$WALLABY11", 13)==0) |
| 43 | { |
| 44 | m_baseoffset= 2*m_sd->GetBlockSize(); |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | if (memcmp(vectorptr(buffer), "HTC$WALLABY22", 13)==0) |
| 49 | { |
| 50 | m_baseoffset= 2*m_sd->GetBlockSize()+0x40000; |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | if (memcmp(vectorptr(buffer), "HTC$WALLABY", 11)==0) |
| 55 | { |
| 56 | g_err.Set(stringformat("%s contains an unsupported HTC sdimage format", m_sd->GetFriendlyName().c_str())); |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | if (memcmp(vectorptr(buffer), "HTC FLASH KEY", 13)==0) |
| 61 | { |
| 62 | if (!m_sd->ReadData(5*m_sd->GetBlockSize(), m_sd->GetBlockSize(), buffer)) |
| 63 | { |
| 64 | g_err.Set(stringformat("error reading from %s : %s", m_sd->GetFriendlyName().c_str(), LastError().c_str())); |
| 65 | return false; |
| 66 | } |
| 67 | if (memcmp(vectorptr(buffer), "HTC$WALLABY11", 13)==0) |
| 68 | { |
| 69 | m_baseoffset= 7*m_sd->GetBlockSize(); |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | if (memcmp(vectorptr(buffer), "HTC$WALLABY22", 13)==0) |
| 74 | { |
| 75 | m_baseoffset= 7*m_sd->GetBlockSize()+0x40000; |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | g_err.Set(stringformat("%s contains an unsupported HTC sdimage format", m_sd->GetFriendlyName().c_str())); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | g_err.Set(stringformat("%s contains does not contain an HTC sdimage card", m_sd->GetFriendlyName().c_str())); |
| 84 |
no test coverage detected