def readDataByAddress(elf, address, size):
    for section in elf.sectionHeaderTable:
        if (address >= section.sh_addr
                and address <= section.sh_addr + section.sh_size):
            offset = address - section.sh_addr
            return utils.convertFromELF(section.contents[offset:offset + size],
                                        size)
    return const.RC_ERROR
Example #2
0
 def getStructMember(self, member):
     size = self.getStructMemberSize(member)
     data = utils.convertFromELF(self.struct, size, self.structOffset)
     self.structOffset += size
     # Print member and value if verbose is enabled
     if (self.verbose):
         print(self.__class__.__name__ + "." +
               member).ljust(35) + " = " + str(data)
     return data
Example #3
0
 def __init__(self, symbolData, strtab):
     ##  This member holds an index into the object file's symbol string
     #   table, which holds the character representations of the symbol
     #   names. If the value is non-zero, it represents a string table index
     #   that gives the symbol name. Otherwise, the symbol table entry has no
     #   name.
     self.st_name = utils.convertFromELF(symbolData,
                                         const.elfDataTypes.Elf32_Word,
                                         const.Elf32_SymOffsets.st_name)
     ##  This member gives the value of the associated symbol. Depending on
     #   the context, this may be an absolute value, an address, etc.
     self.st_value = utils.convertFromELF(symbolData,
                                          const.elfDataTypes.Elf32_Addr,
                                          const.Elf32_SymOffsets.st_value)
     ##  Many symbols have associated sizes. For example, a data object's
     #   size is the number of bytes contained in the object. This member
     #   holds 0 if the symbol has no size or an unknown size.
     self.st_size = utils.convertFromELF(symbolData,
                                         const.elfDataTypes.Elf32_Word,
                                         const.Elf32_SymOffsets.st_size)
     ##  This member specifies the symbol's type and binding attributes.
     self.st_info = utils.convertFromELF(symbolData,
                                         const.elfDataTypes.unsigned_char,
                                         const.Elf32_SymOffsets.st_info)
     ##  This member currently specifies a symbol's visibility
     self.st_other = utils.convertFromELF(symbolData,
                                          const.elfDataTypes.unsigned_char,
                                          const.Elf32_SymOffsets.st_other)
     ##  Every symbol table entry is "defined" in relation to some section;
     #   this member holds the relevant section header table index.
     self.st_shndx = utils.convertFromELF(symbolData,
                                          const.elfDataTypes.Elf32_Half,
                                          const.Elf32_SymOffsets.st_shndx)
     if self.st_name:
         ##  This member contains the string name of the symbol.
         self.st_nameStr = utils.getStringFromContents(
             strtab.contents, self.st_name)
     else:
         self.st_nameStr = ""