Rizin
unix-like reverse engineering framework and cli tools
pdb.c File Reference
#include <rz_bin.h>
#include <rz_type.h>
#include <string.h>
#include <rz_demangler.h>
#include <mspack.h>
#include "pdb.h"

Go to the source code of this file.

Functions

static bool parse_pdb_stream (RzPdb *pdb, RzPdbMsfStream *stream)
 
static bool parse_streams (RzPdb *pdb)
 
static void msf_stream_free (void *data)
 
static void msf_stream_directory_free (void *data)
 
static ut64 count_blocks (ut64 length, ut64 block_size)
 
static RzListpdb7_extract_streams (RzPdb *pdb, RzPdbMsfStreamDirectory *msd)
 
static RzPdbMsfStreamDirectorypdb7_extract_msf_stream_directory (RzPdb *pdb)
 
static bool pdb7_parse (RzPdb *pdb)
 
bool is_compressed_pdb (RzBuffer *buf)
 
RZ_API RZ_OWN RzPdbrz_bin_pdb_parse_from_file (RZ_NONNULL const char *filename)
 Parse PDB file given the path. More...
 
RZ_API RZ_OWN RzPdbrz_bin_pdb_parse_from_buf (RZ_NONNULL const RzBuffer *buf)
 Parse PDB from the buffer. More...
 
RZ_API void rz_bin_pdb_free (RzPdb *pdb)
 Free PDB instance. More...
 

Function Documentation

◆ count_blocks()

static ut64 count_blocks ( ut64  length,
ut64  block_size 
)
static

Definition at line 105 of file pdb.c.

