native_client_sdk/src/tools/lib/elf.py
def ParseElfHeader(path):
  """Determine properties of a nexe by parsing elf header.
  Return tuple of architecture and boolean signalling whether
  the executable is dynamic (has INTERP header) or static.
  """
  # From elf.h:
  # typedef struct
  # {
  #   unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
  #   Elf64_Half e_type; /* Object file type */
  #   Elf64_Half e_machine; /* Architecture */
  #   ...
  # } Elf32_Ehdr;
  elf_header_format = '16s2H'
  elf_header_size = struct.calcsize(elf_header_format)

  with open(path, 'rb') as f:
    header = f.read(elf_header_size)

  try:
    header = struct.unpack(elf_header_format, header)
  except struct.error:
    raise Error("error parsing elf header: %s" % path)
  e_ident, _, e_machine = header[:3]

  elf_magic = b'\x7fELF'
  if e_ident[:4] != elf_magic:
    raise Error('Not a valid NaCl executable: %s' % path)

  e_machine_mapping = {
    3 : 'x86-32',
    8 : 'mips32',
    40 : 'arm',
    62 : 'x86-64'
  }
  if e_machine not in e_machine_mapping:
    raise Error('Unknown machine type: %s' % e_machine)

  # Set arch based on the machine type in the elf header
  arch = e_machine_mapping[e_machine]

  # Now read the full header in either 64bit or 32bit mode
  dynamic = IsDynamicElf(path, arch == 'x86-64')
  return arch, dynamic
Determine properties of a nexe by parsing elf header.
  Return tuple of architecture and boolean signalling whether
  the executable is dynamic (has INTERP header) or static.
  
Determine properties of a nexe by parsing elf header.
Return tuple of architecture and boolean signalling whether
the executable is dynamic (has INTERP header) or static.
Determine properties of a nexe by parsing elf header . Return tuple of architecture and boolean signalling whether the executable is dynamic ( has INTERP header ) or static .
def ParseElfHeader(path):
  elf_header_format = '16s2H'
  elf_header_size = struct.calcsize(elf_header_format)
  with open(path, 'rb') as f:
    header = f.read(elf_header_size)
  try:
    header = struct.unpack(elf_header_format, header)
  except struct.error:
    raise Error("error parsing elf header: %s" % path)
  e_ident, _, e_machine = header[:3]
  elf_magic = b'\x7fELF'
  if e_ident[:4] != elf_magic:
    raise Error('Not a valid NaCl executable: %s' % path)
  e_machine_mapping = {
    3 : 'x86-32',
    8 : 'mips32',
    40 : 'arm',
    62 : 'x86-64'
  }
  if e_machine not in e_machine_mapping:
    raise Error('Unknown machine type: %s' % e_machine)
  arch = e_machine_mapping[e_machine]
  dynamic = IsDynamicElf(path, arch == 'x86-64')
  return arch, dynamic
def ParseElfHeader ( path ) : elf_header_format = '16s2H' elf_header_size = struct . calcsize ( elf_header_format ) with open ( path , 'rb' ) as f : header = f . read ( elf_header_size ) try : header = struct . unpack ( elf_header_format , header ) except struct . error : raise Error ( "error parsing elf header: %s" % path ) e_ident , _ , e_machine = header [ : 3 ] elf_magic = b'\x7fELF' if e_ident [ : 4 ] != elf_magic : raise Error ( 'Not a valid NaCl executable: %s' % path ) e_machine_mapping = { 3 : 'x86-32' , 8 : 'mips32' , 40 : 'arm' , 62 : 'x86-64' } if e_machine not in e_machine_mapping : raise Error ( 'Unknown machine type: %s' % e_machine ) arch = e_machine_mapping [ e_machine ] dynamic = IsDynamicElf ( path , arch == 'x86-64' ) return arch , dynamic
Determine properties of a nexe by parsing elf header.
Determine properties of a nexe by parsing elf header .
"""Determine properties of a nexe by parsing elf header.
  Return tuple of architecture and boolean signalling whether
  the executable is dynamic (has INTERP header) or static.
  """ # From elf.h: # typedef struct # { #   unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ #   Elf64_Half e_type; /* Object file type */ #   Elf64_Half e_machine; /* Architecture */ #   ... # } Elf32_Ehdr; # Set arch based on the machine type in the elf header # Now read the full header in either 64bit or 32bit mode
path