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

Go to the source code of this file.

Functions

static bool __check (RzIO *io, const char *pathname, bool many)
 
static ut8tcpme (const char *pathname, int *code, int *len)
 
static RzIODesc__open (RzIO *io, const char *pathname, int rw, int mode)
 

Variables

RzIOPlugin rz_io_plugin_tcp
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ __check()

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

Definition at line 11 of file io_tcp.c.

11  {
12  return (!strncmp(pathname, "tcp://", 6));
13 }
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

References pathname.

Referenced by __open().

◆ __open()

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

Definition at line 67 of file io_tcp.c.

67  {
68  if (__check(io, pathname, 0)) {
69  int rlen, code;
71  if (!mal) {
72  return NULL;
73  }
74  mal->offset = 0;
75  mal->buf = tcpme(pathname, &code, &rlen);
76  if (mal->buf && rlen > 0) {
77  mal->size = rlen;
78  return rz_io_desc_new(io, &rz_io_plugin_tcp, pathname, rw, mode, mal);
79  }
80  eprintf("No TCP segment\n");
81  free(mal);
82  }
83  return NULL;
84 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static bool __check(RzIO *io, const char *pathname, bool many)
Definition: io_tcp.c:11
RzIOPlugin rz_io_plugin_tcp
Definition: io_tcp.c:86
static ut8 * tcpme(const char *pathname, int *code, int *len)
Definition: io_tcp.c:15
const char int mode
Definition: ioapi.h:137
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: inftree9.h:24
static struct @626 mal

References __check(), code, eprintf, free(), mal, NULL, pathname, rz_io_desc_new(), rz_io_plugin_tcp, RZ_NEW0, and tcpme().

◆ tcpme()

static ut8* tcpme ( const char *  pathname,
int code,
int len 
)
static

Definition at line 15 of file io_tcp.c.

15  {
16  pathname += 6;
17  *code = 404;
18 #if __UNIX__
19  rz_sys_signal(SIGINT, SIG_IGN);
20 #endif
21  if (*pathname == ':') {
22  /* listen and wait for connection */
23  RzSocket *sl = rz_socket_new(false);
24  if (!rz_socket_listen(sl, pathname + 1, NULL)) {
25  eprintf("Cannot listen\n");
26  rz_socket_free(sl);
27  return NULL;
28  }
30  ut8 *res = rz_socket_slurp(sc, len);
32  rz_socket_free(sl);
33  if (res) {
34  *code = 200;
35  return res;
36  }
37  } else {
38  /* connect and slurp the end point */
39  char *host = strdup(pathname);
40  if (!host) {
41  return NULL;
42  }
43  char *port = strchr(host, ':');
44  if (port) {
45  *port++ = 0;
46  RzSocket *s = rz_socket_new(false);
47  if (rz_socket_connect(s, host, port, RZ_SOCKET_PROTO_TCP, 0)) {
48  ut8 *res = rz_socket_slurp(s, len);
49  if (*len < 1) {
50  RZ_FREE(res);
51  } else {
52  *code = 200;
53  }
55  free(host);
56  return res;
57  }
59  } else {
60  eprintf("Missing port.\n");
61  }
62  free(host);
63  }
64  return NULL;
65 }
size_t len
Definition: 6502dis.c:15
static char sc[]
Definition: egg_cb.c:6
uint8_t ut8
Definition: lh5801.h:11
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")
static RzSocket * s
Definition: rtr.c:28
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
Definition: socket.c:582
RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile)
Definition: socket.c:474
RZ_API bool rz_socket_connect(RzSocket *s, const char *host, const char *port, int proto, unsigned int timeout)
Definition: socket.c:257
#define RZ_SOCKET_PROTO_TCP
Definition: rz_socket.h:87
RZ_API RzSocket * rz_socket_new(bool is_ssl)
Definition: socket.c:179
RZ_API ut8 * rz_socket_slurp(RzSocket *s, int *len)
Definition: socket.c:868
RZ_API int rz_socket_free(RzSocket *s)
Definition: socket.c:453
RZ_API int rz_sys_signal(int sig, void(*handler)(int))
Definition: sys.c:178
#define RZ_FREE(x)
Definition: rz_types.h:369

References eprintf, free(), len, NULL, pathname, RZ_FREE, rz_socket_accept(), rz_socket_connect(), rz_socket_free(), rz_socket_listen(), rz_socket_new(), RZ_SOCKET_PROTO_TCP, rz_socket_slurp(), rz_sys_signal(), s, sc, and strdup().

Referenced by __open().

Variable Documentation

◆ rizin_plugin

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

◆ rz_io_plugin_tcp

RzIOPlugin rz_io_plugin_tcp
Initial value:
= {
.name = "tcp",
.desc = "Load files via TCP (listen or connect)",
.uris = "tcp://",
.license = "LGPL3",
.open = __open,
.close = io_memory_close,
.read = io_memory_read,
.check = __check,
.lseek = io_memory_lseek,
.write = io_memory_write,
}
int io_memory_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_memory.c:97
int io_memory_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_memory.c:56
ut64 io_memory_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_memory.c:125
int io_memory_close(RzIODesc *fd)
Definition: io_memory.c:114
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_tcp.c:67

Definition at line 86 of file io_tcp.c.

Referenced by __open().