mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-01 02:53:22 +00:00
Add io.zeromap to toggle old buggy mode doublemapping file to 0
Add http.maxsize to define the maximum file size to be uploaded Add http.upget config var (not yet implemented)
This commit is contained in:
parent
a8a4c5e3e8
commit
35808e31f8
@ -43,6 +43,14 @@ static int config_iomaxblk_callback(void *user, void *data) {
|
|||||||
core->blocksize_max = node->i_value;
|
core->blocksize_max = node->i_value;
|
||||||
return R_TRUE;
|
return R_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int config_iozeromap_callback(void *user, void *data) {
|
||||||
|
RCore *core = (RCore *) user;
|
||||||
|
RConfigNode *node = (RConfigNode *) data;
|
||||||
|
core->io->zeromap = node->i_value;
|
||||||
|
return R_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static int config_ioffio_callback(void *user, void *data) {
|
static int config_ioffio_callback(void *user, void *data) {
|
||||||
RCore *core = (RCore *) user;
|
RCore *core = (RCore *) user;
|
||||||
RConfigNode *node = (RConfigNode *) data;
|
RConfigNode *node = (RConfigNode *) data;
|
||||||
@ -641,10 +649,6 @@ R_API int r_core_config_init(RCore *core) {
|
|||||||
r_config_desc (cfg, "cmd.vprompt", "Visual prompt commands");
|
r_config_desc (cfg, "cmd.vprompt", "Visual prompt commands");
|
||||||
r_config_set (cfg, "cmd.bp", "");
|
r_config_set (cfg, "cmd.bp", "");
|
||||||
r_config_desc (cfg, "cmd.bp", "Command to executed every breakpoint hitted");
|
r_config_desc (cfg, "cmd.bp", "Command to executed every breakpoint hitted");
|
||||||
r_config_set (cfg, "http.sandbox", "false");
|
|
||||||
r_config_set_i (cfg, "http.timeout", 3);
|
|
||||||
r_config_set (cfg, "http.public", "false");
|
|
||||||
r_config_desc (cfg, "http.public", "set to true to listen on 0.0.0.0");
|
|
||||||
#if __WINDOWS__
|
#if __WINDOWS__
|
||||||
r_config_set (cfg, "http.browser", "start");
|
r_config_set (cfg, "http.browser", "start");
|
||||||
#else
|
#else
|
||||||
@ -658,12 +662,22 @@ R_API int r_core_config_init(RCore *core) {
|
|||||||
else r_config_set (cfg, "http.browser", "firefox");
|
else r_config_set (cfg, "http.browser", "firefox");
|
||||||
#endif
|
#endif
|
||||||
r_config_desc (cfg, "http.browser", "command to open http urls");
|
r_config_desc (cfg, "http.browser", "command to open http urls");
|
||||||
|
r_config_set (cfg, "http.sandbox", "false");
|
||||||
|
r_config_set_i (cfg, "http.timeout", 3);
|
||||||
|
r_config_desc (cfg, "http.timeout", "disconnect clients after N seconds if no data sent");
|
||||||
|
r_config_set (cfg, "http.public", "false");
|
||||||
|
r_config_desc (cfg, "http.public", "set to true to listen on 0.0.0.0");
|
||||||
r_config_set (cfg, "http.port", "9090");
|
r_config_set (cfg, "http.port", "9090");
|
||||||
r_config_desc (cfg, "http.root", "port to listen for http connections");
|
r_config_desc (cfg, "http.root", "port to listen for http connections");
|
||||||
r_config_set (cfg, "http.root", WWWROOT);
|
r_config_set (cfg, "http.root", WWWROOT);
|
||||||
r_config_desc (cfg, "http.root", "http root directory");
|
r_config_desc (cfg, "http.root", "http root directory");
|
||||||
|
|
||||||
r_config_set (cfg, "http.upload", "false");
|
r_config_set (cfg, "http.upload", "false");
|
||||||
r_config_desc (cfg, "http.upload", "enable file uploads");
|
r_config_desc (cfg, "http.upload", "enable file POST uploads in /up/<filename>");
|
||||||
|
r_config_set_i (cfg, "http.maxsize", 0);
|
||||||
|
r_config_desc (cfg, "http.maxsize", "define maximum file size to upload");
|
||||||
|
r_config_set (cfg, "http.upget", "false");
|
||||||
|
r_config_desc (cfg, "http.upget", "/up/ can be GET, not only POST");
|
||||||
tmpdir = r_file_tmpdir ();
|
tmpdir = r_file_tmpdir ();
|
||||||
r_config_set (cfg, "http.uproot", tmpdir);
|
r_config_set (cfg, "http.uproot", tmpdir);
|
||||||
free (tmpdir);
|
free (tmpdir);
|
||||||
@ -716,6 +730,8 @@ R_API int r_core_config_init(RCore *core) {
|
|||||||
r_config_desc (cfg, "search.align", "Only catch aligned search hits");
|
r_config_desc (cfg, "search.align", "Only catch aligned search hits");
|
||||||
|
|
||||||
sprintf (buf, "%d", R_CORE_BLOCKSIZE_MAX);
|
sprintf (buf, "%d", R_CORE_BLOCKSIZE_MAX);
|
||||||
|
r_config_set_cb (cfg, "io.zeromap", buf, &config_iozeromap_callback);
|
||||||
|
r_config_desc (cfg, "io.zeromap", "double map the last opened file to address zero");
|
||||||
r_config_set_cb (cfg, "io.maxblk", buf, &config_iomaxblk_callback);
|
r_config_set_cb (cfg, "io.maxblk", buf, &config_iomaxblk_callback);
|
||||||
r_config_desc (cfg, "io.maxblk", "set max block size (soft limit)");
|
r_config_desc (cfg, "io.maxblk", "set max block size (soft limit)");
|
||||||
|
|
||||||
|
@ -86,13 +86,24 @@ R_API int r_core_rtr_http(RCore *core, int launch) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp (rs->method, "GET")) {
|
if (!strcmp (rs->method, "GET")) {
|
||||||
|
if (!memcmp (rs->path, "/up/", 5)) {
|
||||||
|
if (r_config_get_i (core->config, "http.upget")) {
|
||||||
|
// TODO: implement upget
|
||||||
|
r_socket_http_response (rs, 200,
|
||||||
|
"TODO\n", 0, NULL);
|
||||||
|
} else {
|
||||||
|
r_socket_http_response (rs, 403,
|
||||||
|
"Permission denied\n", 0, NULL);
|
||||||
|
}
|
||||||
|
} else
|
||||||
if (!memcmp (rs->path, "/cmd/", 5)) {
|
if (!memcmp (rs->path, "/cmd/", 5)) {
|
||||||
char *out, *cmd = rs->path+5;
|
char *out, *cmd = rs->path+5;
|
||||||
r_str_uri_decode (cmd);
|
r_str_uri_decode (cmd);
|
||||||
out = r_core_cmd_str_pipe (core, cmd);
|
out = r_core_cmd_str_pipe (core, cmd);
|
||||||
if (out) {
|
if (out) {
|
||||||
char *res = r_str_uri_encode (out);
|
char *res = r_str_uri_encode (out);
|
||||||
r_socket_http_response (rs, 200, out, 0, "Content-Type: text/plain\n");
|
r_socket_http_response (rs, 200, out, 0,
|
||||||
|
"Content-Type: text/plain\n");
|
||||||
free (out);
|
free (out);
|
||||||
free (res);
|
free (res);
|
||||||
} else r_socket_http_response (rs, 200, "", 0, NULL);
|
} else r_socket_http_response (rs, 200, "", 0, NULL);
|
||||||
@ -101,12 +112,15 @@ R_API int r_core_rtr_http(RCore *core, int launch) {
|
|||||||
char path[1024];
|
char path[1024];
|
||||||
// fix crosspath
|
// fix crosspath
|
||||||
if (rs->path [strlen (rs->path)-1] == '/') {
|
if (rs->path [strlen (rs->path)-1] == '/') {
|
||||||
rs->path = r_str_concat (rs->path, "index.html");
|
rs->path = r_str_concat (rs->path,
|
||||||
|
"index.html");
|
||||||
} else {
|
} else {
|
||||||
snprintf (path, sizeof (path), "%s/%s", root, rs->path);
|
snprintf (path, sizeof (path), "%s/%s", root, rs->path);
|
||||||
if (r_file_is_directory (path)) {
|
if (r_file_is_directory (path)) {
|
||||||
snprintf (path, sizeof (path), "Location: %s/\n", rs->path);
|
snprintf (path, sizeof (path),
|
||||||
r_socket_http_response (rs, 302, NULL, 0, path);
|
"Location: %s/\n", rs->path);
|
||||||
|
r_socket_http_response (rs, 302,
|
||||||
|
NULL, 0, path);
|
||||||
r_socket_http_close (rs);
|
r_socket_http_close (rs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -130,33 +144,32 @@ R_API int r_core_rtr_http(RCore *core, int launch) {
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
if (!strcmp (rs->method, "POST")) {
|
if (!strcmp (rs->method, "POST")) {
|
||||||
const ut8 *ret;
|
ut8 *ret;
|
||||||
int retlen;
|
int retlen;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
if (r_config_get_i (core->config, "http.upload")) {
|
if (r_config_get_i (core->config, "http.upload")) {
|
||||||
ret = r_socket_http_handle_upload (
|
ret = r_socket_http_handle_upload (
|
||||||
rs->data, rs->data_length, &retlen);
|
rs->data, rs->data_length, &retlen);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
char *filename = r_file_root (
|
ut64 size = r_config_get_i (core->config, "http.maxsize");
|
||||||
r_config_get (core->config, "http.uproot"),
|
if (size && retlen > size) {
|
||||||
rs->path + 4);
|
r_socket_http_response (rs, 403, "403 File too big\n", 0, NULL);
|
||||||
eprintf ("UPLOADED '%s'\n", filename);
|
} else {
|
||||||
r_file_dump (filename, ret, retlen);
|
char *filename = r_file_root (
|
||||||
free (filename);
|
r_config_get (core->config, "http.uproot"),
|
||||||
free (ret);
|
rs->path + 4);
|
||||||
} else {
|
eprintf ("UPLOADED '%s'\n", filename);
|
||||||
r_str_uri_decode ((char *)rs->data);
|
r_file_dump (filename, ret, retlen);
|
||||||
}
|
free (filename);
|
||||||
snprintf (buf, sizeof (buf),
|
snprintf (buf, sizeof (buf),
|
||||||
"<html><body><h2>uploaded %d bytes. Thanks</h2>\n", retlen);
|
"<html><body><h2>uploaded %d bytes. Thanks</h2>\n", retlen);
|
||||||
r_socket_http_response (rs, 200, buf, 0, NULL);
|
r_socket_http_response (rs, 200, buf, 0, NULL);
|
||||||
|
}
|
||||||
|
free (ret);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
r_socket_http_response (rs, 403, "403 Forbidden\n", 0, NULL);
|
r_socket_http_response (rs, 403, "403 Forbidden\n", 0, NULL);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
strcat (buf, (char*)rs->data);
|
|
||||||
strcat (buf, ret);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
r_socket_http_response (rs, 404, "Invalid protocol", 0, NULL);
|
r_socket_http_response (rs, 404, "Invalid protocol", 0, NULL);
|
||||||
}
|
}
|
||||||
@ -378,7 +391,8 @@ R_API void r_core_rtr_session(RCore *core, const char *input) {
|
|||||||
|
|
||||||
if (input[0] >= '0' && input[0] <= '9') {
|
if (input[0] >= '0' && input[0] <= '9') {
|
||||||
fd = r_num_math (core->num, input);
|
fd = r_num_math (core->num, input);
|
||||||
for (rtr_n = 0; rtr_host[rtr_n].fd->fd != fd && rtr_n < RTR_MAX_HOSTS; rtr_n++);
|
for (rtr_n = 0; rtr_host[rtr_n].fd->fd != fd \
|
||||||
|
&& rtr_n < RTR_MAX_HOSTS; rtr_n++);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -124,6 +124,7 @@ typedef struct r_io_t {
|
|||||||
RList *maps; /*<RIOMap>*/
|
RList *maps; /*<RIOMap>*/
|
||||||
RList *desc;
|
RList *desc;
|
||||||
RList *cache;
|
RList *cache;
|
||||||
|
int zeromap;
|
||||||
//XXX: Need by rap
|
//XXX: Need by rap
|
||||||
void *user;
|
void *user;
|
||||||
int (*core_cmd_cb)(void *user, const char *str);
|
int (*core_cmd_cb)(void *user, const char *str);
|
||||||
|
@ -83,6 +83,6 @@ typedef struct r_socket_http_request {
|
|||||||
R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, int timeout);
|
R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, int timeout);
|
||||||
R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char *out, int x, const char *headers);
|
R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char *out, int x, const char *headers);
|
||||||
R_API void r_socket_http_close (RSocketHTTPRequest *rs);
|
R_API void r_socket_http_close (RSocketHTTPRequest *rs);
|
||||||
R_API char *r_socket_http_handle_upload(const ut8 *str, int len, int *olen);
|
R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *olen);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
13
libr/io/io.c
13
libr/io/io.c
@ -10,6 +10,7 @@
|
|||||||
R_API RIO *r_io_new() {
|
R_API RIO *r_io_new() {
|
||||||
RIO *io = R_NEW (RIO);
|
RIO *io = R_NEW (RIO);
|
||||||
if (!io) return NULL;
|
if (!io) return NULL;
|
||||||
|
io->zeromap = R_FALSE; // if true, then 0 is mapped with contents of file
|
||||||
io->fd = NULL;
|
io->fd = NULL;
|
||||||
io->write_mask_fd = -1;
|
io->write_mask_fd = -1;
|
||||||
io->redirect = NULL;
|
io->redirect = NULL;
|
||||||
@ -123,7 +124,7 @@ R_API RIODesc *r_io_open(RIO *io, const char *file, int flags, int mode) {
|
|||||||
} else fd = r_sandbox_open (uri, O_BINARY);
|
} else fd = r_sandbox_open (uri, O_BINARY);
|
||||||
#else
|
#else
|
||||||
fd = r_sandbox_open (uri, (flags&R_IO_WRITE)?
|
fd = r_sandbox_open (uri, (flags&R_IO_WRITE)?
|
||||||
O_RDWR:O_RDONLY, mode);
|
O_RDWR: O_RDONLY, mode);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
@ -178,7 +179,7 @@ R_API int r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
|
|||||||
int ret, l, olen = len;
|
int ret, l, olen = len;
|
||||||
int w = 0;
|
int w = 0;
|
||||||
|
|
||||||
r_io_seek (io, addr, R_IO_SEEK_SET);
|
//r_io_seek (io, addr, R_IO_SEEK_SET);
|
||||||
// XXX: this is buggy!
|
// XXX: this is buggy!
|
||||||
memset (buf, 0xff, len);
|
memset (buf, 0xff, len);
|
||||||
while (len>0) {
|
while (len>0) {
|
||||||
@ -193,6 +194,14 @@ R_API int r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
|
|||||||
memset (buf+w, 0xff, l);
|
memset (buf+w, 0xff, l);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!io->zeromap)
|
||||||
|
if (!r_io_map_get (io, addr+w)) {
|
||||||
|
if (r_io_section_getv (io, addr+w)) {
|
||||||
|
memset (buf+w, 0xff, l);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// XXX is this necessary?
|
||||||
ms = r_io_map_select (io, addr+w);
|
ms = r_io_map_select (io, addr+w);
|
||||||
ret = r_io_read_internal (io, buf+w, l);
|
ret = r_io_read_internal (io, buf+w, l);
|
||||||
if (ret<1) {
|
if (ret<1) {
|
||||||
|
@ -160,9 +160,8 @@ R_API RIOSection *r_io_section_getv(RIO *io, ut64 vaddr) {
|
|||||||
RListIter *iter;
|
RListIter *iter;
|
||||||
RIOSection *s;
|
RIOSection *s;
|
||||||
r_list_foreach (io->sections, iter, s) {
|
r_list_foreach (io->sections, iter, s) {
|
||||||
if (vaddr >= s->vaddr && vaddr < s->vaddr + s->vsize) {
|
if (vaddr >= s->vaddr && vaddr < s->vaddr + s->vsize)
|
||||||
return s;
|
return s;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char
|
|||||||
if (out && len>0) r_socket_write (rs->s, (void*)out, len);
|
if (out && len>0) r_socket_write (rs->s, (void*)out, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
R_API char *r_socket_http_handle_upload(const ut8 *str, int len, int *retlen) {
|
R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *retlen) {
|
||||||
if (retlen)
|
if (retlen)
|
||||||
*retlen = 0;
|
*retlen = 0;
|
||||||
if (!strncmp ((const char *)str, "------------------------------", 10)) {
|
if (!strncmp ((const char *)str, "------------------------------", 10)) {
|
||||||
@ -98,7 +98,7 @@ R_API char *r_socket_http_handle_upload(const ut8 *str, int len, int *retlen) {
|
|||||||
ret[datalen] = 0;
|
ret[datalen] = 0;
|
||||||
if (retlen)
|
if (retlen)
|
||||||
*retlen = datalen;
|
*retlen = datalen;
|
||||||
return ret;
|
return (ut8*)ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -53,8 +53,8 @@ Lungo.init ({
|
|||||||
</script>
|
</script>
|
||||||
<!-- windows -->
|
<!-- windows -->
|
||||||
|
|
||||||
<div id="exampleB" style="position:fixed!important;top:200px;left:10;width:250px;height:350px;background-color:#e0e0e0;border: 1px solid black;z-index:99">
|
<div id="exampleB" style="position:fixed!important;top:200px;left:10;width:250px;height:350px;background-color:#e0e0e0;border: 1px solid black;z-index:999">
|
||||||
<div id="exampleBHandle" style="height:20px;left:0px;top:0px;cursor:move;width:248px;background-color:#20a0e0;font-weight:bold;color:white;border:1px solid black"> Registers</div>
|
<div id="exampleBHandle" style="height:20px;left:0px;top:0px;cursor:move;width:248px;background-color:#20a0e0;font-weight:bold;color:white;z-index:1000;border:1px solid black"> Registers</div>
|
||||||
<div style="margin:5px">
|
<div style="margin:5px">
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<pre>
|
<pre>
|
||||||
|
8
shlr/www/upload.html
Normal file
8
shlr/www/upload.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<form action="/up/test.bin" enctype="multipart/form-data" method="post">
|
||||||
|
<input type="file" name="file" />
|
||||||
|
<input type="submit" value="Upload" />
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user