2013-02-11 09:51:45 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2013 - pancake */
|
2009-02-18 12:10:59 +00:00
|
|
|
|
|
|
|
#include "r_core.h"
|
|
|
|
|
2012-01-31 01:45:17 +00:00
|
|
|
R_API void r_core_yank_set (RCore *core, const char *str) {
|
2012-09-19 12:08:44 +00:00
|
|
|
free (core->yank_buf);
|
2012-01-31 01:45:17 +00:00
|
|
|
if (str) {
|
2012-09-19 12:08:44 +00:00
|
|
|
core->yank_buf = (ut8*)strdup (str);
|
2012-01-31 01:45:17 +00:00
|
|
|
core->yank_off = core->offset;
|
|
|
|
core->yank_len = strlen (str);
|
|
|
|
} else {
|
2012-09-19 12:08:44 +00:00
|
|
|
core->yank_buf = NULL;
|
2012-01-31 01:45:17 +00:00
|
|
|
core->yank_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) {
|
2012-02-04 23:33:34 +00:00
|
|
|
ut64 oldbsz = 0LL;
|
2010-01-12 01:12:18 +00:00
|
|
|
ut64 curseek = core->offset;
|
2012-09-19 12:08:44 +00:00
|
|
|
free (core->yank_buf);
|
|
|
|
core->yank_buf = (ut8 *)malloc (len);
|
2010-01-12 01:12:18 +00:00
|
|
|
if (addr != core->offset)
|
2010-03-11 00:04:59 +00:00
|
|
|
r_core_seek (core, addr, 1);
|
2009-02-18 12:10:59 +00:00
|
|
|
if (len == 0)
|
|
|
|
len = core->blocksize;
|
2012-02-04 23:33:34 +00:00
|
|
|
if (len > core->blocksize) {
|
|
|
|
oldbsz = core->blocksize;
|
2010-03-11 00:04:59 +00:00
|
|
|
r_core_block_size (core, len);
|
2012-02-04 23:33:34 +00:00
|
|
|
}
|
2012-09-19 12:08:44 +00:00
|
|
|
memcpy (core->yank_buf, core->block, len);
|
2009-02-18 12:10:59 +00:00
|
|
|
core->yank_off = addr;
|
|
|
|
core->yank_len = len;
|
|
|
|
if (curseek != addr)
|
2010-03-11 00:04:59 +00:00
|
|
|
r_core_seek (core, curseek, 1);
|
2012-02-04 23:33:34 +00:00
|
|
|
if (oldbsz)
|
|
|
|
r_core_block_size (core, oldbsz);
|
2009-02-18 12:10:59 +00:00
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-08 11:45:22 +00:00
|
|
|
R_API int r_core_yank_paste(struct r_core_t *core, ut64 addr, int len) {
|
2009-02-18 12:10:59 +00:00
|
|
|
if (len == 0)
|
|
|
|
len = core->yank_len;
|
|
|
|
if (len > core->yank_len)
|
|
|
|
len = core->yank_len;
|
2012-09-19 12:08:44 +00:00
|
|
|
r_core_write_at (core, addr, core->yank_buf, len);
|
2009-02-18 12:10:59 +00:00
|
|
|
return R_TRUE;
|
|
|
|
}
|
2012-02-05 00:14:09 +00:00
|
|
|
|
2012-08-09 10:42:44 +00:00
|
|
|
R_API int r_core_yank_to(RCore *core, const char *_arg) {
|
2012-02-05 00:14:09 +00:00
|
|
|
ut64 src = core->offset;
|
|
|
|
ut64 len = 0;
|
|
|
|
ut64 pos = -1;
|
2012-08-09 10:42:44 +00:00
|
|
|
char *str, *arg;
|
2012-02-05 00:14:09 +00:00
|
|
|
ut8 *buf;
|
|
|
|
|
2012-08-09 10:42:44 +00:00
|
|
|
while (*_arg==' ') _arg++;
|
|
|
|
arg = strdup (_arg);
|
2012-02-05 00:14:09 +00:00
|
|
|
str = strchr (arg, ' ');
|
|
|
|
if (str) {
|
|
|
|
str[0]='\0';
|
|
|
|
len = r_num_math (core->num, arg);
|
|
|
|
pos = r_num_math (core->num, str+1);
|
|
|
|
str[0]=' ';
|
|
|
|
}
|
|
|
|
if ((str == NULL) || (pos == -1) || (len == 0)) {
|
|
|
|
eprintf ("Usage: yt [len] [dst-addr]\n");
|
2012-08-09 10:42:44 +00:00
|
|
|
free (arg);
|
2012-02-05 00:14:09 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (!config_get("file.write")) {
|
|
|
|
eprintf("You are not in read-write mode.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
buf = (ut8*)malloc (len);
|
|
|
|
r_core_read_at (core, src, buf, len);
|
|
|
|
r_core_write_at (core, pos, buf, len);
|
|
|
|
free (buf);
|
|
|
|
|
|
|
|
core->offset = src;
|
|
|
|
r_core_block_read (core, 0);
|
2012-08-09 10:42:44 +00:00
|
|
|
free (arg);
|
2012-02-05 00:14:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|