Rizin
unix-like reverse engineering framework and cli tools
socket_rap_server.c File Reference
#include <rz_socket.h>
#include <rz_util.h>

Go to the source code of this file.

Functions

RZ_API RzSocketRapServerrz_socket_rap_server_new (bool use_ssl, const char *port)
 
RZ_API RzSocketRapServerrz_socket_rap_server_create (const char *pathname)
 
RZ_API void rz_socket_rap_server_free (RzSocketRapServer *s)
 
RZ_API bool rz_socket_rap_server_listen (RzSocketRapServer *s, const char *certfile)
 
RZ_API RzSocketrz_socket_rap_server_accept (RzSocketRapServer *s)
 
RZ_API bool rz_socket_rap_server_continue (RzSocketRapServer *s)
 

Function Documentation

◆ rz_socket_rap_server_accept()

RZ_API RzSocket* rz_socket_rap_server_accept ( RzSocketRapServer s)

Definition at line 48 of file socket_rap_server.c.

48  {
50  return rz_socket_accept(s->fd);
51 }
#define NULL
Definition: cris-opc.c:27
static RzSocket * s
Definition: rtr.c:28
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
Definition: socket.c:582

References rz_socket_t::fd, NULL, rz_return_val_if_fail, rz_socket_accept(), and s.

◆ rz_socket_rap_server_continue()

RZ_API bool rz_socket_rap_server_continue ( RzSocketRapServer s)

Definition at line 53 of file socket_rap_server.c.

53  {
54  rz_return_val_if_fail(s && s->fd, false);
55 
56  int i;
57  char *ptr = NULL;
58 
59  if (!rz_socket_is_connected(s->fd)) {
60  return false;
61  }
62  rz_socket_read_block(s->fd, s->buf, 1);
63  switch (s->buf[0]) {
64  case RAP_PACKET_OPEN:
65  rz_socket_read_block(s->fd, &s->buf[1], 2);
66  rz_socket_read_block(s->fd, &s->buf[3], (int)s->buf[2]);
67  {
68  int fd = s->open(s->user, (const char *)&s->buf[3], (int)s->buf[1], 0);
70  eprintf("REPLY BACK %d\n", fd);
71  rz_write_be32(s->buf + 1, fd);
72  }
73  rz_socket_write(s->fd, s->buf, 5);
75  break;
76  case RAP_PACKET_READ:
77  rz_socket_read_block(s->fd, &s->buf[1], 4);
78  i = rz_read_be32(&s->buf[1]);
79  if (i > RAP_PACKET_MAX || i < 0) {
80  i = RAP_PACKET_MAX;
81  }
82  s->read(s->user, &s->buf[5], i);
84  rz_socket_write(s->fd, s->buf, i + 5);
86  break;
87  case RAP_PACKET_WRITE:
88  rz_socket_read_block(s->fd, s->buf + 1, 4);
89  i = rz_read_be32(s->buf + 1);
90  if (i > RAP_PACKET_MAX || i < 0) {
91  i = RAP_PACKET_MAX;
92  }
93  rz_socket_read_block(s->fd, s->buf + 5, i);
94  rz_write_be32(s->buf + 1, s->write(s->user, s->buf + 5, i));
96  rz_socket_write(s->fd, s->buf, 5);
98  break;
99  case RAP_PACKET_SEEK: {
100  rz_socket_read_block(s->fd, &s->buf[1], 9);
101  int whence = s->buf[0];
102  ut64 offset = rz_read_be64(s->buf + 1);
103  offset = s->seek(s->user, offset, whence);
104  /* prepare reply */
105  s->buf[0] = RAP_PACKET_SEEK | RAP_PACKET_REPLY;
106  rz_write_be64(s->buf + 1, offset);
107  rz_socket_write(s->fd, s->buf, 9);
108  rz_socket_flush(s->fd);
109  } break;
110  case RAP_PACKET_CMD:
111  rz_socket_read_block(s->fd, &s->buf[1], 4);
112  i = rz_read_be32(&s->buf[1]);
113  if (rz_socket_read_block(s->fd, &s->buf[5], i) > 0) {
114  ptr = s->cmd(s->user, (const char *)s->buf + 5);
115  i = (ptr) ? strlen(ptr) + 1 : 0;
116  rz_write_be32(&s->buf[1], i);
117  s->buf[0] = RAP_PACKET_CMD | RAP_PACKET_REPLY;
118  rz_socket_write(s->fd, s->buf, 5);
119  if (i) {
120  rz_socket_write(s->fd, ptr, i);
121  }
122  rz_socket_flush(s->fd);
123  RZ_FREE(ptr);
124  }
125  break;
126  case RAP_PACKET_CLOSE:
127  rz_socket_read_block(s->fd, &s->buf[1], 4);
128  i = rz_read_be32(&s->buf[1]);
129  s->close(s->user, i);
130  s->buf[0] = RAP_PACKET_CLOSE | RAP_PACKET_REPLY;
131  rz_socket_write(s->fd, s->buf, 5);
132  rz_socket_flush(s->fd);
133  break;
134  default:
135  eprintf("unknown command 0x%02x\n", (ut8)(s->buf[0] & 0xff));
136  rz_socket_close(s->fd);
137  return false;
138  }
139  return true;
140 }
lzma_index ** i
Definition: index.h:629
voidpf uLong offset
Definition: ioapi.h:144
uint8_t ut8
Definition: lh5801.h:11
#define eprintf(x, y...)
Definition: rlcc.c:7
static ut64 rz_read_be64(const void *src)
Definition: rz_endian.h:108
static void rz_write_be64(void *dest, ut64 val)
Definition: rz_endian.h:119
static ut32 rz_read_be32(const void *src)
Definition: rz_endian.h:87
static void rz_write_be32(void *dest, ut32 val)
Definition: rz_endian.h:98
RZ_API int rz_socket_close(RzSocket *s)
Definition: socket.c:419
RZ_API int rz_socket_read_block(RzSocket *s, unsigned char *buf, int len)
Definition: socket.c:808
RZ_API bool rz_socket_is_connected(RzSocket *)
Definition: socket.c:101
RZ_API int rz_socket_flush(RzSocket *s)
Definition: socket.c:677
@ RAP_PACKET_MAX
Definition: rz_socket.h:179
@ RAP_PACKET_READ
Definition: rz_socket.h:172
@ RAP_PACKET_SEEK
Definition: rz_socket.h:174
@ RAP_PACKET_OPEN
Definition: rz_socket.h:171
@ RAP_PACKET_CMD
Definition: rz_socket.h:177
@ RAP_PACKET_REPLY
Definition: rz_socket.h:178
@ RAP_PACKET_CLOSE
Definition: rz_socket.h:175
@ RAP_PACKET_WRITE
Definition: rz_socket.h:173
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
Definition: socket.c:724
#define RZ_FREE(x)
Definition: rz_types.h:369
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997

