Commits

Chris Perl committed a20c21e

Rename dictionary descriptors to be more accurate

  • Participants
  • Parent commits e0d0ccd

Comments (0)

Files changed (1)

         else:
             return value 
 
-    def _unpack(self, f, obj32, obj64):
+    def _unpack(self, f, descriptor_32, descriptor_64):
         """
-        Unpacks an ElfObject subclass.  If the object is 32 bit, it uses the keys from the obj32
-        dictionary, while if the object is 64 bit, it uses the keys from the obj64 dictionary.
+        Unpacks an ElfObject subclass.  If the object is 32 bit, it uses the keys from the descriptor_32
+        dictionary, while if the object is 64 bit, it uses the keys from the descriptor_64 dictionary.
         """
         elfclass = self.elf_hdr.elfclass
         if elfclass == ElfIdent.ELFCLASS32:
-            fmt    = obj32['fmt']
-            fields = obj32['fields']
-            offset = obj32['offset']
-            size   = obj32['size']
+            fmt    = descriptor_32['fmt']
+            fields = descriptor_32['fields']
+            offset = descriptor_32['offset']
+            size   = descriptor_32['size']
         elif elfclass == ElfIdent.ELFCLASS64:
-            fmt    = obj64['fmt']
-            fields = obj64['fields']
-            offset = obj64['offset']
-            size   = obj64['size']
+            fmt    = descriptor_64['fmt']
+            fields = descriptor_64['fields']
+            offset = descriptor_64['offset']
+            size   = descriptor_64['size']
         else:
             raise InvalidFileFormat("Unsupported elfclass for %s: %d" % (self.__class__.__name__, elfclass))
 
         # I is unsigned 4 bytes
         # Q is unsigned 8 bytes
         # Note that we skip the first field, e_ident, as that was taken care of above manually
-        obj32 = { 'fmt': "HHIIIIIHHHHHH",
-                  'size': 0x24,
-                  'fields': ElfHeader.fields[1:],
-                  'offset': 0x10 }
+        descriptor_32 = { 
+            'fmt': "HHIIIIIHHHHHH",
+            'size': 0x24,
+            'fields': ElfHeader.fields[1:],
+            'offset': 0x10,
+        }
 
-        obj64 = { 'fmt': "HHIQQQIHHHHHH",
-                  'size': 0x30,
-                  'fields': ElfHeader.fields[1:],
-                  'offset': 0x10 }
-        self._unpack(self._f, obj32, obj64)
+        descriptor_64 = { 
+            'fmt': "HHIQQQIHHHHHH",
+            'size': 0x30,
+            'fields': ElfHeader.fields[1:],
+            'offset': 0x10,
+        }
+        self._unpack(self._f, descriptor_32, descriptor_64)
 
     def _symbol_resolve_e_ident(self, value):
         tmp = []
         self._idx = idx
         self._size = size
 
-        obj32 = { 'fmt': "IIIIIIIIII",
-                  'size': 0x28,
-                  'fields': SectionHeader.fields,
-                  'offset': sht_offset+(idx*size) }
+        descriptor_32 = { 
+            'fmt': "IIIIIIIIII",
+            'size': 0x28,
+            'fields': SectionHeader.fields,
+            'offset': sht_offset+(idx*size),
+        }
 
-        obj64 = { 'fmt': "IIQQQQIIQQ",
-                  'size': 0x40,
-                  'fields': SectionHeader.fields,
-                  'offset': sht_offset+(idx*size) }
+        descriptor_64 = {
+            'fmt': "IIQQQQIIQQ",
+            'size': 0x40,
+            'fields': SectionHeader.fields,
+            'offset': sht_offset+(idx*size),
+        }
                  
-        self._unpack(self._f, obj32, obj64)
+        self._unpack(self._f, descriptor_32, descriptor_64)
 
         if str_tbl is not None:
             self.name = str_tbl[self.sh_name]
         self._idx = idx
         self._size = size
 
