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 const char *dump_prefix
= "";
145 static const char * const tkind
[TKIND_MAX
] = {
146 "TKIND_ENUM", "TKIND_RECORD", "TKIND_MODULE",
147 "TKIND_INTERFACE", "TKIND_DISPATCH", "TKIND_COCLASS",
148 "TKIND_ALIAS", "TKIND_UNION"
151 static const void *tlb_read(int size
) {
152 const void *ret
= PRD(offset
, size
);
162 static int tlb_read_int(void)
164 const int *ret
= tlb_read(sizeof(int));
165 return ret
? *ret
: -1;
168 static int tlb_read_short(void)
170 const unsigned short *ret
= tlb_read(sizeof(short));
171 return ret
? *ret
: -1;
174 static int tlb_read_byte(void)
176 const unsigned char *ret
= tlb_read(sizeof(char));
177 return ret
? *ret
: -1;
180 static void print_offset(void)
183 printf("%s", dump_prefix
);
184 for(i
=0; i
<indent
; i
++)
188 static void print_begin_block(const char *name
)
191 printf("%s {\n", name
);
195 static void print_begin_block_id(const char *name
, int id
)
198 sprintf(buf
, "%s %d", name
, id
);
199 print_begin_block(buf
);
202 static void print_end_block(void)
209 static int print_byte(const char *name
)
213 printf("%s = %02xh\n", name
, ret
=tlb_read_byte());
217 static int print_hex(const char *name
)
221 printf("%s = %08xh\n", name
, ret
=tlb_read_int());
225 static int print_hex_id(const char *name
, int id
)
228 sprintf(buf
, name
, id
);
229 return print_hex(buf
);
232 static int print_short_hex(const char *name
)
236 printf("%s = %04xh\n", name
, ret
=tlb_read_short());
240 static int print_short_dec(const char *name
)
244 printf("%s = %d\n", name
, ret
=tlb_read_short());
248 static int print_dec(const char *name
)
252 printf("%s = %d\n", name
, ret
=tlb_read_int());
256 static void print_guid(const char *name
)
258 GUID guid
= *(const GUID
*)tlb_read(sizeof(guid
));
262 printf("%s = {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", name
,
263 (unsigned int)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
]);
284 printf("unk %d\n", vartype
);
287 static void print_ctl2(const char *name
)
294 len
= tlb_read_short();
296 printf("%s = %d \"", name
, len
);
299 fwrite(buf
, len
, 1, stdout
);
304 printf("\\%02x", tlb_read_byte());
308 static void dump_binary(int size
)
310 const unsigned char *ptr
;
315 ptr
= tlb_read(size
);
318 prefix
= malloc( strlen(dump_prefix
) + 4 * indent
+ 1 );
319 strcpy( prefix
, dump_prefix
);
320 for (i
= 0; i
< indent
; i
++) strcat( prefix
, " " );
321 dump_data_offset( ptr
, size
, offset
, prefix
);
325 static int dump_msft_varflags(void)
327 static const char *syskind
[] = {
328 "SYS_WIN16", "SYS_WIN32", "SYS_MAC", "SYS_WIN64", "unknown"
333 flags
= tlb_read_int();
335 if (kind
> 3) kind
= 4;
336 printf("varflags = %08x, syskind = %s\n", flags
, syskind
[kind
]);
340 static void dump_msft_version(void)
344 version
= tlb_read_int();
345 printf("version = %u.%u\n", version
& 0xffff, version
>> 16);
348 static void dump_msft_header(void)
350 print_begin_block("Header");
354 print_hex("posguid");
357 header_flags
= dump_msft_varflags();
360 typeinfo_cnt
= print_dec("ntypeinfos");
361 print_dec("helpstring");
362 print_dec("helpstringcontext");
363 print_dec("helpcontext");
364 print_dec("nametablecount");
365 print_dec("nametablechars");
366 print_hex("NameOffset");
367 print_hex("helpfile");
368 print_hex("CustomDataOffset");
371 print_hex("dispatchpos");
377 static int dump_msft_typekind(void)
382 ret
= tlb_read_int();
383 typekind
= ret
& 0xf;
384 printf("typekind = %s, align = %d\n", typekind
< TKIND_MAX
? tkind
[typekind
] : "unknown", (ret
>> 11) & 0x1f);
388 static void dump_msft_typeinfobase(void)
390 print_begin_block_id("TypeInfoBase", msft_typeinfo_cnt
);
392 msft_typeinfo_kind
[msft_typeinfo_cnt
] = dump_msft_typekind();
393 msft_typeinfo_offs
[msft_typeinfo_cnt
] = print_hex("memoffset");
398 msft_typeinfo_elemcnt
[msft_typeinfo_cnt
] = print_hex("cElement");
403 print_hex("posguid");
405 print_hex("NameOffset");
406 print_hex("version");
407 print_hex("docstringoffs");
408 print_hex("docstringcontext");
409 print_hex("helpcontext");
410 print_hex("oCustData");
411 msft_typeinfo_impltypes
[msft_typeinfo_cnt
++] = print_short_hex("cImplTypes");
412 print_short_hex("bSizeVftt");
414 print_hex("datatype1");
415 print_hex("datatype2");
422 static BOOL
dump_msft_typeinfobases(seg_t
*seg
)
424 while (offset
< seg
->offset
+seg
->length
)
425 dump_msft_typeinfobase();
427 assert(offset
== seg
->offset
+seg
->length
);
431 static void dump_msft_impinfo(int n
)
433 print_begin_block_id("ImpInfo", n
);
436 print_hex("oImpInfo");
442 static BOOL
dump_msft_impinfos(seg_t
*seg
)
446 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
447 dump_msft_impinfo(i
);
449 assert(offset
== seg
->offset
+seg
->length
);
453 static void dump_msft_impfile(int n
)
455 print_begin_block_id("ImpFile", n
);
459 print_hex("version");
460 print_ctl2("impfile");
465 static BOOL
dump_msft_impfiles(seg_t
*seg
)
469 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
470 dump_msft_impfile(i
);
472 assert(offset
== seg
->offset
+seg
->length
);
476 static BOOL
dump_msft_reftabs(seg_t
*seg
)
478 print_begin_block("RefTab");
480 dump_binary(seg
->length
); /* FIXME */
487 static BOOL
dump_msft_guidhashtab(seg_t
*seg
)
489 print_begin_block("GuidHashTab");
491 dump_binary(seg
->length
); /* FIXME */
495 assert(offset
== seg
->offset
+seg
->length
);
499 static void dump_msft_guidentry(int n
)
501 print_begin_block_id("GuidEntry", n
);
504 print_hex("hreftype");
505 print_hex("next_hash");
510 static BOOL
dump_msft_guidtab(seg_t
*seg
)
514 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
515 dump_msft_guidentry(i
);
517 assert(offset
== seg
->offset
+seg
->length
);
521 static BOOL
dump_msft_namehashtab(seg_t
*seg
)
523 print_begin_block("NameHashTab");
525 dump_binary(seg
->length
); /* FIXME */
531 static void print_string0(void)
536 while ((c
= tlb_read_byte()) != 0)
539 fwrite(&c
, 1, 1, stdout
);
543 sprintf(buf
, "\\%u", c
);
544 fwrite(buf
, 1, strlen(buf
), stdout
);
550 static void print_string(int len
)
553 fwrite(tlb_read(len
), len
, 1, stdout
);
557 static void dump_string(int len
, int align_off
)
561 while((len
++ + align_off
) & 3)
562 printf("\\%2.2x", tlb_read_byte());
565 static void dump_msft_name(int base
, int n
)
569 print_begin_block_id("Name", n
);
571 print_hex("hreftype");
572 print_hex("next_hash");
573 len
= print_hex("namelen")&0xff;
583 static BOOL
dump_msft_nametab(seg_t
*seg
)
585 int i
, base
= offset
;
587 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
588 dump_msft_name(base
, i
);
590 assert(offset
== seg
->offset
+seg
->length
);
594 static void dump_msft_string(int n
)
598 print_begin_block_id("String", n
);
600 len
= print_short_hex("stringlen");
607 for(len
= 0; len
< 4; len
++)
608 printf("\\%2.2x", tlb_read_byte());
615 static BOOL
dump_msft_stringtab(seg_t
*seg
)
619 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
622 assert(offset
== seg
->offset
+seg
->length
);
626 static void dump_msft_typedesc(int n
)
628 print_begin_block_id("TYPEDESC", n
);
630 print_hex("hreftype");
636 static BOOL
dump_msft_typedesctab(seg_t
*seg
)
640 print_begin_block("TypedescTab");
642 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
643 dump_msft_typedesc(i
);
647 assert(offset
== seg
->offset
+seg
->length
);
651 static BOOL
dump_msft_arraydescs(seg_t
*seg
)
653 print_begin_block("ArrayDescriptions");
655 dump_binary(seg
->length
); /* FIXME */
661 static BOOL
dump_msft_custdata(seg_t
*seg
)
666 print_begin_block("CustData");
668 while (offset
< seg
->offset
+seg
->length
)
672 vt
= tlb_read_short();
678 printf(" len %d: ", n
);
684 printf("\\%2.2x ", tlb_read_byte());
685 printf("\\%2.2x\n", tlb_read_byte());
693 static void dump_msft_cdguid(int n
)
695 print_begin_block_id("CGUid", n
);
697 print_hex("GuidOffset");
698 print_hex("DataOffset");
704 static BOOL
dump_msft_cdguids(seg_t
*seg
)
708 for(i
= 0; offset
< seg
->offset
+seg
->length
; i
++)
711 assert(offset
== seg
->offset
+seg
->length
);
715 static BOOL
dump_msft_res0e(seg_t
*seg
)
717 print_begin_block("res0e");
718 dump_binary(seg
->length
);
724 static BOOL
dump_msft_res0f(seg_t
*seg
)
726 print_begin_block("res0f");
727 dump_binary(seg
->length
);
733 /* Used for function return value and arguments type */
734 static void dump_msft_datatype(const char *name
)
739 datatype
= tlb_read_int();
740 printf("%s = %08x", name
, datatype
);
743 print_vartype(datatype
);
748 if (datatype
> segdir
[SEGDIR_TYPEDESC
].length
) {
749 printf(", invalid offset\n");
753 /* FIXME: in case of VT_USERDEFINED use hreftype */
754 vt
= PRD(segdir
[SEGDIR_TYPEDESC
].offset
+ datatype
, 4*sizeof(short));
755 datatype
= vt
[0] & VT_TYPEMASK
;
756 if (datatype
== VT_PTR
) {
757 printf(", VT_PTR -> ");
761 vt
= PRD(segdir
[SEGDIR_TYPEDESC
].offset
+ vt
[2], 4*sizeof(short));
770 print_vartype(datatype
);
774 static void dump_defaultvalue(int id
)
779 offset
= tlb_read_int();
781 printf("default value[%d] = %08x", id
, offset
);
784 else if (offset
< 0) {
786 print_vartype((offset
& 0x7c000000) >> 26);
789 const unsigned short *vt
;
791 if (offset
> segdir
[SEGDIR_CUSTDATA
].length
) {
792 printf(", invalid offset\n");
796 vt
= PRD(segdir
[SEGDIR_CUSTDATA
].offset
+ offset
, sizeof(*vt
));
802 static void dump_msft_func(int n
)
804 int size
, args_cnt
, i
, extra_attr
, fkccic
;
806 print_begin_block_id("FuncRecord", n
);
808 size
= print_short_hex("size");
809 print_short_hex("index");
810 dump_msft_datatype("retval type");
812 print_short_hex("VtableOffset");
813 print_short_hex("funcdescsize");
814 fkccic
= print_hex("FKCCIC");
815 args_cnt
= print_short_hex("nrargs");
816 print_short_hex("noptargs");
818 extra_attr
= size
/sizeof(INT
) - 6 - args_cnt
*(fkccic
&0x1000 ? 4 : 3);
821 print_hex("helpcontext");
823 print_hex("oHelpString");
825 print_hex("toEntry");
831 print_hex("HelpStringContext");
833 print_hex("oCustData");
834 for(i
= 0; i
< extra_attr
-7; i
++)
835 print_hex_id("oArgCustData", i
);
837 if(fkccic
& 0x1000) {
838 for(i
=0; i
< args_cnt
; i
++)
839 dump_defaultvalue(i
);
842 for(i
=0; i
< args_cnt
; i
++) {
843 print_begin_block_id("param", i
);
845 /* FIXME: Handle default values */
846 dump_msft_datatype("datatype");
848 print_hex("paramflags");
856 static void dump_msft_var(int n
)
860 print_begin_block_id("VarRecord", n
);
862 size
= print_hex("recsize")&0x1ff;
863 print_hex("DataType");
865 print_short_hex("VarKind");
866 print_short_hex("vardescsize");
867 print_hex("OffsValue");
869 if(size
> 5*sizeof(INT
))
870 dump_binary(size
- 5*sizeof(INT
));
875 static void dump_msft_ref(int n
)
877 print_begin_block_id("RefRecord", n
);
879 print_hex("reftype");
881 print_hex("oCustData");
887 static void dump_msft_coclass(int n
)
893 for(i
=0; i
< msft_typeinfo_impltypes
[n
]; i
++)
897 static BOOL
dump_msft_typeinfo(int n
)
901 print_begin_block_id("TypeInfo", n
);
903 if((msft_typeinfo_kind
[n
] & 0xf) == TKIND_COCLASS
) {
904 dump_msft_coclass(n
);
911 for(i
= 0; i
< LOWORD(msft_typeinfo_elemcnt
[n
]); i
++)
914 for(i
= 0; i
< HIWORD(msft_typeinfo_elemcnt
[n
]); i
++)
917 for(i
= 0; i
< LOWORD(msft_typeinfo_elemcnt
[n
]); i
++)
918 print_hex_id("func %d id", i
);
920 for(i
= 0; i
< HIWORD(msft_typeinfo_elemcnt
[n
]); i
++)
921 print_hex_id("var %d id", i
);
923 for(i
= 0; i
< LOWORD(msft_typeinfo_elemcnt
[n
]); i
++)
924 print_hex_id("func %d name", i
);
926 for(i
= 0; i
< HIWORD(msft_typeinfo_elemcnt
[n
]); i
++)
927 print_hex_id("var %d name", i
);
929 for(i
= 0; i
< LOWORD(msft_typeinfo_elemcnt
[n
]); i
++)
930 print_hex_id("func %d offset", i
);
932 for(i
= 0; i
< HIWORD(msft_typeinfo_elemcnt
[n
]); i
++)
933 print_hex_id("var %d offset", i
);
940 static seg_t segdir
[] = {
941 {"TypeInfoTab", dump_msft_typeinfobases
, -1, -1},
942 {"ImpInfo", dump_msft_impinfos
, -1, -1},
943 {"ImpFiles", dump_msft_impfiles
, -1, -1},
944 {"RefTab", dump_msft_reftabs
, -1, -1},
945 {"GuidHashTab", dump_msft_guidhashtab
, -1, -1},
946 {"GuidTab", dump_msft_guidtab
, -1, -1},
947 {"NameHashTab", dump_msft_namehashtab
, -1, -1},
948 {"pNameTab", dump_msft_nametab
, -1, -1},
949 {"pStringTab", dump_msft_stringtab
, -1, -1},
950 {"TypedescTab", dump_msft_typedesctab
, -1, -1},
951 {"ArrayDescriptions", dump_msft_arraydescs
, -1, -1},
952 {"CustData", dump_msft_custdata
, -1, -1},
953 {"CDGuid", dump_msft_cdguids
, -1, -1},
954 {"res0e", dump_msft_res0e
, -1, -1},
955 {"res0f", dump_msft_res0f
, -1, -1}
958 static void dump_msft_seg(seg_t
*seg
)
960 print_begin_block(seg
->name
);
962 seg
->offset
= print_hex("offset");
963 seg
->length
= print_dec("length");
970 static void dump_msft_segdir(void)
974 print_begin_block("SegDir");
976 for(i
=0; i
< ARRAY_SIZE(segdir
); i
++)
977 dump_msft_seg(segdir
+i
);
982 static BOOL
dump_offset(void)
986 for(i
=0; i
< ARRAY_SIZE(segdir
); i
++)
987 if(segdir
[i
].offset
== offset
)
988 return segdir
[i
].func(segdir
+i
);
990 for(i
=0; i
< msft_typeinfo_cnt
; i
++)
991 if(msft_typeinfo_offs
[i
] == offset
)
992 return dump_msft_typeinfo(i
);
997 static void msft_dump(void)
1003 for(i
=0; i
< typeinfo_cnt
; i
++)
1004 print_hex_id("typeinfo %d offset", i
);
1006 if(header_flags
& HELPDLLFLAG
)
1007 print_hex("help dll offset");
1015 print_hex("unknown");
1019 /****************************** SLTG Typelibs ******************************/
1035 #include "pshpack1.h"
1036 struct sltg_typeinfo_header
1047 unsigned unknown1
: 3;
1048 unsigned flags
: 16;
1049 unsigned unknown2
: 5;
1050 unsigned typekind
: 8;
1055 struct sltg_member_header
1065 unsigned short cFuncs
;
1066 unsigned short cVars
;
1067 unsigned short cImplTypes
;
1068 unsigned short res06
; /* always 0000 */
1069 unsigned short funcs_off
; /* offset to functions (starting from the member header) */
1070 unsigned short vars_off
; /* offset to vars (starting from the member header) */
1071 unsigned short impls_off
; /* offset to implemented types (starting from the member header) */
1072 unsigned short funcs_bytes
; /* bytes used by function data */
1073 unsigned short vars_bytes
; /* bytes used by var data */
1074 unsigned short impls_bytes
; /* bytes used by implemented type data */
1075 unsigned short tdescalias_vt
; /* for TKIND_ALIAS */
1076 unsigned short res16
; /* always ffff */
1077 unsigned short res18
; /* always 0000 */
1078 unsigned short res1a
; /* always 0000 */
1079 unsigned short simple_alias
; /* tdescalias_vt is a vt rather than an offset? */
1080 unsigned short res1e
; /* always 0000 */
1081 unsigned short cbSizeInstance
;
1082 unsigned short cbAlignment
;
1083 unsigned short res24
;
1084 unsigned short res26
;
1085 unsigned short cbSizeVft
;
1086 unsigned short res2a
; /* always ffff */
1087 unsigned short res2c
; /* always ffff */
1088 unsigned short res2e
; /* always ffff */
1089 unsigned short res30
; /* always ffff */
1090 unsigned short res32
;
1091 unsigned short res34
;
1094 struct sltg_variable
1096 char magic
; /* 0x0a */
1100 short byte_offs
; /* pos in struct, or offset to const type or const data (if flags & 0x08) */
1101 short type
; /* if flags & 0x02 this is the type, else offset to type */
1103 short helpcontext
; /* ?? */
1104 short helpstring
; /* ?? */
1106 short varflags
; /* only present if magic & 0x20 */
1109 #include "poppack.h"
1111 static const char *lookup_code(const BYTE
*table
, DWORD table_size
, struct bitstream
*bits
)
1113 const BYTE
*p
= table
;
1115 while (p
< table
+ table_size
&& *p
== 0x80)
1117 if (p
+ 2 >= table
+ table_size
) return NULL
;
1119 if (!(bits
->current
& 0xff))
1121 if (!bits
->length
) return NULL
;
1122 bits
->current
= (*bits
->buffer
<< 8) | 1;
1127 if (bits
->current
& 0x8000)
1133 p
= table
+ (*(p
+ 2) | (*(p
+ 1) << 8));
1136 bits
->current
<<= 1;
1139 if (p
+ 1 < table
+ table_size
&& *(p
+ 1))
1141 /* FIXME: What is the meaning of *p? */
1142 const BYTE
*q
= p
+ 1;
1143 while (q
< table
+ table_size
&& *q
) q
++;
1144 return (q
< table
+ table_size
) ? (const char *)(p
+ 1) : NULL
;
1150 static const char *decode_string(const BYTE
*table
, const char *stream
, UINT stream_length
, UINT
*read_bytes
)
1153 DWORD buf_size
, table_size
;
1155 struct bitstream bits
;
1157 bits
.buffer
= (const BYTE
*)stream
;
1158 bits
.length
= stream_length
;
1161 buf_size
= *(const WORD
*)table
;
1162 table
+= sizeof(WORD
);
1163 table_size
= *(const DWORD
*)table
;
1164 table
+= sizeof(DWORD
);
1166 buf
= xmalloc(buf_size
);
1169 while ((p
= lookup_code(table
, table_size
, &bits
)))
1171 if (buf
[0]) strcat(buf
, " ");
1172 assert(strlen(buf
) + strlen(p
) + 1 <= buf_size
);
1176 if (read_bytes
) *read_bytes
= stream_length
- bits
.length
;
1181 static void print_sltg_name(const char *name
)
1183 unsigned short len
= tlb_read_short();
1185 printf("%s = %#x (", name
, len
);
1186 if (len
!= 0xffff) print_string(len
);
1190 static int dump_sltg_header(int *sltg_first_blk
, int *size_of_index
, int *size_of_pad
)
1194 print_begin_block("Header");
1197 n_file_blocks
= print_short_dec("# file blocks");
1198 *size_of_pad
= print_short_hex("pad");
1199 *size_of_index
= print_short_hex("size of index");
1200 *sltg_first_blk
= print_short_dec("first block");
1207 return n_file_blocks
;
1210 static void dump_sltg_index(int count
)
1224 for (i
= 0; i
< count
- 2; i
++)
1234 static void dump_sltg_pad(int size_of_pad
)
1238 dump_binary(size_of_pad
);
1243 static void dump_sltg_block_entry(int idx
, const char *index
)
1248 sprintf(name
, "Block entry %d", idx
);
1249 print_begin_block(name
);
1252 index_offset
= tlb_read_short();
1254 printf("index string = %xh \"%s\"\n", index_offset
, index
+ index_offset
);
1255 print_short_hex("next");
1260 static void dump_sltg_library_block(void)
1262 print_begin_block("Library block entry");
1264 print_short_hex("magic");
1265 print_short_hex("res02");
1266 print_sltg_name("name");
1267 print_short_hex("res06");
1268 print_sltg_name("helpstring");
1269 print_sltg_name("helpfile");
1270 print_hex("helpcontext");
1271 print_short_hex("syskind");
1272 print_short_hex("lcid");
1274 print_short_hex("libflags");
1275 dump_msft_version();
1281 static void skip_sltg_library_block(void)
1283 unsigned short skip
;
1287 skip
= tlb_read_short();
1288 if (skip
!= 0xffff) tlb_read(skip
);
1290 skip
= tlb_read_short();
1291 if (skip
!= 0xffff) tlb_read(skip
);
1292 skip
= tlb_read_short();
1293 if (skip
!= 0xffff) tlb_read(skip
);
1300 tlb_read(sizeof(GUID
));
1303 static void dump_sltg_other_typeinfo(int idx
, const char *hlp_strings
)
1305 int hlpstr_len
, saved_offset
;
1308 sprintf(name
, "Other typeinfo %d", idx
);
1309 print_begin_block(name
);
1311 print_sltg_name("index name");
1312 print_sltg_name("other name");
1313 print_short_hex("res1a");
1314 print_short_hex("name offset");
1317 hlpstr_len
= tlb_read_short();
1322 saved_offset
= offset
;
1323 str
= tlb_read(hlpstr_len
);
1324 str
= decode_string((const BYTE
*)hlp_strings
, str
, hlpstr_len
, NULL
);
1325 printf("helpstring: \"%s\"\n", str
);
1327 offset
= saved_offset
;
1329 printf("helpstring encoded bits: %d bytes\n", hlpstr_len
);
1330 dump_binary(hlpstr_len
);
1333 printf("helpstring: \"\"\n");
1335 print_short_hex("res20");
1336 print_hex("helpcontext");
1337 print_short_hex("res26");
1339 print_short_dec("typekind");
1344 static void skip_sltg_other_typeinfo(void)
1346 unsigned short skip
;
1348 skip
= tlb_read_short();
1349 if (skip
!= 0xffff) tlb_read(skip
);
1350 skip
= tlb_read_short();
1351 if (skip
!= 0xffff) tlb_read(skip
);
1354 skip
= tlb_read_short();
1355 if (skip
) tlb_read(skip
);
1359 tlb_read(sizeof(GUID
));
1363 static void sltg_print_simple_type(short type
)
1366 if ((type
& 0x0f00) == 0x0e00)
1368 printf("%04x | (%d)\n", type
& 0xff80, type
& 0x7f);
1371 static void dump_safe_array(int array_offset
)
1373 int i
, cDims
, saved_offset
= offset
;
1375 offset
= array_offset
;
1378 printf("safe array starts at %#x\n", offset
);
1380 cDims
= print_short_dec("cDims");
1381 print_short_hex("fFeatures");
1382 print_dec("cbElements");
1383 print_dec("cLocks");
1384 print_hex("pvData");
1386 for (i
= 0; i
< cDims
; i
++)
1387 dump_binary(8); /* sizeof(SAFEARRAYBOUND) */
1390 printf("safe array ends at %#x\n", offset
);
1391 offset
= saved_offset
;
1394 static int sltg_print_compound_type(int vars_start_offset
, int type_offset
)
1397 int type_bytes
, saved_offset
= offset
;
1399 offset
= vars_start_offset
+ type_offset
;
1401 printf("type description starts at %#x\n", offset
);
1407 type
= tlb_read_short();
1413 printf("%04x | VT_PTR\n", type
& 0xff80);
1415 } while (vt
== VT_PTR
);
1417 if (vt
== VT_USERDEFINED
)
1419 short href
= tlb_read_short();
1421 if ((type
& 0x0f00) == 0x0e00)
1423 printf("%04x | VT_USERDEFINED (href %d)\n", type
& 0xff80, href
);
1426 else if (vt
== VT_CARRAY
)
1430 off
= tlb_read_short();
1432 printf("VT_CARRAY: offset %#x (+%#x=%#x)\n",
1433 off
, vars_start_offset
, off
+ vars_start_offset
);
1434 dump_safe_array(vars_start_offset
+ off
);
1436 /* type description follows */
1438 printf("array element type:\n");
1441 else if (vt
== VT_SAFEARRAY
)
1445 off
= tlb_read_short();
1447 printf("VT_SAFEARRAY: offset %#x (+%#x=%#x)\n",
1448 off
, vars_start_offset
, off
+ vars_start_offset
);
1449 dump_safe_array(vars_start_offset
+ off
);
1454 sltg_print_simple_type(type
);
1460 printf("type description ends at %#x\n", offset
);
1461 type_bytes
= offset
- saved_offset
;
1462 offset
= saved_offset
;
1467 static void dump_type(int len
, const char *hlp_strings
)
1473 unsigned unknown1
: 3;
1474 unsigned flags
: 13;
1475 unsigned unknown2
: 8;
1476 unsigned typekind
: 8;
1480 int typeinfo_start_offset
, extra
, member_offset
, href_offset
, i
;
1483 const struct sltg_typeinfo_header
*ti
;
1484 const struct sltg_member_header
*mem
;
1485 const struct sltg_tail
*tail
;
1487 typeinfo_start_offset
= offset
;
1488 block
= tlb_read(len
);
1489 offset
= typeinfo_start_offset
;
1492 mem
= (const struct sltg_member_header
*)((char *)block
+ ti
->elem_table
);
1493 tail
= (const struct sltg_tail
*)((char *)(mem
+ 1) + mem
->extra
);
1495 typeinfo_start_offset
= offset
;
1497 print_short_hex("magic");
1498 href_offset
= tlb_read_int();
1500 if (href_offset
!= -1)
1501 printf("href offset = %#x (+%#x=%#x)\n",
1502 href_offset
, typeinfo_start_offset
, href_offset
+ typeinfo_start_offset
);
1504 printf("href offset = ffffffffh\n");
1506 member_offset
= tlb_read_int();
1508 printf("member offset = %#x (+%#x=%#x)\n",
1509 member_offset
, typeinfo_start_offset
, member_offset
+ typeinfo_start_offset
);
1511 print_hex("version");
1513 misc
.flags
= print_hex("misc");
1515 printf("misc: unknown1 %02x, flags %04x, unknown2 %02x, typekind %u (%s)\n",
1516 misc
.s
.unknown1
, misc
.s
.flags
, misc
.s
.unknown2
, misc
.s
.typekind
,
1517 misc
.s
.typekind
< TKIND_MAX
? tkind
[misc
.s
.typekind
] : "unknown");
1520 if (href_offset
!= -1)
1524 print_begin_block("href_table");
1526 print_short_hex("magic");
1543 print_short_hex("res42");
1544 number
= print_hex("number");
1546 for (i
= 0; i
< number
; i
+= 8)
1549 print_short_hex("res50");
1550 print_byte("res52");
1553 for (i
= 0; i
< number
/8; i
++)
1554 print_sltg_name("name");
1556 print_byte("resxx");
1562 printf("member_header starts at %#x, current offset = %#x\n", typeinfo_start_offset
+ member_offset
, offset
);
1563 member_offset
= offset
;
1564 print_short_hex("res00");
1565 print_short_hex("res02");
1566 print_byte("res04");
1567 extra
= print_hex("extra");
1569 if (misc
.s
.typekind
== TKIND_RECORD
|| misc
.s
.typekind
== TKIND_ENUM
)
1571 int vars_start_offset
= offset
;
1573 for (i
= 0; i
< tail
->cVars
; i
++)
1580 sprintf(name
, "variable %d", i
);
1581 print_begin_block(name
);
1584 dump_binary(sizeof(struct sltg_variable
));
1587 magic
= print_byte("magic");
1588 flags
= print_byte("flags");
1589 next
= tlb_read_short();
1592 printf("next offset = %#x (+%#x=%#x)\n",
1593 next
, vars_start_offset
, next
+ vars_start_offset
);
1595 printf("next offset = ffffh\n");
1596 print_short_hex("name");
1599 print_short_hex("dispatch");
1600 else if (flags
& 0x10)
1603 print_short_hex("const value");
1606 value
= tlb_read_short();
1608 printf("byte offset = %#x (+%#x=%#x)\n",
1609 value
, vars_start_offset
, value
+ vars_start_offset
);
1613 print_short_hex("oInst");
1615 value
= tlb_read_short();
1616 if (!(flags
& 0x02))
1619 printf("type offset = %#x (+%#x=%#x)\n",
1620 value
, vars_start_offset
, value
+ vars_start_offset
);
1623 sltg_print_compound_type(vars_start_offset
, value
);
1629 sltg_print_simple_type(value
);
1633 print_short_hex("helpcontext");
1635 value
= tlb_read_short();
1642 printf("helpstring offset = %#x (+%#x=%#x)\n",
1643 value
, vars_start_offset
, value
+ vars_start_offset
);
1645 saved_offset
= offset
;
1647 offset
= value
+ vars_start_offset
;
1649 hlpstr_maxlen
= member_offset
+ sizeof(struct sltg_member_header
) + mem
->extra
- offset
;
1651 str
= tlb_read(hlpstr_maxlen
);
1652 str
= decode_string((const BYTE
*)hlp_strings
, str
, hlpstr_maxlen
, &hlpstr_maxlen
);
1654 printf("helpstring: \"%s\"\n", str
);
1656 offset
= value
+ vars_start_offset
;
1658 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen
);
1659 dump_binary(hlpstr_maxlen
);
1661 offset
= saved_offset
;
1664 printf("helpstring offset = ffffh\n");
1666 if (magic
& 0x20) print_short_hex("varflags");
1670 if (offset
!= vars_start_offset
+ next
)
1671 dump_binary(vars_start_offset
+ next
- offset
);
1677 else if (misc
.s
.typekind
== TKIND_INTERFACE
|| misc
.s
.typekind
== TKIND_COCLASS
)
1680 int funcs_start_offset
= offset
;
1682 for (i
= 0; i
< tail
->cImplTypes
; i
++)
1686 sprintf(name
, "impl.type %d (current offset %#x)", i
, offset
);
1687 print_begin_block(name
);
1689 print_short_hex("res00");
1690 next
= tlb_read_short();
1693 printf("next offset = %#x (+%#x=%#x)\n",
1694 next
, funcs_start_offset
, next
+ funcs_start_offset
);
1696 printf("next offset = ffffh\n");
1697 print_short_hex("res04");
1698 print_byte("impltypeflags");
1699 print_byte("res07");
1700 print_short_hex("res08");
1701 print_short_hex("ref");
1702 print_short_hex("res0c");
1703 print_short_hex("res0e");
1704 print_short_hex("res10");
1705 print_short_hex("res12");
1706 print_short_hex("pos in table");
1711 for (i
= 0; i
< tail
->cFuncs
; i
++)
1715 short args_off
, value
, n_params
, j
;
1717 sprintf(name
, "function %d (current offset %#x)", i
, offset
);
1718 print_begin_block(name
);
1720 magic
= print_byte("magic");
1721 flags
= tlb_read_byte();
1723 printf("invoke_kind = %u\n", flags
>> 4);
1724 next
= tlb_read_short();
1727 printf("next offset = %#x (+%#x=%#x)\n",
1728 next
, funcs_start_offset
, next
+ funcs_start_offset
);
1730 printf("next offset = ffffh\n");
1731 print_short_hex("name");
1732 print_hex("dispid");
1733 print_short_hex("helpcontext");
1735 value
= tlb_read_short();
1742 printf("helpstring offset = %#x (+%#x=%#x)\n",
1743 value
, funcs_start_offset
, value
+ funcs_start_offset
);
1745 saved_offset
= offset
;
1747 offset
= value
+ funcs_start_offset
;
1749 hlpstr_maxlen
= member_offset
+ sizeof(struct sltg_member_header
) + mem
->extra
- offset
;
1751 str
= tlb_read(hlpstr_maxlen
);
1752 str
= decode_string((const BYTE
*)hlp_strings
, str
, hlpstr_maxlen
, &hlpstr_maxlen
);
1754 printf("helpstring: \"%s\"\n", str
);
1756 offset
= value
+ funcs_start_offset
;
1758 printf("helpstring encoded bits: %d bytes\n", hlpstr_maxlen
);
1759 dump_binary(hlpstr_maxlen
);
1761 offset
= saved_offset
;
1764 printf("helpstring offset = ffffh\n");
1766 args_off
= tlb_read_short();
1769 printf("args off = %#x (+%#x=%#x)\n",
1770 args_off
, funcs_start_offset
, args_off
+ funcs_start_offset
);
1772 printf("args off = ffffh\n");
1773 flags
= tlb_read_byte();
1774 n_params
= flags
>> 3;
1776 printf("callconv %u, cParams %u\n", flags
& 0x7, n_params
);
1778 flags
= tlb_read_byte();
1780 printf("retnextop %02x, cParamsOpt %u\n", flags
, (flags
& 0x7e) >> 1);
1782 value
= print_short_hex("rettype");
1783 if (!(flags
& 0x80))
1786 printf("rettype offset = %#x (+%#x=%#x)\n",
1787 value
, funcs_start_offset
, value
+ funcs_start_offset
);
1789 printf("rettype:\n");
1790 sltg_print_compound_type(funcs_start_offset
, value
);
1795 printf("rettype:\n");
1796 sltg_print_simple_type(value
);
1799 print_short_hex("vtblpos");
1801 print_short_hex("funcflags");
1805 offset
= args_off
+ funcs_start_offset
;
1807 printf("arguments start at %#x\n", offset
);
1810 for (j
= 0; j
< n_params
; j
++)
1813 unsigned short name_offset
;
1815 sprintf(name
, "arg %d", j
);
1816 print_begin_block(name
);
1818 name_offset
= tlb_read_short();
1820 printf("name: %04xh\n", name_offset
);
1822 value
= tlb_read_short();
1824 printf("type/offset %04xh\n", value
);
1825 if (name_offset
& 1) /* type follows */
1828 printf("type follows, using current offset for type\n");
1830 value
= offset
- funcs_start_offset
;
1834 printf("arg[%d] off = %#x (+%#x=%#x)\n",
1835 j
, value
, funcs_start_offset
, value
+ funcs_start_offset
);
1838 value
= sltg_print_compound_type(funcs_start_offset
, value
);
1839 if (name_offset
& 1)
1848 printf("arguments end at %#x\n", offset
);
1853 if (offset
!= funcs_start_offset
+ next
)
1854 dump_binary(funcs_start_offset
+ next
- offset
);
1865 if (offset
< member_offset
+ sizeof(struct sltg_member_header
) + mem
->extra
)
1867 dump_binary(member_offset
+ sizeof(struct sltg_member_header
) + mem
->extra
- offset
);
1870 len
-= offset
- typeinfo_start_offset
;
1872 printf("sltg_tail %d (%#x) bytes:\n", len
, len
);
1873 saved_offset
= offset
;
1875 offset
= saved_offset
;
1876 print_short_hex("cFuncs");
1877 print_short_hex("cVars");
1878 print_short_hex("cImplTypes");
1879 print_short_hex("res06");
1880 print_short_hex("funcs_off");
1881 print_short_hex("vars_off");
1882 print_short_hex("impls_off");
1883 print_short_hex("funcs_bytes");
1884 print_short_hex("vars_bytes");
1885 print_short_hex("impls_bytes");
1886 print_short_hex("tdescalias_vt");
1887 print_short_hex("res16");
1888 print_short_hex("res18");
1889 print_short_hex("res1a");
1890 print_short_hex("simple_alias");
1891 print_short_hex("res1e");
1892 print_short_hex("cbSizeInstance");
1893 print_short_hex("cbAlignment");
1894 print_short_hex("res24");
1895 print_short_hex("res26");
1896 print_short_hex("cbSizeVft");
1897 print_short_hex("res2a");
1898 print_short_hex("res2c");
1899 print_short_hex("res2e");
1900 print_short_hex("res30");
1901 print_short_hex("res32");
1902 print_short_hex("res34");
1903 offset
= saved_offset
+ len
;
1906 static void sltg_dump(void)
1908 int i
, n_file_blocks
, n_first_blk
, size_of_index
, size_of_pad
;
1909 int name_table_start
, name_table_size
, saved_offset
;
1910 int libblk_start
, libblk_len
, hlpstr_len
, len
;
1911 const char *index
, *hlp_strings
;
1912 const struct block_entry
*entry
;
1914 n_file_blocks
= dump_sltg_header(&n_first_blk
, &size_of_index
, &size_of_pad
);
1916 saved_offset
= offset
;
1917 entry
= tlb_read((n_file_blocks
- 1) * sizeof(*entry
));
1919 index
= tlb_read(size_of_index
);
1921 offset
= saved_offset
;
1923 for (i
= 0; i
< n_file_blocks
- 1; i
++)
1924 dump_sltg_block_entry(i
, index
);
1926 saved_offset
= offset
;
1927 dump_sltg_index(n_file_blocks
);
1928 assert(offset
- saved_offset
== size_of_index
);
1930 dump_sltg_pad(size_of_pad
);
1932 /* read the helpstrings for later decoding */
1933 saved_offset
= offset
;
1935 for (i
= n_first_blk
- 1; entry
[i
].next
!= 0; i
= entry
[i
].next
- 1)
1936 tlb_read(entry
[i
].len
);
1938 libblk_start
= offset
;
1939 skip_sltg_library_block();
1941 typeinfo_cnt
= tlb_read_short();
1943 for (i
= 0; i
< typeinfo_cnt
; i
++)
1944 skip_sltg_other_typeinfo();
1946 len
= tlb_read_int();
1947 hlpstr_len
= (libblk_start
+ len
) - offset
;
1948 hlp_strings
= tlb_read(hlpstr_len
);
1949 assert(hlp_strings
!= NULL
);
1950 /* check the helpstrings header values */
1951 len
= *(int *)(hlp_strings
+ 2);
1952 assert(hlpstr_len
== len
+ 6);
1954 offset
= saved_offset
;
1956 for (i
= n_first_blk
- 1; entry
[i
].next
!= 0; i
= entry
[i
].next
- 1)
1961 saved_offset
= offset
;
1963 sprintf(name
, "Block %d", i
);
1964 print_begin_block(name
);
1965 magic
= tlb_read_short();
1966 assert(magic
== 0x0501);
1968 dump_binary(entry
[i
].len
);
1971 offset
= saved_offset
;
1973 print_begin_block(name
);
1974 dump_type(entry
[i
].len
, hlp_strings
);
1977 offset
= saved_offset
+ entry
[i
].len
;
1980 libblk_len
= entry
[i
].len
;
1982 libblk_start
= offset
;
1983 dump_sltg_library_block();
1989 typeinfo_cnt
= print_short_dec("typeinfo count");
1993 for (i
= 0; i
< typeinfo_cnt
; i
++)
1994 dump_sltg_other_typeinfo(i
, hlp_strings
);
1996 len
= print_hex("offset from start of library block to name table");
1998 printf("%#x + %#x = %#x\n", libblk_start
, len
, libblk_start
+ len
);
1999 len
= (libblk_start
+ len
) - offset
;
2001 printf("skipping %#x bytes (encoded/compressed helpstrings)\n", len
);
2003 printf("max string length: %#x, strings length %#x\n", *(short *)hlp_strings
, *(int *)(hlp_strings
+ 2));
2008 len
= print_short_hex("name table jump");
2011 dump_binary(0x000a);
2015 else if (len
== 0x0200)
2017 dump_binary(0x002a);
2023 printf("FIXME: please report! (%#x)\n", len
);
2031 name_table_size
= print_hex("name table size");
2033 name_table_start
= offset
;
2035 printf("name table offset = %#x\n", offset
);
2039 while (offset
< name_table_start
+ name_table_size
)
2048 len
= offset
- name_table_start
;
2049 aligned_len
= (len
+ 0x1f) & ~0x1f;
2050 if (aligned_len
- len
< 4)
2051 dump_binary(aligned_len
- len
);
2053 dump_binary(len
& 1);
2058 print_hex("01ffff01");
2059 len
= print_hex("length");
2064 len
= (libblk_start
+ libblk_len
) - offset
;
2066 printf("skipping libblk remainder %#x bytes\n", len
);
2071 /* FIXME: msodumper/olestream.py parses this block differently
2072 print_short_hex("unknown");
2073 print_short_hex("byte order mark");
2074 i = tlb_read_short();
2075 printf("version = %u.%u\n", i & 0xff, i >> 8);
2076 print_short_hex("system identifier");
2077 print_hex("unknown");
2081 printf("skipping 12 bytes\n");
2090 /* 0x0008,"TYPELIB",0 */
2096 printf("skipping 12 bytes\n");
2102 printf("skipping remainder 0x10 bytes\n");
2108 const DWORD
*sig
= PRD(0, sizeof(DWORD
));
2109 if (*sig
== MSFT_MAGIC
)
2115 void tlb_dump_resource( void *ptr
, size_t size
, const char *prefix
)
2117 void *prev_dump_base
= dump_base
;
2118 size_t prev_dump_total_len
= dump_total_len
;
2122 dump_total_len
= size
;
2123 dump_prefix
= prefix
;
2125 sig
= PRD(0, sizeof(DWORD
));
2126 if (*sig
== MSFT_MAGIC
)
2131 dump_base
= prev_dump_base
;
2132 dump_total_len
= prev_dump_total_len
;
2135 enum FileSig
get_kind_tlb(void)
2137 const DWORD
*sig
= PRD(0, sizeof(DWORD
));
2138 if (sig
&& (*sig
== MSFT_MAGIC
|| *sig
== SLTG_MAGIC
)) return SIG_TLB
;