示例#1
0
 def _repr_properties(self):
     properties = [
         ('Entry address', hex_addr(self.e_entry)),
         ('Program headers offset', hex_addr(self.e_phoff)),
         ('Section headers offset', hex_addr(self.e_shoff)),
         ('Flags', hex_addr(self.e_flags)),
         ('ELF header size', self.e_ehsize),
         ('Program headers size', self.e_phentsize),
         ('Number of program headers', self.e_phnum),
         ('Section headers size', self.e_shentsize),
         ('Number of section headers', self.e_shnum),
         ('String table section index', self.e_shstrndx),
     ]
     return Elf_Ehdr_Common._repr_properties(self) + properties
 def _repr_properties(self):
     properties = [
                     ('Entry address', hex_addr(self.e_entry)),
                     ('Program headers offset', hex_addr(self.e_phoff)),
                     ('Section headers offset', hex_addr(self.e_shoff)),
                     ('Flags', hex_addr(self.e_flags)),
                     ('ELF header size', self.e_ehsize),
                     ('Program headers size', self.e_phentsize),
                     ('Number of program headers', self.e_phnum),
                     ('Section headers size', self.e_shentsize),
                     ('Number of section headers', self.e_shnum),
                     ('String table section index', self.e_shstrndx),
                  ]
     return Elf_Ehdr_Common._repr_properties(self) + properties
示例#3
0
 def _repr_properties(self):
     properties = [
         (
             defines.SN_STRING, self.sh_name
         ),  # TODO: extract name of section from the string table in section specified by e_shstrndx
         (ST_STRING, ST_DESCRIPTION.get(self.sh_type, self.sh_type)),
         PERM_DESCRIPTION.get(self.flags,
                              self.flags)(defines.SA_STRING,
                                          hex_addr(self.sh_addr)),
         (defines.SO_STRING, hex_addr(self.sh_offset)),
         (defines.SS_STRING, hex_addr(self.sh_size)),
         (defines.SL_STRING, self.sh_link),
         (defines.SI_STRING, self.sh_info),
         (defines.SAL_STRING, self.sh_addralign),
         (defines.SE_STRING, hex_addr(self.sh_entsize))
     ]
     return [(attr, val) for attr, val in properties]
