tlb.c 21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/*
 *  Dump a typelib (tlb) file
 *
 *  Copyright 2006 Jacek Caban
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "config.h"
#include "wine/port.h"

#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "windef.h"

#include "winedump.h"

#define MSFT_MAGIC 0x5446534d
#define HELPDLLFLAG 0x0100

enum TYPEKIND {
  TKIND_ENUM = 0,
  TKIND_RECORD,
  TKIND_MODULE,
  TKIND_INTERFACE,
  TKIND_DISPATCH,
  TKIND_COCLASS,
  TKIND_ALIAS,
  TKIND_UNION,
  TKIND_MAX
};

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
enum VARENUM {
    VT_EMPTY = 0,
    VT_NULL = 1,
    VT_I2 = 2,
    VT_I4 = 3,
    VT_R4 = 4,
    VT_R8 = 5,
    VT_CY = 6,
    VT_DATE = 7,
    VT_BSTR = 8,
    VT_DISPATCH = 9,
    VT_ERROR = 10,
    VT_BOOL = 11,
    VT_VARIANT = 12,
    VT_UNKNOWN = 13,
    VT_DECIMAL = 14,
    VT_I1 = 16,
    VT_UI1 = 17,
    VT_UI2 = 18,
    VT_UI4 = 19,
    VT_I8 = 20,
    VT_UI8 = 21,
    VT_INT = 22,
    VT_UINT = 23,
    VT_VOID = 24,
    VT_HRESULT = 25,
    VT_PTR = 26,
    VT_SAFEARRAY = 27,
    VT_CARRAY = 28,
    VT_USERDEFINED = 29,
    VT_LPSTR = 30,
    VT_LPWSTR = 31,
    VT_RECORD = 36,
    VT_INT_PTR = 37,
    VT_UINT_PTR = 38,
    VT_FILETIME = 64,
    VT_BLOB = 65,
    VT_STREAM = 66,
    VT_STORAGE = 67,
    VT_STREAMED_OBJECT = 68,
    VT_STORED_OBJECT = 69,
    VT_BLOB_OBJECT = 70,
    VT_CF = 71,
    VT_CLSID = 72,
    VT_VERSIONED_STREAM = 73,
    VT_BSTR_BLOB = 0xfff,
    VT_VECTOR = 0x1000,
    VT_ARRAY = 0x2000,
    VT_BYREF = 0x4000,
    VT_RESERVED = 0x8000,
    VT_ILLEGAL = 0xffff,
    VT_ILLEGALMASKED = 0xfff,
    VT_TYPEMASK = 0xfff
};

102 103
struct seg_t;

104
typedef BOOL (*dump_seg_t)(struct seg_t*);
105 106 107 108 109 110 111

typedef struct seg_t {
    const char *name;
    dump_seg_t func;
    int offset;
    int length;
} seg_t;
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
static seg_t segdir[];

enum SEGDIRTYPE {
    SEGDIR_TYPEINFO,
    SEGDIR_IMPINFO,
    SEGDIR_IMPFILES,
    SEGDIR_REF,
    SEGDIR_GUIDHASH,
    SEGDIR_GUID,
    SEGDIR_NAMEHASH,
    SEGDIR_NAME,
    SEGDIR_STRING,
    SEGDIR_TYPEDESC,
    SEGDIR_ARRAYDESC,
    SEGDIR_CUSTDATA,
    SEGDIR_CDGUID,
    SEGDIR_res0e,
    SEGDIR_res0f
};
131 132 133 134 135

static int offset=0;
static int indent;
static int typeinfo_cnt;
static int header_flags = 0;
136
static BOOL msft_eof = FALSE;
137 138 139 140 141 142 143 144 145 146 147 148 149

static int msft_typeinfo_offs[1000];
static int msft_typeinfo_kind[1000];
static int msft_typeinfo_impltypes[1000];
static int msft_typeinfo_elemcnt[1000];
static int msft_typeinfo_cnt = 0;

static const void *tlb_read(int size) {
    const void *ret = PRD(offset, size);

    if(ret)
        offset += size;
    else
150
        msft_eof = TRUE;
151 152 153 154 155 156

    return ret;
}

static int tlb_read_int(void)
{
157
    const int *ret = tlb_read(sizeof(int));
158 159 160 161 162
    return ret ? *ret : -1;
}

static int tlb_read_short(void)
{
163
    const short *ret = tlb_read(sizeof(short));
164 165 166 167 168
    return ret ? *ret : -1;
}

static int tlb_read_byte(void)
{
169
    const unsigned char *ret = tlb_read(sizeof(char));
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
    return ret ? *ret : -1;
}

static void print_offset(void)
{
    int i;

    printf("%04x:   ", offset);

    for(i=0; i<indent; i++)
        printf("    ");
}

static void print_begin_block(const char *name)
{
    print_offset();
    printf("%s {\n", name);
    indent++;
}

static void print_begin_block_id(const char *name, int id)
{
    char buf[64];
    sprintf(buf, "%s %d", name, id);
    print_begin_block(buf);
}

static void print_end_block(void)
{
    indent--;
    print_offset();
    printf("}\n");
    print_offset();
    printf("\n");
}

static int print_hex(const char *name)
{
    int ret;
    print_offset();
    printf("%s = %08x\n", name, ret=tlb_read_int());
    return ret;
}

static int print_hex_id(const char *name, int id)
{
    char buf[64];
    sprintf(buf, name, id);
    return print_hex(buf);
}

static int print_short_hex(const char *name)
{
    int ret;
    print_offset();
    printf("%s = %xh\n", name, ret=tlb_read_short());
    return ret;
}

static int print_dec(const char *name)
{
    int ret;
    print_offset();
    printf("%s = %d\n", name, ret=tlb_read_int());
    return ret;
}

static void print_guid(const char *name)
{
    GUID guid = *(const GUID*)tlb_read(sizeof(guid));

    print_offset();

    printf("%s = {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n", name,
           guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
           guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4],
           guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
static void print_vartype(int vartype)
{
    static const char *vartypes[VT_LPWSTR+1] = {
      "VT_EMPTY",   "VT_NULL", "VT_I2",       "VT_I4",     "VT_R4",
      "VT_R8",      "VT_CY",   "VT_DATE",     "VT_BSTR",   "VT_DISPATCH",
      "VT_ERROR",   "VT_BOOL", "VT_VARIANT",  "VT_UNKNOWN","VT_DECIMAL",
      "unk 15",     "VT_I1",   "VT_UI1",      "VT_UI2",    "VT_UI4",
      "VT_I8",      "VT_UI8",  "VT_INT",      "VT_UINT",   "VT_VOID",
      "VT_HRESULT", "VT_PTR",  "VT_SAFEARRAY","VT_CARRAY", "VT_USERDEFINED",
      "VT_LPSTR",   "VT_LPWSTR"
    };

    vartype &= VT_TYPEMASK;
    if (vartype >= VT_EMPTY && vartype <= VT_LPWSTR)
        printf("%s\n", vartypes[vartype]);
    else
        printf("unk %d\n", vartype);
}

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
static void print_ctl2(const char *name)
{
    int len;
    const char *buf;

    print_offset();

    len = tlb_read_short();

    printf("%s = %d \"", name, len);
    len >>= 2;
    buf = tlb_read(len);
    fwrite(buf, len, 1, stdout);
    printf("\"");
    len += 2;

    while(len++ & 3)
        printf("\\%02x", tlb_read_byte());
    printf("\n");
}

static void dump_binary(int n)
{
    int i;

    for(i = 1; i <= n; i++) {
        switch(i & 0x0f) {
        case 0:
            printf("%02x\n", tlb_read_byte());
            break;
        case 1:
            print_offset();
            /* fall through */
        default:
            printf("%02x ", tlb_read_byte());
        }
    }

    if(n&0x0f)
        printf("\n");
}

