From cbbde3f5e1ba1973ea1cb88f490c039885bdc835 Mon Sep 17 00:00:00 2001
From: Mark Hellegers <mark@firedisk.net>
Date: Sat, 14 May 2016 16:33:38 +0200
Subject: [PATCH] #12779: Handle version info in resource in other endianness
than host
---
src/kits/storage/ResourceFile.cpp | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/kits/storage/ResourceFile.cpp b/src/kits/storage/ResourceFile.cpp
index 907ee87..fb8c265 100644
a
|
b
|
const char* kFileTypeNames[] = {
|
67 | 67 | #define DBG(x) |
68 | 68 | #define OUT printf |
69 | 69 | |
| 70 | #define B_VERSION_INFO_TYPE 'APPV' |
| 71 | |
| 72 | static const uint32 kVersionInfoIntCount = 5; |
70 | 73 | |
71 | 74 | // #pragma mark - helper functions/classes |
72 | 75 | |
… |
… |
ResourceFile::ReadResource(ResourceItem& resource, bool force)
|
323 | 326 | } |
324 | 327 | if (error == B_OK) { |
325 | 328 | // convert the data, if necessary |
326 | | if (!fHostEndianess) |
327 | | swap_data(resource.Type(), data, size, B_SWAP_ALWAYS); |
| 329 | if (!fHostEndianess) { |
| 330 | if (resource.Type() == B_VERSION_INFO_TYPE) { |
| 331 | // Version info contains integers that need to be swapped |
| 332 | swap_data(B_UINT32_TYPE, data, |
| 333 | kVersionInfoIntCount * sizeof(uint32), |
| 334 | B_SWAP_ALWAYS); |
| 335 | } |
| 336 | else |
| 337 | swap_data(resource.Type(), data, size, B_SWAP_ALWAYS); |
| 338 | } |
328 | 339 | resource.SetLoaded(true); |
329 | 340 | resource.SetModified(false); |
330 | 341 | } |
… |
… |
ResourceFile::_WriteResources(ResourcesContainer& container)
|
1200 | 1211 | // swap data, if necessary |
1201 | 1212 | if (!fHostEndianess) { |
1202 | 1213 | memcpy(data, itemData, itemSize); |
1203 | | swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS); |
| 1214 | if (item->Type() == B_VERSION_INFO_TYPE) { |
| 1215 | // Version info contains integers |
| 1216 | // that need to be swapped |
| 1217 | swap_data(B_UINT32_TYPE, data, |
| 1218 | kVersionInfoIntCount * sizeof(uint32), |
| 1219 | B_SWAP_ALWAYS); |
| 1220 | } |
| 1221 | else |
| 1222 | swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS); |
1204 | 1223 | itemData = data; |
1205 | 1224 | } |
1206 | 1225 | write_exactly(fFile, itemOffset, itemData, itemSize, |