this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreServices: Fix Carbon resource file parsing

+27 -10
+27 -10
src/frameworks/CoreServices/ResourcesImpl.cpp
··· 135 135 dataBacking = std::move(that.dataBacking); 136 136 attributes = that.attributes; 137 137 data = that.data; 138 + parent = that.parent; 138 139 that.data = nullptr; 139 140 } 140 141 ··· 179 180 180 181 #ifdef __LITTLE_ENDIAN__ 181 182 # define SWAP(x) x = _bswap(x) 183 + # define SWAP3(x) x = _bswap24(x) 182 184 183 185 static inline uint16_t _bswap(uint16_t v) { return __builtin_bswap16(v); } 184 186 static inline int16_t _bswap(int16_t v) { return __builtin_bswap16(v); } 185 187 static inline uint32_t _bswap(uint32_t v) { return __builtin_bswap32(v); } 188 + 189 + static inline uint32_t _bswap24(uint32_t v) 190 + { 191 + uint32_t rv = (v >> 16) & 0xff; 192 + rv |= v & 0xff00; 193 + rv |= (v << 16) & 0xff0000; 194 + return rv; 195 + } 186 196 187 197 #else 188 198 # define SWAP(x) 199 + # define SWAP3(x) 189 200 #endif 190 201 191 202 void Resources::loadResources(const uint8_t* mem, size_t length) ··· 219 230 220 231 m_attributes = resourceMapHeader.attributes; 221 232 222 - const ResourceType* t = reinterpret_cast<const ResourceType*>(mem + header.resourceMapOffset + resourceMapHeader.typeListOffset); 233 + // NOTE: +2 here is not documented, but is needed! 234 + const ResourceType* t = reinterpret_cast<const ResourceType*>(mem + header.resourceMapOffset + resourceMapHeader.typeListOffset + 2); 223 235 for (int i = 0; i <= resourceMapHeader.numOfTypesMinusOne; i++, t++) 224 236 { 225 237 ResourceType type = *t; ··· 229 241 SWAP(type.referenceListOffset); 230 242 231 243 const ReferenceListItem* rli = reinterpret_cast<const ReferenceListItem*>( 232 - reinterpret_cast<const uint8_t*>(t) + type.referenceListOffset 244 + mem + header.resourceMapOffset + resourceMapHeader.typeListOffset + type.referenceListOffset 233 245 ); 234 246 235 247 ResourceTypeData resourceTypeData; ··· 242 254 243 255 SWAP(refListItem.resourceID); 244 256 SWAP(refListItem.resourceNameListOffset); 245 - SWAP(refListItem.resourceDataOffset); 257 + SWAP3(refListItem.resourceDataOffset); 246 258 247 - const char* pascalStringName = reinterpret_cast<const char*>(mem + header.resourceMapOffset + resourceMapHeader.nameListOffset + refListItem.resourceNameListOffset); 259 + if (refListItem.resourceNameListOffset != 0xffff) 260 + { 261 + const char* pascalStringName = reinterpret_cast<const char*>(mem + header.resourceMapOffset + resourceMapHeader.nameListOffset + refListItem.resourceNameListOffset); 262 + res.name.assign(pascalStringName+1, *pascalStringName); 263 + } 248 264 249 - const uint8_t* dataHeader = mem + header.resourceDataOffset + refListItem.resourceDataOffset; 250 - uint32_t dataLength = *reinterpret_cast<const uint32_t*>(dataHeader); 251 - 252 - SWAP(dataLength); 265 + if (refListItem.resourceDataOffset != 0xffff) 266 + { 267 + const uint8_t* dataHeader = mem + header.resourceDataOffset + refListItem.resourceDataOffset; 268 + uint32_t dataLength = *reinterpret_cast<const uint32_t*>(dataHeader); 253 269 254 - res.name.assign(pascalStringName+1, *pascalStringName); 270 + SWAP(dataLength); 255 271 256 - res.dataBacking.assign(dataHeader + 4, dataHeader + 4 + dataLength); 272 + res.dataBacking.assign(dataHeader + 4, dataHeader + 4 + dataLength); 273 + } 257 274 258 275 res.id = refListItem.resourceID; 259 276 res.attributes = refListItem.attributes;