Rizin
unix-like reverse engineering framework and cli tools
stream_pe.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2021 Basstorm <basstorm@nyist.edu.cn>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include "pdb.h"
6 
9  return rz_buf_read_le32(buf, &hdr->misc.physical_address) &&
18 }
19 
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 }
54  if (!stream) {
55  return;
56  }
57  rz_list_free(stream->sections_hdrs);
58  free(stream);
59 };
#define RZ_IPI
Definition: analysis_wasm.c:11
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf stream
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
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 RzSocket * s
Definition: rtr.c:28
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#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)
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
RZ_IPI void free_pe_stream(RzPdbPeStream *stream)
Definition: stream_pe.c:53
RZ_IPI bool parse_pe_stream(RzPdb *pdb, RzPdbMsfStream *stream)
Definition: stream_pe.c:20
static bool parse_image_header(PeImageSectionHeader *hdr, RzBuffer *buf)
Definition: stream_pe.c:7
#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
RzPdbPeStream * s_pe
Definition: rz_pdb.h:250
ut32 physical_address
Definition: stream_pe.h:10