def read_symbols(executable, imports=True):
    '\n    Parse an ELF executable and return a list of (symbol,version) tuples\n    for dynamic, imported symbols.\n    '
    p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    (stdout, stderr) = p.communicate()
    if p.returncode:
        raise IOError(('Could not read symbols for %s: %s' % (executable, stderr.strip())))
    syms = []
    for line in stdout.split(b'\n'):
        line = line.split()
        if ((len(line) > 7) and re.match(b'[0-9]+:$', line[0])):
            (sym, _, version) = line[7].partition(b'@')
            is_import = (line[6] == b'UND')
            if version.startswith(b'@'):
                version = version[1:]
            if (is_import == imports):
                syms.append((sym, version))
    return syms
Parse an ELF executable and return a list of (symbol,version) tuples
for dynamic, imported symbols.
def read_symbols(executable, imports=True):
    '\n    Parse an ELF executable and return a list of (symbol,version) tuples\n    for dynamic, imported symbols.\n    '
    p = subprocess.Popen([READELF_CMD, '--dyn-syms', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    (stdout, stderr) = p.communicate()
    if p.returncode:
        raise IOError(('Could not read symbols for %s: %s' % (executable, stderr.strip())))
    syms = []
    for line in stdout.split(b'\n'):
        line = line.split()
        if ((len(line) > 7) and re.match(b'[0-9]+:$', line[0])):
            (sym, _, version) = line[7].partition(b'@')
            is_import = (line[6] == b'UND')
            if version.startswith(b'@'):
                version = version[1:]
            if (is_import == imports):
                syms.append((sym, version))
    return syms