mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-20 20:55:32 +00:00
Implement wts to send data to socket
This commit is contained in:
parent
f80685c259
commit
5fcee5d712
@ -425,7 +425,8 @@ static int cmd_write(void *data, const char *input) {
|
||||
"wp"," -|file","apply radare patch file. See wp? fmi",
|
||||
"wr"," 10","write 10 random bytes",
|
||||
"ws"," pstring","write 1 byte for length and then the string",
|
||||
"wt"," file [sz]","write to file (from current seek, blocksize or sz bytes)",
|
||||
"wt[f]"," file [sz]","write to file (from current seek, blocksize or sz bytes)",
|
||||
"wts"," host:port", "send data to remote host:port via tcp://",
|
||||
"ww"," foobar","write wide string 'f\\x00o\\x00o\\x00b\\x00a\\x00r\\x00'",
|
||||
"wx","[?][fs] 9090","write two intel nops (from wxfile or wxseek)",
|
||||
"wv","[?] eip+34","write 32-64 bit value",
|
||||
@ -920,13 +921,64 @@ static int cmd_write(void *data, const char *input) {
|
||||
r_core_block_read (core);
|
||||
break;
|
||||
case 't': // "wt"
|
||||
if (*str == '?' || *str == '\0') {
|
||||
if (*str == 's') { // "wts"
|
||||
if (str[1] == ' ') {
|
||||
eprintf ("Write to server\n");
|
||||
st64 sz = r_io_size (core->io);
|
||||
if (sz > 0) {
|
||||
ut64 addr = 0;
|
||||
char *host = str + 2;
|
||||
char *port = strchr (host, ':');
|
||||
if (port) {
|
||||
*port ++= 0;
|
||||
char *space = strchr (port, ' ');
|
||||
if (space) {
|
||||
*space++ = 0;
|
||||
sz = r_num_math (core->num, space);
|
||||
addr = core->offset;
|
||||
}
|
||||
ut8 *buf = calloc (1, sz);
|
||||
if (space) {
|
||||
(void)r_io_vread (core->io, addr, buf, sz);
|
||||
} else {
|
||||
(void)r_io_pread (core->io, addr, buf, sz);
|
||||
}
|
||||
RSocket *s = r_socket_new (false);
|
||||
if (r_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) {
|
||||
int done = 0;
|
||||
eprintf ("Transfering file to the end-point...\n");
|
||||
while (done < sz) {
|
||||
int rc = r_socket_write (s, buf + done, sz - done);
|
||||
if (rc <1) {
|
||||
eprintf ("oops\n");
|
||||
break;
|
||||
}
|
||||
done += rc;
|
||||
}
|
||||
} else {
|
||||
eprintf ("Cannot connect\n");
|
||||
}
|
||||
r_socket_free (s);
|
||||
free (buf);
|
||||
} else {
|
||||
eprintf ("Usage wts host:port [sz]\n");
|
||||
}
|
||||
} else {
|
||||
eprintf ("Unknown file size\n");
|
||||
}
|
||||
} else {
|
||||
eprintf ("Usage wts host:port [sz]\n");
|
||||
}
|
||||
} else if (*str == '?' || *str == '\0') {
|
||||
eprintf ("Usage: wt[a] file [size] write 'size' bytes in current block to file\n");
|
||||
free (ostr);
|
||||
return 0;
|
||||
} else {
|
||||
int append = 0;
|
||||
st64 sz = core->blocksize;
|
||||
if (*str=='f') { // "wtf"
|
||||
str++;
|
||||
} else
|
||||
if (*str=='a') { // "wta"
|
||||
append = 1;
|
||||
str++;
|
||||
|
@ -1002,9 +1002,12 @@ static ut8 *r_io_desc_read(RIO *io, RIODesc *desc, ut64 *out_sz) {
|
||||
ut8 *buf = NULL;
|
||||
ut64 off = 0;
|
||||
|
||||
if (!io || !desc || !out_sz) {
|
||||
if (!io || !out_sz) {
|
||||
return NULL;
|
||||
}
|
||||
if (!desc) {
|
||||
desc = io->desc;
|
||||
}
|
||||
if (*out_sz == UT64_MAX) {
|
||||
*out_sz = r_io_desc_size (io, desc);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user