示例#4
0
    def validate_header(self, hdr):
        sign_assets_size = [hdr.sig_size + hdr.cert_chain_size]
        if hdr.supports_qti_signing():
            sign_assets_size += [hdr.sig_size_qti + hdr.cert_chain_size_qti,
                                 hdr.sig_size + hdr.cert_chain_size +
                                 hdr.sig_size_qti + hdr.cert_chain_size_qti +
                                 self.pad_max_sig_size - hdr.sig_size +
                                 self.pad_max_cert_chain_size - hdr.cert_chain_size]
        expected_image_size = [ALIGNED_IMAGE_SIZE(hdr.code_size + ss) for ss in sign_assets_size]

        if hdr.image_size not in expected_image_size:
            # Check for QTI sign asset related errors
            qti_segment, qti_err_string = '', ''
            if hdr.supports_qti_signing():
                qti_segment = ('    ' + 'QTI Signature Size:       ' + hex_addr(hdr.sig_size_qti) + '\n'
                               '    ' + 'QTI Cert Chain Size:      ' + hex_addr(hdr.cert_chain_size_qti) + '\n')

                # Handles case where incoming data header contains residual data in QTI sign/cc fields
                if (hdr.image_size + hdr.sig_size_qti + hdr.cert_chain_size_qti in expected_image_size or
                        hdr.cert_chain_size_qti == MBN_PTR_MAX):
                    qti_err_string = ('Unsigned hash table header must not contain junk data in '
                                      'QTI attribute fields when double-signing.' + '\n\n')

            raise RuntimeError('Mbn header verification failed. '
                               'Image size does not match the sum of its segments:' + '\n'
                               '\n'
                               '    ' + 'Code Size:               ' + hex_addr(hdr.code_size) + '\n' + qti_segment +
                               '    ' + 'Signature Size:          ' + hex_addr(hdr.sig_size) + '\n'
                               '    ' + 'Cert Chain Size:         ' + hex_addr(hdr.cert_chain_size) + '\n'
                               '    ' + 'Image Size (expected):  *' + str([hex_addr(s) for s in expected_image_size]) +
                               ' (Code + Signature + Cert Chain)' + '\n'
                               '    ' + 'Image Size (from file): *' + hex_addr(hdr.image_size) + '\n'
                               '\n' + qti_err_string +
                               'Header:' + '\n' + repr(hdr))
    def validate_header(self, hdr):
        expected_image_size = ALIGNED_IMAGE_SIZE(hdr.code_size +
                                                 hdr.sig_size +
                                                 hdr.cert_chain_size)

        if hdr.image_size != expected_image_size:
            raise RuntimeError('Mbn header verification failed. '
                               'Image size does not match the sum of its segments:' + '\n'
                               '\n'
                               '    ' + 'Code Size:               ' + hex_addr(hdr.code_size) + '\n'
                               '    ' + 'Signature Size:          ' + hex_addr(hdr.sig_size) + '\n'
                               '    ' + 'Cert Chain Size:         ' + hex_addr(hdr.cert_chain_size) + '\n'
                               '    ' + 'Image Size (expected):  *' + hex_addr(expected_image_size) + ' (Code + Signature + Cert Chain)' + '\n'
                               '    ' + 'Image Size (from file): *' + hex_addr(hdr.image_size) + '\n'
                               '\n'
                               'Header:' + '\n' +
                                repr(hdr)
                              )
 def _repr_properties(self):
     properties = [
         (PT_STRING, PT_DESCRIPTION.get(self.p_type, self.p_type)),
         (PO_STRING, hex_addr(self.p_offset)),
         (PV_STRING, hex_addr(self.p_vaddr)),
         (PP_STRING, hex_addr(self.p_paddr)),
         (PF_STRING, hex_addr(self.p_filesz)),
         (PM_STRING, hex_addr(self.p_memsz)),
         (PA_STRING, hex(self.p_align)),
         (PFL_STRING, hex_addr(self.p_flags)),
         (PF_PERM_STRING, PF_PERM_DESCRIPTION.get(self.f_perm,
                                                  self.f_perm)),
         (PF_OS_POOL_INDEX_STRING,
          PF_OS_POOL_INDEX_DESCRIPTION.get(self.f_os_pool_index,
                                           self.f_os_pool_index)),
         (PF_OS_SEGMENT_TYPE_STRING,
          PF_OS_SEGMENT_TYPE_DESCRIPTION.get(self.f_os_segment_type,
                                             self.f_os_segment_type)),
         (PF_OS_ACCESS_TYPE_STRING,
          PF_OS_ACCESS_TYPE_DESCRIPTION.get(self.f_os_access_type,
                                            self.f_os_access_type)),
         (PF_OS_PAGE_MODE_STRING,
          PF_OS_PAGE_MODE_DESCRIPTION.get(self.f_os_page_mode,
                                          self.f_os_page_mode)),
     ]
     return [(attr, val) for attr, val in properties]
示例#7
0
    def validate_header(self, hdr):
        expected_image_size = ALIGNED_IMAGE_SIZE(hdr.code_size + hdr.sig_size +
                                                 hdr.cert_chain_size)

        if hdr.image_size != expected_image_size:
            raise RuntimeError(
                'Mbn header verification failed. '
                'Image size does not match the sum of its segments:' + '\n'
                '\n'
                '    ' + 'Code Size:               ' +
                hex_addr(hdr.code_size) + '\n'
                '    ' + 'Signature Size:          ' + hex_addr(hdr.sig_size) +
                '\n'
                '    ' + 'Cert Chain Size:         ' +
                hex_addr(hdr.cert_chain_size) + '\n'
                '    ' + 'Image Size (expected):  *' +
                hex_addr(expected_image_size) +
                ' (Code + Signature + Cert Chain)' + '\n'
                '    ' + 'Image Size (from file): *' +
                hex_addr(hdr.image_size) + '\n'
                '\n'
                'Header:' + '\n' + repr(hdr))
