Rizin
unix-like reverse engineering framework and cli tools
io_rzk.c File Reference
#include <rz_io.h>
#include <rz_lib.h>
#include <rz_types.h>
#include <rz_util.h>
#include <sys/types.h>

Go to the source code of this file.

Functions

int rzk__write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static int rzk__read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int rzk__close (RzIODesc *fd)
 
static ut64 rzk__lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static bool rzk__plugin_open (RzIO *io, const char *pathname, bool many)
 
static char * rzk__system (RzIO *io, RzIODesc *fd, const char *cmd)
 
static RzIODescrzk__open (RzIO *io, const char *pathname, int rw, int mode)
 

Variables

RzIOPlugin rz_io_plugin_rzk
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ rzk__close()

static int rzk__close ( RzIODesc fd)
static

Definition at line 63 of file io_rzk.c.

63  {
64 #if __WINDOWS__
65  if (gHandleDriver) {
66  CloseHandle(gHandleDriver);
67  StartStopService(TEXT("rzk"), TRUE);
68  }
69 #elif defined(__linux__) && !defined(__GNU__)
70  if (fd) {
71  close((int)(size_t)fd->data);
72  }
73 #else
74  eprintf("TODO: rzk not implemented for this plataform.\n");
75 #endif
76  return 0;
77 }
static static fork const void static count close
Definition: sflib.h:33
HANDLE gHandleDriver
Definition: io_rzk_windows.c:8
BOOL StartStopService(LPCTSTR lpServiceName, BOOL bStop)
#define TRUE
Definition: mybfd.h:103
#define eprintf(x, y...)
Definition: rlcc.c:7
static const z80_opcode fd[]
Definition: z80_tab.h:997

References close, eprintf, fd, gHandleDriver, StartStopService(), and TRUE.

◆ rzk__lseek()

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

Definition at line 79 of file io_rzk.c.

79  {
80  return (!whence) ? offset : whence == 1 ? io->off + offset
81  : UT64_MAX;
82 }
voidpf uLong offset
Definition: ioapi.h:144
#define UT64_MAX
Definition: rz_types_base.h:86
ut64 off
Definition: rz_io.h:61

References rz_io_t::off, and UT64_MAX.

◆ rzk__open()

static RzIODesc* rzk__open ( RzIO io,
const char *  pathname,
int  rw,
int  mode 
)
static

Definition at line 107 of file io_rzk.c.

107  {
108  if (!strncmp(pathname, "rzk://", 6)) {
109  rw |= RZ_PERM_WX;
110 #if __WINDOWS__
111  RzIOW32 *w32 = RZ_NEW0(RzIOW32);
112  if (Init(&pathname[6]) == FALSE) {
113  eprintf("rzk__open: Error cant init driver: %s\n", &pathname[6]);
114  free(w32);
115  return NULL;
116  }
117  // return rz_io_desc_new (&rz_io_plugin_rzk, -1, pathname, rw, mode, w32);
118  return rz_io_desc_new(io, &rz_io_plugin_rzk, pathname, rw, mode, w32);
119 #elif defined(__linux__) && !defined(__GNU__)
120  int fd = open("/dev/rzk", O_RDONLY);
121  if (fd == -1) {
122  io->cb_printf("rzk__open: Error in opening /dev/rzk.");
123  return NULL;
124  }
125 
126  rzk_struct.beid = 0;
127  rzk_struct.pid = 0;
128  rzk_struct.wp = 1;
129  return rz_io_desc_new(io, &rz_io_plugin_rzk, pathname, rw, mode, (void *)(size_t)fd);
130 #else
131  io->cb_printf("Not supported on this platform\n");
132 #endif
133  }
134  return NULL;
135 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RzIOPlugin rz_io_plugin_rzk
Definition: io_rzk.c:137
struct io_rzk_linux rzk_struct
int Init(const char *driverPath)
const char int mode
Definition: ioapi.h:137
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
Definition: sflib.h:66
#define FALSE
Definition: mybfd.h:102
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 RZ_PERM_WX
Definition: rz_types.h:99
#define O_RDONLY
Definition: sftypes.h:486
PrintfCallback cb_printf
Definition: rz_io.h:91

References io_rzk_linux::beid, rz_io_t::cb_printf, eprintf, FALSE, fd, free(), Init(), NULL, O_RDONLY, pathname, io_rzk_linux::pid, rz_io_desc_new(), rz_io_plugin_rzk, RZ_NEW0, RZ_PERM_WX, rzk_struct, and io_rzk_linux::wp.

◆ rzk__plugin_open()

static bool rzk__plugin_open ( RzIO io,
const char *  pathname,
bool  many 
)
static

Definition at line 84 of file io_rzk.c.

84  {
85  return (!strncmp(pathname, "rzk://", 6));
86 }

References pathname.

◆ rzk__read()

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

Definition at line 40 of file io_rzk.c.

40  {
41 #if __WINDOWS__
42  return ReadKernelMemory(io->off, buf, count);
43 #elif defined(__linux__) && !defined(__GNU__)
44  switch (rzk_struct.beid) {
45  case 0:
47  case 1:
49  case 2:
51  default:
52  io->cb_printf("ERROR: Undefined beid in rzk__read.\n");
53  memset(buf, 0xff, count);
54  return count;
55  }
56 #else
57  io->cb_printf("TODO: rzk not implemented for this plataform.\n");
58  memset(buf, 0xff, count);
59  return count;
60 #endif
61 }
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
int ReadMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len)
Definition: io_rzk_linux.c:272
#define IOCTL_READ_KERNEL_MEMORY
Definition: io_rzk_linux.h:110
#define IOCTL_READ_PHYSICAL_ADDR
Definition: io_rzk_linux.h:114
#define IOCTL_READ_PROCESS_ADDR
Definition: io_rzk_linux.h:112
int ReadKernelMemory(ut64 address, ut8 *buf, int len)
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)