References eprintf, fd, rz_socket_t::fd, i, NULL, RAP_PACKET_CLOSE, RAP_PACKET_CMD, RAP_PACKET_MAX, RAP_PACKET_OPEN, RAP_PACKET_READ, RAP_PACKET_REPLY, RAP_PACKET_SEEK, RAP_PACKET_WRITE, RZ_FREE, rz_read_be32(), rz_read_be64(), rz_return_val_if_fail, rz_socket_close(), rz_socket_flush(), rz_socket_is_connected(), rz_socket_read_block(), rz_socket_write(), rz_write_be32(), rz_write_be64(), s, and ut64().

◆ rz_socket_rap_server_create()

RZ_API RzSocketRapServer* rz_socket_rap_server_create ( const char *  pathname)

Definition at line 23 of file socket_rap_server.c.

23  {
25  if (strlen(pathname) < 11) {
26  return NULL;
27  }
28  if (strncmp(pathname, "rap", 3)) {
29  return NULL;
30  }
31  bool is_ssl = (pathname[3] == 's');
32  const char *port = &pathname[7 + is_ssl];
33  return rz_socket_rap_server_new(is_ssl, port);
34 }
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
RZ_API RzSocketRapServer * rz_socket_rap_server_new(bool use_ssl, const char *port)

References NULL, pathname, rz_return_val_if_fail, and rz_socket_rap_server_new().

◆ rz_socket_rap_server_free()

RZ_API void rz_socket_rap_server_free ( RzSocketRapServer s)

Definition at line 36 of file socket_rap_server.c.

36  {
37  if (s) {
39  free(s);
40  }
41 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API int rz_socket_free(RzSocket *s)
Definition: socket.c:453

References rz_socket_t::fd, free(), rz_socket_free(), and s.

◆ rz_socket_rap_server_listen()

RZ_API bool rz_socket_rap_server_listen ( RzSocketRapServer s,
const char *  certfile 
)

Definition at line 43 of file socket_rap_server.c.

43  {
44  rz_return_val_if_fail(s && s->port && *s->port, false);
45  return rz_socket_listen(s->fd, s->port, certfile);
46 }
RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile)
Definition: socket.c:474

References rz_socket_t::fd, rz_socket_t::port, rz_return_val_if_fail, rz_socket_listen(), and s.

◆ rz_socket_rap_server_new()

RZ_API RzSocketRapServer* rz_socket_rap_server_new ( bool  use_ssl,
const char *  port 
)

Definition at line 8 of file socket_rap_server.c.

8  {
11  if (s) {
12  s->port = strdup(port);
13  s->fd = rz_socket_new(use_ssl);
14  if (s->fd) {
15  return s;
16  }
18  free(s);
19  }
20  return NULL;
21 }
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 RzSocket * rz_socket_new(bool is_ssl)
Definition: socket.c:179
#define RZ_NEW0(x)
Definition: rz_types.h:284

References rz_socket_t::fd, free(), NULL, rz_socket_t::port, RZ_NEW0, rz_return_val_if_fail, rz_socket_free(), rz_socket_new(), s, and strdup().

Referenced by rz_socket_rap_server_create().