def __repr__(self): return properties_repr([("Segment Size", str(self.get_size()) + "B"), ("namesz", self.namesz), ("descsz", self.descsz), ("type", self.type), ("name", self.name), ("version", self.version), ("client_id", hex_addr(self.client_id)), ("lib_id", hex_addr(self.lib_id)), ("is_cass_signed", self.is_cass_signed)])
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()
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]
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__(self): image_entries = list() index = 1 for (sw_id, app_id), _ in self.image_hash_dict.iteritems(): image_entries.append( ("Entry " + str(index), "SW_ID: " + hex_addr(sw_id) + " APP_ID: " + hex_addr(app_id))) index += 1 return "Header:\n" + properties_repr([("Segment Size", str(self.get_size())+"B"), ("Magic", self.magic_number), ("Version", self.version), ("Hash Algorithm", self.hash_algorithm), ("Num Image Entries", len(self.image_hash_dict)), ]) + \ 'Image Entries: ' + '\n' + properties_repr(image_entries)
def __repr__(self): return ('Base Properties: ' + '\n' + SecParseGenBase.__repr__(self) + '\n' 'ELF Properties: ' + '\n' + repr(self._elf_parsegen) + '\n' 'Hash Segment Properties: ' + '\n' + repr(self._mbn_parsegen) + '\n' 'SecElf Properties: ' + '\n' '' + properties_repr([('image_type', self.image_type), ('testsig_serialnum', hex_addr(self.serial_num) if self.serial_num is not None else self.serial_num),]))
def __repr__(self): return ('Base Properties: ' + '\n' + SecParseGenBase.__repr__(self) + '\n' 'ELF Properties: ' + '\n' + repr(self._elf_parsegen) + '\n' 'Hash Segment Properties: ' + '\n' + repr(self._mbn_parsegen) + '\n' 'SecElf Properties: ' + '\n' '' + properties_repr([('image_type', self.image_type), ('testsig_serialnum', hex_addr(self.serial_num) if self.serial_num is not None else self.serial_num),]))
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__(self): def segment_properties(seg, segment_name): if seg: return segment_name + ' Segment Properties: ' + '\n' + repr(seg) + '\n' else: return '' return ('Base Properties: ' + '\n' + SecParseGenBase.__repr__(self) + '\n' 'ELF Properties: ' + '\n' + repr(self._elf_parsegen) + '\n' 'Hash Segment Properties: ' + '\n' + repr(self._mbn_parsegen) + '\n' + segment_properties(self._license_manager_segment, 'License Manager') + 'SecElf Properties: ' + '\n' '' + properties_repr([('image_type', self.image_type), ('max_elf_segments', self.max_elf_segments), ('testsig_serialnum', hex_addr(self.serial_num) if self.serial_num is not None else self.serial_num), ]))
def validate_header(self, hdr): possible_image_sizes = self._compute_possible_image_sizes(hdr) try: extracted_max_num_root_certs = possible_image_sizes[hdr.image_size] if (self.config_max_num_root_certs and extracted_max_num_root_certs is not None and extracted_max_num_root_certs != self.config_max_num_root_certs): error_str = [] create_mismatch_table( [("max_num_root_certs", extracted_max_num_root_certs, self.config_max_num_root_certs)], error_str, operation="signing", image_region="Hash Segment") raise RuntimeError("\n".join(error_str)) except KeyError: # 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 possible_image_sizes 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: Code Size: {header_code_size} {qti_segment} Signature Size: {signature_size} Cert Chain Size: {cert_chain_size} Image Size (expected): *{expected_image_size} Image Size (from file): *{image_size} {qti_err_string} Header: {header} """.format(header_code_size=hex_addr(hdr.code_size), qti_segment=qti_segment, signature_size=hex_addr(hdr.sig_size), cert_chain_size=hex_addr(hdr.cert_chain_size), expected_image_size=(str([hex_addr(s) for s in possible_image_sizes]) + ' (Code + Signature + Cert Chain)'), image_size=hex_addr(hdr.image_size), qti_err_string=qti_err_string, header=repr(hdr)))
def repr_phdrs(phdrs, sno_range=None): 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, 'Num') 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 if sno_range is None: sno_range = range(1, len(phdrs) + 1) for idx, phdr in enumerate(phdrs): retval.insert_data(idx + 1, COLUMN_SNO, str(sno_range[idx])) retval.insert_data(idx + 1, COLUMN_TYPE, str(PT_DESCRIPTION.get(phdr.p_type, phdr.p_type)), justify=retval.LEFT) 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, PF_PERM_DESCRIPTION.get( phdr.f_perm, 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()