Commits

Chris Perl committed b69157c

Tweak how elfclass and byte_order are passed around. WIP

  • Participants
  • Parent commits c0332e1

Comments (0)

Files changed (1)

     # Variables that control certain behavior
     SYMBOLIC = True
 
-    @staticmethod
-    def save(attr, value):
-        setattr(ElfObject, attr, value)
+    def __init__(self, elfclass=None, byte_order=None):
+        self.elfclass = elfclass
+        self.byte_order = byte_order
 
     def __repr__(self):
         values = [ getattr(self, x) for x in self.fields ]
         else:
             raise StandardError("Unknown Parse Type: %d" % what)
 
-class ElfIdent(ElfObject):
+class ElfIdent(object):
     """
     A Class to hold the constants that are related to the first 16 bytes of the ELF header
     """
                "e_shnum", "e_shstrndx" ) 
 
     def __init__(self, f):
+        super(ElfHeader, self).__init__(elfclass=None, byte_order=None)
         self._f = f
         self.e_ident = struct.unpack("16B", self._f.read(16))
         magic = "".join(map(chr, [self.e_ident[ElfIdent.EI_MAG0],
             raise InvalidFileFormat("Incorrect Version Number: %d" % version)
 
         # Set our elfclass and byte_order
-        # Note that this will mean that any object that inherits from ElfObject instantiated after
-        # this will have their 'elfclass' and 'byte_order' attributes set correctly already.  Since
-        # we are the first object to be created (we're the ELF Header, we have to be first),
-        # everyone else can just rely on the fact that these attributes will be there when that
-        # class is instantiated.
-        ElfObject.save("elfclass", self.e_ident[ElfIdent.EI_CLASS])
-        ElfObject.save("byte_order", self.e_ident[ElfIdent.EI_DATA])
+        # Note that for every other class that inherits from ElfObject, these will be set via the
+        # super call to ElfObject, but since we are the first object instantiated and its up to us
+        # to determine these values, we set them here explicitly.
+        self.elfclass = self.e_ident[ElfIdent.EI_CLASS]
+        self.byte_order = self.e_ident[ElfIdent.EI_DATA]
 
         # H is unsigned 2 bytes
         # I is unsigned 4 bytes
               "sh_addralign", "sh_entsize" )
 
     def __init__(self, sct_hdr_tbl, sht_offset, idx, size, f, str_tbl):
+        super(SectionHeader, self).__init__(sct_hdr_tbl.elf_hdr.elfclass,
+                                            sct_hdr_tbl.elf_hdr.byte_order)
         self.sht = sct_hdr_tbl
         self._f = f
         self._idx = idx
               "p_filesz", "p_memsz", "p_flags", "p_align")
     
     def __init__(self, prg_hdr_tbl, pht_offset, idx, size, f):
+        super(ProgramHeader, self).__init__(prg_hdr_tbl.elf_hdr.elfclass,
+                                            prg_hdr_tbl.elf_hdr.byte_order)
         self.pht = prg_hdr_tbl
         self._f = f
         self._idx = idx
     STT_HIPROC  = 15
 
     def __init__(self, sym_tbl, size, idx, f):
+        super(Symbol, self).__init__(sym_tbl.sct_hdr.sht.elf_hdr.elfclass,
+                                     sym_tbl.sct_hdr.sht.elf_hdr.byte_order)
         self.st = sym_tbl
         self._f = f
         self._idx = idx
     R_386_GOTOFF   = 9
     R_386_GOTPC    = 10
 
+    def __init__(self, rel_tbl):
+        super(BaseRelocation, self).__init__(rel_tbl.sct_hdr.sht.elf_hdr.elfclass,
+                                             rel_tbl.sct_hdr.sht.elf_hdr.byte_order)
+
     # Dynamically define these attributes and this function if we are 32 bit
     @property
     def r_sym(self):
     fields = ("r_offset", "r_info")
 
     def __init__(self, rel_tbl, size, idx, f):
+        super(Relocation, self).__init__(rel_tbl)
         self.rt = rel_tbl
         self._f = f
         self._idx = idx
         self._size = size
 
-        # Call our super class constructor
-        BaseRelocation.__init__(self)
-
         # Note that we don't need a base for our offset, because in this case f is not the actual
         # file, but instead a StringIO instance instantiated by the RelocationTable to which we belong,
         # therefore the start of the table is at offset 0
     fields = ("r_offset", "r_info", "r_addend")
 
     def __init__(self, rel_tbl, size, idx, f):
+        super(RelocationA, self).__init__(rel_tbl)
         self.rt = rel_tbl
         self._f = f
         self._idx = idx
         self._size = size
 
-        # Call our super class constructor
-        BaseRelocation.__init__(self)
-
         # Note that we don't need a base for our offset, because in this case f is not the actual
         # file, but instead a StringIO instance instantiated by the RelocationTable to which we belong,
         # therefore the start of the table is at offset 0
                sh.sh_type == SectionHeader.SHT_RELA:
                 self.rts.append(RelocationTable.get_single_instance(sh))
 
-    def get_symbolic(self):
-        return ElfObject.SYMBOLIC 
-
-    def set_symbolic(self, value):
-        ElfObject.SYMBOLIC = value
-
-    SYMBOLIC = property(get_symbolic, set_symbolic)
-    
 def main():
         pass