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_dlgex: return "DIALOGEX";
48 case res_fnt: return "FONT";
49 case res_ico: return "ICON";
50 case res_icog: return "GROUP_ICON";
51 case res_men: return "MENU";
52 case res_menex: return "MENUEX";
53 case res_rdt: return "RCDATA";
54 case res_stt: return "STRINGTABLE";
55 case res_usr: return "UserResource";
56 case res_msg: return "MESSAGETABLE";
57 case res_ver: return "VERSIONINFO";
58 case res_dlginit: return "DLGINIT";
59 case res_toolbar: return "TOOLBAR";
60 case res_anicur: return "CURSOR (animated)";
61 case res_aniico: return "ICON (animated)";
62 default: return "Unknown";
67 *****************************************************************************
68 * Function : strncpyWtoA
69 * Syntax : char *strncpyWtoA(char *cs, short *ws, int maxlen)
71 * cs - Pointer to buffer to receive result
72 * ws - Source wide-string
73 * maxlen - Max chars to copy
75 * Description : Copy a unicode string to ascii. Copying stops after the
76 * first occurring '\0' or when maxlen-1 chars are copied. The
77 * String is always nul terminated.
78 * Remarks : No codepage translation is done.
79 *****************************************************************************
81 static char *strncpyWtoA(char *cs, const WCHAR *ws, int maxlen)
84 const WCHAR *wsMax = ws + maxlen - 1;
85 while(*ws && ws < wsMax)
88 fprintf(stderr, "***Warning: Unicode string contains non-printable chars***\n");
89 *cptr++ = (char)*ws++;
96 *****************************************************************************
97 * Function : print_string
98 * Syntax : void print_string(string_t *str)
103 *****************************************************************************
105 static void print_string(const string_t *str)
110 else if(str->type == str_char)
111 printf("\"%s\"", str->str.cstr);
114 strncpyWtoA(buffer, str->str.wstr, sizeof(buffer));
115 printf("L\"%s\"", buffer);
120 *****************************************************************************
121 * Function : get_nameid_str
122 * Syntax : const char *get_nameid_str(const name_id_t *n)
124 * n - nameid to convert to text
125 * Output : A pointer to the name.
127 * Remarks : Not reentrant because of static buffer
128 *****************************************************************************
130 const char *get_nameid_str(const name_id_t *n)
132 static char buffer[256];
137 if(n->type == name_ord)
139 sprintf(buffer, "%d", n->name.i_name);
142 else if(n->type == name_str)
144 if(n->name.s_name->type == str_char)
145 return n->name.s_name->str.cstr;
148 strncpyWtoA(buffer, n->name.s_name->str.wstr, sizeof(buffer));
153 return "Hoooo, report this: wrong type in nameid";
157 *****************************************************************************
158 * Function : dump_memopt
159 * Syntax : void dump_memopt(DWORD memopt)
161 * memopt - flag bits of the options set
165 *****************************************************************************
167 static void dump_memopt(DWORD memopt)
169 printf("Memory/load options: ");
173 printf("LOADONCALL ");
183 printf("DISCARDABLE");
188 *****************************************************************************
189 * Function : dump_lvc
190 * Syntax : void dump_lvc(const lvc_t *l)
192 * l - pointer to lvc structure
194 * Description : Dump language, version and characteristics
196 *****************************************************************************
198 static void dump_lvc(const lvc_t *l)
201 printf("LANGUAGE %04x, %04x\n", l->language->id, l->language->sub);
203 printf("LANGUAGE <not set>\n");
206 printf("VERSION %08lx\n", *(l->version));
208 printf("VERSION <not set>\n");
211 printf("CHARACTERISTICS %08lx\n", *(l->characts));
213 printf("CHARACTERISTICS <not set>\n");
217 *****************************************************************************
218 * Function : dump_raw_data
219 * Syntax : void dump_raw_data(const raw_data_t *d)
221 * d - Raw data descriptor
225 *****************************************************************************
227 static void dump_raw_data(const raw_data_t *d)
238 printf("Rawdata size: %d\n", d->size);
242 for(n = 0; n < d->size; n++)
249 for(i = 0; i < 16; i++)
250 printf("%c", isprint(d->data[n-16+i] & 0xff) ? d->data[n-16+i] : '.');
251 printf("\n%08x: ", n);
256 printf("%02x ", d->data[n] & 0xff);
262 for(i = 0; i < j; i++)
263 printf("%c", isprint(d->data[n-j+i] & 0xff) ? d->data[n-j+i] : '.');
268 *****************************************************************************
269 * Function : dump_accelerator
270 * Syntax : void dump_accelerator(const accelerator_t *acc)
272 * acc - Accelerator resource descriptor
276 *****************************************************************************
278 static void dump_accelerator(const accelerator_t *acc)
280 event_t *ev = acc->events;
282 dump_memopt(acc->memopt);
283 dump_lvc(&(acc->lvc));
285 printf("Events: %s\n", ev ? "" : "<none>");
290 printf("\"%c\"", ev->key);
291 else if(iscntrl(ev->key))
292 printf("\"^%c\"", ev->key +'@');
294 printf("\\x%02x", ev->key & 0xff);
296 printf(" Id=%d flags=%04x\n", ev->id, ev->flags);
302 *****************************************************************************
303 * Function : dump_cursor
304 * Syntax : void dump_cursor(const cursor_t *cur)
306 * cur - Cursor resource descriptor
310 *****************************************************************************
312 static void dump_cursor(const cursor_t *cur)
314 printf("Id: %d\n", cur->id);
315 printf("Width: %d\n", cur->width);
316 printf("Height: %d\n", cur->height);
317 printf("X Hotspot: %d\n", cur->xhot);
318 printf("Y Hotspot: %d\n", cur->yhot);
319 dump_raw_data(cur->data);
323 *****************************************************************************
324 * Function : dump_cursor_group
325 * Syntax : void dump_cursor_group(const cursor_group_t *cur)
327 * cur - Cursor group resource descriptor
331 *****************************************************************************
333 static void dump_cursor_group(const cursor_group_t *curg)
335 dump_memopt(curg->memopt);
336 printf("There are %d cursors in this group\n", curg->ncursor);
340 *****************************************************************************
341 * Function : dump_icon
342 * Syntax : void dump_icon(const icon_t *ico)
344 * ico - Icon resource descriptor
348 *****************************************************************************
350 static void dump_icon(const icon_t *ico)
352 printf("Id: %d\n", ico->id);
353 printf("Width: %d\n", ico->width);
354 printf("Height: %d\n", ico->height);
355 printf("NColor: %d\n", ico->nclr);
356 printf("NPlanes: %d\n", ico->planes);
357 printf("NBits: %d\n", ico->bits);
358 dump_raw_data(ico->data);
362 *****************************************************************************
363 * Function : dump_icon_group
364 * Syntax : void dump_icon_group(const icon_group_t *ico)
366 * ico - Icon group resource descriptor
370 *****************************************************************************
372 static void dump_icon_group(const icon_group_t *icog)
374 dump_memopt(icog->memopt);
375 printf("There are %d icons in this group\n", icog->nicon);
379 *****************************************************************************
380 * Function : dump_ani_curico
381 * Syntax : void dump_ani_curico(const ani_curico_t *ani)
383 * ani - Animated object resource descriptor
387 *****************************************************************************
389 static void dump_ani_curico(const ani_curico_t *ani)
391 dump_memopt(ani->memopt);
392 dump_lvc(&ani->data->lvc);
393 dump_raw_data(ani->data);
397 *****************************************************************************
398 * Function : dump_font
399 * Syntax : void dump_font(const font_t *fnt)
401 * fnt - Font resource descriptor
405 *****************************************************************************
407 static void dump_font(const font_t *fnt)
409 dump_memopt(fnt->memopt);
410 dump_lvc(&(fnt->data->lvc));
411 dump_raw_data(fnt->data);
415 *****************************************************************************
416 * Function : dump_bitmap
417 * Syntax : void dump_bitmap(const bitmap_t *bmp)
419 * bmp - Bitmap resource descriptor
423 *****************************************************************************
425 static void dump_bitmap(const bitmap_t *bmp)
427 dump_memopt(bmp->memopt);
428 dump_lvc(&(bmp->data->lvc));
429 dump_raw_data(bmp->data);
433 *****************************************************************************
434 * Function : dump_rcdata
435 * Syntax : void dump_rcdata(const rcdata_t *rdt)
437 * rdt - RCData resource descriptor
441 *****************************************************************************
443 static void dump_rcdata(const rcdata_t *rdt)
445 dump_memopt(rdt->memopt);
446 dump_lvc(&(rdt->data->lvc));
447 dump_raw_data(rdt->data);
451 *****************************************************************************
452 * Function : dump_user
453 * Syntax : void dump_user(const user_t *usr)
455 * usr - User resource descriptor
459 *****************************************************************************
461 static void dump_user(const user_t *usr)
463 dump_memopt(usr->memopt);
464 dump_lvc(&(usr->data->lvc));
465 printf("Class %s\n", get_nameid_str(usr->type));
466 dump_raw_data(usr->data);
470 *****************************************************************************
471 * Function : dump_messagetable
472 * Syntax : void dump_messagetable(const messagetable_t *msg)
474 * msg - Messagetable resource descriptor
478 *****************************************************************************
480 static void dump_messagetable(const messagetable_t *msg)
482 dump_memopt(msg->memopt);
483 dump_lvc(&(msg->data->lvc));
484 dump_raw_data(msg->data);
488 *****************************************************************************
489 * Function : dump_stringtable
490 * Syntax : void dump_stringtable(const stringtable_t *stt)
492 * stt - Stringtable resource descriptor
496 *****************************************************************************
498 static void dump_stringtable(const stringtable_t *stt)
501 for(; stt; stt = stt->next)
504 dump_memopt(stt->memopt);
505 dump_lvc(&(stt->lvc));
506 for(i = 0; i < stt->nentries; i++)
508 printf("Id=%-5d (%d) ", stt->idbase+i, stt->entries[i].id);
509 if(stt->entries[i].str)
510 print_string(stt->entries[i].str);
520 *****************************************************************************
521 * Function : dump_control
522 * Syntax : void dump_control(const control_t *ctrl)
524 * ctrl - Control resource descriptor
528 *****************************************************************************
530 static void dump_control(const control_t *ctrl)
532 printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl->ctlclass));
533 printf("\tText: "); get_nameid_str(ctrl->title); printf("\n");
534 printf("\tId: %d\n", ctrl->id);
535 printf("\tx, y, w, h: %d, %d, %d, %d\n", ctrl->x, ctrl->y, ctrl->width, ctrl->height);
538 assert(ctrl->style != NULL);
539 assert(ctrl->style->and_mask == 0);
540 printf("\tStyle: %08lx\n", ctrl->style->or_mask);
544 assert(ctrl->exstyle != NULL);
545 assert(ctrl->exstyle->and_mask == 0);
546 printf("\tExStyle: %08lx\n", ctrl->exstyle->or_mask);
549 printf("\tHelpid: %ld\n", ctrl->helpid);
553 dump_raw_data(ctrl->extra);
559 *****************************************************************************
560 * Function : dump_dialog
561 * Syntax : void dump_dialog(const dialog_t *dlg)
563 * dlg - Dialog resource descriptor
567 *****************************************************************************
569 static void dump_dialog(const dialog_t *dlg)
571 control_t *c = dlg->controls;
573 dump_memopt(dlg->memopt);
574 dump_lvc(&(dlg->lvc));
575 printf("x, y, w, h: %d, %d, %d, %d\n", dlg->x, dlg->y, dlg->width, dlg->height);
578 assert(dlg->style != NULL);
579 assert(dlg->style->and_mask == 0);
580 printf("Style: %08lx\n", dlg->style->or_mask);
585 assert(dlg->exstyle != NULL);
586 assert(dlg->exstyle->and_mask == 0);
587 printf("ExStyle: %08lx\n", dlg->exstyle->or_mask);
589 printf("Menu: %s\n", get_nameid_str(dlg->menu));
590 printf("Class: %s\n", get_nameid_str(dlg->dlgclass));
591 printf("Title: "); print_string(dlg->title); printf("\n");
597 printf("%d, ", dlg->font->size);
598 print_string(dlg->font->name);
609 *****************************************************************************
610 * Function : dump_dialogex
611 * Syntax : void dump_dialogex(const dialogex_t *dlgex)
613 * dlgex - DialogEx resource descriptor
617 *****************************************************************************
619 static void dump_dialogex(const dialogex_t *dlgex)
621 const control_t *c = dlgex->controls;
623 dump_memopt(dlgex->memopt);
624 dump_lvc(&(dlgex->lvc));
625 printf("x, y, w, h: %d, %d, %d, %d\n", dlgex->x, dlgex->y, dlgex->width, dlgex->height);
628 assert(dlgex->style != NULL);
629 assert(dlgex->style->and_mask == 0);
630 printf("Style: %08lx\n", dlgex->style->or_mask);
632 if(dlgex->gotexstyle)
634 assert(dlgex->exstyle != NULL);
635 assert(dlgex->exstyle->and_mask == 0);
636 printf("ExStyle: %08lx\n", dlgex->exstyle->or_mask);
639 printf("Helpid: %ld\n", dlgex->helpid);
640 printf("Menu: %s\n", get_nameid_str(dlgex->menu));
641 printf("Class: %s\n", get_nameid_str(dlgex->dlgclass));
642 printf("Title: "); print_string(dlgex->title); printf("\n");
648 printf("%d, ", dlgex->font->size);
649 print_string(dlgex->font->name);
650 printf(", %d, %d\n", dlgex->font->weight, dlgex->font->italic);
660 *****************************************************************************
661 * Function : dump_menu_item
662 * Syntax : void dump_menu_item(const menu_item_t *item)
667 *****************************************************************************
669 static void dump_menu_item(const menu_item_t *item)
676 print_string(item->name);
678 dump_menu_item(item->popup);
685 print_string(item->name);
686 printf(", %d, %08lx", item->id, item->state);
697 *****************************************************************************
698 * Function : dump_menu
699 * Syntax : void dump_menu(const menu_t *men)
701 * men - Menu resource descriptor
705 *****************************************************************************
707 static void dump_menu(const menu_t *men)
709 dump_memopt(men->memopt);
710 dump_lvc(&(men->lvc));
711 dump_menu_item(men->items);
715 *****************************************************************************
716 * Function : dump_menuex_item
717 * Syntax : void dump_menuex_item(const menuex_item_t *item)
722 *****************************************************************************
724 static void dump_menuex_item(const menuex_item_t *item)
731 print_string(item->name);
733 printf(", Id=%d", item->id);
735 printf(", Type=%ld", item->type);
737 printf(", State=%08lx", item->state);
739 printf(", HelpId=%d", item->helpid);
741 dump_menuex_item(item->popup);
748 print_string(item->name);
750 printf(", Id=%d", item->id);
752 printf(", Type=%ld", item->type);
754 printf(", State=%08lx", item->state);
756 printf(", HelpId=%d", item->helpid);
767 *****************************************************************************
768 * Function : dump_menuex
769 * Syntax : void dump_menuex(const menuex_t *menex)
771 * menex - MenuEx resource descriptor
775 *****************************************************************************
777 static void dump_menuex(const menuex_t *menex)
779 dump_memopt(menex->memopt);
780 dump_lvc(&(menex->lvc));
781 dump_menuex_item(menex->items);
785 *****************************************************************************
786 * Function : dump_ver_value
787 * Syntax : void dump_ver_value(const ver_value_t *val)
792 *****************************************************************************
794 static void dump_ver_block(const ver_block_t *); /* Forward ref */
796 static void dump_ver_value(const ver_value_t *val)
798 if(val->type == val_str)
801 print_string(val->key);
803 print_string(val->value.str);
806 else if(val->type == val_words)
810 print_string(val->key);
811 for(i = 0; i < val->value.words->nwords; i++)
812 printf(" %04x", val->value.words->words[i]);
815 else if(val->type == val_block)
817 dump_ver_block(val->value.block);
822 *****************************************************************************
823 * Function : dump_ver_block
824 * Syntax : void dump_ver_block(const ver_block_t *blk)
829 *****************************************************************************
831 static void dump_ver_block(const ver_block_t *blk)
833 const ver_value_t *val = blk->values;
835 print_string(blk->name);
846 *****************************************************************************
847 * Function : dump_versioninfo
848 * Syntax : void dump_versioninfo(const versioninfo_t *ver)
850 * ver - Versioninfo resource descriptor
854 *****************************************************************************
856 static void dump_versioninfo(const versioninfo_t *ver)
858 const ver_block_t *blk = ver->blocks;
860 dump_lvc(&(ver->lvc));
863 printf("FILEVERSION %04x, %04x, %04x, %04x\n",
869 printf("PRODUCTVERSION %04x, %04x, %04x, %04x\n",
875 printf("FILEOS %08x\n", ver->fileos);
877 printf("FILEFLAGS %08x\n", ver->fileflags);
879 printf("FILEFLAGSMASK %08x\n", ver->fileflagsmask);
881 printf("FILETYPE %08x\n", ver->filetype);
883 printf("FILESUBTYPE %08x\n", ver->filesubtype);
892 *****************************************************************************
893 * Function : dump_toolbar_item
894 * Syntax : void dump_toolbar_item(const toolbar_item_t *item)
899 *****************************************************************************
901 static void dump_toolbar_items(const toolbar_item_t *items)
906 printf(" BUTTON %d", items->id );
908 printf(" SEPARATOR");
917 *****************************************************************************
918 * Function : dump_toolbar
919 * Syntax : void dump_toolbar(const toolbar_t *toolbar)
921 * toolbar - Toolbar resource descriptor
925 *****************************************************************************
927 static void dump_toolbar(const toolbar_t *toolbar)
929 dump_memopt(toolbar->memopt);
930 dump_lvc(&(toolbar->lvc));
931 dump_toolbar_items(toolbar->items);
935 *****************************************************************************
936 * Function : dump_dlginit
937 * Syntax : void dump_dlginit(const dlginit_t *dit)
939 * dit - DlgInit resource descriptor
943 *****************************************************************************
945 static void dump_dlginit(const dlginit_t *dit)
947 dump_memopt(dit->memopt);
948 dump_lvc(&(dit->data->lvc));
949 dump_raw_data(dit->data);
953 *****************************************************************************
954 * Function : dump_resources
955 * Syntax : void dump_resources(const resource_t *top)
957 * top - Top of the resource tree
960 * Description : Dump the parsed resource-tree to stdout
962 *****************************************************************************
964 void dump_resources(const 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);