Rizin
unix-like reverse engineering framework and cli tools
mdmp.h File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include "mdmp_specs.h"
#include "mdmp_pe.h"
#include "mdmp_pe64.h"

Go to the source code of this file.

Classes

struct  rz_bin_mdmp_obj
 
struct  rz_bin_mdmp_obj::minidump_streams
 

Functions

struct rz_bin_mdmp_objrz_bin_mdmp_new_buf (RzBuffer *buf)
 
void rz_bin_mdmp_free (struct rz_bin_mdmp_obj *obj)
 
ut64 rz_bin_mdmp_get_paddr (struct rz_bin_mdmp_obj *obj, ut64 vaddr)
 
ut32 rz_bin_mdmp_get_perm (struct rz_bin_mdmp_obj *obj, ut64 vaddr)
 
struct minidump_memory_info * rz_bin_mdmp_get_mem_info (struct rz_bin_mdmp_obj *obj, ut64 vaddr)
 

Function Documentation

◆ rz_bin_mdmp_free()

void rz_bin_mdmp_free ( struct rz_bin_mdmp_obj obj)

Definition at line 97 of file mdmp.c.

97  {
98  if (!obj) {
99  return;
100  }
101 
112  free(obj->streams.exception);
113  free(obj->streams.system_info);
114  free(obj->streams.comments_a);
115  free(obj->streams.comments_w);
116  free(obj->streams.handle_data);
119 
120  rz_list_free(obj->pe32_bins);
121  rz_list_free(obj->pe64_bins);
122 
123  rz_buf_free(obj->b);
124  free(obj->hdr);
125  obj->b = NULL;
126  free(obj);
127 
128  return;
129 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
struct minidump_handle_data_stream * handle_data
Definition: mdmp.h:27
struct minidump_exception_stream * exception
Definition: mdmp.h:25
struct minidump_misc_info * misc_info_1
Definition: mdmp.h:31
struct minidump_function_table_stream * function_table
Definition: mdmp.h:26
struct minidump_system_info * system_info
Definition: mdmp.h:28
union rz_bin_mdmp_obj::minidump_streams::@162 misc_info
struct rz_bin_mdmp_obj::minidump_streams::@163 memories64
RzList * pe32_bins
Definition: mdmp.h:52
RzBuffer * b
Definition: mdmp.h:55
struct rz_bin_mdmp_obj::minidump_streams streams
RzList * pe64_bins
Definition: mdmp.h:53
struct minidump_header * hdr
Definition: mdmp.h:18

References rz_bin_mdmp_obj::b, rz_bin_mdmp_obj::minidump_streams::comments_a, rz_bin_mdmp_obj::minidump_streams::comments_w, rz_bin_mdmp_obj::minidump_streams::ex_threads, rz_bin_mdmp_obj::minidump_streams::exception, free(), rz_bin_mdmp_obj::minidump_streams::function_table, rz_bin_mdmp_obj::minidump_streams::handle_data, rz_bin_mdmp_obj::hdr, rz_bin_mdmp_obj::minidump_streams::memories, rz_bin_mdmp_obj::minidump_streams::memories64, rz_bin_mdmp_obj::minidump_streams::memory_infos, rz_bin_mdmp_obj::minidump_streams::misc_info, rz_bin_mdmp_obj::minidump_streams::misc_info_1, rz_bin_mdmp_obj::minidump_streams::modules, NULL, rz_bin_mdmp_obj::minidump_streams::operations, rz_bin_mdmp_obj::pe32_bins, rz_bin_mdmp_obj::pe64_bins, rz_buf_free(), rz_list_free(), rz_bin_mdmp_obj::streams, rz_bin_mdmp_obj::minidump_streams::system_info, rz_bin_mdmp_obj::minidump_streams::thread_infos, rz_bin_mdmp_obj::minidump_streams::threads, rz_bin_mdmp_obj::minidump_streams::token_infos, and rz_bin_mdmp_obj::minidump_streams::unloaded_modules.

Referenced by destroy(), and rz_bin_mdmp_new_buf().

◆ rz_bin_mdmp_get_mem_info()

struct minidump_memory_info* rz_bin_mdmp_get_mem_info ( struct rz_bin_mdmp_obj obj,
ut64  vaddr 
)

Definition at line 30 of file mdmp.c.

30  {
31  struct minidump_memory_info *mem_info;
32  RzListIter *it;
33 
34  if (!obj) {
35  return NULL;
36  }
37 
38  rz_list_foreach (obj->streams.memory_infos, it, mem_info) {
39  if (mem_info->allocation_base && vaddr == mem_info->base_address) {
40  return mem_info;
41  }
42  }
43 
44  return NULL;
45 }

References rz_bin_mdmp_obj::minidump_streams::memory_infos, NULL, and rz_bin_mdmp_obj::streams.

Referenced by mem(), and rz_bin_mdmp_get_perm().

◆ rz_bin_mdmp_get_paddr()

ut64 rz_bin_mdmp_get_paddr ( struct rz_bin_mdmp_obj obj,
ut64  vaddr 
)

Definition at line 11 of file mdmp.c.

11  {
12  /* FIXME: Will only resolve exact matches, probably no need to fix as
13  ** this function will become redundant on the optimisation stage */
14  struct minidump_memory_descriptor64 *memory;
15  ut64 index, paddr = 0;
16  RzListIter *it;
17 
18  /* Loop through the memories sections looking for a match */
19  index = obj->streams.memories64.base_rva;
20  rz_list_foreach (obj->streams.memories64.memories, it, memory) {
21  if (vaddr == memory->start_of_memory_range) {
22  paddr = index;
23  break;
24  }
25  index += memory->data_size;
26  }
27  return paddr;
28 }
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_bin_mdmp_obj::minidump_streams::base_rva, rz_bin_mdmp_obj::minidump_streams::memories, rz_bin_mdmp_obj::minidump_streams::memories64, rz_bin_mdmp_obj::streams, and ut64().

Referenced by rz_bin_mdmp_init_pe_bins(), and sections().

◆ rz_bin_mdmp_get_perm()

ut32 rz_bin_mdmp_get_perm ( struct rz_bin_mdmp_obj obj,
ut64  vaddr 
)

Definition at line 47 of file mdmp.c.

47  {
48  struct minidump_memory_info *mem_info;
49 
50  if (!(mem_info = rz_bin_mdmp_get_mem_info(obj, vaddr))) {
51  /* if there is no mem info in the dump, assume default permission */
52  return RZ_PERM_R;
53  }
54 
55  /* FIXME: Have I got these mappings right, I am not sure I have!!! */
56 
57  switch (mem_info->protect) {
59  return RZ_PERM_R;
61  return RZ_PERM_RW;
63  return RZ_PERM_X;
65  return RZ_PERM_RX;
67  return RZ_PERM_RWX;
74  default:
75  return 0;
76  }
77 }
struct minidump_memory_info * rz_bin_mdmp_get_mem_info(struct rz_bin_mdmp_obj *obj, ut64 vaddr)
Definition: mdmp.c:30
#define MINIDUMP_PAGE_EXECUTE_WRITECOPY
Definition: mdmp_specs.h:58
#define MINIDUMP_PAGE_NOACCESS
Definition: mdmp_specs.h:51
#define MINIDUMP_PAGE_WRITECOMBINE
Definition: mdmp_specs.h:61
#define MINIDUMP_PAGE_GUARD
Definition: mdmp_specs.h:59
#define MINIDUMP_PAGE_EXECUTE_READ
Definition: mdmp_specs.h:56
#define MINIDUMP_PAGE_READONLY
Definition: mdmp_specs.h:52
#define MINIDUMP_PAGE_EXECUTE_READWRITE
Definition: mdmp_specs.h:57
#define MINIDUMP_PAGE_READWRITE
Definition: mdmp_specs.h:53
#define MINIDUMP_PAGE_NOCACHE
Definition: mdmp_specs.h:60
#define MINIDUMP_PAGE_WRITECOPY
Definition: mdmp_specs.h:54
#define MINIDUMP_PAGE_EXECUTE
Definition: mdmp_specs.h:55
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_PERM_RW
Definition: rz_types.h:96
#define RZ_PERM_X
Definition: rz_types.h:95
#define RZ_PERM_RX
Definition: rz_types.h:97
#define RZ_PERM_RWX
Definition: rz_types.h:98

References MINIDUMP_PAGE_EXECUTE, MINIDUMP_PAGE_EXECUTE_READ, MINIDUMP_PAGE_EXECUTE_READWRITE, MINIDUMP_PAGE_EXECUTE_WRITECOPY, MINIDUMP_PAGE_GUARD, MINIDUMP_PAGE_NOACCESS, MINIDUMP_PAGE_NOCACHE, MINIDUMP_PAGE_READONLY, MINIDUMP_PAGE_READWRITE, MINIDUMP_PAGE_WRITECOMBINE, MINIDUMP_PAGE_WRITECOPY, rz_bin_mdmp_get_mem_info(), RZ_PERM_R, RZ_PERM_RW, RZ_PERM_RWX, RZ_PERM_RX, and RZ_PERM_X.

Referenced by maps(), and mem().

◆ rz_bin_mdmp_new_buf()

struct rz_bin_mdmp_obj* rz_bin_mdmp_new_buf ( RzBuffer buf)

Definition at line 1389 of file mdmp.c.

1389  {
1390  bool fail = false;
1391  struct rz_bin_mdmp_obj *obj = RZ_NEW0(struct rz_bin_mdmp_obj);
1392  if (!obj) {
1393  return NULL;
1394  }
1395  obj->kv = sdb_new0();
1396  obj->size = (ut32)rz_buf_size(buf);
1397 
1398  fail |= (!(obj->streams.ex_threads = rz_list_new()));
1399  fail |= (!(obj->streams.memories = rz_list_newf((RzListFree)free)));
1400  fail |= (!(obj->streams.memories64.memories = rz_list_new()));
1402  fail |= (!(obj->streams.modules = rz_list_newf((RzListFree)free)));
1406  fail |= (!(obj->streams.threads = rz_list_new()));
1408 
1411 
1412  if (fail) {
1413  rz_bin_mdmp_free(obj);
1414  return NULL;
1415  }
1416 
1417  obj->b = rz_buf_ref(buf);
1418  if (!rz_bin_mdmp_init(obj)) {
1419  rz_bin_mdmp_free(obj);
1420  return NULL;
1421  }
1422 
1423  return obj;
1424 }
uint32_t ut32
voidpf void * buf
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_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
static int rz_bin_mdmp_init(struct rz_bin_mdmp_obj *obj)
Definition: mdmp.c:1368
static void rz_bin_mdmp_free_pe64_bin(void *pe_bin_)
Definition: mdmp.c:88
void rz_bin_mdmp_free(struct rz_bin_mdmp_obj *obj)
Definition: mdmp.c:97
static void rz_bin_mdmp_free_pe32_bin(void *pe_bin_)
Definition: mdmp.c:79
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
Sdb * kv
Definition: mdmp.h:58
size_t size
Definition: mdmp.h:56
#define fail(test)
Definition: tests.h:29

References rz_bin_mdmp_obj::b, rz_bin_mdmp_obj::minidump_streams::ex_threads, fail, free(), rz_bin_mdmp_obj::kv, rz_bin_mdmp_obj::minidump_streams::memories, rz_bin_mdmp_obj::minidump_streams::memories64, rz_bin_mdmp_obj::minidump_streams::memory_infos, rz_bin_mdmp_obj::minidump_streams::modules, NULL, rz_bin_mdmp_obj::minidump_streams::operations, rz_bin_mdmp_obj::pe32_bins, rz_bin_mdmp_obj::pe64_bins, rz_bin_mdmp_free(), rz_bin_mdmp_free_pe32_bin(), rz_bin_mdmp_free_pe64_bin(), rz_bin_mdmp_init(), rz_buf_ref(), rz_buf_size(), rz_list_new(), rz_list_newf(), RZ_NEW0, sdb_new0(), rz_bin_mdmp_obj::size, rz_bin_mdmp_obj::streams, rz_bin_mdmp_obj::minidump_streams::thread_infos, rz_bin_mdmp_obj::minidump_streams::threads, rz_bin_mdmp_obj::minidump_streams::token_infos, and rz_bin_mdmp_obj::minidump_streams::unloaded_modules.

Referenced by load_buffer().