Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        logger.debug("Creating ElfContainer for %s", self.source.path)

        cmd = [
            get_tool_name('readelf'), '--wide', '--section-headers',
            self.source.path
        ]
        output = subprocess.check_output(cmd,
                                         shell=False,
                                         stderr=subprocess.DEVNULL)
        has_debug_symbols = False

        try:
            output = output.decode('utf-8').split('\n')
            if output[1].startswith('File:'):
                output = output[2:]
            output = output[5:]

            # Entries of readelf --section-headers have the following columns:
            # [Nr]  Name  Type  Address  Off  Size  ES  Flg  Lk  Inf  Al
            self._sections = collections.OrderedDict()
            for line in output:
                if line.startswith('Key to Flags'):
                    break

                # Strip number column because there may be spaces in the brakets
                line = line.split(']', 1)[1].split()
                name, type, flags = line[0], line[1], line[6] + '_'

                if name.startswith('.debug') or name.startswith('.zdebug'):
                    has_debug_symbols = True

                if _should_skip_section(name, type):
                    continue

                # Use first match, with last option being '_' as fallback
                elf_class = [
                    ElfContainer.SECTION_FLAG_MAPPING[x] for x in flags
                    if x in ElfContainer.SECTION_FLAG_MAPPING
                ][0]

                logger.debug("Adding section %s (%s) as %s", name, type,
                             elf_class)
                self._sections[name] = elf_class(self, name)

        except Exception as e:
            command = ' '.join(cmd)
            logger.debug(
                "OutputParsingError in %s from `%s` output - %s:%s",
                self.__class__.__name__,
                command,
                e.__class__.__name__,
                e,
            )
            raise OutputParsingError(command, self)

        if not has_debug_symbols:
            self._install_debug_symbols()
Exemplo n.º 2
0
 def compare_details(self, other, source=None):
     subprocess.check_output(['sh', '-c', 'exit 0'], shell=False)
     raise OutputParsingError('sh', self)