310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
static int dump_msft_varflags(void)
{
    static const char *syskind[] = {
        "SYS_WIN16", "SYS_WIN32", "SYS_MAC", "SYS_WIN64", "unknown"
    };
    int kind, flags;

    print_offset();
    flags = tlb_read_int();
    kind = flags & 0xf;
    if (kind > 3) kind = 4;
    printf("varflags = %08x, syskind = %s\n", flags, syskind[kind]);
    return flags;
}

static void dump_msft_version(void)
{
    int version;
    print_offset();
    version = tlb_read_int();
    printf("version = %d.%d\n", version & 0xff, version >> 16);
}

333 334 335 336 337 338 339 340
static void dump_msft_header(void)
{
    print_begin_block("Header");

    print_hex("magic1");
    print_hex("magic2");
    print_hex("posguid");
    print_hex("lcid");
341 342 343
    print_hex("lcid2");
    header_flags = dump_msft_varflags();
    dump_msft_version();
344 345
    print_hex("flags");
    typeinfo_cnt = print_dec("ntypeinfos");
346 347 348 349
    print_dec("helpstring");
    print_dec("helpstringcontext");
    print_dec("helpcontext");
    print_dec("nametablecount");
350 351 352 353 354 355 356 357 358 359 360 361
    print_dec("nametablechars");
    print_hex("NameOffset");
    print_hex("helpfile");
    print_hex("CustomDataOffset");
    print_hex("res44");
    print_hex("res48");
    print_hex("dispatchpos");
    print_hex("res50");

    print_end_block();
}

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
static int dump_msft_typekind(void)
{
    static const char *tkind[TKIND_MAX] = {
      "TKIND_ENUM", "TKIND_RECORD", "TKIND_MODULE",
      "TKIND_INTERFACE", "TKIND_DISPATCH", "TKIND_COCLASS",
      "TKIND_ALIAS", "TKIND_UNION"
    };
    int ret, typekind;

    print_offset();
    ret = tlb_read_int();
    typekind = ret & 0xf;
    printf("typekind = %s, align = %d\n", typekind < TKIND_MAX ? tkind[typekind] : "unknown", (ret >> 11) & 0x1f);
    return ret;
}

