2 * Copyright 1998 Bertho A. Stultiens (BS)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 *****************************************************************************
30 * Function : get_typename
31 * Syntax : char *get_typename(resource_t* r)
33 * r - Resource description
34 * Output : A pointer to a string representing the resource type
37 *****************************************************************************
39 const char *get_typename(const resource_t
* r
)
42 case res_acc
: return "ACCELERATOR";
43 case res_bmp
: return "BITMAP";
44 case res_cur
: return "CURSOR";
45 case res_curg
: return "GROUP_CURSOR";
46 case res_dlg
: return "DIALOG";
47 case res_fnt
: return "FONT";
48 case res_ico
: return "ICON";
49 case res_icog
: return "GROUP_ICON";
50 case res_men
: return "MENU";
51 case res_rdt
: return "RCDATA";
52 case res_stt
: return "STRINGTABLE";
53 case res_usr
: return "UserResource";
54 case res_msg
: return "MESSAGETABLE";
55 case res_ver
: return "VERSIONINFO";
56 case res_dlginit
: return "DLGINIT";
57 case res_toolbar
: return "TOOLBAR";
58 case res_anicur
: return "CURSOR (animated)";
59 case res_aniico
: return "ICON (animated)";
60 default: return "Unknown";
65 *****************************************************************************
66 * Function : strncpyWtoA
67 * Syntax : char *strncpyWtoA(char *cs, short *ws, int maxlen)
69 * cs - Pointer to buffer to receive result
70 * ws - Source wide-string
71 * maxlen - Max chars to copy
73 * Description : Copy a unicode string to ascii. Copying stops after the
74 * first occurring '\0' or when maxlen-1 chars are copied. The
75 * String is always nul terminated.
76 * Remarks : No codepage translation is done.
77 *****************************************************************************
79 static char *strncpyWtoA(char *cs
, const WCHAR
*ws
, int maxlen
)
82 const WCHAR
*wsMax
= ws
+ maxlen
- 1;
83 while(*ws
&& ws
< wsMax
)
86 fprintf(stderr
, "***Warning: Unicode string contains non-printable chars***\n");
87 *cptr
++ = (char)*ws
++;
94 *****************************************************************************
95 * Function : print_string
96 * Syntax : void print_string(string_t *str)
101 *****************************************************************************
103 static void print_string(const string_t
*str
)
108 else if(str
->type
== str_char
)
109 printf("\"%s\"", str
->str
.cstr
);
112 strncpyWtoA(buffer
, str
->str
.wstr
, sizeof(buffer
));
113 printf("L\"%s\"", buffer
);
118 *****************************************************************************
119 * Function : get_nameid_str
120 * Syntax : const char *get_nameid_str(const name_id_t *n)
122 * n - nameid to convert to text
123 * Output : A pointer to the name.
125 * Remarks : Not reentrant because of static buffer
126 *****************************************************************************
128 const char *get_nameid_str(const name_id_t
*n
)
130 static char buffer
[256];
135 if(n
->type
== name_ord
)
137 sprintf(buffer
, "%d", n
->name
.i_name
);
140 else if(n
->type
== name_str
)
142 if(n
->name
.s_name
->type
== str_char
)
143 return n
->name
.s_name
->str
.cstr
;
146 strncpyWtoA(buffer
, n
->name
.s_name
->str
.wstr
, sizeof(buffer
));
151 return "Hoooo, report this: wrong type in nameid";
155 *****************************************************************************
156 * Function : dump_memopt
157 * Syntax : void dump_memopt(DWORD memopt)
159 * memopt - flag bits of the options set
163 *****************************************************************************
165 static void dump_memopt(DWORD memopt
)
167 printf("Memory/load options: ");
171 printf("LOADONCALL ");
181 printf("DISCARDABLE");
186 *****************************************************************************
187 * Function : dump_lvc
188 * Syntax : void dump_lvc(const lvc_t *l)
190 * l - pointer to lvc structure
192 * Description : Dump language, version and characteristics
194 *****************************************************************************
196 static void dump_lvc(const lvc_t
*l
)
199 printf("LANGUAGE %04x, %04x\n", l
->language
->id
, l
->language
->sub
);
201 printf("LANGUAGE <not set>\n");
204 printf("VERSION %08x\n", *(l
->version
));
206 printf("VERSION <not set>\n");
209 printf("CHARACTERISTICS %08x\n", *(l
->characts
));
211 printf("CHARACTERISTICS <not set>\n");
215 *****************************************************************************
216 * Function : dump_raw_data
217 * Syntax : void dump_raw_data(const raw_data_t *d)
219 * d - Raw data descriptor
223 *****************************************************************************
225 static void dump_raw_data(const raw_data_t
*d
)
236 printf("Rawdata size: %d\n", d
->size
);
240 for(n
= 0; n
< d
->size
; n
++)
247 for(i
= 0; i
< 16; i
++)
248 printf("%c", isprint(d
->data
[n
-16+i
] & 0xff) ? d
->data
[n
-16+i
] : '.');
249 printf("\n%08x: ", n
);
254 printf("%02x ", d
->data
[n
] & 0xff);
260 for(i
= 0; i
< j
; i
++)
261 printf("%c", isprint(d
->data
[n
-j
+i
] & 0xff) ? d
->data
[n
-j
+i
] : '.');
266 *****************************************************************************
267 * Function : dump_accelerator
268 * Syntax : void dump_accelerator(const accelerator_t *acc)
270 * acc - Accelerator resource descriptor
274 *****************************************************************************
276 static void dump_accelerator(const accelerator_t
*acc
)
278 event_t
*ev
= acc
->events
;
280 dump_memopt(acc
->memopt
);
281 dump_lvc(&(acc
->lvc
));
283 printf("Events: %s\n", ev
? "" : "<none>");
288 printf("\"%c\"", ev
->key
);
289 else if(iscntrl(ev
->key
))
290 printf("\"^%c\"", ev
->key
+'@');
292 printf("\\x%02x", ev
->key
& 0xff);
294 printf(" Id=%d flags=%04x\n", ev
->id
, ev
->flags
);
300 *****************************************************************************
301 * Function : dump_cursor
302 * Syntax : void dump_cursor(const cursor_t *cur)
304 * cur - Cursor resource descriptor
308 *****************************************************************************
310 static void dump_cursor(const cursor_t
*cur
)
312 printf("Id: %d\n", cur
->id
);
313 printf("Width: %d\n", cur
->width
);
314 printf("Height: %d\n", cur
->height
);
315 printf("X Hotspot: %d\n", cur
->xhot
);
316 printf("Y Hotspot: %d\n", cur
->yhot
);
317 dump_raw_data(cur
->data
);
321 *****************************************************************************
322 * Function : dump_cursor_group
323 * Syntax : void dump_cursor_group(const cursor_group_t *cur)
325 * cur - Cursor group resource descriptor
329 *****************************************************************************
331 static void dump_cursor_group(const cursor_group_t
*curg
)
333 dump_memopt(curg
->memopt
);
334 printf("There are %d cursors in this group\n", curg
->ncursor
);
338 *****************************************************************************
339 * Function : dump_icon
340 * Syntax : void dump_icon(const icon_t *ico)
342 * ico - Icon resource descriptor
346 *****************************************************************************
348 static void dump_icon(const icon_t
*ico
)
350 printf("Id: %d\n", ico
->id
);
351 printf("Width: %d\n", ico
->width
);
352 printf("Height: %d\n", ico
->height
);
353 printf("NColor: %d\n", ico
->nclr
);
354 printf("NPlanes: %d\n", ico
->planes
);
355 printf("NBits: %d\n", ico
->bits
);
356 dump_raw_data(ico
->data
);
360 *****************************************************************************
361 * Function : dump_icon_group
362 * Syntax : void dump_icon_group(const icon_group_t *ico)
364 * ico - Icon group resource descriptor
368 *****************************************************************************
370 static void dump_icon_group(const icon_group_t
*icog
)
372 dump_memopt(icog
->memopt
);
373 printf("There are %d icons in this group\n", icog
->nicon
);
377 *****************************************************************************
378 * Function : dump_ani_curico
379 * Syntax : void dump_ani_curico(const ani_curico_t *ani)
381 * ani - Animated object resource descriptor
385 *****************************************************************************
387 static void dump_ani_curico(const ani_curico_t
*ani
)
389 dump_memopt(ani
->memopt
);
390 dump_lvc(&ani
->data
->lvc
);
391 dump_raw_data(ani
->data
);
395 *****************************************************************************
396 * Function : dump_font
397 * Syntax : void dump_font(const font_t *fnt)
399 * fnt - Font resource descriptor
403 *****************************************************************************
405 static void dump_font(const font_t
*fnt
)
407 dump_memopt(fnt
->memopt
);
408 dump_lvc(&(fnt
->data
->lvc
));
409 dump_raw_data(fnt
->data
);
413 *****************************************************************************
414 * Function : dump_bitmap
415 * Syntax : void dump_bitmap(const bitmap_t *bmp)
417 * bmp - Bitmap resource descriptor
421 *****************************************************************************
423 static void dump_bitmap(const bitmap_t
*bmp
)
425 dump_memopt(bmp
->memopt
);
426 dump_lvc(&(bmp
->data
->lvc
));
427 dump_raw_data(bmp
->data
);
431 *****************************************************************************
432 * Function : dump_rcdata
433 * Syntax : void dump_rcdata(const rcdata_t *rdt)
435 * rdt - RCData resource descriptor
439 *****************************************************************************
441 static void dump_rcdata(const rcdata_t
*rdt
)
443 dump_memopt(rdt
->memopt
);
444 dump_lvc(&(rdt
->data
->lvc
));
445 dump_raw_data(rdt
->data
);
449 *****************************************************************************
450 * Function : dump_user
451 * Syntax : void dump_user(const user_t *usr)
453 * usr - User resource descriptor
457 *****************************************************************************
459 static void dump_user(const user_t
*usr
)
461 dump_memopt(usr
->memopt
);
462 dump_lvc(&(usr
->data
->lvc
));
463 printf("Class %s\n", get_nameid_str(usr
->type
));
464 dump_raw_data(usr
->data
);
468 *****************************************************************************
469 * Function : dump_messagetable
470 * Syntax : void dump_messagetable(const messagetable_t *msg)
472 * msg - Messagetable resource descriptor
476 *****************************************************************************
478 static void dump_messagetable(const messagetable_t
*msg
)
480 dump_memopt(msg
->memopt
);
481 dump_lvc(&(msg
->data
->lvc
));
482 dump_raw_data(msg
->data
);
486 *****************************************************************************
487 * Function : dump_stringtable
488 * Syntax : void dump_stringtable(const stringtable_t *stt)
490 * stt - Stringtable resource descriptor
494 *****************************************************************************
496 static void dump_stringtable(const stringtable_t
*stt
)
499 for(; stt
; stt
= stt
->next
)
502 dump_memopt(stt
->memopt
);
503 dump_lvc(&(stt
->lvc
));
504 for(i
= 0; i
< stt
->nentries
; i
++)
506 printf("Id=%-5d (%d) ", stt
->idbase
+i
, stt
->entries
[i
].id
);
507 if(stt
->entries
[i
].str
)
508 print_string(stt
->entries
[i
].str
);
518 *****************************************************************************
519 * Function : dump_control
520 * Syntax : void dump_control(const control_t *ctrl)
522 * ctrl - Control resource descriptor
526 *****************************************************************************
528 static void dump_control(const control_t
*ctrl
)
530 printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl
->ctlclass
));
531 printf("\tText: "); get_nameid_str(ctrl
->title
); printf("\n");
532 printf("\tId: %d\n", ctrl
->id
);
533 printf("\tx, y, w, h: %d, %d, %d, %d\n", ctrl
->x
, ctrl
->y
, ctrl
->width
, ctrl
->height
);
536 assert(ctrl
->style
!= NULL
);
537 assert(ctrl
->style
->and_mask
== 0);
538 printf("\tStyle: %08x\n", ctrl
->style
->or_mask
);
542 assert(ctrl
->exstyle
!= NULL
);
543 assert(ctrl
->exstyle
->and_mask
== 0);
544 printf("\tExStyle: %08x\n", ctrl
->exstyle
->or_mask
);
547 printf("\tHelpid: %d\n", ctrl
->helpid
);
551 dump_raw_data(ctrl
->extra
);
557 *****************************************************************************
558 * Function : dump_dialog
559 * Syntax : void dump_dialog(const dialog_t *dlg)
561 * dlg - Dialog resource descriptor
565 *****************************************************************************
567 static void dump_dialog(const dialog_t
*dlg
)
569 control_t
*c
= dlg
->controls
;
571 dump_memopt(dlg
->memopt
);
572 dump_lvc(&(dlg
->lvc
));
573 printf("x, y, w, h: %d, %d, %d, %d\n", dlg
->x
, dlg
->y
, dlg
->width
, dlg
->height
);
576 assert(dlg
->style
!= NULL
);
577 assert(dlg
->style
->and_mask
== 0);
578 printf("Style: %08x\n", dlg
->style
->or_mask
);
583 assert(dlg
->exstyle
!= NULL
);
584 assert(dlg
->exstyle
->and_mask
== 0);
585 printf("ExStyle: %08x\n", dlg
->exstyle
->or_mask
);
587 printf("Menu: %s\n", get_nameid_str(dlg
->menu
));
588 printf("Class: %s\n", get_nameid_str(dlg
->dlgclass
));
589 printf("Title: "); print_string(dlg
->title
); printf("\n");
595 printf("%d, ", dlg
->font
->size
);
596 print_string(dlg
->font
->name
);
607 *****************************************************************************
608 * Function : dump_menu_item
609 * Syntax : void dump_menu_item(const menuex_item_t *item)
614 *****************************************************************************
616 static void dump_menu_item(const menu_item_t
*item
)
623 print_string(item
->name
);
625 printf(", Id=%d", item
->id
);
627 printf(", Type=%d", item
->type
);
629 printf(", State=%08x", item
->state
);
631 printf(", HelpId=%d", item
->helpid
);
633 dump_menu_item(item
->popup
);
640 print_string(item
->name
);
642 printf(", Id=%d", item
->id
);
644 printf(", Type=%d", item
->type
);
646 printf(", State=%08x", item
->state
);
648 printf(", HelpId=%d", item
->helpid
);
659 *****************************************************************************
660 * Function : dump_menu
661 * Syntax : void dump_menu(const menu_t *men)
663 * men - Menu resource descriptor
667 *****************************************************************************
669 static void dump_menu(const menu_t
*men
)
671 dump_memopt(men
->memopt
);
672 dump_lvc(&(men
->lvc
));
673 dump_menu_item(men
->items
);
677 *****************************************************************************
678 * Function : dump_ver_value
679 * Syntax : void dump_ver_value(const ver_value_t *val)
684 *****************************************************************************
686 static void dump_ver_block(const ver_block_t
*); /* Forward ref */
688 static void dump_ver_value(const ver_value_t
*val
)
690 if(val
->type
== val_str
)
693 print_string(val
->key
);
695 print_string(val
->value
.str
);
698 else if(val
->type
== val_words
)
702 print_string(val
->key
);
703 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
704 printf(" %04x", val
->value
.words
->words
[i
]);
707 else if(val
->type
== val_block
)
709 dump_ver_block(val
->value
.block
);
714 *****************************************************************************
715 * Function : dump_ver_block
716 * Syntax : void dump_ver_block(const ver_block_t *blk)
721 *****************************************************************************
723 static void dump_ver_block(const ver_block_t
*blk
)
725 const ver_value_t
*val
= blk
->values
;
727 print_string(blk
->name
);
738 *****************************************************************************
739 * Function : dump_versioninfo
740 * Syntax : void dump_versioninfo(const versioninfo_t *ver)
742 * ver - Versioninfo resource descriptor
746 *****************************************************************************
748 static void dump_versioninfo(const versioninfo_t
*ver
)
750 const ver_block_t
*blk
= ver
->blocks
;
752 dump_lvc(&(ver
->lvc
));
755 printf("FILEVERSION %04x, %04x, %04x, %04x\n",
761 printf("PRODUCTVERSION %04x, %04x, %04x, %04x\n",
767 printf("FILEOS %08x\n", ver
->fileos
);
769 printf("FILEFLAGS %08x\n", ver
->fileflags
);
771 printf("FILEFLAGSMASK %08x\n", ver
->fileflagsmask
);
773 printf("FILETYPE %08x\n", ver
->filetype
);
775 printf("FILESUBTYPE %08x\n", ver
->filesubtype
);
784 *****************************************************************************
785 * Function : dump_toolbar_item
786 * Syntax : void dump_toolbar_item(const toolbar_item_t *item)
791 *****************************************************************************
793 static void dump_toolbar_items(const toolbar_item_t
*items
)
798 printf(" BUTTON %d", items
->id
);
800 printf(" SEPARATOR");
809 *****************************************************************************
810 * Function : dump_toolbar
811 * Syntax : void dump_toolbar(const toolbar_t *toolbar)
813 * toolbar - Toolbar resource descriptor
817 *****************************************************************************
819 static void dump_toolbar(const toolbar_t
*toolbar
)
821 dump_memopt(toolbar
->memopt
);
822 dump_lvc(&(toolbar
->lvc
));
823 dump_toolbar_items(toolbar
->items
);
827 *****************************************************************************
828 * Function : dump_dlginit
829 * Syntax : void dump_dlginit(const dlginit_t *dit)
831 * dit - DlgInit resource descriptor
835 *****************************************************************************
837 static void dump_dlginit(const dlginit_t
*dit
)
839 dump_memopt(dit
->memopt
);
840 dump_lvc(&(dit
->data
->lvc
));
841 dump_raw_data(dit
->data
);
845 *****************************************************************************
846 * Function : dump_resources
847 * Syntax : void dump_resources(const resource_t *top)
849 * top - Top of the resource tree
852 * Description : Dump the parsed resource-tree to stdout
854 *****************************************************************************
856 void dump_resources(const resource_t
*top
)
858 printf("Internal resource-tree dump:\n");
861 printf("Resource: %s\nId: %s\n",
863 get_nameid_str(top
->name
));
867 dump_accelerator(top
->res
.acc
);
870 dump_bitmap(top
->res
.bmp
);
873 dump_cursor(top
->res
.cur
);
876 dump_cursor_group(top
->res
.curg
);
879 dump_dialog(top
->res
.dlg
);
882 dump_font(top
->res
.fnt
);
885 dump_icon_group(top
->res
.icog
);
888 dump_icon(top
->res
.ico
);
891 dump_menu(top
->res
.men
);
894 dump_rcdata(top
->res
.rdt
);
897 dump_stringtable(top
->res
.stt
);
900 dump_user(top
->res
.usr
);
903 dump_messagetable(top
->res
.msg
);
906 dump_versioninfo(top
->res
.ver
);
909 dump_dlginit(top
->res
.dlgi
);
912 dump_toolbar(top
->res
.tbt
);
916 dump_ani_curico(top
->res
.ani
);
919 printf("Report this: Unknown resource type parsed %08x\n", top
->type
);