2 * Copyrignt 1998 Bertho A. Stultiens (BS)
4 * 16-Apr-1998 BS - Yeah, dump it to stdout.
18 *****************************************************************************
19 * Function : get_typename
20 * Syntax : char *get_typename(resource_t* r)
22 * r - Resource description
23 * Output : A pointer to a string representing the resource type
26 *****************************************************************************
28 char *get_typename(resource_t
* r
)
31 case res_acc
: return "ACCELERATOR";
32 case res_bmp
: return "BITMAP";
33 case res_cur
: return "CURSOR";
34 case res_curg
: return "GROUP_CURSOR";
35 case res_dlg
: return "DIALOG";
36 case res_dlgex
: return "DIALOGEX";
37 case res_fnt
: return "FONT";
38 case res_ico
: return "ICON";
39 case res_icog
: return "GROUP_ICON";
40 case res_men
: return "MENU";
41 case res_menex
: return "MENUEX";
42 case res_rdt
: return "RCDATA";
43 case res_stt
: return "STRINGTABLE";
44 case res_usr
: return "UserResource";
45 case res_msg
: return "MESSAGETABLE";
46 case res_ver
: return "VERSIONINFO";
47 case res_dlginit
: return "DLGINIT";
48 case res_toolbar
: return "TOOLBAR";
49 case res_anicur
: return "CURSOR (animated)";
50 case res_aniico
: return "ICON (animated)";
51 default: return "Unknown";
56 *****************************************************************************
57 * Function : strncpyWtoA
58 * Syntax : char *strncpyWtoA(char *cs, short *ws, int maxlen)
60 * cs - Pointer to buffer to receive result
61 * ws - Source wide-string
62 * maxlen - Max chars to copy
64 * Description : Copy a unicode string to ascii. Copying stops after the
65 * first occuring '\0' or when maxlen-1 chars are copied. The
66 * String is always nul terminated.
67 * Remarks : No codepage translation is done.
68 *****************************************************************************
70 char *strncpyWtoA(char *cs
, short *ws
, int maxlen
)
73 short *wsMax
= ws
+ maxlen
;
76 if(*ws
< -128 || *ws
> 127)
77 printf("***Warning: Unicode string contains non-printable chars***");
78 *cptr
++ = (char)*ws
++;
86 *****************************************************************************
87 * Function : print_string
88 * Syntax : void print_string(string_t *str)
93 *****************************************************************************
95 void print_string(string_t
*str
)
100 else if(str
->type
== str_char
)
101 printf("\"%s\"", str
->str
.cstr
);
104 strncpyWtoA(buffer
, str
->str
.wstr
, sizeof(buffer
));
105 printf("L\"%s\"", buffer
);
110 *****************************************************************************
111 * Function : get_nameid_str
112 * Syntax : char *get_nameid_str(name_id_t *n)
114 * n - nameid to convert to text
115 * Output : A pointer to the name.
117 * Remarks : Not reentrant because of static buffer
118 *****************************************************************************
120 char *get_nameid_str(name_id_t
*n
)
122 static char buffer
[256];
127 if(n
->type
== name_ord
)
129 sprintf(buffer
, "%d", n
->name
.i_name
);
132 else if(n
->type
== name_str
)
134 if(n
->name
.s_name
->type
== str_char
)
135 return n
->name
.s_name
->str
.cstr
;
138 strncpyWtoA(buffer
, n
->name
.s_name
->str
.wstr
, sizeof(buffer
));
143 return "Hoooo, report this: wrong type in nameid";
147 *****************************************************************************
148 * Function : dump_memopt
149 * Syntax : void dump_memopt(DWORD memopt)
151 * memopt - flag bits of the options set
155 *****************************************************************************
157 static void dump_memopt(DWORD memopt
)
159 printf("Memory/load options: ");
163 printf("LOADONCALL ");
173 printf("DISCARDABLE");
178 *****************************************************************************
179 * Function : dump_lvc
180 * Syntax : void dump_lvc(lvc_t *l)
182 * l - pointer to lvc structure
184 * Description : Dump language, version and characteristics
186 *****************************************************************************
188 static void dump_lvc(lvc_t
*l
)
191 printf("LANGUAGE %04x, %04x\n", l
->language
->id
, l
->language
->sub
);
193 printf("LANGUAGE <not set>\n");
196 printf("VERSION %08lx\n", *(l
->version
));
198 printf("VERSION <not set>\n");
201 printf("CHARACTERISTICS %08lx\n", *(l
->characts
));
203 printf("CHARACTERISTICS <not set>\n");
207 *****************************************************************************
208 * Function : dump_raw_data
209 * Syntax : void dump_raw_data(raw_data_t *d)
211 * d - Raw data descriptor
215 *****************************************************************************
217 static void dump_raw_data(raw_data_t
*d
)
228 printf("Rawdata size: %d\n", d
->size
);
232 for(n
= 0; n
< d
->size
; n
++)
239 for(i
= 0; i
< 16; i
++)
240 printf("%c", isprint(d
->data
[n
-16+i
] & 0xff) ? d
->data
[n
-16+i
] : '.');
241 printf("\n%08x: ", n
);
246 printf("%02x ", d
->data
[n
] & 0xff);
252 for(i
= 0; i
< j
; i
++)
253 printf("%c", isprint(d
->data
[n
-j
+i
] & 0xff) ? d
->data
[n
-j
+i
] : '.');
258 *****************************************************************************
259 * Function : dump_accelerator
260 * Syntax : void dump_accelerator(resource_t *acc)
262 * acc - Accelerator resource descriptor
266 *****************************************************************************
268 static void dump_accelerator(accelerator_t
*acc
)
270 event_t
*ev
= acc
->events
;
272 dump_memopt(acc
->memopt
);
273 dump_lvc(&(acc
->lvc
));
275 printf("Events: %s\n", ev
? "" : "<none>");
280 printf("\"%c\"", ev
->key
);
281 else if(iscntrl(ev
->key
))
282 printf("\"^%c\"", ev
->key
+'@');
284 printf("\\x%02x", ev
->key
& 0xff);
286 printf(" Id=%d flags=%04x\n", ev
->id
, ev
->flags
);
292 *****************************************************************************
293 * Function : dump_cursor
294 * Syntax : void dump_cursor(cursor_t *cur)
296 * cur - Cursor resource descriptor
300 *****************************************************************************
302 static void dump_cursor(cursor_t
*cur
)
304 printf("Id: %d\n", cur
->id
);
305 printf("Width: %d\n", cur
->width
);
306 printf("Height: %d\n", cur
->height
);
307 printf("X Hotspot: %d\n", cur
->xhot
);
308 printf("Y Hotspot: %d\n", cur
->yhot
);
309 dump_raw_data(cur
->data
);
313 *****************************************************************************
314 * Function : dump_cursor_group
315 * Syntax : void dump_cursor_group(cursor_group_t *cur)
317 * cur - Cursor group resource descriptor
321 *****************************************************************************
323 static void dump_cursor_group(cursor_group_t
*curg
)
325 dump_memopt(curg
->memopt
);
326 printf("There are %d cursors in this group\n", curg
->ncursor
);
330 *****************************************************************************
331 * Function : dump_icon
332 * Syntax : void dump_icon(icon_t *ico)
334 * ico - Icon resource descriptor
338 *****************************************************************************
340 static void dump_icon(icon_t
*ico
)
342 printf("Id: %d\n", ico
->id
);
343 printf("Width: %d\n", ico
->width
);
344 printf("Height: %d\n", ico
->height
);
345 printf("NColor: %d\n", ico
->nclr
);
346 printf("NPlanes: %d\n", ico
->planes
);
347 printf("NBits: %d\n", ico
->bits
);
348 dump_raw_data(ico
->data
);
352 *****************************************************************************
353 * Function : dump_icon_group
354 * Syntax : void dump_icon_group(icon_group_t *ico)
356 * ico - Icon group resource descriptor
360 *****************************************************************************
362 static void dump_icon_group(icon_group_t
*icog
)
364 dump_memopt(icog
->memopt
);
365 printf("There are %d icons in this group\n", icog
->nicon
);
369 *****************************************************************************
370 * Function : dump_ani_curico
371 * Syntax : void dump_ani_curico(ani_curico_t *ani)
373 * ani - Animated object resource descriptor
377 *****************************************************************************
379 static void dump_ani_curico(ani_curico_t
*ani
)
381 dump_memopt(ani
->memopt
);
382 dump_lvc(&ani
->data
->lvc
);
383 dump_raw_data(ani
->data
);
387 *****************************************************************************
388 * Function : dump_font
389 * Syntax : void dump_font(font_t *fnt)
391 * fnt - Font resource descriptor
395 *****************************************************************************
397 static void dump_font(font_t
*fnt
)
399 dump_memopt(fnt
->memopt
);
400 dump_lvc(&(fnt
->data
->lvc
));
401 dump_raw_data(fnt
->data
);
405 *****************************************************************************
406 * Function : dump_bitmap
407 * Syntax : void dump_bitmap(bitmap_t *bmp)
409 * bmp - Bitmap resource descriptor
413 *****************************************************************************
415 static void dump_bitmap(bitmap_t
*bmp
)
417 dump_memopt(bmp
->memopt
);
418 dump_lvc(&(bmp
->data
->lvc
));
419 dump_raw_data(bmp
->data
);
423 *****************************************************************************
424 * Function : dump_rcdata
425 * Syntax : void dump_rcdata(rcdata_t *rdt)
427 * rdt - RCData resource descriptor
431 *****************************************************************************
433 static void dump_rcdata(rcdata_t
*rdt
)
435 dump_memopt(rdt
->memopt
);
436 dump_lvc(&(rdt
->data
->lvc
));
437 dump_raw_data(rdt
->data
);
441 *****************************************************************************
442 * Function : dump_user
443 * Syntax : void dump_user(user_t *usr)
445 * usr - User resource descriptor
449 *****************************************************************************
451 static void dump_user(user_t
*usr
)
453 dump_memopt(usr
->memopt
);
454 dump_lvc(&(usr
->data
->lvc
));
455 printf("Class %s\n", get_nameid_str(usr
->type
));
456 dump_raw_data(usr
->data
);
460 *****************************************************************************
461 * Function : dump_messagetable
462 * Syntax : void dump_messagetable(messagetable_t *msg)
464 * msg - Messagetable resource descriptor
468 *****************************************************************************
470 static void dump_messagetable(messagetable_t
*msg
)
472 dump_memopt(msg
->memopt
);
473 dump_lvc(&(msg
->data
->lvc
));
474 dump_raw_data(msg
->data
);
478 *****************************************************************************
479 * Function : dump_stringtable
480 * Syntax : void dump_stringtable(stringtable_t *stt)
482 * stt - Stringtable resource descriptor
486 *****************************************************************************
488 static void dump_stringtable(stringtable_t
*stt
)
491 for(; stt
; stt
= stt
->next
)
494 dump_memopt(stt
->memopt
);
495 dump_lvc(&(stt
->lvc
));
496 for(i
= 0; i
< stt
->nentries
; i
++)
498 printf("Id=%-5d (%d) ", stt
->idbase
+i
, stt
->entries
[i
].id
);
499 if(stt
->entries
[i
].str
)
500 print_string(stt
->entries
[i
].str
);
510 *****************************************************************************
511 * Function : dump_control
512 * Syntax : void dump_control(control_t *ctrl)
514 * ctrl - Control resource descriptor
518 *****************************************************************************
520 static void dump_control(control_t
*ctrl
)
522 printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl
->ctlclass
));
523 printf("\tText: "); get_nameid_str(ctrl
->title
); printf("\n");
524 printf("\tId: %d\n", ctrl
->id
);
525 printf("\tx, y, w, h: %d, %d, %d, %d\n", ctrl
->x
, ctrl
->y
, ctrl
->width
, ctrl
->height
);
528 assert(ctrl
->style
!= NULL
);
529 assert(ctrl
->style
->and_mask
== 0);
530 printf("\tStyle: %08lx\n", ctrl
->style
->or_mask
);
534 assert(ctrl
->exstyle
!= NULL
);
535 assert(ctrl
->exstyle
->and_mask
== 0);
536 printf("\tExStyle: %08lx\n", ctrl
->exstyle
->or_mask
);
539 printf("\tHelpid: %ld\n", ctrl
->helpid
);
543 dump_raw_data(ctrl
->extra
);
549 *****************************************************************************
550 * Function : dump_dialog
551 * Syntax : void dump_dialog(dialog_t *dlg)
553 * dlg - Dialog resource descriptor
557 *****************************************************************************
559 static void dump_dialog(dialog_t
*dlg
)
561 control_t
*c
= dlg
->controls
;
563 dump_memopt(dlg
->memopt
);
564 dump_lvc(&(dlg
->lvc
));
565 printf("x, y, w, h: %d, %d, %d, %d\n", dlg
->x
, dlg
->y
, dlg
->width
, dlg
->height
);
568 assert(dlg
->style
!= NULL
);
569 assert(dlg
->style
->and_mask
== 0);
570 printf("Style: %08lx\n", dlg
->style
->or_mask
);
575 assert(dlg
->exstyle
!= NULL
);
576 assert(dlg
->exstyle
->and_mask
== 0);
577 printf("ExStyle: %08lx\n", dlg
->exstyle
->or_mask
);
579 printf("Menu: %s\n", get_nameid_str(dlg
->menu
));
580 printf("Class: %s\n", get_nameid_str(dlg
->dlgclass
));
581 printf("Title: "); print_string(dlg
->title
); printf("\n");
587 printf("%d, ", dlg
->font
->size
);
588 print_string(dlg
->font
->name
);
599 *****************************************************************************
600 * Function : dump_dialogex
601 * Syntax : void dump_dialogex(dialogex_t *dlgex)
603 * dlgex - DialogEx resource descriptor
607 *****************************************************************************
609 static void dump_dialogex(dialogex_t
*dlgex
)
611 control_t
*c
= dlgex
->controls
;
613 dump_memopt(dlgex
->memopt
);
614 dump_lvc(&(dlgex
->lvc
));
615 printf("x, y, w, h: %d, %d, %d, %d\n", dlgex
->x
, dlgex
->y
, dlgex
->width
, dlgex
->height
);
618 assert(dlgex
->style
!= NULL
);
619 assert(dlgex
->style
->and_mask
== 0);
620 printf("Style: %08lx\n", dlgex
->style
->or_mask
);
622 if(dlgex
->gotexstyle
)
624 assert(dlgex
->exstyle
!= NULL
);
625 assert(dlgex
->exstyle
->and_mask
== 0);
626 printf("ExStyle: %08lx\n", dlgex
->exstyle
->or_mask
);
629 printf("Helpid: %ld\n", dlgex
->helpid
);
630 printf("Menu: %s\n", get_nameid_str(dlgex
->menu
));
631 printf("Class: %s\n", get_nameid_str(dlgex
->dlgclass
));
632 printf("Title: "); print_string(dlgex
->title
); printf("\n");
638 printf("%d, ", dlgex
->font
->size
);
639 print_string(dlgex
->font
->name
);
640 printf(", %d, %d\n", dlgex
->font
->weight
, dlgex
->font
->italic
);
650 *****************************************************************************
651 * Function : dump_menu_item
652 * Syntax : void dump_menu_item(menu_item_t *item)
657 *****************************************************************************
659 static void dump_menu_item(menu_item_t
*item
)
666 print_string(item
->name
);
668 dump_menu_item(item
->popup
);
675 print_string(item
->name
);
676 printf(", %d, %08lx", item
->id
, item
->state
);
687 *****************************************************************************
688 * Function : dump_menu
689 * Syntax : void dump_menu(menu_t *men)
691 * men - Menu resource descriptor
695 *****************************************************************************
697 static void dump_menu(menu_t
*men
)
699 dump_memopt(men
->memopt
);
700 dump_lvc(&(men
->lvc
));
701 dump_menu_item(men
->items
);
705 *****************************************************************************
706 * Function : dump_menuex_item
707 * Syntax : void dump_menuex_item(menuex_item_t *item)
712 *****************************************************************************
714 static void dump_menuex_item(menuex_item_t
*item
)
721 print_string(item
->name
);
723 printf(", Id=%d", item
->id
);
725 printf(", Type=%ld", item
->type
);
727 printf(", State=%08lx", item
->state
);
729 printf(", HelpId=%d", item
->helpid
);
731 dump_menuex_item(item
->popup
);
738 print_string(item
->name
);
740 printf(", Id=%d", item
->id
);
742 printf(", Type=%ld", item
->type
);
744 printf(", State=%08lx", item
->state
);
746 printf(", HelpId=%d", item
->helpid
);
757 *****************************************************************************
758 * Function : dump_menuex
759 * Syntax : void dump_menuex(dialogex_t *menex)
761 * menex - MenuEx resource descriptor
765 *****************************************************************************
767 static void dump_menuex(menuex_t
*menex
)
769 dump_memopt(menex
->memopt
);
770 dump_lvc(&(menex
->lvc
));
771 dump_menuex_item(menex
->items
);
775 *****************************************************************************
776 * Function : dump_ver_value
777 * Syntax : void dump_ver_value(ver_value_t *val)
782 *****************************************************************************
784 static void dump_ver_block(ver_block_t
*); /* Forward ref */
786 static void dump_ver_value(ver_value_t
*val
)
788 if(val
->type
== val_str
)
791 print_string(val
->key
);
793 print_string(val
->value
.str
);
796 else if(val
->type
== val_words
)
800 print_string(val
->key
);
801 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
802 printf(" %04x", val
->value
.words
->words
[i
]);
805 else if(val
->type
== val_block
)
807 dump_ver_block(val
->value
.block
);
812 *****************************************************************************
813 * Function : dump_ver_block
814 * Syntax : void dump_ver_block(ver_block_t *blk)
819 *****************************************************************************
821 static void dump_ver_block(ver_block_t
*blk
)
823 ver_value_t
*val
= blk
->values
;
825 print_string(blk
->name
);
836 *****************************************************************************
837 * Function : dump_versioninfo
838 * Syntax : void dump_versioninfo(versioninfo_t *ver)
840 * ver - Versioninfo resource descriptor
844 *****************************************************************************
846 static void dump_versioninfo(versioninfo_t
*ver
)
848 ver_block_t
*blk
= ver
->blocks
;
850 dump_lvc(&(ver
->lvc
));
853 printf("FILEVERSION %04x, %04x, %04x, %04x\n",
859 printf("PRODUCTVERSION %04x, %04x, %04x, %04x\n",
865 printf("FILEOS %08x\n", ver
->fileos
);
867 printf("FILEFLAGS %08x\n", ver
->fileflags
);
869 printf("FILEFLAGSMASK %08x\n", ver
->fileflagsmask
);
871 printf("FILETYPE %08x\n", ver
->filetype
);
873 printf("FILESUBTYPE %08x\n", ver
->filesubtype
);
882 *****************************************************************************
883 * Function : dump_toolbar_item
884 * Syntax : void dump_toolbar_item(toolbar_item_t *item)
889 *****************************************************************************
891 static void dump_toolbar_items(toolbar_item_t
*items
)
896 printf(" BUTTON %d", items
->id
);
898 printf(" SEPARATOR");
907 *****************************************************************************
908 * Function : dump_toolbar
909 * Syntax : void dump_toolbar(toolbar_t *toolbar)
911 * toolbar - Toolbar resource descriptor
915 *****************************************************************************
917 static void dump_toolbar(toolbar_t
*toolbar
)
919 dump_memopt(toolbar
->memopt
);
920 dump_lvc(&(toolbar
->lvc
));
921 dump_toolbar_items(toolbar
->items
);
925 *****************************************************************************
926 * Function : dump_dlginit
927 * Syntax : void dump_dlginit(dlginit_t *dit)
929 * dit - DlgInit resource descriptor
933 *****************************************************************************
935 static void dump_dlginit(dlginit_t
*dit
)
937 dump_memopt(dit
->memopt
);
938 dump_lvc(&(dit
->data
->lvc
));
939 dump_raw_data(dit
->data
);
943 *****************************************************************************
950 *****************************************************************************
953 *****************************************************************************
954 * Function : dump_resources
955 * Syntax : void dump_resources(resource_t *top)
957 * top - Top of the resource tree
960 * Description : Dump the parsed resource-tree to stdout
962 *****************************************************************************
964 void dump_resources(resource_t
*top
)
966 printf("Internal resource-tree dump:\n");
969 printf("Resource: %s\nId: %s\n",
971 get_nameid_str(top
->name
));
975 dump_accelerator(top
->res
.acc
);
978 dump_bitmap(top
->res
.bmp
);
981 dump_cursor(top
->res
.cur
);
984 dump_cursor_group(top
->res
.curg
);
987 dump_dialog(top
->res
.dlg
);
990 dump_dialogex(top
->res
.dlgex
);
993 dump_font(top
->res
.fnt
);
996 dump_icon_group(top
->res
.icog
);
999 dump_icon(top
->res
.ico
);
1002 dump_menu(top
->res
.men
);
1005 dump_menuex(top
->res
.menex
);
1008 dump_rcdata(top
->res
.rdt
);
1011 dump_stringtable(top
->res
.stt
);
1014 dump_user(top
->res
.usr
);
1017 dump_messagetable(top
->res
.msg
);
1020 dump_versioninfo(top
->res
.ver
);
1023 dump_dlginit(top
->res
.dlgi
);
1026 dump_toolbar(top
->res
.tbt
);
1030 dump_ani_curico(top
->res
.ani
);
1033 printf("Report this: Unknown resource type parsed %08x\n", top
->type
);