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 case res_toolbar: return "TOOLBAR";
46 default: return "Unknown";
51 *****************************************************************************
52 * Function : strncpyWtoA
53 * Syntax : char *strncpyWtoA(char *cs, short *ws, int maxlen)
55 * cs - Pointer to buffer to receive result
56 * ws - Source wide-string
57 * maxlen - Max chars to copy
59 * Description : Copy a unicode string to ascii. Copying stops after the
60 * first occuring '\0' or when maxlen-1 chars are copied. The
61 * String is always nul terminated.
62 * Remarks : No codepage translation is done.
63 *****************************************************************************
65 char *strncpyWtoA(char *cs, short *ws, int maxlen)
68 short *wsMax = ws + maxlen;
71 if(*ws < -128 || *ws > 127)
72 printf("***Warning: Unicode string contains non-printable chars***");
73 *cptr++ = (char)*ws++;
81 *****************************************************************************
82 * Function : print_string
83 * Syntax : void print_string(string_t *str)
88 *****************************************************************************
90 void print_string(string_t *str)
95 else if(str->type == str_char)
96 printf("\"%s\"", str->str.cstr);
99 strncpyWtoA(buffer, str->str.wstr, sizeof(buffer));
100 printf("L\"%s\"", buffer);
105 *****************************************************************************
106 * Function : get_nameid_str
107 * Syntax : char *get_nameid_str(name_id_t *n)
109 * n - nameid to convert to text
110 * Output : A pointer to the name.
112 * Remarks : Not reentrant because of static buffer
113 *****************************************************************************
115 char *get_nameid_str(name_id_t *n)
117 static char buffer[256];
122 if(n->type == name_ord)
124 sprintf(buffer, "%d", n->name.i_name);
127 else if(n->type == name_str)
129 if(n->name.s_name->type == str_char)
130 return n->name.s_name->str.cstr;
133 strncpyWtoA(buffer, n->name.s_name->str.wstr, sizeof(buffer));
138 return "Hoooo, report this: wrong type in nameid";
142 *****************************************************************************
143 * Function : dump_memopt
144 * Syntax : void dump_memopt(DWORD memopt)
146 * memopt - flag bits of the options set
150 *****************************************************************************
152 void dump_memopt(DWORD memopt)
154 printf("Memory/load options: ");
158 printf("LOADONCALL ");
168 printf("DISCARDABLE");
173 *****************************************************************************
174 * Function : dump_lvc
175 * Syntax : void dump_lvc(lvc_t *l)
177 * l - pointer to lvc structure
179 * Description : Dump language, version and characteristics
181 *****************************************************************************
183 void dump_lvc(lvc_t *l)
186 printf("LANGUAGE %04x, %04x\n", l->language->id, l->language->sub);
188 printf("LANGUAGE <not set>\n");
191 printf("VERSION %08lx\n", *(l->version));
193 printf("VERSION <not set>\n");
196 printf("CHARACTERISTICS %08lx\n", *(l->characts));
198 printf("CHARACTERISTICS <not set>\n");
202 *****************************************************************************
203 * Function : dump_raw_data
204 * Syntax : void dump_raw_data(raw_data_t *d)
206 * d - Raw data descriptor
210 *****************************************************************************
212 void dump_raw_data(raw_data_t *d)
223 printf("Rawdata size: %d\n", d->size);
227 for(n = 0; n < d->size; n++)
234 for(i = 0; i < 16; i++)
235 printf("%c", isprint(d->data[n-16+i]) ? d->data[n-16+i] : '.');
236 printf("\n%08x: ", n);
241 printf("%02x ", d->data[n] & 0xff);
247 for(i = 0; i < j; i++)
248 printf("%c", isprint(d->data[n-j+i]) ? d->data[n-j+i] : '.');
253 *****************************************************************************
254 * Function : dump_accelerator
255 * Syntax : void dump_accelerator(resource_t *acc)
257 * acc - Accelerator resource descriptor
261 *****************************************************************************
263 void dump_accelerator(accelerator_t *acc)
265 event_t *ev = acc->events;
267 dump_memopt(acc->memopt);
268 dump_lvc(&(acc->lvc));
270 printf("Events: %s\n", ev ? "" : "<none>");
275 printf("\"%c\"", ev->key);
276 else if(iscntrl(ev->key))
277 printf("\"^%c\"", ev->key +'@');
279 printf("\\x%02x", ev->key & 0xff);
281 printf(" Id=%d flags=%04x\n", ev->id, ev->flags);
287 *****************************************************************************
288 * Function : dump_cursor
289 * Syntax : void dump_cursor(cursor_t *cur)
291 * cur - Cursor resource descriptor
295 *****************************************************************************
297 void dump_cursor(cursor_t *cur)
299 printf("Id: %d\n", cur->id);
300 printf("Width: %d\n", cur->width);
301 printf("Height: %d\n", cur->height);
302 printf("X Hotspot: %d\n", cur->xhot);
303 printf("Y Hotspot: %d\n", cur->yhot);
304 dump_raw_data(cur->data);
308 *****************************************************************************
309 * Function : dump_cursor_group
310 * Syntax : void dump_cursor_group(cursor_group_t *cur)
312 * cur - Cursor group resource descriptor
316 *****************************************************************************
318 void dump_cursor_group(cursor_group_t *curg)
320 dump_memopt(curg->memopt);
321 printf("There are %d cursors in this group\n", curg->ncursor);
325 *****************************************************************************
326 * Function : dump_icon
327 * Syntax : void dump_icon(icon_t *ico)
329 * ico - Icon resource descriptor
333 *****************************************************************************
335 void dump_icon(icon_t *ico)
337 printf("Id: %d\n", ico->id);
338 printf("Width: %d\n", ico->width);
339 printf("Height: %d\n", ico->height);
340 printf("NColor: %d\n", ico->nclr);
341 printf("NPlanes: %d\n", ico->planes);
342 printf("NBits: %d\n", ico->bits);
343 dump_raw_data(ico->data);
347 *****************************************************************************
348 * Function : dump_icon_group
349 * Syntax : void dump_icon_group(icon_group_t *ico)
351 * ico - Icon group resource descriptor
355 *****************************************************************************
357 void dump_icon_group(icon_group_t *icog)
359 dump_memopt(icog->memopt);
360 printf("There are %d icons in this group\n", icog->nicon);
364 *****************************************************************************
365 * Function : dump_font
366 * Syntax : void dump_font(font_t *fnt)
368 * fnt - Font resource descriptor
372 *****************************************************************************
374 void dump_font(font_t *fnt)
376 dump_memopt(fnt->memopt);
377 dump_raw_data(fnt->data);
381 *****************************************************************************
382 * Function : dump_bitmap
383 * Syntax : void dump_bitmap(bitmap_t *bmp)
385 * bmp - Bitmap resource descriptor
389 *****************************************************************************
391 void dump_bitmap(bitmap_t *bmp)
393 dump_memopt(bmp->memopt);
394 dump_raw_data(bmp->data);
398 *****************************************************************************
399 * Function : dump_rcdata
400 * Syntax : void dump_rcdata(rcdata_t *rdt)
402 * rdt - RCData resource descriptor
406 *****************************************************************************
408 void dump_rcdata(rcdata_t *rdt)
410 dump_memopt(rdt->memopt);
411 dump_raw_data(rdt->data);
415 *****************************************************************************
416 * Function : dump_user
417 * Syntax : void dump_user(user_t *usr)
419 * usr - User resource descriptor
423 *****************************************************************************
425 void dump_user(user_t *usr)
427 dump_memopt(usr->memopt);
428 printf("Class %s\n", get_nameid_str(usr->type));
429 dump_raw_data(usr->data);
433 *****************************************************************************
434 * Function : dump_messagetable
435 * Syntax : void dump_messagetable(messagetable_t *msg)
437 * msg - Messagetable resource descriptor
441 *****************************************************************************
443 void dump_messagetable(messagetable_t *msg)
445 dump_raw_data(msg->data);
449 *****************************************************************************
450 * Function : dump_stringtable
451 * Syntax : void dump_stringtable(stringtable_t *stt)
453 * stt - Stringtable resource descriptor
457 *****************************************************************************
459 void dump_stringtable(stringtable_t *stt)
462 for(; stt; stt = stt->next)
465 dump_memopt(stt->memopt);
466 dump_lvc(&(stt->lvc));
467 for(i = 0; i < stt->nentries; i++)
469 printf("Id=%-5d (%d) ", stt->idbase+i, stt->entries[i].id);
470 if(stt->entries[i].str)
471 print_string(stt->entries[i].str);
481 *****************************************************************************
482 * Function : dump_control
483 * Syntax : void dump_control(control_t *ctrl)
485 * ctrl - Control resource descriptor
489 *****************************************************************************
491 void dump_control(control_t *ctrl)
493 printf("Control {\n\tClass: %s\n", get_nameid_str(ctrl->ctlclass));
494 printf("\tText: "); print_string(ctrl->title); printf("\n");
495 printf("\tId: %d\n", ctrl->id);
496 printf("\tx, y, w, h: %d, %d, %d, %d\n", ctrl->x, ctrl->y, ctrl->width, ctrl->height);
498 printf("\tStyle: %08lx\n", ctrl->style);
500 printf("\tExStyle: %08lx\n", ctrl->exstyle);
502 printf("\tHelpid: %ld\n", ctrl->helpid);
506 dump_raw_data(ctrl->extra);
512 *****************************************************************************
513 * Function : dump_dialog
514 * Syntax : void dump_dialog(dialog_t *dlg)
516 * dlg - Dialog resource descriptor
520 *****************************************************************************
522 void dump_dialog(dialog_t *dlg)
524 control_t *c = dlg->controls;
526 dump_memopt(dlg->memopt);
527 dump_lvc(&(dlg->lvc));
528 printf("x, y, w, h: %d, %d, %d, %d\n", dlg->x, dlg->y, dlg->width, dlg->height);
530 printf("Style: %08lx\n", dlg->style);
532 printf("ExStyle: %08lx\n", dlg->exstyle);
533 printf("Menu: %s\n", get_nameid_str(dlg->menu));
534 printf("Class: %s\n", get_nameid_str(dlg->dlgclass));
535 printf("Title: "); print_string(dlg->title); printf("\n");
541 printf("%d, ", dlg->font->size);
542 print_string(dlg->font->name);
553 *****************************************************************************
554 * Function : dump_dialogex
555 * Syntax : void dump_dialogex(dialogex_t *dlgex)
557 * dlgex - DialogEx resource descriptor
561 *****************************************************************************
563 void dump_dialogex(dialogex_t *dlgex)
565 control_t *c = dlgex->controls;
567 dump_memopt(dlgex->memopt);
568 dump_lvc(&(dlgex->lvc));
569 printf("x, y, w, h: %d, %d, %d, %d\n", dlgex->x, dlgex->y, dlgex->width, dlgex->height);
571 printf("Style: %08lx\n", dlgex->style);
572 if(dlgex->gotexstyle)
573 printf("ExStyle: %08lx\n", dlgex->exstyle);
575 printf("Helpid: %ld\n", dlgex->helpid);
576 printf("Menu: %s\n", get_nameid_str(dlgex->menu));
577 printf("Class: %s\n", get_nameid_str(dlgex->dlgclass));
578 printf("Title: "); print_string(dlgex->title); printf("\n");
584 printf("%d, ", dlgex->font->size);
585 print_string(dlgex->font->name);
586 printf(", %d, %d\n", dlgex->font->weight, dlgex->font->italic);
596 *****************************************************************************
597 * Function : dump_menu_item
598 * Syntax : void dump_menu_item(menu_item_t *item)
603 *****************************************************************************
605 void dump_menu_item(menu_item_t *item)
612 print_string(item->name);
614 dump_menu_item(item->popup);
621 print_string(item->name);
622 printf(", %d, %08lx", item->id, item->state);
633 *****************************************************************************
634 * Function : dump_menu
635 * Syntax : void dump_menu(menu_t *men)
637 * men - Menu resource descriptor
641 *****************************************************************************
643 void dump_menu(menu_t *men)
645 dump_memopt(men->memopt);
646 dump_lvc(&(men->lvc));
647 dump_menu_item(men->items);
651 *****************************************************************************
652 * Function : dump_menuex_item
653 * Syntax : void dump_menuex_item(menuex_item_t *item)
658 *****************************************************************************
660 void dump_menuex_item(menuex_item_t *item)
667 print_string(item->name);
669 printf(", Id=%d", item->id);
671 printf(", Type=%ld", item->type);
673 printf(", State=%08lx", item->state);
675 printf(", HelpId=%d", item->helpid);
677 dump_menuex_item(item->popup);
684 print_string(item->name);
686 printf(", Id=%d", item->id);
688 printf(", Type=%ld", item->type);
690 printf(", State=%08lx", item->state);
692 printf(", HelpId=%d", item->helpid);
703 *****************************************************************************
704 * Function : dump_menuex
705 * Syntax : void dump_menuex(dialogex_t *menex)
707 * menex - MenuEx resource descriptor
711 *****************************************************************************
713 void dump_menuex(menuex_t *menex)
715 dump_memopt(menex->memopt);
716 dump_lvc(&(menex->lvc));
717 dump_menuex_item(menex->items);
721 *****************************************************************************
722 * Function : dump_ver_value
723 * Syntax : void dump_ver_value(ver_value_t *val)
728 *****************************************************************************
730 void dump_ver_value(ver_value_t *val)
732 extern void dump_ver_block(ver_block_t *);
733 if(val->type == val_str)
736 print_string(val->key);
738 print_string(val->value.str);
741 else if(val->type == val_words)
745 print_string(val->key);
746 for(i = 0; i < val->value.words->nwords; i++)
747 printf(" %04x", val->value.words->words[i]);
750 else if(val->type == val_block)
752 dump_ver_block(val->value.block);
757 *****************************************************************************
758 * Function : dump_ver_block
759 * Syntax : void dump_ver_block(ver_block_t *blk)
764 *****************************************************************************
766 void dump_ver_block(ver_block_t *blk)
768 ver_value_t *val = blk->values;
770 print_string(blk->name);
781 *****************************************************************************
782 * Function : dump_versioninfo
783 * Syntax : void dump_versioninfo(versioninfo_t *ver)
785 * ver - Versioninfo resource descriptor
789 *****************************************************************************
791 void dump_versioninfo(versioninfo_t *ver)
793 ver_block_t *blk = ver->blocks;
796 printf("FILEVERSION %04x, %04x, %04x, %04x\n",
802 printf("PRODUCTVERSION %04x, %04x, %04x, %04x\n",
808 printf("FILEOS %08x\n", ver->fileos);
810 printf("FILEFLAGS %08x\n", ver->fileflags);
812 printf("FILEFLAGSMASK %08x\n", ver->fileflagsmask);
814 printf("FILETYPE %08x\n", ver->filetype);
816 printf("FILESUBTYPE %08x\n", ver->filesubtype);
825 *****************************************************************************
826 * Function : dump_toolbar_item
827 * Syntax : void dump_toolbar_item(toolbar_item_t *item)
832 *****************************************************************************
834 void dump_toolbar_items(toolbar_item_t *items)
839 printf(" BUTTON %d", items->id );
841 printf(" SEPARATOR");
850 *****************************************************************************
851 * Function : dump_toolbar
852 * Syntax : void dump_toolbar(dialogex_t *toolbar)
854 * toolbar - Toolbar resource descriptor
858 *****************************************************************************
860 void dump_toolbar(toolbar_t *toolbar)
862 dump_memopt(toolbar->memopt);
863 dump_lvc(&(toolbar->lvc));
864 dump_toolbar_items(toolbar->items);
868 *****************************************************************************
875 *****************************************************************************
878 *****************************************************************************
879 * Function : dump_resources
880 * Syntax : void dump_resources(resource_t *top)
882 * top - Top of the resource tree
885 * Description : Dump the parsed resource-tree to stdout
887 *****************************************************************************
889 void dump_resources(resource_t *top)
891 printf("Internal resource-tree dump:\n");
894 printf("Resource: %s\nId: %s\n",
896 get_nameid_str(top->name));
900 dump_accelerator(top->res.acc);
903 dump_bitmap(top->res.bmp);
906 dump_cursor(top->res.cur);
909 dump_cursor_group(top->res.curg);
912 dump_dialog(top->res.dlg);
915 dump_dialogex(top->res.dlgex);
918 dump_font(top->res.fnt);
921 dump_icon_group(top->res.icog);
924 dump_icon(top->res.ico);
927 dump_menu(top->res.men);
930 dump_menuex(top->res.menex);
933 dump_rcdata(top->res.rdt);
936 dump_stringtable(top->res.stt);
939 dump_user(top->res.usr);
942 dump_messagetable(top->res.msg);
945 dump_versioninfo(top->res.ver);
948 dump_toolbar(top->res.tbt);
951 printf("Report this: Unknown resource type parsed %08x\n", top->type);