105  {
106  ut64 num_blocks = 0;
107  if (block_size > 0) {
108  num_blocks = length / block_size;
109  if (length % block_size) {
110  num_blocks++;
111  }
112  }
113  return num_blocks;
114 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References length, and ut64().

Referenced by pdb7_extract_msf_stream_directory(), and pdb7_extract_streams().

◆ is_compressed_pdb()

bool is_compressed_pdb ( RzBuffer buf)

Definition at line 275 of file pdb.c.

275  {
276  ut8 magic[4] = { 0 };
277  // avoids to seek back, when using rz_buf_read_at
278  if (rz_buf_read_at(buf, 0, magic, sizeof(magic)) != sizeof(magic)) {
279  return false;
280  } else if (memcmp(magic, CAB_SIGNATURE, sizeof(magic))) {
281  return false;
282  }
283  return true;
284 }
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
#define CAB_SIGNATURE
Definition: rz_pdb.h:15

References CAB_SIGNATURE, and rz_buf_read_at().

Referenced by rz_bin_pdb_parse_from_file().

◆ msf_stream_directory_free()

static void msf_stream_directory_free ( void *  data)
static

Definition at line 98 of file pdb.c.

98  {
99  RzPdbMsfStreamDirectory *msd = data;
100  RZ_FREE(msd->StreamSizes);
101  rz_buf_free(msd->sd);
102  RZ_FREE(msd);
103 }
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
#define RZ_FREE(x)
Definition: rz_types.h:369

References rz_buf_free(), RZ_FREE, RzPdbMsfStreamDirectory::sd, and RzPdbMsfStreamDirectory::StreamSizes.

Referenced by pdb7_extract_streams(), and pdb7_parse().

◆ msf_stream_free()

static void msf_stream_free ( void *  data)
static

Definition at line 92 of file pdb.c.

92  {
93  RzPdbMsfStream *msfstream = data;
94  rz_buf_free(msfstream->stream_data);
95  RZ_FREE(msfstream);
96 }
RzBuffer * stream_data
Definition: rz_pdb.h:232

References rz_buf_free(), RZ_FREE, and RzPdbMsfStream::stream_data.

Referenced by pdb7_extract_streams().

◆ parse_pdb_stream()

static bool parse_pdb_stream ( RzPdb pdb,
RzPdbMsfStream stream 
)
static

Definition at line 13 of file pdb.c.

13  {
14  if (!pdb || !stream) {
15  return false;
16  }
17 
18  pdb->s_pdb = RZ_NEW0(RzPdbStream);
19  RzPdbStream *s = pdb->s_pdb;
20  RzBuffer *buf = stream->stream_data;
21  if (!rz_buf_read_le32(buf, &s->hdr.version) ||
22  !rz_buf_read_le32(buf, &s->hdr.signature) ||
23  !rz_buf_read_le32(buf, &s->hdr.age) ||
24  !rz_buf_read_le32(buf, &s->hdr.unique_id.data1) ||
25  !rz_buf_read_le16(buf, &s->hdr.unique_id.data2) ||
26  !rz_buf_read_le16(buf, &s->hdr.unique_id.data3) ||
27  rz_buf_read(buf, s->hdr.unique_id.data4, 8) != 8) {
28  return false;
29  }
30 
31  if (s->hdr.version != VC70) {
32  RZ_LOG_ERROR("Error Unsupported PDB version.\n");
33  return false;
34  }
35  return true;
36 }
voidpf stream
Definition: ioapi.h:138
static RzSocket * s
Definition: rtr.c:28
#define rz_buf_read_le16(b, result)
Read a big endian or little endian (ut16, ut32, ut64) at the specified offset in the buffer and shift...
Definition: rz_buf.h:266
#define rz_buf_read_le32(b, result)
Definition: rz_buf.h:267
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
@ VC70
Definition: rz_pdb.h:187
#define RZ_NEW0(x)
Definition: rz_types.h:284
RzPdbStream * s_pdb
Definition: rz_pdb.h:245

References rz_buf_read(), rz_buf_read_le16, rz_buf_read_le32, RZ_LOG_ERROR, RZ_NEW0, s, rz_pdb_t::s_pdb, and VC70.

Referenced by parse_streams().

◆ parse_streams()

static bool parse_streams ( RzPdb pdb)
static

Definition at line 38 of file pdb.c.

38  {
39  RzListIter *it;
40  RzPdbMsfStream *ms;
41  rz_list_foreach (pdb->streams, it, ms) {
42  switch (ms->stream_idx) {
43  case PDB_STREAM_ROOT:
44  break;
45  case PDB_STREAM_PDB:
46  if (!parse_pdb_stream(pdb, ms)) {
47  RZ_LOG_ERROR("Parse pdb stream failed.");
48  return false;
49  }
50  break;
51  case PDB_STREAM_TPI:
52  if (!parse_tpi_stream(pdb, ms)) {
53  RZ_LOG_ERROR("Parse tpi stream failed.");
54  return false;
55  }
56  break;
57  case PDB_STREAM_DBI:
58  if (!parse_dbi_stream(pdb, ms)) {
59  RZ_LOG_ERROR("Parse dbi stream failed.");
60  return false;
61  }
62  break;
63  default: {
64  if (!pdb->s_dbi) {
65  break;
66  }
67  if (ms->stream_idx == pdb->s_dbi->hdr.sym_record_stream) {
68  if (!parse_gdata_stream(pdb, ms)) {
69  RZ_LOG_ERROR("Parse gdata stream failed.");
70  return false;
71  }
72  } else if (ms->stream_idx == pdb->s_dbi->dbg_hdr.sn_section_hdr ||
74  if (!parse_pe_stream(pdb, ms)) {
75  RZ_LOG_ERROR("Parse pe stream failed.");
76  return false;
77  }
78  } else if (ms->stream_idx == pdb->s_dbi->dbg_hdr.sn_omap_to_src ||
80  if (!parse_omap_stream(pdb, ms)) {
81  RZ_LOG_ERROR("Parse omap stream failed.");
82  return false;
83  }
84  }
85  break;
86  }
87  }
88  }
89  return true;
90 }
RZ_IPI bool parse_dbi_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: dbi.c:151
RZ_IPI bool parse_gdata_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: gdata.c:33
RZ_IPI bool parse_omap_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: omap.c:8
static bool parse_pdb_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: pdb.c:13
RZ_IPI bool parse_tpi_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: tpi.c:1799
RZ_IPI bool parse_pe_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: stream_pe.c:20
@ PDB_STREAM_TPI
Definition: rz_pdb.h:164
@ PDB_STREAM_PDB
Definition: rz_pdb.h:163
@ PDB_STREAM_DBI
Definition: rz_pdb.h:165
@ PDB_STREAM_ROOT
Definition: rz_pdb.h:162
ut32 stream_idx
Definition: rz_pdb.h:229
ut16 sym_record_stream
Definition: rz_pdb.h:30
RzPdbRzPdbDbiStreamHdr hdr
Definition: rz_pdb.h:60
RzPdbRzPdbDbiStreamDbgHeader dbg_hdr
Definition: rz_pdb.h:62
RzPdbDbiStream * s_dbi
Definition: rz_pdb.h:246
RzList * streams
Definition: rz_pdb.h:244

References dbi_stream_t::dbg_hdr, dbi_stream_t::hdr, parse_dbi_stream(), parse_gdata_stream(), parse_omap_stream(), parse_pdb_stream(), parse_pe_stream(), parse_tpi_stream(), PDB_STREAM_DBI, PDB_STREAM_PDB, PDB_STREAM_ROOT, PDB_STREAM_TPI, RZ_LOG_ERROR, rz_pdb_t::s_dbi, RzPdbRzPdbDbiStreamDbgHeader::sn_omap_from_src, RzPdbRzPdbDbiStreamDbgHeader::sn_omap_to_src, RzPdbRzPdbDbiStreamDbgHeader::sn_section_hdr, RzPdbRzPdbDbiStreamDbgHeader::sn_section_hdr_orig, RzPdbMsfStream::stream_idx, rz_pdb_t::streams, and dbi_stream_header_t::sym_record_stream.

Referenced by pdb7_parse().

◆ pdb7_extract_msf_stream_directory()

static RzPdbMsfStreamDirectory* pdb7_extract_msf_stream_directory ( RzPdb pdb)
static

Definition at line 170 of file pdb.c.

170  {
171  // Get block map
173  if (!block_num) {
174  RZ_LOG_ERROR("Error block map size.\n");
175  goto error;
176  }
177  rz_buf_seek(pdb->buf, (long long)pdb->super_block->block_size * pdb->super_block->block_map_addr, RZ_BUF_SET);
178  ut32 *block_map = (ut32 *)malloc(sizeof(ut32) * block_num);
179  if (!block_map) {
180  goto error_memory;
181  }
182  for (size_t i = 0; i < block_num; i++) {
183  ut32 block_idx;
184  if (!rz_buf_read_le32(pdb->buf, &block_idx)) {
185  RZ_FREE(block_map);
186  goto error;
187  }
188  if (block_idx > pdb->super_block->num_blocks) {
189  RZ_LOG_ERROR("Error block index.\n");
190  RZ_FREE(block_map);
191  goto error;
192  }
193  block_map[i] = block_idx;
194  }
195 
196  ut32 stream_directory_len = block_num * pdb->super_block->block_size;
197  ut8 *stream_directory = (ut8 *)malloc(stream_directory_len);
198  if (!stream_directory) {
199  RZ_FREE(block_map);
200  goto error_memory;
201  }
202  for (size_t i = 0; i < block_num; i++) {
203  rz_buf_seek(pdb->buf, (long long)block_map[i] * pdb->super_block->block_size, RZ_BUF_SET);
204  rz_buf_read(pdb->buf, stream_directory + i * pdb->super_block->block_size, pdb->super_block->block_size);
205  }
206  RzBuffer *sd = rz_buf_new_with_pointers(stream_directory, stream_directory_len, true);
207  if (!sd) {
208  RZ_FREE(stream_directory);
209  RZ_FREE(block_map);
210  goto error_memory;
211  }
212  RZ_FREE(block_map);
213 
215  if (!msd) {
216  goto error_memory;
217  }
218  if (!rz_buf_read_le32(sd, &msd->NumStreams)) {
219  RZ_FREE(msd);
220  goto error;
221  }
222  msd->StreamSizes = (ut32 *)malloc(msd->NumStreams * sizeof(ut32));
223  msd->sd = sd;
224  if (!msd->StreamSizes) {
225  RZ_FREE(msd);
226  goto error_memory;
227  }
228  ut32 total_blocks = 0;
229  for (size_t i = 0; i < msd->NumStreams; i++) {
230  ut32 stream_size;
231  if (!rz_buf_read_le32(sd, &stream_size)) {
232  RZ_FREE(msd);
233  goto error;
234  }
235  if (stream_size == UT32_MAX) {
236  msd->StreamSizes[i] = 0;
237  continue;
238  }
239  msd->StreamSizes[i] = stream_size;
240  ut32 blocks = count_blocks(stream_size, pdb->super_block->block_size);
241  total_blocks += blocks;
242  }
243  // NumStreams StreamsSizes StreamsBlockMap
244  ut32 msd_size = sizeof(ut32) + msd->NumStreams * sizeof(ut32) + total_blocks * sizeof(ut32);
245  if (msd_size != pdb->super_block->num_directory_bytes) {
246  RZ_LOG_ERROR("Error stream directory size.\n");
247  RZ_FREE(msd);
248  goto error;
249  }
250  return msd;
251 
252 error_memory:
253  RZ_LOG_ERROR("Error memory allocation.\n");
254 error:
255  return NULL;
256 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
void * malloc(size_t size)
Definition: malloc.c:123
static ut64 count_blocks(ut64 length, ut64 block_size)
Definition: pdb.c:105
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal)
Creates a new buffer with a bytes array.
Definition: buf.c:552
#define RZ_BUF_SET
Definition: rz_buf.h:14
#define UT32_MAX
Definition: rz_types_base.h:99
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
RzPdbMsfSuperBlock * super_block
Definition: rz_pdb.h:243
RzBuffer * buf
Definition: rz_pdb.h:242
uint64_t blocks
Definition: list.c:104
void error(const char *msg)
Definition: untgz.c:593

References RzPdbMsfSuperBlock::block_map_addr, RzPdbMsfSuperBlock::block_size, blocks, rz_pdb_t::buf, count_blocks(), error(), i, malloc(), NULL, RzPdbMsfSuperBlock::num_blocks, RzPdbMsfSuperBlock::num_directory_bytes, RzPdbMsfStreamDirectory::NumStreams, rz_buf_new_with_pointers(), rz_buf_read(), rz_buf_read_le32, rz_buf_seek(), RZ_BUF_SET, RZ_FREE, RZ_LOG_ERROR, RZ_NEW0, RzPdbMsfStreamDirectory::sd, RzPdbMsfStreamDirectory::StreamSizes, rz_pdb_t::super_block, and UT32_MAX.

Referenced by pdb7_parse().

◆ pdb7_extract_streams()

static RzList* pdb7_extract_streams ( RzPdb pdb,
RzPdbMsfStreamDirectory msd 
)
static

Definition at line 116 of file pdb.c.

116  {
118  if (!streams) {
119  goto error_memory;
120  }
121  for (size_t i = 0; i < msd->NumStreams; i++) {
123  if (!stream) {
125  goto error_memory;
126  }
127  stream->stream_idx = i;
128  stream->stream_size = msd->StreamSizes[i];
129  stream->blocks_num = count_blocks(stream->stream_size, pdb->super_block->block_size);
130  if (!stream->stream_size) {
131  stream->stream_data = NULL;
133  continue;
134  }
135  ut8 *stream_data = (ut8 *)malloc((size_t)stream->blocks_num * pdb->super_block->block_size);
136  if (!stream_data) {
137  RZ_FREE(stream);
139  RZ_LOG_ERROR("Error allocating memory.\n");
140  return NULL;
141  }
142  for (size_t j = 0; j < stream->blocks_num; j++) {
143  ut32 block_idx;
144  if (!rz_buf_read_le32(msd->sd, &block_idx)) {
145  RZ_FREE(stream);
146  RZ_FREE(stream_data);
148  return NULL;
149  }
150  rz_buf_seek(pdb->buf, (long long)block_idx * pdb->super_block->block_size, RZ_BUF_SET);
151  rz_buf_read(pdb->buf, stream_data + j * pdb->super_block->block_size, pdb->super_block->block_size);
152  }
153  stream->stream_data = rz_buf_new_with_pointers(stream_data, stream->stream_size, true);
154  if (!stream->stream_data) {
155  RZ_FREE(stream);
156  RZ_FREE(stream_data);
158  goto error_memory;
159  }
161  }
163  return streams;
164 
165 error_memory:
166  RZ_LOG_ERROR("Error memory allocation.\n");
167  return NULL;
168 }
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
static void msf_stream_directory_free(void *data)
Definition: pdb.c:98
static void msf_stream_free(void *data)
Definition: pdb.c:92
uint64_t streams
Definition: list.c:103

References RzPdbMsfSuperBlock::block_size, rz_pdb_t::buf, count_blocks(), i, malloc(), msf_stream_directory_free(), msf_stream_free(), NULL, RzPdbMsfStreamDirectory::NumStreams, rz_buf_new_with_pointers(), rz_buf_read(), rz_buf_read_le32, rz_buf_seek(), RZ_BUF_SET, RZ_FREE, rz_list_append(), rz_list_free(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, RzPdbMsfStreamDirectory::sd, streams, RzPdbMsfStreamDirectory::StreamSizes, and rz_pdb_t::super_block.

Referenced by pdb7_parse().

◆ pdb7_parse()

static bool pdb7_parse ( RzPdb pdb)
static

Definition at line 258 of file pdb.c.

258  {
260  if (!msd) {
261  RZ_LOG_ERROR("Error extracting stream directory.\n");
262  goto error;
263  }
264  pdb->streams = pdb7_extract_streams(pdb, msd);
265  if (!pdb->streams) {
267  RZ_LOG_ERROR("Error extracting streams.\n");
268  goto error;
269  }
270  return parse_streams(pdb);
271 error:
272  return false;
273 }
static bool parse_streams(RzPdb *pdb)
Definition: pdb.c:38
static RzPdbMsfStreamDirectory * pdb7_extract_msf_stream_directory(RzPdb *pdb)
Definition: pdb.c:170
static RzList * pdb7_extract_streams(RzPdb *pdb, RzPdbMsfStreamDirectory *msd)
Definition: pdb.c:116

References error(), msf_stream_directory_free(), parse_streams(), pdb7_extract_msf_stream_directory(), pdb7_extract_streams(), RZ_LOG_ERROR, and rz_pdb_t::streams.

Referenced by rz_bin_pdb_parse_from_buf().

◆ rz_bin_pdb_free()

RZ_API void rz_bin_pdb_free ( RzPdb pdb)

Free PDB instance.

Parameters
pdbPDB instance
Returns
void

Definition at line 366 of file pdb.c.

366  {
367  if (!pdb) {
368  return;
369  }
370  rz_buf_free(pdb->buf);
371  free(pdb->super_block);
372  rz_list_free(pdb->streams);
373  free(pdb->s_pdb);
374  free_dbi_stream(pdb->s_dbi);
376  free_omap_stream(pdb->s_omap);
377  free_tpi_stream(pdb->s_tpi);
378  free_pe_stream(pdb->s_pe);
379  free(pdb);
380 }
RZ_IPI void free_dbi_stream(RzPdbDbiStream *stream)
Definition: dbi.c:7
RZ_IPI void free_gdata_stream(RzPdbGDataStream *stream)
Definition: gdata.c:80
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_IPI void free_omap_stream(RzPdbOmapStream *stream)
Definition: omap.c:42
RZ_IPI void free_pe_stream(RzPdbPeStream *stream)
Definition: stream_pe.c:53
RZ_IPI void free_tpi_stream(RzPdbTpiStream *stream)
Definition: tpi.c:705
RzPdbGDataStream * s_gdata
Definition: rz_pdb.h:248
RzPdbTpiStream * s_tpi
Definition: rz_pdb.h:247
RzPdbPeStream * s_pe
Definition: rz_pdb.h:250
RzPdbOmapStream * s_omap
Definition: rz_pdb.h:249

References rz_pdb_t::buf, free(), free_dbi_stream(), free_gdata_stream(), free_omap_stream(), free_pe_stream(), free_tpi_stream(), rz_buf_free(), rz_list_free(), rz_pdb_t::s_dbi, rz_pdb_t::s_gdata, rz_pdb_t::s_omap, rz_pdb_t::s_pdb, rz_pdb_t::s_pe, rz_pdb_t::s_tpi, rz_pdb_t::streams, and rz_pdb_t::super_block.

Referenced by GetHeapGlobalsOffset(), rz_bin_pdb_parse_from_buf(), rz_cmd_info_pdb_show_handler(), rz_core_bin_pdb_load(), and rz_core_bin_print().

◆ rz_bin_pdb_parse_from_buf()

RZ_API RZ_OWN RzPdb* rz_bin_pdb_parse_from_buf ( RZ_NONNULL const RzBuffer buf)

Parse PDB from the buffer.

Parameters
bufmmap of the PDB file
Returns
RzPdb *

Definition at line 315 of file pdb.c.

315  {
317  RzPdb *pdb = RZ_NEW0(RzPdb);
318  if (!pdb) {
319  goto error;
320  }
321  pdb->buf = (RzBuffer *)buf;
324  if (len != PDB_SIGNATURE_LEN) {
325  RZ_LOG_ERROR("Wrong magic length!\n");
326  goto error;
327  }
329  RZ_LOG_ERROR("PDB Signature Error!\n");
330  goto error;
331  }
332  if (!rz_buf_read_le32(pdb->buf, &pdb->super_block->block_size) ||
334  !rz_buf_read_le32(pdb->buf, &pdb->super_block->num_blocks) ||
336  !rz_buf_read_le32(pdb->buf, &pdb->super_block->unknown) ||
338  goto error;
339  }
340  ut64 bufsize = rz_buf_size((RzBuffer *)buf); // length of whole PDB file
341  bool valid =
342  pdb->super_block->num_blocks > 0 &&
343  (ut64)pdb->super_block->num_blocks * pdb->super_block->block_size == bufsize &&
346  if (!valid) {
347  RZ_LOG_ERROR("Invalid MSF superblock!\n");
348  goto error;
349  }
350  if (!pdb7_parse(pdb)) {
351  goto error;
352  }
353  return pdb;
354 error:
355 
356  rz_bin_pdb_free(pdb);
357  return NULL;
358 }
size_t len
Definition: 6502dis.c:15
static bool pdb7_parse(RzPdb *pdb)
Definition: pdb.c:258
RZ_API void rz_bin_pdb_free(RzPdb *pdb)
Free PDB instance.
Definition: pdb.c:366
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define PDB_SIGNATURE
Definition: rz_pdb.h:16
#define PDB_SIGNATURE_LEN
Definition: rz_pdb.h:17
#define st64
Definition: rz_types_base.h:10
MSF file format header https://llvm.org/docs/PDB/MsfFile.html#the-superblock.
Definition: rz_pdb.h:218
char file_magic[PDB_SIGNATURE_LEN]
Must be equal to "Microsoft C / C++ MSF 7.00\\r\\n" followed by the bytes 1A 44 53 00 00 00.
Definition: rz_pdb.h:219
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
bool valid
Definition: core.c:77
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References RzPdbMsfSuperBlock::block_map_addr, RzPdbMsfSuperBlock::block_size, rz_pdb_t::buf, error(), RzPdbMsfSuperBlock::file_magic, RzPdbMsfSuperBlock::free_block_map_block, if(), len, NULL, RzPdbMsfSuperBlock::num_blocks, RzPdbMsfSuperBlock::num_directory_bytes, pdb7_parse(), PDB_SIGNATURE, PDB_SIGNATURE_LEN, rz_bin_pdb_free(), rz_buf_read(), rz_buf_read_le32, rz_buf_size(), RZ_LOG_ERROR, RZ_NEW0, rz_return_val_if_fail, st64, rz_pdb_t::super_block, RzPdbMsfSuperBlock::unknown, ut64(), and valid.

Referenced by rz_bin_pdb_parse_from_file().

◆ rz_bin_pdb_parse_from_file()

RZ_API RZ_OWN RzPdb* rz_bin_pdb_parse_from_file ( RZ_NONNULL const char *  filename)

Parse PDB file given the path.

Parameters
filenamepath of the PDB file
Returns
RzPdb *

Definition at line 292 of file pdb.c.

292  {
295  if (!buf) {
296  RZ_LOG_ERROR("%s: Error reading file \"%s\"\n", __FUNCTION__, filename);
297  return false;
298  }
299 
300  if (is_compressed_pdb(buf)) {
301  rz_buf_free(buf);
302  RZ_LOG_ERROR("The pdb file %s seems to be compressed, please use idpx command to extract the contents.\n", filename);
303  return NULL;
304  }
305 
307 }
const char * filename
Definition: ioapi.h:137
bool is_compressed_pdb(RzBuffer *buf)
Definition: pdb.c:275
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
RZ_API RZ_OWN RzBuffer * rz_buf_new_slurp(const char *file)
Creates a new buffer from a file.
Definition: buf.c:384

References is_compressed_pdb(), NULL, rz_bin_pdb_parse_from_buf(), rz_buf_free(), rz_buf_new_slurp(), RZ_LOG_ERROR, and rz_return_val_if_fail.

Referenced by GetHeapGlobalsOffset(), and rz_core_pdb_load_info().