/* resbin.c -- manipulate the Windows binary resource format.
- Copyright 1997 Free Software Foundation, Inc.
+ Copyright 1997, 1998, 1999, 2002, 2003
+ Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
This file is part of GNU Binutils.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+ 02110-1301, USA. */
/* This file contains functions to convert between the binary resource
format and the internal structures that we want to use. The same
/* Macros to swap in values. */
+#define get_8(s) (*((unsigned char *)(s)))
#define get_16(be, s) ((be) ? bfd_getb16 (s) : bfd_getl16 (s))
#define get_32(be, s) ((be) ? bfd_getb32 (s) : bfd_getl32 (s))
/* Local functions. */
-static void toosmall PARAMS ((const char *));
+static void toosmall (const char *);
+
static unichar *get_unicode
- PARAMS ((const unsigned char *, unsigned long, int, int *));
+ (const unsigned char *, unsigned long, int, int *);
static int get_resid
- PARAMS ((struct res_id *, const unsigned char *, unsigned long, int));
+ (struct res_id *, const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_generic
- PARAMS ((enum res_type, const unsigned char *, unsigned long));
+ (enum res_type, const unsigned char *, unsigned long);
static struct res_resource *bin_to_res_cursor
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_menu
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct menuitem *bin_to_res_menuitems
- PARAMS ((const unsigned char *, unsigned long, int, int *));
+ (const unsigned char *, unsigned long, int, int *);
static struct menuitem *bin_to_res_menuexitems
- PARAMS ((const unsigned char *, unsigned long, int, int *));
+ (const unsigned char *, unsigned long, int, int *);
static struct res_resource *bin_to_res_dialog
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_string
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_fontdir
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_accelerators
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_rcdata
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_group_cursor
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_group_icon
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_version
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
static struct res_resource *bin_to_res_userdata
- PARAMS ((const unsigned char *, unsigned long, int));
+ (const unsigned char *, unsigned long, int);
+static void get_version_header
+ (const unsigned char *, unsigned long, int, const char *,
+ unichar **, int *, int *, int *, int *);
/* Given a resource type ID, a pointer to data, a length, return a
res_resource structure which represents that resource. The caller
of the returned structure. */
struct res_resource *
-bin_to_res (type, data, length, big_endian)
- struct res_id type;
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res (struct res_id type, const unsigned char *data,
+ unsigned long length, int big_endian)
{
if (type.named)
return bin_to_res_userdata (data, length, big_endian);
return bin_to_res_fontdir (data, length, big_endian);
case RT_FONT:
return bin_to_res_generic (RES_TYPE_FONT, data, length);
- case RT_ACCELERATORS:
+ case RT_ACCELERATOR:
return bin_to_res_accelerators (data, length, big_endian);
case RT_RCDATA:
return bin_to_res_rcdata (data, length, big_endian);
/* Give an error if the binary data is too small. */
static void
-toosmall (msg)
- const char *msg;
+toosmall (const char *msg)
{
- fatal ("%s: not enough binary data", msg);
+ fatal (_("%s: not enough binary data"), msg);
}
/* Swap in a NULL terminated unicode string. */
static unichar *
-get_unicode (data, length, big_endian, retlen)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
- int *retlen;
+get_unicode (const unsigned char *data, unsigned long length,
+ int big_endian, int *retlen)
{
int c, i;
unichar *ret;
c = 0;
while (1)
{
- if (length < c * 2 + 2)
- toosmall ("null terminated unicode string");
+ if (length < (unsigned long) c * 2 + 2)
+ toosmall (_("null terminated unicode string"));
if (get_16 (big_endian, data + c * 2) == 0)
break;
++c;
/* Get a resource identifier. This returns the number of bytes used. */
static int
-get_resid (id, data, length, big_endian)
- struct res_id *id;
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+get_resid (struct res_id *id, const unsigned char *data,
+ unsigned long length, int big_endian)
{
int first;
if (length < 2)
- toosmall ("resource ID");
+ toosmall (_("resource ID"));
first = get_16 (big_endian, data);
if (first == 0xffff)
{
if (length < 4)
- toosmall ("resource ID");
+ toosmall (_("resource ID"));
id->named = 0;
id->u.id = get_16 (big_endian, data + 2);
return 4;
binary. */
struct res_resource *
-bin_to_res_generic (type, data, length)
- enum res_type type;
- const unsigned char *data;
- unsigned long length;
+bin_to_res_generic (enum res_type type, const unsigned char *data,
+ unsigned long length)
{
struct res_resource *r;
/* Convert a cursor resource from binary. */
struct res_resource *
-bin_to_res_cursor (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_cursor (const unsigned char *data, unsigned long length,
+ int big_endian)
{
struct cursor *c;
struct res_resource *r;
if (length < 4)
- toosmall ("cursor");
+ toosmall (_("cursor"));
c = (struct cursor *) res_alloc (sizeof *c);
c->xhotspot = get_16 (big_endian, data);
/* Convert a menu resource from binary. */
struct res_resource *
-bin_to_res_menu (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_menu (const unsigned char *data, unsigned long length,
+ int big_endian)
{
struct res_resource *r;
struct menu *m;
r->u.menu = m;
if (length < 2)
- toosmall ("menu header");
+ toosmall (_("menu header"));
version = get_16 (big_endian, data);
if (version == 0)
{
if (length < 4)
- toosmall ("menu header");
+ toosmall (_("menu header"));
m->help = 0;
m->items = bin_to_res_menuitems (data + 4, length - 4, big_endian,
&read);
}
else if (version == 1)
{
- int offset;
+ unsigned int offset;
if (length < 8)
- toosmall ("menuex header");
+ toosmall (_("menuex header"));
m->help = get_32 (big_endian, data + 4);
offset = get_16 (big_endian, data + 2);
if (offset + 4 >= length)
- toosmall ("menuex offset");
+ toosmall (_("menuex offset"));
m->items = bin_to_res_menuexitems (data + 4 + offset,
length - (4 + offset),
big_endian,
&read);
}
else
- fatal ("unsupported menu version %d", version);
+ fatal (_("unsupported menu version %d"), version);
return r;
}
/* Convert menu items from binary. */
static struct menuitem *
-bin_to_res_menuitems (data, length, big_endian, read)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
- int *read;
+bin_to_res_menuitems (const unsigned char *data, unsigned long length,
+ int big_endian, int *read)
{
struct menuitem *first, **pp;
while (length > 0)
{
- int flags, stroff, slen, itemlen;
+ int flags, slen, itemlen;
+ unsigned int stroff;
struct menuitem *mi;
if (length < 4)
- toosmall ("menuitem header");
+ toosmall (_("menuitem header"));
mi = (struct menuitem *) res_alloc (sizeof *mi);
mi->state = 0;
mi->help = 0;
flags = get_16 (big_endian, data);
- mi->type = flags;
+ mi->type = flags &~ (MENUITEM_POPUP | MENUITEM_ENDMENU);
if ((flags & MENUITEM_POPUP) == 0)
stroff = 4;
stroff = 2;
if (length < stroff + 2)
- toosmall ("menuitem header");
+ toosmall (_("menuitem header"));
if (get_16 (big_endian, data + stroff) == 0)
{
/* Convert menuex items from binary. */
static struct menuitem *
-bin_to_res_menuexitems (data, length, big_endian, read)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
- int *read;
+bin_to_res_menuexitems (const unsigned char *data, unsigned long length,
+ int big_endian, int *read)
{
struct menuitem *first, **pp;
while (length > 0)
{
- int flags, slen, itemlen;
+ int flags, slen;
+ unsigned int itemlen;
struct menuitem *mi;
if (length < 14)
- toosmall ("menuitem header");
+ toosmall (_("menuitem header"));
mi = (struct menuitem *) res_alloc (sizeof *mi);
mi->type = get_32 (big_endian, data);
int subread;
if (length < itemlen + 4)
- toosmall ("menuitem");
+ toosmall (_("menuitem"));
mi->help = get_32 (big_endian, data + itemlen);
itemlen += 4;
/* Convert a dialog resource from binary. */
static struct res_resource *
-bin_to_res_dialog (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_dialog (const unsigned char *data, unsigned long length,
+ int big_endian)
{
- int version;
+ int signature;
struct dialog *d;
- int c, sublen, off, i;
+ int c, sublen, i;
+ unsigned int off;
struct dialog_control **pp;
struct res_resource *r;
if (length < 18)
- toosmall ("dialog header");
+ toosmall (_("dialog header"));
d = (struct dialog *) res_alloc (sizeof *d);
- version = get_16 (big_endian, data);
- if (version != 0xffff)
+ signature = get_16 (big_endian, data + 2);
+ if (signature != 0xffff)
{
d->ex = NULL;
d->style = get_32 (big_endian, data);
}
else
{
- int signature;
+ int version;
- signature = get_16 (big_endian, data + 2);
- if (signature != 1)
- fatal ("unexpected dialog signature %d", signature);
+ version = get_16 (big_endian, data);
+ if (version != 1)
+ fatal (_("unexpected DIALOGEX version %d"), version);
d->ex = (struct dialog_ex *) res_alloc (sizeof (struct dialog_ex));
d->ex->help = get_32 (big_endian, data + 4);
}
if (length < off + 10)
- toosmall ("dialog header");
+ toosmall (_("dialog header"));
c = get_16 (big_endian, data + off);
d->x = get_16 (big_endian, data + off + 2);
d->caption = get_unicode (data + off, length - off, big_endian, &sublen);
off += sublen * 2 + 2;
+ if (sublen == 0)
+ d->caption = NULL;
if ((d->style & DS_SETFONT) == 0)
{
{
d->ex->weight = 0;
d->ex->italic = 0;
+ d->ex->charset = 1; /* Default charset. */
}
}
else
{
if (length < off + 2)
- toosmall ("dialog font point size");
+ toosmall (_("dialog font point size"));
d->pointsize = get_16 (big_endian, data + off);
off += 2;
if (d->ex != NULL)
{
if (length < off + 4)
- toosmall ("dialogex font information");
+ toosmall (_("dialogex font information"));
d->ex->weight = get_16 (big_endian, data + off);
- d->ex->italic = get_16 (big_endian, data + off + 2);
+ d->ex->italic = get_8 (data + off + 2);
+ d->ex->charset = get_8 (data + off + 3);
off += 4;
}
if (d->ex == NULL)
{
if (length < off + 8)
- toosmall ("dialog control");
+ toosmall (_("dialog control"));
dc->style = get_32 (big_endian, data + off);
dc->exstyle = get_32 (big_endian, data + off + 4);
else
{
if (length < off + 12)
- toosmall ("dialogex control");
+ toosmall (_("dialogex control"));
dc->help = get_32 (big_endian, data + off);
dc->exstyle = get_32 (big_endian, data + off + 4);
- dc->style = get_32 (big_endian, data + off + 18);
+ dc->style = get_32 (big_endian, data + off + 8);
off += 12;
}
if (length < off + 10)
- toosmall ("dialog control");
+ toosmall (_("dialog control"));
dc->x = get_16 (big_endian, data + off);
dc->y = get_16 (big_endian, data + off + 2);
dc->width = get_16 (big_endian, data + off + 4);
dc->height = get_16 (big_endian, data + off + 6);
- dc->id = get_16 (big_endian, data + off + 8);
- off += 10;
+ if (d->ex != NULL)
+ dc->id = get_32 (big_endian, data + off + 8);
+ else
+ dc->id = get_16 (big_endian, data + off + 8);
+
+ off += 10 + (d->ex != NULL ? 2 : 0);
sublen = get_resid (&dc->class, data + off, length - off, big_endian);
off += sublen;
off += sublen;
if (length < off + 2)
- toosmall ("dialog control end");
+ toosmall (_("dialog control end"));
datalen = get_16 (big_endian, data + off);
off += 2;
off = (off + 3) &~ 3;
if (length < off + datalen)
- toosmall ("dialog control data");
+ toosmall (_("dialog control data"));
dc->data = ((struct rcdata_item *)
res_alloc (sizeof (struct rcdata_item)));
dc->data->u.buffer.length = datalen;
dc->data->u.buffer.data = data + off;
- off += datalen;
+ off += datalen;
}
dc->next = NULL;
/* Convert a stringtable resource from binary. */
static struct res_resource *
-bin_to_res_string (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_string (const unsigned char *data, unsigned long length,
+ int big_endian)
{
struct stringtable *st;
int i;
for (i = 0; i < 16; i++)
{
- int slen;
+ unsigned int slen;
if (length < 2)
- toosmall ("stringtable string length");
+ toosmall (_("stringtable string length"));
slen = get_16 (big_endian, data);
st->strings[i].length = slen;
if (slen > 0)
{
unichar *s;
- int j;
+ unsigned int j;
if (length < 2 + 2 * slen)
- toosmall ("stringtable string");
+ toosmall (_("stringtable string"));
s = (unichar *) res_alloc (slen * sizeof (unichar));
st->strings[i].string = s;
s[j] = get_16 (big_endian, data + 2 + j * 2);
}
- data += 2 + slen;
- length -= 2 + slen;
+ data += 2 + 2 * slen;
+ length -= 2 + 2 * slen;
}
r = (struct res_resource *) res_alloc (sizeof *r);
/* Convert a fontdir resource from binary. */
static struct res_resource *
-bin_to_res_fontdir (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_fontdir (const unsigned char *data, unsigned long length,
+ int big_endian)
{
int c, i;
struct fontdir *first, **pp;
struct res_resource *r;
if (length < 2)
- toosmall ("fontdir header");
+ toosmall (_("fontdir header"));
c = get_16 (big_endian, data);
for (i = 0; i < c; i++)
{
struct fontdir *fd;
- int off;
+ unsigned int off;
if (length < 56)
- toosmall ("fontdir");
+ toosmall (_("fontdir"));
fd = (struct fontdir *) res_alloc (sizeof *fd);
fd->index = get_16 (big_endian, data);
while (off < length && data[off] != '\0')
++off;
if (off >= length)
- toosmall ("fontdir device name");
+ toosmall (_("fontdir device name"));
++off;
while (off < length && data[off] != '\0')
++off;
if (off >= length)
- toosmall ("fontdir face name");
+ toosmall (_("fontdir face name"));
++off;
fd->length = off;
/* Convert an accelerators resource from binary. */
static struct res_resource *
-bin_to_res_accelerators (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_accelerators (const unsigned char *data, unsigned long length,
+ int big_endian)
{
struct accelerator *first, **pp;
struct res_resource *r;
struct accelerator *a;
if (length < 8)
- toosmall ("accelerator");
+ toosmall (_("accelerator"));
+
+ a = (struct accelerator *) res_alloc (sizeof *a);
a->flags = get_16 (big_endian, data);
a->key = get_16 (big_endian, data + 2);
/* Convert an rcdata resource from binary. */
static struct res_resource *
-bin_to_res_rcdata (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_rcdata (const unsigned char *data, unsigned long length,
+ int big_endian ATTRIBUTE_UNUSED)
{
struct rcdata_item *ri;
struct res_resource *r;
/* Convert a group cursor resource from binary. */
static struct res_resource *
-bin_to_res_group_cursor (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_group_cursor (const unsigned char *data, unsigned long length,
+ int big_endian)
{
int type, c, i;
struct group_cursor *first, **pp;
struct res_resource *r;
if (length < 6)
- toosmall ("group cursor header");
+ toosmall (_("group cursor header"));
type = get_16 (big_endian, data + 2);
if (type != 2)
- fatal ("unexpected group cursor type %d", type);
+ fatal (_("unexpected group cursor type %d"), type);
c = get_16 (big_endian, data + 4);
struct group_cursor *gc;
if (length < 14)
- toosmall ("group cursor");
+ toosmall (_("group cursor"));
gc = (struct group_cursor *) res_alloc (sizeof *gc);
/* Convert a group icon resource from binary. */
static struct res_resource *
-bin_to_res_group_icon (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_group_icon (const unsigned char *data, unsigned long length,
+ int big_endian)
{
int type, c, i;
struct group_icon *first, **pp;
struct res_resource *r;
if (length < 6)
- toosmall ("group icon header");
+ toosmall (_("group icon header"));
type = get_16 (big_endian, data + 2);
if (type != 1)
- fatal ("unexpected group icon type %d", type);
+ fatal (_("unexpected group icon type %d"), type);
c = get_16 (big_endian, data + 4);
struct group_icon *gi;
if (length < 14)
- toosmall ("group icon");
+ toosmall (_("group icon"));
gi = (struct group_icon *) res_alloc (sizeof *gi);
to the type, and *OFF to the offset to the children. */
static void
-get_version_header (data, length, big_endian, key, pkey, len, vallen, type,
- off)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
- const char *key;
- unichar **pkey;
- int *len;
- int *vallen;
- int *type;
- int *off;
+get_version_header (const unsigned char *data, unsigned long length,
+ int big_endian, const char *key, unichar **pkey,
+ int *len, int *vallen, int *type, int *off)
{
if (length < 8)
toosmall (key);
{
if (length < 2)
toosmall (key);
- if (get_16 (big_endian, data) != *key)
- fatal ("unexpected version string");
+ if (get_16 (big_endian, data) != (unsigned char) *key)
+ fatal (_("unexpected version string"));
*off += 2;
length -= 2;
/* Convert a version resource from binary. */
static struct res_resource *
-bin_to_res_version (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_version (const unsigned char *data, unsigned long length,
+ int big_endian)
{
int verlen, vallen, type, off;
struct fixed_versioninfo *fi;
struct res_resource *r;
get_version_header (data, length, big_endian, "VS_VERSION_INFO",
- (unichar *) NULL, &verlen, &vallen, &type, &off);
+ (unichar **) NULL, &verlen, &vallen, &type, &off);
- if (verlen != length)
- fatal ("version length %d does not match resource length %lu",
+ if ((unsigned int) verlen != length)
+ fatal (_("version length %d does not match resource length %lu"),
verlen, length);
if (type != 0)
- fatal ("unexpected version type %d", type);
+ fatal (_("unexpected version type %d"), type);
data += off;
length -= off;
unsigned long signature, fiv;
if (vallen != 52)
- fatal ("unexpected fixed version information length %d", vallen);
+ fatal (_("unexpected fixed version information length %d"), vallen);
if (length < 52)
- toosmall ("fixed version info");
+ toosmall (_("fixed version info"));
signature = get_32 (big_endian, data);
if (signature != 0xfeef04bd)
- fatal ("unexpected fixed version signature %lu", signature);
+ fatal (_("unexpected fixed version signature %lu"), signature);
fiv = get_32 (big_endian, data + 4);
if (fiv != 0 && fiv != 0x10000)
- fatal ("unexpected fixed version info version %lu", fiv);
+ fatal (_("unexpected fixed version info version %lu"), fiv);
fi = (struct fixed_versioninfo *) res_alloc (sizeof *fi);
int ch;
if (length < 8)
- toosmall ("version var info");
+ toosmall (_("version var info"));
vi = (struct ver_info *) res_alloc (sizeof *vi);
vi->type = VERINFO_STRING;
get_version_header (data, length, big_endian, "StringFileInfo",
- (unichar *) NULL, &verlen, &vallen, &type,
+ (unichar **) NULL, &verlen, &vallen, &type,
&off);
if (vallen != 0)
- fatal ("unexpected stringfileinfo value length %d", vallen);
+ fatal (_("unexpected stringfileinfo value length %d"), vallen);
data += off;
length -= off;
&type, &off);
if (vallen != 0)
- fatal ("unexpected version stringtable value length %d", vallen);
+ fatal (_("unexpected version stringtable value length %d"), vallen);
data += off;
length -= off;
valoff = (valoff + 3) &~ 3;
if (off + valoff != subverlen)
- fatal ("unexpected version string length %d != %d + %d",
+ fatal (_("unexpected version string length %d != %d + %d"),
subverlen, off, valoff);
vs->next = NULL;
length -= valoff;
if (verlen < subverlen)
- fatal ("unexpected version string length %d < %d",
+ fatal (_("unexpected version string length %d < %d"),
verlen, subverlen);
verlen -= subverlen;
vi->type = VERINFO_VAR;
get_version_header (data, length, big_endian, "VarFileInfo",
- (unichar *) NULL, &verlen, &vallen, &type,
+ (unichar **) NULL, &verlen, &vallen, &type,
&off);
if (vallen != 0)
- fatal ("unexpected varfileinfo value length %d", vallen);
+ fatal (_("unexpected varfileinfo value length %d"), vallen);
data += off;
length -= off;
struct ver_varinfo *vv;
if (length < 4)
- toosmall ("version varfileinfo");
+ toosmall (_("version varfileinfo"));
vv = (struct ver_varinfo *) res_alloc (sizeof *vv);
length -= 4;
if (vallen < 4)
- fatal ("unexpected version value length %d", vallen);
+ fatal (_("unexpected version value length %d"), vallen);
vallen -= 4;
}
}
else
- fatal ("unexpected version string");
+ fatal (_("unexpected version string"));
vi->next = NULL;
*pp = vi;
- pp = &vi->next;
+ pp = &vi->next;
}
v = (struct versioninfo *) res_alloc (sizeof *v);
r->type = RES_TYPE_VERSIONINFO;
r->u.versioninfo = v;
- return r;
+ return r;
}
/* Convert an arbitrary user defined resource from binary. */
static struct res_resource *
-bin_to_res_userdata (data, length, big_endian)
- const unsigned char *data;
- unsigned long length;
- int big_endian;
+bin_to_res_userdata (const unsigned char *data, unsigned long length,
+ int big_endian ATTRIBUTE_UNUSED)
{
struct rcdata_item *ri;
struct res_resource *r;
\f
/* Macros to swap out values. */
+#define put_8(v, s) (*((unsigned char *) (s)) = (unsigned char) (v))
#define put_16(be, v, s) ((be) ? bfd_putb16 ((v), (s)) : bfd_putl16 ((v), (s)))
#define put_32(be, v, s) ((be) ? bfd_putb32 ((v), (s)) : bfd_putl32 ((v), (s)))
/* Local functions used to convert resources to binary format. */
-static void dword_align_bin PARAMS ((struct bindata ***, unsigned long *));
-static struct bindata *resid_to_bin PARAMS ((struct res_id, int));
-static struct bindata *unicode_to_bin PARAMS ((const unichar *, int));
+static void dword_align_bin (struct bindata ***, unsigned long *);
+static struct bindata *resid_to_bin (struct res_id, int);
+static struct bindata *unicode_to_bin (const unichar *, int);
static struct bindata *res_to_bin_accelerator
- PARAMS ((const struct accelerator *, int));
+ (const struct accelerator *, int);
static struct bindata *res_to_bin_cursor
- PARAMS ((const struct cursor *, int));
+ (const struct cursor *, int);
static struct bindata *res_to_bin_group_cursor
- PARAMS ((const struct group_cursor *, int));
+ (const struct group_cursor *, int);
static struct bindata *res_to_bin_dialog
- PARAMS ((const struct dialog *, int));
+ (const struct dialog *, int);
static struct bindata *res_to_bin_fontdir
- PARAMS ((const struct fontdir *, int));
+ (const struct fontdir *, int);
static struct bindata *res_to_bin_group_icon
- PARAMS ((const struct group_icon *, int));
+ (const struct group_icon *, int);
static struct bindata *res_to_bin_menu
- PARAMS ((const struct menu *, int));
+ (const struct menu *, int);
static struct bindata *res_to_bin_menuitems
- PARAMS ((const struct menuitem *, int));
+ (const struct menuitem *, int);
static struct bindata *res_to_bin_menuexitems
- PARAMS ((const struct menuitem *, int));
+ (const struct menuitem *, int);
static struct bindata *res_to_bin_rcdata
- PARAMS ((const struct rcdata_item *, int));
+ (const struct rcdata_item *, int);
static struct bindata *res_to_bin_stringtable
- PARAMS ((const struct stringtable *, int));
-static struct bindata *string_to_unicode_bin PARAMS ((const char *, int));
+ (const struct stringtable *, int);
+static struct bindata *string_to_unicode_bin (const char *, int);
static struct bindata *res_to_bin_versioninfo
- PARAMS ((const struct versioninfo *, int));
+ (const struct versioninfo *, int);
static struct bindata *res_to_bin_generic
- PARAMS ((unsigned long, const unsigned char *));
+ (unsigned long, const unsigned char *);
/* Convert a resource to binary. */
struct bindata *
-res_to_bin (res, big_endian)
- const struct res_resource *res;
- int big_endian;
+res_to_bin (const struct res_resource *res, int big_endian)
{
switch (res->type)
{
boundary. It updates *PPP and *LENGTH. */
static void
-dword_align_bin (ppp, length)
- struct bindata ***ppp;
- unsigned long *length;
+dword_align_bin (struct bindata ***ppp, unsigned long *length)
{
int add;
struct bindata *d;
bindata structure. */
static struct bindata *
-resid_to_bin (id, big_endian)
- struct res_id id;
- int big_endian;
+resid_to_bin (struct res_id id, int big_endian)
{
struct bindata *d;
returns exactly one bindata structure. */
static struct bindata *
-unicode_to_bin (str, big_endian)
- const unichar *str;
- int big_endian;
+unicode_to_bin (const unichar *str, int big_endian)
{
int len;
struct bindata *d;
/* Convert an accelerator resource to binary. */
static struct bindata *
-res_to_bin_accelerator (accelerators, big_endian)
- const struct accelerator *accelerators;
- int big_endian;
+res_to_bin_accelerator (const struct accelerator *accelerators,
+ int big_endian)
{
struct bindata *first, **pp;
const struct accelerator *a;
d->data = (unsigned char *) reswr_alloc (8);
put_16 (big_endian,
- a->flags | (a->next == NULL ? 0 : ACC_LAST),
+ a->flags | (a->next != NULL ? 0 : ACC_LAST),
d->data);
put_16 (big_endian, a->key, d->data + 2);
put_16 (big_endian, a->id, d->data + 4);
- put_16 (big_endian, 0, d->data + 8);
+ put_16 (big_endian, 0, d->data + 6);
d->next = NULL;
*pp = d;
/* Convert a cursor resource to binary. */
static struct bindata *
-res_to_bin_cursor (c, big_endian)
- const struct cursor *c;
- int big_endian;
+res_to_bin_cursor (const struct cursor *c, int big_endian)
{
struct bindata *d;
/* Convert a group cursor resource to binary. */
static struct bindata *
-res_to_bin_group_cursor (group_cursors, big_endian)
- const struct group_cursor *group_cursors;
- int big_endian;
+res_to_bin_group_cursor (const struct group_cursor *group_cursors,
+ int big_endian)
{
struct bindata *first, **pp;
int c;
/* Convert a dialog resource to binary. */
static struct bindata *
-res_to_bin_dialog (dialog, big_endian)
- const struct dialog *dialog;
- int big_endian;
+res_to_bin_dialog (const struct dialog *dialog, int big_endian)
{
int dialogex;
struct bindata *first, **pp;
if (! dialogex)
{
put_32 (big_endian, dialog->style, first->data);
- put_32 (big_endian, dialog->style, first->data + 4);
+ put_32 (big_endian, dialog->exstyle, first->data + 4);
off = 8;
}
else
{
- put_16 (big_endian, 0xffff, first->data);
- put_16 (big_endian, 1, first->data + 2);
+ put_16 (big_endian, 1, first->data);
+ put_16 (big_endian, 0xffff, first->data + 2);
+
if (dialog->ex == NULL)
put_32 (big_endian, 0, first->data + 4);
else
struct bindata *d;
d = (struct bindata *) reswr_alloc (sizeof *d);
- d->length = dialogex ? 2 : 6;
+ d->length = dialogex ? 6 : 2;
d->data = (unsigned char *) reswr_alloc (d->length);
length += d->length;
if (dialog->ex == NULL)
{
put_16 (big_endian, 0, d->data + 2);
- put_16 (big_endian, 0, d->data + 4);
+ put_8 (0, d->data + 4);
+ put_8 (1, d->data + 5);
}
else
{
put_16 (big_endian, dialog->ex->weight, d->data + 2);
- put_16 (big_endian, dialog->ex->italic, d->data + 4);
+ put_8 (dialog->ex->italic, d->data + 4);
+ put_8 (dialog->ex->charset, d->data + 5);
}
}
c = 0;
for (dc = dialog->controls; dc != NULL; dc = dc->next)
{
- unsigned long length;
struct bindata *d;
int dcoff;
dword_align_bin (&pp, &length);
d = (struct bindata *) reswr_alloc (sizeof *d);
- d->length = dialogex ? 22 : 18;
+ d->length = dialogex ? 24 : 18;
d->data = (unsigned char *) reswr_alloc (d->length);
length += d->length;
put_16 (big_endian, dc->y, d->data + dcoff + 2);
put_16 (big_endian, dc->width, d->data + dcoff + 4);
put_16 (big_endian, dc->height, d->data + dcoff + 6);
- put_16 (big_endian, dc->id, d->data + dcoff + 8);
+
+ if (dialogex)
+ put_32 (big_endian, dc->id, d->data + dcoff + 8);
+ else
+ put_16 (big_endian, dc->id, d->data + dcoff + 8);
*pp = d;
pp = &d->next;
put_16 (big_endian, 0, d->data);
else
{
+ unsigned long sublen;
+
dword_align_bin (&pp, &length);
*pp = res_to_bin_rcdata (dc->data, big_endian);
+ sublen = 0;
while (*pp != NULL)
{
- length += (*pp)->length;
+ sublen += (*pp)->length;
pp = &(*pp)->next;
}
+
+ put_16 (big_endian, sublen, d->data);
+
+ length += sublen;
}
}
-
put_16 (big_endian, c, first->data + off);
return first;
/* Convert a fontdir resource to binary. */
static struct bindata *
-res_to_bin_fontdir (fontdirs, big_endian)
- const struct fontdir *fontdirs;
- int big_endian;
+res_to_bin_fontdir (const struct fontdir *fontdirs, int big_endian)
{
struct bindata *first, **pp;
int c;
d->next = NULL;
*pp = d;
- pp = &d->next;
+ pp = &d->next;
}
put_16 (big_endian, c, first->data);
- return first;
+ return first;
}
/* Convert a group icon resource to binary. */
static struct bindata *
-res_to_bin_group_icon (group_icons, big_endian)
- const struct group_icon *group_icons;
- int big_endian;
+res_to_bin_group_icon (const struct group_icon *group_icons, int big_endian)
{
struct bindata *first, **pp;
int c;
/* Convert a menu resource to binary. */
static struct bindata *
-res_to_bin_menu (menu, big_endian)
- const struct menu *menu;
- int big_endian;
+res_to_bin_menu (const struct menu *menu, int big_endian)
{
int menuex;
struct bindata *d;
menuex = extended_menu (menu);
d = (struct bindata *) reswr_alloc (sizeof *d);
- d->length = menuex ? 4 : 8;
+ d->length = menuex ? 8 : 4;
d->data = (unsigned char *) reswr_alloc (d->length);
if (! menuex)
/* Convert menu items to binary. */
static struct bindata *
-res_to_bin_menuitems (items, big_endian)
- const struct menuitem *items;
- int big_endian;
+res_to_bin_menuitems (const struct menuitem *items, int big_endian)
{
struct bindata *first, **pp;
const struct menuitem *mi;
/* Convert menuex items to binary. */
static struct bindata *
-res_to_bin_menuexitems (items, big_endian)
- const struct menuitem *items;
- int big_endian;
+res_to_bin_menuexitems (const struct menuitem *items, int big_endian)
{
struct bindata *first, **pp;
unsigned long length;
to binary. */
static struct bindata *
-res_to_bin_rcdata (items, big_endian)
- const struct rcdata_item *items;
- int big_endian;
+res_to_bin_rcdata (const struct rcdata_item *items, int big_endian)
{
struct bindata *first, **pp;
const struct rcdata_item *ri;
/* Convert a stringtable resource to binary. */
static struct bindata *
-res_to_bin_stringtable (st, big_endian)
- const struct stringtable *st;
- int big_endian;
+res_to_bin_stringtable (const struct stringtable *st, int big_endian)
{
struct bindata *first, **pp;
int i;
d->next = NULL;
*pp = d;
- pp = &d->next;
+ pp = &d->next;
}
return first;
returns exactly one bindata structure. */
static struct bindata *
-string_to_unicode_bin (s, big_endian)
- const char *s;
- int big_endian;
+string_to_unicode_bin (const char *s, int big_endian)
{
size_t len, i;
struct bindata *d;
d->next = NULL;
- return d;
+ return d;
}
/* Convert a versioninfo resource to binary. */
static struct bindata *
-res_to_bin_versioninfo (versioninfo, big_endian)
- const struct versioninfo *versioninfo;
- int big_endian;
+res_to_bin_versioninfo (const struct versioninfo *versioninfo, int big_endian)
{
struct bindata *first, **pp;
unsigned long length;
vslen += 6;
vsslen = 6;
- put_16 (big_endian, 0, vssd->data + 2);
put_16 (big_endian, 1, vssd->data + 4);
*pp = vssd;
vsslen += length - hold;
*pp = unicode_to_bin (vs->value, big_endian);
+ put_16 (big_endian, (*pp)->length / 2, vssd->data + 2);
length += (*pp)->length;
vilen += (*pp)->length;
vslen += (*pp)->length;
/* Convert a generic resource to binary. */
static struct bindata *
-res_to_bin_generic (length, data)
- unsigned long length;
- const unsigned char *data;
+res_to_bin_generic (unsigned long length, const unsigned char *data)
{
struct bindata *d;