예제 #1
0
파일: plugin.c 프로젝트: Winter3un/ctf_task
int
bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file)
{
  bfd *iobfd;

  iobfd = ibfd;
  if (ibfd->my_archive && !bfd_is_thin_archive (ibfd->my_archive))
    iobfd = ibfd->my_archive;
  file->name = iobfd->filename;

  if (!iobfd->iostream && !bfd_open_file (iobfd))
    return 0;

  file->fd = fileno ((FILE *) iobfd->iostream);

  if (iobfd == ibfd)
    {
      struct stat stat_buf;
      if (fstat (file->fd, &stat_buf))
        return 0;
      file->offset = 0;
      file->filesize = stat_buf.st_size;
    }
  else
    {
      file->offset = ibfd->origin;
      file->filesize = arelt_size (ibfd);
    }
  return 1;
}
예제 #2
0
static const bfd_target *
bfd_plugin_object_p (bfd *abfd)
{
  int claimed = 0;
  struct ld_plugin_input_file file;
  bfd *iobfd;
  static int have_loaded = 0;
  static int have_plugin = 0;

  if (!have_loaded)
    {
      have_loaded = 1;
      have_plugin = load_plugin ();
    }
  if (!have_plugin)
    return NULL;

  file.name = abfd->filename;

  if (abfd->my_archive)
    {
      iobfd = abfd->my_archive;
      file.offset = abfd->origin;
      file.filesize = arelt_size (abfd);
    }
  else
    {
      iobfd = abfd;
      file.offset = 0;
      file.filesize = 0;
    }

  if (!iobfd->iostream && !bfd_open_file (iobfd))
    return NULL;

  file.fd = fileno ((FILE *) iobfd->iostream);

  if (!abfd->my_archive)
    {
      struct stat stat_buf;
      if (fstat (file.fd, &stat_buf))
        return NULL;
      file.filesize = stat_buf.st_size;
    }

  file.handle = abfd;
  off_t cur_offset = lseek(file.fd, 0, SEEK_CUR);
  claim_file (&file, &claimed);
  lseek(file.fd, cur_offset, SEEK_SET);
  if (!claimed)
    return NULL;

  return abfd->xvec;
}
예제 #3
0
static int
try_claim (bfd *abfd)
{
  int claimed = 0;
  struct ld_plugin_input_file file;
  bfd *iobfd;

  file.name = abfd->filename;

  if (abfd->my_archive)
    {
      iobfd = abfd->my_archive;
      file.offset = abfd->origin;
      file.filesize = arelt_size (abfd);
    }
  else
    {
      iobfd = abfd;
      file.offset = 0;
      file.filesize = 0;
    }

  if (!iobfd->iostream && !bfd_open_file (iobfd))
    return 0;

  file.fd = fileno ((FILE *) iobfd->iostream);

  if (!abfd->my_archive)
    {
      struct stat stat_buf;
      if (fstat (file.fd, &stat_buf))
        return 0;
      file.filesize = stat_buf.st_size;
    }

  file.handle = abfd;
  off_t cur_offset = lseek(file.fd, 0, SEEK_CUR);
  claim_file (&file, &claimed);
  lseek(file.fd, cur_offset, SEEK_SET);
  if (!claimed)
    return 0;

  return 1;
}
예제 #4
0
파일: cache.c 프로젝트: Winter3un/ctf_task
static FILE *
bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag)
{
  bfd *orig_bfd = abfd;
  if ((abfd->flags & BFD_IN_MEMORY) != 0)
    abort ();

  while (abfd->my_archive != NULL
	 && !bfd_is_thin_archive (abfd->my_archive))
    abfd = abfd->my_archive;

  if (abfd->iostream != NULL)
    {
      /* Move the file to the start of the cache.  */
      if (abfd != bfd_last_cache)
	{
	  snip (abfd);
	  insert (abfd);
	}
      return (FILE *) abfd->iostream;
    }

  if (flag & CACHE_NO_OPEN)
    return NULL;

  if (bfd_open_file (abfd) == NULL)
    ;
  else if (!(flag & CACHE_NO_SEEK)
	   && _bfd_real_fseek ((FILE *) abfd->iostream,
			       abfd->where, SEEK_SET) != 0
	   && !(flag & CACHE_NO_SEEK_ERROR))
    bfd_set_error (bfd_error_system_call);
  else
    return (FILE *) abfd->iostream;

  /* xgettext:c-format */
  _bfd_error_handler (_("reopening %B: %s\n"),
		      orig_bfd, bfd_errmsg (bfd_get_error ()));
  return NULL;
}