parameters: (executable)
return_statement: return headers
docstring: Return type and flags for ELF program headers
docstring_summary: Return type and flags for ELF program headers
docstring_tokens: Return type and flags for ELF program headers
function: def get_ELF_program_headers(executable):
      '''Return type and flags for ELF program headers'''
      p = subprocess.Popen([READELF_CMD, '-l', '-W', executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
      (stdout, stderr) = p.communicate()
      if p.returncode:
          raise IOError('Error opening file')
      in_headers = False
      count = 0
      headers = []
      for line in stdout.split(b'\n'):
          if line.startswith(b'Program Headers:'):
              in_headers = True
          if line == b'':
              in_headers = False
          if in_headers:
              if count == 1: # header line
                  ofs_typ = line.find(b'Type')
                  ofs_offset = line.find(b'Offset')
                  ofs_flags = line.find(b'Flg')
                  ofs_align = line.find(b'Align')
                  if ofs_typ == -1 or ofs_offset == -1 or ofs_flags == -1 or ofs_align  == -1:
                      raise ValueError('Cannot parse elfread -lW output')
              elif count > 1:
                  typ = line[ofs_typ:ofs_offset].rstrip()
                  flags = line[ofs_flags:ofs_align].rstrip()
                  headers.append((typ, flags))
              count += 1
      return headers
function_tokens: def get_ELF_program_headers ( executable ) : p = subprocess . Popen ( [ READELF_CMD , '-l' , '-W' , executable ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE , stdin = subprocess . PIPE ) ( stdout , stderr ) = p . communicate ( ) if p . returncode : raise IOError ( 'Error opening file' ) in_headers = False count = 0 headers = [ ] for line in stdout . split ( b'\n' ) : if line . startswith ( b'Program Headers:' ) : in_headers = True if line == b'' : in_headers = False if in_headers : if count == 1 : # header line ofs_typ = line . find ( b'Type' ) ofs_offset = line . find ( b'Offset' ) ofs_flags = line . find ( b'Flg' ) ofs_align = line . find ( b'Align' ) if ofs_typ == - 1 or ofs_offset == - 1 or ofs_flags == - 1 or ofs_align == - 1 : raise ValueError ( 'Cannot parse elfread -lW output' ) elif count > 1 : typ = line [ ofs_typ : ofs_offset ] . rstrip ( ) flags = line [ ofs_flags : ofs_align ] . rstrip ( ) headers . append ( ( typ , flags ) ) count += 1 return headers