windowscodecs: Silence fixme for IID_CMetaBitmapRenderTarget.
[wine.git] / tools / winedump / tlb.c
blobe2ad4eb51f0b54b629bc3cb53220cd2da647c850
1 /*
2 * Dump a typelib (tlb) file
4 * Copyright 2006 Jacek Caban
5 * Copyright 2015 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <assert.h>
28 #include "winedump.h"
30 #define MSFT_MAGIC 0x5446534d
31 #define SLTG_MAGIC 0x47544c53
32 #define HELPDLLFLAG 0x0100
34 enum TYPEKIND {
35 TKIND_ENUM = 0,
36 TKIND_RECORD,
37 TKIND_MODULE,
38 TKIND_INTERFACE,
39 TKIND_DISPATCH,
40 TKIND_COCLASS,
41 TKIND_ALIAS,
42 TKIND_UNION,
43 TKIND_MAX
46 enum VARENUM {
47 VT_EMPTY = 0,
48 VT_NULL = 1,
49 VT_I2 = 2,
50 VT_I4 = 3,
51 VT_R4 = 4,
52 VT_R8 = 5,
53 VT_CY = 6,
54 VT_DATE = 7,
55 VT_BSTR = 8,
56 VT_DISPATCH = 9,
57 VT_ERROR = 10,
58 VT_BOOL = 11,
59 VT_VARIANT = 12,
60 VT_UNKNOWN = 13,
61 VT_DECIMAL = 14,
62 VT_I1 = 16,
63 VT_UI1 = 17,
64 VT_UI2 = 18,
65 VT_UI4 = 19,
66 VT_I8 = 20,
67 VT_UI8 = 21,
68 VT_INT = 22,
69 VT_UINT = 23,
70 VT_VOID = 24,
71 VT_HRESULT = 25,
72 VT_PTR = 26,
73 VT_SAFEARRAY = 27,
74 VT_CARRAY = 28,
75 VT_USERDEFINED = 29,
76 VT_LPSTR = 30,
77 VT_LPWSTR = 31,
78 VT_RECORD = 36,
79 VT_INT_PTR = 37,
80 VT_UINT_PTR = 38,
81 VT_FILETIME = 64,
82 VT_BLOB = 65,
83 VT_STREAM = 66,
84 VT_STORAGE = 67,
85 VT_STREAMED_OBJECT = 68,
86 VT_STORED_OBJECT = 69,
87 VT_BLOB_OBJECT = 70,
88 VT_CF = 71,
89 VT_CLSID = 72,
90 VT_VERSIONED_STREAM = 73,
91 VT_BSTR_BLOB = 0xfff,
92 VT_VECTOR = 0x1000,
93 VT_ARRAY = 0x2000,
94 VT_BYREF = 0x4000,
95 VT_RESERVED = 0x8000,
96 VT_ILLEGAL = 0xffff,
97 VT_ILLEGALMASKED = 0xfff,
98 VT_TYPEMASK = 0xfff
101 struct seg_t;
103 typedef BOOL (*dump_seg_t)(struct seg_t*);
105 typedef struct seg_t {
106 const char *name;
107 dump_seg_t func;
108 int offset;
109 int length;
110 } seg_t;
111 static seg_t segdir[15];
113 enum SEGDIRTYPE {
114 SEGDIR_TYPEINFO,
115 SEGDIR_IMPINFO,
116 SEGDIR_IMPFILES,
117 SEGDIR_REF,
118 SEGDIR_GUIDHASH,
119 SEGDIR_GUID,
120 SEGDIR_NAMEHASH,
121 SEGDIR_NAME,
122 SEGDIR_STRING,
123 SEGDIR_TYPEDESC,
124 SEGDIR_ARRAYDESC,
125 SEGDIR_CUSTDATA,
126 SEGDIR_CDGUID,
127 SEGDIR_res0e,
128 SEGDIR_res0f
131 static int offset=0;
132 static int indent;
133 static int typeinfo_cnt;
134 static int header_flags = 0;
135 static BOOL msft_eof = FALSE;
137 static int msft_typeinfo_offs[1000];
138 static int msft_typeinfo_kind[1000];
139 static int msft_typeinfo_impltypes[1000];
140 static int msft_typeinfo_elemcnt[1000];
141 static int msft_typeinfo_cnt = 0;
143 static const char * const tkind[TKIND_MAX] = {
144 "TKIND_ENUM", "TKIND_RECORD", "TKIND_MODULE",
145 "TKIND_INTERFACE", "TKIND_DISPATCH", "TKIND_COCLASS",
146 "TKIND_ALIAS", "TKIND_UNION"
149 static const void *tlb_read(int size) {
150 const void *ret = PRD(offset, size);
152 if(ret)
153 offset += size;
154 else
155 msft_eof = TRUE;
157 return ret;
160 static int tlb_read_int(void)
162 const int *ret = tlb_read(sizeof(int));
163 return ret ? *ret : -1;
166 static int tlb_read_short(void)
168 const unsigned short *ret = tlb_read(sizeof(short));
169 return ret ? *ret : -1;
172 static int tlb_read_byte(void)
174 const unsigned char *ret = tlb_read(sizeof(char));
175 return ret ? *ret : -1;
178 static void print_offset(void)
180 int i;
181 for(i=0; i<indent; i++)
182 printf(" ");
185 static void print_begin_block(const char *name)
187 print_offset();
188 printf("%s {\n", name);
189 indent++;
192 static void print_begin_block_id(const char *name, int id)
194 char buf[64];
195 sprintf(buf, "%s %d", name, id);
196 print_begin_block(buf);
199 static void print_end_block(void)
201 indent--;
202 print_offset();
203 printf("}\n");
206 static int print_byte(const char *name)
208 unsigned char ret;
209 print_offset();
210 printf("%s = %02xh\n", name, ret=tlb_read_byte());
211 return ret;
214 static int print_hex(const char *name)
216 int ret;
217 print_offset();
218 printf("%s = %08xh\n", name, ret=tlb_read_int());
219 return ret;
222 static int print_hex_id(const char *name, int id)
224 char buf[64];
225 sprintf(buf, name, id);
226 return print_hex(buf);
229 static int print_short_hex(const char *name)
231 int ret;
232 print_offset();
233 printf("%s = %04xh\n", name, ret=tlb_read_short());
234 return ret;
237 static int print_short_dec(const char *name)
239 int ret;
240 print_offset();
241 printf("%s = %d\n", name, ret=tlb_read_short());
242 return ret;
245 static int print_dec(const char *name)
247 int ret;
248 print_offset();
249 printf("%s = %d\n", name, ret=tlb_read_int());
250 return ret;
253 static void print_guid(const char *name)
255 GUID guid = *(const GUID*)tlb_read(sizeof(guid));
257 print_offset();
259 printf("%s = {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", name,
260 (unsigned int)guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
261 guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4],
262 guid.Data4[5], guid.Data4[6], guid.Data4[7]);
265 static void print_vartype(int vartype)
267 static const char *vartypes[VT_LPWSTR+1] = {
268 "VT_EMPTY", "VT_NULL", "VT_I2", "VT_I4", "VT_R4",
269 "VT_R8", "VT_CY", "VT_DATE", "VT_BSTR", "VT_DISPATCH",
270 "VT_ERROR", "VT_BOOL", "VT_VARIANT", "VT_UNKNOWN","VT_DECIMAL",
271 "unk 15", "VT_I1", "VT_UI1", "VT_UI2", "VT_UI4",
272 "VT_I8", "VT_UI8", "VT_INT", "VT_UINT", "VT_VOID",
273 "VT_HRESULT", "VT_PTR", "VT_SAFEARRAY","VT_CARRAY", "VT_USERDEFINED",
274 "VT_LPSTR", "VT_LPWSTR"
277 vartype &= VT_TYPEMASK;
278 if (vartype >= VT_EMPTY && vartype <= VT_LPWSTR)
279 printf("%s\n", vartypes[vartype]);
280 else
281 printf("unk %d\n", vartype);
284 static void print_ctl2(const char *name)
286 int len;
287 const char *buf;
289 print_offset();
291 len = tlb_read_short();
293 printf("%s = %d \"", name, len);
294 len >>= 2;
295 buf = tlb_read(len);
296 fwrite(buf, len, 1, stdout);
297 printf("\"");
298 len += 2;
300 while(len++ & 3)
301 printf("\\%02x", tlb_read_byte());
302 printf("\n");
305 static int tlb_isprint(unsigned char c)
307 return c >= 32;
310 static void dump_binary(int size)
312 const unsigned char *ptr;
313 int i, j;
315 if (!size) return;
317 ptr = tlb_read(size);
318 if (!ptr) return;
320 print_offset();
321 printf("%08x: ", offset - size);
323 for (i = 0; i < size; i++)
325 printf("%02x%c", ptr[i], (i % 16 == 7) ? '-' : ' ');
326 if ((i % 16) == 15)
328 printf( " " );
329 for (j = 0; j < 16; j++)
330 printf("%c", tlb_isprint(ptr[i-15+j]) ? ptr[i-15+j] : '.');
331 if (i < size-1)
333 printf("\n");
334 print_offset();
335 printf("%08x: ", offset - size + i + 1);
339 if (i % 16)
341 printf("%*s ", 3 * (16-(i%16)), "");
342 for (j = 0; j < i % 16; j++)
343 printf("%c", tlb_isprint(ptr[i-(i%16)+j]) ? ptr[i-(i%16)+j] : '.');
345 printf("\n");
348 static int dump_msft_varflags(void)
350 static const char *syskind[] = {
351 "SYS_WIN16", "SYS_WIN32", "SYS_MAC", "SYS_WIN64", "unknown"
353 int kind, flags;
355 print_offset();
356 flags = tlb_read_int();
357 kind = flags & 0xf;
358 if (kind > 3) kind = 4;
359 printf("varflags = %08x, syskind = %s\n", flags, syskind[kind]);
360 return flags;
363 static void dump_msft_version(void)
365 unsigned version;
366 print_offset();
367 version = tlb_read_int();
368 printf("version = %u.%u\n", version & 0xffff, version >> 16);
371 static void dump_msft_header(void)
373 print_begin_block("Header");
375 print_hex("magic1");
376 print_hex("magic2");
377 print_hex("posguid");
378 print_hex("lcid");
379 print_hex("lcid2");
380 header_flags = dump_msft_varflags();
381 dump_msft_version();
382 print_hex("flags");
383 typeinfo_cnt = print_dec("ntypeinfos");
384 print_dec("helpstring");
385 print_dec("helpstringcontext");
386 print_dec("helpcontext");
387 print_dec("nametablecount");
388 print_dec("nametablechars");
389 print_hex("NameOffset");
390 print_hex("helpfile");
391 print_hex("CustomDataOffset");
392 print_hex("res44");
393 print_hex("res48");
394 print_hex("dispatchpos");
395 print_hex("res50");
397 print_end_block();
400 static int dump_msft_typekind(void)
402 int ret, typekind;
404 print_offset();
405 ret = tlb_read_int();
406 typekind = ret & 0xf;
407 printf("typekind = %s, align = %d\n", typekind < TKIND_MAX ? tkind[typekind] : "unknown", (ret >> 11) & 0x1f);
408 return ret;
411 static void dump_msft_typeinfobase(void)
413 print_begin_block_id("TypeInfoBase", msft_typeinfo_cnt);
415 msft_typeinfo_kind[msft_typeinfo_cnt] = dump_msft_typekind();
416 msft_typeinfo_offs[msft_typeinfo_cnt] = print_hex("memoffset");
417 print_hex("res2");
418 print_hex("res3");
419 print_hex("res4");
420 print_hex("res5");
421 msft_typeinfo_elemcnt[msft_typeinfo_cnt] = print_hex("cElement");
422 print_hex("res7");
423 print_hex("res8");
424 print_hex("res9");
425 print_hex("resA");
426 print_hex("posguid");
427 print_hex("flags");
428 print_hex("NameOffset");
429 print_hex("version");
430 print_hex("docstringoffs");
431 print_hex("docstringcontext");
432 print_hex("helpcontext");
433 print_hex("oCustData");
434 msft_typeinfo_impltypes[msft_typeinfo_cnt++] = print_short_hex("cImplTypes");
435 print_short_hex("bSizeVftt");
436 print_dec("size");
437 print_hex("datatype1");
438 print_hex("datatype2");
439 print_hex("res18");
440 print_hex("res19");
442 print_end_block();
445 static BOOL dump_msft_typeinfobases(seg_t *seg)
447 int i;
449 for(i = 0; offset < seg->offset+seg->length; i++)
450 dump_msft_typeinfobase();
452 assert(offset == seg->offset+seg->length);
453 return TRUE;
456 static void dump_msft_impinfo(int n)
458 print_begin_block_id("ImpInfo", n);
460 print_hex("flags");
461 print_hex("oImpInfo");
462 print_hex("oGuid");
464 print_end_block();
467 static BOOL dump_msft_impinfos(seg_t *seg)
469 int i;
471 for(i = 0; offset < seg->offset+seg->length; i++)
472 dump_msft_impinfo(i);
474 assert(offset == seg->offset+seg->length);
475 return TRUE;
478 static void dump_msft_impfile(int n)
480 print_begin_block_id("ImpFile", n);
482 print_hex("guid");
483 print_hex("lcid");
484 print_hex("version");
485 print_ctl2("impfile");
487 print_end_block();
490 static BOOL dump_msft_impfiles(seg_t *seg)
492 int i;
494 for(i = 0; offset < seg->offset+seg->length; i++)
495 dump_msft_impfile(i);
497 assert(offset == seg->offset+seg->length);
498 return TRUE;
501 static BOOL dump_msft_reftabs(seg_t *seg)
503 print_begin_block("RefTab");
505 dump_binary(seg->length); /* FIXME */
507 print_end_block();
509 return TRUE;
512 static BOOL dump_msft_guidhashtab(seg_t *seg)
514 print_begin_block("GuidHashTab");
516 dump_binary(seg->length); /* FIXME */
518 print_end_block();
520 assert(offset == seg->offset+seg->length);
521 return TRUE;
524 static void dump_msft_guidentry(int n)
526 print_begin_block_id("GuidEntry", n);
528 print_guid("guid");
529 print_hex("hreftype");
530 print_hex("next_hash");
532 print_end_block();
535 static BOOL dump_msft_guidtab(seg_t *seg)
537 int i;
539 for(i = 0; offset < seg->offset+seg->length; i++)
540 dump_msft_guidentry(i);
542 assert(offset == seg->offset+seg->length);
543 return TRUE;
546 static BOOL dump_msft_namehashtab(seg_t *seg)
548 print_begin_block("NameHashTab");
550 dump_binary(seg->length); /* FIXME */
552 print_end_block();
553 return TRUE;
556 static void print_string0(void)
558 unsigned char c;
560 printf("\"");
561 while ((c = tlb_read_byte()) != 0)
563 if (isprint(c))
564 fwrite(&c, 1, 1, stdout);
565 else
567 char buf[16];
568 sprintf(buf, "\\%u", c);
569 fwrite(buf, 1, strlen(buf), stdout);
572 printf("\"");
575 static void print_string(int len)
577 printf("\"");
578 fwrite(tlb_read(len), len, 1, stdout);
579 printf("\"");
582 static void dump_string(int len, int align_off)
584 print_string(len);
585 printf(" ");
586 while((len++ + align_off) & 3)
587 printf("\\%2.2x", tlb_read_byte());
590 static void dump_msft_name(int base, int n)
592 int len;
594 print_begin_block_id("Name", n);
596 print_hex("hreftype");
597 print_hex("next_hash");
598 len = print_hex("namelen")&0xff;
600 print_offset();
601 printf("name = ");
602 dump_string(len, 0);
603 printf("\n");
605 print_end_block();
608 static BOOL dump_msft_nametab(seg_t *seg)
610 int i, base = offset;
612 for(i = 0; offset < seg->offset+seg->length; i++)
613 dump_msft_name(base, i);
615 assert(offset == seg->offset+seg->length);
616 return TRUE;
619 static void dump_msft_string(int n)
621 int len;
623 print_begin_block_id("String", n);
625 len = print_short_hex("stringlen");
627 print_offset();
628 printf("string = ");
629 dump_string(len, 2);
631 if(len < 3) {
632 for(len = 0; len < 4; len++)
633 printf("\\%2.2x", tlb_read_byte());
635 printf("\n");
637 print_end_block();
640 static BOOL dump_msft_stringtab(seg_t *seg)
642 int i;
644 for(i = 0; offset < seg->offset+seg->length; i++)
645 dump_msft_string(i);
647 assert(offset == seg->offset+seg->length);
648 return TRUE;
651 static void dump_msft_typedesc(int n)
653 print_begin_block_id("TYPEDESC", n);
655 print_hex("hreftype");
656 print_hex("vt");
658 print_end_block();
661 static BOOL dump_msft_typedesctab(seg_t *seg)
663 int i;
665 print_begin_block("TypedescTab");
667 for(i = 0; offset < seg->offset+seg->length; i++)
668 dump_msft_typedesc(i);
670 print_end_block();
672 assert(offset == seg->offset+seg->length);
673 return TRUE;
676 static BOOL dump_msft_arraydescs(seg_t *seg)
678 print_begin_block("ArrayDescriptions");
680 dump_binary(seg->length); /* FIXME */
682 print_end_block();
683 return TRUE;
686 static BOOL dump_msft_custdata(seg_t *seg)
688 unsigned short vt;
689 unsigned i, n;
691 print_begin_block("CustData");
693 for(i=0; offset < seg->offset+seg->length; i++) {
694 print_offset();
696 vt = tlb_read_short();
697 printf("vt %d", vt);
698 n = tlb_read_int();
700 switch(vt) {
701 case VT_BSTR:
702 printf(" len %d: ", n);
703 dump_string(n, 2);
704 printf("\n");
705 break;
706 default:
707 printf(": %x ", n);
708 printf("\\%2.2x ", tlb_read_byte());
709 printf("\\%2.2x\n", tlb_read_byte());
713 print_end_block();
714 return TRUE;
717 static void dump_msft_cdguid(int n)
719 print_begin_block_id("CGUid", n);
721 print_hex("GuidOffset");
722 print_hex("DataOffset");
723 print_hex("next");
725 print_end_block();
728 static BOOL dump_msft_cdguids(seg_t *seg)
730 int i;
732 for(i = 0; offset < seg->offset+seg->length; i++)
733 dump_msft_cdguid(i);
735 assert(offset == seg->offset+seg->length);
736 return TRUE;
739 static BOOL dump_msft_res0e(seg_t *seg)
741 print_begin_block("res0e");
742 dump_binary(seg->length);
743 print_end_block();
745 return TRUE;
748 static BOOL dump_msft_res0f(seg_t *seg)
750 print_begin_block("res0f");
751 dump_binary(seg->length);
752 print_end_block();
754 return TRUE;
757 /* Used for function return value and arguments type */
758 static void dump_msft_datatype(const char *name)
760 int datatype;
762 print_offset();
763 datatype = tlb_read_int();
764 printf("%s = %08x", name, datatype);
765 if (datatype < 0) {
766 printf(", ");
767 print_vartype(datatype);
769 else {
770 const short *vt;
772 if (datatype > segdir[SEGDIR_TYPEDESC].length) {
773 printf(", invalid offset\n");
774 return;
777 /* FIXME: in case of VT_USERDEFINED use hreftype */
778 vt = PRD(segdir[SEGDIR_TYPEDESC].offset + datatype, 4*sizeof(short));
779 datatype = vt[0] & VT_TYPEMASK;
780 if (datatype == VT_PTR) {
781 printf(", VT_PTR -> ");
782 if (vt[3] < 0)
783 datatype = vt[2];
784 else {
785 vt = PRD(segdir[SEGDIR_TYPEDESC].offset + vt[2], 4*sizeof(short));
786 datatype = *vt;
789 else {
790 printf(", ");
791 datatype = *vt;
794 print_vartype(datatype);
798 static void dump_defaultvalue(int id)
800 int offset;
802 print_offset();
803 offset = tlb_read_int();
805 printf("default value[%d] = %08x", id, offset);
806 if (offset == -1)
807 printf("\n");
808 else if (offset < 0) {
809 printf(", ");
810 print_vartype((offset & 0x7c000000) >> 26);
812 else {
813 const unsigned short *vt;
815 if (offset > segdir[SEGDIR_CUSTDATA].length) {
816 printf(", invalid offset\n");
817 return;
820 vt = PRD(segdir[SEGDIR_CUSTDATA].offset + offset, sizeof(*vt));
821 printf(", ");
822 print_vartype(*vt);
826 static void dump_msft_func(int n)
828 int size, args_cnt, i, extra_attr, fkccic;
830 print_begin_block_id("FuncRecord", n);
832 size = print_short_hex("size");
833 print_short_hex("index");
834 dump_msft_datatype("retval type");
835 print_hex("flags");
836 print_short_hex("VtableOffset");
837 print_short_hex("funcdescsize");
838 fkccic = print_hex("FKCCIC");
839 args_cnt = print_short_hex("nrargs");
840 print_short_hex("noptargs");
842 extra_attr = size/sizeof(INT) - 6 - args_cnt*(fkccic&0x1000 ? 4 : 3);
844 if(extra_attr)
845 print_hex("helpcontext");
846 if(extra_attr >= 2)
847 print_hex("oHelpString");
848 if(extra_attr >= 3)
849 print_hex("toEntry");
850 if(extra_attr >= 4)
851 print_hex("res9");
852 if(extra_attr >= 5)
853 print_hex("resA");
854 if(extra_attr >= 6)
855 print_hex("HelpStringContext");
856 if(extra_attr >= 7)
857 print_hex("oCustData");
858 for(i = 0; i < extra_attr-7; i++)
859 print_hex_id("oArgCustData", i);
861 if(fkccic & 0x1000) {
862 for(i=0; i < args_cnt; i++)
863 dump_defaultvalue(i);
866 for(i=0; i < args_cnt; i++) {
867 print_begin_block_id("param", i);
869 /* FIXME: Handle default values */
870 dump_msft_datatype("datatype");
871 print_hex("name");
872 print_hex("paramflags");
874 print_end_block();
877 print_end_block();
880 static void dump_msft_var(int n)
882 INT size;
884 print_begin_block_id("VarRecord", n);
886 size = print_hex("recsize")&0x1ff;
887 print_hex("DataType");
888 print_hex("flags");
889 print_short_hex("VarKind");
890 print_short_hex("vardescsize");
891 print_hex("OffsValue");
893 if(size > 5*sizeof(INT))
894 dump_binary(size - 5*sizeof(INT));
896 print_end_block();
899 static void dump_msft_ref(int n)
901 print_begin_block_id("RefRecord", n);
903 print_hex("reftype");
904 print_hex("flags");
905 print_hex("oCustData");
906 print_hex("onext");
908 print_end_block();
911 static void dump_msft_coclass(int n)
913 int i;
915 print_dec("size");
917 for(i=0; i < msft_typeinfo_impltypes[n]; i++)
918 dump_msft_ref(i);
921 static BOOL dump_msft_typeinfo(int n)
923 int i;
925 print_begin_block_id("TypeInfo", n);
927 if((msft_typeinfo_kind[n] & 0xf) == TKIND_COCLASS) {
928 dump_msft_coclass(n);
929 print_end_block();
930 return TRUE;
933 print_dec("size");
935 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
936 dump_msft_func(i);
938 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
939 dump_msft_var(i);
941 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
942 print_hex_id("func %d id", i);
944 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
945 print_hex_id("var %d id", i);
947 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
948 print_hex_id("func %d name", i);
950 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
951 print_hex_id("var %d name", i);
953 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
954 print_hex_id("func %d offset", i);
956 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
957 print_hex_id("var %d offset", i);
959 print_end_block();
961 return TRUE;
964 static seg_t segdir[] = {
965 {"TypeInfoTab", dump_msft_typeinfobases, -1, -1},
966 {"ImpInfo", dump_msft_impinfos, -1, -1},
967 {"ImpFiles", dump_msft_impfiles, -1, -1},
968 {"RefTab", dump_msft_reftabs, -1, -1},
969 {"GuidHashTab", dump_msft_guidhashtab, -1, -1},
970 {"GuidTab", dump_msft_guidtab, -1, -1},
971 {"NameHashTab", dump_msft_namehashtab, -1, -1},
972 {"pNameTab", dump_msft_nametab, -1, -1},
973 {"pStringTab", dump_msft_stringtab, -1, -1},
974 {"TypedescTab", dump_msft_typedesctab, -1, -1},
975 {"ArrayDescriptions", dump_msft_arraydescs, -1, -1},
976 {"CustData", dump_msft_custdata, -1, -1},
977 {"CDGuid", dump_msft_cdguids, -1, -1},
978 {"res0e", dump_msft_res0e, -1, -1},
979 {"res0f", dump_msft_res0f, -1, -1}
982 static void dump_msft_seg(seg_t *seg)
984 print_begin_block(seg->name);
986 seg->offset = print_hex("offset");
987 seg->length = print_dec("length");
988 print_hex("res08");
989 print_hex("res0c");
991 print_end_block();
994 static void dump_msft_segdir(void)
996 int i;
998 print_begin_block("SegDir");
1000 for(i=0; i < ARRAY_SIZE(segdir); i++)
1001 dump_msft_seg(segdir+i);
1003 print_end_block();
1006 static BOOL dump_offset(void)
1008 int i;
1010 for(i=0; i < ARRAY_SIZE(segdir); i++)
1011 if(segdir[i].offset == offset)
1012 return segdir[i].func(segdir+i);
1014 for(i=0; i < msft_typeinfo_cnt; i++)
1015 if(msft_typeinfo_offs[i] == offset)
1016 return dump_msft_typeinfo(i);
1018 return FALSE;
1021 static void msft_dump(void)
1023 int i;
1025 dump_msft_header();
1027 for(i=0; i < typeinfo_cnt; i++)
1028 print_hex_id("typeinfo %d offset", i);
1030 if(header_flags & HELPDLLFLAG)
1031 print_hex("help dll offset");
1032 print_offset();
1033 printf("\n");
1035 dump_msft_segdir();
1037 while(!msft_eof) {
1038 if(!dump_offset())
1039 print_hex("unknown");
1043 /****************************** SLTG Typelibs ******************************/
1045 struct block_entry
1047 DWORD len;
1048 WORD index_string;
1049 WORD next;
1052 struct bitstream
1054 const BYTE *buffer;
1055 DWORD length;
1056 WORD current;
1059 #include "pshpack1.h"
1060 struct sltg_typeinfo_header
1062 short magic;
1063 int href_table;
1064 int res06;
1065 int elem_table;
1066 int res0e;
1067 int version;
1068 int res16;
1069 struct
1071 unsigned unknown1 : 3;
1072 unsigned flags : 16;
1073 unsigned unknown2 : 5;
1074 unsigned typekind : 8;
1075 } misc;
1076 int res1e;
1079 struct sltg_member_header
1081 short res00;
1082 short res02;
1083 char res04;
1084 int extra;
1087 struct sltg_tail
1089 unsigned short cFuncs;
1090 unsigned short cVars;
1091 unsigned short cImplTypes;
1092 unsigned short res06; /* always 0000 */
1093 unsigned short funcs_off; /* offset to functions (starting from the member header) */
1094 unsigned short vars_off; /* offset to vars (starting from the member header) */
1095 unsigned short impls_off; /* offset to implemented types (starting from the member header) */
1096 unsigned short funcs_bytes; /* bytes used by function data */
1097 unsigned short vars_bytes; /* bytes used by var data */
1098 unsigned short impls_bytes; /* bytes used by implemented type data */
1099 unsigned short tdescalias_vt; /* for TKIND_ALIAS */
1100 unsigned short res16; /* always ffff */
1101 unsigned short res18; /* always 0000 */
1102 unsigned short res1a; /* always 0000 */
1103 unsigned short simple_alias; /* tdescalias_vt is a vt rather than an offset? */
1104 unsigned short res1e; /* always 0000 */
1105 unsigned short cbSizeInstance;
1106 unsigned short cbAlignment;
1107 unsigned short res24;
1108 unsigned short res26;
1109 unsigned short cbSizeVft;
1110 unsigned short res2a; /* always ffff */
1111 unsigned short res2c; /* always ffff */
1112 unsigned short res2e; /* always ffff */
1113 unsigned short res30; /* always ffff */
1114 unsigned short res32;
1115 unsigned short res34;
1118 struct sltg_variable
1120 char magic; /* 0x0a */
1121 char flags;
1122 short next;
1123 short name;
1124 short byte_offs; /* pos in struct, or offset to const type or const data (if flags & 0x08) */
1125 short type; /* if flags & 0x02 this is the type, else offset to type */
1126 int memid;
1127 short helpcontext; /* ?? */
1128 short helpstring; /* ?? */
1129 #if 0
1130 short varflags; /* only present if magic & 0x20 */
1131 #endif
1133 #include "poppack.h"
1135 static const char *lookup_code(const BYTE *table, DWORD table_size, struct bitstream *bits)
1137 const BYTE *p = table;
1139 while (p < table + table_size && *p == 0x80)
1141 if (p + 2 >= table + table_size) return NULL;
1143 if (!(bits->current & 0xff))
1145 if (!bits->length) return NULL;
1146 bits->current = (*bits->buffer << 8) | 1;
1147 bits->buffer++;
1148 bits->length--;
1151 if (bits->current & 0x8000)
1153 p += 3;
1155 else
1157 p = table + (*(p + 2) | (*(p + 1) << 8));
1160 bits->current <<= 1;
1163 if (p + 1 < table + table_size && *(p + 1))
1165 /* FIXME: What is the meaning of *p? */
1166 const BYTE *q = p + 1;
1167 while (q < table + table_size && *q) q++;
1168 return (q < table + table_size) ? (const char *)(p + 1) : NULL;
1171 return NULL;
1174 static const char *decode_string(const BYTE *table, const char *stream, UINT stream_length, UINT *read_bytes)
1176 char *buf;
1177 DWORD buf_size, table_size;
1178 const char *p;
1179 struct bitstream bits;
1181 bits.buffer = (const BYTE *)stream;
1182 bits.length = stream_length;
1183 bits.current = 0;
1185 buf_size = *(const WORD *)table;
1186 table += sizeof(WORD);
1187 table_size = *(const DWORD *)table;
1188 table += sizeof(DWORD);
1190 buf = xmalloc(buf_size);
1191 buf[0] = 0;
1193 while ((p = lookup_code(table, table_size, &bits)))
1195 if (buf[0]) strcat(buf, " ");
1196 assert(strlen(buf) + strlen(p) + 1 <= buf_size);
1197 strcat(buf, p);
1200 if (read_bytes) *read_bytes = stream_length - bits.length;
1202 return buf;
1205 static void print_sltg_name(const char *name)
1207 unsigned short len = tlb_read_short();
1208 print_offset();
1209 printf("%s = %#x (", name, len);
1210 if (len != 0xffff) print_string(len);
1211 printf(")\n");
1214 static int dump_sltg_header(int *sltg_first_blk, int *size_of_index, int *size_of_pad)
1216 int n_file_blocks;
1218 print_begin_block("Header");
1220 print_hex("magic");
1221 n_file_blocks = print_short_dec("# file blocks");
1222 *size_of_pad = print_short_hex("pad");
1223 *size_of_index = print_short_hex("size of index");
1224 *sltg_first_blk = print_short_dec("first block");
1225 print_guid("guid");
1226 print_hex("res1c");
1227 print_hex("res20");
1229 print_end_block();
1231 return n_file_blocks;
1234 static void dump_sltg_index(int count)
1236 int i;
1238 printf("index:\n");
1240 print_string0();
1241 printf("\n");
1242 print_string0();
1243 printf("\n");
1245 for (i = 0; i < count - 2; i++)
1247 print_string0();
1248 printf("\n");
1251 printf("\n");
1254 static void dump_sltg_pad(int size_of_pad)
1256 printf("pad:\n");
1257 dump_binary(size_of_pad);
1258 printf("\n");
1261 static void dump_sltg_block_entry(int idx, const char *index)
1263 char name[32];
1264 short index_offset;
1266 sprintf(name, "Block entry %d", idx);
1267 print_begin_block(name);
1269 print_hex("len");
1270 index_offset = tlb_read_short();
1271 print_offset();
1272 printf("index string = %xh \"%s\"\n", index_offset, index + index_offset);
1273 print_short_hex("next");
1275 print_end_block();
1278 static void dump_sltg_library_block(void)
1280 print_begin_block("Library block entry");
1282 print_short_hex("magic");
1283 print_short_hex("res02");
1284 print_sltg_name("name");
1285 print_short_hex("res06");
1286 print_sltg_name("helpstring");
1287 print_sltg_name("helpfile");
1288 print_hex("helpcontext");
1289 print_short_hex("syskind");
1290 print_short_hex("lcid");
1291 print_hex("res12");
1292 print_short_hex("libflags");
1293 dump_msft_version();
1294 print_guid("uuid");
1296 print_end_block();
1299 static void skip_sltg_library_block(void)
1301 unsigned short skip;
1303 tlb_read_short();
1304 tlb_read_short();
1305 skip = tlb_read_short();
1306 if (skip != 0xffff) tlb_read(skip);
1307 tlb_read_short();
1308 skip = tlb_read_short();
1309 if (skip != 0xffff) tlb_read(skip);
1310 skip = tlb_read_short();
1311 if (skip != 0xffff) tlb_read(skip);
1312 tlb_read_int();
1313 tlb_read_short();
1314 tlb_read_short();
1315 tlb_read_int();
1316 tlb_read_short();
1317 tlb_read_int();
1318 tlb_read(sizeof(GUID));
1321 static void dump_sltg_other_typeinfo(int idx, const char *hlp_strings)
1323 int hlpstr_len, saved_offset;
1324 char name[32];
1326 sprintf(name, "Other typeinfo %d", idx);
1327 print_begin_block(name);
1329 print_sltg_name("index name");
1330 print_sltg_name("other name");
1331 print_short_hex("res1a");
1332 print_short_hex("name offset");
1334 print_offset();
1335 hlpstr_len = tlb_read_short();
1336 if (hlpstr_len)
1338 const char *str;
1340 saved_offset = offset;
1341 str = tlb_read(hlpstr_len);
1342 str = decode_string((const BYTE *)hlp_strings, str, hlpstr_len, NULL);
1343 printf("helpstring: \"%s\"\n", str);
1345 offset = saved_offset;
1346 print_offset();
1347 printf("helpstring encoded bits: %d bytes\n", hlpstr_len);
1348 dump_binary(hlpstr_len);
1350 else
1351 printf("helpstring: \"\"\n");
1353 print_short_hex("res20");
1354 print_hex("helpcontext");
1355 print_short_hex("res26");
1356 print_guid("uuid");
1357 print_short_dec("typekind");
1359 print_end_block();
1362 static void skip_sltg_other_typeinfo(void)
1364 unsigned short skip;
1366 skip = tlb_read_short();
1367 if (skip != 0xffff) tlb_read(skip);
1368 skip = tlb_read_short();
1369 if (skip != 0xffff) tlb_read(skip);
1370 tlb_read_short();
1371 tlb_read_short();
1372 skip = tlb_read_short();
1373 if (skip) tlb_read(skip);
1374 tlb_read_short();
1375 tlb_read_int();
1376 tlb_read_short();
1377 tlb_read(sizeof(GUID));
1378 tlb_read_short();
1381 static void sltg_print_simple_type(short type)
1383 print_offset();
1384 if ((type & 0x0f00) == 0x0e00)
1385 printf("*");
1386 printf("%04x | (%d)\n", type & 0xff80, type & 0x7f);
1389 static void dump_safe_array(int array_offset)
1391 int i, cDims, saved_offset = offset;
1393 offset = array_offset;
1395 print_offset();
1396 printf("safe array starts at %#x\n", offset);
1398 cDims = print_short_dec("cDims");
1399 print_short_hex("fFeatures");
1400 print_dec("cbElements");
1401 print_dec("cLocks");
1402 print_hex("pvData");
1404 for (i = 0; i < cDims; i++)
1405 dump_binary(8); /* sizeof(SAFEARRAYBOUND) */
1407 print_offset();
1408 printf("safe array ends at %#x\n", offset);
1409 offset = saved_offset;
1412 static int sltg_print_compound_type(int vars_start_offset, int type_offset)
1414 short type, vt;
1415 int type_bytes, saved_offset = offset;
1417 offset = vars_start_offset + type_offset;
1418 print_offset();
1419 printf("type description starts at %#x\n", offset);
1421 for (;;)
1425 type = tlb_read_short();
1426 vt = type & 0x7f;
1428 if (vt == VT_PTR)
1430 print_offset();
1431 printf("%04x | VT_PTR\n", type & 0xff80);
1433 } while (vt == VT_PTR);
1435 if (vt == VT_USERDEFINED)
1437 short href = tlb_read_short();
1438 print_offset();
1439 if ((type & 0x0f00) == 0x0e00)
1440 printf("*");
1441 printf("%04x | VT_USERDEFINED (href %d)\n", type & 0xff80, href);
1442 break;
1444 else if (vt == VT_CARRAY)
1446 short off;
1448 off = tlb_read_short();
1449 print_offset();
1450 printf("VT_CARRAY: offset %#x (+%#x=%#x)\n",
1451 off, vars_start_offset, off + vars_start_offset);
1452 dump_safe_array(vars_start_offset + off);
1454 /* type description follows */
1455 print_offset();
1456 printf("array element type:\n");
1457 continue;
1459 else if (vt == VT_SAFEARRAY)
1461 short off;
1463 off = tlb_read_short();
1464 print_offset();
1465 printf("VT_SAFEARRAY: offset %#x (+%#x=%#x)\n",
1466 off, vars_start_offset, off + vars_start_offset);
1467 dump_safe_array(vars_start_offset + off);
1468 break;
1470 else
1472 sltg_print_simple_type(type);
1473 break;
1477 print_offset();
1478 printf("type description ends at %#x\n", offset);
1479 type_bytes = offset - saved_offset;
1480 offset = saved_offset;
1482 return type_bytes;
1485 static void dump_type(int len, const char *hlp_strings)
1487 union
1489 struct
1491 unsigned unknown1 : 3;
1492 unsigned flags : 13;
1493 unsigned unknown2 : 8;
1494 unsigned typekind : 8;
1495 } s;
1496 unsigned flags;
1497 } misc;
1498 int typeinfo_start_offset, extra, member_offset, href_offset, i;
1499 int saved_offset;
1500 const void *block;
1501 const struct sltg_typeinfo_header *ti;
1502 const struct sltg_member_header *mem;
1503 const struct sltg_tail *tail;
1505 typeinfo_start_offset = offset;
1506 block = tlb_read(len);
1507 offset = typeinfo_start_offset;
1509 ti = block;
1510 mem = (const struct sltg_member_header *)((char *)block + ti->elem_table);
1511 tail = (const struct sltg_tail *)((char *)(mem + 1) + mem->extra);
1513 typeinfo_start_offset = offset;
1515 print_short_hex("magic");
1516 href_offset = tlb_read_int();
1517 print_offset();
1518 if (href_offset != -1)
1519 printf("href offset = %#x (+%#x=%#x)\n",
1520 href_offset, typeinfo_start_offset, href_offset + typeinfo_start_offset);
1521 else
1522 printf("href offset = ffffffffh\n");
1523 print_hex("res06");
1524 member_offset = tlb_read_int();
1525 print_offset();
1526 printf("member offset = %#x (+%#x=%#x)\n",
1527 member_offset, typeinfo_start_offset, member_offset + typeinfo_start_offset);
1528 print_hex("res0e");
1529 print_hex("version");
1530 print_hex("res16");
1531 misc.flags = print_hex("misc");
1532 print_offset();
1533 printf("misc: unknown1 %02x, flags %04x, unknown2 %02x, typekind %u (%s)\n",
1534 misc.s.unknown1, misc.s.flags, misc.s.unknown2, misc.s.typekind,
1535 misc.s.typekind < TKIND_MAX ? tkind[misc.s.typekind] : "unknown");
1536 print_hex("res1e");
1538 if (href_offset != -1)
1540 int i, number;
1542 print_begin_block("href_table");
1544 print_short_hex("magic");
1545 print_hex("res02");
1546 print_hex("res06");
1547 print_hex("res0a");
1548 print_hex("res0e");
1549 print_hex("res12");
1550 print_hex("res16");
1551 print_hex("res1a");
1552 print_hex("res1e");
1553 print_hex("res22");
1554 print_hex("res26");
1555 print_hex("res2a");
1556 print_hex("res2e");
1557 print_hex("res32");
1558 print_hex("res36");
1559 print_hex("res3a");
1560 print_hex("res3e");
1561 print_short_hex("res42");
1562 number = print_hex("number");
1564 for (i = 0; i < number; i += 8)
1565 dump_binary(8);
1567 print_short_hex("res50");
1568 print_byte("res52");
1569 print_hex("res53");
1571 for (i = 0; i < number/8; i++)
1572 print_sltg_name("name");
1574 print_byte("resxx");
1576 print_end_block();
1579 print_offset();
1580 printf("member_header starts at %#x, current offset = %#x\n", typeinfo_start_offset + member_offset, offset);
1581 member_offset = offset;
1582 print_short_hex("res00");
1583 print_short_hex("res02");
1584 print_byte("res04");
1585 extra = print_hex("extra");
1587 if (misc.s.typekind == TKIND_RECORD || misc.s.typekind == TKIND_ENUM)
1589 int vars_start_offset = offset;
1591 for (i = 0; i < tail->cVars; i++)
1593 char name[32];
1594 int saved_off;
1595 char magic, flags;
1596 short next, value;
1598 sprintf(name, "variable %d", i);
1599 print_begin_block(name);
1601 saved_off = offset;
1602 dump_binary(sizeof(struct sltg_variable));
1603 offset = saved_off;
1605 magic = print_byte("magic");
1606 flags = print_byte("flags");
1607 next = tlb_read_short();
1608 print_offset();
1609 if (next != -1)
1610 printf("next offset = %#x (+%#x=%#x)\n",
1611 next, vars_start_offset, next + vars_start_offset);
1612 else
1613 printf("next offset = ffffh\n");
1614 print_short_hex("name");
1616 if (flags & 0x40)
1617 print_short_hex("dispatch");
1618 else if (flags & 0x10)
1620 if (flags & 0x08)
1621 print_short_hex("const value");
1622 else
1624 value = tlb_read_short();
1625 print_offset();
1626 printf("byte offset = %#x (+%#x=%#x)\n",
1627 value, vars_start_offset, value + vars_start_offset);
1630 else
1631 print_short_hex("oInst");
1633 value = tlb_read_short();
1634 if (!(flags & 0x02))
1636 print_offset();
1637 printf("type offset = %#x (+%#x=%#x)\n",
1638 value, vars_start_offset, value + vars_start_offset);
1639 print_offset();
1640 printf("type:\n");
1641 sltg_print_compound_type(vars_start_offset, value);
1643 else
1645 print_offset();
1646 printf("type:\n");
1647 sltg_print_simple_type(value);
1650 print_hex("memid");
1651 print_short_hex("helpcontext");
1653 value = tlb_read_short();
1654 print_offset();
1655 if (value != -1)
1657 const char *str;
1658 UINT hlpstr_maxlen;
1660 printf("helpstring offset = %#x (+%#x=%#x)\n",
1661 value, vars_start_offset, value + vars_start_offset);
1663 saved_offset = offset;
1665 offset = value + vars_start_offset;
1667 hlpstr_maxlen = member_offset + sizeof(struct sltg_member_header) + mem->extra - offset;
1669 str = tlb_read(hlpstr_maxlen);
1670 str = decode_string((const BYTE *)hlp_strings, str, hlpstr_maxlen, &hlpstr_maxlen);
1671 print_offset();
1672 printf("helpstring: \"%s\"\n", str);
1674 offset = value + vars_start_offset;
1675 print_offset();
1676 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen);
1677 dump_binary(hlpstr_maxlen);
1679 offset = saved_offset;
1681 else
1682 printf("helpstring offset = ffffh\n");
1684 if (magic & 0x20) print_short_hex("varflags");
1686 if (next != -1)
1688 if (offset != vars_start_offset + next)
1689 dump_binary(vars_start_offset + next - offset);
1692 print_end_block();
1695 else if (misc.s.typekind == TKIND_INTERFACE || misc.s.typekind == TKIND_COCLASS)
1697 short next, i;
1698 int funcs_start_offset = offset;
1700 for (i = 0; i < tail->cImplTypes; i++)
1702 char name[64];
1704 sprintf(name, "impl.type %d (current offset %#x)", i, offset);
1705 print_begin_block(name);
1707 print_short_hex("res00");
1708 next = tlb_read_short();
1709 print_offset();
1710 if (next != -1)
1711 printf("next offset = %#x (+%#x=%#x)\n",
1712 next, funcs_start_offset, next + funcs_start_offset);
1713 else
1714 printf("next offset = ffffh\n");
1715 print_short_hex("res04");
1716 print_byte("impltypeflags");
1717 print_byte("res07");
1718 print_short_hex("res08");
1719 print_short_hex("ref");
1720 print_short_hex("res0c");
1721 print_short_hex("res0e");
1722 print_short_hex("res10");
1723 print_short_hex("res12");
1724 print_short_hex("pos in table");
1726 print_end_block();
1729 for (i = 0; i < tail->cFuncs; i++)
1731 char name[64];
1732 BYTE magic, flags;
1733 short args_off, value, n_params, j;
1735 sprintf(name, "function %d (current offset %#x)", i, offset);
1736 print_begin_block(name);
1738 magic = print_byte("magic");
1739 flags = tlb_read_byte();
1740 print_offset();
1741 printf("invoke_kind = %u\n", flags >> 4);
1742 next = tlb_read_short();
1743 print_offset();
1744 if (next != -1)
1745 printf("next offset = %#x (+%#x=%#x)\n",
1746 next, funcs_start_offset, next + funcs_start_offset);
1747 else
1748 printf("next offset = ffffh\n");
1749 print_short_hex("name");
1750 print_hex("dispid");
1751 print_short_hex("helpcontext");
1753 value = tlb_read_short();
1754 print_offset();
1755 if (value != -1)
1757 const char *str;
1758 UINT hlpstr_maxlen;
1760 printf("helpstring offset = %#x (+%#x=%#x)\n",
1761 value, funcs_start_offset, value + funcs_start_offset);
1763 saved_offset = offset;
1765 offset = value + funcs_start_offset;
1767 hlpstr_maxlen = member_offset + sizeof(struct sltg_member_header) + mem->extra - offset;
1769 str = tlb_read(hlpstr_maxlen);
1770 str = decode_string((const BYTE *)hlp_strings, str, hlpstr_maxlen, &hlpstr_maxlen);
1771 print_offset();
1772 printf("helpstring: \"%s\"\n", str);
1774 offset = value + funcs_start_offset;
1775 print_offset();
1776 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen);
1777 dump_binary(hlpstr_maxlen);
1779 offset = saved_offset;
1781 else
1782 printf("helpstring offset = ffffh\n");
1784 args_off = tlb_read_short();
1785 print_offset();
1786 if (args_off != -1)
1787 printf("args off = %#x (+%#x=%#x)\n",
1788 args_off, funcs_start_offset, args_off + funcs_start_offset);
1789 else
1790 printf("args off = ffffh\n");
1791 flags = tlb_read_byte();
1792 n_params = flags >> 3;
1793 print_offset();
1794 printf("callconv %u, cParams %u\n", flags & 0x7, n_params);
1796 flags = tlb_read_byte();
1797 print_offset();
1798 printf("retnextop %02x, cParamsOpt %u\n", flags, (flags & 0x7e) >> 1);
1800 value = print_short_hex("rettype");
1801 if (!(flags & 0x80))
1803 print_offset();
1804 printf("rettype offset = %#x (+%#x=%#x)\n",
1805 value, funcs_start_offset, value + funcs_start_offset);
1806 print_offset();
1807 printf("rettype:\n");
1808 sltg_print_compound_type(funcs_start_offset, value);
1810 else
1812 print_offset();
1813 printf("rettype:\n");
1814 sltg_print_simple_type(value);
1817 print_short_hex("vtblpos");
1818 if (magic & 0x20)
1819 print_short_hex("funcflags");
1821 if (n_params)
1823 offset = args_off + funcs_start_offset;
1824 print_offset();
1825 printf("arguments start at %#x\n", offset);
1828 for (j = 0; j < n_params; j++)
1830 char name[32];
1831 unsigned short name_offset;
1833 sprintf(name, "arg %d", j);
1834 print_begin_block(name);
1836 name_offset = tlb_read_short();
1837 print_offset();
1838 printf("name: %04xh\n", name_offset);
1840 value = tlb_read_short();
1841 print_offset();
1842 printf("type/offset %04xh\n", value);
1843 if (name_offset & 1) /* type follows */
1845 print_offset();
1846 printf("type follows, using current offset for type\n");
1847 offset -= 2;
1848 value = offset - funcs_start_offset;
1851 print_offset();
1852 printf("arg[%d] off = %#x (+%#x=%#x)\n",
1853 j, value, funcs_start_offset, value + funcs_start_offset);
1854 print_offset();
1855 printf("type:\n");
1856 value = sltg_print_compound_type(funcs_start_offset, value);
1857 if (name_offset & 1)
1858 offset += value;
1860 print_end_block();
1863 if (n_params)
1865 print_offset();
1866 printf("arguments end at %#x\n", offset);
1869 if (next != -1)
1871 if (offset != funcs_start_offset + next)
1872 dump_binary(funcs_start_offset + next - offset);
1875 print_end_block();
1878 else
1880 printf("skipping %#x bytes\n", extra);
1881 dump_binary(extra);
1884 if (offset < member_offset + sizeof(struct sltg_member_header) + mem->extra)
1886 print_offset();
1887 printf("skipping %d bytes\n", member_offset + (int)sizeof(struct sltg_member_header) + mem->extra - offset);
1888 dump_binary(member_offset + sizeof(struct sltg_member_header) + mem->extra - offset);
1891 print_offset();
1892 printf("dumped %d (%#x) bytes\n", offset - typeinfo_start_offset, offset - typeinfo_start_offset);
1893 len -= offset - typeinfo_start_offset;
1894 print_offset();
1895 printf("sltg_tail %d (%#x) bytes:\n", len, len);
1896 saved_offset = offset;
1897 dump_binary(len);
1898 offset = saved_offset;
1899 print_short_hex("cFuncs");
1900 print_short_hex("cVars");
1901 print_short_hex("cImplTypes");
1902 print_short_hex("res06");
1903 print_short_hex("funcs_off");
1904 print_short_hex("vars_off");
1905 print_short_hex("impls_off");
1906 print_short_hex("funcs_bytes");
1907 print_short_hex("vars_bytes");
1908 print_short_hex("impls_bytes");
1909 print_short_hex("tdescalias_vt");
1910 print_short_hex("res16");
1911 print_short_hex("res18");
1912 print_short_hex("res1a");
1913 print_short_hex("simple_alias");
1914 print_short_hex("res1e");
1915 print_short_hex("cbSizeInstance");
1916 print_short_hex("cbAlignment");
1917 print_short_hex("res24");
1918 print_short_hex("res26");
1919 print_short_hex("cbSizeVft");
1920 print_short_hex("res2a");
1921 print_short_hex("res2c");
1922 print_short_hex("res2e");
1923 print_short_hex("res30");
1924 print_short_hex("res32");
1925 print_short_hex("res34");
1926 offset = saved_offset + len;
1929 static void sltg_dump(void)
1931 int i, n_file_blocks, n_first_blk, size_of_index, size_of_pad;
1932 int name_table_start, name_table_size, saved_offset;
1933 int libblk_start, libblk_len, hlpstr_len, len;
1934 const char *index, *hlp_strings;
1935 const struct block_entry *entry;
1937 n_file_blocks = dump_sltg_header(&n_first_blk, &size_of_index, &size_of_pad);
1939 saved_offset = offset;
1940 entry = tlb_read((n_file_blocks - 1) * sizeof(*entry));
1941 if (!entry) return;
1942 index = tlb_read(size_of_index);
1943 if (!index) return;
1944 offset = saved_offset;
1946 for (i = 0; i < n_file_blocks - 1; i++)
1947 dump_sltg_block_entry(i, index);
1949 saved_offset = offset;
1950 dump_sltg_index(n_file_blocks);
1951 assert(offset - saved_offset == size_of_index);
1953 dump_sltg_pad(size_of_pad);
1955 /* read the helpstrings for later decoding */
1956 saved_offset = offset;
1958 for (i = n_first_blk - 1; entry[i].next != 0; i = entry[i].next - 1)
1959 tlb_read(entry[i].len);
1961 libblk_start = offset;
1962 skip_sltg_library_block();
1963 tlb_read(0x40);
1964 typeinfo_cnt = tlb_read_short();
1966 for (i = 0; i < typeinfo_cnt; i++)
1967 skip_sltg_other_typeinfo();
1969 len = tlb_read_int();
1970 hlpstr_len = (libblk_start + len) - offset;
1971 hlp_strings = tlb_read(hlpstr_len);
1972 assert(hlp_strings != NULL);
1973 /* check the helpstrings header values */
1974 len = *(int *)(hlp_strings + 2);
1975 assert(hlpstr_len == len + 6);
1977 offset = saved_offset;
1979 for (i = n_first_blk - 1; entry[i].next != 0; i = entry[i].next - 1)
1981 short magic;
1982 char name[32];
1984 saved_offset = offset;
1986 sprintf(name, "Block %d", i);
1987 print_begin_block(name);
1988 magic = tlb_read_short();
1989 assert(magic == 0x0501);
1990 offset -= 2;
1991 dump_binary(entry[i].len);
1992 print_end_block();
1994 offset = saved_offset;
1996 print_begin_block(name);
1997 dump_type(entry[i].len, hlp_strings);
1998 print_end_block();
2000 offset = saved_offset + entry[i].len;
2003 libblk_len = entry[i].len;
2005 libblk_start = offset;
2006 dump_sltg_library_block();
2008 printf("skipping 0x40 bytes\n");
2009 dump_binary(0x40);
2010 printf("\n");
2011 typeinfo_cnt = print_short_dec("typeinfo count");
2012 printf("\n");
2014 for (i = 0; i < typeinfo_cnt; i++)
2015 dump_sltg_other_typeinfo(i, hlp_strings);
2017 len = print_hex("offset from start of library block to name table");
2018 printf("%#x + %#x = %#x\n", libblk_start, len, libblk_start + len);
2019 len = (libblk_start + len) - offset;
2020 printf("skipping %#x bytes (encoded/compressed helpstrings)\n", len);
2021 printf("max string length: %#x, strings length %#x\n", *(short *)hlp_strings, *(int *)(hlp_strings + 2));
2022 dump_binary(len);
2023 printf("\n");
2025 len = print_short_hex("name table jump");
2026 if (len == 0xffff)
2028 printf("skipping 0x000a bytes\n");
2029 dump_binary(0x000a);
2030 printf("\n");
2032 else if (len == 0x0200)
2034 printf("skipping 0x002a bytes\n");
2035 dump_binary(0x002a);
2036 printf("\n");
2038 else
2040 printf("FIXME: please report! (%#x)\n", len);
2041 assert(0);
2044 printf("skipping 0x200 bytes\n");
2045 dump_binary(0x200);
2046 printf("\n");
2048 name_table_size = print_hex("name table size");
2050 name_table_start = offset;
2051 printf("name table offset = %#x\n\n", offset);
2053 while (offset < name_table_start + name_table_size)
2055 int aligned_len;
2057 dump_binary(8);
2058 print_string0();
2059 printf("\n");
2061 len = offset - name_table_start;
2062 aligned_len = (len + 0x1f) & ~0x1f;
2063 if (aligned_len - len < 4)
2064 dump_binary(aligned_len - len);
2065 else
2066 dump_binary(len & 1);
2067 printf("\n");
2070 print_hex("01ffff01");
2071 len = print_hex("length");
2072 printf("skipping %#x bytes\n", len);
2073 dump_binary(len);
2074 printf("\n");
2076 len = (libblk_start + libblk_len) - offset;
2077 printf("skipping libblk remainder %#x bytes\n", len);
2078 dump_binary(len);
2079 printf("\n");
2081 /* FIXME: msodumper/olestream.py parses this block differently
2082 print_short_hex("unknown");
2083 print_short_hex("byte order mark");
2084 i = tlb_read_short();
2085 printf("version = %u.%u\n", i & 0xff, i >> 8);
2086 print_short_hex("system identifier");
2087 print_hex("unknown");
2088 printf("\n");
2090 printf("skipping 12 bytes\n");
2091 dump_binary(12);
2092 printf("\n");
2094 print_guid("uuid");
2095 printf("\n");
2097 /* 0x0008,"TYPELIB",0 */
2098 dump_binary(12);
2099 printf("\n");
2101 printf("skipping 12 bytes\n");
2102 dump_binary(12);
2103 printf("\n");
2105 printf("skipping remainder 0x10 bytes\n");
2106 dump_binary(0x10);
2107 printf("\n");
2110 void tlb_dump(void)
2112 const DWORD *sig = PRD(0, sizeof(DWORD));
2113 if (*sig == MSFT_MAGIC)
2114 msft_dump();
2115 else
2116 sltg_dump();
2119 enum FileSig get_kind_tlb(void)
2121 const DWORD *sig = PRD(0, sizeof(DWORD));
2122 if (sig && (*sig == MSFT_MAGIC || *sig == SLTG_MAGIC)) return SIG_TLB;
2123 return SIG_UNKNOWN;