* renamed file to constants.py
authorebenders <devnull@localhost>
Thu, 8 Sep 2011 07:06:18 +0000 (10:06 +0300)
committerebenders <devnull@localhost>
Thu, 8 Sep 2011 07:06:18 +0000 (10:06 +0300)
* defined stuff for program header

elftools/elf/constants.py [new file with mode: 0644]
elftools/elf/enums.py
elftools/elf/flags.py [deleted file]
elftools/elf/structs.py

diff --git a/elftools/elf/constants.py b/elftools/elf/constants.py
new file mode 100644 (file)
index 0000000..1c64a8f
--- /dev/null
@@ -0,0 +1,40 @@
+# Constants and flags, placed into classes for namespacing\r
+\r
+class SHN_INDICES(object):\r
+    """ Special section indices
+    """\r
+    SHN_UNDEF=0\r
+    SHN_LORESERVE=0xff00\r
+    SHN_LOPROC=0xff00\r
+    SHN_HIPROC=0xff1f\r
+    SHN_ABS=0xfff1\r
+    SHN_COMMON=0xfff2\r
+    SHN_HIRESERVE=0xffff
+\r
+\r
+class SH_FLAGS(object):\r
+    """ Flag values for the sh_flags field of section headers
+    """\r
+    SHF_WRITE=0x1\r
+    SHF_ALLOC=0x2\r
+    SHF_EXECINSTR=0x4\r
+    SHF_MERGE=0x10\r
+    SHF_STRINGS=0x20\r
+    SHF_INFO_LINK=0x40\r
+    SHF_LINK_ORDER=0x80\r
+    SHF_OS_NONCONFORMING=0x100\r
+    SHF_GROUP=0x200\r
+    SHF_TLS=0x400\r
+    SHF_MASKOS=0x0ff00000\r
+    SHF_MASKPROC=0xf0000000\r
+\r
+\r
+class P_FLAGS(object):\r
+    """ Flag values for the p_flags field of program headers
+    """\r
+    PF_X=0x1\r
+    PF_W=0x2\r
+    PF_R=0x4\r
+    PF_MASKOS=0x00FF0000\r
+    PF_MASKPROC=0xFF000000\r
+\r
index 0b76c52db8492e8672608c5d7a7bedd9076545a0..076297994b9a6f9806a0493cbf6ee62ff57a060d 100644 (file)
@@ -82,3 +82,16 @@ ENUM_SH_TYPE = dict(
     _default_='RESERVED',\r
 )\r
 \r
+# p_type in the program header\r
+ENUM_P_TYPE = dict(\r
+    PT_NULL=0,\r
+    PT_LOAD=1,\r
+    PT_DYNAMIC=2,\r
+    PT_INTERP=3,\r
+    PT_NOTE=4,\r
+    PT_SHLIB=5,\r
+    PT_PHDR=6,\r
+    PT_LOPROC=0x70000000,\r
+    PT_HIPROC=0x7fffffff,\r
+)\r
+\r
diff --git a/elftools/elf/flags.py b/elftools/elf/flags.py
deleted file mode 100644 (file)
index 32a1ed3..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-# Flag values, placed into classes for namespacing\r
-\r
-class SH_FLAGS(object):\r
-    SHF_WRITE=0x1\r
-    SHF_ALLOC=0x2\r
-    SHF_EXECINSTR=0x4\r
-    SHF_MERGE=0x10\r
-    SHF_STRINGS=0x20\r
-    SHF_INFO_LINK=0x40\r
-    SHF_LINK_ORDER=0x80\r
-    SHF_OS_NONCONFORMING=0x100\r
-    SHF_GROUP=0x200\r
-    SHF_TLS=0x400\r
-    SHF_MASKOS=0x0ff00000\r
-    SHF_MASKPROC=0xf0000000\r
-\r
index 090a8a9d0e709c5a8ec406014669dd7860e4a3fe..8c610dc01fda2c9072051fab0539d79a184726ca 100644 (file)
@@ -36,6 +36,7 @@ class ELFStructs(object):
             self.Elf_sxword = SBInt32 if self.elfclass == 32 else SBInt64\r
         \r
         self._create_ehdr()\r
+        self._create_phdr()\r
         self._create_shdr()\r
         self._create_sym()\r
     \r
@@ -63,6 +64,30 @@ class ELFStructs(object):
             self.Elf_half('e_shstrndx'),\r
         )\r
     \r
+    def _create_phdr(self):\r
+        if self.elfclass == 32:\r
+            self.Elf_Phdr = Struct('Elf_Phdr',\r
+                Enum(self.Elf_word('p_type'), **ENUM_P_TYPE),\r
+                self.Elf_offset('p_offset'),\r
+                self.Elf_addr('p_vaddr'),\r
+                self.Elf_addr('p_paddr'),\r
+                self.Elf_word('p_filesz'),\r
+                self.Elf_word('p_memsz'),\r
+                self.Elf_word('p_flags'),\r
+                self.Elf_word('p_align'),\r
+            )\r
+        else:\r
+            self.Elf_Phdr = Struct('Elf_Phdr',\r
+                Enum(self.Elf_word('p_type'), **ENUM_P_TYPE),\r
+                self.Elf_word('p_flags'),\r
+                self.Elf_offset('p_offset'),\r
+                self.Elf_addr('p_vaddr'),\r
+                self.Elf_addr('p_paddr'),\r
+                self.Elf_word('p_filesz'),\r
+                self.Elf_word('p_memsz'),\r
+                self.Elf_word('p_align'),\r
+            )   \r
+        \r
     def _create_shdr(self):
         self.Elf_Shdr = Struct('Elf_Shdr',\r
             self.Elf_word('sh_name'),\r