2006-11-29 20:40:58 +00:00
|
|
|
/*
|
|
|
|
* PDB dumping utility
|
|
|
|
*
|
|
|
|
* Copyright 2006 Eric Pouech
|
|
|
|
*
|
|
|
|
* 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
|
2007-05-04 10:08:15 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-11-29 20:40:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winedump.h"
|
|
|
|
|
|
|
|
struct pdb_reader
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
const struct PDB_JG_HEADER* header;
|
|
|
|
const struct PDB_JG_TOC* toc;
|
2011-01-17 20:53:08 +00:00
|
|
|
const struct PDB_JG_ROOT* root;
|
2006-11-29 20:40:58 +00:00
|
|
|
} jg;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
const struct PDB_DS_HEADER* header;
|
|
|
|
const struct PDB_DS_TOC* toc;
|
2011-01-17 20:53:08 +00:00
|
|
|
const struct PDB_DS_ROOT* root;
|
2006-11-29 20:40:58 +00:00
|
|
|
} ds;
|
|
|
|
} u;
|
2007-07-07 16:21:07 +00:00
|
|
|
void* (*read_file)(struct pdb_reader*, DWORD);
|
2006-11-29 20:40:58 +00:00
|
|
|
DWORD file_used[1024];
|
|
|
|
};
|
|
|
|
|
2021-11-10 15:42:14 +00:00
|
|
|
static inline BOOL has_file_been_read(struct pdb_reader* reader, unsigned file_nr)
|
|
|
|
{
|
|
|
|
return reader->file_used[file_nr / 32] & (1 << (file_nr % 32));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mark_file_been_read(struct pdb_reader* reader, unsigned file_nr)
|
|
|
|
{
|
|
|
|
reader->file_used[file_nr / 32] |= 1 << (file_nr % 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear_file_been_read(struct pdb_reader* reader, unsigned file_nr)
|
|
|
|
{
|
|
|
|
reader->file_used[file_nr / 32] &= ~(1 << (file_nr % 32));
|
|
|
|
}
|
|
|
|
|
2007-07-07 16:21:07 +00:00
|
|
|
static void* pdb_jg_read(const struct PDB_JG_HEADER* pdb, const WORD* block_list, int size)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
|
|
|
int i, nBlocks;
|
|
|
|
BYTE* buffer;
|
|
|
|
|
|
|
|
if (!size) return NULL;
|
|
|
|
|
|
|
|
nBlocks = (size + pdb->block_size - 1) / pdb->block_size;
|
2021-09-29 09:14:01 +00:00
|
|
|
buffer = xmalloc(nBlocks * pdb->block_size);
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nBlocks; i++)
|
|
|
|
memcpy(buffer + i * pdb->block_size,
|
|
|
|
(const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2007-07-07 16:21:07 +00:00
|
|
|
static void* pdb_jg_read_file(struct pdb_reader* reader, DWORD file_nr)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
|
|
|
const WORD* block_list;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!reader->u.jg.toc || file_nr >= reader->u.jg.toc->num_files) return NULL;
|
|
|
|
|
2021-11-10 15:42:14 +00:00
|
|
|
mark_file_been_read(reader, file_nr);
|
2006-11-29 20:40:58 +00:00
|
|
|
if (reader->u.jg.toc->file[file_nr].size == 0 ||
|
|
|
|
reader->u.jg.toc->file[file_nr].size == 0xFFFFFFFF)
|
|
|
|
return NULL;
|
|
|
|
block_list = (const WORD*) &reader->u.jg.toc->file[reader->u.jg.toc->num_files];
|
|
|
|
for (i = 0; i < file_nr; i++)
|
|
|
|
block_list += (reader->u.jg.toc->file[i].size +
|
|
|
|
reader->u.jg.header->block_size - 1) / reader->u.jg.header->block_size;
|
|
|
|
|
|
|
|
return pdb_jg_read(reader->u.jg.header, block_list,
|
|
|
|
reader->u.jg.toc->file[file_nr].size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pdb_jg_init(struct pdb_reader* reader)
|
|
|
|
{
|
|
|
|
reader->u.jg.header = PRD(0, sizeof(struct PDB_JG_HEADER));
|
|
|
|
reader->read_file = pdb_jg_read_file;
|
|
|
|
reader->u.jg.toc = pdb_jg_read(reader->u.jg.header,
|
|
|
|
reader->u.jg.header->toc_block,
|
|
|
|
reader->u.jg.header->toc.size);
|
|
|
|
memset(reader->file_used, 0, sizeof(reader->file_used));
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD pdb_get_num_files(const struct pdb_reader* reader)
|
|
|
|
{
|
|
|
|
if (reader->read_file == pdb_jg_read_file)
|
|
|
|
return reader->u.jg.toc->num_files;
|
|
|
|
else
|
|
|
|
return reader->u.ds.toc->num_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD pdb_get_file_size(const struct pdb_reader* reader, unsigned idx)
|
|
|
|
{
|
|
|
|
if (reader->read_file == pdb_jg_read_file)
|
|
|
|
return reader->u.jg.toc->file[idx].size;
|
|
|
|
else
|
|
|
|
return reader->u.ds.toc->file_size[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pdb_exit(struct pdb_reader* reader)
|
|
|
|
{
|
2022-04-22 14:33:11 +00:00
|
|
|
unsigned i, size;
|
2007-07-07 16:21:07 +00:00
|
|
|
unsigned char* file;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < pdb_get_num_files(reader); i++)
|
|
|
|
{
|
2021-11-10 15:42:14 +00:00
|
|
|
if (has_file_been_read(reader, i)) continue;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
file = reader->read_file(reader, i);
|
|
|
|
if (!file) continue;
|
|
|
|
|
|
|
|
size = pdb_get_file_size(reader, i);
|
|
|
|
|
|
|
|
printf("File --unused-- #%d (%x)\n", i, size);
|
2006-12-07 13:42:44 +00:00
|
|
|
dump_data(file, size, " ");
|
2007-07-07 16:21:07 +00:00
|
|
|
free(file);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
2014-01-11 12:53:26 +00:00
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
if (reader->read_file == pdb_jg_read_file)
|
2011-01-17 20:53:08 +00:00
|
|
|
{
|
|
|
|
free((char*)reader->u.jg.root);
|
2006-11-29 20:40:58 +00:00
|
|
|
free((char*)reader->u.jg.toc);
|
2011-01-17 20:53:08 +00:00
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
else
|
2011-01-17 20:53:08 +00:00
|
|
|
{
|
|
|
|
free((char*)reader->u.ds.root);
|
2006-11-29 20:40:58 +00:00
|
|
|
free((char*)reader->u.ds.toc);
|
2011-01-17 20:53:08 +00:00
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 20:53:20 +00:00
|
|
|
static unsigned get_stream_by_name(struct pdb_reader* reader, const char* name)
|
|
|
|
{
|
|
|
|
DWORD* pdw;
|
|
|
|
DWORD* ok_bits;
|
|
|
|
DWORD cbstr, count;
|
|
|
|
DWORD string_idx, stream_idx;
|
|
|
|
unsigned i;
|
|
|
|
const char* str;
|
|
|
|
|
|
|
|
if (reader->read_file == pdb_jg_read_file)
|
|
|
|
{
|
2012-07-23 08:37:06 +00:00
|
|
|
str = reader->u.jg.root->names;
|
2011-01-17 20:53:20 +00:00
|
|
|
cbstr = reader->u.jg.root->cbNames;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-23 08:37:06 +00:00
|
|
|
str = reader->u.ds.root->names;
|
2011-01-17 20:53:20 +00:00
|
|
|
cbstr = reader->u.ds.root->cbNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdw = (DWORD*)(str + cbstr);
|
|
|
|
pdw++; /* number of ok entries */
|
|
|
|
count = *pdw++;
|
|
|
|
|
|
|
|
/* bitfield: first dword is len (in dword), then data */
|
|
|
|
ok_bits = pdw;
|
|
|
|
pdw += *ok_bits++ + 1;
|
|
|
|
if (*pdw++ != 0)
|
|
|
|
{
|
|
|
|
printf("unexpected value\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (ok_bits[i / 32] & (1 << (i % 32)))
|
|
|
|
{
|
|
|
|
string_idx = *pdw++;
|
|
|
|
stream_idx = *pdw++;
|
|
|
|
if (!strcmp(name, &str[string_idx])) return stream_idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-09-09 15:06:04 +00:00
|
|
|
static PDB_STRING_TABLE* read_string_table(struct pdb_reader* reader)
|
2011-01-12 09:45:54 +00:00
|
|
|
{
|
2022-09-09 15:06:04 +00:00
|
|
|
unsigned stream_idx;
|
|
|
|
PDB_STRING_TABLE* ret;
|
|
|
|
unsigned stream_size;
|
2011-01-12 09:45:54 +00:00
|
|
|
|
2011-01-17 20:53:20 +00:00
|
|
|
stream_idx = get_stream_by_name(reader, "/names");
|
|
|
|
if (stream_idx == -1) return NULL;
|
|
|
|
ret = reader->read_file(reader, stream_idx);
|
2017-10-03 15:28:08 +00:00
|
|
|
if (!ret) return NULL;
|
2022-09-09 15:06:04 +00:00
|
|
|
stream_size = pdb_get_file_size(reader, stream_idx);
|
|
|
|
if (ret->magic == 0xeffeeffe && sizeof(*ret) + ret->length < stream_size) return ret;
|
|
|
|
printf("Improper string table header (magic=%x)\n", ret->magic);
|
|
|
|
dump_data((const unsigned char*)ret, stream_size, " ");
|
2011-01-12 09:45:54 +00:00
|
|
|
free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-09-09 15:06:04 +00:00
|
|
|
const char* pdb_get_string_table_entry(const PDB_STRING_TABLE* table, unsigned ofs)
|
|
|
|
{
|
|
|
|
if (!table) return "<<no string table>>";
|
|
|
|
if (ofs >= table->length) return "<<invalid string table offset>>";
|
|
|
|
/* strings start after header */
|
|
|
|
return (char*)(table + 1) + ofs;
|
|
|
|
}
|
|
|
|
|
2022-09-27 09:22:11 +00:00
|
|
|
static void dump_dbi_hash_table(const BYTE* root, unsigned size, const char* name, const char* pfx)
|
|
|
|
{
|
|
|
|
if (size >= sizeof(DBI_HASH_HEADER))
|
|
|
|
{
|
|
|
|
const DBI_HASH_HEADER* hdr = (const DBI_HASH_HEADER*)root;
|
|
|
|
|
|
|
|
printf("%s%s symbols hash:\n", pfx, name);
|
|
|
|
printf("%s\tSignature: 0x%x\n", pfx, hdr->signature);
|
|
|
|
printf("%s\tVersion: 0x%x (%u)\n", pfx, hdr->version, hdr->version - 0xeffe0000);
|
|
|
|
printf("%s\tSize of hash records: %u\n", pfx, hdr->size_hash_records);
|
|
|
|
printf("%s\tUnknown: %u\n", pfx, hdr->unknown);
|
|
|
|
|
|
|
|
if (hdr->signature != 0xFFFFFFFF ||
|
|
|
|
hdr->version != 0xeffe0000 + 19990810 ||
|
|
|
|
(hdr->size_hash_records % sizeof(DBI_HASH_RECORD)) != 0 ||
|
|
|
|
sizeof(DBI_HASH_HEADER) + hdr->size_hash_records + DBI_BITMAP_HASH_SIZE > size ||
|
|
|
|
(size - (sizeof(DBI_HASH_HEADER) + hdr->size_hash_records + DBI_BITMAP_HASH_SIZE)) % sizeof(unsigned))
|
|
|
|
{
|
|
|
|
printf("%s\t\tIncorrect hash structure\n", pfx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
unsigned num_hash_records = hdr->size_hash_records / sizeof(DBI_HASH_RECORD);
|
|
|
|
const DBI_HASH_RECORD* hr = (const DBI_HASH_RECORD*)(hdr + 1);
|
|
|
|
unsigned* bitmap = (unsigned*)((char*)(hdr + 1) + hdr->size_hash_records);
|
|
|
|
unsigned* buckets = (unsigned*)((char*)(hdr + 1) + hdr->size_hash_records + DBI_BITMAP_HASH_SIZE);
|
|
|
|
unsigned index, last_index = (size - (sizeof(DBI_HASH_HEADER) + hdr->size_hash_records + DBI_BITMAP_HASH_SIZE)) / sizeof(unsigned);
|
|
|
|
|
|
|
|
/* Yes, offsets for accessiong hr[] are stored as multiple of 12; and not
|
|
|
|
* as multiple of sizeof(*hr) = 8 as one might expect.
|
|
|
|
* Perhaps, native implementation likes to keep the same offsets between
|
|
|
|
* in memory representation vs on file representations.
|
|
|
|
*/
|
|
|
|
for (index = 0, i = 0; i <= DBI_MAX_HASH; i++)
|
|
|
|
{
|
|
|
|
if (bitmap[i / 32] & (1u << (i % 32)))
|
|
|
|
{
|
|
|
|
unsigned j;
|
|
|
|
printf("%s\t[%u]\n", pfx, i);
|
|
|
|
for (j = buckets[index] / 12; j < (index + 1 < last_index ? buckets[index + 1] / 12 : num_hash_records); j++)
|
|
|
|
printf("%s\t\t[%u] offset=%08x unk=%x\n", pfx, j, hr[j].offset - 1, hr[j].unknown);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("%s\t[%u] <<empty>>\n", pfx, i);
|
|
|
|
}
|
|
|
|
/* shouldn't happen */
|
|
|
|
if (sizeof(DBI_HASH_HEADER) + hdr->size_hash_records + DBI_BITMAP_HASH_SIZE + index * sizeof(unsigned) > size)
|
|
|
|
{
|
|
|
|
printf("%s-- left over %u bytes\n", pfx,
|
|
|
|
size - (unsigned)(sizeof(DBI_HASH_HEADER) + hdr->size_hash_records + DBI_BITMAP_HASH_SIZE + index * sizeof(unsigned)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("%sNo header in symbols hash\n", pfx);
|
|
|
|
}
|
|
|
|
|
2021-08-24 09:12:45 +00:00
|
|
|
static void dump_global_symbol(struct pdb_reader* reader, unsigned file)
|
|
|
|
{
|
|
|
|
void* global = NULL;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
global = reader->read_file(reader, file);
|
|
|
|
if (!global) return;
|
|
|
|
|
|
|
|
size = pdb_get_file_size(reader, file);
|
|
|
|
|
2022-09-27 09:22:11 +00:00
|
|
|
dump_dbi_hash_table(global, size, "Global", "");
|
2021-08-24 09:12:45 +00:00
|
|
|
free(global);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_public_symbol(struct pdb_reader* reader, unsigned file)
|
|
|
|
{
|
2022-09-27 09:22:12 +00:00
|
|
|
unsigned size;
|
|
|
|
DBI_PUBLIC_HEADER* hdr;
|
2021-08-24 09:12:45 +00:00
|
|
|
|
2022-09-27 09:22:12 +00:00
|
|
|
hdr = reader->read_file(reader, file);
|
|
|
|
if (!hdr) return;
|
2021-08-24 09:12:45 +00:00
|
|
|
|
|
|
|
size = pdb_get_file_size(reader, file);
|
|
|
|
|
2022-09-27 09:22:12 +00:00
|
|
|
printf("Public symbols table: (%u)\n", size);
|
|
|
|
|
|
|
|
printf("\tHash size: %u\n", hdr->hash_size);
|
|
|
|
printf("\tAddress map size: %u\n", hdr->address_map_size);
|
|
|
|
printf("\tNumber of thunks: %u\n", hdr->num_thunks);
|
|
|
|
printf("\tSize of thunk: %u\n", hdr->size_thunk);
|
|
|
|
printf("\tSection of thunk table: %u\n", hdr->section_thunk_table);
|
|
|
|
printf("\tOffset of thunk table: %u\n", hdr->offset_thunk_table);
|
|
|
|
printf("\tNumber of sections: %u\n", hdr->num_sects);
|
|
|
|
|
|
|
|
dump_dbi_hash_table((const BYTE*)(hdr + 1), hdr->hash_size, "Public", "\t");
|
|
|
|
free(hdr);
|
2021-08-24 09:12:45 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
static void pdb_dump_symbols(struct pdb_reader* reader, PDB_STREAM_INDEXES* sidx)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
2022-09-09 15:06:04 +00:00
|
|
|
PDB_SYMBOLS* symbols;
|
|
|
|
unsigned char* modimage;
|
|
|
|
const char* file;
|
|
|
|
PDB_STRING_TABLE* filesimage;
|
|
|
|
char tcver[32];
|
2006-11-29 20:40:58 +00:00
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
sidx->FPO = sidx->unk0 = sidx->unk1 = sidx->unk2 = sidx->unk3 = sidx->segments =
|
|
|
|
sidx->unk4 = sidx->unk5 = sidx->unk6 = sidx->FPO_EXT = sidx->unk7 = -1;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
symbols = reader->read_file(reader, 3);
|
2006-11-29 20:40:58 +00:00
|
|
|
if (!symbols) return;
|
|
|
|
|
|
|
|
switch (symbols->version)
|
|
|
|
{
|
|
|
|
case 0: /* VC 4.0 */
|
|
|
|
case 19960307: /* VC 5.0 */
|
|
|
|
case 19970606: /* VC 6.0 */
|
2008-04-30 19:26:04 +00:00
|
|
|
case 19990903: /* VC 7.0 */
|
2006-11-29 20:40:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("-Unknown symbol info version %d\n", symbols->version);
|
|
|
|
}
|
2021-08-24 09:12:45 +00:00
|
|
|
if (symbols->flags & 0x8000) /* new */
|
2021-10-06 08:16:59 +00:00
|
|
|
sprintf(tcver, "%u.%u", (symbols->flags >> 8) & 0x7f, symbols->flags & 0xff);
|
2021-08-24 09:12:45 +00:00
|
|
|
else
|
2021-10-06 08:16:59 +00:00
|
|
|
sprintf(tcver, "old-%x", symbols->flags);
|
2006-11-29 20:40:58 +00:00
|
|
|
printf("Symbols:\n"
|
2022-09-27 09:22:11 +00:00
|
|
|
"\tsignature: %08x\n"
|
|
|
|
"\tversion: %u\n"
|
|
|
|
"\tage: %08x\n"
|
|
|
|
"\tglobal_hash_file: %u\n"
|
|
|
|
"\tbuilder: %s\n"
|
|
|
|
"\tpublic_file: %u\n"
|
|
|
|
"\tbldVer: %u\n"
|
|
|
|
"\tgsym_file: %u\n"
|
|
|
|
"\trbldVer: %u\n"
|
|
|
|
"\tmodule_size: %08x\n"
|
|
|
|
"\toffset_size: %08x\n"
|
|
|
|
"\thash_size: %08x\n"
|
|
|
|
"\tsrc_module_size: %08x\n"
|
|
|
|
"\tpdbimport_size: %08x\n"
|
|
|
|
"\tresvd0: %08x\n"
|
|
|
|
"\tstream_idx_size: %08x\n"
|
|
|
|
"\tunknown2_size: %08x\n"
|
|
|
|
"\tresvd3: %04x\n"
|
|
|
|
"\tmachine: %s\n"
|
|
|
|
"\tresvd4 %08x\n",
|
2006-11-29 20:40:58 +00:00
|
|
|
symbols->signature,
|
|
|
|
symbols->version,
|
2021-08-24 09:12:45 +00:00
|
|
|
symbols->age,
|
2022-09-27 09:22:11 +00:00
|
|
|
symbols->global_hash_file,
|
2021-08-24 09:12:45 +00:00
|
|
|
tcver, /* from symbols->flags */
|
|
|
|
symbols->public_file,
|
|
|
|
symbols->bldVer,
|
2006-11-29 20:40:58 +00:00
|
|
|
symbols->gsym_file,
|
2021-08-24 09:12:45 +00:00
|
|
|
symbols->rbldVer,
|
2006-11-29 20:40:58 +00:00
|
|
|
symbols->module_size,
|
|
|
|
symbols->offset_size,
|
|
|
|
symbols->hash_size,
|
|
|
|
symbols->srcmodule_size,
|
2009-10-31 13:56:29 +00:00
|
|
|
symbols->pdbimport_size,
|
2011-01-17 20:53:25 +00:00
|
|
|
symbols->resvd0,
|
|
|
|
symbols->stream_index_size,
|
|
|
|
symbols->unknown2_size,
|
2011-01-11 15:17:27 +00:00
|
|
|
symbols->resvd3,
|
|
|
|
get_machine_str( symbols->machine ),
|
|
|
|
symbols->resvd4);
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
if (symbols->offset_size)
|
|
|
|
{
|
|
|
|
const BYTE* src;
|
|
|
|
|
|
|
|
printf("\t----------offsets------------\n");
|
|
|
|
src = (const BYTE*)((const char*)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size);
|
2006-12-07 13:42:44 +00:00
|
|
|
dump_data(src, symbols->offset_size, " ");
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 09:45:54 +00:00
|
|
|
if (!(filesimage = read_string_table(reader))) printf("string table not found\n");
|
2008-09-29 19:32:21 +00:00
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
if (symbols->srcmodule_size)
|
|
|
|
{
|
|
|
|
const PDB_SYMBOL_SOURCE*src;
|
2008-04-30 19:25:41 +00:00
|
|
|
int i, j, cfile;
|
|
|
|
const WORD* indx;
|
2006-11-29 20:40:58 +00:00
|
|
|
const DWORD* offset;
|
2008-04-30 19:25:41 +00:00
|
|
|
const char* start_cstr;
|
2006-11-29 20:40:58 +00:00
|
|
|
const char* cstr;
|
|
|
|
|
|
|
|
printf("\t----------src module------------\n");
|
|
|
|
src = (const PDB_SYMBOL_SOURCE*)((const char*)symbols + sizeof(PDB_SYMBOLS) +
|
|
|
|
symbols->module_size + symbols->offset_size + symbols->hash_size);
|
|
|
|
printf("\tSource Modules\n"
|
|
|
|
"\t\tnModules: %u\n"
|
2008-04-30 19:25:41 +00:00
|
|
|
"\t\tnSrcFiles: %u\n",
|
2006-11-29 20:40:58 +00:00
|
|
|
src->nModules, src->nSrcFiles);
|
|
|
|
|
|
|
|
/* usage of table seems to be as follows:
|
|
|
|
* two arrays of WORD (src->nModules as size)
|
2008-04-30 19:25:41 +00:00
|
|
|
* - first array contains index into files for "module" compilation
|
|
|
|
* (module = compilation unit ??)
|
|
|
|
* - second array contains the number of source files in module
|
|
|
|
* an array of DWORD (src->nSrcFiles as size)
|
2006-11-29 20:40:58 +00:00
|
|
|
* - contains offset (in following string table) of the source file name
|
2008-04-30 19:25:41 +00:00
|
|
|
* a string table
|
|
|
|
* - each string is a pascal string (ie. with its length as first BYTE) or
|
|
|
|
* 0-terminated string (depending on version)
|
2006-11-29 20:40:58 +00:00
|
|
|
*/
|
2008-04-30 19:25:41 +00:00
|
|
|
indx = &src->table[src->nModules];
|
2006-11-29 20:40:58 +00:00
|
|
|
offset = (const DWORD*)&src->table[2 * src->nModules];
|
|
|
|
cstr = (const char*)&src->table[2 * (src->nModules + src->nSrcFiles)];
|
2008-04-30 19:25:41 +00:00
|
|
|
start_cstr = cstr;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
2008-04-30 19:25:41 +00:00
|
|
|
for (i = cfile = 0; i < src->nModules; i++)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
2008-04-30 19:25:41 +00:00
|
|
|
printf("\t\tModule[%2d]:\n", i);
|
2011-01-11 13:18:35 +00:00
|
|
|
cfile = src->table[i];
|
|
|
|
for (j = cfile; j < src->nSrcFiles && j < cfile + indx[i]; j++)
|
2008-04-30 19:25:41 +00:00
|
|
|
{
|
|
|
|
/* FIXME: in some cases, it's a p_string but WHEN ? */
|
2019-03-01 20:08:20 +00:00
|
|
|
if (cstr + offset[j] >= start_cstr /* wrap around */ &&
|
2011-01-11 13:18:35 +00:00
|
|
|
cstr + offset[j] < (const char*)src + symbols->srcmodule_size)
|
|
|
|
printf("\t\t\tSource file: %s\n", cstr + offset[j]);
|
2008-04-30 19:25:41 +00:00
|
|
|
else
|
|
|
|
printf("\t\t\tSource file: <<out of bounds>>\n");
|
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (symbols->pdbimport_size)
|
|
|
|
{
|
|
|
|
const PDB_SYMBOL_IMPORT* imp;
|
|
|
|
const char* first;
|
|
|
|
const char* last;
|
|
|
|
const char* ptr;
|
|
|
|
|
|
|
|
printf("\t------------import--------------\n");
|
|
|
|
imp = (const PDB_SYMBOL_IMPORT*)((const char*)symbols + sizeof(PDB_SYMBOLS) +
|
|
|
|
symbols->module_size + symbols->offset_size +
|
|
|
|
symbols->hash_size + symbols->srcmodule_size);
|
|
|
|
first = (const char*)imp;
|
|
|
|
last = (const char*)imp + symbols->pdbimport_size;
|
|
|
|
while (imp < (const PDB_SYMBOL_IMPORT*)last)
|
|
|
|
{
|
|
|
|
ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
|
2007-05-21 06:56:31 +00:00
|
|
|
printf("\tImport: %lx\n"
|
2006-11-29 20:40:58 +00:00
|
|
|
"\t\tUnknown1: %08x\n"
|
|
|
|
"\t\tUnknown2: %08x\n"
|
|
|
|
"\t\tTimeDateStamp: %08x\n"
|
|
|
|
"\t\tAge: %08u\n"
|
|
|
|
"\t\tfile1: %s\n"
|
|
|
|
"\t\tfile2: %s\n",
|
2019-03-01 20:08:20 +00:00
|
|
|
(ULONG_PTR)((const char*)imp - first),
|
2006-11-29 20:40:58 +00:00
|
|
|
imp->unknown1,
|
|
|
|
imp->unknown2,
|
|
|
|
imp->TimeDateStamp,
|
|
|
|
imp->Age,
|
|
|
|
imp->filename,
|
|
|
|
ptr);
|
|
|
|
imp = (const PDB_SYMBOL_IMPORT*)(first + ((ptr - first + strlen(ptr) + 1 + 3) & ~3));
|
|
|
|
}
|
|
|
|
}
|
2011-01-17 20:53:25 +00:00
|
|
|
if (symbols->stream_index_size)
|
|
|
|
{
|
|
|
|
printf("\t------------stream indexes--------------\n");
|
|
|
|
switch (symbols->stream_index_size)
|
|
|
|
{
|
|
|
|
case sizeof(PDB_STREAM_INDEXES_OLD):
|
2011-01-17 20:53:31 +00:00
|
|
|
/* PDB_STREAM_INDEXES is a superset of PDB_STREAM_INDEX_OLD
|
|
|
|
* FIXME: to be confirmed when all fields are fully understood
|
|
|
|
*/
|
|
|
|
memcpy(sidx,
|
|
|
|
(const char*)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size +
|
|
|
|
symbols->offset_size + symbols->hash_size + symbols->srcmodule_size +
|
|
|
|
symbols->pdbimport_size + symbols->unknown2_size,
|
|
|
|
sizeof(PDB_STREAM_INDEXES_OLD));
|
2011-01-17 20:53:25 +00:00
|
|
|
printf("\tFPO: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\tSegments: %04x\n",
|
2011-01-17 20:53:31 +00:00
|
|
|
sidx->FPO, sidx->unk0, sidx->unk1, sidx->unk2, sidx->unk3,
|
|
|
|
sidx->segments);
|
2011-01-17 20:53:25 +00:00
|
|
|
break;
|
|
|
|
case sizeof(PDB_STREAM_INDEXES):
|
2011-01-17 20:53:31 +00:00
|
|
|
memcpy(sidx,
|
|
|
|
(const char*)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size +
|
|
|
|
symbols->offset_size + symbols->hash_size + symbols->srcmodule_size +
|
|
|
|
symbols->pdbimport_size + symbols->unknown2_size,
|
|
|
|
sizeof(*sidx));
|
2011-01-17 20:53:25 +00:00
|
|
|
printf("\tFPO: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\tSegments: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\t?: %04x\n"
|
|
|
|
"\tFPO-ext: %04x\n"
|
|
|
|
"\t?: %04x\n",
|
|
|
|
sidx->FPO, sidx->unk0, sidx->unk1, sidx->unk2, sidx->unk3,
|
|
|
|
sidx->segments, sidx->unk4, sidx->unk5, sidx->unk6, sidx->FPO_EXT,
|
|
|
|
sidx->unk7);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unexpected size for stream index %d\n", symbols->stream_index_size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
/* Read global symbol table */
|
|
|
|
modimage = reader->read_file(reader, symbols->gsym_file);
|
2006-11-29 20:41:05 +00:00
|
|
|
if (modimage)
|
|
|
|
{
|
|
|
|
printf("\t------------globals-------------\n");
|
2021-11-10 15:42:55 +00:00
|
|
|
codeview_dump_symbols(modimage, 0, pdb_get_file_size(reader, symbols->gsym_file));
|
2007-07-07 16:21:07 +00:00
|
|
|
free(modimage);
|
2006-11-29 20:41:05 +00:00
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
/* Read per-module symbol / linenumber tables */
|
|
|
|
file = (const char*)symbols + sizeof(PDB_SYMBOLS);
|
|
|
|
while (file - (const char*)symbols < sizeof(PDB_SYMBOLS) + symbols->module_size)
|
|
|
|
{
|
2021-11-02 14:31:16 +00:00
|
|
|
int file_nr, symbol_size, lineno_size, lineno2_size;
|
2006-11-29 20:40:58 +00:00
|
|
|
const char* file_name;
|
2021-11-02 14:32:10 +00:00
|
|
|
const char* lib_name;
|
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
if (symbols->version < 19970000)
|
|
|
|
{
|
|
|
|
const PDB_SYMBOL_FILE* sym_file = (const PDB_SYMBOL_FILE*) file;
|
|
|
|
file_nr = sym_file->file;
|
|
|
|
file_name = sym_file->filename;
|
2021-11-02 14:32:10 +00:00
|
|
|
lib_name = file_name + strlen(file_name) + 1;
|
2006-11-29 20:40:58 +00:00
|
|
|
symbol_size = sym_file->symbol_size;
|
|
|
|
lineno_size = sym_file->lineno_size;
|
2021-11-02 14:31:16 +00:00
|
|
|
lineno2_size = sym_file->lineno2_size;
|
2021-11-02 14:32:10 +00:00
|
|
|
printf("\t--------symbol file-----------\n");
|
|
|
|
printf("\tName: %s\n", file_name);
|
|
|
|
if (strcmp(file_name, lib_name)) printf("\tLibrary: %s\n", lib_name);
|
|
|
|
printf("\t\tunknown1: %08x\n"
|
2006-11-29 20:41:05 +00:00
|
|
|
"\t\trange\n"
|
|
|
|
"\t\t\tsegment: %04x\n"
|
|
|
|
"\t\t\tpad1: %04x\n"
|
|
|
|
"\t\t\toffset: %08x\n"
|
|
|
|
"\t\t\tsize: %08x\n"
|
|
|
|
"\t\t\tcharacteristics: %08x\n"
|
|
|
|
"\t\t\tindex: %04x\n"
|
|
|
|
"\t\t\tpad2: %04x\n"
|
|
|
|
"\t\tflag: %04x\n"
|
|
|
|
"\t\tfile: %04x\n"
|
|
|
|
"\t\tsymb size: %08x\n"
|
|
|
|
"\t\tline size: %08x\n"
|
2021-11-02 14:31:16 +00:00
|
|
|
"\t\tline2 size: %08x\n"
|
2006-11-29 20:41:05 +00:00
|
|
|
"\t\tnSrcFiles: %08x\n"
|
|
|
|
"\t\tattribute: %08x\n",
|
|
|
|
sym_file->unknown1,
|
|
|
|
sym_file->range.segment,
|
|
|
|
sym_file->range.pad1,
|
|
|
|
sym_file->range.offset,
|
|
|
|
sym_file->range.size,
|
|
|
|
sym_file->range.characteristics,
|
|
|
|
sym_file->range.index,
|
|
|
|
sym_file->range.pad2,
|
|
|
|
sym_file->flag,
|
|
|
|
sym_file->file,
|
|
|
|
sym_file->symbol_size,
|
|
|
|
sym_file->lineno_size,
|
2021-11-02 14:31:16 +00:00
|
|
|
sym_file->lineno2_size,
|
2006-11-29 20:41:05 +00:00
|
|
|
sym_file->nSrcFiles,
|
|
|
|
sym_file->attribute);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const PDB_SYMBOL_FILE_EX* sym_file = (const PDB_SYMBOL_FILE_EX*) file;
|
2021-11-02 14:32:10 +00:00
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
file_nr = sym_file->file;
|
|
|
|
file_name = sym_file->filename;
|
2021-11-02 14:32:10 +00:00
|
|
|
lib_name = file_name + strlen(file_name) + 1;
|
2006-11-29 20:40:58 +00:00
|
|
|
symbol_size = sym_file->symbol_size;
|
|
|
|
lineno_size = sym_file->lineno_size;
|
2021-11-02 14:31:16 +00:00
|
|
|
lineno2_size = sym_file->lineno2_size;
|
2021-11-02 14:32:10 +00:00
|
|
|
printf("\t--------symbol file-----------\n");
|
|
|
|
printf("\tName: %s\n", file_name);
|
|
|
|
if (strcmp(file_name, lib_name)) printf("\tLibrary: %s\n", lib_name);
|
2009-03-08 22:48:03 +00:00
|
|
|
printf("\t\tunknown1: %08x\n"
|
2006-11-29 20:40:58 +00:00
|
|
|
"\t\trange\n"
|
|
|
|
"\t\t\tsegment: %04x\n"
|
|
|
|
"\t\t\tpad1: %04x\n"
|
|
|
|
"\t\t\toffset: %08x\n"
|
|
|
|
"\t\t\tsize: %08x\n"
|
|
|
|
"\t\t\tcharacteristics: %08x\n"
|
|
|
|
"\t\t\tindex: %04x\n"
|
|
|
|
"\t\t\tpad2: %04x\n"
|
|
|
|
"\t\t\ttimestamp: %08x\n"
|
|
|
|
"\t\t\tunknown: %08x\n"
|
|
|
|
"\t\tflag: %04x\n"
|
|
|
|
"\t\tfile: %04x\n"
|
|
|
|
"\t\tsymb size: %08x\n"
|
|
|
|
"\t\tline size: %08x\n"
|
2021-11-02 14:31:16 +00:00
|
|
|
"\t\tline2 size: %08x\n"
|
2006-11-29 20:40:58 +00:00
|
|
|
"\t\tnSrcFiles: %08x\n"
|
|
|
|
"\t\tattribute: %08x\n"
|
|
|
|
"\t\treserved/0: %08x\n"
|
|
|
|
"\t\treserved/1: %08x\n",
|
|
|
|
sym_file->unknown1,
|
|
|
|
sym_file->range.segment,
|
|
|
|
sym_file->range.pad1,
|
|
|
|
sym_file->range.offset,
|
|
|
|
sym_file->range.size,
|
|
|
|
sym_file->range.characteristics,
|
|
|
|
sym_file->range.index,
|
|
|
|
sym_file->range.pad2,
|
|
|
|
sym_file->range.timestamp,
|
|
|
|
sym_file->range.unknown,
|
|
|
|
sym_file->flag,
|
|
|
|
sym_file->file,
|
|
|
|
sym_file->symbol_size,
|
|
|
|
sym_file->lineno_size,
|
2021-11-02 14:31:16 +00:00
|
|
|
sym_file->lineno2_size,
|
2006-11-29 20:40:58 +00:00
|
|
|
sym_file->nSrcFiles,
|
|
|
|
sym_file->attribute,
|
|
|
|
sym_file->reserved[0],
|
|
|
|
sym_file->reserved[1]);
|
|
|
|
}
|
|
|
|
modimage = reader->read_file(reader, file_nr);
|
|
|
|
if (modimage)
|
|
|
|
{
|
|
|
|
int total_size = pdb_get_file_size(reader, file_nr);
|
2006-11-29 20:41:05 +00:00
|
|
|
|
|
|
|
if (symbol_size)
|
2021-11-10 15:42:55 +00:00
|
|
|
codeview_dump_symbols((const char*)modimage, sizeof(DWORD), symbol_size);
|
2006-12-07 13:42:44 +00:00
|
|
|
|
2008-09-29 19:32:09 +00:00
|
|
|
/* line number info */
|
|
|
|
if (lineno_size)
|
2011-12-11 08:25:16 +00:00
|
|
|
codeview_dump_linetab((const char*)modimage + symbol_size, TRUE, " ");
|
2021-11-02 14:31:16 +00:00
|
|
|
else if (lineno2_size) /* actually, only one of the 2 lineno should be present */
|
|
|
|
codeview_dump_linetab2((const char*)modimage + symbol_size, lineno2_size,
|
2022-09-09 15:06:04 +00:00
|
|
|
filesimage, " ");
|
2006-11-29 20:41:05 +00:00
|
|
|
/* what's that part ??? */
|
|
|
|
if (0)
|
2021-11-02 14:31:16 +00:00
|
|
|
dump_data(modimage + symbol_size + lineno_size + lineno2_size,
|
|
|
|
total_size - (symbol_size + lineno_size + lineno2_size), " ");
|
2007-07-07 16:21:07 +00:00
|
|
|
free(modimage);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
2006-12-07 13:42:44 +00:00
|
|
|
|
2021-11-02 14:32:10 +00:00
|
|
|
file = (char*)((DWORD_PTR)(lib_name + strlen(lib_name) + 1 + 3) & ~3);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
2022-09-27 09:22:11 +00:00
|
|
|
dump_global_symbol(reader, symbols->global_hash_file);
|
2021-08-24 09:12:45 +00:00
|
|
|
dump_public_symbol(reader, symbols->public_file);
|
2022-09-27 09:22:11 +00:00
|
|
|
|
2007-07-07 16:21:07 +00:00
|
|
|
free(symbols);
|
2008-09-29 19:32:21 +00:00
|
|
|
free(filesimage);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 14:28:08 +00:00
|
|
|
static BOOL is_bit_set(const unsigned* dw, unsigned len, unsigned i)
|
2021-08-24 09:12:33 +00:00
|
|
|
{
|
2022-06-22 14:28:08 +00:00
|
|
|
if (i >= len * sizeof(unsigned) * 8) return FALSE;
|
|
|
|
return (dw[i >> 5] & (1u << (i & 31u))) != 0;
|
|
|
|
}
|
2021-08-24 09:12:33 +00:00
|
|
|
|
2022-06-22 14:28:08 +00:00
|
|
|
static void pdb_dump_hash_value(const BYTE* ptr, unsigned len)
|
|
|
|
{
|
|
|
|
int i;
|
2021-08-24 09:12:33 +00:00
|
|
|
|
2022-06-22 14:28:08 +00:00
|
|
|
printf("[");
|
|
|
|
for (i = len - 1; i >= 0; i--)
|
|
|
|
printf("%02x", ptr[i]);
|
|
|
|
printf("]");
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const BYTE* hash;
|
|
|
|
unsigned hash_size;
|
|
|
|
} collision_arg;
|
|
|
|
|
|
|
|
static int collision_compar(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
unsigned idx1 = *(unsigned*)p1;
|
|
|
|
unsigned idx2 = *(unsigned*)p2;
|
|
|
|
return memcmp(collision_arg.hash + idx1 * collision_arg.hash_size,
|
|
|
|
collision_arg.hash + idx2 * collision_arg.hash_size,
|
|
|
|
collision_arg.hash_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pdb_dump_types_hash(struct pdb_reader* reader, const PDB_TYPES* types, const char* strmname)
|
|
|
|
{
|
|
|
|
void* hash = NULL;
|
|
|
|
unsigned i, strmsize;
|
|
|
|
const unsigned* table;
|
2022-09-09 15:06:04 +00:00
|
|
|
PDB_STRING_TABLE* strbase;
|
2022-06-22 14:28:08 +00:00
|
|
|
unsigned *collision;
|
|
|
|
hash = reader->read_file(reader, types->hash_file);
|
|
|
|
if (!hash) return;
|
2021-08-24 09:12:33 +00:00
|
|
|
|
|
|
|
printf("Types (%s) hash:\n", strmname);
|
2022-06-22 14:28:08 +00:00
|
|
|
strmsize = pdb_get_file_size(reader, types->hash_file);
|
|
|
|
if (types->hash_offset + types->hash_len > strmsize ||
|
|
|
|
(types->last_index - types->first_index) * types->hash_size != types->hash_len ||
|
|
|
|
types->search_offset + types->search_len > strmsize ||
|
|
|
|
types->type_remap_offset + types->type_remap_len > strmsize)
|
|
|
|
{
|
|
|
|
printf("\nIncoherent sizes... skipping\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("\n\tIndexes => hash value:\n");
|
|
|
|
for (i = types->first_index; i < types->last_index; i++)
|
|
|
|
{
|
|
|
|
printf("\t\t%08x => ", i);
|
|
|
|
pdb_dump_hash_value((const BYTE*)hash + types->hash_offset + (i - types->first_index) * types->hash_size, types->hash_size);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
/* print collisions in hash table (if any) */
|
|
|
|
collision = malloc((types->last_index - types->first_index) * sizeof(unsigned));
|
|
|
|
if (collision)
|
|
|
|
{
|
|
|
|
unsigned head_printed = 0;
|
|
|
|
|
|
|
|
collision_arg.hash = (const BYTE*)hash + types->hash_offset;
|
|
|
|
collision_arg.hash_size = types->hash_size;
|
|
|
|
|
|
|
|
for (i = 0; i < types->last_index - types->first_index; i++) collision[i] = i;
|
|
|
|
qsort(collision, types->last_index - types->first_index, sizeof(unsigned), collision_compar);
|
|
|
|
for (i = 0; i < types->last_index - types->first_index; i++)
|
|
|
|
{
|
|
|
|
unsigned j;
|
|
|
|
for (j = i + 1; j < types->last_index - types->first_index; j++)
|
|
|
|
if (memcmp((const BYTE*)hash + types->hash_offset + collision[i] * types->hash_size,
|
|
|
|
(const BYTE*)hash + types->hash_offset + collision[j] * types->hash_size,
|
|
|
|
types->hash_size))
|
|
|
|
break;
|
|
|
|
if (j > i + 1)
|
|
|
|
{
|
|
|
|
unsigned k;
|
|
|
|
if (!head_printed)
|
|
|
|
{
|
|
|
|
printf("\n\t\tCollisions:\n");
|
|
|
|
head_printed = 1;
|
|
|
|
}
|
|
|
|
printf("\t\t\tHash ");
|
|
|
|
pdb_dump_hash_value((const BYTE*)hash + types->hash_offset + collision[i] * types->hash_size, types->hash_size);
|
|
|
|
printf(":");
|
|
|
|
for (k = i; k < j; k++)
|
|
|
|
printf(" %x", types->first_index + collision[k]);
|
|
|
|
printf("\n");
|
|
|
|
i = j - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(collision);
|
|
|
|
}
|
|
|
|
printf("\n\tIndexes => offsets:\n");
|
|
|
|
table = (const unsigned*)((const BYTE*)hash + types->search_offset);
|
|
|
|
for (i = 0; i < types->search_len / (2 * sizeof(unsigned)); i += 2)
|
|
|
|
{
|
|
|
|
printf("\t\t%08x => %08x\n", table[2 * i + 0], table[2 * i + 1]);
|
|
|
|
}
|
|
|
|
if (types->type_remap_len && (strbase = read_string_table(reader)))
|
|
|
|
{
|
|
|
|
unsigned num, capa, count_present, count_deleted;
|
|
|
|
const unsigned* present_bitset;
|
|
|
|
const unsigned* deleted_bitset;
|
|
|
|
|
|
|
|
printf("\n\tType remap:\n");
|
|
|
|
table = (const unsigned*)((const BYTE*)hash + types->type_remap_offset);
|
|
|
|
num = *table++;
|
|
|
|
capa = *table++;
|
|
|
|
count_present = *table++;
|
|
|
|
present_bitset = table;
|
|
|
|
table += count_present;
|
|
|
|
count_deleted = *table++;
|
|
|
|
deleted_bitset = table;
|
|
|
|
table += count_deleted;
|
|
|
|
printf("\t\tNumber of present entries: %u\n", num);
|
|
|
|
printf("\t\tCapacity: %u\n", capa);
|
|
|
|
printf("\t\tBitset present:\n");
|
|
|
|
printf("\t\t\tCount: %u\n", count_present);
|
|
|
|
printf("\t\t\tBitset: ");
|
|
|
|
pdb_dump_hash_value((const BYTE*)present_bitset, count_present * sizeof(unsigned));
|
|
|
|
printf("\n");
|
|
|
|
printf("\t\tBitset deleted:\n");
|
|
|
|
printf("\t\t\tCount: %u\n", count_deleted);
|
|
|
|
printf("\t\t\tBitset: ");
|
|
|
|
pdb_dump_hash_value((const BYTE*)deleted_bitset, count_deleted * sizeof(unsigned));
|
|
|
|
printf("\n");
|
|
|
|
for (i = 0; i < capa; ++i)
|
|
|
|
{
|
|
|
|
printf("\t\t%2u) %c",
|
|
|
|
i,
|
|
|
|
is_bit_set(present_bitset, count_present, i) ? 'P' :
|
|
|
|
is_bit_set(deleted_bitset, count_deleted, i) ? 'D' : '_');
|
|
|
|
if (is_bit_set(present_bitset, count_present, i))
|
|
|
|
{
|
2022-09-09 15:06:04 +00:00
|
|
|
printf(" %s => ", pdb_get_string_table_entry(strbase, *table++));
|
2022-06-22 14:28:08 +00:00
|
|
|
pdb_dump_hash_value((const BYTE*)table, types->hash_size);
|
|
|
|
table = (const unsigned*)((const BYTE*)table + types->hash_size);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
free(strbase);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2021-08-24 09:12:33 +00:00
|
|
|
free(hash);
|
|
|
|
}
|
|
|
|
|
2021-08-24 09:12:26 +00:00
|
|
|
/* there are two 'type' related streams, but with different indexes... */
|
|
|
|
static void pdb_dump_types(struct pdb_reader* reader, unsigned strmidx, const char* strmname)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
2007-07-07 16:21:07 +00:00
|
|
|
PDB_TYPES* types = NULL;
|
2021-11-10 15:42:14 +00:00
|
|
|
BOOL used = has_file_been_read(reader, strmidx);
|
2006-11-29 20:40:58 +00:00
|
|
|
|
2021-11-10 15:42:14 +00:00
|
|
|
if (pdb_get_file_size(reader, strmidx) < sizeof(*types))
|
|
|
|
{
|
|
|
|
if (strmidx == 2)
|
|
|
|
printf("-Too small type header\n");
|
|
|
|
return;
|
|
|
|
}
|
2021-08-24 09:12:26 +00:00
|
|
|
types = reader->read_file(reader, strmidx);
|
|
|
|
if (!types) return;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
switch (types->version)
|
|
|
|
{
|
|
|
|
case 19950410: /* VC 4.0 */
|
|
|
|
case 19951122:
|
|
|
|
case 19961031: /* VC 5.0 / 6.0 */
|
|
|
|
case 19990903: /* VC 7.0 */
|
2009-06-28 12:04:17 +00:00
|
|
|
case 20040203: /* VC 8.0 */
|
2006-11-29 20:40:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2021-11-10 15:42:14 +00:00
|
|
|
/* IPI stream is not always present in older PDB files */
|
|
|
|
if (strmidx == 2)
|
|
|
|
printf("-Unknown type info version %d\n", types->version);
|
|
|
|
free(types);
|
|
|
|
if (used) clear_file_been_read(reader, strmidx);
|
|
|
|
return;
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read type table */
|
2021-08-24 09:12:26 +00:00
|
|
|
printf("Types (%s):\n"
|
2022-06-22 14:28:08 +00:00
|
|
|
"\tversion: %u\n"
|
|
|
|
"\ttype_offset: %08x\n"
|
|
|
|
"\tfirst_index: %x\n"
|
|
|
|
"\tlast_index: %x\n"
|
|
|
|
"\ttype_size: %x\n"
|
|
|
|
"\thash_file: %x\n"
|
|
|
|
"\tpad: %x\n"
|
|
|
|
"\thash_size: %x\n"
|
|
|
|
"\thash_buckets %x\n"
|
|
|
|
"\thash_offset: %x\n"
|
|
|
|
"\thash_len: %x\n"
|
|
|
|
"\tsearch_offset: %x\n"
|
|
|
|
"\tsearch_len: %x\n"
|
|
|
|
"\ttype_remap_offset: %x\n"
|
|
|
|
"\ttype_remap_len: %x\n",
|
2021-08-24 09:12:26 +00:00
|
|
|
strmname,
|
2006-11-29 20:40:58 +00:00
|
|
|
types->version,
|
|
|
|
types->type_offset,
|
|
|
|
types->first_index,
|
|
|
|
types->last_index,
|
|
|
|
types->type_size,
|
2022-06-22 14:28:08 +00:00
|
|
|
types->hash_file,
|
2006-11-29 20:40:58 +00:00
|
|
|
types->pad,
|
|
|
|
types->hash_size,
|
2022-06-22 14:28:08 +00:00
|
|
|
types->hash_num_buckets,
|
2006-11-29 20:40:58 +00:00
|
|
|
types->hash_offset,
|
|
|
|
types->hash_len,
|
|
|
|
types->search_offset,
|
|
|
|
types->search_len,
|
2022-06-22 14:28:08 +00:00
|
|
|
types->type_remap_offset,
|
|
|
|
types->type_remap_len);
|
2007-01-05 20:43:23 +00:00
|
|
|
codeview_dump_types_from_block((const char*)types + types->type_offset, types->type_size);
|
2022-06-22 14:28:08 +00:00
|
|
|
pdb_dump_types_hash(reader, types, strmname);
|
2007-07-07 16:21:07 +00:00
|
|
|
free(types);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
static void pdb_dump_fpo(struct pdb_reader* reader, unsigned stream_idx)
|
2011-01-08 13:03:52 +00:00
|
|
|
{
|
|
|
|
FPO_DATA* fpo;
|
2011-01-17 20:53:31 +00:00
|
|
|
unsigned i, size;
|
2011-01-08 13:03:52 +00:00
|
|
|
const char* frame_type[4] = {"Fpo", "Trap", "Tss", "NonFpo"};
|
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
if (stream_idx == (WORD)-1) return;
|
|
|
|
fpo = reader->read_file(reader, stream_idx);
|
|
|
|
size = pdb_get_file_size(reader, stream_idx);
|
2011-01-08 13:03:52 +00:00
|
|
|
if (fpo && (size % sizeof(*fpo)) == 0)
|
|
|
|
{
|
|
|
|
size /= sizeof(*fpo);
|
|
|
|
printf("FPO data:\n\t Start Length #loc #pmt #prolog #reg frame SEH /BP\n");
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
printf("\t%08x %08x %4d %4d %7d %4d %6s %c %c\n",
|
2022-04-22 14:48:00 +00:00
|
|
|
(UINT)fpo[i].ulOffStart, (UINT)fpo[i].cbProcSize, (UINT)fpo[i].cdwLocals, fpo[i].cdwParams,
|
2011-01-08 13:03:52 +00:00
|
|
|
fpo[i].cbProlog, fpo[i].cbRegs, frame_type[fpo[i].cbFrame],
|
|
|
|
fpo[i].fHasSEH ? 'Y' : 'N', fpo[i].fUseBP ? 'Y' : 'N');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(fpo);
|
2011-01-17 20:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pdb_dump_fpo_ext(struct pdb_reader* reader, unsigned stream_idx)
|
|
|
|
{
|
|
|
|
PDB_FPO_DATA* fpoext;
|
2022-09-09 15:06:04 +00:00
|
|
|
unsigned i, size;
|
|
|
|
PDB_STRING_TABLE* strbase;
|
2011-01-08 13:03:52 +00:00
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
if (stream_idx == (WORD)-1) return;
|
2011-01-17 20:53:20 +00:00
|
|
|
strbase = read_string_table(reader);
|
2011-01-08 13:03:52 +00:00
|
|
|
if (!strbase) return;
|
|
|
|
|
2011-01-17 20:53:31 +00:00
|
|
|
fpoext = reader->read_file(reader, stream_idx);
|
|
|
|
size = pdb_get_file_size(reader, stream_idx);
|
2011-01-08 13:03:52 +00:00
|
|
|
if (fpoext && (size % sizeof(*fpoext)) == 0)
|
|
|
|
{
|
|
|
|
size /= sizeof(*fpoext);
|
|
|
|
printf("FPO data (extended):\n"
|
|
|
|
"\t Start Length Locals Params MaxStack Prolog #SavedRegs Flags Command\n");
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
printf("\t%08x %08x %8x %8x %8x %6x %8x %08x %s\n",
|
|
|
|
fpoext[i].start, fpoext[i].func_size, fpoext[i].locals_size, fpoext[i].params_size,
|
|
|
|
fpoext[i].maxstack_size, fpoext[i].prolog_size, fpoext[i].savedregs_size, fpoext[i].flags,
|
2022-09-09 15:06:04 +00:00
|
|
|
pdb_get_string_table_entry(strbase, fpoext[i].str_offset));
|
2011-01-08 13:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free(fpoext);
|
|
|
|
free(strbase);
|
|
|
|
}
|
|
|
|
|
2011-01-17 20:53:42 +00:00
|
|
|
static void pdb_dump_segments(struct pdb_reader* reader, unsigned stream_idx)
|
|
|
|
{
|
|
|
|
const char* segs;
|
|
|
|
DWORD size;
|
|
|
|
const char* ptr;
|
|
|
|
|
|
|
|
if (stream_idx == (WORD)-1) return;
|
|
|
|
segs = reader->read_file(reader, stream_idx);
|
|
|
|
|
|
|
|
if (segs)
|
|
|
|
{
|
|
|
|
size = pdb_get_file_size(reader, stream_idx);
|
|
|
|
for (ptr = segs; ptr < segs + size; )
|
|
|
|
{
|
|
|
|
printf("Segment %s\n", ptr);
|
|
|
|
ptr += (strlen(ptr) + 1 + 3) & ~3;
|
2022-04-22 14:33:11 +00:00
|
|
|
printf("\tdword[0]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[1]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[2]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[3]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[4]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[5]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[6]: %08x\n", *(UINT *)ptr); ptr += 4;
|
|
|
|
printf("\tdword[7]: %08x\n", *(UINT *)ptr); ptr += 4;
|
2011-01-17 20:53:42 +00:00
|
|
|
}
|
|
|
|
free((char*)segs);
|
|
|
|
} else printf("nosdfsdffd\n");
|
|
|
|
}
|
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
static const char pdb2[] = "Microsoft C/C++ program database 2.00";
|
|
|
|
|
|
|
|
static void pdb_jg_dump(void)
|
|
|
|
{
|
2007-07-07 16:21:07 +00:00
|
|
|
struct pdb_reader reader;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in TOC and well-known files
|
|
|
|
*/
|
|
|
|
pdb_jg_init(&reader);
|
|
|
|
printf("Header (JG):\n"
|
|
|
|
"\tident: %.*s\n"
|
|
|
|
"\tsignature: %08x\n"
|
|
|
|
"\tblock_size: %08x\n"
|
|
|
|
"\tfree_list: %04x\n"
|
|
|
|
"\ttotal_alloc:%04x\n",
|
2006-12-08 10:39:21 +00:00
|
|
|
(int)sizeof(pdb2) - 1, reader.u.jg.header->ident,
|
2006-11-29 20:40:58 +00:00
|
|
|
reader.u.jg.header->signature,
|
|
|
|
reader.u.jg.header->block_size,
|
|
|
|
reader.u.jg.header->free_list,
|
|
|
|
reader.u.jg.header->total_alloc);
|
|
|
|
|
2011-01-17 20:53:08 +00:00
|
|
|
reader.u.jg.root = reader.read_file(&reader, 1);
|
|
|
|
if (reader.u.jg.root)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
2022-04-22 14:33:11 +00:00
|
|
|
UINT *pdw, *ok_bits;
|
|
|
|
UINT i, numok, count;
|
2011-01-17 20:53:31 +00:00
|
|
|
PDB_STREAM_INDEXES sidx;
|
2011-01-17 20:53:14 +00:00
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
printf("Root:\n"
|
|
|
|
"\tVersion: %u\n"
|
|
|
|
"\tTimeDateStamp: %08x\n"
|
|
|
|
"\tAge: %08x\n"
|
2011-01-17 20:53:14 +00:00
|
|
|
"\tnames: %d\n",
|
2011-01-17 20:53:08 +00:00
|
|
|
reader.u.jg.root->Version,
|
|
|
|
reader.u.jg.root->TimeDateStamp,
|
|
|
|
reader.u.jg.root->Age,
|
2011-01-17 20:53:14 +00:00
|
|
|
(unsigned)reader.u.jg.root->cbNames);
|
|
|
|
|
2022-04-22 14:33:11 +00:00
|
|
|
pdw = (UINT *)(reader.u.jg.root->names + reader.u.jg.root->cbNames);
|
2011-01-17 20:53:14 +00:00
|
|
|
numok = *pdw++;
|
|
|
|
count = *pdw++;
|
|
|
|
printf("\tStreams directory:\n"
|
|
|
|
"\t\tok: %08x\n"
|
|
|
|
"\t\tcount: %08x\n"
|
|
|
|
"\t\ttable:\n",
|
|
|
|
numok, count);
|
|
|
|
|
|
|
|
/* bitfield: first dword is len (in dword), then data */
|
|
|
|
ok_bits = pdw;
|
|
|
|
pdw += *ok_bits++ + 1;
|
|
|
|
if (*pdw++ != 0)
|
|
|
|
{
|
|
|
|
printf("unexpected value\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (ok_bits[i / 32] & (1 << (i % 32)))
|
|
|
|
{
|
2022-04-22 14:33:11 +00:00
|
|
|
UINT string_idx, stream_idx;
|
2011-01-17 20:53:14 +00:00
|
|
|
string_idx = *pdw++;
|
|
|
|
stream_idx = *pdw++;
|
|
|
|
printf("\t\t\t%2d) %-20s => %x\n", i, &reader.u.jg.root->names[string_idx], stream_idx);
|
|
|
|
numok--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (numok) printf(">>> unmatched present field with found\n");
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
/* Check for unknown versions */
|
2011-01-17 20:53:08 +00:00
|
|
|
switch (reader.u.jg.root->Version)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
|
|
|
case 19950623: /* VC 4.0 */
|
|
|
|
case 19950814:
|
|
|
|
case 19960307: /* VC 5.0 */
|
|
|
|
case 19970604: /* VC 6.0 */
|
|
|
|
break;
|
|
|
|
default:
|
2011-01-17 20:53:08 +00:00
|
|
|
printf("-Unknown root block version %d\n", reader.u.jg.root->Version);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
2021-08-24 09:12:26 +00:00
|
|
|
pdb_dump_types(&reader, 2, "TPI");
|
|
|
|
pdb_dump_types(&reader, 4, "IPI");
|
2011-01-17 20:53:31 +00:00
|
|
|
pdb_dump_symbols(&reader, &sidx);
|
2011-01-17 20:53:51 +00:00
|
|
|
pdb_dump_fpo(&reader, sidx.FPO);
|
2011-01-17 20:53:42 +00:00
|
|
|
pdb_dump_segments(&reader, sidx.segments);
|
2011-01-17 20:53:08 +00:00
|
|
|
}
|
|
|
|
else printf("-Unable to get root\n");
|
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
pdb_exit(&reader);
|
|
|
|
}
|
|
|
|
|
2022-04-22 14:33:11 +00:00
|
|
|
static void* pdb_ds_read(const struct PDB_DS_HEADER* header, const UINT *block_list, int size)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
|
|
|
int i, nBlocks;
|
|
|
|
BYTE* buffer;
|
|
|
|
|
|
|
|
if (!size) return NULL;
|
|
|
|
|
|
|
|
nBlocks = (size + header->block_size - 1) / header->block_size;
|
2021-09-29 09:14:01 +00:00
|
|
|
buffer = xmalloc(nBlocks * header->block_size);
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nBlocks; i++)
|
|
|
|
memcpy(buffer + i * header->block_size,
|
|
|
|
(const char*)header + block_list[i] * header->block_size, header->block_size);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2007-07-07 16:21:07 +00:00
|
|
|
static void* pdb_ds_read_file(struct pdb_reader* reader, DWORD file_number)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
2022-04-22 14:33:11 +00:00
|
|
|
const UINT *block_list;
|
|
|
|
UINT i;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
if (!reader->u.ds.toc || file_number >= reader->u.ds.toc->num_files) return NULL;
|
|
|
|
|
2021-11-10 15:42:14 +00:00
|
|
|
mark_file_been_read(reader, file_number);
|
2006-11-29 20:40:58 +00:00
|
|
|
if (reader->u.ds.toc->file_size[file_number] == 0 ||
|
|
|
|
reader->u.ds.toc->file_size[file_number] == 0xFFFFFFFF)
|
|
|
|
return NULL;
|
|
|
|
block_list = reader->u.ds.toc->file_size + reader->u.ds.toc->num_files;
|
|
|
|
for (i = 0; i < file_number; i++)
|
|
|
|
block_list += (reader->u.ds.toc->file_size[i] + reader->u.ds.header->block_size - 1) /
|
|
|
|
reader->u.ds.header->block_size;
|
|
|
|
|
|
|
|
return pdb_ds_read(reader->u.ds.header, block_list, reader->u.ds.toc->file_size[file_number]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL pdb_ds_init(struct pdb_reader* reader)
|
|
|
|
{
|
|
|
|
reader->u.ds.header = PRD(0, sizeof(*reader->u.ds.header));
|
|
|
|
if (!reader->u.ds.header) return FALSE;
|
|
|
|
reader->read_file = pdb_ds_read_file;
|
2022-04-22 14:33:11 +00:00
|
|
|
reader->u.ds.toc = pdb_ds_read(reader->u.ds.header,
|
|
|
|
(const UINT *)((const char*)reader->u.ds.header + reader->u.ds.header->toc_page * reader->u.ds.header->block_size),
|
2006-11-29 20:40:58 +00:00
|
|
|
reader->u.ds.header->toc_size);
|
|
|
|
memset(reader->file_used, 0, sizeof(reader->file_used));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char pdb7[] = "Microsoft C/C++ MSF 7.00";
|
|
|
|
|
|
|
|
static void pdb_ds_dump(void)
|
|
|
|
{
|
2007-07-07 16:21:07 +00:00
|
|
|
struct pdb_reader reader;
|
2006-11-29 20:40:58 +00:00
|
|
|
|
|
|
|
pdb_ds_init(&reader);
|
|
|
|
printf("Header (DS)\n"
|
|
|
|
"\tsignature: %.*s\n"
|
|
|
|
"\tblock_size: %08x\n"
|
|
|
|
"\tunknown1: %08x\n"
|
|
|
|
"\tnum_pages: %08x\n"
|
|
|
|
"\ttoc_size: %08x\n"
|
|
|
|
"\tunknown2: %08x\n"
|
|
|
|
"\ttoc_page: %08x\n",
|
2006-12-08 10:39:21 +00:00
|
|
|
(int)sizeof(pdb7) - 1, reader.u.ds.header->signature,
|
2006-11-29 20:40:58 +00:00
|
|
|
reader.u.ds.header->block_size,
|
|
|
|
reader.u.ds.header->unknown1,
|
|
|
|
reader.u.ds.header->num_pages,
|
|
|
|
reader.u.ds.header->toc_size,
|
|
|
|
reader.u.ds.header->unknown2,
|
|
|
|
reader.u.ds.header->toc_page);
|
|
|
|
|
2021-08-24 09:12:45 +00:00
|
|
|
/* files with static indexes:
|
|
|
|
* 0: JG says old toc pages
|
2011-01-08 13:03:52 +00:00
|
|
|
* 1: root structure
|
|
|
|
* 2: types
|
|
|
|
* 3: modules
|
2021-08-24 09:12:45 +00:00
|
|
|
* 4: types (second stream)
|
2011-01-17 20:53:20 +00:00
|
|
|
* other known streams:
|
2014-02-07 21:42:49 +00:00
|
|
|
* - string table: its index is in the stream table from ROOT object under "/names"
|
2021-08-24 09:12:45 +00:00
|
|
|
* - type hash table: its index is in the types header (2 and 4)
|
|
|
|
* - global and public streams: from symbol stream header
|
2011-01-17 20:53:31 +00:00
|
|
|
* those streams get their indexes out of the PDB_STREAM_INDEXES object
|
|
|
|
* - FPO data
|
|
|
|
* - segments
|
|
|
|
* - extended FPO data
|
2006-11-29 20:40:58 +00:00
|
|
|
*/
|
2021-11-10 15:42:14 +00:00
|
|
|
mark_file_been_read(&reader, 0); /* mark stream #0 as read */
|
2011-01-17 20:53:08 +00:00
|
|
|
reader.u.ds.root = reader.read_file(&reader, 1);
|
|
|
|
if (reader.u.ds.root)
|
2006-11-29 20:40:58 +00:00
|
|
|
{
|
2022-04-22 14:33:11 +00:00
|
|
|
UINT *pdw, *ok_bits;
|
|
|
|
UINT i, numok, count;
|
2011-01-17 20:53:31 +00:00
|
|
|
PDB_STREAM_INDEXES sidx;
|
2007-01-05 20:42:32 +00:00
|
|
|
|
2006-11-29 20:40:58 +00:00
|
|
|
printf("Root:\n"
|
|
|
|
"\tVersion: %u\n"
|
|
|
|
"\tTimeDateStamp: %08x\n"
|
|
|
|
"\tAge: %08x\n"
|
2007-01-05 20:42:32 +00:00
|
|
|
"\tguid %s\n"
|
2006-11-29 20:40:58 +00:00
|
|
|
"\tcbNames: %08x\n",
|
2011-01-17 20:53:08 +00:00
|
|
|
reader.u.ds.root->Version,
|
|
|
|
reader.u.ds.root->TimeDateStamp,
|
|
|
|
reader.u.ds.root->Age,
|
|
|
|
get_guid_str(&reader.u.ds.root->guid),
|
|
|
|
reader.u.ds.root->cbNames);
|
2022-04-22 14:33:11 +00:00
|
|
|
pdw = (UINT *)(reader.u.ds.root->names + reader.u.ds.root->cbNames);
|
2011-01-17 20:53:14 +00:00
|
|
|
numok = *pdw++;
|
|
|
|
count = *pdw++;
|
|
|
|
printf("\tStreams directory:\n"
|
|
|
|
"\t\tok: %08x\n"
|
|
|
|
"\t\tcount: %08x\n"
|
|
|
|
"\t\ttable:\n",
|
|
|
|
numok, count);
|
|
|
|
|
|
|
|
/* bitfield: first dword is len (in dword), then data */
|
|
|
|
ok_bits = pdw;
|
|
|
|
pdw += *ok_bits++ + 1;
|
|
|
|
if (*pdw++ != 0)
|
|
|
|
{
|
|
|
|
printf("unexpected value\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (ok_bits[i / 32] & (1 << (i % 32)))
|
|
|
|
{
|
2022-04-22 14:33:11 +00:00
|
|
|
UINT string_idx, stream_idx;
|
2011-01-17 20:53:14 +00:00
|
|
|
string_idx = *pdw++;
|
|
|
|
stream_idx = *pdw++;
|
|
|
|
printf("\t\t\t%2d) %-20s => %x\n", i, &reader.u.ds.root->names[string_idx], stream_idx);
|
|
|
|
numok--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (numok) printf(">>> unmatched present field with found\n");
|
|
|
|
|
2021-08-24 09:12:26 +00:00
|
|
|
pdb_dump_types(&reader, 2, "TPI");
|
|
|
|
pdb_dump_types(&reader, 4, "IPI");
|
2011-01-17 20:53:31 +00:00
|
|
|
pdb_dump_symbols(&reader, &sidx);
|
|
|
|
pdb_dump_fpo(&reader, sidx.FPO);
|
|
|
|
pdb_dump_fpo_ext(&reader, sidx.FPO_EXT);
|
2011-01-17 20:53:42 +00:00
|
|
|
pdb_dump_segments(&reader, sidx.segments);
|
2006-11-29 20:40:58 +00:00
|
|
|
}
|
|
|
|
else printf("-Unable to get root\n");
|
|
|
|
|
|
|
|
pdb_exit(&reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum FileSig get_kind_pdb(void)
|
|
|
|
{
|
|
|
|
const char* head;
|
|
|
|
|
|
|
|
head = PRD(0, sizeof(pdb2) - 1);
|
|
|
|
if (head && !memcmp(head, pdb2, sizeof(pdb2) - 1))
|
|
|
|
return SIG_PDB;
|
|
|
|
head = PRD(0, sizeof(pdb7) - 1);
|
|
|
|
if (head && !memcmp(head, pdb7, sizeof(pdb7) - 1))
|
|
|
|
return SIG_PDB;
|
|
|
|
return SIG_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pdb_dump(void)
|
|
|
|
{
|
|
|
|
const char* head;
|
|
|
|
|
|
|
|
/* init_types(); */
|
|
|
|
head = PRD(0, sizeof(pdb2) - 1);
|
|
|
|
if (head && !memcmp(head, pdb2, sizeof(pdb2) - 1))
|
2006-12-07 13:42:54 +00:00
|
|
|
{
|
|
|
|
pdb_jg_dump();
|
|
|
|
return;
|
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
head = PRD(0, sizeof(pdb7) - 1);
|
|
|
|
if (head && !memcmp(head, pdb7, sizeof(pdb7) - 1))
|
2006-12-07 13:42:54 +00:00
|
|
|
{
|
|
|
|
pdb_ds_dump();
|
|
|
|
return;
|
|
|
|
}
|
2006-11-29 20:40:58 +00:00
|
|
|
printf("Unrecognized header %s\n", head);
|
|
|
|
}
|