Rizin
unix-like reverse engineering framework and cli tools
io_dmp.c File Reference
#include <rz_io.h>
#include <winkd.h>
#include "librz/bin/format/dmp/dmp_specs.h"

Go to the source code of this file.

Classes

struct  ReadAtCtx
 

Functions

static bool dmp_plugin_open (RzIO *io, const char *file, bool many)
 
static int op_at_phys (void *user, ut64 address, const ut8 *in, ut8 *out, int len, bool write)
 
static int read_at_phys (void *user, ut64 address, ut8 *buf, int len)
 
static int write_at_phys (void *user, ut64 address, const ut8 *buf, int len)
 
static int read_at_kernel_virtual (void *user, ut64 address, ut8 *buf, int len)
 
static RzIODescdmp_open (RzIO *io, const char *file, int rw, int mode)
 
static int dmp_write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static ut64 dmp_lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static int dmp_read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int dmp_close (RzIODesc *fd)
 

Variables

RzIOPlugin rz_io_plugin_dmp
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ dmp_close()

static int dmp_close ( RzIODesc fd)
static

Definition at line 152 of file io_dmp.c.

152  {
153  DmpCtx *ctx = fd->data;
154  rz_io_desc_close(ctx->backend);
155  winkd_ctx_fini(&ctx->windctx);
156  rz_vector_fini(&ctx->KiProcessorBlock);
157  free(ctx->context);
158  RZ_FREE(fd->data);
159  return true;
160 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API bool rz_io_desc_close(RzIODesc *desc)
Definition: io_desc.c:165
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_API void rz_vector_fini(RzVector *vec)
Definition: vector.c:61
Definition: winkd.h:118
static void winkd_ctx_fini(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.h:141
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, free(), RZ_FREE, rz_io_desc_close(), rz_vector_fini(), and winkd_ctx_fini().

◆ dmp_lseek()

static ut64 dmp_lseek ( RzIO io,
RzIODesc fd,
ut64  offset,
int  whence 
)
static

Definition at line 116 of file io_dmp.c.

116  {
117  DmpCtx *ctx = fd->data;
118  if (ctx->target == TARGET_BACKEND) {
119  return rz_io_desc_seek(ctx->backend, offset, whence);
120  } else {
121  switch (whence) {
122  case RZ_IO_SEEK_SET: return io->off = offset;
123  case RZ_IO_SEEK_CUR: return io->off += offset;
124  case RZ_IO_SEEK_END: return io->off = UT64_MAX - offset;
125  default: return offset;
126  }
127  }
128 }
voidpf uLong offset
Definition: ioapi.h:144
#define RZ_IO_SEEK_CUR
Definition: rz_io.h:16
RZ_API ut64 rz_io_desc_seek(RzIODesc *desc, ut64 offset, int whence)
Definition: io_desc.c:217
#define RZ_IO_SEEK_SET
Definition: rz_io.h:15
#define RZ_IO_SEEK_END
Definition: rz_io.h:17
#define UT64_MAX
Definition: rz_types_base.h:86
ut64 off
Definition: rz_io.h:61
#define TARGET_BACKEND
Definition: winkd.h:113

References fd, rz_io_t::off, rz_io_desc_seek(), RZ_IO_SEEK_CUR, RZ_IO_SEEK_END, RZ_IO_SEEK_SET, TARGET_BACKEND, and UT64_MAX.

◆ dmp_open()

static RzIODesc* dmp_open ( RzIO io,
const char *  file,
int  rw,
int  mode 
)
static

Definition at line 55 of file io_dmp.c.

55  {
56  if (!dmp_plugin_open(io, file, 0)) {
57  return NULL;
58  }
59  RzIOPlugin *p = rz_io_plugin_resolve(io, file + 6, false);
60  if (!p) {
61  return NULL;
62  }
64  if (!ctx) {
65  return NULL;
66  }
67  rz_vector_init(&ctx->KiProcessorBlock, sizeof(ut64), NULL, NULL);
68  ctx->backend = p->open(io, file + 6, rw, mode);
69  if (!ctx->backend) {
70  free(ctx);
71  return NULL;
72  }
73  ctx->target = TARGET_BACKEND;
74  ctx->windctx.read_at_physical = read_at_phys;
75  ctx->windctx.write_at_physical = write_at_phys;
76  ctx->windctx.read_at_kernel_virtual = read_at_kernel_virtual;
78  if (!c) {
79  free(ctx);
80  return NULL;
81  }
82  c->io = io;
83  c->fd = rz_io_desc_new(io, &rz_io_plugin_dmp, file, rw, mode, ctx);
84  if (!c->fd) {
85  free(c);
86  free(ctx);
87  return NULL;
88  }
89  c->fd->name = strdup(file + 6);
90  ctx->windctx.user = c;
91  return c->fd;
92 }
#define NULL
Definition: cris-opc.c:27
static int read_at_phys(void *user, ut64 address, ut8 *buf, int len)
Definition: io_dmp.c:30
static bool dmp_plugin_open(RzIO *io, const char *file, bool many)
Definition: io_dmp.c:8
static int read_at_kernel_virtual(void *user, ut64 address, ut8 *buf, int len)
Definition: io_dmp.c:38
static int write_at_phys(void *user, ut64 address, const ut8 *buf, int len)
Definition: io_dmp.c:34
RzIOPlugin rz_io_plugin_dmp
Definition: io_dmp.c:162
const char int mode
Definition: ioapi.h:137
void * p
Definition: libc.cpp:67
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
Definition: io_desc.c:11
RZ_API RzIOPlugin * rz_io_plugin_resolve(RzIO *io, const char *filename, bool many)
Definition: io_plugin.c:54
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:33
#define c(i)
Definition: sha256.c:43
Definition: gzappend.c:170
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References c, dmp_plugin_open(), free(), NULL, p, read_at_kernel_virtual(), read_at_phys(), rz_io_desc_new(), rz_io_plugin_dmp, rz_io_plugin_resolve(), RZ_NEW0, rz_vector_init(), strdup(), TARGET_BACKEND, ut64(), and write_at_phys().

◆ dmp_plugin_open()

static bool dmp_plugin_open ( RzIO io,
const char *  file,
bool  many 
)
static

Definition at line 8 of file io_dmp.c.

8  {
9  return (!strncmp(file, "dmp://", 6));
10 }

Referenced by dmp_open().

◆ dmp_read()

static int dmp_read ( RzIO io,
RzIODesc fd,
ut8 buf,
int  count 
)
static

Definition at line 130 of file io_dmp.c.

130  {
131  if (!fd) {
132  return -1;
133  }
134  DmpCtx *ctx = fd->data;
135  if (ctx->target == TARGET_BACKEND) {
136  return rz_io_desc_read_at(ctx->backend, io->off, buf, count);
137  }
138  ut64 address = io->off;
139  if (ctx->target != TARGET_PHYSICAL) {
140  WindProc saved_proc = ctx->windctx.target;
141  WindProc kernel_proc = { .dir_base_table = ctx->kernelDirectoryTable };
142  if (ctx->target == TARGET_KERNEL) {
143  ctx->windctx.target = kernel_proc;
144  }
145  int ret = winkd_read_at_uva(&ctx->windctx, address, buf, count);
146  ctx->windctx.target = saved_proc;
147  return ret;
148  }
149  return read_at_phys(ctx->windctx.user, address, buf, count);
150 }
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 count
Definition: sflib.h:98
@ TARGET_KERNEL
Definition: io_windbg.c:397
voidpf void * buf
Definition: ioapi.h:138
RZ_API int rz_io_desc_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, int len)
Definition: io_desc.c:351
Definition: winkd.h:11
ut64 dir_base_table
Definition: winkd.h:15
int winkd_read_at_uva(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 address, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, int count)
Definition: winkd.c:596
#define TARGET_PHYSICAL
Definition: winkd.h:114

References count, WindProc::dir_base_table, fd, rz_io_t::off, read_at_phys(), rz_io_desc_read_at(), TARGET_BACKEND, TARGET_KERNEL, TARGET_PHYSICAL, ut64(), and winkd_read_at_uva().

◆ dmp_write()

static int dmp_write ( RzIO io,
RzIODesc fd,
const ut8 buf,
int  count 
)
static

Definition at line 94 of file io_dmp.c.

94  {
95  if (!fd) {
96  return -1;
97  }
98  DmpCtx *ctx = fd->data;
99  if (ctx->target == TARGET_BACKEND) {
100  return rz_io_desc_write_at(ctx->backend, io->off, buf, count);
101  }
102  ut64 address = io->off;
103  if (ctx->target != TARGET_PHYSICAL) {
104  WindProc saved_proc = ctx->windctx.target;
105  WindProc kernel_proc = { .dir_base_table = ctx->kernelDirectoryTable };
106  if (ctx->target == TARGET_KERNEL) {
107  ctx->windctx.target = kernel_proc;
108  }
109  int ret = winkd_write_at_uva(&ctx->windctx, address, buf, count);
110  ctx->windctx.target = saved_proc;
111  return ret;
112  }
113  return write_at_phys(ctx->windctx.user, address, buf, count);
114 }
RZ_API int rz_io_desc_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, int len)
Definition: io_desc.c:358
int winkd_write_at_uva(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 address, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, int count)
Definition: winkd.c:600

