/*
** plt.c for libelfsh
** 
** Started on  Tue Jul 24 06:40:07 2001 mayhem
** Last update Sun Mar 10 08:38:03 2002 mayhem
*/
#include "libelfsh.h"



/* Load the Procedure Linkage Table */
Elfsh32_Sect	*elfsh_get_plt(Elfsh32_Obj *file, int *num)
{
  Elfsh32_Sect	*actual;
  void		*ret;

  if (!elfsh_get_sht(file, NULL))
    return (NULL);

  for (actual = file->sections; actual; actual = actual->next)
    if (elfsh_is_plt(file, actual->shdr))
      {
	ret = elfsh_get_anonymous_section(file, actual);
	file->plt = actual;
	return (ret ? actual : NULL);
      }
  
  return (NULL);
}





/* Return 1 if the section is the plt or 0 if its not */
int		elfsh_is_plt(Elfsh32_Obj *file, Elf32_Shdr *sct)
{
  if (!strcmp(elfsh_get_section_name(file, sct), ELFSH_SECTION_NAME_PLT))
    return (1);
  return (0);
}




/* Return 1 if the symbol points in the PLT, 0 if not, -1 if the PLT cant be found */
int			elfsh_is_pltentry(Elfsh32_Obj *file, Elf32_Sym *sym)
{
  if (!elfsh_get_plt(file, NULL))
    return (-1);
  if (INTERVAL(file->plt->shdr->sh_addr, sym->st_value, file->plt->shdr->sh_addr + file->plt->shdr->sh_size))
    return (1);
  return (0);
}
































