本文整理汇总了C++中r_io_read_at函数的典型用法代码示例。如果您正苦于以下问题:C++ r_io_read_at函数的具体用法?C++ r_io_read_at怎么用?C++ r_io_read_at使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_io_read_at函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: r_core_asm_back_disassemble_all
static RList * r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len, ut64 max_hit_count, ut32 extra_padding){
RList *hits = r_core_asm_hit_list_new ();
RCoreAsmHit dummy_value;
RCoreAsmHit *hit = NULL;
RAsmOp op;
ut8 *buf = (ut8 *)malloc (len + extra_padding);
int current_instr_len = 0;
ut64 current_instr_addr = addr,
current_buf_pos = len - 1,
hit_count = 0;
memset (&dummy_value, 0, sizeof (RCoreAsmHit));
if (hits == NULL || buf == NULL ){
if (hits) {
r_list_purge (hits);
free (hits);
}
free (buf);
return NULL;
}
if (r_io_read_at (core->io, addr-(len+extra_padding), buf, len+extra_padding) != len+extra_padding) {
r_list_purge (hits);
free (hits);
free (buf);
return NULL;
}
if (len == 0){
return hits;
}
current_buf_pos = len - 1;
do {
if (r_cons_singleton ()->breaked) break;
// reset assembler
r_asm_set_pc (core->assembler, current_instr_addr);
current_instr_len = len - current_buf_pos + extra_padding;
IFDBG eprintf("current_buf_pos: 0x%"PFMT64x", current_instr_len: %d\n", current_buf_pos, current_instr_len);
current_instr_len = r_asm_disassemble (core->assembler, &op, buf+current_buf_pos, current_instr_len);
hit = r_core_asm_hit_new ();
hit->addr = current_instr_addr;
hit->len = current_instr_len;
hit->code = NULL;
r_list_add_sorted (hits, hit, ((RListComparator)rcoreasm_address_comparator));
current_buf_pos--;
current_instr_addr--;
hit_count++;
} while ( ((int) current_buf_pos >= 0) && (int)(len - current_buf_pos) >= 0 && hit_count <= max_hit_count);
free(buf);
return hits;
}
示例2: r_io_read_i
R_API ut64 r_io_read_i(RIO *io, ut64 addr, int sz, int endian) {
ut64 ret = 0LL;
int err;
ut8 buf[8];
if (sz > 8) sz = 8;
if (sz < 0) sz = 1;
err = r_io_read_at (io, addr, buf, sz);
if (err == sz) r_mem_copyendian ((ut8*)&ret, buf, sz, endian);
else return -1;
//else perror("Cannot read");
return ret;
}
示例3: R_NEW0
R_API RBuffer *r_io_read_buf(RIO *io, ut64 addr, int len) {
RBuffer *b = R_NEW0 (RBuffer);
if (!b) return NULL;
b->buf = malloc (len);
if (!b->buf) {
free (b);
return NULL;
}
len = r_io_read_at (io, addr, b->buf, len);
b->length = (len < 0)? 0: len;
return b;
}
示例4: cmd_write_bits
static void cmd_write_bits(RCore *core, int set, ut64 val) {
ut64 ret, orig;
// used to set/unset bit in current address
r_io_read_at (core->io, core->offset, (ut8*)&orig, sizeof (orig));
if (set) {
ret = orig | val;
} else {
ret = orig & (~(val));
}
if (!r_core_write_at (core, core->offset, (const ut8*)&ret, sizeof (ret))) {
cmd_write_fail ();
}
}
示例5: r_list_destroy
R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len) {
RCoreAsmHit *hit;
RAsmOp op;
RList *hits = NULL;
ut8 *buf;
ut64 at;
int instrlen, ni, idx;
if (!(hits = r_core_asm_hit_list_new ()))
return NULL;
buf = (ut8 *)malloc (len);
if (!buf) {
r_list_destroy (hits);
return NULL;
}
if (r_io_read_at (core->io, addr-len, buf, len) != len) {
r_list_destroy (hits);
free (buf);
return NULL;
}
for (idx = 1; idx < len; idx++) {
if (r_cons_singleton ()->breaked)
break;
at = addr - idx; ni = 1;
while (at < addr) {
r_asm_set_pc (core->assembler, at);
//XXX HACK We need another way to detect invalid disasm!!
if (!(instrlen = r_asm_disassemble (core->assembler, &op, buf+(len-(addr-at)), addr-at)) || strstr (op.buf_asm, "invalid")) {
break;
} else {
at += instrlen;
if (at == addr) {
if (ni == n) {
if (!(hit = r_core_asm_hit_new ())) {
r_list_destroy (hits);
free (buf);
return NULL;
}
hit->addr = addr-idx;
hit->len = idx;
hit->code = NULL;
r_list_append (hits, hit);
}
} else ni++;
}
}
}
r_asm_set_pc (core->assembler, addr);
free (buf);
return hits;
}
示例6: r_core_visual_asm
R_API void r_core_visual_asm(RCore *core) {
RCoreVisualAsm cva = {0};
cva.core = core;
r_io_read_at (core->io, core->offset, cva.buf, sizeof (cva.buf));
cva.blocklen = r_hex_bin2str (cva.buf, sizeof (cva.buf), cva.blockbuf);
r_line_readline_cb (readline_callback, &cva);
if (cva.acode && cva.acode->len>0)
if (r_cons_yesno ('y', "Save changes? (Y/n)"))
r_core_cmdf (core, "wx %s", cva.acode->buf_hex);
r_asm_code_free (cva.acode);
}
示例7: r_core_read_at
R_API int r_core_read_at(RCore *core, ut64 addr, ut8 *buf, int size) {
int ret;
if (!core->io || !core->file || size<1)
return R_FALSE;
r_io_set_fd (core->io, core->file->fd); // XXX ignore ret? -- ultra slow method.. inverse resolution of io plugin brbrb
ret = r_io_read_at (core->io, addr, buf, size);
if (ret != size) {
if (ret<size && ret>0)
memset (buf+ret, 0xff, size-ret);
else memset (buf, 0xff, size);
}
if (addr>=core->offset && addr<=core->offset+core->blocksize)
r_core_block_read (core, 0);
return (ret!=UT64_MAX);
}
示例8: r_core_dump
R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int append) {
ut64 i;
ut8 *buf;
int bs = core->blocksize;
FILE *fd;
if (append) {
fd = r_sandbox_fopen (file, "ab");
} else {
r_sys_truncate (file, 0);
fd = r_sandbox_fopen (file, "wb");
}
if (!fd) {
eprintf ("Cannot open '%s' for writing\n", file);
return false;
}
/* some io backends seems to be buggy in those cases */
if (bs > 4096) {
bs = 4096;
}
buf = malloc (bs);
if (!buf) {
eprintf ("Cannot alloc %d byte(s)\n", bs);
fclose (fd);
return false;
}
r_cons_break_push (NULL, NULL);
for (i = 0; i < size; i += bs) {
if (r_cons_is_breaked ()) {
break;
}
if ((i + bs) > size) {
bs = size - i;
}
r_io_read_at (core->io, addr + i, buf, bs);
if (fwrite (buf, bs, 1, fd) < 1) {
eprintf ("write error\n");
break;
}
}
r_cons_break_pop ();
fclose (fd);
free (buf);
return true;
}
示例9: ioMemcpy
static bool ioMemcpy (RCore *core, ut64 dst, ut64 src, int len) {
bool ret = false;
if (len > 0) {
ut8 * buf = calloc (1, len);
if (buf) {
if (r_io_read_at (core->io, src, buf, len)) {
if (r_io_write_at (core->io, dst, buf, len)) {
r_core_block_read (core);
ret = true;
} else {
eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", dst);
}
} else {
eprintf ("r_io_read_at failed at 0x%08"PFMT64x"\n", src);
}
free (buf);
}
}
return ret;
}
示例10: r_core_read_at
R_API int r_core_read_at(RCore *core, ut64 addr, ut8 *buf, int size) {
int ret;
if (!core->io || !core->file || size<1)
return R_FALSE;
#if 0
r_io_set_fd (core->io, core->file->fd); // XXX ignore ret? -- ultra slow method.. inverse resolution of io plugin brbrb
ret = r_io_read_at (core->io, addr, buf, size);
if (addr>=core->offset && addr<=core->offset+core->blocksize)
r_core_block_read (core, 0);
#else
r_io_set_fd (core->io, core->file->fd); // XXX ignore ret? -- ultra slow method.. inverse resolution of io plugin brbrb
//ret = r_io_read_at (core->io, addr, buf, size);
r_io_seek (core->io, addr, R_IO_SEEK_SET);
ret = r_io_read (core->io, buf, size);
if (ret != size) {
if (ret>=size || ret<0) ret = 0;
memset (buf+ret, 0xff, size-ret);
}
if (addr>=core->offset && addr<=core->offset+core->blocksize)
r_core_block_read (core, 0);
#endif
return (ret==size); //UT64_MAX);
}
示例11: test_r_io_priority
bool test_r_io_priority(void) {
RIO *io = r_io_new();
ut32 map0, map1;
ut64 buf;
bool ret;
io->va = true;
r_io_open_at (io, "malloc://8", R_PERM_RW, 0644, 0x0);
map0 = r_io_map_get (io, 0)->id;
ret = r_io_read_at (io, 0, (ut8 *)&buf, 8);
mu_assert ("should be able to read", ret);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x00\x00\x00\x00\x00\x00\x00\x00", 8, "0 should be there initially");
buf = 0x9090909090909090;
r_io_write_at (io, 0, (ut8 *)&buf, 8);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x90\x90\x90\x90\x90\x90\x90\x90", 8, "0x90 should have been written");
r_io_open_at (io, "malloc://2", R_PERM_RW, 0644, 0x4);
map1 = r_io_map_get (io, 4)->id;
r_io_read_at (io, 0, (ut8 *)&buf, 8);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x90\x90\x90\x90\x00\x00\x90\x90", 8, "0x00 from map1 should overlap");
buf ^= UT64_MAX;
r_io_write_at (io, 0, (ut8 *)&buf, 8);
r_io_read_at (io, 0, (ut8 *)&buf, 8);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x6f\x6f\x6f\x6f\xff\xff\x6f\x6f", 8, "memory has been xored");
r_io_map_priorize (io, map0);
r_io_read_at (io, 0, (ut8 *)&buf, 8);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x6f\x6f\x6f\x6f\x90\x90\x6f\x6f", 8, "map0 should have been prioritized");
r_io_map_remap (io, map1, 0x2);
r_io_read_at (io, 0, (ut8 *)&buf, 8);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x6f\x6f\x6f\x6f\x90\x90\x6f\x6f", 8, "map1 should have been remapped");
r_io_map_priorize (io, map1);
r_io_read_at (io, 0, (ut8 *)&buf, 8);
mu_assert_memeq ((ut8 *)&buf, (ut8 *)"\x6f\x6f\xff\xff\x90\x90\x6f\x6f", 8, "map1 should have been prioritized");
r_io_free (io);
mu_end;
}
示例12: eprintf
// TODO: add support for byte-per-byte opcode search
R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to) {
RCoreAsmHit *hit;
RAsmOp op;
RList *hits;
ut64 at, toff = core->offset;
ut8 *buf;
char *tok, *tokens[1024], *code = NULL, *ptr;
int idx, tidx = 0, ret, len;
int tokcount, matchcount;
if (!*input)
return NULL;
if (core->blocksize<=OPSZ) {
eprintf ("error: block size too small\n");
return NULL;
}
if (!(buf = (ut8 *)malloc (core->blocksize)))
return NULL;
if (!(ptr = strdup (input))) {
free (buf);
return NULL;
}
if (!(hits = r_core_asm_hit_list_new ())) {
free (buf);
free (ptr);
return NULL;
}
tokens[0] = NULL;
for (tokcount=0; tokcount<(sizeof (tokens) / sizeof (char*)) - 1; tokcount++) {
tok = strtok (tokcount? NULL: ptr, ",");
if (tok == NULL)
break;
tokens[tokcount] = r_str_trim_head_tail (tok);
}
tokens[tokcount] = NULL;
r_cons_break (NULL, NULL);
for (at = from, matchcount = 0; at < to; at += core->blocksize-OPSZ) {
if (r_cons_singleton ()->breaked)
break;
ret = r_io_read_at (core->io, at, buf, core->blocksize);
if (ret != core->blocksize)
break;
idx = 0, matchcount = 0;
while (idx<core->blocksize) {
r_asm_set_pc (core->assembler, at+idx);
op.buf_asm[0] = 0;
op.buf_hex[0] = 0;
if (!(len = r_asm_disassemble (core->assembler, &op, buf+idx, core->blocksize-idx))) {
idx = (matchcount)? tidx+1: idx+1;
matchcount = 0;
continue;
}
if (tokens[matchcount] && strstr (op.buf_asm, tokens[matchcount])) {
code = r_str_concatf (code, "%s", op.buf_asm);
if (matchcount == tokcount-1) {
if (tokcount == 1)
tidx = idx;
if (!(hit = r_core_asm_hit_new ())) {
r_list_purge (hits);
free (hits);
hits = NULL;
goto beach;
}
hit->addr = at+tidx;
hit->len = idx+len-tidx;
if (hit->len == -1) {
r_core_asm_hit_free (hit);
goto beach;
}
hit->code = strdup (code);
r_list_append (hits, hit);
R_FREE (code);
matchcount = 0;
idx = tidx+1;
} else if (matchcount == 0) {
tidx = idx;
matchcount++;
idx += len;
} else {
matchcount++;
idx += len;
}
} else {
idx = matchcount? tidx+1: idx+1;
R_FREE (code);
matchcount = 0;
}
}
}
r_asm_set_pc (core->assembler, toff);
beach:
free (buf);
free (ptr);
free (code);
return hits;
}
示例13: r_core_asm_hit_list_new
R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len) {
RList *hits = r_core_asm_hit_list_new();
RCoreAsmHit dummy_value;
RAsmOp op;
ut8 *buf = (ut8 *)malloc (len);
ut64 instrlen = 0,
at = 0;
ut32
idx = 0,
hit_count = 0;
memset (&dummy_value, 0, sizeof (RCoreAsmHit));
if (hits == NULL || buf == NULL ){
if (hits) {
r_list_purge (hits);
free (hits);
}
free (buf);
return NULL;
}
if (r_io_read_at (core->io, addr-len, buf, len) != len) {
if (hits) {
r_list_purge (hits);
free (hits);
}
free (buf);
return NULL;
}
for (idx = 1; idx < len; idx++) {
ut32 current_buf_pos;
if (r_cons_singleton ()->breaked) break;
at = addr - idx; hit_count = 0;
// XXX - buf here. at may be greater than addr if near boundary.
for (current_buf_pos = len - idx, hit_count = 0;
current_buf_pos < len && hit_count <= n;
current_buf_pos += instrlen, at += instrlen, hit_count++) {
r_asm_set_pc (core->assembler, at);
//XXX HACK We need another way to detect invalid disasm!!
if (!(instrlen = r_asm_disassemble (core->assembler, &op, buf+(len-(addr-at)), addr-at)) || strstr (op.buf_asm, "invalid")) {
break;
}
}
if (hit_count >= n) break;
}
if (hit_count == n) {
at = addr - idx;
hit_count = 0;
r_asm_set_pc (core->assembler, at);
for ( hit_count = 0; hit_count < n; hit_count++) {
instrlen = r_asm_disassemble (core->assembler, &op, buf+(len-(addr-at)), addr-at);
add_hit_to_hits(hits, at, instrlen, R_TRUE);
at += instrlen;
}
}
r_asm_set_pc (core->assembler, addr);
free (buf);
return hits;
}
示例14: print_format_values
static void print_format_values(RCore *core, const char *fmt, bool onstack, ut64 src, bool color) {
char opt;
ut64 bval = src;
int i;
int endian = core->print->big_endian;
int width = (core->anal->bits == 64)? 8: 4;
int bsize = R_MIN (64, core->blocksize);
ut8 *buf = malloc (bsize);
if (!buf) {
eprintf ("Cannot allocate %d byte(s)\n", bsize);
free (buf);
return;
}
if (fmt) {
opt = *fmt;
} else {
opt = 'p'; // void *ptr
}
if (onstack || ((opt != 'd' && opt != 'x') && !onstack)) {
if (color) {
r_cons_printf (Color_BGREEN"0x%08"PFMT64x Color_RESET" --> ", bval);
} else {
r_cons_printf ("0x%08"PFMT64x" --> ", bval);
}
r_io_read_at (core->io, bval, buf, bsize);
}
if (onstack) { // Fetch value from stack
bval = get_buf_val (buf, endian, width);
if (opt != 'd' && opt != 'x') {
r_io_read_at (core->io, bval, buf, bsize); // update buf with val from stack
}
}
r_cons_print (color? Color_BGREEN: "");
switch (opt) {
case 'z' : // Null terminated string
r_cons_print (color ?Color_RESET Color_BWHITE:"");
r_cons_print ("\"");
for (i = 0; i < MAXSTRLEN; i++) {
if (buf[i] == '\0') {
break;
}
ut8 b = buf[i];
if (IS_PRINTABLE (b)) {
r_cons_printf ("%c", b);
} else {
r_cons_printf ("\\x%02x", b);
}
if (i == MAXSTRLEN - 1) {
r_cons_print ("..."); // To show string is truncated
}
}
r_cons_print ("\"");
r_cons_newline ();
break;
case 'd' : // integer
case 'x' :
r_cons_printf ("0x%08" PFMT64x, bval);
r_cons_newline ();
break;
case 'c' : // char
r_cons_print ("\'");
ut8 ch = buf[0];
if (IS_PRINTABLE (ch)) {
r_cons_printf ("%c", ch);
} else {
r_cons_printf ("\\x%02x", ch);
}
r_cons_print ("\'");
r_cons_newline ();
break;
case 'p' : // pointer
{
// Try to deref the pointer once again
r_cons_printf ("0x%08"PFMT64x, get_buf_val (buf, endian, width));
r_cons_newline ();
break;
}
default:
//TODO: support types like structs and unions
r_cons_println ("unk_format");
}
r_cons_print (Color_RESET);
free (buf);
}
示例15: num_callback
static ut64 num_callback(RNum *userptr, const char *str, int *ok) {
RCore *core = (RCore *)userptr; // XXX ?
RAnalFunction *fcn;
char *ptr, *bptr;
RFlagItem *flag;
RIOSection *s;
RAnalOp op;
ut64 ret = 0;
if (ok) *ok = R_FALSE;
if (*str=='[') {
int refsz = (core->assembler->bits & R_SYS_BITS_64)? 8: 4;
const char *p = strchr (str+5, ':');
ut64 n;
// TODO: honor endian
if (p) {
refsz = atoi (str+1);
str = p;
}
// push state
{
char *o = strdup (str+1);
const char *q = r_num_calc_index (core->num, NULL);
r_str_replace_char (o, ']', 0);
n = r_num_math (core->num, o);
r_num_calc_index (core->num, q);
free (o);
}
// pop state
switch (refsz) {
case 8: {
ut64 num = 0;
r_io_read_at (core->io, n, (ut8*)&num, sizeof (num));
return num; }
case 4: {
ut32 num = 0;
r_io_read_at (core->io, n, (ut8*)&num, sizeof (num));
return num; }
case 2: {
ut16 num = 0;
r_io_read_at (core->io, n, (ut8*)&num, sizeof (num));
return num; }
case 1: {
ut8 num = 0;
r_io_read_at (core->io, n, (ut8*)&num, sizeof (num));
return num; }
default:
eprintf ("Invalid reference size: %d (%s)\n", refsz, str);
break;
}
} else
if (str[0]=='$') {
if (ok) *ok = 1;
// TODO: group analop-dependant vars after a char, so i can filter
r_anal_op (core->anal, &op, core->offset,
core->block, core->blocksize);
switch (str[1]) {
case '.': // can use pc, sp, a0, a1, ...
return r_debug_reg_get (core->dbg, str+2);
case '{':
bptr = strdup (str+2);
ptr = strchr (bptr, '}');
if (ptr != NULL) {
ut64 ret;
ptr[0] = '\0';
ret = r_config_get_i (core->config, bptr);
free (bptr);
return ret;
}
break;
case 'h': {
int rows;
r_cons_get_size (&rows);
return rows;
}
case 'e': return op.eob;
case 'j': return op.jump;
case 'f': return op.fail;
case 'r': return op.ref;
case 'l': return op.length;
case 'b': return core->blocksize;
case 's': return core->file->size;
case 'w': return r_config_get_i (core->config, "asm.bits") / 8;
case 'S':
s = r_io_section_get (core->io,
r_io_section_vaddr_to_offset (core->io,
core->offset));
return s? (str[2]=='S'? s->size: s->offset): 0;
case '?': return core->num->value;
case '$': return core->offset;
case 'o': return core->io->off;
case 'C': return getref (core, atoi (str+2), 'r',
R_ANAL_REF_TYPE_CALL);
case 'J': return getref (core, atoi (str+2), 'r',
R_ANAL_REF_TYPE_CODE);
case 'D': return getref (core, atoi (str+2), 'r',
R_ANAL_REF_TYPE_DATA);
case 'X': return getref (core, atoi (str+2), 'x',
R_ANAL_REF_TYPE_CALL);
case 'I':
//.........这里部分代码省略.........