References count, WindProc::dir_base_table, fd, rz_io_t::off, rz_io_desc_write_at(), TARGET_BACKEND, TARGET_KERNEL, TARGET_PHYSICAL, ut64(), winkd_write_at_uva(), and write_at_phys().

◆ op_at_phys()

static int op_at_phys ( void *  user,
ut64  address,
const ut8 in,
ut8 out,
int  len,
bool  write 
)
static

Definition at line 17 of file io_dmp.c.

17  {
18  ReadAtCtx *ctx = user;
19  DmpCtx *dmp = ctx->fd->data;
20  const ut64 saved_target = dmp->target;
21  dmp->target = TARGET_BACKEND;
22  int saved_va = ctx->io->va;
23  ctx->io->va = 1;
24  int ret = write ? rz_io_write_at(ctx->io, address, in, len) : rz_io_nread_at(ctx->io, address, out, len);
25  ctx->io->va = saved_va;
26  dmp->target = saved_target;
27  return ret;
28 }
size_t len
Definition: 6502dis.c:15
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static static fork write
Definition: sflib.h:33
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358
RZ_API int rz_io_nread_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:338
ut64 target
Definition: winkd.h:121

References in, len, out, rz_io_nread_at(), rz_io_write_at(), _DmpCtx::target, TARGET_BACKEND, ut64(), and write.

