mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / tools / winedump / tlb.c
blob6a908795728f2c506f1b5396db4fcda243e45f48
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"
23 #include "wine/port.h"
25 #include <stdlib.h>
26 #include <string.h>
27 #include <assert.h>
29 #include "windef.h"
31 #include "winedump.h"
33 #define MSFT_MAGIC 0x5446534d
34 #define SLTG_MAGIC 0x47544c53
35 #define HELPDLLFLAG 0x0100
37 enum TYPEKIND {
38 TKIND_ENUM = 0,
39 TKIND_RECORD,
40 TKIND_MODULE,
41 TKIND_INTERFACE,
42 TKIND_DISPATCH,
43 TKIND_COCLASS,
44 TKIND_ALIAS,
45 TKIND_UNION,
46 TKIND_MAX
49 enum VARENUM {
50 VT_EMPTY = 0,
51 VT_NULL = 1,
52 VT_I2 = 2,
53 VT_I4 = 3,
54 VT_R4 = 4,
55 VT_R8 = 5,
56 VT_CY = 6,
57 VT_DATE = 7,
58 VT_BSTR = 8,
59 VT_DISPATCH = 9,
60 VT_ERROR = 10,
61 VT_BOOL = 11,
62 VT_VARIANT = 12,
63 VT_UNKNOWN = 13,
64 VT_DECIMAL = 14,
65 VT_I1 = 16,
66 VT_UI1 = 17,
67 VT_UI2 = 18,
68 VT_UI4 = 19,
69 VT_I8 = 20,
70 VT_UI8 = 21,
71 VT_INT = 22,
72 VT_UINT = 23,
73 VT_VOID = 24,
74 VT_HRESULT = 25,
75 VT_PTR = 26,
76 VT_SAFEARRAY = 27,
77 VT_CARRAY = 28,
78 VT_USERDEFINED = 29,
79 VT_LPSTR = 30,
80 VT_LPWSTR = 31,
81 VT_RECORD = 36,
82 VT_INT_PTR = 37,
83 VT_UINT_PTR = 38,
84 VT_FILETIME = 64,
85 VT_BLOB = 65,
86 VT_STREAM = 66,
87 VT_STORAGE = 67,
88 VT_STREAMED_OBJECT = 68,
89 VT_STORED_OBJECT = 69,
90 VT_BLOB_OBJECT = 70,
91 VT_CF = 71,
92 VT_CLSID = 72,
93 VT_VERSIONED_STREAM = 73,
94 VT_BSTR_BLOB = 0xfff,
95 VT_VECTOR = 0x1000,
96 VT_ARRAY = 0x2000,
97 VT_BYREF = 0x4000,
98 VT_RESERVED = 0x8000,
99 VT_ILLEGAL = 0xffff,
100 VT_ILLEGALMASKED = 0xfff,
101 VT_TYPEMASK = 0xfff
104 struct seg_t;
106 typedef BOOL (*dump_seg_t)(struct seg_t*);
108 typedef struct seg_t {
109 const char *name;
110 dump_seg_t func;
111 int offset;
112 int length;
113 } seg_t;
114 static seg_t segdir[15];
116 enum SEGDIRTYPE {
117 SEGDIR_TYPEINFO,
118 SEGDIR_IMPINFO,
119 SEGDIR_IMPFILES,
120 SEGDIR_REF,
121 SEGDIR_GUIDHASH,
122 SEGDIR_GUID,
123 SEGDIR_NAMEHASH,
124 SEGDIR_NAME,
125 SEGDIR_STRING,
126 SEGDIR_TYPEDESC,
127 SEGDIR_ARRAYDESC,
128 SEGDIR_CUSTDATA,
129 SEGDIR_CDGUID,
130 SEGDIR_res0e,
131 SEGDIR_res0f
134 static int offset=0;
135 static int indent;
136 static int typeinfo_cnt;
137 static int header_flags = 0;
138 static BOOL msft_eof = FALSE;
140 static int msft_typeinfo_offs[1000];
141 static int msft_typeinfo_kind[1000];
142 static int msft_typeinfo_impltypes[1000];
143 static int msft_typeinfo_elemcnt[1000];
144 static int msft_typeinfo_cnt = 0;
146 static const char * const tkind[TKIND_MAX] = {
147 "TKIND_ENUM", "TKIND_RECORD", "TKIND_MODULE",
148 "TKIND_INTERFACE", "TKIND_DISPATCH", "TKIND_COCLASS",
149 "TKIND_ALIAS", "TKIND_UNION"
152 static const void *tlb_read(int size) {
153 const void *ret = PRD(offset, size);
155 if(ret)
156 offset += size;
157 else
158 msft_eof = TRUE;
160 return ret;
163 static int tlb_read_int(void)
165 const int *ret = tlb_read(sizeof(int));
166 return ret ? *ret : -1;
169 static int tlb_read_short(void)
171 const unsigned short *ret = tlb_read(sizeof(short));
172 return ret ? *ret : -1;
175 static int tlb_read_byte(void)
177 const unsigned char *ret = tlb_read(sizeof(char));
178 return ret ? *ret : -1;
181 static void print_offset(void)
183 int i;
184 for(i=0; i<indent; i++)
185 printf(" ");
188 static void print_begin_block(const char *name)
190 print_offset();
191 printf("%s {\n", name);
192 indent++;
195 static void print_begin_block_id(const char *name, int id)
197 char buf[64];
198 sprintf(buf, "%s %d", name, id);
199 print_begin_block(buf);
202 static void print_end_block(void)
204 indent--;
205 print_offset();
206 printf("}\n");
209 static int print_byte(const char *name)
211 unsigned char ret;
212 print_offset();
213 printf("%s = %02xh\n", name, ret=tlb_read_byte());
214 return ret;
217 static int print_hex(const char *name)
219 int ret;
220 print_offset();
221 printf("%s = %08xh\n", name, ret=tlb_read_int());
222 return ret;
225 static int print_hex_id(const char *name, int id)
227 char buf[64];
228 sprintf(buf, name, id);
229 return print_hex(buf);
232 static int print_short_hex(const char *name)
234 int ret;
235 print_offset();
236 printf("%s = %04xh\n", name, ret=tlb_read_short());
237 return ret;
240 static int print_short_dec(const char *name)
242 int ret;
243 print_offset();
244 printf("%s = %d\n", name, ret=tlb_read_short());
245 return ret;
248 static int print_dec(const char *name)
250 int ret;
251 print_offset();
252 printf("%s = %d\n", name, ret=tlb_read_int());
253 return ret;
256 static void print_guid(const char *name)
258 GUID guid = *(const GUID*)tlb_read(sizeof(guid));
260 print_offset();
262 printf("%s = {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", name,
263 guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
264 guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4],
265 guid.Data4[5], guid.Data4[6], guid.Data4[7]);
268 static void print_vartype(int vartype)
270 static const char *vartypes[VT_LPWSTR+1] = {
271 "VT_EMPTY", "VT_NULL", "VT_I2", "VT_I4", "VT_R4",
272 "VT_R8", "VT_CY", "VT_DATE", "VT_BSTR", "VT_DISPATCH",
273 "VT_ERROR", "VT_BOOL", "VT_VARIANT", "VT_UNKNOWN","VT_DECIMAL",
274 "unk 15", "VT_I1", "VT_UI1", "VT_UI2", "VT_UI4",
275 "VT_I8", "VT_UI8", "VT_INT", "VT_UINT", "VT_VOID",
276 "VT_HRESULT", "VT_PTR", "VT_SAFEARRAY","VT_CARRAY", "VT_USERDEFINED",
277 "VT_LPSTR", "VT_LPWSTR"
280 vartype &= VT_TYPEMASK;
281 if (vartype >= VT_EMPTY && vartype <= VT_LPWSTR)
282 printf("%s\n", vartypes[vartype]);
283 else
284 printf("unk %d\n", vartype);
287 static void print_ctl2(const char *name)
289 int len;
290 const char *buf;
292 print_offset();
294 len = tlb_read_short();
296 printf("%s = %d \"", name, len);
297 len >>= 2;
298 buf = tlb_read(len);
299 fwrite(buf, len, 1, stdout);
300 printf("\"");
301 len += 2;
303 while(len++ & 3)
304 printf("\\%02x", tlb_read_byte());
305 printf("\n");
308 static int tlb_isprint(unsigned char c)
310 return c >= 32;
313 static void dump_binary(int size)
315 const unsigned char *ptr;
316 int i, j;
318 if (!size) return;
320 ptr = tlb_read(size);
321 if (!ptr) return;
323 print_offset();
324 printf("%08x: ", offset - size);
326 for (i = 0; i < size; i++)
328 printf("%02x%c", ptr[i], (i % 16 == 7) ? '-' : ' ');
329 if ((i % 16) == 15)
331 printf( " " );
332 for (j = 0; j < 16; j++)
333 printf("%c", tlb_isprint(ptr[i-15+j]) ? ptr[i-15+j] : '.');
334 if (i < size-1)
336 printf("\n");
337 print_offset();
338 printf("%08x: ", offset - size + i + 1);
342 if (i % 16)
344 printf("%*s ", 3 * (16-(i%16)), "");
345 for (j = 0; j < i % 16; j++)
346 printf("%c", tlb_isprint(ptr[i-(i%16)+j]) ? ptr[i-(i%16)+j] : '.');
348 printf("\n");
351 static int dump_msft_varflags(void)
353 static const char *syskind[] = {
354 "SYS_WIN16", "SYS_WIN32", "SYS_MAC", "SYS_WIN64", "unknown"
356 int kind, flags;
358 print_offset();
359 flags = tlb_read_int();
360 kind = flags & 0xf;
361 if (kind > 3) kind = 4;
362 printf("varflags = %08x, syskind = %s\n", flags, syskind[kind]);
363 return flags;
366 static void dump_msft_version(void)
368 unsigned version;
369 print_offset();
370 version = tlb_read_int();
371 printf("version = %u.%u\n", version & 0xffff, version >> 16);
374 static void dump_msft_header(void)
376 print_begin_block("Header");
378 print_hex("magic1");
379 print_hex("magic2");
380 print_hex("posguid");
381 print_hex("lcid");
382 print_hex("lcid2");
383 header_flags = dump_msft_varflags();
384 dump_msft_version();
385 print_hex("flags");
386 typeinfo_cnt = print_dec("ntypeinfos");
387 print_dec("helpstring");
388 print_dec("helpstringcontext");
389 print_dec("helpcontext");
390 print_dec("nametablecount");
391 print_dec("nametablechars");
392 print_hex("NameOffset");
393 print_hex("helpfile");
394 print_hex("CustomDataOffset");
395 print_hex("res44");
396 print_hex("res48");
397 print_hex("dispatchpos");
398 print_hex("res50");
400 print_end_block();
403 static int dump_msft_typekind(void)
405 int ret, typekind;
407 print_offset();
408 ret = tlb_read_int();
409 typekind = ret & 0xf;
410 printf("typekind = %s, align = %d\n", typekind < TKIND_MAX ? tkind[typekind] : "unknown", (ret >> 11) & 0x1f);
411 return ret;
414 static void dump_msft_typeinfobase(void)
416 print_begin_block_id("TypeInfoBase", msft_typeinfo_cnt);
418 msft_typeinfo_kind[msft_typeinfo_cnt] = dump_msft_typekind();
419 msft_typeinfo_offs[msft_typeinfo_cnt] = print_hex("memoffset");
420 print_hex("res2");
421 print_hex("res3");
422 print_hex("res4");
423 print_hex("res5");
424 msft_typeinfo_elemcnt[msft_typeinfo_cnt] = print_hex("cElement");
425 print_hex("res7");
426 print_hex("res8");
427 print_hex("res9");
428 print_hex("resA");
429 print_hex("posguid");
430 print_hex("flags");
431 print_hex("NameOffset");
432 print_hex("version");
433 print_hex("docstringoffs");
434 print_hex("docstringcontext");
435 print_hex("helpcontext");
436 print_hex("oCustData");
437 msft_typeinfo_impltypes[msft_typeinfo_cnt++] = print_short_hex("cImplTypes");
438 print_short_hex("bSizeVftt");
439 print_dec("size");
440 print_hex("datatype1");
441 print_hex("datatype2");
442 print_hex("res18");
443 print_hex("res19");
445 print_end_block();
448 static BOOL dump_msft_typeinfobases(seg_t *seg)
450 int i;
452 for(i = 0; offset < seg->offset+seg->length; i++)
453 dump_msft_typeinfobase();
455 assert(offset == seg->offset+seg->length);
456 return TRUE;
459 static void dump_msft_impinfo(int n)
461 print_begin_block_id("ImpInfo", n);
463 print_hex("flags");
464 print_hex("oImpInfo");
465 print_hex("oGuid");
467 print_end_block();
470 static BOOL dump_msft_impinfos(seg_t *seg)
472 int i;
474 for(i = 0; offset < seg->offset+seg->length; i++)
475 dump_msft_impinfo(i);
477 assert(offset == seg->offset+seg->length);
478 return TRUE;
481 static void dump_msft_impfile(int n)
483 print_begin_block_id("ImpFile", n);
485 print_hex("guid");
486 print_hex("lcid");
487 print_hex("version");
488 print_ctl2("impfile");
490 print_end_block();
493 static BOOL dump_msft_impfiles(seg_t *seg)
495 int i;
497 for(i = 0; offset < seg->offset+seg->length; i++)
498 dump_msft_impfile(i);
500 assert(offset == seg->offset+seg->length);
501 return TRUE;
504 static BOOL dump_msft_reftabs(seg_t *seg)
506 print_begin_block("RefTab");
508 dump_binary(seg->length); /* FIXME */
510 print_end_block();
512 return TRUE;
515 static BOOL dump_msft_guidhashtab(seg_t *seg)
517 print_begin_block("GuidHashTab");
519 dump_binary(seg->length); /* FIXME */
521 print_end_block();
523 assert(offset == seg->offset+seg->length);
524 return TRUE;
527 static void dump_msft_guidentry(int n)
529 print_begin_block_id("GuidEntry", n);
531 print_guid("guid");
532 print_hex("hreftype");
533 print_hex("next_hash");
535 print_end_block();
538 static BOOL dump_msft_guidtab(seg_t *seg)
540 int i;
542 for(i = 0; offset < seg->offset+seg->length; i++)
543 dump_msft_guidentry(i);
545 assert(offset == seg->offset+seg->length);
546 return TRUE;
549 static BOOL dump_msft_namehashtab(seg_t *seg)
551 print_begin_block("NameHashTab");
553 dump_binary(seg->length); /* FIXME */
555 print_end_block();
556 return TRUE;
559 static void print_string0(void)
561 unsigned char c;
563 printf("\"");
564 while ((c = tlb_read_byte()) != 0)
566 if (isprint(c))
567 fwrite(&c, 1, 1, stdout);
568 else
570 char buf[16];
571 sprintf(buf, "\\%u", c);
572 fwrite(buf, 1, strlen(buf), stdout);
575 printf("\"");
578 static void print_string(int len)
580 printf("\"");
581 fwrite(tlb_read(len), len, 1, stdout);
582 printf("\"");
585 static void dump_string(int len, int align_off)
587 print_string(len);
588 printf(" ");
589 while((len++ + align_off) & 3)
590 printf("\\%2.2x", tlb_read_byte());
593 static void dump_msft_name(int base, int n)
595 int len;
597 print_begin_block_id("Name", n);
599 print_hex("hreftype");
600 print_hex("next_hash");
601 len = print_hex("namelen")&0xff;
603 print_offset();
604 printf("name = ");
605 dump_string(len, 0);
606 printf("\n");
608 print_end_block();
611 static BOOL dump_msft_nametab(seg_t *seg)
613 int i, base = offset;
615 for(i = 0; offset < seg->offset+seg->length; i++)
616 dump_msft_name(base, i);
618 assert(offset == seg->offset+seg->length);
619 return TRUE;
622 static void dump_msft_string(int n)
624 int len;
626 print_begin_block_id("String", n);
628 len = print_short_hex("stringlen");
630 print_offset();
631 printf("string = ");
632 dump_string(len, 2);
634 if(len < 3) {
635 for(len = 0; len < 4; len++)
636 printf("\\%2.2x", tlb_read_byte());
638 printf("\n");
640 print_end_block();
643 static BOOL dump_msft_stringtab(seg_t *seg)
645 int i;
647 for(i = 0; offset < seg->offset+seg->length; i++)
648 dump_msft_string(i);
650 assert(offset == seg->offset+seg->length);
651 return TRUE;
654 static void dump_msft_typedesc(int n)
656 print_begin_block_id("TYPEDESC", n);
658 print_hex("hreftype");
659 print_hex("vt");
661 print_end_block();
664 static BOOL dump_msft_typedesctab(seg_t *seg)
666 int i;
668 print_begin_block("TypedescTab");
670 for(i = 0; offset < seg->offset+seg->length; i++)
671 dump_msft_typedesc(i);
673 print_end_block();
675 assert(offset == seg->offset+seg->length);
676 return TRUE;
679 static BOOL dump_msft_arraydescs(seg_t *seg)
681 print_begin_block("ArrayDescriptions");
683 dump_binary(seg->length); /* FIXME */
685 print_end_block();
686 return TRUE;
689 static BOOL dump_msft_custdata(seg_t *seg)
691 unsigned short vt;
692 unsigned i, n;
694 print_begin_block("CustData");
696 for(i=0; offset < seg->offset+seg->length; i++) {
697 print_offset();
699 vt = tlb_read_short();
700 printf("vt %d", vt);
701 n = tlb_read_int();
703 switch(vt) {
704 case VT_BSTR:
705 printf(" len %d: ", n);
706 dump_string(n, 2);
707 printf("\n");
708 break;
709 default:
710 printf(": %x ", n);
711 printf("\\%2.2x ", tlb_read_byte());
712 printf("\\%2.2x\n", tlb_read_byte());
716 print_end_block();
717 return TRUE;
720 static void dump_msft_cdguid(int n)
722 print_begin_block_id("CGUid", n);
724 print_hex("GuidOffset");
725 print_hex("DataOffset");
726 print_hex("next");
728 print_end_block();
731 static BOOL dump_msft_cdguids(seg_t *seg)
733 int i;
735 for(i = 0; offset < seg->offset+seg->length; i++)
736 dump_msft_cdguid(i);
738 assert(offset == seg->offset+seg->length);
739 return TRUE;
742 static BOOL dump_msft_res0e(seg_t *seg)
744 print_begin_block("res0e");
745 dump_binary(seg->length);
746 print_end_block();
748 return TRUE;
751 static BOOL dump_msft_res0f(seg_t *seg)
753 print_begin_block("res0f");
754 dump_binary(seg->length);
755 print_end_block();
757 return TRUE;
760 /* Used for function return value and arguments type */
761 static void dump_msft_datatype(const char *name)
763 int datatype;
765 print_offset();
766 datatype = tlb_read_int();
767 printf("%s = %08x", name, datatype);
768 if (datatype < 0) {
769 printf(", ");
770 print_vartype(datatype);
772 else {
773 const short *vt;
775 if (datatype > segdir[SEGDIR_TYPEDESC].length) {
776 printf(", invalid offset\n");
777 return;
780 /* FIXME: in case of VT_USERDEFINED use hreftype */
781 vt = PRD(segdir[SEGDIR_TYPEDESC].offset + datatype, 4*sizeof(short));
782 datatype = vt[0] & VT_TYPEMASK;
783 if (datatype == VT_PTR) {
784 printf(", VT_PTR -> ");
785 if (vt[3] < 0)
786 datatype = vt[2];
787 else {
788 vt = PRD(segdir[SEGDIR_TYPEDESC].offset + vt[2], 4*sizeof(short));
789 datatype = *vt;
792 else {
793 printf(", ");
794 datatype = *vt;
797 print_vartype(datatype);
801 static void dump_defaultvalue(int id)
803 int offset;
805 print_offset();
806 offset = tlb_read_int();
808 printf("default value[%d] = %08x", id, offset);
809 if (offset == -1)
810 printf("\n");
811 else if (offset < 0) {
812 printf(", ");
813 print_vartype((offset & 0x7c000000) >> 26);
815 else {
816 const unsigned short *vt;
818 if (offset > segdir[SEGDIR_CUSTDATA].length) {
819 printf(", invalid offset\n");
820 return;
823 vt = PRD(segdir[SEGDIR_CUSTDATA].offset + offset, sizeof(*vt));
824 printf(", ");
825 print_vartype(*vt);
829 static void dump_msft_func(int n)
831 int size, args_cnt, i, extra_attr, fkccic;
833 print_begin_block_id("FuncRecord", n);
835 size = print_short_hex("size");
836 print_short_hex("index");
837 dump_msft_datatype("retval type");
838 print_hex("flags");
839 print_short_hex("VtableOffset");
840 print_short_hex("funcdescsize");
841 fkccic = print_hex("FKCCIC");
842 args_cnt = print_short_hex("nrargs");
843 print_short_hex("noptargs");
845 extra_attr = size/sizeof(INT) - 6 - args_cnt*(fkccic&0x1000 ? 4 : 3);
847 if(extra_attr)
848 print_hex("helpcontext");
849 if(extra_attr >= 2)
850 print_hex("oHelpString");
851 if(extra_attr >= 3)
852 print_hex("toEntry");
853 if(extra_attr >= 4)
854 print_hex("res9");
855 if(extra_attr >= 5)
856 print_hex("resA");
857 if(extra_attr >= 6)
858 print_hex("HelpStringContext");
859 if(extra_attr >= 7)
860 print_hex("oCustData");
861 for(i = 0; i < extra_attr-7; i++)
862 print_hex_id("oArgCustData", i);
864 if(fkccic & 0x1000) {
865 for(i=0; i < args_cnt; i++)
866 dump_defaultvalue(i);
869 for(i=0; i < args_cnt; i++) {
870 print_begin_block_id("param", i);
872 /* FIXME: Handle default values */
873 dump_msft_datatype("datatype");
874 print_hex("name");
875 print_hex("paramflags");
877 print_end_block();
880 print_end_block();
883 static void dump_msft_var(int n)
885 INT size;
887 print_begin_block_id("VarRecord", n);
889 size = print_hex("recsize")&0x1ff;
890 print_hex("DataType");
891 print_hex("flags");
892 print_short_hex("VarKind");
893 print_short_hex("vardescsize");
894 print_hex("OffsValue");
896 if(size > 5*sizeof(INT))
897 dump_binary(size - 5*sizeof(INT));
899 print_end_block();
902 static void dump_msft_ref(int n)
904 print_begin_block_id("RefRecord", n);
906 print_hex("reftype");
907 print_hex("flags");
908 print_hex("oCustData");
909 print_hex("onext");
911 print_end_block();
914 static void dump_msft_coclass(int n)
916 int i;
918 print_dec("size");
920 for(i=0; i < msft_typeinfo_impltypes[n]; i++)
921 dump_msft_ref(i);
924 static BOOL dump_msft_typeinfo(int n)
926 int i;
928 print_begin_block_id("TypeInfo", n);
930 if((msft_typeinfo_kind[n] & 0xf) == TKIND_COCLASS) {
931 dump_msft_coclass(n);
932 print_end_block();
933 return TRUE;
936 print_dec("size");
938 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
939 dump_msft_func(i);
941 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
942 dump_msft_var(i);
944 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
945 print_hex_id("func %d id", i);
947 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
948 print_hex_id("var %d id", i);
950 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
951 print_hex_id("func %d name", i);
953 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
954 print_hex_id("var %d name", i);
956 for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
957 print_hex_id("func %d offset", i);
959 for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
960 print_hex_id("var %d offset", i);
962 print_end_block();
964 return TRUE;
967 static seg_t segdir[] = {
968 {"TypeInfoTab", dump_msft_typeinfobases, -1, -1},
969 {"ImpInfo", dump_msft_impinfos, -1, -1},
970 {"ImpFiles", dump_msft_impfiles, -1, -1},
971 {"RefTab", dump_msft_reftabs, -1, -1},
972 {"GuidHashTab", dump_msft_guidhashtab, -1, -1},
973 {"GuidTab", dump_msft_guidtab, -1, -1},
974 {"NameHashTab", dump_msft_namehashtab, -1, -1},
975 {"pNameTab", dump_msft_nametab, -1, -1},
976 {"pStringTab", dump_msft_stringtab, -1, -1},
977 {"TypedescTab", dump_msft_typedesctab, -1, -1},
978 {"ArrayDescriptions", dump_msft_arraydescs, -1, -1},
979 {"CustData", dump_msft_custdata, -1, -1},
980 {"CDGuid", dump_msft_cdguids, -1, -1},
981 {"res0e", dump_msft_res0e, -1, -1},
982 {"res0f", dump_msft_res0f, -1, -1}
985 static void dump_msft_seg(seg_t *seg)
987 print_begin_block(seg->name);
989 seg->offset = print_hex("offset");
990 seg->length = print_dec("length");
991 print_hex("res08");
992 print_hex("res0c");
994 print_end_block();
997 static void dump_msft_segdir(void)
999 int i;
1001 print_begin_block("SegDir");
1003 for(i=0; i < ARRAY_SIZE(segdir); i++)
1004 dump_msft_seg(segdir+i);
1006 print_end_block();
1009 static BOOL dump_offset(void)
1011 int i;
1013 for(i=0; i < ARRAY_SIZE(segdir); i++)
1014 if(segdir[i].offset == offset)
1015 return segdir[i].func(segdir+i);
1017 for(i=0; i < msft_typeinfo_cnt; i++)
1018 if(msft_typeinfo_offs[i] == offset)
1019 return dump_msft_typeinfo(i);
1021 return FALSE;
1024 static void msft_dump(void)
1026 int i;
1028 dump_msft_header();
1030 for(i=0; i < typeinfo_cnt; i++)
1031 print_hex_id("typeinfo %d offset", i);
1033 if(header_flags & HELPDLLFLAG)
1034 print_hex("help dll offset");
1035 print_offset();
1036 printf("\n");
1038 dump_msft_segdir();
1040 while(!msft_eof) {
1041 if(!dump_offset())
1042 print_hex("unknown");
1046 /****************************** SLTG Typelibs ******************************/
1048 struct block_entry
1050 DWORD len;
1051 WORD index_string;
1052 WORD next;
1055 struct bitstream
1057 const BYTE *buffer;
1058 DWORD length;
1059 WORD current;
1062 #include "pshpack1.h"
1063 struct sltg_typeinfo_header
1065 short magic;
1066 int href_table;
1067 int res06;
1068 int elem_table;
1069 int res0e;
1070 int version;
1071 int res16;
1072 struct
1074 unsigned unknown1 : 3;
1075 unsigned flags : 16;
1076 unsigned unknown2 : 5;
1077 unsigned typekind : 8;
1078 } misc;
1079 int res1e;
1082 struct sltg_member_header
1084 short res00;
1085 short res02;
1086 char res04;
1087 int extra;
1090 struct sltg_tail
1092 unsigned short cFuncs;
1093 unsigned short cVars;
1094 unsigned short cImplTypes;
1095 unsigned short res06; /* always 0000 */
1096 unsigned short funcs_off; /* offset to functions (starting from the member header) */
1097 unsigned short vars_off; /* offset to vars (starting from the member header) */
1098 unsigned short impls_off; /* offset to implemented types (starting from the member header) */
1099 unsigned short funcs_bytes; /* bytes used by function data */
1100 unsigned short vars_bytes; /* bytes used by var data */
1101 unsigned short impls_bytes; /* bytes used by implemented type data */
1102 unsigned short tdescalias_vt; /* for TKIND_ALIAS */
1103 unsigned short res16; /* always ffff */
1104 unsigned short res18; /* always 0000 */
1105 unsigned short res1a; /* always 0000 */
1106 unsigned short simple_alias; /* tdescalias_vt is a vt rather than an offset? */
1107 unsigned short res1e; /* always 0000 */
1108 unsigned short cbSizeInstance;
1109 unsigned short cbAlignment;
1110 unsigned short res24;
1111 unsigned short res26;
1112 unsigned short cbSizeVft;
1113 unsigned short res2a; /* always ffff */
1114 unsigned short res2c; /* always ffff */
1115 unsigned short res2e; /* always ffff */
1116 unsigned short res30; /* always ffff */
1117 unsigned short res32;
1118 unsigned short res34;
1121 struct sltg_variable
1123 char magic; /* 0x0a */
1124 char flags;
1125 short next;
1126 short name;
1127 short byte_offs; /* pos in struct, or offset to const type or const data (if flags & 0x08) */
1128 short type; /* if flags & 0x02 this is the type, else offset to type */
1129 int memid;
1130 short helpcontext; /* ?? */
1131 short helpstring; /* ?? */
1132 #if 0
1133 short varflags; /* only present if magic & 0x20 */
1134 #endif
1136 #include "poppack.h"
1138 static const char *lookup_code(const BYTE *table, DWORD table_size, struct bitstream *bits)
1140 const BYTE *p = table;
1142 while (p < table + table_size && *p == 0x80)
1144 if (p + 2 >= table + table_size) return NULL;
1146 if (!(bits->current & 0xff))
1148 if (!bits->length) return NULL;
1149 bits->current = (*bits->buffer << 8) | 1;
1150 bits->buffer++;
1151 bits->length--;
1154 if (bits->current & 0x8000)
1156 p += 3;
1158 else
1160 p = table + (*(p + 2) | (*(p + 1) << 8));
1163 bits->current <<= 1;
1166 if (p + 1 < table + table_size && *(p + 1))
1168 /* FIXME: What is the meaning of *p? */
1169 const BYTE *q = p + 1;
1170 while (q < table + table_size && *q) q++;
1171 return (q < table + table_size) ? (const char *)(p + 1) : NULL;
1174 return NULL;
1177 static const char *decode_string(const BYTE *table, const char *stream, DWORD stream_length, DWORD *read_bytes)
1179 char *buf;
1180 DWORD buf_size, table_size;
1181 const char *p;
1182 struct bitstream bits;
1184 bits.buffer = (const BYTE *)stream;
1185 bits.length = stream_length;
1186 bits.current = 0;
1188 buf_size = *(const WORD *)table;
1189 table += sizeof(WORD);
1190 table_size = *(const DWORD *)table;
1191 table += sizeof(DWORD);
1193 buf = malloc(buf_size);
1194 buf[0] = 0;
1196 while ((p = lookup_code(table, table_size, &bits)))
1198 if (buf[0]) strcat(buf, " ");
1199 assert(strlen(buf) + strlen(p) + 1 <= buf_size);
1200 strcat(buf, p);
1203 if (read_bytes) *read_bytes = stream_length - bits.length;
1205 return buf;
1208 static void print_sltg_name(const char *name)
1210 unsigned short len = tlb_read_short();
1211 print_offset();
1212 printf("%s = %#x (", name, len);
1213 if (len != 0xffff) print_string(len);
1214 printf(")\n");
1217 static int dump_sltg_header(int *sltg_first_blk, int *size_of_index, int *size_of_pad)
1219 int n_file_blocks;
1221 print_begin_block("Header");
1223 print_hex("magic");
1224 n_file_blocks = print_short_dec("# file blocks");
1225 *size_of_pad = print_short_hex("pad");
1226 *size_of_index = print_short_hex("size of index");
1227 *sltg_first_blk = print_short_dec("first block");
1228 print_guid("guid");
1229 print_hex("res1c");
1230 print_hex("res20");
1232 print_end_block();
1234 return n_file_blocks;
1237 static void dump_sltg_index(int count)
1239 int i;
1241 printf("index:\n");
1243 print_string0();
1244 printf("\n");
1245 print_string0();
1246 printf("\n");
1248 for (i = 0; i < count - 2; i++)
1250 print_string0();
1251 printf("\n");
1254 printf("\n");
1257 static void dump_sltg_pad(int size_of_pad)
1259 printf("pad:\n");
1260 dump_binary(size_of_pad);
1261 printf("\n");
1264 static void dump_sltg_block_entry(int idx, const char *index)
1266 char name[32];
1267 short index_offset;
1269 sprintf(name, "Block entry %d", idx);
1270 print_begin_block(name);
1272 print_hex("len");
1273 index_offset = tlb_read_short();
1274 print_offset();
1275 printf("index string = %xh \"%s\"\n", index_offset, index + index_offset);
1276 print_short_hex("next");
1278 print_end_block();
1281 static void dump_sltg_library_block(void)
1283 print_begin_block("Library block entry");
1285 print_short_hex("magic");
1286 print_short_hex("res02");
1287 print_sltg_name("name");
1288 print_short_hex("res06");
1289 print_sltg_name("helpstring");
1290 print_sltg_name("helpfile");
1291 print_hex("helpcontext");
1292 print_short_hex("syskind");
1293 print_short_hex("lcid");
1294 print_hex("res12");
1295 print_short_hex("libflags");
1296 dump_msft_version();
1297 print_guid("uuid");
1299 print_end_block();
1302 static void skip_sltg_library_block(void)
1304 unsigned short skip;
1306 tlb_read_short();
1307 tlb_read_short();
1308 skip = tlb_read_short();
1309 if (skip != 0xffff) tlb_read(skip);
1310 tlb_read_short();
1311 skip = tlb_read_short();
1312 if (skip != 0xffff) tlb_read(skip);
1313 skip = tlb_read_short();
1314 if (skip != 0xffff) tlb_read(skip);
1315 tlb_read_int();
1316 tlb_read_short();
1317 tlb_read_short();
1318 tlb_read_int();
1319 tlb_read_short();
1320 tlb_read_int();
1321 tlb_read(sizeof(GUID));
1324 static void dump_sltg_other_typeinfo(int idx, const char *hlp_strings)
1326 int hlpstr_len, saved_offset;
1327 char name[32];
1329 sprintf(name, "Other typeinfo %d", idx);
1330 print_begin_block(name);
1332 print_sltg_name("index name");
1333 print_sltg_name("other name");
1334 print_short_hex("res1a");
1335 print_short_hex("name offset");
1337 print_offset();
1338 hlpstr_len = tlb_read_short();
1339 if (hlpstr_len)
1341 const char *str;
1343 saved_offset = offset;
1344 str = tlb_read(hlpstr_len);
1345 str = decode_string((const BYTE *)hlp_strings, str, hlpstr_len, NULL);
1346 printf("helpstring: \"%s\"\n", str);
1348 offset = saved_offset;
1349 print_offset();
1350 printf("helpstring encoded bits: %d bytes\n", hlpstr_len);
1351 dump_binary(hlpstr_len);
1353 else
1354 printf("helpstring: \"\"\n");
1356 print_short_hex("res20");
1357 print_hex("helpcontext");
1358 print_short_hex("res26");
1359 print_guid("uuid");
1360 print_short_dec("typekind");
1362 print_end_block();
1365 static void skip_sltg_other_typeinfo(void)
1367 unsigned short skip;
1369 skip = tlb_read_short();
1370 if (skip != 0xffff) tlb_read(skip);
1371 skip = tlb_read_short();
1372 if (skip != 0xffff) tlb_read(skip);
1373 tlb_read_short();
1374 tlb_read_short();
1375 skip = tlb_read_short();
1376 if (skip) tlb_read(skip);
1377 tlb_read_short();
1378 tlb_read_int();
1379 tlb_read_short();
1380 tlb_read(sizeof(GUID));
1381 tlb_read_short();
1384 static void sltg_print_simple_type(short type)
1386 print_offset();
1387 if ((type & 0x0f00) == 0x0e00)
1388 printf("*");
1389 printf("%04x | (%d)\n", type & 0xff80, type & 0x7f);
1392 static void dump_safe_array(int array_offset)
1394 int i, cDims, saved_offset = offset;
1396 offset = array_offset;
1398 print_offset();
1399 printf("safe array starts at %#x\n", offset);
1401 cDims = print_short_dec("cDims");
1402 print_short_hex("fFeatures");
1403 print_dec("cbElements");
1404 print_dec("cLocks");
1405 print_hex("pvData");
1407 for (i = 0; i < cDims; i++)
1408 dump_binary(8); /* sizeof(SAFEARRAYBOUND) */
1410 print_offset();
1411 printf("safe array ends at %#x\n", offset);
1412 offset = saved_offset;
1415 static int sltg_print_compound_type(int vars_start_offset, int type_offset)
1417 short type, vt;
1418 int type_bytes, saved_offset = offset;
1420 offset = vars_start_offset + type_offset;
1421 print_offset();
1422 printf("type description starts at %#x\n", offset);
1424 for (;;)
1428 type = tlb_read_short();
1429 vt = type & 0x7f;
1431 if (vt == VT_PTR)
1433 print_offset();
1434 printf("%04x | VT_PTR\n", type & 0xff80);
1436 } while (vt == VT_PTR);
1438 if (vt == VT_USERDEFINED)
1440 short href = tlb_read_short();
1441 print_offset();
1442 if ((type & 0x0f00) == 0x0e00)
1443 printf("*");
1444 printf("%04x | VT_USERDEFINED (href %d)\n", type & 0xff80, href);
1445 break;
1447 else if (vt == VT_CARRAY)
1449 short off;
1451 off = tlb_read_short();
1452 print_offset();
1453 printf("VT_CARRAY: offset %#x (+%#x=%#x)\n",
1454 off, vars_start_offset, off + vars_start_offset);
1455 dump_safe_array(vars_start_offset + off);
1457 /* type description follows */
1458 print_offset();
1459 printf("array element type:\n");
1460 continue;
1462 else if (vt == VT_SAFEARRAY)
1464 short off;
1466 off = tlb_read_short();
1467 print_offset();
1468 printf("VT_SAFEARRAY: offset %#x (+%#x=%#x)\n",
1469 off, vars_start_offset, off + vars_start_offset);
1470 dump_safe_array(vars_start_offset + off);
1471 break;
1473 else
1475 sltg_print_simple_type(type);
1476 break;
1480 print_offset();
1481 printf("type description ends at %#x\n", offset);
1482 type_bytes = offset - saved_offset;
1483 offset = saved_offset;
1485 return type_bytes;
1488 static void dump_type(int len, const char *hlp_strings)
1490 union
1492 struct
1494 unsigned unknown1 : 3;
1495 unsigned flags : 13;
1496 unsigned unknown2 : 8;
1497 unsigned typekind : 8;
1498 } s;
1499 unsigned flags;
1500 } misc;
1501 int typeinfo_start_offset, extra, member_offset, href_offset, i;
1502 int vars_header_bytes = 0, vars_bytes = 0, saved_offset;
1503 const void *block;
1504 const struct sltg_typeinfo_header *ti;
1505 const struct sltg_member_header *mem;
1506 const struct sltg_tail *tail;
1508 typeinfo_start_offset = offset;
1509 block = tlb_read(len);
1510 offset = typeinfo_start_offset;
1512 ti = block;
1513 mem = (const struct sltg_member_header *)((char *)block + ti->elem_table);
1514 tail = (const struct sltg_tail *)((char *)(mem + 1) + mem->extra);
1516 typeinfo_start_offset = offset;
1518 print_short_hex("magic");
1519 href_offset = tlb_read_int();
1520 print_offset();
1521 if (href_offset != -1)
1522 printf("href offset = %#x (+%#x=%#x)\n",
1523 href_offset, typeinfo_start_offset, href_offset + typeinfo_start_offset);
1524 else
1525 printf("href offset = ffffffffh\n");
1526 print_hex("res06");
1527 member_offset = tlb_read_int();
1528 print_offset();
1529 printf("member offset = %#x (+%#x=%#x)\n",
1530 member_offset, typeinfo_start_offset, member_offset + typeinfo_start_offset);
1531 print_hex("res0e");
1532 print_hex("version");
1533 print_hex("res16");
1534 misc.flags = print_hex("misc");
1535 print_offset();
1536 printf("misc: unknown1 %02x, flags %04x, unknown2 %02x, typekind %u (%s)\n",
1537 misc.s.unknown1, misc.s.flags, misc.s.unknown2, misc.s.typekind,
1538 misc.s.typekind < TKIND_MAX ? tkind[misc.s.typekind] : "unknown");
1539 print_hex("res1e");
1541 if (href_offset != -1)
1543 int i, number;
1545 print_begin_block("href_table");
1547 print_short_hex("magic");
1548 print_hex("res02");
1549 print_hex("res06");
1550 print_hex("res0a");
1551 print_hex("res0e");
1552 print_hex("res12");
1553 print_hex("res16");
1554 print_hex("res1a");
1555 print_hex("res1e");
1556 print_hex("res22");
1557 print_hex("res26");
1558 print_hex("res2a");
1559 print_hex("res2e");
1560 print_hex("res32");
1561 print_hex("res36");
1562 print_hex("res3a");
1563 print_hex("res3e");
1564 print_short_hex("res42");
1565 number = print_hex("number");
1567 for (i = 0; i < number; i += 8)
1568 dump_binary(8);
1570 print_short_hex("res50");
1571 print_byte("res52");
1572 print_hex("res53");
1574 for (i = 0; i < number/8; i++)
1575 print_sltg_name("name");
1577 print_byte("resxx");
1579 print_end_block();
1582 print_offset();
1583 printf("member_header starts at %#x, current offset = %#x\n", typeinfo_start_offset + member_offset, offset);
1584 member_offset = offset;
1585 print_short_hex("res00");
1586 print_short_hex("res02");
1587 print_byte("res04");
1588 extra = print_hex("extra");
1590 if (misc.s.typekind == TKIND_RECORD || misc.s.typekind == TKIND_ENUM)
1592 int vars_start_offset = offset;
1594 for (i = 0; i < tail->cVars; i++)
1596 char name[32];
1597 int saved_off;
1598 char magic, flags;
1599 short next, value;
1601 sprintf(name, "variable %d", i);
1602 print_begin_block(name);
1604 saved_off = offset;
1605 dump_binary(sizeof(struct sltg_variable));
1606 offset = saved_off;
1608 magic = print_byte("magic");
1609 flags = print_byte("flags");
1610 next = tlb_read_short();
1611 print_offset();
1612 if (next != -1)
1613 printf("next offset = %#x (+%#x=%#x)\n",
1614 next, vars_start_offset, next + vars_start_offset);
1615 else
1616 printf("next offset = ffffh\n");
1617 print_short_hex("name");
1619 if (flags & 0x40)
1620 print_short_hex("dispatch");
1621 else if (flags & 0x10)
1623 if (flags & 0x08)
1624 print_short_hex("const value");
1625 else
1627 value = tlb_read_short();
1628 print_offset();
1629 printf("byte offset = %#x (+%#x=%#x)\n",
1630 value, vars_start_offset, value + vars_start_offset);
1633 else
1634 print_short_hex("oInst");
1636 value = tlb_read_short();
1637 if (!(flags & 0x02))
1639 print_offset();
1640 printf("type offset = %#x (+%#x=%#x)\n",
1641 value, vars_start_offset, value + vars_start_offset);
1642 print_offset();
1643 printf("type:\n");
1644 vars_bytes += sltg_print_compound_type(vars_start_offset, value);
1646 else
1648 print_offset();
1649 printf("type:\n");
1650 sltg_print_simple_type(value);
1653 print_hex("memid");
1654 print_short_hex("helpcontext");
1656 value = tlb_read_short();
1657 print_offset();
1658 if (value != -1)
1660 const char *str;
1661 DWORD hlpstr_maxlen;
1663 printf("helpstring offset = %#x (+%#x=%#x)\n",
1664 value, vars_start_offset, value + vars_start_offset);
1666 saved_offset = offset;
1668 offset = value + vars_start_offset;
1670 hlpstr_maxlen = member_offset + sizeof(struct sltg_member_header) + mem->extra - offset;
1672 str = tlb_read(hlpstr_maxlen);
1673 str = decode_string((const BYTE *)hlp_strings, str, hlpstr_maxlen, &hlpstr_maxlen);
1674 print_offset();
1675 printf("helpstring: \"%s\"\n", str);
1677 offset = value + vars_start_offset;
1678 print_offset();
1679 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen);
1680 dump_binary(hlpstr_maxlen);
1682 offset = saved_offset;
1684 else
1685 printf("helpstring offset = ffffh\n");
1687 if (magic & 0x20)
1689 print_short_hex("varflags");
1690 vars_header_bytes += 2;
1693 vars_header_bytes += sizeof(struct sltg_variable);
1695 if (next != -1)
1697 if (offset != vars_start_offset + next)
1698 dump_binary(vars_start_offset + next - offset);
1701 print_end_block();
1704 else if (misc.s.typekind == TKIND_INTERFACE || misc.s.typekind == TKIND_COCLASS)
1706 short next, i;
1707 int funcs_start_offset = offset;
1709 for (i = 0; i < tail->cImplTypes; i++)
1711 char name[64];
1713 sprintf(name, "impl.type %d (current offset %#x)", i, offset);
1714 print_begin_block(name);
1716 print_short_hex("res00");
1717 next = tlb_read_short();
1718 print_offset();
1719 if (next != -1)
1720 printf("next offset = %#x (+%#x=%#x)\n",
1721 next, funcs_start_offset, next + funcs_start_offset);
1722 else
1723 printf("next offset = ffffh\n");
1724 print_short_hex("res04");
1725 print_byte("impltypeflags");
1726 print_byte("res07");
1727 print_short_hex("res08");
1728 print_short_hex("ref");
1729 print_short_hex("res0c");
1730 print_short_hex("res0e");
1731 print_short_hex("res10");
1732 print_short_hex("res12");
1733 print_short_hex("pos in table");
1735 print_end_block();
1738 for (i = 0; i < tail->cFuncs; i++)
1740 char name[64];
1741 BYTE magic, flags;
1742 short args_off, value, n_params, j;
1744 sprintf(name, "function %d (current offset %#x)", i, offset);
1745 print_begin_block(name);
1747 magic = print_byte("magic");
1748 flags = tlb_read_byte();
1749 print_offset();
1750 printf("invoke_kind = %u\n", flags >> 4);
1751 next = tlb_read_short();
1752 print_offset();
1753 if (next != -1)
1754 printf("next offset = %#x (+%#x=%#x)\n",
1755 next, funcs_start_offset, next + funcs_start_offset);
1756 else
1757 printf("next offset = ffffh\n");
1758 print_short_hex("name");
1759 print_hex("dispid");
1760 print_short_hex("helpcontext");
1762 value = tlb_read_short();
1763 print_offset();
1764 if (value != -1)
1766 const char *str;
1767 DWORD hlpstr_maxlen;
1769 printf("helpstring offset = %#x (+%#x=%#x)\n",
1770 value, funcs_start_offset, value + funcs_start_offset);
1772 saved_offset = offset;
1774 offset = value + funcs_start_offset;
1776 hlpstr_maxlen = member_offset + sizeof(struct sltg_member_header) + mem->extra - offset;
1778 str = tlb_read(hlpstr_maxlen);
1779 str = decode_string((const BYTE *)hlp_strings, str, hlpstr_maxlen, &hlpstr_maxlen);
1780 print_offset();
1781 printf("helpstring: \"%s\"\n", str);
1783 offset = value + funcs_start_offset;
1784 print_offset();
1785 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen);
1786 dump_binary(hlpstr_maxlen);
1788 offset = saved_offset;
1790 else
1791 printf("helpstring offset = ffffh\n");
1793 args_off = tlb_read_short();
1794 print_offset();
1795 if (args_off != -1)
1796 printf("args off = %#x (+%#x=%#x)\n",
1797 args_off, funcs_start_offset, args_off + funcs_start_offset);
1798 else
1799 printf("args off = ffffh\n");
1800 flags = tlb_read_byte();
1801 n_params = flags >> 3;
1802 print_offset();
1803 printf("callconv %u, cParams %u\n", flags & 0x7, n_params);
1805 flags = tlb_read_byte();
1806 print_offset();
1807 printf("retnextop %02x, cParamsOpt %u\n", flags, (flags & 0x7e) >> 1);
1809 value = print_short_hex("rettype");
1810 if (!(flags & 0x80))
1812 print_offset();
1813 printf("rettype offset = %#x (+%#x=%#x)\n",
1814 value, funcs_start_offset, value + funcs_start_offset);
1815 print_offset();
1816 printf("rettype:\n");
1817 sltg_print_compound_type(funcs_start_offset, value);
1819 else
1821 print_offset();
1822 printf("rettype:\n");
1823 sltg_print_simple_type(value);
1826 print_short_hex("vtblpos");
1827 if (magic & 0x20)
1828 print_short_hex("funcflags");
1830 if (n_params)
1832 offset = args_off + funcs_start_offset;
1833 print_offset();
1834 printf("arguments start at %#x\n", offset);
1837 for (j = 0; j < n_params; j++)
1839 char name[32];
1840 unsigned short name_offset;
1842 sprintf(name, "arg %d", j);
1843 print_begin_block(name);
1845 name_offset = tlb_read_short();
1846 print_offset();
1847 printf("name: %04xh\n", name_offset);
1849 value = tlb_read_short();
1850 print_offset();
1851 printf("type/offset %04xh\n", value);
1852 if (name_offset & 1) /* type follows */
1854 print_offset();
1855 printf("type follows, using current offset for type\n");
1856 offset -= 2;
1857 value = offset - funcs_start_offset;
1860 print_offset();
1861 printf("arg[%d] off = %#x (+%#x=%#x)\n",
1862 j, value, funcs_start_offset, value + funcs_start_offset);
1863 print_offset();
1864 printf("type:\n");
1865 value = sltg_print_compound_type(funcs_start_offset, value);
1866 if (name_offset & 1)
1867 offset += value;
1869 print_end_block();
1872 if (n_params)
1874 print_offset();
1875 printf("arguments end at %#x\n", offset);
1878 if (next != -1)
1880 if (offset != funcs_start_offset + next)
1881 dump_binary(funcs_start_offset + next - offset);
1884 print_end_block();
1887 else
1889 printf("skipping %#x bytes\n", extra);
1890 dump_binary(extra);
1893 if (offset < member_offset + sizeof(struct sltg_member_header) + mem->extra)
1895 print_offset();
1896 printf("skipping %d bytes\n", member_offset + (int)sizeof(struct sltg_member_header) + mem->extra - offset);
1897 dump_binary(member_offset + sizeof(struct sltg_member_header) + mem->extra - offset);
1900 print_offset();
1901 printf("dumped %d (%#x) bytes\n", offset - typeinfo_start_offset, offset - typeinfo_start_offset);
1902 len -= offset - typeinfo_start_offset;
1903 print_offset();
1904 printf("sltg_tail %d (%#x) bytes:\n", len, len);
1905 saved_offset = offset;
1906 dump_binary(len);
1907 offset = saved_offset;
1908 print_short_hex("cFuncs");
1909 print_short_hex("cVars");
1910 print_short_hex("cImplTypes");
1911 print_short_hex("res06");
1912 print_short_hex("funcs_off");
1913 print_short_hex("vars_off");
1914 print_short_hex("impls_off");
1915 print_short_hex("funcs_bytes");
1916 print_short_hex("vars_bytes");
1917 print_short_hex("impls_bytes");
1918 print_short_hex("tdescalias_vt");
1919 print_short_hex("res16");
1920 print_short_hex("res18");
1921 print_short_hex("res1a");
1922 print_short_hex("simple_alias");
1923 print_short_hex("res1e");
1924 print_short_hex("cbSizeInstance");
1925 print_short_hex("cbAlignment");
1926 print_short_hex("res24");
1927 print_short_hex("res26");
1928 print_short_hex("cbSizeVft");
1929 print_short_hex("res2a");
1930 print_short_hex("res2c");
1931 print_short_hex("res2e");
1932 print_short_hex("res30");
1933 print_short_hex("res32");
1934 print_short_hex("res34");
1935 offset = saved_offset + len;
1938 static void sltg_dump(void)
1940 int i, n_file_blocks, n_first_blk, size_of_index, size_of_pad;
1941 int name_table_start, name_table_size, saved_offset;
1942 int libblk_start, libblk_len, hlpstr_len, len;
1943 const char *index, *hlp_strings;
1944 const struct block_entry *entry;
1946 n_file_blocks = dump_sltg_header(&n_first_blk, &size_of_index, &size_of_pad);
1948 saved_offset = offset;
1949 entry = tlb_read((n_file_blocks - 1) * sizeof(*entry));
1950 if (!entry) return;
1951 index = tlb_read(size_of_index);
1952 if (!index) return;
1953 offset = saved_offset;
1955 for (i = 0; i < n_file_blocks - 1; i++)
1956 dump_sltg_block_entry(i, index);
1958 saved_offset = offset;
1959 dump_sltg_index(n_file_blocks);
1960 assert(offset - saved_offset == size_of_index);
1962 dump_sltg_pad(size_of_pad);
1964 /* read the helpstrings for later decoding */
1965 saved_offset = offset;
1967 for (i = n_first_blk - 1; entry[i].next != 0; i = entry[i].next - 1)
1968 tlb_read(entry[i].len);
1970 libblk_start = offset;
1971 skip_sltg_library_block();
1972 tlb_read(0x40);
1973 typeinfo_cnt = tlb_read_short();
1975 for (i = 0; i < typeinfo_cnt; i++)
1976 skip_sltg_other_typeinfo();
1978 len = tlb_read_int();
1979 hlpstr_len = (libblk_start + len) - offset;
1980 hlp_strings = tlb_read(hlpstr_len);
1981 assert(hlp_strings != NULL);
1982 /* check the helpstrings header values */
1983 len = *(int *)(hlp_strings + 2);
1984 assert(hlpstr_len == len + 6);
1986 offset = saved_offset;
1988 for (i = n_first_blk - 1; entry[i].next != 0; i = entry[i].next - 1)
1990 short magic;
1991 char name[32];
1993 saved_offset = offset;
1995 sprintf(name, "Block %d", i);
1996 print_begin_block(name);
1997 magic = tlb_read_short();
1998 assert(magic == 0x0501);
1999 offset -= 2;
2000 dump_binary(entry[i].len);
2001 print_end_block();
2003 offset = saved_offset;
2005 print_begin_block(name);
2006 dump_type(entry[i].len, hlp_strings);
2007 print_end_block();
2009 offset = saved_offset + entry[i].len;
2012 libblk_len = entry[i].len;
2014 libblk_start = offset;
2015 dump_sltg_library_block();
2017 printf("skipping 0x40 bytes\n");
2018 dump_binary(0x40);
2019 printf("\n");
2020 typeinfo_cnt = print_short_dec("typeinfo count");
2021 printf("\n");
2023 for (i = 0; i < typeinfo_cnt; i++)
2024 dump_sltg_other_typeinfo(i, hlp_strings);
2026 len = print_hex("offset from start of library block to name table");
2027 printf("%#x + %#x = %#x\n", libblk_start, len, libblk_start + len);
2028 len = (libblk_start + len) - offset;
2029 printf("skipping %#x bytes (encoded/compressed helpstrings)\n", len);
2030 printf("max string length: %#x, strings length %#x\n", *(short *)hlp_strings, *(int *)(hlp_strings + 2));
2031 dump_binary(len);
2032 printf("\n");
2034 len = print_short_hex("name table jump");
2035 if (len == 0xffff)
2037 printf("skipping 0x000a bytes\n");
2038 dump_binary(0x000a);
2039 printf("\n");
2041 else if (len == 0x0200)
2043 printf("skipping 0x002a bytes\n");
2044 dump_binary(0x002a);
2045 printf("\n");
2047 else
2049 printf("FIXME: please report! (%#x)\n", len);
2050 assert(0);
2053 printf("skipping 0x200 bytes\n");
2054 dump_binary(0x200);
2055 printf("\n");
2057 name_table_size = print_hex("name table size");
2059 name_table_start = offset;
2060 printf("name table offset = %#x\n\n", offset);
2062 while (offset < name_table_start + name_table_size)
2064 int aligned_len;
2066 dump_binary(8);
2067 print_string0();
2068 printf("\n");
2070 len = offset - name_table_start;
2071 aligned_len = (len + 0x1f) & ~0x1f;
2072 if (aligned_len - len < 4)
2073 dump_binary(aligned_len - len);
2074 else
2075 dump_binary(len & 1);
2076 printf("\n");
2079 print_hex("01ffff01");
2080 len = print_hex("length");
2081 printf("skipping %#x bytes\n", len);
2082 dump_binary(len);
2083 printf("\n");
2085 len = (libblk_start + libblk_len) - offset;
2086 printf("skipping libblk remainder %#x bytes\n", len);
2087 dump_binary(len);
2088 printf("\n");
2090 /* FIXME: msodumper/olestream.py parses this block differently
2091 print_short_hex("unknown");
2092 print_short_hex("byte order mark");
2093 i = tlb_read_short();
2094 printf("version = %u.%u\n", i & 0xff, i >> 8);
2095 print_short_hex("system identifier");
2096 print_hex("unknown");
2097 printf("\n");
2099 printf("skipping 12 bytes\n");
2100 dump_binary(12);
2101 printf("\n");
2103 print_guid("uuid");
2104 printf("\n");
2106 /* 0x0008,"TYPELIB",0 */
2107 dump_binary(12);
2108 printf("\n");
2110 printf("skipping 12 bytes\n");
2111 dump_binary(12);
2112 printf("\n");
2114 printf("skipping remainder 0x10 bytes\n");
2115 dump_binary(0x10);
2116 printf("\n");
2119 void tlb_dump(void)
2121 const DWORD *sig = PRD(0, sizeof(DWORD));
2122 if (*sig == MSFT_MAGIC)
2123 msft_dump();
2124 else
2125 sltg_dump();
2128 enum FileSig get_kind_tlb(void)
2130 const DWORD *sig = PRD(0, sizeof(DWORD));
2131 if (sig && (*sig == MSFT_MAGIC || *sig == SLTG_MAGIC)) return SIG_TLB;
2132 return SIG_UNKNOWN;