378 379 380 381
static void dump_msft_typeinfobase(void)
{
    print_begin_block_id("TypeInfoBase", msft_typeinfo_cnt);

382
    msft_typeinfo_kind[msft_typeinfo_cnt] = dump_msft_typekind();
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
    msft_typeinfo_offs[msft_typeinfo_cnt] = print_hex("memoffset");
    print_hex("res2");
    print_hex("res3");
    print_hex("res4");
    print_hex("res5");
    msft_typeinfo_elemcnt[msft_typeinfo_cnt] = print_hex("cElement");
    print_hex("res7");
    print_hex("res8");
    print_hex("res9");
    print_hex("resA");
    print_hex("posguid");
    print_hex("flags");
    print_hex("NameOffset");
    print_hex("version");
    print_hex("docstringoffs");
    print_hex("docstringcontext");
    print_hex("helpcontext");
    print_hex("oCustData");
    msft_typeinfo_impltypes[msft_typeinfo_cnt++] = print_short_hex("cImplTypes");
    print_short_hex("bSizeVftt");
    print_dec("size");
    print_hex("datatype1");
    print_hex("datatype2");
    print_hex("res18");
    print_hex("res19");

    print_end_block();
}

412
static BOOL dump_msft_typeinfobases(seg_t *seg)
413 414 415 416 417 418 419
{
    int i;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_typeinfobase();

    assert(offset == seg->offset+seg->length);
420
    return TRUE;
421 422 423 424 425 426 427 428 429 430 431 432 433
}

static void dump_msft_impinfo(int n)
{
    print_begin_block_id("ImpInfo", n);

    print_hex("flags");
    print_hex("oImpInfo");
    print_hex("oGuid");

    print_end_block();
}

434
static BOOL dump_msft_impinfos(seg_t *seg)
435 436 437 438 439 440 441
{
    int i;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_impinfo(i);

    assert(offset == seg->offset+seg->length);
442
    return TRUE;
443 444 445 446 447 448 449 450 451 452 453 454 455 456
}

static void dump_msft_impfile(int n)
{
    print_begin_block_id("ImpFile", n);

    print_hex("guid");
    print_hex("lcid");
    print_hex("version");
    print_ctl2("impfile");

    print_end_block();
}

457
static BOOL dump_msft_impfiles(seg_t *seg)
458 459 460 461 462 463 464
{
    int i;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_impfile(i);

    assert(offset == seg->offset+seg->length);
465
    return TRUE;
466 467
}

468
static BOOL dump_msft_reftabs(seg_t *seg)
469 470 471 472 473 474 475
{
    print_begin_block("RefTab");

    dump_binary(seg->length); /* FIXME */

    print_end_block();

476
    return TRUE;
477 478
}

479
static BOOL dump_msft_guidhashtab(seg_t *seg)
480
{
481
    print_begin_block("GuidHashTab");
482 483 484 485 486 487

    dump_binary(seg->length); /* FIXME */

    print_end_block();

    assert(offset == seg->offset+seg->length);
488
    return TRUE;
489 490 491 492 493 494 495 496 497 498 499 500 501
}

