Rizin
unix-like reverse engineering framework and cli tools
rz_pdb.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 Basstorm <basstorm@nyist.edu.cn>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef RZ_PDB_H
5 #define RZ_PDB_H
6 
7 #include <rz_util.h>
8 #include <rz_type.h>
9 #include <rz_cmd.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #define CAB_SIGNATURE "MSCF"
16 #define PDB_SIGNATURE "Microsoft C/C++ MSF 7.00\r\n\x1a\x44\x53\x00\x00\x00"
17 #define PDB_SIGNATURE_LEN 32
18 
19 #define GET_BF(value, start, len) (((value) >> (start)) & ((1 << len) - 1))
20 
21 // DBI
22 typedef struct dbi_stream_header_t {
44 
45 typedef struct {
58 
59 typedef struct dbi_stream_t {
61  RzList /* RzPdbDbiStreamExHdr */ *ex_hdrs;
63 
65 
66 // GDATA
67 typedef struct {
68  RzList /* GDataGlobal */ *global_list;
70 
71 // OMAP
72 typedef struct
73 {
74  RzList /* OmapEntry */ *entries;
77 
78 // PE Stream
79 typedef struct {
80  RzList /* PeImageSectionHeader */ *sections_hdrs;
82 
83 // TPI
84 typedef enum {
85  NEAR_C = 0x00000000,
86  FAR_C = 0x00000001,
87  NEAR_PASCAL = 0x00000002,
88  FAR_PASCAL = 0x00000003,
89  NEAR_FAST = 0x00000004,
90  FAR_FAST = 0x00000005,
91  SKIPPED = 0x00000006,
92  NEAR_STD = 0x00000007,
93  FAR_STD = 0x00000008,
94  NEAR_SYS = 0x00000009,
95  FAR_SYS = 0x0000000A,
96  THISCALL = 0x0000000B,
97  MIPSCALL = 0x0000000C,
98  GENERIC = 0x0000000D,
99  ALPHACALL = 0x0000000E,
100  PPCCALL = 0x0000000F,
101  SHCALL = 0x00000010,
102  ARMCALL = 0x00000011,
103  AM33CALL = 0x00000012,
104  TRICALL = 0x00000013,
105  SH5CALL = 0x00000014,
106  M32RCALL = 0x00000015,
107  CLRCALL = 0x00000016,
108  INLINECALL = 0x00000017,
109  NEAR_VEC = 0X00000018,
110  RESERVED = 0x00000019,
113 
114 typedef enum {
115  V40 = 19950410,
116  V41 = 19951122,
117  V50 = 19961031,
118  V70 = 19990903,
119  V80 = 20040203,
121 
122 typedef struct tpi_stream_header_t {
128 
133 
136 
139 
143 
144 typedef struct tpi_types {
149  void *type_data;
150  bool parsed;
152 
153 typedef struct tpi_stream_t {
157  RzList /* RzBaseType */ *print_type;
159 
160 // PDB
161 typedef enum pdb_stream_index_t {
162  PDB_STREAM_ROOT = 0, // PDB_ROOT_DIRECTORY
163  PDB_STREAM_PDB, // PDB STREAM INFO
164  PDB_STREAM_TPI, // TYPE INFO
165  PDB_STREAM_DBI, // DEBUG INFO
166 
179 
181  VC2 = 19941610,
182  VC4 = 19950623,
183  VC41 = 19950814,
184  VC50 = 19960307,
185  VC98 = 19970604,
186  VC70Dep = 19990604,
187  VC70 = 20000404,
188  VC80 = 20030901,
189  VC110 = 20091201,
190  VC140 = 20140508,
191 };
192 
196 typedef struct {
200  ut8 data4[8];
201 } RzPdbGuid;
202 
203 typedef struct {
209 
210 typedef struct {
212  /* Todo: parse named table */
213 } RzPdbStream;
214 
218 typedef struct {
219  char file_magic[PDB_SIGNATURE_LEN];
227 
228 typedef struct {
234 
235 typedef struct {
240 
241 typedef struct rz_pdb_t {
242  RzBuffer *buf; // mmap of file
244  RzList /* RzPdbMsfStream */ *streams;
252 
253 // PDB
254 RZ_API bool rz_bin_pdb_extract_in_folder(RZ_NONNULL const char *file_cab, RZ_NONNULL const char *output_dir);
257 RZ_API void rz_bin_pdb_free(RzPdb *pdb);
258 
259 // TPI
266 
267 // OMAP
268 RZ_API int rz_bin_pdb_omap_remap(RZ_NONNULL RzPdbOmapStream *omap_stream, int address);
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 
274 #endif
#define RZ_API
uint16_t ut16
uint32_t ut32
const char * filename
Definition: ioapi.h:137
voidpf stream
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
int type
Definition: mipsasm.c:17
int idx
Definition: setup.py:197
struct dbi_stream_header_t RzPdbRzPdbDbiStreamHdr
RZ_API int rz_bin_pdb_omap_remap(RZ_NONNULL RzPdbOmapStream *omap_stream, int address)
return remapped symbol address
Definition: omap.c:89
RZ_API ut64 rz_bin_pdb_get_type_val(RZ_NONNULL RzPdbTpiType *type)
Get the numeric value inside the type.
Definition: tpi.c:507
struct dbi_stream_t RzPdbDbiStream
enum pdb_stream_index_t RzRzPdbStreamIndex
RZ_API RZ_BORROW RzList * rz_bin_pdb_get_type_members(RZ_NONNULL RzPdbTpiStream *stream, RzPdbTpiType *t)
Get the RzPdbTpiType member list.
Definition: tpi.c:406
RZ_API RZ_OWN RzPdb * rz_bin_pdb_parse_from_file(RZ_NONNULL const char *filename)
Parse PDB file given the path.
Definition: pdb.c:292
#define PDB_SIGNATURE_LEN
Definition: rz_pdb.h:17
RzPdbTpiStreamVersion
Definition: rz_pdb.h:114
@ V80
Definition: rz_pdb.h:119
@ V41
Definition: rz_pdb.h:116
@ V70
Definition: rz_pdb.h:118
@ V50
Definition: rz_pdb.h:117
@ V40
Definition: rz_pdb.h:115
RZ_API RZ_BORROW RzPdbTpiType * rz_bin_pdb_get_type_by_index(RZ_NONNULL RzPdbTpiStream *stream, ut32 index)
Get RzPdbTpiType that matches tpi stream index.
Definition: tpi.c:1844
RZ_API RZ_OWN char * rz_bin_pdb_calling_convention_as_string(RZ_NONNULL RzPdbTpiCallingConvention idx)
Parses calling convention type as string.
Definition: tpi.c:35
RZ_API RZ_BORROW char * rz_bin_pdb_get_type_name(RZ_NONNULL RzPdbTpiType *type)
Get the name of the type.
Definition: tpi.c:447
RzPdbTpiCallingConvention
Definition: rz_pdb.h:84
@ INLINECALL
Definition: rz_pdb.h:108
@ SH5CALL
Definition: rz_pdb.h:105
@ MAX_CV_CALL
Definition: rz_pdb.h:111
@ PPCCALL
Definition: rz_pdb.h:100
@ TRICALL
Definition: rz_pdb.h:104
@ THISCALL
Definition: rz_pdb.h:96
@ ALPHACALL
Definition: rz_pdb.h:99
@ CLRCALL
Definition: rz_pdb.h:107
@ MIPSCALL
Definition: rz_pdb.h:97
@ NEAR_PASCAL
Definition: rz_pdb.h:87
@ NEAR_FAST
Definition: rz_pdb.h:89
@ SKIPPED
Definition: rz_pdb.h:91
@ FAR_PASCAL
Definition: rz_pdb.h:88
@ ARMCALL
Definition: rz_pdb.h:102
@ FAR_FAST
Definition: rz_pdb.h:90
@ GENERIC
Definition: rz_pdb.h:98
@ NEAR_C
Definition: rz_pdb.h:85
@ NEAR_SYS
Definition: rz_pdb.h:94
@ NEAR_VEC
Definition: rz_pdb.h:109
@ FAR_C
Definition: rz_pdb.h:86
@ AM33CALL
Definition: rz_pdb.h:103
@ FAR_SYS
Definition: rz_pdb.h:95
@ NEAR_STD
Definition: rz_pdb.h:92
@ M32RCALL
Definition: rz_pdb.h:106
@ SHCALL
Definition: rz_pdb.h:101
@ FAR_STD
Definition: rz_pdb.h:93
@ RESERVED
Definition: rz_pdb.h:110
RZ_API void rz_bin_pdb_free(RzPdb *pdb)
Free PDB instance.
Definition: pdb.c:366
RZ_API RZ_OWN RzPdb * rz_bin_pdb_parse_from_buf(RZ_NONNULL const RzBuffer *buf)
Parse PDB from the buffer.
Definition: pdb.c:315
pdb_stream_version
Definition: rz_pdb.h:180
@ VC70Dep
Definition: rz_pdb.h:186
@ VC80
Definition: rz_pdb.h:188
@ VC110
Definition: rz_pdb.h:189
@ VC50
Definition: rz_pdb.h:184
@ VC98
Definition: rz_pdb.h:185
@ VC41
Definition: rz_pdb.h:183
@ VC70
Definition: rz_pdb.h:187
@ VC4
Definition: rz_pdb.h:182
@ VC140
Definition: rz_pdb.h:190
@ VC2
Definition: rz_pdb.h:181
pdb_stream_index_t
Definition: rz_pdb.h:161
@ PDB_STREAM_GSYM
Definition: rz_pdb.h:167
@ PDB_STREAM_SECT__HDR_ORIG
Definition: rz_pdb.h:169
@ PDB_STREAM_TPI
Definition: rz_pdb.h:164
@ PDB_STREAM_PDB
Definition: rz_pdb.h:163
@ PDB_STREAM_SECT_HDR
Definition: rz_pdb.h:168
@ PDB_STREAM_PDATA
Definition: rz_pdb.h:175
@ PDB_STREAM_OMAP_TO_SRC
Definition: rz_pdb.h:170
@ PDB_STREAM_FPO_NEW
Definition: rz_pdb.h:173
@ PDB_STREAM_MAX
Definition: rz_pdb.h:177
@ PDB_STREAM_TOKEN_RID_MAP
Definition: rz_pdb.h:176
@ PDB_STREAM_FPO
Definition: rz_pdb.h:172
@ PDB_STREAM_DBI
Definition: rz_pdb.h:165
@ PDB_STREAM_ROOT
Definition: rz_pdb.h:162
@ PDB_STREAM_XDATA
Definition: rz_pdb.h:174
@ PDB_STREAM_OMAP_FROM_SRC
Definition: rz_pdb.h:171
struct tpi_stream_header_t RzPdbTpiStreamHeader
struct rz_pdb_t RzPdb
RZ_API bool rz_bin_pdb_extract_in_folder(RZ_NONNULL const char *file_cab, RZ_NONNULL const char *output_dir)
Extracts compressed PDB files into a folder.
Definition: cab_extract.c:209
RZ_API bool rz_bin_pdb_type_is_fwdref(RZ_NONNULL RzPdbTpiType *t)
Return true if type is forward definition.
Definition: tpi.c:372
struct tpi_types RzPdbTpiType
struct tpi_stream_t RzPdbTpiStream
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
#define st16
Definition: rz_types_base.h:14
#define st32
Definition: rz_types_base.h:12
RzList * global_list
Definition: rz_pdb.h:68
ut16 data2
Definition: rz_pdb.h:198
ut16 data3
Definition: rz_pdb.h:199
ut32 data1
Definition: rz_pdb.h:197
RzBuffer * stream_data
Definition: rz_pdb.h:232
ut32 stream_idx
Definition: rz_pdb.h:229
ut32 blocks_num
Definition: rz_pdb.h:231
ut32 stream_size
Definition: rz_pdb.h:230
MSF file format header https://llvm.org/docs/PDB/MsfFile.html#the-superblock.
Definition: rz_pdb.h:218
ut32 num_directory_bytes
The size of the stream directory, in bytes.
Definition: rz_pdb.h:223
ut32 num_blocks
The total number of blocks in the file.
Definition: rz_pdb.h:222
ut32 block_size
The block size of the internal file system.
Definition: rz_pdb.h:220
ut32 block_map_addr
The index of a block within the MSF file.
Definition: rz_pdb.h:225
ut32 free_block_map_block
The index of a block within the file, the data within that block is not used.
Definition: rz_pdb.h:221
RzList * entries
Definition: rz_pdb.h:74
ut32 * froms
Definition: rz_pdb.h:75
RzList * sections_hdrs
Definition: rz_pdb.h:80
RzRzPdbStreamHeader hdr
Definition: rz_pdb.h:211
RzPdbGuid unique_id
Definition: rz_pdb.h:207
ut16 sym_record_stream
Definition: rz_pdb.h:30
ut32 type_server_map_size
Definition: rz_pdb.h:36
ut32 optional_dbg_header_size
Definition: rz_pdb.h:38
ut32 mod_info_size
Definition: rz_pdb.h:32
ut16 pdb_dll_version
Definition: rz_pdb.h:29
ut32 ec_substream_size
Definition: rz_pdb.h:39
ut32 version_header
Definition: rz_pdb.h:24
st32 version_signature
Definition: rz_pdb.h:23
ut32 section_map_size
Definition: rz_pdb.h:34
ut16 public_stream_index
Definition: rz_pdb.h:28
ut32 section_contribution_size
Definition: rz_pdb.h:33
ut32 mfc_type_server_index
Definition: rz_pdb.h:37
ut32 source_info_size
Definition: rz_pdb.h:35
ut16 global_stream_index
Definition: rz_pdb.h:26
RzPdbRzPdbDbiStreamHdr hdr
Definition: rz_pdb.h:60
RzList * ex_hdrs
Definition: rz_pdb.h:61
RzPdbRzPdbDbiStreamDbgHeader dbg_hdr
Definition: rz_pdb.h:62
RzPdbDbiStream * s_dbi
Definition: rz_pdb.h:246
RzPdbGDataStream * s_gdata
Definition: rz_pdb.h:248
RzPdbTpiStream * s_tpi
Definition: rz_pdb.h:247
RzList * streams
Definition: rz_pdb.h:244
RzPdbPeStream * s_pe
Definition: rz_pdb.h:250
RzPdbMsfSuperBlock * super_block
Definition: rz_pdb.h:243
RzPdbOmapStream * s_omap
Definition: rz_pdb.h:249
RzPdbStream * s_pdb
Definition: rz_pdb.h:245
RzBuffer * buf
Definition: rz_pdb.h:242
RzPdbTpiStreamVersion Version
Definition: rz_pdb.h:123
ut16 HashStreamIndex
Definition: rz_pdb.h:129
st32 IndexOffsetBufferOffset
Definition: rz_pdb.h:137
st32 HashAdjBufferOffset
Definition: rz_pdb.h:140
ut32 HashValueBufferLength
Definition: rz_pdb.h:135
ut32 HashAdjBufferLength
Definition: rz_pdb.h:141
ut32 IndexOffsetBufferLength
Definition: rz_pdb.h:138
ut32 TypeRecordBytes
Definition: rz_pdb.h:127
ut16 HashAuxStreamIndex
Definition: rz_pdb.h:130
st32 HashValueBufferOffset
Definition: rz_pdb.h:134
RzPdbTpiStreamHeader header
Definition: rz_pdb.h:154
RzList * print_type
Definition: rz_pdb.h:157
ut64 type_index_base
Definition: rz_pdb.h:156
RBTree types
Definition: rz_pdb.h:155
ut16 leaf_type
Definition: rz_pdb.h:147
ut16 length
Definition: rz_pdb.h:148
bool parsed
Definition: rz_pdb.h:150
RBNode rb
Definition: rz_pdb.h:145
void * type_data
Definition: rz_pdb.h:149
ut32 type_index
Definition: rz_pdb.h:146
ut64(WINAPI *w32_GetEnabledXStateFeatures)()