2 * Copyrignt 1998 Bertho A. Stultiens (BS)
4 * 16-Apr-1998 BS - Yeah, dump it to stdout.
16 *****************************************************************************
17 * Function : get_typename
18 * Syntax : char *get_typename(resource_t* r)
20 * r - Resource description
21 * Output : A pointer to a string representing the resource type
24 *****************************************************************************
26 char *get_typename(resource_t
* r
)
29 case res_acc
: return "ACCELERATOR";
30 case res_bmp
: return "BITMAP";
31 case res_cur
: return "CURSOR";
32 case res_curg
: return "GROUP_CURSOR";
33 case res_dlg
: return "DIALOG";
34 case res_dlgex
: return "DIALOGEX";
35 case res_fnt
: return "FONT";
36 case res_ico
: return "ICON";
37 case res_icog
: return "GROUP_ICON";
38 case res_men
: return "MENU";
39 case res_menex
: return "MENUEX";
40 case res_rdt
: return "RCDATA";
41 case res_stt
: return "STRINGTABLE";
42 case res_usr
: return "UserResource";
43 case res_msg
: return "MESSAGETABLE";
44 case res_ver
: return "VERSIONINFO";
45 default: return "Unknown";
50 *****************************************************************************
51 * Function : strncpyWtoA
52 * Syntax : char *strncpyWtoA(char *cs, short *ws, int maxlen)
54 * cs - Pointer to buffer to receive result
55 * ws - Source wide-string
56 * maxlen - Max chars to copy
58 * Description : Copy a unicode string to ascii. Copying stops after the
59 * first occuring '\0' or when maxlen-1 chars are copied. The
60 * String is always nul terminated.
61 * Remarks : No codepage translation is done.
62 *****************************************************************************
64 char *strncpyWtoA(char *cs
, short *ws
, int maxlen
)
67 while(*ws
&& maxlen
-1)
69 if(*ws
< -128 || *ws
> 127)
70 printf("***Warning: Unicode string contains non-printable chars***");
71 *cptr
++ = (char)*ws
++;
79 *****************************************************************************
80 * Function : print_string
81 * Syntax : void print_string(string_t *str)
86 *****************************************************************************
88 void print_string(string_t
*str
)
93 else if(str
->type
== str_char
)
94 printf("\"%s\"", str
->str
.cstr
);
97 strncpyWtoA(buffer
, str
->str
.wstr
, sizeof(buffer
));
98 printf("L\"%s\"", buffer
);
103 *****************************************************************************
104 * Function : get_nameid_str
105 * Syntax : char *get_nameid_str(name_id_t *n)
107 * n - nameid to convert to text
108 * Output : A pointer to the name.
110 * Remarks : Not reentrant because of static buffer
111 *****************************************************************************
113 char *get_nameid_str(name_id_t
*n
)
115 static char buffer
[256];
120 if(n
->type
== name_ord
)
122 sprintf(buffer
, "%d", n
->name
.i_name
);
125 else if(n
->type
== name_str
)
127 if(n
->name
.s_name
->type
== str_char
)
128 return n
->name
.s_name
->str
.cstr
;
131 strncpyWtoA(buffer
, n
->name
.s_name
->str
.wstr
, sizeof(buffer
));
136 return "Hoooo, report this: wrong type in nameid";
140 *****************************************************************************
141 * Function : dump_memopt
142 * Syntax : void dump_memopt(DWORD memopt)
144 * memopt - flag bits of the options set
148 *****************************************************************************
150 void dump_memopt(DWORD memopt
)
152 printf("Memory/load options: ");
156 printf("LOADONCALL ");
166 printf("DISCARDABLE");
171 *****************************************************************************
172 * Function : dump_lvc
173 * Syntax : void dump_lvc(lvc_t *l)
175 * l - pointer to lvc structure
177 * Description : Dump language, version and characteristics
179 *****************************************************************************
181 void dump_lvc(lvc_t
*l
)
184 printf("LANGUAGE %04x, %04x\n", l
->language
->id
, l
->language
->sub
);
186 printf("LANGUAGE <not set>\n");
189 printf("VERSION %08lx\n", *(l
->version
));
191 printf("VERSION <not set>\n");
194 printf("CHARACTERISTICS %08lx\n", *(l
->characts
));
196 printf("CHARACTERISTICS <not set>\n");
200 *****************************************************************************
201 * Function : dump_raw_data
202 * Syntax : void dump_raw_data(raw_data_t *d)
204 * d - Raw data descriptor
208 *****************************************************************************
210 void dump_raw_data(raw_data_t
*d
)
221 printf("Rawdata size: %d\n", d
->size
);
225 for(n
= 0; n
< d
->size
; n
++)
231 for(i
= 0; i
< 16; i
++)
232 printf("%c", isprint(d
->data
[n
-16+i
]) ? d
->data
[n
-16+i
] : '.');
233 printf("\n%08x: ", n
);
237 printf("%02x ", d
->data
[n
] & 0xff);
243 for(i
= 0; i
< j
; i
++)
244 printf("%c", isprint(d
->data
[n
-j
+i
]) ? d
->data
[n
-j
+i
] : '.');
249 *****************************************************************************
250 * Function : dump_accelerator
251 * Syntax : void dump_accelerator(resource_t *acc)
253 * acc - Accelerator resource descriptor
257 *****************************************************************************
259 void dump_accelerator(accelerator_t
*acc
)
261 event_t
*ev
= acc
->events
;
263 dump_memopt(acc
->memopt
);
264 dump_lvc(&(acc
->lvc
));
266 printf("Events: %s\n", ev
? "" : "<none>");
271 printf("\"%c\"", ev
->key
);
272 else if(iscntrl(ev
->key
))
273 printf("\"^%c\"", ev
->key
+'@');
275 printf("\\x%02x", ev
->key
& 0xff);
277 printf(" Id=%d flags=%04x\n", ev
->id
, ev
->flags
);
283 *****************************************************************************
284 * Function : dump_cursor
285 * Syntax : void dump_cursor(cursor_t *cur)
287 * cur - Cursor resource descriptor
291 *****************************************************************************
293 void dump_cursor(cursor_t
*cur
)
295 printf("Id: %d\n", cur
->id
);
296 printf("Width: %d\n", cur
->width
);
297 printf("Height: %d\n", cur
->height
);
298 printf("X Hotspot: %d\n", cur
->xhot
);
299 printf("Y Hotspot: %d\n", cur
->yhot
);
300 dump_raw_data(cur
->data
);
304 *****************************************************************************
305 * Function : dump_cursor_group
306 * Syntax : void dump_cursor_group(cursor_group_t *cur)
308 * cur - Cursor group resource descriptor
312 *****************************************************************************
314 void dump_cursor_group(cursor_group_t
*curg
)
316 dump_memopt(curg
->memopt
);
317 printf("There are %d cursors in this group\n", curg
->ncursor
);
321 *****************************************************************************
322 * Function : dump_icon
323 * Syntax : void dump_icon(icon_t *ico)
325 * ico - Icon resource descriptor
329 *****************************************************************************
331 void dump_icon(icon_t
*ico
)
333 printf("Id: %d\n", ico
->id
);
334 printf("Width: %d\n", ico
->width
);
335 printf("Height: %d\n", ico
->height
);
336 printf("NColor: %d\n", ico
->nclr
);
337 printf("NPlanes: %d\n", ico
->planes
);
338 printf("NBits: %d\n", ico
->bits
);
339 dump_raw_data(ico
->data
);
343 *****************************************************************************
344 * Function : dump_icon_group
345 * Syntax : void dump_icon_group(icon_group_t *ico)
347 * ico - Icon group resource descriptor
351 *****************************************************************************
353 void dump_icon_group(icon_group_t
*icog
)
355 dump_memopt(icog
->memopt
);
356 printf("There are %d icons in this group\n", icog
->nicon
);
360 *****************************************************************************
361 * Function : dump_font
362 * Syntax : void dump_font(font_t *fnt)
364 * fnt - Font resource descriptor
368 *****************************************************************************
370 void dump_font(font_t
*fnt
)
372 dump_memopt(fnt
->memopt
);
373 dump_raw_data(fnt
->data
);
377 *****************************************************************************
378 * Function : dump_bitmap
379 * Syntax : void dump_bitmap(bitmap_t *bmp)
381 * bmp - Bitmap resource descriptor
385 *****************************************************************************
387 void dump_bitmap(bitmap_t
*bmp
)
389 dump_memopt(bmp
->memopt
);
390 dump_raw_data(bmp
->data
);
394 *****************************************************************************
395 * Function : dump_rcdata
396 * Syntax : void dump_rcdata(rcdata_t *rdt)
398 * rdt - RCData resource descriptor
402 *****************************************************************************
404 void dump_rcdata(rcdata_t
*rdt
)
406 dump_memopt(rdt
->memopt
);
407 dump_raw_data(rdt
->data
);
411 *****************************************************************************
412 * Function : dump_user
413 * Syntax : void dump_user(user_t *usr)
415 * usr - User resource descriptor
419 *****************************************************************************
421 void dump_user(user_t
*usr
)
423 dump_memopt(usr
->memopt
);
424 printf("Class %s\n", get_nameid_str(usr
->type
));
425 dump_raw_data(usr
->data
);
429 *****************************************************************************
430 * Function : dump_messagetable
431 * Syntax : void dump_messagetable(messagetable_t *msg)
433 * msg - Messagetable resource descriptor
437 *****************************************************************************
439 void dump_messagetable(messagetable_t
*msg
)
441 dump_raw_data(msg
->data
);
445 *****************************************************************************
446 * Function : dump_stringtable
447 * Syntax : void dump_stringtable(stringtable_t *stt)
449 * stt - Stringtable resource descriptor
453 *****************************************************************************
455 void dump_stringtable(stringtable_t
*stt
)
458 for(; stt
; stt
= stt
->next
)
461 dump_memopt(stt
->memopt
);
462 dump_lvc(&(stt
->lvc
));
463 for(i
= 0; i
< stt
->nentries
; i
++)
465 printf("Id=%-5d (%d) ", stt
->idbase
+i
, stt
->entries
[i
].id
);
466 if(stt
->entries
[i
].str
)
467 print_string(stt
->entries
[i
].str
);
477 *****************************************************************************
478 * Function : dump_control
479 * Syntax : void dump_control(control_t *ctrl)
481 * ctrl - Control resource descriptor
485 *****************************************************************************
487 void dump_control(control_t
*ctrl
)
489 printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl
->ctlclass
));
490 printf("\tText: "); print_string(ctrl
->title
); printf("\n");
491 printf("\tId: %d\n", ctrl
->id
);
492 printf("\tx, y, w, h: %d, %d, %d, %d\n", ctrl
->x
, ctrl
->y
, ctrl
->width
, ctrl
->height
);
494 printf("\tStyle: %08lx\n", ctrl
->style
);
496 printf("\tExStyle: %08lx\n", ctrl
->exstyle
);
498 printf("\tHelpid: %ld\n", ctrl
->helpid
);
502 dump_raw_data(ctrl
->extra
);
508 *****************************************************************************
509 * Function : dump_dialog
510 * Syntax : void dump_dialog(dialog_t *dlg)
512 * dlg - Dialog resource descriptor
516 *****************************************************************************
518 void dump_dialog(dialog_t
*dlg
)
520 control_t
*c
= dlg
->controls
;
522 dump_memopt(dlg
->memopt
);
523 dump_lvc(&(dlg
->lvc
));
524 printf("x, y, w, h: %d, %d, %d, %d\n", dlg
->x
, dlg
->y
, dlg
->width
, dlg
->height
);
526 printf("Style: %08lx\n", dlg
->style
);
528 printf("ExStyle: %08lx\n", dlg
->exstyle
);
529 printf("Menu: %s\n", get_nameid_str(dlg
->menu
));
530 printf("Class: %s\n", get_nameid_str(dlg
->dlgclass
));
531 printf("Title: "); print_string(dlg
->title
); printf("\n");
537 printf("%d, ", dlg
->font
->size
);
538 print_string(dlg
->font
->name
);
549 *****************************************************************************
550 * Function : dump_dialogex
551 * Syntax : void dump_dialogex(dialogex_t *dlgex)
553 * dlgex - DialogEx resource descriptor
557 *****************************************************************************
559 void dump_dialogex(dialogex_t
*dlgex
)
561 control_t
*c
= dlgex
->controls
;
563 dump_memopt(dlgex
->memopt
);
564 dump_lvc(&(dlgex
->lvc
));
565 printf("x, y, w, h: %d, %d, %d, %d\n", dlgex
->x
, dlgex
->y
, dlgex
->width
, dlgex
->height
);
567 printf("Style: %08lx\n", dlgex
->style
);
568 if(dlgex
->gotexstyle
)
569 printf("ExStyle: %08lx\n", dlgex
->exstyle
);
571 printf("Helpid: %ld\n", dlgex
->helpid
);
572 printf("Menu: %s\n", get_nameid_str(dlgex
->menu
));
573 printf("Class: %s\n", get_nameid_str(dlgex
->dlgclass
));
574 printf("Title: "); print_string(dlgex
->title
); printf("\n");
580 printf("%d, ", dlgex
->font
->size
);
581 print_string(dlgex
->font
->name
);
582 printf(", %d, %d\n", dlgex
->font
->weight
, dlgex
->font
->italic
);
592 *****************************************************************************
593 * Function : dump_menu_item
594 * Syntax : void dump_menu_item(menu_item_t *item)
599 *****************************************************************************
601 void dump_menu_item(menu_item_t
*item
)
608 print_string(item
->name
);
610 dump_menu_item(item
->popup
);
617 print_string(item
->name
);
618 printf(", %d, %08lx", item
->id
, item
->state
);
629 *****************************************************************************
630 * Function : dump_menu
631 * Syntax : void dump_menu(menu_t *men)
633 * men - Menu resource descriptor
637 *****************************************************************************
639 void dump_menu(menu_t
*men
)
641 dump_memopt(men
->memopt
);
642 dump_lvc(&(men
->lvc
));
643 dump_menu_item(men
->items
);
647 *****************************************************************************
648 * Function : dump_menuex_item
649 * Syntax : void dump_menuex_item(menuex_item_t *item)
654 *****************************************************************************
656 void dump_menuex_item(menuex_item_t
*item
)
663 print_string(item
->name
);
665 printf(", Id=%d", item
->id
);
667 printf(", Type=%ld", item
->type
);
669 printf(", State=%08lx", item
->state
);
671 printf(", HelpId=%d", item
->helpid
);
673 dump_menuex_item(item
->popup
);
680 print_string(item
->name
);
682 printf(", Id=%d", item
->id
);
684 printf(", Type=%ld", item
->type
);
686 printf(", State=%08lx", item
->state
);
688 printf(", HelpId=%d", item
->helpid
);
699 *****************************************************************************
700 * Function : dump_menuex
701 * Syntax : void dump_menuex(dialogex_t *menex)
703 * menex - MenuEx resource descriptor
707 *****************************************************************************
709 void dump_menuex(menuex_t
*menex
)
711 dump_memopt(menex
->memopt
);
712 dump_lvc(&(menex
->lvc
));
713 dump_menuex_item(menex
->items
);
717 *****************************************************************************
718 * Function : dump_ver_value
719 * Syntax : void dump_ver_value(ver_value_t *val)
724 *****************************************************************************
726 void dump_ver_value(ver_value_t
*val
)
728 extern void dump_ver_block(ver_block_t
*);
729 if(val
->type
== val_str
)
732 print_string(val
->key
);
734 print_string(val
->value
.str
);
737 else if(val
->type
== val_words
)
741 print_string(val
->key
);
742 for(i
= 0; i
< val
->value
.words
->nwords
; i
++)
743 printf(" %04x", val
->value
.words
->words
[i
]);
746 else if(val
->type
== val_block
)
748 dump_ver_block(val
->value
.block
);
753 *****************************************************************************
754 * Function : dump_ver_block
755 * Syntax : void dump_ver_block(ver_block_t *blk)
760 *****************************************************************************
762 void dump_ver_block(ver_block_t
*blk
)
764 ver_value_t
*val
= blk
->values
;
766 print_string(blk
->name
);
777 *****************************************************************************
778 * Function : dump_versioninfo
779 * Syntax : void dump_versioninfo(versioninfo_t *ver)
781 * ver - Versioninfo resource descriptor
785 *****************************************************************************
787 void dump_versioninfo(versioninfo_t
*ver
)
789 ver_block_t
*blk
= ver
->blocks
;
792 printf("FILEVERSION %04x, %04x, %04x, %04x\n",
798 printf("PRODUCTVERSION %04x, %04x, %04x, %04x\n",
804 printf("FILEOS %08x\n", ver
->fileos
);
806 printf("FILEFLAGS %08x\n", ver
->fileflags
);
808 printf("FILEFLAGSMASK %08x\n", ver
->fileflagsmask
);
810 printf("FILETYPE %08x\n", ver
->filetype
);
812 printf("FILESUBTYPE %08x\n", ver
->filesubtype
);
821 *****************************************************************************
828 *****************************************************************************
831 *****************************************************************************
832 * Function : dump_resources
833 * Syntax : void dump_resources(resource_t *top)
835 * top - Top of the resource tree
838 * Description : Dump the parsed resource-tree to stdout
840 *****************************************************************************
842 void dump_resources(resource_t
*top
)
844 printf("Internal resource-tree dump:\n");
847 printf("Resource: %s\nId: %s\n",
849 get_nameid_str(top
->name
));
853 dump_accelerator(top
->res
.acc
);
856 dump_bitmap(top
->res
.bmp
);
859 dump_cursor(top
->res
.cur
);
862 dump_cursor_group(top
->res
.curg
);
865 dump_dialog(top
->res
.dlg
);
868 dump_dialogex(top
->res
.dlgex
);
871 dump_font(top
->res
.fnt
);
874 dump_icon_group(top
->res
.icog
);
877 dump_icon(top
->res
.ico
);
880 dump_menu(top
->res
.men
);
883 dump_menuex(top
->res
.menex
);
886 dump_rcdata(top
->res
.rdt
);
889 dump_stringtable(top
->res
.stt
);
892 dump_user(top
->res
.usr
);
895 dump_messagetable(top
->res
.msg
);
898 dump_versioninfo(top
->res
.ver
);
901 printf("Report this: Unknown resource type parsed %08x\n", top
->type
);