static void dump_msft_guidentry(int n)
{
    print_begin_block_id("GuidEntry", n);

    print_guid("guid");
    print_hex("hreftype");
    print_hex("next_hash");

    print_end_block();
}

502
static BOOL dump_msft_guidtab(seg_t *seg)
503 504 505 506 507 508 509
{
    int i;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_guidentry(i);

    assert(offset == seg->offset+seg->length);
510
    return TRUE;
511 512
}

513
static BOOL dump_msft_namehashtab(seg_t *seg)
514
{
515
    print_begin_block("NameHashTab");
516 517 518 519

    dump_binary(seg->length); /* FIXME */

    print_end_block();
520
    return TRUE;
521 522
}

523 524 525 526 527 528 529 530 531
static void dump_string(int len, int align_off)
{
    printf("\"");
    fwrite(tlb_read(len), len, 1, stdout);
    printf("\" ");
    while((len++ + align_off) & 3)
        printf("\\%2.2x", tlb_read_byte());
}

532 533 534 535 536 537 538 539 540 541 542
static void dump_msft_name(int base, int n)
{
    int len;

    print_begin_block_id("Name", n);

    print_hex("hreftype");
    print_hex("next_hash");
    len = print_hex("namelen")&0xff;

    print_offset();
543 544
    printf("name = ");
    dump_string(len, 0);
545 546 547 548 549
    printf("\n");

    print_end_block();
}

550
static BOOL dump_msft_nametab(seg_t *seg)
551 552 553 554 555 556 557
{
    int i, base = offset;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_name(base, i);

    assert(offset == seg->offset+seg->length);
558
    return TRUE;
559 560
}

561
static void dump_msft_string(int n)
562
{
563
    int len;
564

565 566 567 568 569 570 571 572 573 574 575 576 577
    print_begin_block_id("String", n);

    len = print_short_hex("stringlen");

    print_offset();
    printf("string = ");
    dump_string(len, 2);

    if(len < 3) {
        for(len = 0; len < 4; len++)
            printf("\\%2.2x", tlb_read_byte());
    }
    printf("\n");
578 579

    print_end_block();
580 581
}

582
static BOOL dump_msft_stringtab(seg_t *seg)
583 584 585 586 587
{
    int i;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_string(i);
588

589
    assert(offset == seg->offset+seg->length);
590
    return TRUE;
591 592 593 594 595 596 597 598 599 600 601 602
}

static void dump_msft_typedesc(int n)
{
    print_begin_block_id("TYPEDESC", n);

    print_hex("hreftype");
    print_hex("vt");

    print_end_block();
}

603
static BOOL dump_msft_typedesctab(seg_t *seg)
604 605 606 607 608 609 610 611 612 613 614
{
    int i;

    print_begin_block("TypedescTab");

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_typedesc(i);

    print_end_block();

    assert(offset == seg->offset+seg->length);
615
    return TRUE;
616 617
}

618
static BOOL dump_msft_arraydescs(seg_t *seg)
619 620 621 622 623 624
{
    print_begin_block("ArrayDescriptions");

    dump_binary(seg->length); /* FIXME */

    print_end_block();
625
    return TRUE;
626 627
}

628
static BOOL dump_msft_custdata(seg_t *seg)
629
{
630 631 632
    unsigned short vt;
    unsigned i, n;

633 634
    print_begin_block("CustData");

635 636 637 638 639 640 641 642
    for(i=0; offset < seg->offset+seg->length; i++) {
        print_offset();

        vt = tlb_read_short();
        printf("vt %d", vt);
        n = tlb_read_int();

        switch(vt) {
643
        case VT_BSTR:
644 645 646 647 648 649
            printf(" len %d: ", n);
            dump_string(n, 2);
            printf("\n");
            break;
        default:
            printf(": %x ", n);
650 651
            printf("\\%2.2x ", tlb_read_byte());
            printf("\\%2.2x\n", tlb_read_byte());
652 653
        }
    }
654 655

    print_end_block();
656
    return TRUE;
657 658 659 660 661 662 663 664 665 666 667 668 669
}

static void dump_msft_cdguid(int n)
{
    print_begin_block_id("CGUid", n);

    print_hex("GuidOffset");
    print_hex("DataOffset");
    print_hex("next");

    print_end_block();
}

