/*
** elf.c for elfsh
** 
** Started on  Fri Nov  2 15:21:14 2001 mayhem
** Last update Sat Mar 23 08:23:19 2002 mayhem
*/
#include "elfsh.h"









/* Display the elf header */
int		display_elf(Elfsh32_Obj *file, argv_t *av)
{
  Elf32_Ehdr	*header;
  u_int		archnum;
  u_int		typenum;
  char		*type;
  char		*arch;

  if ((header = elfsh_get_hdr(file)) == NULL)
    RET(-1);

  archnum = elfsh_get_arch(header);
  typenum = elfsh_get_objtype(header);
  arch = (archnum >= ARCHTYPE_MAX ? "Unknown" : elfsh_arch_type[archnum]);
  type = (typenum >= OBJTYPE_MAX  ? "Unknown" : elfsh_obj_type[typenum]);
  
  puts("\n[ELF HEADER]");
  printf("Architecture       : %18s   \t"
	 "ELF Version        : %10u   \n"
	 "Object type        : %18s   \t"
	 "Entry point        : %10p   \n"
	 "PHT foffset        : %18u   \t"
	 "SHT foffset        : %10u   \n"
	 "PHT entries number : %18u   \t"
	 "SHT entries number : %10u   \n"
	 "PHT entry size     : %18u   \t"
	 "SHT entry size     : %10u   \n"
	 "ELF header size    : %18u   \t"
	 "SHT strtab index   : %10u \n\n",
	 arch,
	 header->e_version, 
	 type,
	 (void *) header->e_entry,
	 header->e_phoff,
	 header->e_shoff,
	 header->e_phnum,
	 header->e_shnum,
	 header->e_phentsize,
	 header->e_shentsize,
	 header->e_ehsize,
	 header->e_shstrndx);

  return (0);
}
