/* Read resource file */
rc_res_directory *
read_res_file (const char *fn)
{
    rc_uint_type off, flen;
    windres_bfd wrbfd;
    bfd *abfd;
    asection *sec;
    filename = fn;

    flen = (rc_uint_type) get_file_size (filename);
    if (! flen)
        fatal ("can't open '%s' for input.", filename);
    abfd = windres_open_as_binary (filename, 1);
    sec = bfd_get_section_by_name (abfd, ".data");
    if (sec == NULL)
        bfd_fatal ("bfd_get_section_by_name");
    set_windres_bfd (&wrbfd, abfd, sec,
                     (target_is_bigendian ? WR_KIND_BFD_BIN_B
                      : WR_KIND_BFD_BIN_L));
    off = 0;

    if (! probe_binary (&wrbfd, flen))
        set_windres_bfd_endianess (&wrbfd, ! target_is_bigendian);

    skip_null_resource (&wrbfd, &off, flen);

    while (read_resource_entry (&wrbfd, &off, flen))
        ;

    bfd_close (abfd);

    return resources;
}
示例#2
0
/* Write resource file */
void
write_res_file (const char *fn,const rc_res_directory *resdir)
{
  asection *sec;
  rc_uint_type language;
  bfd *abfd;
  windres_bfd wrbfd;
  unsigned long sec_length = 0,sec_length_wrote;
  static const bfd_byte sign[] =
  {0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
   0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  filename = fn;

  abfd = windres_open_as_binary (filename, 0);
  sec = bfd_make_section (abfd, ".data");
  if (sec == NULL)
    bfd_fatal ("bfd_make_section");
  if (! bfd_set_section_flags (abfd, sec,
			       (SEC_HAS_CONTENTS | SEC_ALLOC
			        | SEC_LOAD | SEC_DATA)))
    bfd_fatal ("bfd_set_section_flags");
  /* Requiring this is probably a bug in BFD.  */
  sec->output_section = sec;

  set_windres_bfd (&wrbfd, abfd, sec,
		   (target_is_bigendian ? WR_KIND_BFD_BIN_B
					: WR_KIND_BFD_BIN_L));

  language = -1;
  sec_length = write_res_directory ((windres_bfd *) NULL, 0x20UL, resdir,
				    (const rc_res_id *) NULL,
				    (const rc_res_id *) NULL, &language, 1);
  if (! bfd_set_section_size (abfd, sec, (sec_length + 3) & ~3))
    bfd_fatal ("bfd_set_section_size");
  if ((sec_length & 3) != 0)
    set_windres_bfd_content (&wrbfd, sign, sec_length, 4-(sec_length & 3));
  set_windres_bfd_content (&wrbfd, sign, 0, sizeof (sign));
  language = -1;
  sec_length_wrote = write_res_directory (&wrbfd, 0x20UL, resdir,
					  (const rc_res_id *) NULL,
					  (const rc_res_id *) NULL,
					  &language, 1);
  if (sec_length != sec_length_wrote)
    fatal ("res write failed with different sizes (%lu/%lu).", (long) sec_length,
    	   (long) sec_length_wrote);

  bfd_close (abfd);
  return;
}