4 * Copyright 2006 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
34 #ifdef HAVE_SYS_STAT_H
35 # include <sys/stat.h>
37 #ifdef HAVE_SYS_MMAN_H
42 #define NONAMELESSUNION
43 #define NONAMELESSSTRUCT
47 #include "wine/mscvpdb.h"
55 const struct PDB_JG_HEADER
* header
;
56 const struct PDB_JG_TOC
* toc
;
57 const struct PDB_JG_ROOT
* root
;
61 const struct PDB_DS_HEADER
* header
;
62 const struct PDB_DS_TOC
* toc
;
63 const struct PDB_DS_ROOT
* root
;
66 void* (*read_file
)(struct pdb_reader
*, DWORD
);
67 DWORD file_used
[1024];
70 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
, int size
)
75 if (!size
) return NULL
;
77 nBlocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
78 buffer
= malloc(nBlocks
* pdb
->block_size
);
80 for (i
= 0; i
< nBlocks
; i
++)
81 memcpy(buffer
+ i
* pdb
->block_size
,
82 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
87 static void* pdb_jg_read_file(struct pdb_reader
* reader
, DWORD file_nr
)
89 const WORD
* block_list
;
92 if (!reader
->u
.jg
.toc
|| file_nr
>= reader
->u
.jg
.toc
->num_files
) return NULL
;
94 reader
->file_used
[file_nr
/ 32] |= 1 << (file_nr
% 32);
95 if (reader
->u
.jg
.toc
->file
[file_nr
].size
== 0 ||
96 reader
->u
.jg
.toc
->file
[file_nr
].size
== 0xFFFFFFFF)
98 block_list
= (const WORD
*) &reader
->u
.jg
.toc
->file
[reader
->u
.jg
.toc
->num_files
];
99 for (i
= 0; i
< file_nr
; i
++)
100 block_list
+= (reader
->u
.jg
.toc
->file
[i
].size
+
101 reader
->u
.jg
.header
->block_size
- 1) / reader
->u
.jg
.header
->block_size
;
103 return pdb_jg_read(reader
->u
.jg
.header
, block_list
,
104 reader
->u
.jg
.toc
->file
[file_nr
].size
);
107 static void pdb_jg_init(struct pdb_reader
* reader
)
109 reader
->u
.jg
.header
= PRD(0, sizeof(struct PDB_JG_HEADER
));
110 reader
->read_file
= pdb_jg_read_file
;
111 reader
->u
.jg
.toc
= pdb_jg_read(reader
->u
.jg
.header
,
112 reader
->u
.jg
.header
->toc_block
,
113 reader
->u
.jg
.header
->toc
.size
);
114 memset(reader
->file_used
, 0, sizeof(reader
->file_used
));
117 static DWORD
pdb_get_num_files(const struct pdb_reader
* reader
)
119 if (reader
->read_file
== pdb_jg_read_file
)
120 return reader
->u
.jg
.toc
->num_files
;
122 return reader
->u
.ds
.toc
->num_files
;
125 static DWORD
pdb_get_file_size(const struct pdb_reader
* reader
, unsigned idx
)
127 if (reader
->read_file
== pdb_jg_read_file
)
128 return reader
->u
.jg
.toc
->file
[idx
].size
;
130 return reader
->u
.ds
.toc
->file_size
[idx
];
133 static void pdb_exit(struct pdb_reader
* reader
)
140 for (i
= 0; i
< pdb_get_num_files(reader
); i
++)
142 if (reader
->file_used
[i
/ 32] & (1 << (i
% 32))) continue;
144 file
= reader
->read_file(reader
, i
);
147 size
= pdb_get_file_size(reader
, i
);
149 printf("File --unused-- #%d (%x)\n", i
, size
);
150 dump_data(file
, size
, " ");
154 if (reader
->read_file
== pdb_jg_read_file
)
156 free((char*)reader
->u
.jg
.root
);
157 free((char*)reader
->u
.jg
.toc
);
161 free((char*)reader
->u
.ds
.root
);
162 free((char*)reader
->u
.ds
.toc
);
166 static unsigned get_stream_by_name(struct pdb_reader
* reader
, const char* name
)
171 DWORD string_idx
, stream_idx
;
175 if (reader
->read_file
== pdb_jg_read_file
)
177 str
= &reader
->u
.jg
.root
->names
[0];
178 cbstr
= reader
->u
.jg
.root
->cbNames
;
182 str
= &reader
->u
.ds
.root
->names
[0];
183 cbstr
= reader
->u
.ds
.root
->cbNames
;
186 pdw
= (DWORD
*)(str
+ cbstr
);
187 pdw
++; /* number of ok entries */
190 /* bitfield: first dword is len (in dword), then data */
192 pdw
+= *ok_bits
++ + 1;
195 printf("unexpected value\n");
199 for (i
= 0; i
< count
; i
++)
201 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
205 if (!strcmp(name
, &str
[string_idx
])) return stream_idx
;
211 static void *read_string_table(struct pdb_reader
* reader
)
216 stream_idx
= get_stream_by_name(reader
, "/names");
217 if (stream_idx
== -1) return NULL
;
218 ret
= reader
->read_file(reader
, stream_idx
);
219 if (ret
&& *(const DWORD
*)ret
== 0xeffeeffe) return ret
;
220 printf("wrong header %x expecting 0xeffeeffe\n", *(const DWORD
*)ret
);
225 static void pdb_dump_symbols(struct pdb_reader
* reader
, PDB_STREAM_INDEXES
* sidx
)
227 PDB_SYMBOLS
* symbols
;
228 unsigned char* modimage
;
233 sidx
->FPO
= sidx
->unk0
= sidx
->unk1
= sidx
->unk2
= sidx
->unk3
= sidx
->segments
=
234 sidx
->unk4
= sidx
->unk5
= sidx
->unk6
= sidx
->FPO_EXT
= sidx
->unk7
= -1;
236 symbols
= reader
->read_file(reader
, 3);
237 if (!symbols
) return;
239 switch (symbols
->version
)
242 case 19960307: /* VC 5.0 */
243 case 19970606: /* VC 6.0 */
244 case 19990903: /* VC 7.0 */
247 printf("-Unknown symbol info version %d\n", symbols
->version
);
250 "\tsignature: %08x\n"
253 "\thash1_file: %08x\n"
254 "\thash2_file: %08x\n"
255 "\tgsym_file: %04x\n"
257 "\tmodule_size: %08x\n"
258 "\toffset_size: %08x\n"
259 "\thash_size: %08x\n"
260 "\tsrc_module_size: %08x\n"
261 "\tpdbimport_size: %08x\n"
263 "\tstream_idx_size: %08x\n"
264 "\tunknown2_size: %08x\n"
275 symbols
->module_size
,
276 symbols
->offset_size
,
278 symbols
->srcmodule_size
,
279 symbols
->pdbimport_size
,
281 symbols
->stream_index_size
,
282 symbols
->unknown2_size
,
284 get_machine_str( symbols
->machine
),
287 if (symbols
->offset_size
)
291 printf("\t----------offsets------------\n");
292 src
= (const BYTE
*)((const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
);
293 dump_data(src
, symbols
->offset_size
, " ");
296 if (!(filesimage
= read_string_table(reader
))) printf("string table not found\n");
297 else filessize
= *(const DWORD
*)(filesimage
+ 8);
299 if (symbols
->srcmodule_size
)
301 const PDB_SYMBOL_SOURCE
*src
;
305 const char* start_cstr
;
308 printf("\t----------src module------------\n");
309 src
= (const PDB_SYMBOL_SOURCE
*)((const char*)symbols
+ sizeof(PDB_SYMBOLS
) +
310 symbols
->module_size
+ symbols
->offset_size
+ symbols
->hash_size
);
311 printf("\tSource Modules\n"
313 "\t\tnSrcFiles: %u\n",
314 src
->nModules
, src
->nSrcFiles
);
316 /* usage of table seems to be as follows:
317 * two arrays of WORD (src->nModules as size)
318 * - first array contains index into files for "module" compilation
319 * (module = compilation unit ??)
320 * - second array contains the number of source files in module
321 * an array of DWORD (src->nSrcFiles as size)
322 * - contains offset (in following string table) of the source file name
324 * - each string is a pascal string (ie. with its length as first BYTE) or
325 * 0-terminated string (depending on version)
327 indx
= &src
->table
[src
->nModules
];
328 offset
= (const DWORD
*)&src
->table
[2 * src
->nModules
];
329 cstr
= (const char*)&src
->table
[2 * (src
->nModules
+ src
->nSrcFiles
)];
332 for (i
= cfile
= 0; i
< src
->nModules
; i
++)
334 printf("\t\tModule[%2d]:\n", i
);
335 cfile
= src
->table
[i
];
336 for (j
= cfile
; j
< src
->nSrcFiles
&& j
< cfile
+ indx
[i
]; j
++)
338 /* FIXME: in some cases, it's a p_string but WHEN ? */
339 if (cstr
+ offset
[j
] >= (const char*)start_cstr
/* wrap around */ &&
340 cstr
+ offset
[j
] < (const char*)src
+ symbols
->srcmodule_size
)
341 printf("\t\t\tSource file: %s\n", cstr
+ offset
[j
]);
343 printf("\t\t\tSource file: <<out of bounds>>\n");
347 if (symbols
->pdbimport_size
)
349 const PDB_SYMBOL_IMPORT
* imp
;
354 printf("\t------------import--------------\n");
355 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols
+ sizeof(PDB_SYMBOLS
) +
356 symbols
->module_size
+ symbols
->offset_size
+
357 symbols
->hash_size
+ symbols
->srcmodule_size
);
358 first
= (const char*)imp
;
359 last
= (const char*)imp
+ symbols
->pdbimport_size
;
360 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
362 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
363 printf("\tImport: %lx\n"
364 "\t\tUnknown1: %08x\n"
365 "\t\tUnknown2: %08x\n"
366 "\t\tTimeDateStamp: %08x\n"
370 (ULONG_PTR
)((const char*)imp
- (const char*)first
),
377 imp
= (const PDB_SYMBOL_IMPORT
*)(first
+ ((ptr
- first
+ strlen(ptr
) + 1 + 3) & ~3));
380 if (symbols
->stream_index_size
)
382 printf("\t------------stream indexes--------------\n");
383 switch (symbols
->stream_index_size
)
385 case sizeof(PDB_STREAM_INDEXES_OLD
):
386 /* PDB_STREAM_INDEXES is a superset of PDB_STREAM_INDEX_OLD
387 * FIXME: to be confirmed when all fields are fully understood
390 (const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
+
391 symbols
->offset_size
+ symbols
->hash_size
+ symbols
->srcmodule_size
+
392 symbols
->pdbimport_size
+ symbols
->unknown2_size
,
393 sizeof(PDB_STREAM_INDEXES_OLD
));
394 printf("\tFPO: %04x\n"
399 "\tSegments: %04x\n",
400 sidx
->FPO
, sidx
->unk0
, sidx
->unk1
, sidx
->unk2
, sidx
->unk3
,
403 case sizeof(PDB_STREAM_INDEXES
):
405 (const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
+
406 symbols
->offset_size
+ symbols
->hash_size
+ symbols
->srcmodule_size
+
407 symbols
->pdbimport_size
+ symbols
->unknown2_size
,
409 printf("\tFPO: %04x\n"
420 sidx
->FPO
, sidx
->unk0
, sidx
->unk1
, sidx
->unk2
, sidx
->unk3
,
421 sidx
->segments
, sidx
->unk4
, sidx
->unk5
, sidx
->unk6
, sidx
->FPO_EXT
,
425 printf("unexpected size for stream index %d\n", symbols
->stream_index_size
);
430 /* Read global symbol table */
431 modimage
= reader
->read_file(reader
, symbols
->gsym_file
);
434 printf("\t------------globals-------------\n");
435 codeview_dump_symbols(modimage
, pdb_get_file_size(reader
, symbols
->gsym_file
));
439 /* Read per-module symbol / linenumber tables */
440 file
= (const char*)symbols
+ sizeof(PDB_SYMBOLS
);
441 while (file
- (const char*)symbols
< sizeof(PDB_SYMBOLS
) + symbols
->module_size
)
443 int file_nr
, symbol_size
, lineno_size
;
444 const char* file_name
;
446 if (symbols
->version
< 19970000)
448 const PDB_SYMBOL_FILE
* sym_file
= (const PDB_SYMBOL_FILE
*) file
;
449 file_nr
= sym_file
->file
;
450 file_name
= sym_file
->filename
;
451 symbol_size
= sym_file
->symbol_size
;
452 lineno_size
= sym_file
->lineno_size
;
453 printf("\t--------symbol file----------- %s\n", file_name
);
454 printf("\tgot symbol_file\n"
455 "\t\tunknown1: %08x\n"
457 "\t\t\tsegment: %04x\n"
459 "\t\t\toffset: %08x\n"
461 "\t\t\tcharacteristics: %08x\n"
462 "\t\t\tindex: %04x\n"
466 "\t\tsymb size: %08x\n"
467 "\t\tline size: %08x\n"
468 "\t\tunknown2: %08x\n"
469 "\t\tnSrcFiles: %08x\n"
470 "\t\tattribute: %08x\n",
472 sym_file
->range
.segment
,
473 sym_file
->range
.pad1
,
474 sym_file
->range
.offset
,
475 sym_file
->range
.size
,
476 sym_file
->range
.characteristics
,
477 sym_file
->range
.index
,
478 sym_file
->range
.pad2
,
481 sym_file
->symbol_size
,
482 sym_file
->lineno_size
,
485 sym_file
->attribute
);
489 const PDB_SYMBOL_FILE_EX
* sym_file
= (const PDB_SYMBOL_FILE_EX
*) file
;
490 file_nr
= sym_file
->file
;
491 file_name
= sym_file
->filename
;
492 symbol_size
= sym_file
->symbol_size
;
493 lineno_size
= sym_file
->lineno_size
;
494 printf("\t--------symbol file----------- %s\n", file_name
);
495 printf("\t\tunknown1: %08x\n"
497 "\t\t\tsegment: %04x\n"
499 "\t\t\toffset: %08x\n"
501 "\t\t\tcharacteristics: %08x\n"
502 "\t\t\tindex: %04x\n"
504 "\t\t\ttimestamp: %08x\n"
505 "\t\t\tunknown: %08x\n"
508 "\t\tsymb size: %08x\n"
509 "\t\tline size: %08x\n"
510 "\t\tunknown2: %08x\n"
511 "\t\tnSrcFiles: %08x\n"
512 "\t\tattribute: %08x\n"
513 "\t\treserved/0: %08x\n"
514 "\t\treserved/1: %08x\n",
516 sym_file
->range
.segment
,
517 sym_file
->range
.pad1
,
518 sym_file
->range
.offset
,
519 sym_file
->range
.size
,
520 sym_file
->range
.characteristics
,
521 sym_file
->range
.index
,
522 sym_file
->range
.pad2
,
523 sym_file
->range
.timestamp
,
524 sym_file
->range
.unknown
,
527 sym_file
->symbol_size
,
528 sym_file
->lineno_size
,
532 sym_file
->reserved
[0],
533 sym_file
->reserved
[1]);
535 modimage
= reader
->read_file(reader
, file_nr
);
538 int total_size
= pdb_get_file_size(reader
, file_nr
);
541 codeview_dump_symbols((const char*)modimage
+ sizeof(DWORD
), symbol_size
);
543 /* line number info */
545 codeview_dump_linetab((const char*)modimage
+ symbol_size
, TRUE
, " ");
546 /* anyway, lineno_size doesn't see to really be the size of the line number information, and
547 * it's not clear yet when to call for linetab2...
549 codeview_dump_linetab2((const char*)modimage
+ symbol_size
+ lineno_size
,
550 total_size
- (symbol_size
+ lineno_size
),
551 filesimage
? filesimage
+ 12 : NULL
, filessize
, " ");
552 /* what's that part ??? */
554 dump_data(modimage
+ symbol_size
+ lineno_size
, total_size
- (symbol_size
+ lineno_size
), " ");
558 file_name
+= strlen(file_name
) + 1;
559 file
= (char*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
565 static void pdb_dump_types(struct pdb_reader
* reader
)
567 PDB_TYPES
* types
= NULL
;
569 types
= reader
->read_file(reader
, 2);
571 switch (types
->version
)
573 case 19950410: /* VC 4.0 */
575 case 19961031: /* VC 5.0 / 6.0 */
576 case 19990903: /* VC 7.0 */
577 case 20040203: /* VC 8.0 */
580 printf("-Unknown type info version %d\n", types
->version
);
583 /* Read type table */
586 "\ttype_offset: %08x\n"
587 "\tfirst_index: %x\n"
594 "\thash_offset: %x\n"
596 "\tsearch_offset: %x\n"
598 "\tunknown_offset: %x\n"
599 "\tunknown_len: %x\n",
611 types
->search_offset
,
613 types
->unknown_offset
,
615 codeview_dump_types_from_block((const char*)types
+ types
->type_offset
, types
->type_size
);
619 static void pdb_dump_fpo(struct pdb_reader
* reader
, unsigned stream_idx
)
623 const char* frame_type
[4] = {"Fpo", "Trap", "Tss", "NonFpo"};
625 if (stream_idx
== (WORD
)-1) return;
626 fpo
= reader
->read_file(reader
, stream_idx
);
627 size
= pdb_get_file_size(reader
, stream_idx
);
628 if (fpo
&& (size
% sizeof(*fpo
)) == 0)
630 size
/= sizeof(*fpo
);
631 printf("FPO data:\n\t Start Length #loc #pmt #prolog #reg frame SEH /BP\n");
632 for (i
= 0; i
< size
; i
++)
634 printf("\t%08x %08x %4d %4d %7d %4d %6s %c %c\n",
635 fpo
[i
].ulOffStart
, fpo
[i
].cbProcSize
, fpo
[i
].cdwLocals
, fpo
[i
].cdwParams
,
636 fpo
[i
].cbProlog
, fpo
[i
].cbRegs
, frame_type
[fpo
[i
].cbFrame
],
637 fpo
[i
].fHasSEH
? 'Y' : 'N', fpo
[i
].fUseBP
? 'Y' : 'N');
643 static void pdb_dump_fpo_ext(struct pdb_reader
* reader
, unsigned stream_idx
)
645 PDB_FPO_DATA
* fpoext
;
646 unsigned i
, size
, strsize
;
649 if (stream_idx
== (WORD
)-1) return;
650 strbase
= read_string_table(reader
);
651 if (!strbase
) return;
653 strsize
= *(const DWORD
*)(strbase
+ 8);
654 fpoext
= reader
->read_file(reader
, stream_idx
);
655 size
= pdb_get_file_size(reader
, stream_idx
);
656 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
658 size
/= sizeof(*fpoext
);
659 printf("FPO data (extended):\n"
660 "\t Start Length Locals Params MaxStack Prolog #SavedRegs Flags Command\n");
661 for (i
= 0; i
< size
; i
++)
663 printf("\t%08x %08x %8x %8x %8x %6x %8x %08x %s\n",
664 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
, fpoext
[i
].params_size
,
665 fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
, fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
666 fpoext
[i
].str_offset
< strsize
? strbase
+ 12 + fpoext
[i
].str_offset
: "<out of bounds>");
673 static void pdb_dump_segments(struct pdb_reader
* reader
, unsigned stream_idx
)
679 if (stream_idx
== (WORD
)-1) return;
680 segs
= reader
->read_file(reader
, stream_idx
);
684 size
= pdb_get_file_size(reader
, stream_idx
);
685 for (ptr
= segs
; ptr
< segs
+ size
; )
687 printf("Segment %s\n", ptr
);
688 ptr
+= (strlen(ptr
) + 1 + 3) & ~3;
689 printf("\tdword[0]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
690 printf("\tdword[1]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
691 printf("\tdword[2]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
692 printf("\tdword[3]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
693 printf("\tdword[4]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
694 printf("\tdword[5]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
695 printf("\tdword[6]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
696 printf("\tdword[7]: %08x\n", *(DWORD
*)ptr
); ptr
+= 4;
699 } else printf("nosdfsdffd\n");
702 static const char pdb2
[] = "Microsoft C/C++ program database 2.00";
704 static void pdb_jg_dump(void)
706 struct pdb_reader reader
;
709 * Read in TOC and well-known files
711 pdb_jg_init(&reader
);
712 printf("Header (JG):\n"
714 "\tsignature: %08x\n"
715 "\tblock_size: %08x\n"
716 "\tfree_list: %04x\n"
717 "\ttotal_alloc:%04x\n",
718 (int)sizeof(pdb2
) - 1, reader
.u
.jg
.header
->ident
,
719 reader
.u
.jg
.header
->signature
,
720 reader
.u
.jg
.header
->block_size
,
721 reader
.u
.jg
.header
->free_list
,
722 reader
.u
.jg
.header
->total_alloc
);
724 reader
.u
.jg
.root
= reader
.read_file(&reader
, 1);
725 if (reader
.u
.jg
.root
)
731 PDB_STREAM_INDEXES sidx
;
735 "\tTimeDateStamp: %08x\n"
738 reader
.u
.jg
.root
->Version
,
739 reader
.u
.jg
.root
->TimeDateStamp
,
740 reader
.u
.jg
.root
->Age
,
741 (unsigned)reader
.u
.jg
.root
->cbNames
);
743 pdw
= (DWORD
*)(&reader
.u
.jg
.root
->names
[0] + reader
.u
.jg
.root
->cbNames
);
746 printf("\tStreams directory:\n"
752 /* bitfield: first dword is len (in dword), then data */
754 pdw
+= *ok_bits
++ + 1;
757 printf("unexpected value\n");
761 for (i
= 0; i
< count
; i
++)
763 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
765 DWORD string_idx
, stream_idx
;
768 printf("\t\t\t%2d) %-20s => %x\n", i
, &reader
.u
.jg
.root
->names
[string_idx
], stream_idx
);
772 if (numok
) printf(">>> unmatched present field with found\n");
774 /* Check for unknown versions */
775 switch (reader
.u
.jg
.root
->Version
)
777 case 19950623: /* VC 4.0 */
779 case 19960307: /* VC 5.0 */
780 case 19970604: /* VC 6.0 */
783 printf("-Unknown root block version %d\n", reader
.u
.jg
.root
->Version
);
785 pdb_dump_types(&reader
);
786 pdb_dump_symbols(&reader
, &sidx
);
787 pdb_dump_fpo(&reader
, sidx
.FPO
);
788 pdb_dump_segments(&reader
, sidx
.segments
);
790 else printf("-Unable to get root\n");
795 static void* pdb_ds_read(const struct PDB_DS_HEADER
* header
, const DWORD
* block_list
, int size
)
800 if (!size
) return NULL
;
802 nBlocks
= (size
+ header
->block_size
- 1) / header
->block_size
;
803 buffer
= malloc(nBlocks
* header
->block_size
);
805 for (i
= 0; i
< nBlocks
; i
++)
806 memcpy(buffer
+ i
* header
->block_size
,
807 (const char*)header
+ block_list
[i
] * header
->block_size
, header
->block_size
);
812 static void* pdb_ds_read_file(struct pdb_reader
* reader
, DWORD file_number
)
814 const DWORD
* block_list
;
817 if (!reader
->u
.ds
.toc
|| file_number
>= reader
->u
.ds
.toc
->num_files
) return NULL
;
819 reader
->file_used
[file_number
/ 32] |= 1 << (file_number
% 32);
820 if (reader
->u
.ds
.toc
->file_size
[file_number
] == 0 ||
821 reader
->u
.ds
.toc
->file_size
[file_number
] == 0xFFFFFFFF)
823 block_list
= reader
->u
.ds
.toc
->file_size
+ reader
->u
.ds
.toc
->num_files
;
824 for (i
= 0; i
< file_number
; i
++)
825 block_list
+= (reader
->u
.ds
.toc
->file_size
[i
] + reader
->u
.ds
.header
->block_size
- 1) /
826 reader
->u
.ds
.header
->block_size
;
828 return pdb_ds_read(reader
->u
.ds
.header
, block_list
, reader
->u
.ds
.toc
->file_size
[file_number
]);
831 static BOOL
pdb_ds_init(struct pdb_reader
* reader
)
833 reader
->u
.ds
.header
= PRD(0, sizeof(*reader
->u
.ds
.header
));
834 if (!reader
->u
.ds
.header
) return FALSE
;
835 reader
->read_file
= pdb_ds_read_file
;
836 reader
->u
.ds
.toc
= pdb_ds_read(reader
->u
.ds
.header
,
837 (const DWORD
*)((const char*)reader
->u
.ds
.header
+ reader
->u
.ds
.header
->toc_page
* reader
->u
.ds
.header
->block_size
),
838 reader
->u
.ds
.header
->toc_size
);
839 memset(reader
->file_used
, 0, sizeof(reader
->file_used
));
843 static const char pdb7
[] = "Microsoft C/C++ MSF 7.00";
845 static void pdb_ds_dump(void)
847 struct pdb_reader reader
;
849 pdb_ds_init(&reader
);
850 printf("Header (DS)\n"
851 "\tsignature: %.*s\n"
852 "\tblock_size: %08x\n"
854 "\tnum_pages: %08x\n"
857 "\ttoc_page: %08x\n",
858 (int)sizeof(pdb7
) - 1, reader
.u
.ds
.header
->signature
,
859 reader
.u
.ds
.header
->block_size
,
860 reader
.u
.ds
.header
->unknown1
,
861 reader
.u
.ds
.header
->num_pages
,
862 reader
.u
.ds
.header
->toc_size
,
863 reader
.u
.ds
.header
->unknown2
,
864 reader
.u
.ds
.header
->toc_page
);
867 * 0: JG says old toc pages, I'd say free pages (tbc, low prio)
871 * other known streams:
872 * - string table: it's index is in the stream table from ROOT object under "/names"
873 * those streams get their indexes out of the PDB_STREAM_INDEXES object
876 * - extended FPO data
878 reader
.u
.ds
.root
= reader
.read_file(&reader
, 1);
879 if (reader
.u
.ds
.root
)
885 PDB_STREAM_INDEXES sidx
;
889 "\tTimeDateStamp: %08x\n"
893 reader
.u
.ds
.root
->Version
,
894 reader
.u
.ds
.root
->TimeDateStamp
,
895 reader
.u
.ds
.root
->Age
,
896 get_guid_str(&reader
.u
.ds
.root
->guid
),
897 reader
.u
.ds
.root
->cbNames
);
898 pdw
= (DWORD
*)(&reader
.u
.ds
.root
->names
[0] + reader
.u
.ds
.root
->cbNames
);
901 printf("\tStreams directory:\n"
907 /* bitfield: first dword is len (in dword), then data */
909 pdw
+= *ok_bits
++ + 1;
912 printf("unexpected value\n");
916 for (i
= 0; i
< count
; i
++)
918 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
920 DWORD string_idx
, stream_idx
;
923 printf("\t\t\t%2d) %-20s => %x\n", i
, &reader
.u
.ds
.root
->names
[string_idx
], stream_idx
);
927 if (numok
) printf(">>> unmatched present field with found\n");
929 pdb_dump_types(&reader
);
930 pdb_dump_symbols(&reader
, &sidx
);
931 pdb_dump_fpo(&reader
, sidx
.FPO
);
932 pdb_dump_fpo_ext(&reader
, sidx
.FPO_EXT
);
933 pdb_dump_segments(&reader
, sidx
.segments
);
935 else printf("-Unable to get root\n");
940 enum FileSig
get_kind_pdb(void)
944 head
= PRD(0, sizeof(pdb2
) - 1);
945 if (head
&& !memcmp(head
, pdb2
, sizeof(pdb2
) - 1))
947 head
= PRD(0, sizeof(pdb7
) - 1);
948 if (head
&& !memcmp(head
, pdb7
, sizeof(pdb7
) - 1))
958 head
= PRD(0, sizeof(pdb2
) - 1);
959 if (head
&& !memcmp(head
, pdb2
, sizeof(pdb2
) - 1))
964 head
= PRD(0, sizeof(pdb7
) - 1);
965 if (head
&& !memcmp(head
, pdb7
, sizeof(pdb7
) - 1))
970 printf("Unrecognized header %s\n", head
);