ResourceFile: Handle version info in resource in other endianness than host.

Fixes #12779.

Signed-off-by: Augustin Cavalier <[email protected]>
Includes some minor whitespace fixes by me.
This commit is contained in:
Mark Hellegers
2016-05-14 14:52:47 -04:00
committed by Augustin Cavalier
parent 49448867f5
commit 213ddbf656
+20 -3
View File
@@ -67,6 +67,9 @@ const char* kFileTypeNames[] = {
#define DBG(x) #define DBG(x)
#define OUT printf #define OUT printf
#define B_VERSION_INFO_TYPE 'APPV'
static const uint32 kVersionInfoIntCount = 5;
// #pragma mark - helper functions/classes // #pragma mark - helper functions/classes
@@ -323,8 +326,15 @@ ResourceFile::ReadResource(ResourceItem& resource, bool force)
} }
if (error == B_OK) { if (error == B_OK) {
// convert the data, if necessary // convert the data, if necessary
if (!fHostEndianess) if (!fHostEndianess) {
swap_data(resource.Type(), data, size, B_SWAP_ALWAYS); if (resource.Type() == B_VERSION_INFO_TYPE) {
// Version info contains integers that need to be swapped
swap_data(B_UINT32_TYPE, data,
kVersionInfoIntCount * sizeof(uint32),
B_SWAP_ALWAYS);
} else
swap_data(resource.Type(), data, size, B_SWAP_ALWAYS);
}
resource.SetLoaded(true); resource.SetLoaded(true);
resource.SetModified(false); resource.SetModified(false);
} }
@@ -1200,7 +1210,14 @@ ResourceFile::_WriteResources(ResourcesContainer& container)
// swap data, if necessary // swap data, if necessary
if (!fHostEndianess) { if (!fHostEndianess) {
memcpy(data, itemData, itemSize); memcpy(data, itemData, itemSize);
swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS); if (item->Type() == B_VERSION_INFO_TYPE) {
// Version info contains integers
// that need to be swapped
swap_data(B_UINT32_TYPE, data,
kVersionInfoIntCount * sizeof(uint32),
B_SWAP_ALWAYS);
} else
swap_data(item->Type(), data, itemSize, B_SWAP_ALWAYS);
itemData = data; itemData = data;
} }
write_exactly(fFile, itemOffset, itemData, itemSize, write_exactly(fFile, itemOffset, itemData, itemSize,