Rizin
unix-like reverse engineering framework and cli tools
io_winkd.c File Reference
#include <rz_io.h>
#include <rz_lib.h>
#include <rz_socket.h>
#include <rz_util.h>
#include <transport.h>
#include <winkd.h>

Go to the source code of this file.

Classes

struct  ReadAtCtx
 

Functions

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 bool __plugin_open (RzIO *io, const char *file, bool many)
 
static RzIODesc__open (RzIO *io, const char *file, int rw, int mode)
 
static int __write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static ut64 __lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static int __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int __close (RzIODesc *fd)
 

Variables

RzIOPlugin rz_io_plugin_winkd
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ __close()

static int __close ( RzIODesc fd)
static

Definition at line 143 of file io_winkd.c.

143  {
144  winkd_kdctx_free((KdCtx **)&fd->data);
145  return true;
146 }
Definition: winkd.h:95
void winkd_kdctx_free(RZ_OWN KdCtx **ctx)
Definition: winkd.c:187
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, and winkd_kdctx_free().

◆ __lseek()

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

Definition at line 118 of file io_winkd.c.

118  {
119  switch (whence) {
120  case RZ_IO_SEEK_SET:
121  return io->off = offset;
122  case RZ_IO_SEEK_CUR:
123  return io->off += offset;
124  case RZ_IO_SEEK_END:
125  return io->off = UT64_MAX;
126  default:
127  return offset;
128  }
129 }
voidpf uLong offset
Definition: ioapi.h:144
#define RZ_IO_SEEK_CUR
Definition: rz_io.h:16
#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

References rz_io_t::off, RZ_IO_SEEK_CUR, RZ_IO_SEEK_END, RZ_IO_SEEK_SET, and UT64_MAX.

◆ __open()

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

Definition at line 53 of file io_winkd.c.

53  {
54  if (!__plugin_open(io, file, 0)) {
55  return NULL;
56  }
57 
58  // net - host:ip:key
59  // pipe - \\.\pipe\com_1 /tmp/windbg.pipe
60  io_backend_t *iob = NULL;
61  if (strchr(file + 8, ':')) {
62  iob = &iob_net;
63  } else {
64  iob = &iob_pipe;
65  }
66 
67  if (!iob) {
68  eprintf("Error: Invalid WinDBG path\n");
69  return NULL;
70  }
71 
72  void *io_ctx = iob->open(file + 8);
73  if (!io_ctx) {
74  eprintf("Error: Could not open the %s\n", iob->name);
75  return NULL;
76  }
77  eprintf("Opened %s %s with fd %p\n", iob->name, file + 8, io_ctx);
78 
79  io_desc_t *desc = io_desc_new(iob, io_ctx);
80  if (!desc) {
81  eprintf("Error: Could not create io_desc_t\n");
82  return NULL;
83  }
84 
86  if (!ctx) {
87  eprintf("Failed to initialize winkd context\n");
88  return NULL;
89  }
90  ctx->windctx.read_at_physical = read_at_phys;
91  ctx->windctx.write_at_physical = write_at_phys;
92  ctx->windctx.read_at_kernel_virtual = read_at_kernel_virtual;
94  if (!c) {
95  free(ctx);
96  return NULL;
97  }
98  c->fd = rz_io_desc_new(io, &rz_io_plugin_winkd, file, rw, mode, ctx);
99  if (!c->fd) {
100  free(c);
101  free(ctx);
102  return NULL;
103  }
104  ctx->windctx.user = c;
105  return c->fd;
106 }
const char * desc
Definition: bin_vsf.c:19
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static int read_at_phys(void *user, ut64 address, ut8 *buf, int len)
Definition: io_winkd.c:36
static bool __plugin_open(RzIO *io, const char *file, bool many)
Definition: io_winkd.c:49
static int read_at_kernel_virtual(void *user, ut64 address, ut8 *buf, int len)
Definition: io_winkd.c:44
static int write_at_phys(void *user, ut64 address, const ut8 *buf, int len)
Definition: io_winkd.c:40
RzIOPlugin rz_io_plugin_winkd
Definition: io_winkd.c:148
const char int mode
Definition: ioapi.h:137
io_backend_t iob_net
Definition: iob_net.c:564
io_backend_t iob_pipe
Definition: iob_pipe.c:130
#define eprintf(x, y...)
Definition: rlcc.c:7
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define c(i)
Definition: sha256.c:43
Definition: gzappend.c:170
const char * name
Definition: transport.h:28
void *(* open)(const char *path)
Definition: transport.h:32
io_desc_t * io_desc_new(io_backend_t *iob, void *fp)
Definition: transport.c:7
KdCtx * winkd_kdctx_new(RZ_BORROW RZ_NONNULL io_desc_t *desc)
Definition: winkd.c:177

