21 - can
access full filesystem
25 #define rtr_n core->rtr_n
26 #define rtr_host core->rtr_host
65 if (http_log_enabled) {
67 if (http_log_file && *http_log_file) {
75 vfprintf(stderr, fmt, ap);
84 char *uri =
rz_str_newf(
"http://%s:%s/%s%s",
T.host,
T.port,
T.file, ptr ? ptr :
str);
91 res = strstr(ptr2,
"\n\n");
93 res = strstr(res + 1,
"\n\n");
95 return res ? res + 2 : ptr2;
101 if (core && core->
vmode) {
119 if (((
size_t)u) > 0xff) {
132 char *ptr =
strdup(
"<html><body>\n");
139 if (
file[0] ==
'.') {
150 static void dietime(
int sig) {
163 eprintf(
"http.dietime only works on *nix systems\n");
184 eprintf(
"%s: Unsupported reg size: %d\n",
225 eprintf(
"%s: big registers (%d byte(s)) not yet supported\n",
233 char sdup[128] = { 0 };
237 strncpy(sdup,
src + 2,
sizeof(sdup) - 1);
238 int len = strlen(sdup);
246 sdup[
len - 4] =
'\0';
250 val.v80.High,
val.v80.Low);
256 sdup[
len - 8] =
'\0';
260 val.v96.High,
val.v96.Low);
266 sdup[
len - 16] =
'\0';
270 val.v128.High,
val.v128.Low);
272 eprintf(
"%s: big registers (%d byte(s)) not yet supported\n",
279 char *
out_buf,
size_t max_len) {
289 if (!core_ptr || !
cmd) {
338 rz_list_foreach (
list,
iter, dbgpid) {
340 if (ret >= max_len - 9) {
362 const char *
name, *val_ptr;
363 char new_cmd[128] = { 0 };
367 if ((val_ptr = strchr(
name,
'='))) {
368 strncpy(new_cmd,
name,
RZ_MIN(val_ptr -
name,
sizeof(new_cmd) - 1));
370 strncpy(new_cmd,
name,
sizeof(new_cmd) - 1);
383 strncpy(new_cmd,
cmd,
off);
385 reg_val = strtoll(val_ptr,
NULL, 16);
387 reg_val,
r->size / 8, be) < 0) {
394 val_ptr,
r->size / 8) < 0) {
402 reg_val,
r->size / 8, be);
407 &val_big,
r->size / 8, be);
452 namelen =
desc ? strlen(
desc->name) : 0;
453 if (
off >= namelen) {
468 sscanf(
cmd + 1,
"%" PFMT64x ",%x", &m_off, &ret);
483 bool debug_msg =
false;
488 if (!core || !
path) {
496 eprintf(
"gdbserver: Port not specified\n");
499 if (!(
p = atoi(
path)) || p < 0 || p > 65535) {
500 eprintf(
"gdbserver: Invalid port: %s\n", port);
503 snprintf(port,
sizeof(port) - 1,
"%d",
p);
505 eprintf(
"gdbserver: File not specified\n");
509 eprintf(
"gdbserver: File not specified\n");
531 eprintf(
"gdbserver: Could not open socket for listening\n");
536 eprintf(
"gdbserver: Cannot listen on port: %s\n", port);
541 eprintf(
"gdbserver: Cannot alloc libgdbr instance\n");
545 g->server_debug = debug_msg;
550 eprintf(
"gdbserver started on port: %s, file: %s\n", port,
file);
575 eprintf(
"gdbserver is already running\n");
601 eprintf(
"Error: Unknown host\n");
606 eprintf(
"Error: rizin_cmd_str returned NULL\n");
612 eprintf(
"Error: Cannot use '=<' to a rap connection.\n");
637 const char *proto =
"rap";
662 char *pikaboo = strstr(host,
"://");
678 for (
i = 0; uris[
i].name;
i++) {
680 proto = uris[
i].protocol;
688 if (!(ptr = strchr(host,
':'))) {
699 file = strchr(ptr,
'/');
704 if (*host ==
':' || strstr(host,
"://:")) {
708 eprintf(
"Error: Missing '/'\n");
715 eprintf(
"Error: Cannot create new socket\n");
733 eprintf(
"Error: Cannot connect to '%s' (%s)\n", host, port);
744 eprintf(
"Error: Cannot connect to 'unix://%s'\n", host);
749 eprintf(
"Connected to: 'unix://%s'\n", host);
754 eprintf(
"Error: Cannot connect to '%s' (%s)\n", host, port);
759 eprintf(
"Connected to: %s at port %s\n", host, port);
764 eprintf(
"Error: Cannot connect to '%s' (%s)\n", host, port);
769 eprintf(
"Connected to: %s at port %s\n", host, port);
839 if (!rt || !rt->
core) {
851 unsigned int cmd_len = 0;
859 cmd_len = strlen(
cmd);
862 if (*
input ==
':' && !strchr(
input + 1,
':')) {
871 eprintf(
"RAP Thread is already running\n");
872 eprintf(
"This is experimental and probably buggy. Use at your own risk\n");
910 eprintf(
"Error: Unknown host\n");
918 if (cmd_len < 1 || cmd_len > 16384) {
932 eprintf(
"Error: Allocating cmd output\n");
940 free((
void *)cmd_output);
946 if (cmd_len < 1 || cmd_len > 16384) {
953 eprintf(
"Cannot find '%s'\n", uri);
979 eprintf(
"Error: Unknown protocol\n");
1028 typedef struct rtr_cmds_context_t {
1034 typedef struct rtr_cmds_client_context_t {
1040 } rtr_cmds_client_context;
1042 static void rtr_cmds_client_close(
uv_tcp_t *client,
bool remove) {
1054 rtr_cmds_client_context *client_context = client->data;
1056 free(client_context->res);
1057 free(client_context);
1067 rtr_cmds_client_context *
context =
req->data;
1074 rtr_cmds_client_close(
context->client,
true);
1078 rtr_cmds_context *
context = client->loop->data;
1079 rtr_cmds_client_context *client_context = client->data;
1082 if (nread != UV_EOF) {
1085 rtr_cmds_client_close((
uv_tcp_t *)client,
true);
1087 }
else if (nread == 0) {
1091 buf->base[nread] =
'\0';
1092 char *
end = strchr(
buf->base,
'\n');
1099 client_context->res =
rz_core_cmd_str(client_context->core, (
const char *)client_context->buf);
1102 if (!client_context->res || !*client_context->res) {
1103 free(client_context->res);
1104 client_context->res =
strdup(
"\n");
1107 if (!client_context->res || (!
rz_config_get_i(client_context->core->config,
"scr.prompt") && !strcmp((
char *)
buf,
"q!")) ||
1108 !strcmp((
char *)
buf,
".--")) {
1109 rtr_cmds_client_close((
uv_tcp_t *)client,
true);
1115 req->data = client_context;
1116 uv_buf_t wrbuf =
uv_buf_init(client_context->res, (
unsigned int)strlen(client_context->res));
1128 rtr_cmds_context *
context = server->loop->data;
1137 rtr_cmds_client_context *client_context =
RZ_NEW(rtr_cmds_client_context);
1138 if (!client_context) {
1143 client_context->core = server->data;
1144 client_context->len = 0;
1145 client_context->buf[0] =
'\0';
1146 client_context->res =
NULL;
1147 client_context->client = client;
1148 client->data = client_context;
1168 rtr_cmds_client_close(client,
false);
1177 if (!port || port[0] ==
'?') {
1178 rz_cons_printf(
"Usage: .:[tcp-port] run rizin commands for clients\n");
1226 unsigned char buf[4097];
1231 if (!port || port[0] ==
'?') {
1232 rz_cons_printf(
"Usage: .:[tcp-port] run rizin commands for clients\n");
1240 eprintf(
"Error listening on port %s\n", port);
1245 eprintf(
"Listening for commands on port %s\n", port);
1259 for (
i = 0;
buf[
i];
i++) {
1260 if (
buf[
i] ==
'\n') {
1265 !strcmp((
char *)
buf,
"q!")) ||
1266 !strcmp((
char *)
buf,
".--")) {
static mcore_handle handle
static ut64 baddr(RzBinFile *bf)
int bits(struct state *s, int need)
RZ_API void rz_core_file_reopen_debug(RzCore *core, const char *args)
RZ_API RZ_BORROW RzCoreFile * rz_core_file_open(RZ_NONNULL RzCore *r, RZ_NONNULL const char *file, int flags, ut64 loadaddr)
Tries to open the file as is, otherwise tries as is a compilation of files.
RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filenameuri, ut64 baddr)
RZ_API int rz_core_cmd(RzCore *core, const char *cstr, int log)
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API bool rz_cons_enable_mouse(const bool enable)
RZ_API RzCons * rz_cons_singleton(void)
RZ_API void * rz_cons_sleep_begin(void)
RZ_API void rz_cons_break_pop(void)
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
RZ_API int rz_cons_printf(const char *format,...)
RZ_API void rz_cons_show_cursor(int cursor)
RZ_API void rz_cons_flush(void)
RZ_API bool rz_cons_is_breaked(void)
RZ_API void rz_cons_println(const char *str)
RZ_API void rz_cons_sleep_end(void *user)
static static fork const void static count static fd const char const char static newpath const char static path const char path
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 static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
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
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
RZ_API char * sdb_fmt(const char *fmt,...)
static const char * commands[]
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
bool gdbr_set_architecture(libgdbr_t *g, int arch, int bits)
Function initializes the architecture of the gdbsession.
int gdbr_cleanup(libgdbr_t *g)
frees all buffers and cleans the libgdbr instance stuff
int gdbr_init(libgdbr_t *g, bool is_server)
Function initializes the libgdbr lib.
RZ_API bool rz_core_serve(RzCore *core, RzIODesc *file)
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
static void list(RzEgg *egg)
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
RZ_API RZ_OWN void * rz_th_get_user(RZ_NONNULL RzThread *th)
Returns user pointer of thread.
RZ_API bool rz_th_set_affinity(RZ_NONNULL RzThread *th, int cpuid)
Sets the thread cpu affinity.
RZ_API RZ_OWN RzThread * rz_th_new(RZ_NONNULL RzThreadFunction function, RZ_NULLABLE void *user)
Creates and starts a new thread.
RZ_API bool rz_th_wait(RZ_NONNULL RzThread *th)
Awaits indefinetely for a thread to join.
RZ_API bool rz_th_set_name(RZ_NONNULL RzThread *th, RZ_NONNULL const char *name)
Sets the name of the thread.
void * calloc(size_t number, size_t size)
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 alarm
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 static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause access
static const char struct stat static buf struct stat static buf static vhangup int status
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
RZ_API void rz_core_rtr_session(RzCore *core, const char *input)
RZ_API void rz_core_rtr_list(RzCore *core)
static const char * listenport
static void * rz_core_rtr_rap_thread(RapThread *rt)
RZ_API int rz_core_rtr_http_stop(RzCore *u)
RZ_API void rz_core_rtr_add(RzCore *core, const char *_input)
static int write_reg_val(char *buf, ut64 sz, ut64 reg, int regsize, bool bigendian)
RZ_API char * rz_core_rtr_cmds_query(RzCore *core, const char *host, const char *port, const char *cmd)
RZ_API int rz_core_rtr_gdb(RzCore *core, int launch, const char *path)
static void http_logf(RzCore *core, const char *fmt,...)
static char * rtr_dir_files(const char *path)
RZ_API bool rz_core_rtr_init(RZ_NONNULL RzCore *core)
Allocates core rtr structure.
static RzThread * rapthread
static int rz_core_rtr_gdb_run(RzCore *core, int launch, const char *path)
static int rz_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, char *out_buf, size_t max_len)
static int write_big_reg(char *buf, ut64 sz, const utX *val, int regsize, bool bigendian)
static void activateDieTime(RzCore *core)
RZ_API void rz_core_rtr_remove(RzCore *core, const char *input)
static char * rtrcmd(TextLog T, const char *str)
static int swap_big_regs(char *dest, ut64 sz, const char *src, int regsz)
RZ_API void rz_core_wait(RzCore *core)
static bool rz_core_rtr_rap_run(RzCore *core, const char *input)
RZ_API int rz_core_rtr_cmds(RzCore *core, const char *port)
RZ_API void rz_core_rtr_pushout(RzCore *core, const char *input)
static void showcursor(RzCore *core, int x)
RZ_API void rz_core_rtr_cmd(RzCore *core, const char *input)
static void __rtr_shell(RzCore *core, int nth)
RZ_API ut64 rz_reg_get_value_big(RzReg *reg, RzRegItem *item, utX *val)
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
#define rz_return_val_if_fail(expr, val)
#define RTR_PROTOCOL_UNIX
#define RTR_PROTOCOL_HTTP
@ RZ_DEBUG_REASON_BREAKPOINT
static ut32 rz_swap_ut32(ut32 val)
static ut16 rz_swap_ut16(ut16 val)
static ut64 rz_swap_ut64(ut64 val)
RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append)
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
RZ_API RzIODesc * rz_io_desc_get(RzIO *io, int fd)
RZ_API bool rz_io_is_listener(RzIO *io)
RZ_API RzIODesc * rz_io_open_nomap(RzIO *io, const char *uri, int flags, int mode)
RZ_API bool rz_io_desc_close(RzIODesc *desc)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API char * rz_socket_rap_client_command(RzSocket *s, const char *cmd, RzCoreBind *c)
RZ_API int rz_socket_close(RzSocket *s)
#define rz_socket_connect_unix(a, b)
RZ_API int rz_socket_read_block(RzSocket *s, unsigned char *buf, int len)
RZ_API int rz_socket_rap_client_open(RzSocket *s, const char *file, int rw)
RZ_API int rz_socket_port_by_name(const char *name)
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
RZ_API void rz_socket_http_server_set_breaked(bool *b)
RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile)
#define rz_socket_connect_tcp(a, b, c, d)
RZ_API void RZ_API int rz_socket_read(RzSocket *s, ut8 *read, int len)
RZ_API bool rz_socket_connect(RzSocket *s, const char *host, const char *port, int proto, unsigned int timeout)
RZ_API char * rz_socket_http_get(const char *url, int *code, int *rlen)
#define RZ_SOCKET_PROTO_TCP
RZ_API RzSocket * rz_socket_new(bool is_ssl)
RZ_API int rz_socket_free(RzSocket *s)
#define rz_socket_connect_udp(a, b, c, d)
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
RZ_API char * rz_str_uri_encode(const char *buf)
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
RZ_API const char * rz_str_trim_head_ro(const char *str)
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
RZ_API RzList * rz_sys_dir(const char *path)
RZ_API int rz_sys_usleep(int usecs)
Sleep for usecs microseconds.
RZ_API int rz_sys_signal(int sig, void(*handler)(int))
RZ_API int rz_sys_arch_id(const char *arch)
void *(* RzThreadFunction)(void *user)
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
static size_t rz_pvector_len(const RzPVector *vec)
RZ_API void * rz_pvector_remove_at(RzPVector *vec, size_t index)
static void ** rz_pvector_push(RzPVector *vec, void *x)
RZ_API void rz_pvector_clear(RzPVector *vec)
static void * rz_pvector_at(const RzPVector *vec, size_t index)
#define rz_pvector_foreach(vec, it)
int gdbr_server_serve(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
static struct sockaddr static addrlen listen
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
static struct sockaddr static addrlen static backlog const void static flags void flags
static struct sockaddr static addrlen static backlog const void msg
RzList *(* threads)(RzDebug *dbg, int pid)
struct rz_debug_plugin_t * cur
RZ_API RZ_OWN RzAtomicBool * rz_atomic_bool_new(bool value)
Initialize a thread safe bool type container.
RZ_API bool rz_atomic_bool_get(RZ_NONNULL RzAtomicBool *tbool)
Gets the current value hold by the RzAtomicBool structure.
RZ_API void rz_atomic_bool_set(RZ_NONNULL RzAtomicBool *tbool, bool value)
Sets the value int the RzAtomicBool structure.
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
UV_EXTERN int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
UV_EXTERN int uv_read_stop(uv_stream_t *)
UV_EXTERN int uv_read_start(uv_stream_t *, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
UV_EXTERN int uv_listen(uv_stream_t *stream, int backlog, uv_connection_cb cb)
UV_EXTERN int uv_loop_init(uv_loop_t *loop)
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
UV_EXTERN const char * uv_err_name(int err)
UV_EXTERN int uv_tcp_bind(uv_tcp_t *handle, const struct sockaddr *addr, unsigned int flags)
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
UV_EXTERN const char * uv_strerror(int err)
UV_EXTERN int uv_accept(uv_stream_t *server, uv_stream_t *client)
UV_EXTERN int uv_tcp_init(uv_loop_t *, uv_tcp_t *handle)
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
UV_EXTERN int uv_async_send(uv_async_t *async)
UV_EXTERN int uv_loop_close(uv_loop_t *loop)
void(* uv_close_cb)(uv_handle_t *handle)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)