Ejemplo n.º 1
0
    def __bytes__(self):
        st_name = uint32(self.st_name, little=self.little)
        st_value = uint32(self.st_value, little=self.little)
        st_size = uint32(self.st_size, little=self.little)
        st_info = uint8(self.st_info, little=self.little)
        st_other = uint8(self.st_other, little=self.little)
        st_shndx = uint16(self.st_shndx, little=self.little)

        return bytes(st_name) + bytes(st_value) + bytes(st_size) + \
                bytes(st_info) + bytes(st_other) + bytes(st_shndx)
Ejemplo n.º 2
0
    def __bytes__(self):
        d_tag = bytes(self.d_tag)
        d_val = uint32(self.d_val, little=self.little)
        d_ptr = uint32(self.d_ptr, little=self.little)

        # make sure d_tag is enum, before reversing bytes
        # other way it may be already reversed
        if self.little and isinstance(self.d_tag, DT):
            d_tag = bytes(reversed(d_tag))

        return bytes(d_tag) + bytes(d_val)
Ejemplo n.º 3
0
    def __init__(self, d_tag=DT.DT_NULL, d_val=None, d_ptr=None, little=False):
        if isinstance(d_tag, DT):
            ## Value of type \link DT \endlink
            #  \details Controls if d_val or d_ptr is present
            self.d_tag = d_tag
        elif d_tag in map(int, DT):
            self.d_tag = DT(d_tag)
        elif isinstance(d_tag, int):
            # TODO: log warning message
            self.d_tag = uint32(d_tag, little)
        else:
            self.d_tag = DT[d_tag]

        # TODO: set only one of d_val or d_ptr

        ## Integer of various interpretations
        self.d_val = d_val

        ## Program virtual addresses
        self.d_ptr = d_ptr

        ## Header endianness indicator
        #  \details Is true, if header values are meant to be stored as
        #  little-endian or false otherwise
        self.little = little  # should not be used, but for consistency set it
Ejemplo n.º 4
0
    def __bytes__(self):
        p_type = uint32(self.p_type, little=self.little)
        p_offset = uint32(self.p_offset, little=self.little)
        p_vaddr = uint32(self.p_vaddr, little=self.little)
        p_paddr = uint32(self.p_paddr, little=self.little)
        p_filesz = uint32(self.p_filesz, little=self.little)
        p_memsz = uint32(self.p_memsz, little=self.little)
        p_flags = uint32(self.p_flags, little=self.little)
        p_align = uint32(self.p_align, little=self.little)

        return bytes(p_type) + bytes(p_offset) + bytes(p_vaddr) + \
                bytes(p_paddr) + bytes(p_filesz) + bytes(p_memsz) + \
                bytes(p_flags) + bytes(p_align)
Ejemplo n.º 5
0
 def __bytes__(self):
     little = self.little
     e_type = bytes(self.e_type)
     e_machine = bytes(self.e_machine)
     e_version = uint32(self.e_version, little)
     e_entry = uint32(self.e_entry, little)
     e_phoff = uint32(self.e_phoff, little)
     e_shoff = uint32(self.e_shoff, little)
     e_flags = uint32(self.e_flags, little)
     e_ehsize = uint16(self.e_ehsize, little)
     e_phentsize = uint16(self.e_phentsize, little)
     e_phnum = uint16(self.e_phnum, little)
     e_shentsize = uint16(self.e_shentsize, little)
     e_shnum = uint16(self.e_shnum, little)
     e_shstrndx = uint16(self.e_shstrndx, little)
     if self.little:
         e_type = bytes(reversed(e_type))
         e_machine = bytes(reversed(e_machine))
     b = bytes(self.e_ident) + bytes(e_type) + bytes(e_machine) + \
             bytes(e_version) + bytes(e_entry) + bytes(e_phoff) + \
             bytes(e_shoff) + bytes(e_flags) + bytes(e_ehsize) + \
             bytes(e_phentsize) + bytes(e_phnum) + bytes(e_shentsize) + \
             bytes(e_shnum) + bytes(e_shstrndx)
     return b
Ejemplo n.º 6
0
    def __bytes__(self):
        sh_name = uint32(self.sh_name, little=self.little)
        sh_type = bytes(self.sh_type)
        sh_flags = uint32(self.sh_flags, little=self.little)
        sh_addr = uint32(self.sh_addr, little=self.little)
        sh_offset = uint32(self.sh_offset, little=self.little)
        sh_size = uint32(self.sh_size, little=self.little)
        sh_link = uint32(self.sh_link, little=self.little)
        sh_info = uint32(self.sh_info, little=self.little)
        sh_addralign = uint32(self.sh_addralign, little=self.little)
        sh_entsize = uint32(self.sh_entsize, little=self.little)

        # make sure sh_type is enum, before reversing bytes
        # other way it may be already reversed
        if self.little and isinstance(self.sh_type, SHT):
            sh_type = bytes(reversed(sh_type))

        return bytes(sh_name) + bytes(sh_type) + bytes(sh_flags) + \
                bytes(sh_addr) + bytes(sh_offset) + bytes(sh_size) + \
                bytes(sh_link) + bytes(sh_info) + bytes(sh_addralign) + \
                bytes(sh_entsize)
Ejemplo n.º 7
0
    def __init__(self,
                 sh_name=0,
                 sh_type=SHT.SHT_NULL,
                 sh_flags=0,
                 sh_addr=0,
                 sh_offset=0,
                 sh_size=0,
                 sh_link=0,
                 sh_info=0,
                 sh_addralign=0,
                 sh_entsize=0,
                 little=False):
        ## Offset of section name in .shstrtab
        self.sh_name = sh_name

        if isinstance(sh_type, SHT):
            ## Value of type \link SHT \endlink
            self.sh_type = sh_type
        elif sh_type in map(int, SHT):
            self.sh_type = SHT(sh_type)
        elif isinstance(sh_type, int):
            # TODO: log warning message
            self.sh_type = uint32(sh_type, little)
        else:
            self.sh_type = SHT[sh_type]

        ## Value of type \link SHF \endlink
        self.sh_flags = sh_flags
        ## Address of first byte of segment in memory
        self.sh_addr = sh_addr
        ## Address of first byte of segment in file
        self.sh_offset = sh_offset
        ## Size of section in file
        self.sh_size = sh_size
        ## Section type dependent value
        self.sh_link = sh_link
        ## Section type dependent value
        self.sh_info = sh_info
        ## Section alignment
        #  \details Value of 0 or 1 means no aligment is required
        self.sh_addralign = sh_addralign
        ## Entry size, if section holds fixed-size entries
        self.sh_entsize = sh_entsize

        ## Header endianness indicator
        #  \details Is true, if header values are meant to be stored as
        #  little-endian or false otherwise
        self.little = little
Ejemplo n.º 8
0
    def __bytes__(self):
        r_offset = uint32(self.r_offset, little=self.little)
        r_info = uint32(self.r_info, little=self.little)
        r_addend = sint32(self.r_addend, little=self.little)

        return bytes(r_offset) + bytes(r_info) + bytes(r_addend)