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
30 #define MSFT_MAGIC 0x5446534d
31 #define SLTG_MAGIC 0x47544c53
32 #define HELPDLLFLAG 0x0100
85 VT_STREAMED_OBJECT
= 68,
86 VT_STORED_OBJECT
= 69,
90 VT_VERSIONED_STREAM
= 73,
97 VT_ILLEGALMASKED
= 0xfff,
103 typedef BOOL (*dump_seg_t
)(struct seg_t
*);
105 typedef struct seg_t
{
111 static seg_t segdir
[15];
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
);
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)
181 for(i
=0; i
<indent
; i
++)
185 static void print_begin_block(const char *name
)
188 printf("%s {\n", name
);
192 static void print_begin_block_id(const char *name
, int id
)
195 sprintf(buf
, "%s %d", name
, id
);
196 print_begin_block(buf
);
199 static void print_end_block(void)
206 static int print_byte(const char *name
)
210 printf("%s = %02xh\n", name
, ret
=tlb_read_byte());
214 static int print_hex(const char *name
)
218 printf("%s = %08xh\n", name
, ret
=tlb_read_int());
222 static int print_hex_id(const char *name
, int id
)
225 sprintf(buf
, name
, id
);
226 return print_hex(buf
);
229 static int print_short_hex(const char *name
)
233 printf("%s = %04xh\n", name
, ret
=tlb_read_short());
237 static int print_short_dec(const char *name
)
241 printf("%s = %d\n", name
, ret
=tlb_read_short());
245 static int print_dec(const char *name
)
249 printf("%s = %d\n", name
, ret
=tlb_read_int());
253 static void print_guid(const char *name
)
255 GUID guid
= *(const GUID
*)tlb_read(sizeof(guid
));
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
]);
281 printf("unk %d\n", vartype
);
284 static void print_ctl2(const char *name
)
291 len
= tlb_read_short();
293 printf("%s = %d \"", name
, len
);
296 fwrite(buf
, len
, 1, stdout
);
301 printf("\\%02x", tlb_read_byte());
305 static int tlb_isprint(unsigned char c
)
310 static void dump_binary(int size
)
312 const unsigned char *ptr
;
317 ptr
= tlb_read(size
);
321 printf("%08x: ", offset
- size
);
323 for (i
= 0; i
< size
; i
++)
325 printf("%02x%c", ptr
[i
], (i
% 16 == 7) ? '-' : ' ');
329 for (j
= 0; j
< 16; j
++)
330 printf("%c", tlb_isprint(ptr
[i
-15+j
]) ? ptr
[i
-15+j
] : '.');
335 printf("%08x: ", offset
- size
+ i
+ 1);
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
] : '.');
348 static int dump_msft_varflags(void)
350 static const char *syskind
[] = {
351 "SYS_WIN16", "SYS_WIN32", "SYS_MAC", "SYS_WIN64", "unknown"
356 flags
= tlb_read_int();
358 if (kind
> 3) kind
= 4;
359 printf("varflags = %08x, syskind = %s\n", flags
, syskind
[kind
]);
363 static void dump_msft_version(void)
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");
377 print_hex("posguid");
380 header_flags
= dump_msft_varflags();
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");
394 print_hex("dispatchpos");
400 static int dump_msft_typekind(void)
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);
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");
421 msft_typeinfo_elemcnt
[msft_typeinfo_cnt
] = print_hex("cElement");
426 print_hex("posguid");
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");
437 print_hex("datatype1");
438 print_hex("datatype2");
445 static BOOL
dump_msft_typeinfobases(seg_t
*seg
)
449 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
450 dump_msft_typeinfobase();
452 assert(offset
== seg
->offset
+seg
->length
);
456 static void dump_msft_impinfo(int n
)
458 print_begin_block_id("ImpInfo", n
);
461 print_hex("oImpInfo");
467 static BOOL
dump_msft_impinfos(seg_t
*seg
)
471 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
472 dump_msft_impinfo(i
);
474 assert(offset
== seg
->offset
+seg
->length
);
478 static void dump_msft_impfile(int n
)
480 print_begin_block_id("ImpFile", n
);
484 print_hex("version");
485 print_ctl2("impfile");
490 static BOOL
dump_msft_impfiles(seg_t
*seg
)
494 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
495 dump_msft_impfile(i
);
497 assert(offset
== seg
->offset
+seg
->length
);
501 static BOOL
dump_msft_reftabs(seg_t
*seg
)
503 print_begin_block("RefTab");
505 dump_binary(seg
->length
); /* FIXME */
512 static BOOL
dump_msft_guidhashtab(seg_t
*seg
)
514 print_begin_block("GuidHashTab");
516 dump_binary(seg
->length
); /* FIXME */
520 assert(offset
== seg
->offset
+seg
->length
);
524 static void dump_msft_guidentry(int n
)
526 print_begin_block_id("GuidEntry", n
);
529 print_hex("hreftype");
530 print_hex("next_hash");
535 static BOOL
dump_msft_guidtab(seg_t
*seg
)
539 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
540 dump_msft_guidentry(i
);
542 assert(offset
== seg
->offset
+seg
->length
);
546 static BOOL
dump_msft_namehashtab(seg_t
*seg
)
548 print_begin_block("NameHashTab");
550 dump_binary(seg
->length
); /* FIXME */
556 static void print_string0(void)
561 while ((c
= tlb_read_byte()) != 0)
564 fwrite(&c
, 1, 1, stdout
);
568 sprintf(buf
, "\\%u", c
);
569 fwrite(buf
, 1, strlen(buf
), stdout
);
575 static void print_string(int len
)
578 fwrite(tlb_read(len
), len
, 1, stdout
);
582 static void dump_string(int len
, int align_off
)
586 while((len
++ + align_off
) & 3)
587 printf("\\%2.2x", tlb_read_byte());
590 static void dump_msft_name(int base
, int n
)
594 print_begin_block_id("Name", n
);
596 print_hex("hreftype");
597 print_hex("next_hash");
598 len
= print_hex("namelen")&0xff;
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
);
619 static void dump_msft_string(int n
)
623 print_begin_block_id("String", n
);
625 len
= print_short_hex("stringlen");
632 for(len
= 0; len
< 4; len
++)
633 printf("\\%2.2x", tlb_read_byte());
640 static BOOL
dump_msft_stringtab(seg_t
*seg
)
644 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
647 assert(offset
== seg
->offset
+seg
->length
);
651 static void dump_msft_typedesc(int n
)
653 print_begin_block_id("TYPEDESC", n
);
655 print_hex("hreftype");
661 static BOOL
dump_msft_typedesctab(seg_t
*seg
)
665 print_begin_block("TypedescTab");
667 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
668 dump_msft_typedesc(i
);
672 assert(offset
== seg
->offset
+seg
->length
);
676 static BOOL
dump_msft_arraydescs(seg_t
*seg
)
678 print_begin_block("ArrayDescriptions");
680 dump_binary(seg
->length
); /* FIXME */
686 static BOOL
dump_msft_custdata(seg_t
*seg
)
691 print_begin_block("CustData");
693 for(i
=0; offset
< seg
->offset
+seg
->length
; i
++) {
696 vt
= tlb_read_short();
702 printf(" len %d: ", n
);
708 printf("\\%2.2x ", tlb_read_byte());
709 printf("\\%2.2x\n", tlb_read_byte());
717 static void dump_msft_cdguid(int n
)
719 print_begin_block_id("CGUid", n
);
721 print_hex("GuidOffset");
722 print_hex("DataOffset");
728 static BOOL
dump_msft_cdguids(seg_t
*seg
)
732 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
735 assert(offset
== seg
->offset
+seg
->length
);
739 static BOOL
dump_msft_res0e(seg_t
*seg
)
741 print_begin_block("res0e");
742 dump_binary(seg
->length
);
748 static BOOL
dump_msft_res0f(seg_t
*seg
)
750 print_begin_block("res0f");
751 dump_binary(seg
->length
);
757 /* Used for function return value and arguments type */
758 static void dump_msft_datatype(const char *name
)
763 datatype
= tlb_read_int();
764 printf("%s = %08x", name
, datatype
);
767 print_vartype(datatype
);
772 if (datatype
> segdir
[SEGDIR_TYPEDESC
].length
) {
773 printf(", invalid offset\n");
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 -> ");
785 vt
= PRD(segdir
[SEGDIR_TYPEDESC
].offset
+ vt
[2], 4*sizeof(short));
794 print_vartype(datatype
);
798 static void dump_defaultvalue(int id
)
803 offset
= tlb_read_int();
805 printf("default value[%d] = %08x", id
, offset
);
808 else if (offset
< 0) {
810 print_vartype((offset
& 0x7c000000) >> 26);
813 const unsigned short *vt
;
815 if (offset
> segdir
[SEGDIR_CUSTDATA
].length
) {
816 printf(", invalid offset\n");
820 vt
= PRD(segdir
[SEGDIR_CUSTDATA
].offset
+ offset
, sizeof(*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");
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);
845 print_hex("helpcontext");
847 print_hex("oHelpString");
849 print_hex("toEntry");
855 print_hex("HelpStringContext");
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");
872 print_hex("paramflags");
880 static void dump_msft_var(int n
)
884 print_begin_block_id("VarRecord", n
);
886 size
= print_hex("recsize")&0x1ff;
887 print_hex("DataType");
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
));
899 static void dump_msft_ref(int n
)
901 print_begin_block_id("RefRecord", n
);
903 print_hex("reftype");
905 print_hex("oCustData");
911 static void dump_msft_coclass(int n
)
917 for(i
=0; i
< msft_typeinfo_impltypes
[n
]; i
++)
921 static BOOL
dump_msft_typeinfo(int n
)
925 print_begin_block_id("TypeInfo", n
);
927 if((msft_typeinfo_kind
[n
] & 0xf) == TKIND_COCLASS
) {
928 dump_msft_coclass(n
);
935 for(i
= 0; i
< LOWORD(msft_typeinfo_elemcnt
[n
]); i
++)
938 for(i
= 0; i
< HIWORD(msft_typeinfo_elemcnt
[n
]); 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
);
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");
994 static void dump_msft_segdir(void)
998 print_begin_block("SegDir");
1000 for(i
=0; i
< ARRAY_SIZE(segdir
); i
++)
1001 dump_msft_seg(segdir
+i
);
1006 static BOOL
dump_offset(void)
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
);
1021 static void msft_dump(void)
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");
1039 print_hex("unknown");
1043 /****************************** SLTG Typelibs ******************************/
1059 #include "pshpack1.h"
1060 struct sltg_typeinfo_header
1071 unsigned unknown1
: 3;
1072 unsigned flags
: 16;
1073 unsigned unknown2
: 5;
1074 unsigned typekind
: 8;
1079 struct sltg_member_header
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 */
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 */
1127 short helpcontext
; /* ?? */
1128 short helpstring
; /* ?? */
1130 short varflags
; /* only present if magic & 0x20 */
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;
1151 if (bits
->current
& 0x8000)
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
;
1174 static const char *decode_string(const BYTE
*table
, const char *stream
, UINT stream_length
, UINT
*read_bytes
)
1177 DWORD buf_size
, table_size
;
1179 struct bitstream bits
;
1181 bits
.buffer
= (const BYTE
*)stream
;
1182 bits
.length
= stream_length
;
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
);
1193 while ((p
= lookup_code(table
, table_size
, &bits
)))
1195 if (buf
[0]) strcat(buf
, " ");
1196 assert(strlen(buf
) + strlen(p
) + 1 <= buf_size
);
1200 if (read_bytes
) *read_bytes
= stream_length
- bits
.length
;
1205 static void print_sltg_name(const char *name
)
1207 unsigned short len
= tlb_read_short();
1209 printf("%s = %#x (", name
, len
);
1210 if (len
!= 0xffff) print_string(len
);
1214 static int dump_sltg_header(int *sltg_first_blk
, int *size_of_index
, int *size_of_pad
)
1218 print_begin_block("Header");
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");
1231 return n_file_blocks
;
1234 static void dump_sltg_index(int count
)
1245 for (i
= 0; i
< count
- 2; i
++)
1254 static void dump_sltg_pad(int size_of_pad
)
1257 dump_binary(size_of_pad
);
1261 static void dump_sltg_block_entry(int idx
, const char *index
)
1266 sprintf(name
, "Block entry %d", idx
);
1267 print_begin_block(name
);
1270 index_offset
= tlb_read_short();
1272 printf("index string = %xh \"%s\"\n", index_offset
, index
+ index_offset
);
1273 print_short_hex("next");
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");
1292 print_short_hex("libflags");
1293 dump_msft_version();
1299 static void skip_sltg_library_block(void)
1301 unsigned short skip
;
1305 skip
= tlb_read_short();
1306 if (skip
!= 0xffff) tlb_read(skip
);
1308 skip
= tlb_read_short();
1309 if (skip
!= 0xffff) tlb_read(skip
);
1310 skip
= tlb_read_short();
1311 if (skip
!= 0xffff) tlb_read(skip
);
1318 tlb_read(sizeof(GUID
));
1321 static void dump_sltg_other_typeinfo(int idx
, const char *hlp_strings
)
1323 int hlpstr_len
, saved_offset
;
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");
1335 hlpstr_len
= tlb_read_short();
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
;
1347 printf("helpstring encoded bits: %d bytes\n", hlpstr_len
);
1348 dump_binary(hlpstr_len
);
1351 printf("helpstring: \"\"\n");
1353 print_short_hex("res20");
1354 print_hex("helpcontext");
1355 print_short_hex("res26");
1357 print_short_dec("typekind");
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
);
1372 skip
= tlb_read_short();
1373 if (skip
) tlb_read(skip
);
1377 tlb_read(sizeof(GUID
));
1381 static void sltg_print_simple_type(short type
)
1384 if ((type
& 0x0f00) == 0x0e00)
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
;
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) */
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
)
1415 int type_bytes
, saved_offset
= offset
;
1417 offset
= vars_start_offset
+ type_offset
;
1419 printf("type description starts at %#x\n", offset
);
1425 type
= tlb_read_short();
1431 printf("%04x | VT_PTR\n", type
& 0xff80);
1433 } while (vt
== VT_PTR
);
1435 if (vt
== VT_USERDEFINED
)
1437 short href
= tlb_read_short();
1439 if ((type
& 0x0f00) == 0x0e00)
1441 printf("%04x | VT_USERDEFINED (href %d)\n", type
& 0xff80, href
);
1444 else if (vt
== VT_CARRAY
)
1448 off
= tlb_read_short();
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 */
1456 printf("array element type:\n");
1459 else if (vt
== VT_SAFEARRAY
)
1463 off
= tlb_read_short();
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
);
1472 sltg_print_simple_type(type
);
1478 printf("type description ends at %#x\n", offset
);
1479 type_bytes
= offset
- saved_offset
;
1480 offset
= saved_offset
;
1485 static void dump_type(int len
, const char *hlp_strings
)
1491 unsigned unknown1
: 3;
1492 unsigned flags
: 13;
1493 unsigned unknown2
: 8;
1494 unsigned typekind
: 8;
1498 int typeinfo_start_offset
, extra
, member_offset
, href_offset
, i
;
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
;
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();
1518 if (href_offset
!= -1)
1519 printf("href offset = %#x (+%#x=%#x)\n",
1520 href_offset
, typeinfo_start_offset
, href_offset
+ typeinfo_start_offset
);
1522 printf("href offset = ffffffffh\n");
1524 member_offset
= tlb_read_int();
1526 printf("member offset = %#x (+%#x=%#x)\n",
1527 member_offset
, typeinfo_start_offset
, member_offset
+ typeinfo_start_offset
);
1529 print_hex("version");
1531 misc
.flags
= print_hex("misc");
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");
1538 if (href_offset
!= -1)
1542 print_begin_block("href_table");
1544 print_short_hex("magic");
1561 print_short_hex("res42");
1562 number
= print_hex("number");
1564 for (i
= 0; i
< number
; i
+= 8)
1567 print_short_hex("res50");
1568 print_byte("res52");
1571 for (i
= 0; i
< number
/8; i
++)
1572 print_sltg_name("name");
1574 print_byte("resxx");
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
++)
1598 sprintf(name
, "variable %d", i
);
1599 print_begin_block(name
);
1602 dump_binary(sizeof(struct sltg_variable
));
1605 magic
= print_byte("magic");
1606 flags
= print_byte("flags");
1607 next
= tlb_read_short();
1610 printf("next offset = %#x (+%#x=%#x)\n",
1611 next
, vars_start_offset
, next
+ vars_start_offset
);
1613 printf("next offset = ffffh\n");
1614 print_short_hex("name");
1617 print_short_hex("dispatch");
1618 else if (flags
& 0x10)
1621 print_short_hex("const value");
1624 value
= tlb_read_short();
1626 printf("byte offset = %#x (+%#x=%#x)\n",
1627 value
, vars_start_offset
, value
+ vars_start_offset
);
1631 print_short_hex("oInst");
1633 value
= tlb_read_short();
1634 if (!(flags
& 0x02))
1637 printf("type offset = %#x (+%#x=%#x)\n",
1638 value
, vars_start_offset
, value
+ vars_start_offset
);
1641 sltg_print_compound_type(vars_start_offset
, value
);
1647 sltg_print_simple_type(value
);
1651 print_short_hex("helpcontext");
1653 value
= tlb_read_short();
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
);
1672 printf("helpstring: \"%s\"\n", str
);
1674 offset
= value
+ vars_start_offset
;
1676 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen
);
1677 dump_binary(hlpstr_maxlen
);
1679 offset
= saved_offset
;
1682 printf("helpstring offset = ffffh\n");
1684 if (magic
& 0x20) print_short_hex("varflags");
1688 if (offset
!= vars_start_offset
+ next
)
1689 dump_binary(vars_start_offset
+ next
- offset
);
1695 else if (misc
.s
.typekind
== TKIND_INTERFACE
|| misc
.s
.typekind
== TKIND_COCLASS
)
1698 int funcs_start_offset
= offset
;
1700 for (i
= 0; i
< tail
->cImplTypes
; i
++)
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();
1711 printf("next offset = %#x (+%#x=%#x)\n",
1712 next
, funcs_start_offset
, next
+ funcs_start_offset
);
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");
1729 for (i
= 0; i
< tail
->cFuncs
; i
++)
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();
1741 printf("invoke_kind = %u\n", flags
>> 4);
1742 next
= tlb_read_short();
1745 printf("next offset = %#x (+%#x=%#x)\n",
1746 next
, funcs_start_offset
, next
+ funcs_start_offset
);
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();
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
);
1772 printf("helpstring: \"%s\"\n", str
);
1774 offset
= value
+ funcs_start_offset
;
1776 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen
);
1777 dump_binary(hlpstr_maxlen
);
1779 offset
= saved_offset
;
1782 printf("helpstring offset = ffffh\n");
1784 args_off
= tlb_read_short();
1787 printf("args off = %#x (+%#x=%#x)\n",
1788 args_off
, funcs_start_offset
, args_off
+ funcs_start_offset
);
1790 printf("args off = ffffh\n");
1791 flags
= tlb_read_byte();
1792 n_params
= flags
>> 3;
1794 printf("callconv %u, cParams %u\n", flags
& 0x7, n_params
);
1796 flags
= tlb_read_byte();
1798 printf("retnextop %02x, cParamsOpt %u\n", flags
, (flags
& 0x7e) >> 1);
1800 value
= print_short_hex("rettype");
1801 if (!(flags
& 0x80))
1804 printf("rettype offset = %#x (+%#x=%#x)\n",
1805 value
, funcs_start_offset
, value
+ funcs_start_offset
);
1807 printf("rettype:\n");
1808 sltg_print_compound_type(funcs_start_offset
, value
);
1813 printf("rettype:\n");
1814 sltg_print_simple_type(value
);
1817 print_short_hex("vtblpos");
1819 print_short_hex("funcflags");
1823 offset
= args_off
+ funcs_start_offset
;
1825 printf("arguments start at %#x\n", offset
);
1828 for (j
= 0; j
< n_params
; j
++)
1831 unsigned short name_offset
;
1833 sprintf(name
, "arg %d", j
);
1834 print_begin_block(name
);
1836 name_offset
= tlb_read_short();
1838 printf("name: %04xh\n", name_offset
);
1840 value
= tlb_read_short();
1842 printf("type/offset %04xh\n", value
);
1843 if (name_offset
& 1) /* type follows */
1846 printf("type follows, using current offset for type\n");
1848 value
= offset
- funcs_start_offset
;
1852 printf("arg[%d] off = %#x (+%#x=%#x)\n",
1853 j
, value
, funcs_start_offset
, value
+ funcs_start_offset
);
1856 value
= sltg_print_compound_type(funcs_start_offset
, value
);
1857 if (name_offset
& 1)
1866 printf("arguments end at %#x\n", offset
);
1871 if (offset
!= funcs_start_offset
+ next
)
1872 dump_binary(funcs_start_offset
+ next
- offset
);
1880 printf("skipping %#x bytes\n", extra
);
1884 if (offset
< member_offset
+ sizeof(struct sltg_member_header
) + mem
->extra
)
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
);
1892 printf("dumped %d (%#x) bytes\n", offset
- typeinfo_start_offset
, offset
- typeinfo_start_offset
);
1893 len
-= offset
- typeinfo_start_offset
;
1895 printf("sltg_tail %d (%#x) bytes:\n", len
, len
);
1896 saved_offset
= offset
;
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
));
1942 index
= tlb_read(size_of_index
);
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();
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)
1984 saved_offset
= offset
;
1986 sprintf(name
, "Block %d", i
);
1987 print_begin_block(name
);
1988 magic
= tlb_read_short();
1989 assert(magic
== 0x0501);
1991 dump_binary(entry
[i
].len
);
1994 offset
= saved_offset
;
1996 print_begin_block(name
);
1997 dump_type(entry
[i
].len
, hlp_strings
);
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");
2011 typeinfo_cnt
= print_short_dec("typeinfo count");
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));
2025 len
= print_short_hex("name table jump");
2028 printf("skipping 0x000a bytes\n");
2029 dump_binary(0x000a);
2032 else if (len
== 0x0200)
2034 printf("skipping 0x002a bytes\n");
2035 dump_binary(0x002a);
2040 printf("FIXME: please report! (%#x)\n", len
);
2044 printf("skipping 0x200 bytes\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
)
2061 len
= offset
- name_table_start
;
2062 aligned_len
= (len
+ 0x1f) & ~0x1f;
2063 if (aligned_len
- len
< 4)
2064 dump_binary(aligned_len
- len
);
2066 dump_binary(len
& 1);
2070 print_hex("01ffff01");
2071 len
= print_hex("length");
2072 printf("skipping %#x bytes\n", len
);
2076 len
= (libblk_start
+ libblk_len
) - offset
;
2077 printf("skipping libblk remainder %#x bytes\n", len
);
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");
2090 printf("skipping 12 bytes\n");
2097 /* 0x0008,"TYPELIB",0 */
2101 printf("skipping 12 bytes\n");
2105 printf("skipping remainder 0x10 bytes\n");
2112 const DWORD
*sig
= PRD(0, sizeof(DWORD
));
2113 if (*sig
== MSFT_MAGIC
)
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
;