From: ebenders Date: Thu, 8 Sep 2011 07:06:18 +0000 (+0300) Subject: * renamed file to constants.py X-Git-Tag: v0.10~140 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f95b7e7043b899b8fd4fba1d0852bb0df262f7a;p=pyelftools.git * renamed file to constants.py * defined stuff for program header --- diff --git a/elftools/elf/constants.py b/elftools/elf/constants.py new file mode 100644 index 0000000..1c64a8f --- /dev/null +++ b/elftools/elf/constants.py @@ -0,0 +1,40 @@ +# Constants and flags, placed into classes for namespacing + +class SHN_INDICES(object): + """ Special section indices + """ + SHN_UNDEF=0 + SHN_LORESERVE=0xff00 + SHN_LOPROC=0xff00 + SHN_HIPROC=0xff1f + SHN_ABS=0xfff1 + SHN_COMMON=0xfff2 + SHN_HIRESERVE=0xffff + + +class SH_FLAGS(object): + """ Flag values for the sh_flags field of section headers + """ + SHF_WRITE=0x1 + SHF_ALLOC=0x2 + SHF_EXECINSTR=0x4 + SHF_MERGE=0x10 + SHF_STRINGS=0x20 + SHF_INFO_LINK=0x40 + SHF_LINK_ORDER=0x80 + SHF_OS_NONCONFORMING=0x100 + SHF_GROUP=0x200 + SHF_TLS=0x400 + SHF_MASKOS=0x0ff00000 + SHF_MASKPROC=0xf0000000 + + +class P_FLAGS(object): + """ Flag values for the p_flags field of program headers + """ + PF_X=0x1 + PF_W=0x2 + PF_R=0x4 + PF_MASKOS=0x00FF0000 + PF_MASKPROC=0xFF000000 + diff --git a/elftools/elf/enums.py b/elftools/elf/enums.py index 0b76c52..0762979 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -82,3 +82,16 @@ ENUM_SH_TYPE = dict( _default_='RESERVED', ) +# p_type in the program header +ENUM_P_TYPE = dict( + PT_NULL=0, + PT_LOAD=1, + PT_DYNAMIC=2, + PT_INTERP=3, + PT_NOTE=4, + PT_SHLIB=5, + PT_PHDR=6, + PT_LOPROC=0x70000000, + PT_HIPROC=0x7fffffff, +) + diff --git a/elftools/elf/flags.py b/elftools/elf/flags.py deleted file mode 100644 index 32a1ed3..0000000 --- a/elftools/elf/flags.py +++ /dev/null @@ -1,16 +0,0 @@ -# Flag values, placed into classes for namespacing - -class SH_FLAGS(object): - SHF_WRITE=0x1 - SHF_ALLOC=0x2 - SHF_EXECINSTR=0x4 - SHF_MERGE=0x10 - SHF_STRINGS=0x20 - SHF_INFO_LINK=0x40 - SHF_LINK_ORDER=0x80 - SHF_OS_NONCONFORMING=0x100 - SHF_GROUP=0x200 - SHF_TLS=0x400 - SHF_MASKOS=0x0ff00000 - SHF_MASKPROC=0xf0000000 - diff --git a/elftools/elf/structs.py b/elftools/elf/structs.py index 090a8a9..8c610dc 100644 --- a/elftools/elf/structs.py +++ b/elftools/elf/structs.py @@ -36,6 +36,7 @@ class ELFStructs(object): self.Elf_sxword = SBInt32 if self.elfclass == 32 else SBInt64 self._create_ehdr() + self._create_phdr() self._create_shdr() self._create_sym() @@ -63,6 +64,30 @@ class ELFStructs(object): self.Elf_half('e_shstrndx'), ) + def _create_phdr(self): + if self.elfclass == 32: + self.Elf_Phdr = Struct('Elf_Phdr', + Enum(self.Elf_word('p_type'), **ENUM_P_TYPE), + self.Elf_offset('p_offset'), + self.Elf_addr('p_vaddr'), + self.Elf_addr('p_paddr'), + self.Elf_word('p_filesz'), + self.Elf_word('p_memsz'), + self.Elf_word('p_flags'), + self.Elf_word('p_align'), + ) + else: + self.Elf_Phdr = Struct('Elf_Phdr', + Enum(self.Elf_word('p_type'), **ENUM_P_TYPE), + self.Elf_word('p_flags'), + self.Elf_offset('p_offset'), + self.Elf_addr('p_vaddr'), + self.Elf_addr('p_paddr'), + self.Elf_word('p_filesz'), + self.Elf_word('p_memsz'), + self.Elf_word('p_align'), + ) + def _create_shdr(self): self.Elf_Shdr = Struct('Elf_Shdr', self.Elf_word('sh_name'),