/* resbin.c -- manipulate the Windows binary resource format.
- Copyright 1997, 1998, 1999, 2002 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.
/* 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
- PARAMS ((const unsigned char *, unsigned long, int, const char *,
- unichar **, int *, int *, int *, int *));
+ (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);
/* 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);
}
/* 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;
/* 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;
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;
/* 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;
/* 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;
/* 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;
/* 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 signature;
struct dialog *d;
else
{
int version;
-
+
version = get_16 (big_endian, data);
if (version != 1)
fatal (_("unexpected DIALOGEX version %d"), version);
d->caption = get_unicode (data + off, length - off, big_endian, &sublen);
off += sublen * 2 + 2;
- if (sublen == 0)
+ if (sublen == 0)
d->caption = NULL;
if ((d->style & DS_SETFONT) == 0)
dc->height = get_16 (big_endian, data + off + 6);
if (d->ex != NULL)
- dc->id = get_32 (big_endian, data + off + 8);
+ dc->id = get_32 (big_endian, data + off + 8);
else
- dc->id = get_16 (big_endian, data + off + 8);
+ dc->id = get_16 (big_endian, data + off + 8);
off += 10 + (d->ex != NULL ? 2 : 0);
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;
/* 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;
/* 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;
/* 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 ATTRIBUTE_UNUSED;
+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;
/* 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;
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);
/* 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;
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 ATTRIBUTE_UNUSED;
+bin_to_res_userdata (const unsigned char *data, unsigned long length,
+ int big_endian ATTRIBUTE_UNUSED)
{
struct rcdata_item *ri;
struct res_resource *r;
/* 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;
/* 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;
put_16 (big_endian, dc->height, d->data + dcoff + 6);
if (dialogex)
- put_32 (big_endian, dc->id, d->data + dcoff + 8);
+ put_32 (big_endian, dc->id, d->data + dcoff + 8);
else
- put_16 (big_endian, dc->id, d->data + dcoff + 8);
+ put_16 (big_endian, dc->id, d->data + dcoff + 8);
*pp = d;
pp = &d->next;
/* 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;
/* 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;
vsslen += length - hold;
*pp = unicode_to_bin (vs->value, big_endian);
- put_16 (big_endian, (*pp)->length / 2, vssd->data + 2);
+ 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;