References io_rzk_linux::beid, rz_io_t::cb_printf, count, fd, IOCTL_READ_KERNEL_MEMORY, IOCTL_READ_PHYSICAL_ADDR, IOCTL_READ_PROCESS_ADDR, memset(), rz_io_t::off, io_rzk_linux::pid, ReadKernelMemory(), ReadMemory(), and rzk_struct.

◆ rzk__system()

static char* rzk__system ( RzIO io,
RzIODesc fd,
const char *  cmd 
)
static

Definition at line 88 of file io_rzk.c.

88  {
89  if (!strcmp(cmd, "")) {
90  return NULL;
91  }
92  if (!strncmp(cmd, "mod", 3)) {
93 #if __WINDOWS__
94  GetSystemModules(io);
95 #endif
96  } else {
97 #if defined(__linux__) && !defined(__GNU__)
98  (void)run_ioctl_command(io, fd, cmd);
99  return NULL;
100 #else
101  eprintf("Try: 'R!mod'\n '.R!mod'\n");
102 #endif
103  }
104  return NULL;
105 }
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 cmd
Definition: sflib.h:79
int run_ioctl_command(RzIO *io, RzIODesc *iodesc, const char *buf)
Definition: io_rzk_linux.c:842
int GetSystemModules(RzIO *io)

References cmd, eprintf, fd, GetSystemModules(), NULL, and run_ioctl_command().

◆ rzk__write()

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

Definition at line 18 of file io_rzk.c.

18  {
19 #if __WINDOWS__
20  // eprintf("writing to: 0x%"PFMT64x" len: %x\n",io->off, count);
21  return WriteKernelMemory(io->off, buf, count);
22 #elif defined(__linux__) && !defined(__GNU__)
23  switch (rzk_struct.beid) {
24  case 0:
26  case 1:
28  case 2:
30  default:
31  io->cb_printf("ERROR: Undefined beid in rzk__write.\n");
32  return -1;
33  }
34 #else
35  io->cb_printf("TODO: rzk not implemented for this plataform.\n");
36  return -1;
37 #endif
38 }
int WriteMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len)
Definition: io_rzk_linux.c:351
#define IOCTL_WRITE_PHYSICAL_ADDR
Definition: io_rzk_linux.h:115
#define IOCTL_WRITE_PROCESS_ADDR
Definition: io_rzk_linux.h:113
#define IOCTL_WRITE_KERNEL_MEMORY
Definition: io_rzk_linux.h:111
int WriteKernelMemory(ut64 address, const ut8 *buf, int len)

References io_rzk_linux::beid, rz_io_t::cb_printf, count, fd, IOCTL_WRITE_KERNEL_MEMORY, IOCTL_WRITE_PHYSICAL_ADDR, IOCTL_WRITE_PROCESS_ADDR, rz_io_t::off, io_rzk_linux::pid, rzk_struct, WriteKernelMemory(), and WriteMemory().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
.data = &rz_io_plugin_rzk,
}
@ 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 152 of file io_rzk.c.

◆ rz_io_plugin_rzk

RzIOPlugin rz_io_plugin_rzk
Initial value:
= {
.name = "rzk",
.desc = "Kernel access API io",
.uris = "rzk://",
.license = "LGPL3",
.open = rzk__open,
.close = rzk__close,
.read = rzk__read,
.check = rzk__plugin_open,
.lseek = rzk__lseek,
.system = rzk__system,
.write = rzk__write,
}
static char * rzk__system(RzIO *io, RzIODesc *fd, const char *cmd)
Definition: io_rzk.c:88
static ut64 rzk__lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_rzk.c:79
static int rzk__close(RzIODesc *fd)
Definition: io_rzk.c:63
static bool rzk__plugin_open(RzIO *io, const char *pathname, bool many)
Definition: io_rzk.c:84
int rzk__write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_rzk.c:18
static RzIODesc * rzk__open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_rzk.c:107
static int rzk__read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_rzk.c:40

Definition at line 137 of file io_rzk.c.

Referenced by rzk__open().