Rizin
unix-like reverse engineering framework and cli tools
io_rzweb.c File Reference
#include <rz_io.h>
#include <rz_lib.h>
#include <rz_socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

Go to the source code of this file.

Classes

struct  RzIOR2Web
 

Macros

#define rFD(x)   (((RzIOR2Web *)(x)->data)->fd)
 
#define rURL(x)   (((RzIOR2Web *)(x)->data)->url)
 

Functions

static int __write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static int __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int __close (RzIODesc *fd)
 
static ut64 __lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static bool __plugin_open (RzIO *io, const char *pathname, bool many)
 
static int getmalfd (RzIOR2Web *mal)
 
static RzIODesc__open (RzIO *io, const char *pathname, int rw, int mode)
 
static char * __system (RzIO *io, RzIODesc *fd, const char *command)
 

Variables

RzIOPlugin rz_io_plugin_rzweb
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ rFD

#define rFD (   x)    (((RzIOR2Web *)(x)->data)->fd)

Definition at line 16 of file io_rzweb.c.

◆ rURL

#define rURL (   x)    (((RzIOR2Web *)(x)->data)->url)

Definition at line 17 of file io_rzweb.c.

Function Documentation

◆ __close()

static int __close ( RzIODesc fd)
static

Definition at line 72 of file io_rzweb.c.

72  {
73  RzIOR2Web *riom;
74  if (!fd || !fd->data) {
75  return -1;
76  }
77  riom = fd->data;
78  RZ_FREE(riom->url);
79  RZ_FREE(fd->data);
80  return 0;
81 }
#define RZ_FREE(x)
Definition: rz_types.h:369
char * url
Definition: io_rzweb.c:13
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, RZ_FREE, and RzIOR2Web::url.

◆ __lseek()

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

Definition at line 83 of file io_rzweb.c.

83  {
84  switch (whence) {
85  case SEEK_SET: return offset;
86  case SEEK_CUR: return io->off + offset;
87  case SEEK_END: return UT64_MAX;
88  }
89  return offset;
90 }
voidpf uLong offset
Definition: ioapi.h:144
#define UT64_MAX
Definition: rz_types_base.h:86
ut64 off
Definition: rz_io.h:61
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84

References rz_io_t::off, SEEK_CUR, SEEK_END, SEEK_SET, and UT64_MAX.

◆ __open()

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

Definition at line 101 of file io_rzweb.c.

101  {
102  char *out;
103  int rlen, code;
104  if (__plugin_open(io, pathname, 0)) {
106  if (!mal) {
107  return NULL;
108  }
109  char *path = strdup(pathname + 8);
110  int path_len = strlen(path);
111  if (path_len > 0) {
112  if (path[path_len - 1] == '/') {
113  path[path_len - 1] = 0;
114  }
115  }
116  char *url = rz_str_newf("http://%s/?V", path);
117  // eprintf ("URL:(%s)\n", url);
118  out = rz_socket_http_get(url, &code, &rlen);
119  // eprintf ("RES %d %d\n", code, rlen);
120  // eprintf ("OUT(%s)\n", out);
121  if (out && rlen > 0) {
122  mal->fd = getmalfd(mal);
123  mal->url = rz_str_newf("http://%s", path);
124  free(path);
125  free(out);
126  free(url);
128  pathname, rw, mode, mal);
129  }
130  free(url);
131  free(mal);
132  free(out);
133  free(path);
134  eprintf("Error: Try http://localhost:9090/cmd/");
135  }
136  return NULL;
137 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define NULL
Definition: cris-opc.c:27
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static bool __plugin_open(RzIO *io, const char *pathname, bool many)
Definition: io_rzweb.c:92
static int getmalfd(RzIOR2Web *mal)
Definition: io_rzweb.c:97
RzIOPlugin rz_io_plugin_rzweb
Definition: io_rzweb.c:156
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
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")
url
Definition: setup.py:262
const char * code
Definition: pal.c:98
#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
RZ_API char * rz_socket_http_get(const char *url, int *code, int *rlen)
Definition: socket_http.c:287
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: inftree9.h:24
static struct @626 mal

References __plugin_open(), code, eprintf, free(), getmalfd(), mal, NULL, out, path, pathname, rz_io_desc_new(), rz_io_plugin_rzweb, RZ_NEW0, rz_socket_http_get(), rz_str_newf(), strdup(), and setup::url.

◆ __plugin_open()

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

Definition at line 92 of file io_rzweb.c.

92  {
93  const char *uri = "rzweb://";
94  return (!strncmp(pathname, uri, strlen(uri)));
95 }