670
static BOOL dump_msft_cdguids(seg_t *seg)
671 672 673 674 675 676 677
{
    int i;

    for(i = 0; offset < seg->offset+seg->length; i++)
        dump_msft_cdguid(i);

    assert(offset == seg->offset+seg->length);
678
    return TRUE;
679 680
}

681
static BOOL dump_msft_res0e(seg_t *seg)
682 683 684 685 686
{
    print_begin_block("res0e");
    dump_binary(seg->length);
    print_end_block();

687
    return TRUE;
688 689
}

690
static BOOL dump_msft_res0f(seg_t *seg)
691 692 693 694 695
{
    print_begin_block("res0f");
    dump_binary(seg->length);
    print_end_block();

696
    return TRUE;
697 698
}

699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
/* Used for function return value and arguments type */
static void dump_msft_datatype(const char *name)
{
    int datatype;

    print_offset();
    datatype = tlb_read_int();
    printf("%s = %08x", name, datatype);
    if (datatype < 0) {
       printf(", ");
       print_vartype(datatype);
    }
    else {
       const short *vt;

       if (datatype > segdir[SEGDIR_TYPEDESC].length) {
           printf(", invalid offset\n");
           return;
       }

       /* FIXME: in case of VT_USERDEFINED use hreftype */
       vt = PRD(segdir[SEGDIR_TYPEDESC].offset + datatype, 4*sizeof(short));
       datatype = vt[0] & VT_TYPEMASK;
       if (datatype == VT_PTR) {
           printf(", VT_PTR -> ");
           if (vt[3] < 0)
               datatype = vt[2];
           else {
               vt = PRD(segdir[SEGDIR_TYPEDESC].offset + vt[2], 4*sizeof(short));
               datatype = *vt;
           }
       }
       else {
           printf(", ");
           datatype = *vt;
       }

       print_vartype(datatype);
    }
}

static void dump_defaultvalue(int id)
{
    int offset;

    print_offset();
    offset = tlb_read_int();

    printf("default value[%d] = %08x", id, offset);
    if (offset == -1)
        printf("\n");
    else if (offset < 0) {
        printf(", ");
        print_vartype((offset & 0x7c000000) >> 26);
    }
    else {
        const unsigned short *vt;

        if (offset > segdir[SEGDIR_CUSTDATA].length) {
            printf(", invalid offset\n");
            return;
        }

        vt = PRD(segdir[SEGDIR_CUSTDATA].offset + offset, sizeof(*vt));
        printf(", ");
        print_vartype(*vt);
    }
}

768 769
static void dump_msft_func(int n)
{
770
    int size, args_cnt, i, extra_attr, fkccic;
771 772 773 774 775

    print_begin_block_id("FuncRecord", n);

    size = print_short_hex("size");
    print_short_hex("index");
776
    dump_msft_datatype("retval type");
777 778 779
    print_hex("flags");
    print_short_hex("VtableOffset");
    print_short_hex("funcdescsize");
780
    fkccic = print_hex("FKCCIC");
781 782 783
    args_cnt = print_short_hex("nrargs");
    print_short_hex("noptargs");

784
    extra_attr = size/sizeof(INT) - 6 - args_cnt*(fkccic&0x1000 ? 4 : 3);
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799

    if(extra_attr)
        print_hex("helpcontext");
    if(extra_attr >= 2)
        print_hex("oHelpString");
    if(extra_attr >= 3)
        print_hex("toEntry");
    if(extra_attr >= 4)
        print_hex("res9");
    if(extra_attr >= 5)
        print_hex("resA");
    if(extra_attr >= 6)
        print_hex("HelpStringContext");
    if(extra_attr >= 7)
        print_hex("oCustData");
800 801
    for(i = 0; i < extra_attr-7; i++)
        print_hex_id("oArgCustData", i);
802

803 804
    if(fkccic & 0x1000) {
        for(i=0; i < args_cnt; i++)
805
            dump_defaultvalue(i);
806 807
    }

808 809 810 811
    for(i=0; i < args_cnt; i++) {
        print_begin_block_id("param", i);

        /* FIXME: Handle default values */
812 813
        dump_msft_datatype("datatype");
        print_hex("name");
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
        print_hex("paramflags");

        print_end_block();
    }

    print_end_block();
}

static void dump_msft_var(int n)
{
    INT size;

    print_begin_block_id("VarRecord", n);

    size = print_hex("recsize")&0x1ff;
    print_hex("DataType");
    print_hex("flags");
    print_short_hex("VarKind");
    print_short_hex("vardescsize");
    print_hex("OffsValue");

    if(size > 5*sizeof(INT))
        dump_binary(size - 5*sizeof(INT));

    print_end_block();
}

