Added ELF64 support to BResources.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34250 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,14 +1,30 @@
|
||||
// Elf.h
|
||||
|
||||
/*
|
||||
* Copyright 2002-2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _ELF_H
|
||||
#define _ELF_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
// 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 <ElfX.h>
|
||||
|
||||
// 64 bit definitions
|
||||
#undef _ELFX_BITS
|
||||
#define _ELFX_BITS 64
|
||||
#include <ElfX.h>
|
||||
|
||||
#undef _ELFX_BITS
|
||||
|
||||
|
||||
#endif // _ELF_H
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2002-2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
// No header guard: The file is included twice by <Elf.h> 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
|
||||
@@ -72,7 +72,13 @@ public:
|
||||
|
||||
private:
|
||||
void _InitFile(BFile& file, bool clobber);
|
||||
|
||||
void _InitELFFile(BFile& file);
|
||||
|
||||
template<typename ElfHeader, typename ElfProgramHeader,
|
||||
typename ElfSectionHeader>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user