2012-01-31 01:45:17 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> */
|
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) {
|
|
|
|
free (core->yank);
|
|
|
|
if (str) {
|
|
|
|
core->yank = (ut8*)strdup (str);
|
|
|
|
core->yank_off = core->offset;
|
|
|
|
core->yank_len = strlen (str);
|
|
|
|
} else {
|
|
|
|
core->yank = NULL;
|
|
|
|
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;
|
2010-03-11 00:04:59 +00:00
|
|
|
free (core->yank);
|
|
|
|
core->yank = (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
|
|
|
}
|
|
|
|
memcpy (core->yank, 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;
|
2010-03-11 00:04:59 +00:00
|
|
|
r_core_write_at (core, addr, core->yank, len);
|
2009-02-18 12:10:59 +00:00
|
|
|
return R_TRUE;
|
|
|
|
}
|