static void dump_msft_ref(int n)
{
    print_begin_block_id("RefRecord", n);

    print_hex("reftype");
    print_hex("flags");
    print_hex("oCustData");
    print_hex("onext");

    print_end_block();
}

static void dump_msft_coclass(int n)
{
    int i;

    print_dec("size");

    for(i=0; i < msft_typeinfo_impltypes[n]; i++)
        dump_msft_ref(i);
}

863
static BOOL dump_msft_typeinfo(int n)
864 865 866 867 868 869 870 871
{
    int i;

    print_begin_block_id("TypeInfo", n);

    if((msft_typeinfo_kind[n] & 0xf) == TKIND_COCLASS) {
        dump_msft_coclass(n);
        print_end_block();
872
        return TRUE;
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
    }

    print_dec("size");

    for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
        dump_msft_func(i);

    for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
        dump_msft_var(i);

    for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
        print_hex_id("func %d id", i);

    for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
        print_hex_id("var %d id", i);

    for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
        print_hex_id("func %d name", i);

    for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
        print_hex_id("var %d name", i);

    for(i = 0; i < LOWORD(msft_typeinfo_elemcnt[n]); i++)
        print_hex_id("func %d offset", i);

    for(i = 0; i < HIWORD(msft_typeinfo_elemcnt[n]); i++)
        print_hex_id("var %d offset", i);

    print_end_block();

903
    return TRUE;
904 905
}

906
static seg_t segdir[] = {
907 908 909 910
    {"TypeInfoTab",       dump_msft_typeinfobases, -1, -1},
    {"ImpInfo",           dump_msft_impinfos, -1, -1},
    {"ImpFiles",          dump_msft_impfiles, -1, -1},
    {"RefTab",            dump_msft_reftabs, -1, -1},
911
    {"GuidHashTab",       dump_msft_guidhashtab, -1, -1},
912
    {"GuidTab",           dump_msft_guidtab, -1, -1},
913
    {"NameHashTab",       dump_msft_namehashtab, -1, -1},
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
    {"pNameTab",          dump_msft_nametab, -1, -1},
    {"pStringTab",        dump_msft_stringtab, -1, -1},
    {"TypedescTab",       dump_msft_typedesctab, -1, -1},
    {"ArrayDescriptions", dump_msft_arraydescs, -1, -1},
    {"CustData",          dump_msft_custdata, -1, -1},
    {"CDGuid",            dump_msft_cdguids, -1, -1},
    {"res0e",             dump_msft_res0e, -1, -1},
    {"res0f",             dump_msft_res0f, -1, -1}
};

static void dump_msft_seg(seg_t *seg)
{
    print_begin_block(seg->name);

    seg->offset = print_hex("offset");
    seg->length = print_dec("length");
    print_hex("res08");
    print_hex("res0c");

    print_end_block();
}

static void dump_msft_segdir(void)
{
    int i;

    print_begin_block("SegDir");

    for(i=0; i < sizeof(segdir)/sizeof(segdir[0]); i++)
        dump_msft_seg(segdir+i);

    print_end_block();
}

948
static BOOL dump_offset(void)
949 950 951 952 953 954 955 956 957 958 959
{
    int i;

    for(i=0; i < sizeof(segdir)/sizeof(segdir[0]); i++)
        if(segdir[i].offset == offset)
            return segdir[i].func(segdir+i);

    for(i=0; i < msft_typeinfo_cnt; i++)
        if(msft_typeinfo_offs[i] == offset)
            return dump_msft_typeinfo(i);

960
    return FALSE;
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
}

enum FileSig get_kind_msft(void)
{
    const DWORD *sig = PRD(0, sizeof(DWORD));
    return sig && *sig == MSFT_MAGIC ? SIG_MSFT : SIG_UNKNOWN;
}

void msft_dump(void)
{
    int i;

    dump_msft_header();

    for(i=0; i < typeinfo_cnt; i++)
        print_hex_id("typeinfo %d offset", i);

    if(header_flags & HELPDLLFLAG)
        print_hex("help dll offset");
    print_offset();
    printf("\n");

    dump_msft_segdir();

    while(!msft_eof) {
        if(!dump_offset())
            print_hex("unknown");
    }
}