References __plugin_open(), c, desc, eprintf, free(), io_desc_new(), iob_net, iob_pipe, io_backend_t::name, NULL, io_backend_t::open, read_at_kernel_virtual(), read_at_phys(), rz_io_desc_new(), rz_io_plugin_winkd, RZ_NEW0, winkd_kdctx_new(), and write_at_phys().

◆ __plugin_open()

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

Definition at line 49 of file io_winkd.c.

49  {
50  return (!strncmp(file, "winkd://", 8));
51 }

Referenced by __open().

◆ __read()

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

Definition at line 131 of file io_winkd.c.

131  {
132  if (!fd) {
133  return -1;
134  }
135 
136  if (winkd_get_target(fd->data)) {
137  return winkd_read_at_uva(fd->data, io->off, buf, count);
138  }
139 
140  return winkd_read_at(fd->data, io->off, buf, count);
141 }
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
voidpf void * buf
Definition: ioapi.h:138
ut32 winkd_get_target(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:158
int winkd_read_at(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, const int count)
Definition: winkd.c:1377
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

References count, fd, rz_io_t::off, winkd_get_target(), winkd_read_at(), and winkd_read_at_uva().

◆ __write()

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

Definition at line 108 of file io_winkd.c.

108  {
109  if (!fd) {
110  return -1;
111  }
112  if (winkd_get_target(fd->data)) {
113  return winkd_write_at_uva(fd->data, io->off, buf, count);
114  }
115  return winkd_write_at(fd->data, io->off, buf, count);
116 }
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
int winkd_write_at(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, const int count)
Definition: winkd.c:1384

References count, fd, rz_io_t::off, winkd_get_target(), winkd_write_at(), and winkd_write_at_uva().

◆ 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 30 of file io_winkd.c.

30  {
31  ReadAtCtx *ctx = user;
32  int ret = write ? winkd_write_at_phys(ctx->fd->data, address, in, len) : winkd_read_at_phys(ctx->fd->data, address, out, len);
33  return ret;
34 }
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
int winkd_write_at_phys(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, const int count)
Definition: winkd.c:1408
int winkd_read_at_phys(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, const int count)
Definition: winkd.c:1370

References in, len, out, winkd_read_at_phys(), winkd_write_at_phys(), 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 44 of file io_winkd.c.

44  {
45  ReadAtCtx *ctx = user;
46  return winkd_read_at(ctx->fd->data, address, buf, len);
47 }

References len, and winkd_read_at().

Referenced by __open().

◆ read_at_phys()

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

Definition at line 36 of file io_winkd.c.

36  {
37  return op_at_phys(user, address, NULL, buf, len, false);
38 }
static int op_at_phys(void *user, ut64 address, const ut8 *in, ut8 *out, int len, bool write)
Definition: io_winkd.c:30

References len, NULL, and op_at_phys().

Referenced by __open().

◆ write_at_phys()

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

Definition at line 40 of file io_winkd.c.

40  {
41  return op_at_phys(user, address, buf, NULL, len, true);
42 }

References len, NULL, and op_at_phys().

Referenced by __open().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
}
@ 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 163 of file io_winkd.c.

◆ rz_io_plugin_winkd

RzIOPlugin rz_io_plugin_winkd
Initial value:
= {
.name = "winkd",
.desc = "Attach to a KD debugger",
.uris = "winkd://",
.license = "LGPL3",
.open = __open,
.close = __close,
.read = __read,
.check = __plugin_open,
.lseek = __lseek,
.write = __write,
.isdbg = true
}
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_winkd.c:131
static RzIODesc * __open(RzIO *io, const char *file, int rw, int mode)
Definition: io_winkd.c:53
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_winkd.c:108
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_winkd.c:118
static int __close(RzIODesc *fd)
Definition: io_winkd.c:143

Definition at line 148 of file io_winkd.c.

Referenced by __open().