From d3ed58a7c930f54288037be26894a38550ec787e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 25 Nov 2009 17:14:29 +0000 Subject: [PATCH] Added ELF64 support to BResources. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34250 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/storage/Elf.h | 83 +++++------- headers/private/storage/ElfX.h | 68 ++++++++++ headers/private/storage/ResourceFile.h | 44 ++++-- src/kits/storage/ResourceFile.cpp | 179 +++++++++++++++---------- 4 files changed, 247 insertions(+), 127 deletions(-) create mode 100644 headers/private/storage/ElfX.h diff --git a/headers/private/storage/Elf.h b/headers/private/storage/Elf.h index f4fb8ab326..979b98ae5d 100644 --- a/headers/private/storage/Elf.h +++ b/headers/private/storage/Elf.h @@ -1,14 +1,30 @@ -// Elf.h - +/* + * Copyright 2002-2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ #ifndef _ELF_H #define _ELF_H + +#include + + // types typedef uint32 Elf32_Addr; -typedef uint16 Elf32_Half; typedef uint32 Elf32_Off; +typedef uint16 Elf32_Half; typedef int32 Elf32_Sword; typedef uint32 Elf32_Word; +typedef uint32 Elf32_Xword; +typedef int32 Elf32_Sxword; + +typedef uint64 Elf64_Addr; +typedef uint64 Elf64_Off; +typedef uint16 Elf64_Half; +typedef int32 Elf64_Sword; +typedef uint32 Elf64_Word; +typedef uint64 Elf64_Xword; +typedef int64 Elf64_Sxword; // e_ident indices #define EI_MAG0 0 @@ -21,23 +37,9 @@ typedef uint32 Elf32_Word; #define EI_PAD 7 #define EI_NIDENT 16 -// object file header -typedef struct { - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; +// e_ident EI_VERSION values +#define EV_NONE 0 +#define EV_CURRENT 1 // e_ident EI_CLASS and EI_DATA values #define ELFCLASSNONE 0 @@ -47,18 +49,6 @@ typedef struct { #define ELFDATA2LSB 1 #define ELFDATA2MSB 2 -// program header -typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - // p_type #define PT_NULL 0 #define PT_LOAD 1 @@ -70,20 +60,6 @@ typedef struct { #define PT_LOPROC 0x70000000 #define PT_HIPROC 0x7fffffff -// section header -typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - // sh_type values #define SHT_NULL 0 #define SHT_PROGBITS 1 @@ -102,6 +78,17 @@ typedef struct { #define SHT_LOUSER 0x80000000 #define SHT_HIUSER 0xffffffff +// 32 bit definitions +#undef _ELFX_BITS +#define _ELFX_BITS 32 +#include + +// 64 bit definitions +#undef _ELFX_BITS +#define _ELFX_BITS 64 +#include + +#undef _ELFX_BITS + + #endif // _ELF_H - - diff --git a/headers/private/storage/ElfX.h b/headers/private/storage/ElfX.h new file mode 100644 index 0000000000..a588ad0aaf --- /dev/null +++ b/headers/private/storage/ElfX.h @@ -0,0 +1,68 @@ +/* + * Copyright 2002-2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +// No header guard: The file is included twice by and must not be +// included elsewhere. The _ELFX_BITS macro must be define before inclusion. + + +#undef ElfX + +#if _ELFX_BITS == 32 +# define ElfX(x) Elf32_##x +#elif _ELFX_BITS == 64 +# define ElfX(x) Elf64_##x +#endif + + +// object file header +typedef struct { + unsigned char e_ident[EI_NIDENT]; + ElfX(Half) e_type; + ElfX(Half) e_machine; + ElfX(Word) e_version; + ElfX(Addr) e_entry; + ElfX(Off) e_phoff; + ElfX(Off) e_shoff; + ElfX(Word) e_flags; + ElfX(Half) e_ehsize; + ElfX(Half) e_phentsize; + ElfX(Half) e_phnum; + ElfX(Half) e_shentsize; + ElfX(Half) e_shnum; + ElfX(Half) e_shstrndx; +} ElfX(Ehdr); + +// program header +typedef struct { + ElfX(Word) p_type; +#if _ELFX_BITS == 64 + ElfX(Word) p_flags; +#endif + ElfX(Off) p_offset; + ElfX(Addr) p_vaddr; + ElfX(Addr) p_paddr; + ElfX(Xword) p_filesz; + ElfX(Xword) p_memsz; +#if _ELFX_BITS == 32 + ElfX(Word) p_flags; +#endif + ElfX(Xword) p_align; +} ElfX(Phdr); + +// section header +typedef struct { + ElfX(Word) sh_name; + ElfX(Word) sh_type; + ElfX(Xword) sh_flags; + ElfX(Addr) sh_addr; + ElfX(Off) sh_offset; + ElfX(Xword) sh_size; + ElfX(Word) sh_link; + ElfX(Word) sh_info; + ElfX(Xword) sh_addralign; + ElfX(Xword) sh_entsize; +} ElfX(Shdr); + +#undef ElfX diff --git a/headers/private/storage/ResourceFile.h b/headers/private/storage/ResourceFile.h index ddc53381af..0f83cf96a1 100644 --- a/headers/private/storage/ResourceFile.h +++ b/headers/private/storage/ResourceFile.h @@ -72,7 +72,13 @@ public: private: void _InitFile(BFile& file, bool clobber); + void _InitELFFile(BFile& file); + + template + void _InitELFXFile(BFile& file, uint64 fileSize); + void _InitPEFFile(BFile& file, const PEFContainerHeader& pefHeader); void _ReadHeader(resource_parse_info& parseInfo); @@ -92,10 +98,12 @@ private: status_t _WriteResources(ResourcesContainer& container); status_t _MakeEmptyResourceFile(); - inline int16 _GetInt16(int16 value); - inline uint16 _GetUInt16(uint16 value); - inline int32 _GetInt32(int32 value); - inline uint32 _GetUInt32(uint32 value); + inline int16 _GetInt(int16 value) const; + inline uint16 _GetInt(uint16 value) const; + inline int32 _GetInt(int32 value) const; + inline uint32 _GetInt(uint32 value) const; + inline int64 _GetInt(int64 value) const; + inline uint64 _GetInt(uint64 value) const; private: OffsetFile fFile; @@ -106,30 +114,44 @@ private: inline int16 -ResourceFile::_GetInt16(int16 value) +ResourceFile::_GetInt(int16 value) const { - return fHostEndianess ? value : B_SWAP_INT16(value); + return fHostEndianess ? value : (int16)B_SWAP_INT16((uint16)value); } inline uint16 -ResourceFile::_GetUInt16(uint16 value) +ResourceFile::_GetInt(uint16 value) const { return fHostEndianess ? value : B_SWAP_INT16(value); } inline int32 -ResourceFile::_GetInt32(int32 value) +ResourceFile::_GetInt(int32 value) const +{ + return fHostEndianess ? value : (int32)B_SWAP_INT32((uint32)value); +} + + +inline uint32 +ResourceFile::_GetInt(uint32 value) const { return fHostEndianess ? value : B_SWAP_INT32(value); } -inline uint32 -ResourceFile::_GetUInt32(uint32 value) +inline int64 +ResourceFile::_GetInt(int64 value) const { - return fHostEndianess ? value : B_SWAP_INT32(value); + return fHostEndianess ? value : (int64)B_SWAP_INT64((uint64)value); +} + + +inline uint64 +ResourceFile::_GetInt(uint64 value) const +{ + return fHostEndianess ? value : B_SWAP_INT64(value); } diff --git a/src/kits/storage/ResourceFile.cpp b/src/kits/storage/ResourceFile.cpp index 356d962339..45cab6a31c 100644 --- a/src/kits/storage/ResourceFile.cpp +++ b/src/kits/storage/ResourceFile.cpp @@ -32,7 +32,8 @@ namespace Storage { // ELF defs -static const uint32 kMaxELFHeaderSize = sizeof(Elf32_Ehdr) + 32; +static const uint32 kMaxELFHeaderSize + = std::max(sizeof(Elf32_Ehdr), sizeof(Elf64_Ehdr)) + 32; static const char kELFFileMagic[4] = { 0x7f, 'E', 'L', 'F' }; // sanity bounds @@ -394,7 +395,7 @@ ResourceFile::_InitFile(BFile& file, bool clobber) } else if (!memcmp(magic, kPEFFileMagic1, 4)) { PEFContainerHeader pefHeader; read_exactly(file, 0, &pefHeader, kPEFContainerHeaderSize, - "Failed to read PEF container header."); + "Failed to read PEF container header."); if (!memcmp(pefHeader.tag2, kPPCResourceFileMagic, 4)) { // PPC resource file fHostEndianess = B_HOST_IS_BENDIAN; @@ -446,17 +447,24 @@ void ResourceFile::_InitELFFile(BFile& file) { status_t error = B_OK; + // get the file size off_t fileSize = 0; error = file.GetSize(&fileSize); if (error != B_OK) throw Exception(error, "Failed to get the file size."); - // read ELF header - Elf32_Ehdr fileHeader; - read_exactly(file, 0, &fileHeader, sizeof(Elf32_Ehdr), - "Failed to read ELF header."); + + // read the ELF headers e_ident field + unsigned char identification[EI_NIDENT]; + read_exactly(file, 0, identification, EI_NIDENT, + "Failed to read ELF identification."); + + // check version + if (identification[EI_VERSION] != EV_CURRENT) + throw Exception(B_UNSUPPORTED, "Unsupported ELF version."); + // check data encoding (endianess) - switch (fileHeader.e_ident[EI_DATA]) { + switch (identification[EI_DATA]) { case ELFDATA2LSB: fHostEndianess = B_HOST_IS_LENDIAN; break; @@ -465,37 +473,63 @@ ResourceFile::_InitELFFile(BFile& file) break; default: case ELFDATANONE: - throw Exception(B_IO_ERROR, "Unsupported ELF data encoding."); - break; + throw Exception(B_UNSUPPORTED, "Unsupported ELF data encoding."); } + + // check class (32/64 bit) and call the respective method handling it + switch (identification[EI_CLASS]) { + case ELFCLASS32: + _InitELFXFile(file, fileSize); + break; + case ELFCLASS64: + _InitELFXFile(file, fileSize); + break; + default: + throw Exception(B_UNSUPPORTED, "Unsupported ELF class."); + } +} + + +template +void +ResourceFile::_InitELFXFile(BFile& file, uint64 fileSize) +{ + // read ELF header + ElfHeader fileHeader; + read_exactly(file, 0, &fileHeader, sizeof(ElfHeader), + "Failed to read ELF header."); + // get the header values - uint32 headerSize = _GetUInt16(fileHeader.e_ehsize); - uint32 programHeaderTableOffset = _GetUInt32(fileHeader.e_phoff); - uint32 programHeaderSize = _GetUInt16(fileHeader.e_phentsize); - uint32 programHeaderCount = _GetUInt16(fileHeader.e_phnum); - uint32 sectionHeaderTableOffset = _GetUInt32(fileHeader.e_shoff); - uint32 sectionHeaderSize = _GetUInt16(fileHeader.e_shentsize); - uint32 sectionHeaderCount = _GetUInt16(fileHeader.e_shnum); + uint32 headerSize = _GetInt(fileHeader.e_ehsize); + uint64 programHeaderTableOffset = _GetInt(fileHeader.e_phoff); + uint32 programHeaderSize = _GetInt(fileHeader.e_phentsize); + uint32 programHeaderCount = _GetInt(fileHeader.e_phnum); + uint64 sectionHeaderTableOffset = _GetInt(fileHeader.e_shoff); + uint32 sectionHeaderSize = _GetInt(fileHeader.e_shentsize); + uint32 sectionHeaderCount = _GetInt(fileHeader.e_shnum); bool hasProgramHeaderTable = (programHeaderTableOffset != 0); bool hasSectionHeaderTable = (sectionHeaderTableOffset != 0); + // check the sanity of the header values // ELF header size - if (headerSize < sizeof(Elf32_Ehdr) || headerSize > kMaxELFHeaderSize) { + if (headerSize < sizeof(ElfHeader) || headerSize > kMaxELFHeaderSize) { throw Exception(B_IO_ERROR, "Invalid ELF header: invalid ELF header size: %lu.", headerSize); } - uint32 resourceOffset = headerSize; - uint32 resourceAlignment = 0; + uint64 resourceOffset = headerSize; + uint64 resourceAlignment = 0; + // program header table offset and entry count/size - uint32 programHeaderTableSize = 0; + uint64 programHeaderTableSize = 0; if (hasProgramHeaderTable) { if (programHeaderTableOffset < headerSize || programHeaderTableOffset > fileSize) { throw Exception(B_IO_ERROR, "Invalid ELF header: invalid program " "header table offset: %lu.", programHeaderTableOffset); } - programHeaderTableSize = programHeaderSize * programHeaderCount; - if (programHeaderSize < sizeof(Elf32_Phdr) + programHeaderTableSize = (uint64)programHeaderSize * programHeaderCount; + if (programHeaderSize < sizeof(ElfProgramHeader) || programHeaderTableOffset + programHeaderTableSize > fileSize) { throw Exception(B_IO_ERROR, "Invalid ELF header: program header " "table exceeds file: %lu.", @@ -503,17 +537,20 @@ ResourceFile::_InitELFFile(BFile& file) } resourceOffset = std::max(resourceOffset, programHeaderTableOffset + programHeaderTableSize); + // iterate through the program headers - for (int32 i = 0; i < (int32)programHeaderCount; i++) { - uint32 shOffset = programHeaderTableOffset + i * programHeaderSize; - Elf32_Phdr programHeader; - read_exactly(file, shOffset, &programHeader, sizeof(Elf32_Shdr), - "Failed to read ELF program header."); + for (uint32 i = 0; i < programHeaderCount; i++) { + uint64 shOffset = programHeaderTableOffset + i * programHeaderSize; + ElfProgramHeader programHeader; + read_exactly(file, shOffset, &programHeader, + sizeof(ElfProgramHeader), "Failed to read ELF program header."); + // get the header values - uint32 type = _GetUInt32(programHeader.p_type); - uint32 offset = _GetUInt32(programHeader.p_offset); - uint32 size = _GetUInt32(programHeader.p_filesz); - uint32 alignment = _GetUInt32(programHeader.p_align); + uint32 type = _GetInt(programHeader.p_type); + uint64 offset = _GetInt(programHeader.p_offset); + uint64 size = _GetInt(programHeader.p_filesz); + uint64 alignment = _GetInt(programHeader.p_align); + // check the values // PT_NULL marks the header unused, if (type != PT_NULL) { @@ -521,7 +558,7 @@ ResourceFile::_InitELFFile(BFile& file) throw Exception(B_IO_ERROR, "Invalid ELF program header: " "invalid program offset: %lu.", offset); } - uint32 segmentEnd = offset + size; + uint64 segmentEnd = offset + size; if (segmentEnd > fileSize) { throw Exception(B_IO_ERROR, "Invalid ELF section header: " "segment exceeds file: %lu.", segmentEnd); @@ -531,16 +568,17 @@ ResourceFile::_InitELFFile(BFile& file) } } } + // section header table offset and entry count/size - uint32 sectionHeaderTableSize = 0; + uint64 sectionHeaderTableSize = 0; if (hasSectionHeaderTable) { if (sectionHeaderTableOffset < headerSize || sectionHeaderTableOffset > fileSize) { throw Exception(B_IO_ERROR, "Invalid ELF header: invalid section " "header table offset: %lu.", sectionHeaderTableOffset); } - sectionHeaderTableSize = sectionHeaderSize * sectionHeaderCount; - if (sectionHeaderSize < sizeof(Elf32_Shdr) + sectionHeaderTableSize = (uint64)sectionHeaderSize * sectionHeaderCount; + if (sectionHeaderSize < sizeof(ElfSectionHeader) || sectionHeaderTableOffset + sectionHeaderTableSize > fileSize) { throw Exception(B_IO_ERROR, "Invalid ELF header: section header " "table exceeds file: %lu.", @@ -548,16 +586,19 @@ ResourceFile::_InitELFFile(BFile& file) } resourceOffset = std::max(resourceOffset, sectionHeaderTableOffset + sectionHeaderTableSize); + // iterate through the section headers - for (int32 i = 0; i < (int32)sectionHeaderCount; i++) { + for (uint32 i = 0; i < sectionHeaderCount; i++) { uint32 shOffset = sectionHeaderTableOffset + i * sectionHeaderSize; - Elf32_Shdr sectionHeader; - read_exactly(file, shOffset, §ionHeader, sizeof(Elf32_Shdr), - "Failed to read ELF section header."); + ElfSectionHeader sectionHeader; + read_exactly(file, shOffset, §ionHeader, + sizeof(ElfSectionHeader), "Failed to read ELF section header."); + // get the header values - uint32 type = _GetUInt32(sectionHeader.sh_type); - uint32 offset = _GetUInt32(sectionHeader.sh_offset); - uint32 size = _GetUInt32(sectionHeader.sh_size); + uint32 type = _GetInt(sectionHeader.sh_type); + uint64 offset = _GetInt(sectionHeader.sh_offset); + uint64 size = _GetInt(sectionHeader.sh_size); + // check the values // SHT_NULL marks the header unused, // SHT_NOBITS sections take no space in the file @@ -566,7 +607,7 @@ ResourceFile::_InitELFFile(BFile& file) throw Exception(B_IO_ERROR, "Invalid ELF section header: " "invalid section offset: %lu.", offset); } - uint32 sectionEnd = offset + size; + uint64 sectionEnd = offset + size; if (sectionEnd > fileSize) { throw Exception(B_IO_ERROR, "Invalid ELF section header: " "section exceeds file: %lu.", sectionEnd); @@ -575,6 +616,7 @@ ResourceFile::_InitELFFile(BFile& file) } } } + // align the offset if (resourceAlignment < kELFMinResourceAlignment) resourceAlignment = kELFMinResourceAlignment; @@ -588,6 +630,7 @@ ResourceFile::_InitELFFile(BFile& file) fEmptyResources = true; } else fEmptyResources = false; + // fine, init the offset file fFile.SetTo(&file, resourceOffset); } @@ -607,7 +650,7 @@ ResourceFile::_InitPEFFile(BFile& file, const PEFContainerHeader& pefHeader) throw Exception(B_IO_ERROR, "PEF file architecture is not PPC."); fHostEndianess = B_HOST_IS_BENDIAN; // get the section count - uint16 sectionCount = _GetUInt16(pefHeader.sectionCount); + uint16 sectionCount = _GetInt(pefHeader.sectionCount); // iterate through the PEF sections headers uint32 sectionHeaderTableOffset = kPEFContainerHeaderSize; uint32 sectionHeaderTableEnd @@ -619,8 +662,8 @@ ResourceFile::_InitPEFFile(BFile& file, const PEFContainerHeader& pefHeader) read_exactly(file, shOffset, §ionHeader, kPEFSectionHeaderSize, "Failed to read PEF section header."); // get the header values - uint32 offset = _GetUInt32(sectionHeader.containerOffset); - uint32 size = _GetUInt32(sectionHeader.packedSize); + uint32 offset = _GetInt(sectionHeader.containerOffset); + uint32 size = _GetInt(sectionHeader.packedSize); // check the values if (offset < sectionHeaderTableEnd || offset > fileSize) { throw Exception(B_IO_ERROR, "Invalid PEF section header: invalid " @@ -652,7 +695,7 @@ ResourceFile::_ReadHeader(resource_parse_info& parseInfo) "Failed to read the header."); // check the header // magic - uint32 magic = _GetUInt32(header.rh_resources_magic); + uint32 magic = _GetInt(header.rh_resources_magic); if (magic == kResourcesHeaderMagic) { // everything is fine } else if (B_SWAP_INT32(magic) == kResourcesHeaderMagic) { @@ -667,11 +710,11 @@ ResourceFile::_ReadHeader(resource_parse_info& parseInfo) } else throw Exception(B_IO_ERROR, "Invalid resources header magic."); // resource count - uint32 resourceCount = _GetUInt32(header.rh_resource_count); + uint32 resourceCount = _GetInt(header.rh_resource_count); if (resourceCount > kMaxResourceCount) throw Exception(B_IO_ERROR, "Bad number of resources."); // index section offset - uint32 indexSectionOffset = _GetUInt32(header.rh_index_section_offset); + uint32 indexSectionOffset = _GetInt(header.rh_index_section_offset); if (indexSectionOffset != kResourceIndexSectionOffset) { throw Exception(B_IO_ERROR, "Unexpected resource index section " "offset. Is: %lu, should be: %lu.", indexSectionOffset, @@ -682,7 +725,7 @@ ResourceFile::_ReadHeader(resource_parse_info& parseInfo) + kResourceIndexEntrySize * resourceCount; indexSectionSize = align_value(indexSectionSize, kResourceIndexSectionAlignment); - uint32 adminSectionSize = _GetUInt32(header.rh_admin_section_size); + uint32 adminSectionSize = _GetInt(header.rh_admin_section_size); if (adminSectionSize != indexSectionOffset + indexSectionSize) { throw Exception(B_IO_ERROR, "Unexpected resource admin section size. " "Is: %lu, should be: %lu.", adminSectionSize, @@ -705,7 +748,7 @@ ResourceFile::_ReadIndex(resource_parse_info& parseInfo) "Failed to read the resource index section header."); // check the header // index section offset - uint32 indexSectionOffset = _GetUInt32(header.rish_index_section_offset); + uint32 indexSectionOffset = _GetInt(header.rish_index_section_offset); if (indexSectionOffset != kResourceIndexSectionOffset) { throw Exception(B_IO_ERROR, "Unexpected resource index section " "offset. Is: %lu, should be: %lu.", indexSectionOffset, @@ -716,7 +759,7 @@ ResourceFile::_ReadIndex(resource_parse_info& parseInfo) + kResourceIndexEntrySize * resourceCount; expectedIndexSectionSize = align_value(expectedIndexSectionSize, kResourceIndexSectionAlignment); - uint32 indexSectionSize = _GetUInt32(header.rish_index_section_size); + uint32 indexSectionSize = _GetInt(header.rish_index_section_size); if (indexSectionSize != expectedIndexSectionSize) { throw Exception(B_IO_ERROR, "Unexpected resource index section size. " "Is: %lu, should be: %lu.", indexSectionSize, @@ -724,22 +767,22 @@ ResourceFile::_ReadIndex(resource_parse_info& parseInfo) } // unknown section offset uint32 unknownSectionOffset - = _GetUInt32(header.rish_unknown_section_offset); + = _GetInt(header.rish_unknown_section_offset); if (unknownSectionOffset != indexSectionOffset + indexSectionSize) { throw Exception(B_IO_ERROR, "Unexpected resource index section size. " "Is: %lu, should be: %lu.", unknownSectionOffset, indexSectionOffset + indexSectionSize); } // unknown section size - uint32 unknownSectionSize = _GetUInt32(header.rish_unknown_section_size); + uint32 unknownSectionSize = _GetInt(header.rish_unknown_section_size); if (unknownSectionSize != kUnknownResourceSectionSize) { throw Exception(B_IO_ERROR, "Unexpected resource index section " "offset. Is: %lu, should be: %lu.", unknownSectionOffset, kUnknownResourceSectionSize); } // info table offset and size - uint32 infoTableOffset = _GetUInt32(header.rish_info_table_offset); - uint32 infoTableSize = _GetUInt32(header.rish_info_table_size); + uint32 infoTableOffset = _GetInt(header.rish_info_table_offset); + uint32 infoTableSize = _GetInt(header.rish_info_table_size); if (infoTableOffset + infoTableSize > fileSize) throw Exception(B_IO_ERROR, "Invalid info table location."); parseInfo.info_table_offset = infoTableOffset; @@ -793,8 +836,8 @@ ResourceFile::_ReadIndexEntry(resource_parse_info& parseInfo, int32 index, } result = false; } - uint32 offset = _GetUInt32(entry.rie_offset); - uint32 size = _GetUInt32(entry.rie_size); + uint32 offset = _GetInt(entry.rie_offset); + uint32 size = _GetInt(entry.rie_size); // check the location if (result && offset + size > fileSize) { if (peekAhead) { @@ -860,7 +903,7 @@ ResourceFile::_ReadInfoTable(resource_parse_info& parseInfo) } const resource_info_block* infoBlock = (const resource_info_block*)data; - type_code type = _GetUInt32(infoBlock->rib_type); + type_code type = _GetInt(infoBlock->rib_type); // read the infos of this block const resource_info* info = infoBlock->rib_info; while (info) { @@ -872,8 +915,8 @@ ResourceFile::_ReadInfoTable(resource_parse_info& parseInfo) } const resource_info_separator* separator = (const resource_info_separator*)data; - if (_GetUInt32(separator->ris_value1) == 0xffffffff - && _GetUInt32(separator->ris_value2) == 0xffffffff) { + if (_GetInt(separator->ris_value1) == 0xffffffff + && _GetInt(separator->ris_value2) == 0xffffffff) { // info block ends info = NULL; data = skip_bytes(data, kResourceInfoSeparatorSize); @@ -893,8 +936,8 @@ ResourceFile::_ReadInfoTable(resource_parse_info& parseInfo) } const resource_info_separator* tableTerminator = (const resource_info_separator*)data; - if (_GetUInt32(tableTerminator->ris_value1) != 0xffffffff - || _GetUInt32(tableTerminator->ris_value2) != 0xffffffff) { + if (_GetInt(tableTerminator->ris_value1) != 0xffffffff + || _GetInt(tableTerminator->ris_value2) != 0xffffffff) { throw Exception(B_IO_ERROR, "The resource info table ought to be " "empty, but is not properly terminated."); } @@ -931,13 +974,13 @@ ResourceFile::_ReadInfoTableEnd(const void* data, int32 dataSize) const resource_info_table_end* tableEnd = (const resource_info_table_end*) skip_bytes(data, dataSize - kResourceInfoTableEndSize); - if (_GetInt32(tableEnd->rite_terminator) != 0) + if (_GetInt(tableEnd->rite_terminator) != 0) hasTableEnd = false; if (hasTableEnd) { dataSize -= kResourceInfoTableEndSize; // checksum uint32 checkSum = calculate_checksum(data, dataSize); - uint32 fileCheckSum = _GetUInt32(tableEnd->rite_check_sum); + uint32 fileCheckSum = _GetInt(tableEnd->rite_check_sum); if (checkSum != fileCheckSum) { throw Exception(B_IO_ERROR, "Invalid resource info table check" " sum: In file: %lx, calculated: %lx.", fileCheckSum, @@ -957,9 +1000,9 @@ ResourceFile::_ReadResourceInfo(resource_parse_info& parseInfo, bool* readIndices) { int32& resourceCount = parseInfo.resource_count; - int32 id = _GetInt32(info->ri_id); - int32 index = _GetInt32(info->ri_index); - uint16 nameSize = _GetUInt16(info->ri_name_size); + int32 id = _GetInt(info->ri_id); + int32 index = _GetInt(info->ri_index); + uint16 nameSize = _GetInt(info->ri_name_size); const char* name = info->ri_name; // check the values bool ignore = false;