-        obj32 = { 'fmt': "IIIIIIII",
-                  'size': 0x20,
-                  'fields': ProgramHeader.fields,
-                  'offset': pht_offset+(idx*size) }
+        descriptor_32 = {
+            'fmt': "IIIIIIII",
+            'size': 0x20,
+            'fields': ProgramHeader.fields,
+            'offset': pht_offset+(idx*size),
+        }
 
-        obj64 = { 'fmt': "IIQQQQQQ",
-                  'size': 0x38,
-                  'fields': ProgramHeader.fields,
-                  'offset': pht_offset+(idx*size) }
+        descriptor_64 = {
+            'fmt': "IIQQQQQQ",
+            'size': 0x38,
+            'fields': ProgramHeader.fields,
+            'offset': pht_offset+(idx*size),
+        }
                  
-        self._unpack(self._f, obj32, obj64)
+        self._unpack(self._f, descriptor_32, descriptor_64)
 
     def _symbol_resolve_p_flags(self, value):
         flags = []
         # 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 SymbolTable to which we belong,
         # therefore the start of the table is at offset 0
-        obj32 = { 'fmt': "IIIBBH",
-                  'size': 0x10,
-                  'fields': ("st_name", "st_value", "st_size",
-                             "st_info", "st_other", "st_shndx"),
-                  'offset': self._idx*self._size }
+        descriptor_32 = {
+            'fmt': "IIIBBH",
+            'size': 0x10,
+            'fields': ("st_name", "st_value", "st_size",
+                       "st_info", "st_other", "st_shndx"),
+            'offset': self._idx*self._size,
+        }
 
-        obj64 = { 'fmt': "IBBHQQ",
-                  'size': 0x18,
-                  'fields': ("st_name", "st_info", "st_other",
-                             "st_shndx", "st_value", "st_size"),
-                  'offset': self._idx*self._size }
-        self._unpack(self._f, obj32, obj64)
+        descriptor_64 = {
+            'fmt': "IBBHQQ",
+            'size': 0x18,
+            'fields': ("st_name", "st_info", "st_other",
+                        "st_shndx", "st_value", "st_size"),
+            'offset': self._idx*self._size,
+        }
+        self._unpack(self._f, descriptor_32, descriptor_64)
 
         # Set the name
         self.name = self.st.str_tbl[self.st_name]
         # 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
-        obj32 = { 'fmt': "II",
-                  'size': 0x8,
-                  'fields': self.fields,
-                  'offset': self._idx*self._size }
+        descriptor_32 = {
+            'fmt': "II",
+            'size': 0x8,
+            'fields': self.fields,
+            'offset': self._idx*self._size,
+        }
 
-        obj64 = { 'fmt': "QQ",
-                  'size': 0x10,
-                  'fields': self.fields,
-                  'offset': self._idx*self._size }
-        self._unpack(self._f, obj32, obj64)
+        descriptor_64 = {
+            'fmt': "QQ",
+            'size': 0x10,
+            'fields': self.fields,
+            'offset': self._idx*self._size,
+        }
+        self._unpack(self._f, descriptor_32, descriptor_64)
 
 class RelocationA(BaseRelocation):
 
         # 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
-        obj32 = { 'fmt': "III",
-                  'size': 0x8,
-                  'fields': self.fields,
-                  'offset': self._idx*self._size }
+        descriptor_32 = {
+            'fmt': "III",
+            'size': 0x8,
+            'fields': self.fields,
+            'offset': self._idx*self._size,
+        }
 
-        obj64 = { 'fmt': "QQQ",
-                  'size': 0x18,
-                  'fields': self.fields,
-                  'offset': self._idx*self._size }
-        self._unpack(self._f, obj32, obj64)
+        descriptor_64 = {
+            'fmt': "QQQ",
+            'size': 0x18,
+            'fields': self.fields,
+            'offset': self._idx*self._size,
+        }
+        self._unpack(self._f, descriptor_32, descriptor_64)
 
 class ELF(object):
     """