/*
** dyn.c for elfsh
** 
** Started on  Fri Nov  2 15:17:36 2001 mayhem
** Last update Sat Mar 23 18:22:37 2002 mayhem
*/
#include "elfsh.h"






/* Display the .dynamic section entries */
int		display_dyn(Elfsh32_Obj *file, argv_t *args)
{
  Elf32_Dyn	*actual;
  int		num;
  int		index;
  int		typenum;
  char		*type;
  char		*type_short;
  regex_t	*tmp;
  char		buff[256];
  
  if ((actual = elfsh_get_dynamic(file, &num)) == NULL)
    RET(-1);
  
  tmp = (REGX_IS_USED(args->dyn_use_regx) ? &args->dyn_regx : 
	 REGX_IS_USED(args->gl_use_regx)  ? &args->gl_regx : NULL);
  
  puts("\n[SHT_DYNAMIC]");
  
  for (index = 0; index < num && actual[index].d_tag != DT_NULL; index++)
    {
      
      typenum = elfsh_get_dynentry_type(actual + index);

      type = (typenum >= DYNAMIC_MAX ? "*Unknown*" : elfsh_dynentry_type[typenum]);
      type_short = (typenum >= DYNAMIC_MAX ? "*Unknown*" : elfsh_dynentry_type_short[typenum]);

      snprintf(buff, sizeof(buff), "\t%-40s => \t\t %20s \t {%s}", 
	       type, elfsh_get_dynentry_info(file, actual + index), type_short);

      if (!tmp || (tmp && !regexec(tmp, buff, 0, 0, 0)))
	puts(buff);

    }
  
  puts("");
  return (0);
}