示例#8
0
def repr_phdrs(phdrs):
    retval = TablePrinter()
    
    COLUMN_SNO      = 0
    COLUMN_TYPE     = 1
    COLUMN_OFF      = 2
    COLUMN_VADDR    = 3
    COLUMN_PADDR    = 4
    COLUMN_FSIZE    = 5
    COLUMN_MSIZE    = 6
    COLUMN_FLAGS    = 7
    COLUMN_ALIGN    = 8
    
    retval.insert_data(0, COLUMN_SNO, 'S.No')
    retval.insert_data(0, COLUMN_TYPE, 'Type')
    retval.insert_data(0, COLUMN_OFF, 'Offset')
    retval.insert_data(0, COLUMN_VADDR, 'VirtAddr')
    retval.insert_data(0, COLUMN_PADDR, 'PhysAddr')
    retval.insert_data(0, COLUMN_FSIZE, 'FileSize')
    retval.insert_data(0, COLUMN_MSIZE, 'MemSize')
    retval.insert_data(0, COLUMN_FLAGS, 'Flags')
    retval.insert_data(0, COLUMN_ALIGN, 'Align')
    
    stats = [0] * (COLUMN_ALIGN + 1)
    for idx, phdr in enumerate(phdrs):
        stats[COLUMN_OFF] = phdr.p_offset if phdr.p_offset > stats[COLUMN_OFF] else stats[COLUMN_OFF]
        stats[COLUMN_VADDR] = phdr.p_vaddr if phdr.p_vaddr > stats[COLUMN_VADDR] else stats[COLUMN_VADDR]
        stats[COLUMN_PADDR] = phdr.p_paddr if phdr.p_paddr > stats[COLUMN_PADDR] else stats[COLUMN_PADDR]
        stats[COLUMN_FSIZE] = phdr.p_filesz if phdr.p_filesz > stats[COLUMN_FSIZE] else stats[COLUMN_FSIZE]
        stats[COLUMN_MSIZE] = phdr.p_memsz if phdr.p_memsz > stats[COLUMN_MSIZE] else stats[COLUMN_MSIZE]
        stats[COLUMN_FLAGS] = phdr.p_flags if phdr.p_flags > stats[COLUMN_FLAGS] else stats[COLUMN_FLAGS]  
        
    for idx in range(COLUMN_ALIGN + 1):
        stats[idx] = len(hex(stats[idx]).rstrip('L'))-2
        
    for idx, phdr in enumerate(phdrs):
        retval.insert_data(idx+1, COLUMN_SNO, str(idx+1))
        retval.insert_data(idx+1, COLUMN_TYPE, PT_DESCRIPTION.get(phdr.p_type, phdr.p_type))
        retval.insert_data(idx+1, COLUMN_OFF, hex_addr(phdr.p_offset, stats[COLUMN_OFF]))
        retval.insert_data(idx+1, COLUMN_VADDR, hex_addr(phdr.p_vaddr, stats[COLUMN_VADDR]))
        retval.insert_data(idx+1, COLUMN_PADDR, hex_addr(phdr.p_paddr, stats[COLUMN_PADDR]))
        retval.insert_data(idx+1, COLUMN_FSIZE, hex_addr(phdr.p_filesz, stats[COLUMN_FSIZE]))
        retval.insert_data(idx+1, COLUMN_MSIZE, hex_addr(phdr.p_memsz, stats[COLUMN_MSIZE]))
        retval.insert_data(idx+1, COLUMN_FLAGS, hex_addr(phdr.p_flags, stats[COLUMN_FLAGS]))
        retval.insert_data(idx+1, COLUMN_ALIGN, hex(phdr.p_align), justify=retval.LEFT)
    return retval.get_data()
 def _repr_properties(self):
     properties = [
                   (PT_STRING, PT_DESCRIPTION.get(self.p_type, self.p_type)),
                   (PO_STRING, hex_addr(self.p_offset)),
                   (PV_STRING, hex_addr(self.p_vaddr)),
                   (PP_STRING, hex_addr(self.p_paddr)),
                   (PF_STRING, hex_addr(self.p_filesz)),
                   (PM_STRING, hex_addr(self.p_memsz)),
                   (PA_STRING, hex(self.p_align)),
                   (PFL_STRING, hex_addr(self.p_flags)),
                   (PF_PERM_STRING, PF_PERM_DESCRIPTION.get(self.f_perm, self.f_perm)),
                   (PF_OS_POOL_INDEX_STRING, PF_OS_POOL_INDEX_DESCRIPTION.get(self.f_os_pool_index, self.f_os_pool_index)),
                   (PF_OS_SEGMENT_TYPE_STRING, PF_OS_SEGMENT_TYPE_DESCRIPTION.get(self.f_os_segment_type, self.f_os_segment_type)),
                   (PF_OS_ACCESS_TYPE_STRING, PF_OS_ACCESS_TYPE_DESCRIPTION.get(self.f_os_access_type, self.f_os_access_type)),
                   (PF_OS_PAGE_MODE_STRING, PF_OS_PAGE_MODE_DESCRIPTION.get(self.f_os_page_mode, self.f_os_page_mode)),
                  ]
     return [(attr, val) for attr, val in properties]