Referenced by read_at_phys(), and write_at_phys().

◆ read_at_kernel_virtual()

static int read_at_kernel_virtual ( void *  user,
ut64  address,
ut8 buf,
int  len 
)
static

Definition at line 38 of file io_dmp.c.

38  {
39  ReadAtCtx *ctx = user;
40  DmpCtx *dmp = ctx->fd->data;
41  if (dmp->type == DMP_DUMPTYPE_TRIAGE) {
42  int saved_va = ctx->io->va;
43  ctx->io->va = 1;
44  int ret = rz_io_nread_at(ctx->io, address, buf, len);
45  ctx->io->va = saved_va;
46  return ret;
47  }
48  const ut64 saved_target = dmp->target;
49  dmp->target = TARGET_KERNEL;
50  int ret = rz_io_desc_read_at(ctx->fd, address, buf, len);
51  dmp->target = saved_target;
52  return ret;
53 }
#define DMP_DUMPTYPE_TRIAGE
Definition: dmp_specs.h:20
ut32 type
Definition: winkd.h:120

References DMP_DUMPTYPE_TRIAGE, len, rz_io_desc_read_at(), rz_io_nread_at(), _DmpCtx::target, TARGET_KERNEL, _DmpCtx::type, and ut64().

Referenced by dmp_open().

◆ read_at_phys()

static int read_at_phys ( void *  user,
ut64  address,
ut8 buf,
int  len 
)
static

Definition at line 30 of file io_dmp.c.

30  {
31  return op_at_phys(user, address, NULL, buf, len, false);
32 }
static int op_at_phys(void *user, ut64 address, const ut8 *in, ut8 *out, int len, bool write)
Definition: io_dmp.c:17

References len, NULL, and op_at_phys().

Referenced by dmp_open(), and dmp_read().

◆ write_at_phys()

static int write_at_phys ( void *  user,
ut64  address,
const ut8 buf,
int  len 
)
static

Definition at line 34 of file io_dmp.c.

34  {
35  return op_at_phys(user, address, buf, NULL, len, true);
36 }

References len, NULL, and op_at_phys().

Referenced by dmp_open(), and dmp_write().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
.data = &rz_io_plugin_dmp,
}
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_io.h:117

Definition at line 176 of file io_dmp.c.

◆ rz_io_plugin_dmp

RzIOPlugin rz_io_plugin_dmp
Initial value:
= {
.name = "dmp",
.desc = "Debug a Windows DMP file",
.uris = "dmp://",
.license = "LGPL3",
.open = dmp_open,
.close = dmp_close,
.read = dmp_read,
.check = dmp_plugin_open,
.lseek = dmp_lseek,
.write = dmp_write,
}
static RzIODesc * dmp_open(RzIO *io, const char *file, int rw, int mode)
Definition: io_dmp.c:55
static int dmp_close(RzIODesc *fd)
Definition: io_dmp.c:152
static ut64 dmp_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_dmp.c:116
static int dmp_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_dmp.c:130
static int dmp_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_dmp.c:94

Definition at line 162 of file io_dmp.c.

Referenced by dmp_open().