Beispiel #1
0
 def cmdline(self):
     return [
         get_tool_name('objdump'),
     ] + self.objdump_options() + [
         '--section={}'.format(self._section_name),
         self.path,
     ]
Beispiel #2
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()
Beispiel #3
0
    def base_options():
        if not hasattr(ReadElfSection, "_base_options"):
            output = our_check_output(
                [get_tool_name("readelf"), "--help"],
                stderr=subprocess.DEVNULL,
            ).decode("us-ascii", errors="replace")

            ReadElfSection._base_options = []
            for x in ("--decompress", ):
                if x in output:
                    ReadElfSection._base_options.append(x)
        return ReadElfSection._base_options
Beispiel #4
0
    def base_options():
        if not hasattr(ReadElfSection, '_base_options'):
            output = subprocess.check_output(
                [get_tool_name('readelf'), '--help'],
                shell=False,
                stderr=subprocess.DEVNULL,
            ).decode('us-ascii', errors='replace')

            ReadElfSection._base_options = []
            for x in ('--decompress', ):
                if x in output:
                    ReadElfSection._base_options.append(x)
        return ReadElfSection._base_options
Beispiel #5
0
def get_debug_link(path):
    try:
        output = subprocess.check_output(
            [get_tool_name('readelf'), '--string-dump=.gnu_debuglink', path],
            stderr=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        logger.debug("Unable to get Build Id for %s: %s", path, e)
        return None

    m = re.search(r'^\s+\[\s+0\]\s+(\S+)$',
                  output.decode('utf-8', errors='replace'),
                  flags=re.MULTILINE)
    if not m:
        return None

    return m.group(1)
Beispiel #6
0
def get_build_id(path):
    try:
        output = subprocess.check_output(
            [get_tool_name('readelf'), '--notes', path],
            stderr=subprocess.DEVNULL,
        )
    except subprocess.CalledProcessError as e:
        logger.debug("Unable to get Build ID for %s: %s", path, e)
        return None

    m = re.search(r'^\s+Build ID: ([0-9a-f]+)$',
                  output.decode('utf-8'),
                  flags=re.MULTILINE)
    if not m:
        return None

    return m.group(1)
Beispiel #7
0
 def cmdline(self):
     return ([get_tool_name('readelf'), '--wide'] + self.readelf_options() +
             [self.path])
Beispiel #8
0
 def objcopy(*args):
     subprocess.check_call(
         (get_tool_name('objcopy'), ) + args,
         shell=False,
         stderr=subprocess.DEVNULL,
     )
Beispiel #9
0
 def objcopy(*args):
     our_check_output(
         (get_tool_name("objcopy"), ) + args,
         shell=False,
         stderr=subprocess.DEVNULL,
     )
Beispiel #10
0
 def cmdline(self):
     return ([get_tool_name("readelf"), "--wide"] + self.readelf_options() +
             [self.path])
Beispiel #11
0
 def cmdline(self):
     return ([get_tool_name("objdump")] + self.objdump_options() +
             ["--section={}".format(self._section_name), self.path])