def repr_phdrs(phdrs):
    retval = TablePrinter()

    COLUMN_SNO      = 0
    COLUMN_TYPE     = 1
    COLUMN_OFF      = 2
    COLUMN_VADDR    = 3
    COLUMN_PADDR    = 4
    COLUMN_FSIZE    = 5
    COLUMN_MSIZE    = 6
    COLUMN_FLAGS    = 7
    COLUMN_ALIGN    = 8

    retval.insert_data(0, COLUMN_SNO, 'S.No')
    retval.insert_data(0, COLUMN_TYPE, 'Type')
    retval.insert_data(0, COLUMN_OFF, 'Offset')
    retval.insert_data(0, COLUMN_VADDR, 'VirtAddr')
    retval.insert_data(0, COLUMN_PADDR, 'PhysAddr')
    retval.insert_data(0, COLUMN_FSIZE, 'FileSize')
    retval.insert_data(0, COLUMN_MSIZE, 'MemSize')
    retval.insert_data(0, COLUMN_FLAGS, 'Flags')
    retval.insert_data(0, COLUMN_ALIGN, 'Align')

    stats = [0] * (COLUMN_ALIGN + 1)
    for idx, phdr in enumerate(phdrs):
        stats[COLUMN_OFF] = phdr.p_offset if phdr.p_offset > stats[COLUMN_OFF] else stats[COLUMN_OFF]
        stats[COLUMN_VADDR] = phdr.p_vaddr if phdr.p_vaddr > stats[COLUMN_VADDR] else stats[COLUMN_VADDR]
        stats[COLUMN_PADDR] = phdr.p_paddr if phdr.p_paddr > stats[COLUMN_PADDR] else stats[COLUMN_PADDR]
        stats[COLUMN_FSIZE] = phdr.p_filesz if phdr.p_filesz > stats[COLUMN_FSIZE] else stats[COLUMN_FSIZE]
        stats[COLUMN_MSIZE] = phdr.p_memsz if phdr.p_memsz > stats[COLUMN_MSIZE] else stats[COLUMN_MSIZE]
        stats[COLUMN_FLAGS] = phdr.p_flags if phdr.p_flags > stats[COLUMN_FLAGS] else stats[COLUMN_FLAGS]

    for idx in range(COLUMN_ALIGN + 1):
        stats[idx] = len(hex(stats[idx]).rstrip('L'))-2

    for idx, phdr in enumerate(phdrs):
        retval.insert_data(idx+1, COLUMN_SNO, str(idx+1))
        retval.insert_data(idx+1, COLUMN_TYPE, PT_DESCRIPTION.get(phdr.p_type, phdr.p_type))
        retval.insert_data(idx+1, COLUMN_OFF, hex_addr(phdr.p_offset, stats[COLUMN_OFF]))
        retval.insert_data(idx+1, COLUMN_VADDR, hex_addr(phdr.p_vaddr, stats[COLUMN_VADDR]))
        retval.insert_data(idx+1, COLUMN_PADDR, hex_addr(phdr.p_paddr, stats[COLUMN_PADDR]))
        retval.insert_data(idx+1, COLUMN_FSIZE, hex_addr(phdr.p_filesz, stats[COLUMN_FSIZE]))
        retval.insert_data(idx+1, COLUMN_MSIZE, hex_addr(phdr.p_memsz, stats[COLUMN_MSIZE]))
        retval.insert_data(idx+1, COLUMN_FLAGS, hex_addr(phdr.p_flags, stats[COLUMN_FLAGS]))
        retval.insert_data(idx+1, COLUMN_ALIGN, hex(phdr.p_align), justify=retval.LEFT)
    return retval.get_data()