References pathname.

Referenced by __open().

◆ __read()

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

Definition at line 43 of file io_rzweb.c.

43  {
44  int code, rlen;
45  char *out, *url;
46  int ret = 0;
47  if (!fd || !fd->data) {
48  return -1;
49  }
50  url = rz_str_newf("%s/p8%%20%d@0x%" PFMT64x,
51  rURL(fd), count, io->off);
52  out = rz_socket_http_get(url, &code, &rlen);
53  if (out && rlen > 0) {
54  ut8 *tmp = calloc(1, rlen + 1);
55  if (!tmp) {
56  goto beach;
57  }
58  ret = rz_hex_str2bin(out, tmp);
59  memcpy(buf, tmp, RZ_MIN(count, rlen));
60  free(tmp);
61  if (ret < 0) {
62  ret = -ret;
63  }
64  }
65 
66 beach:
67  free(out);
68  free(url);
69  return ret;
70 }
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
#define rURL(x)
Definition: io_rzweb.c:17
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
#define PFMT64x
Definition: rz_types.h:393
#define RZ_MIN(x, y)

References calloc(), code, count, fd, free(), memcpy(), rz_io_t::off, out, PFMT64x, rURL, rz_hex_str2bin(), RZ_MIN, rz_socket_http_get(), rz_str_newf(), autogen_x86imm::tmp, and setup::url.

◆ __system()

static char* __system ( RzIO io,
RzIODesc fd,
const char *  command 
)
static

Definition at line 139 of file io_rzweb.c.

139  {
140  if (!*command) {
141  return NULL;
142  }
143  int code, rlen;
144  char *cmd = rz_str_uri_encode(command);
145  char *url = rz_str_newf("%s/%s", rURL(fd), cmd);
146  char *out = rz_socket_http_get(url, &code, &rlen);
147  if (out && rlen > 0) {
148  io->cb_printf("%s", out);
149  }
150  free(out);
151  free(url);
152  free(cmd);
153  return NULL;
154 }
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
RZ_API char * rz_str_uri_encode(const char *buf)
Definition: str.c:2860
PrintfCallback cb_printf
Definition: rz_io.h:91
const char * command
Definition: main.c:7

References rz_io_t::cb_printf, cmd, code, command, fd, free(), NULL, out, rURL, rz_socket_http_get(), rz_str_newf(), rz_str_uri_encode(), and setup::url.

◆ __write()

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

Definition at line 19 of file io_rzweb.c.

19  {
20  int code, rlen;
21  char *out, *url, *hexbuf;
22  if (!fd || !fd->data) {
23  return -1;
24  }
25  if (count * 3 < count) {
26  return -1;
27  }
28  hexbuf = malloc(count * 3);
29  if (!hexbuf) {
30  return -1;
31  }
32  hexbuf[0] = 0;
33  rz_hex_bin2str(buf, count, hexbuf);
34  url = rz_str_newf("%s/wx%%20%s@%" PFMT64d,
35  rURL(fd), hexbuf, io->off);
36  out = rz_socket_http_get(url, &code, &rlen);
37  free(out);
38  free(url);
39  free(hexbuf);
40  return count;
41 }
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
#define PFMT64d
Definition: rz_types.h:394

References code, count, fd, free(), malloc(), rz_io_t::off, out, PFMT64d, rURL, rz_hex_bin2str(), rz_socket_http_get(), rz_str_newf(), and setup::url.

◆ getmalfd()

static int getmalfd ( RzIOR2Web mal)
inlinestatic

Definition at line 97 of file io_rzweb.c.

97  {
98  return 0xfffffff & (int)(size_t)mal;
99 }
static int
Definition: sfsocketcall.h:114

References int, and mal.

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 171 of file io_rzweb.c.

◆ rz_io_plugin_rzweb

RzIOPlugin rz_io_plugin_rzweb
Initial value:
= {
.name = "rzweb",
.desc = "rzweb io client plugin",
.uris = "rzweb://",
.license = "LGPL3",
.open = __open,
.close = __close,
.read = __read,
.check = __plugin_open,
.lseek = __lseek,
.system = __system,
.write = __write,
}
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_rzweb.c:43
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_rzweb.c:101
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_rzweb.c:19
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_rzweb.c:83
static int __close(RzIODesc *fd)
Definition: io_rzweb.c:72
static char * __system(RzIO *io, RzIODesc *fd, const char *command)
Definition: io_rzweb.c:139

Definition at line 156 of file io_rzweb.c.

Referenced by __open().