Rizin
unix-like reverse engineering framework and cli tools
stream_pe.c File Reference
#include "pdb.h"

Go to the source code of this file.

Functions

static bool parse_image_header (PeImageSectionHeader *hdr, RzBuffer *buf)
 
RZ_IPI bool parse_pe_stream (RzPdb *pdb, RzPdbMsfStream *stream)
 
RZ_IPI void free_pe_stream (RzPdbPeStream *stream)
 

Function Documentation

◆ free_pe_stream()

RZ_IPI void free_pe_stream ( RzPdbPeStream stream)

Definition at line 53 of file stream_pe.c.

53  {
54  if (!stream) {
55  return;
56  }
57  rz_list_free(stream->sections_hdrs);
58  free(stream);
59 };
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf stream
Definition: ioapi.h:138
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References free(), and rz_list_free().

Referenced by rz_bin_pdb_free().

◆ parse_image_header()

static bool parse_image_header ( PeImageSectionHeader hdr,
RzBuffer buf 
)
static

Definition at line 7 of file stream_pe.c.

7  {
9  return rz_buf_read_le32(buf, &hdr->misc.physical_address) &&
18 }
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#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 PDB_SIZEOF_SECTION_NAME
Definition: stream_pe.h:14
ut16 number_of_line_numbers
Definition: stream_pe.h:25
ut32 pointer_to_relocations
Definition: stream_pe.h:22
ut16 number_of_relocations
Definition: stream_pe.h:24
ut32 pointer_to_line_numbers
Definition: stream_pe.h:23
ut32 physical_address
Definition: stream_pe.h:10

References PeImageSectionHeader::charactestics, PeImageSectionHeader::misc, PeImageSectionHeader::name, PeImageSectionHeader::number_of_line_numbers, PeImageSectionHeader::number_of_relocations, PDB_SIZEOF_SECTION_NAME, PeMisc::physical_address, PeImageSectionHeader::pointer_to_line_numbers, PeImageSectionHeader::pointer_to_raw_data, PeImageSectionHeader::pointer_to_relocations, rz_buf_read(), rz_buf_read_le16, rz_buf_read_le32, PeImageSectionHeader::size_of_raw_data, and PeImageSectionHeader::virtual_address.

Referenced by parse_pe_stream().

◆ parse_pe_stream()

RZ_IPI bool parse_pe_stream ( RzPdb pdb,
RzPdbMsfStream stream 
)

Definition at line 20 of file stream_pe.c.

20  {
21  rz_return_val_if_fail(pdb && stream, false);
22  if (!pdb->s_pe) {
23  pdb->s_pe = RZ_NEW0(RzPdbPeStream);
24  }
25  RzBuffer *buf = stream->stream_data;
26  RzPdbPeStream *s = pdb->s_pe;
27  if (!s) {
28  RZ_LOG_ERROR("Error allocating memory.\n");
29  return false;
30  }
31  if (!s->sections_hdrs) {
32  s->sections_hdrs = rz_list_newf(free);
33  }
35  ut32 read_len = 0;
36  while (read_len < size) {
38  if (!hdr) {
39  rz_list_free(s->sections_hdrs);
40  return false;
41  }
42  if (!parse_image_header(hdr, buf)) {
43  rz_list_free(s->sections_hdrs);
44  free(hdr);
45  return false;
46  }
47 
48  read_len += sizeof(PeImageSectionHeader);
49  rz_list_append(s->sections_hdrs, hdr);
50  }
51  return true;
52 }
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
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
static RzSocket * s
Definition: rtr.c:28
#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 RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_NEW0(x)
Definition: rz_types.h:284
static bool parse_image_header(PeImageSectionHeader *hdr, RzBuffer *buf)
Definition: stream_pe.c:7
RzPdbPeStream * s_pe
Definition: rz_pdb.h:250

References free(), parse_image_header(), rz_buf_size(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, rz_return_val_if_fail, s, and rz_pdb_t::s_pe.

Referenced by parse_streams().