示例#11
0
def repr_shdrs(shdrs, sno_range=None):
    retval = TablePrinter()

    COLUMN_SNO = 0
    COLUMN_NAME = 1
    COLUMN_TYPE = 2
    COLUMN_ADDR = 3
    COLUMN_OFF = 4
    COLUMN_SIZE = 5
    COLUMN_ENTSIZE = 6
    COLUMN_FLAGS = 7
    COLUMN_LINK = 8
    COLUMN_INFO = 9
    COLUMN_ALIGN = 10

    retval.insert_data(0, COLUMN_SNO, 'Num')
    retval.insert_data(0, COLUMN_NAME, 'Name')
    retval.insert_data(0, COLUMN_TYPE, 'Type')
    retval.insert_data(0, COLUMN_ADDR, 'Addr')
    retval.insert_data(0, COLUMN_OFF, 'Offset')
    retval.insert_data(0, COLUMN_SIZE, 'Size')
    retval.insert_data(0, COLUMN_ENTSIZE, 'EntSize')
    retval.insert_data(0, COLUMN_FLAGS, 'Flags')
    retval.insert_data(0, COLUMN_LINK, 'Link')
    retval.insert_data(0, COLUMN_INFO, 'Info')
    retval.insert_data(0, COLUMN_ALIGN, 'Align')

    stats = [0] * (COLUMN_ALIGN + 1)
    for idx, shdr in enumerate(shdrs):
        stats[COLUMN_ADDR] = shdr.sh_addr if shdr.sh_addr > stats[
            COLUMN_ADDR] else stats[COLUMN_ADDR]
        stats[COLUMN_OFF] = shdr.sh_offset if shdr.sh_offset > stats[
            COLUMN_OFF] else stats[COLUMN_OFF]
        stats[COLUMN_SIZE] = shdr.sh_size if shdr.sh_size > stats[
            COLUMN_SIZE] else stats[COLUMN_SIZE]
        stats[COLUMN_ENTSIZE] = shdr.sh_entsize if shdr.sh_entsize > stats[
            COLUMN_ENTSIZE] else stats[COLUMN_ENTSIZE]

    for idx in range(COLUMN_ALIGN + 1):
        stats[idx] = len(hex(stats[idx]).rstrip('L')) - 2

    if sno_range is None:
        sno_range = range(1, len(shdrs) + 1)

    for idx, shdr in enumerate(shdrs):
        retval.insert_data(idx + 1, COLUMN_SNO, str(sno_range[idx]))
        retval.insert_data(idx + 1,
                           COLUMN_NAME,
                           shdr.sh_name_str,
                           justify=retval.LEFT)
        retval.insert_data(idx + 1,
                           COLUMN_TYPE,
                           str(ST_DESCRIPTION.get(shdr.sh_type, shdr.sh_type)),
                           justify=retval.LEFT)
        retval.insert_data(idx + 1, COLUMN_ADDR,
                           hex_addr(shdr.sh_addr, stats[COLUMN_ADDR]))
        retval.insert_data(idx + 1, COLUMN_OFF,
                           hex_addr(shdr.sh_offset, stats[COLUMN_OFF]))
        retval.insert_data(idx + 1, COLUMN_SIZE,
                           hex_addr(shdr.sh_size, stats[COLUMN_SIZE]))
        retval.insert_data(idx + 1, COLUMN_ENTSIZE,
                           hex_addr(shdr.sh_entsize, stats[COLUMN_ENTSIZE]))
        retval.insert_data(idx + 1, COLUMN_FLAGS,
                           PERM_DESCRIPTION.get(shdr.flags, ""))
        retval.insert_data(idx + 1, COLUMN_LINK, shdr.sh_link)
        retval.insert_data(idx + 1, COLUMN_INFO, shdr.sh_info)
        retval.insert_data(idx + 1, COLUMN_ALIGN, shdr.sh_addralign)
    return retval.get_data()