本文整理汇总了C++中r_io_read_at函数的典型用法代码示例。如果您正苦于以下问题:C++ r_io_read_at函数的具体用法?C++ r_io_read_at怎么用?C++ r_io_read_at使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_io_read_at函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:AnwarMohamed,项目名称:radare2,代码行数:56,代码来源:asm.c
示例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;
}
开发者ID:Rogunix,项目名称:radare2,代码行数:12,代码来源:io.c
示例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;
}
开发者ID:m403,项目名称:radare2,代码行数:12,代码来源:io.c
示例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 ();
}
}
开发者ID:agatti,项目名称:radare2,代码行数:13,代码来源:cmd_write.c
示例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;
}
开发者ID:moon2l,项目名称:radare2,代码行数:51,代码来源:asm.c
示例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);
}
开发者ID:0xroot,项目名称:radare2,代码行数:14,代码来源:vasm.c
示例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);
}
开发者ID:ericfode,项目名称:radare2,代码行数:15,代码来源:io.c
示例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;
}
开发者ID:f0829,项目名称:radare2,代码行数:44,代码来源:cio.c
示例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;
}
开发者ID:agatti,项目名称:radare2,代码行数:20,代码来源:cmd_write.c
示例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);
}
开发者ID:adamharder,项目名称:radare2,代码行数:23,代码来源:io.c
示例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;
}
开发者ID:radare,项目名称:radare2-regressions,代码行数:41,代码来源:test_io.c
示例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;
}
开发者ID:DePierre,项目名称:radare2,代码行数:97,代码来源:asm.c
示例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;
}
开发者ID:DePierre,项目名称:radare2,代码行数:65,代码来源:asm.c
示例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);
}
开发者ID:aronsky,项目名称:radare2,代码行数:85,代码来源:carg.c
示例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':
//.........这里部分代码省略.........
开发者ID:josdiaz,项目名称:radare2,代码行数:101,代码来源:core.c
示例16: r_num_math
// 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, int maxhits, int regexp, int everyByte, int mode) {
RCoreAsmHit *hit;
RAsmOp op;
RList *hits;
ut64 at, toff = core->offset;
ut8 *buf;
int align = core->search->align;
RRegex* rx = NULL;
char *tok, *tokens[1024], *code = NULL, *ptr;
int idx, tidx = 0, len = 0;
int tokcount, matchcount, count = 0;
int matches = 0;
const int addrbytes = core->io->addrbytes;
if (!input || !*input) {
return NULL;
}
ut64 usrimm = r_num_math (core->num, input + 1);
if (core->blocksize < 8) {
eprintf ("error: block size too small\n");
return NULL;
}
if (!(buf = (ut8 *)calloc (core->blocksize, 1))) {
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 < R_ARRAY_SIZE (tokens) - 1; tokcount++) {
tok = strtok (tokcount? NULL: ptr, ";");
if (!tok) {
break;
}
tokens[tokcount] = r_str_trim_head_tail (tok);
}
tokens[tokcount] = NULL;
r_cons_break_push (NULL, NULL);
char *opst = NULL;
for (at = from, matchcount = 0; at < to; at += core->blocksize) {
if (r_cons_is_breaked ()) {
break;
}
if (!r_io_is_valid_offset (core->io, at, 0)) {
break;
}
(void)r_io_read_at (core->io, at, buf, core->blocksize);
idx = 0, matchcount = 0;
while (addrbytes * (idx + 1) <= core->blocksize) {
ut64 addr = at + idx;
if (addr >= to) {
break;
}
r_asm_set_pc (core->assembler, addr);
if (mode == 'i') {
RAnalOp analop = {0};
if (r_anal_op (core->anal, &analop, addr, buf + idx, 15, 0) < 1) {
idx ++; // TODO: honor mininstrsz
continue;
}
if (analop.val == usrimm) {
if (!(hit = r_core_asm_hit_new ())) {
r_list_purge (hits);
R_FREE (hits);
goto beach;
}
hit->addr = addr;
hit->len = analop.size; // idx + len - tidx;
if (hit->len == -1) {
r_core_asm_hit_free (hit);
goto beach;
}
r_asm_disassemble (core->assembler, &op, buf + addrbytes * idx,
core->blocksize - addrbytes * idx);
hit->code = r_str_newf (r_strbuf_get (&op.buf_asm));
idx = (matchcount)? tidx + 1: idx + 1;
matchcount = 0;
r_list_append (hits, hit);
continue;
}
r_anal_op_fini (&analop);
idx ++; // TODO: honor mininstrsz
continue;
} else if (mode == 'e') {
RAnalOp analop = {0};
if (r_anal_op (core->anal, &analop, addr, buf + idx, 15, R_ANAL_OP_MASK_ESIL) < 1) {
idx ++; // TODO: honor mininstrsz
continue;
}
//opsz = analop.size;
opst = strdup (r_strbuf_get (&analop.esil));
//.........这里部分代码省略.........
开发者ID:rlaemmert,项目名称:radare2,代码行数:101,代码来源:casm.c
示例17: 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();
RAsmOp op;
ut8 *buf;
ut64 buf_addr, instrlen = 0, at = 0;
ut32 idx = 0, hit_count = 0, buf_len = 0;
int numinstr, ii;
RAsmCode *c;
if (!hits)
return NULL;
buf_addr = addr - len;
buf_len = len;
buf = (ut8 *)malloc (buf_len);
if (!buf) {
r_list_free (hits);
return NULL;
}
if (r_io_read_at (core->io, buf_addr, buf, buf_len) != buf_len) {
r_list_free (hits);
free (buf);
return NULL;
}
if (!memcmp (buf, "\xff\xff\xff\xff", R_MIN (4, buf_len))) {
eprintf ("error reading at 0x%08"PFMT64x"\n", buf_addr);
r_list_free (hits);
free (buf);
return NULL;
}
if (n<0) n = -n;
for (idx = 1; idx < len; idx++) {
if (r_cons_singleton ()->breaked)
break;
at = addr - idx;
hit_count = 0;
r_asm_set_pc (core->assembler, at);
// XXX: the disassemble errors are because of this line. mdisasm must not be used here
//c = r_asm_mdisassemble (core->assembler, buf+idx, buf_len-idx); //+buf_len-idx, idx);
c = r_asm_mdisassemble (core->assembler, buf+buf_len-idx, idx);
// XXX: relaying on string contents in the buf_asm is a bad idea
if (strstr (c->buf_asm, "invalid") || strstr (c->buf_asm, ".byte")) {
r_asm_code_free (c);
continue;
}
//eprintf ("-->(%x)(%s)\n", at, c->buf_asm);
for (numinstr = ii = 0; c->buf_asm[ii] ; ii++) {
if (c->buf_asm[ii] == '\n')
numinstr++;
}
//eprintf ("mdisasm worked! for 0x%llx with %d\n", addr-len+idx, numinstr);
r_asm_code_free (c);
if (numinstr >= n || idx > 32 * n) {
//eprintf ("idx = %d len = %d ninst = %d n = %d\n", idx, len, numinstr, n);
break;
}
//eprintf ("idx = %d len = %d\n", idx, len);
}
at = addr - idx;
hit_count = 0;
for (hit_count = 0; hit_count < n; hit_count++) {
if (r_cons_singleton ()->breaked)
break;
r_asm_set_pc (core->assembler, at);
instrlen = r_asm_disassemble (core->assembler,
&op, buf+buf_len-(addr-at), addr-at); //addr-at);
// eprintf ("INST LEN = %d\n", instrlen);
if (instrlen<1) {
eprintf ("dissasm failed at %llx\n", at);
instrlen = 1;
// break;
}
add_hit_to_hits (hits, at, instrlen, R_TRUE);
at += instrlen;
}
free (buf);
return hits;
}
开发者ID:AnwarMohamed,项目名称:radare2,代码行数:83,代码来源:asm.c
示例18: 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();
RAsmOp op;
// len = n * 32;
// if (n > core->blocksize) n = core->blocksize;
ut8 *buf;
ut64 instrlen = 0, at = 0;
ut32 idx = 0, hit_count = 0;
int numinstr, asmlen, ii;
RAsmCode *c;
if (len < 1) {
r_list_free (hits);
return NULL;
}
buf = (ut8 *)malloc (len);
if (!hits || !buf) {
if (hits) {
r_list_free (hits);
}
free (buf);
return NULL;
}
if (r_io_read_at (core->io, addr-len, buf, len) != len) {
if (hits) {
r_list_free (hits);
}
free (buf);
return NULL;
}
for (idx = 1; idx < len; ++idx) {
if (r_cons_singleton ()->breaked) break;
at = addr - idx; hit_count = 0;
c = r_asm_mdisassemble (core->assembler, buf+(len-idx), idx);
if (strstr(c->buf_asm, "invalid") || strstr(c->buf_asm, ".byte")) {
r_asm_code_free(c);
continue;
}
numinstr = 0;
asmlen = strlen(c->buf_asm);
for(ii = 0; ii < asmlen; ++ii) {
if (c->buf_asm[ii] == '\n') ++numinstr;
}
r_asm_code_free(c);
if (numinstr >= n || idx > 32 * n) {
break;
}
}
at = addr - idx;
hit_count = 0;
r_asm_set_pc (core->assembler, at);
at = addr-idx;
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, true);
at += instrlen;
}
free (buf);
return hits;
}
开发者ID:ghostbar,项目名称:radare2.deb,代码行数:63,代码来源:asm.c
示例19: 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, int maxhits, int regexp) {
RCoreAsmHit *hit;
RAsmOp op;
RList *hits;
ut64 at, toff = core->offset;
ut8 *buf;
int align = core->search->align;
RRegex* rx = NULL;
char *tok, *tokens[1024], *code = NULL, *ptr;
int idx, tidx = 0, ret, len;
int tokcount, matchcount, count = 0;
int matches = 0;
if (!*input)
return NULL;
if (core->blocksize <= OPSZ) {
eprintf ("error: block size too small\n");
return NULL;
}
if (!(buf = (ut8 *)calloc (core->blocksize, 1)))
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)
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) {
matches = 0;
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) {
ut64 addr = at + idx;
r_asm_set_pc (core->assembler, addr);
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;
}
matches = true;
if (!strcmp (op.buf_asm, "unaligned"))
matches = false;
if (!strcmp (op.buf_asm, "invalid"))
matches = false;
if (matches && tokens[matchcount]) {
if (!regexp) matches = strstr(op.buf_asm, tokens[matchcount]) != NULL;
else {
rx = r_regex_new (tokens[matchcount], "");
matches = r_regex_exec (rx, op.buf_asm, 0, 0, 0) == 0;
r_regex_free (rx);
}
}
if (align && align>1) {
if (addr % align) {
matches = false;
}
}
if (matches) {
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 = addr;
hit->len = idx + len - tidx;
if (hit->len == -1) {
r_core_asm_hit_free (hit);
goto beach;
}
code[strlen (code)-2] = 0;
hit->code = strdup (code);
r_list_append (hits, hit);
R_FREE (code);
matchcount = 0;
idx = tidx+1;
if (maxhits) {
//.........这里部分代码省略.........
开发者ID:ghostbar,项目名称:radare2.deb,代码行数:101,代码来源:asm.c
示例20: perform_mapped_file_yank
static int perform_mapped_file_yank (RCore *core, ut64 offset, ut64 len, const char *filename) {
// grab the current file descriptor, so we can reset core and io state
// after our io op is done
RIODesc *yankfd = NULL;
ut64 fd = core->file ? core->file->desc->fd : -1, yank_file_sz = 0,
loadaddr = 0, addr = offset;
int res = R_FALSE;
if (filename && *filename) {
ut64 load_align = r_config_get_i (core->config,
"file.loadalign");
RIOMap * map = NULL;
yankfd = r_io_open (core->io, filename, R_IO_READ, 0644);
// map the file in for IO operations.
if (yankfd && load_align) {
yank_file_sz = r_io_size (core->io);
map = r_io_map_add_next_available (core->io,
yankfd->fd,
R_IO_READ, 0, 0,
yank_file_sz,
load_align);
loadaddr = map ? map->from : -1;
if (yankfd && map && loadaddr != -1) {
// ***NOTE*** this is important, we need to
// address the file at its physical address!
addr += loadaddr;
} else if (yankfd) {
eprintf ("Unable to map the opened file: %s", filename);
r_io_close (core->io, yankfd);
yankfd = NULL;
} else {
eprintf ("Unable to open the file: %s", filename);
}
}
}
// if len is -1 then we yank in everything
if (len == -1) len = yank_file_sz;
IFDBG eprintf ("yankfd: %p, yank->fd = %d, fd=%d\n", yankfd,
(int)(yankfd ? yankfd->fd : -1), (int)fd);
// this wont happen if the file failed to open or the file failed to
// map into the IO layer
if (yankfd) {
ut64 res = r_io_seek (core->io, addr, R_IO_SEEK_SET),
actual_len = len <= yank_file_sz ? len : 0;
ut8 *buf = NULL;
IFDBG eprintf (
"Addr (%"PFMT64d
") file_sz (%"PFMT64d
") actual_len (%"PFMT64d
") len (%"PFMT64d
") bytes from file: %s\n", addr, yank_file_sz,
actual_len, len, filename);
if (actual_len > 0 && res == addr) {
IFDBG eprintf (
"Creating buffer and reading %"PFMT64d
" bytes from file: %s\n", actual_len, filename);
buf = malloc (actual_len);
actual_len = r_io_read_at (core->io, addr, buf,
actual_len);
IFDBG eprintf (
"Reading %"PFMT64d " bytes from file: %s\n",
actual_len, filename);
/*IFDBG {
int i = 0;
eprintf ("Read these bytes from file: \n");
for (i = 0; i < actual_len; i++)
eprintf ("%02x", buf[i]);
eprintf ("\n");
}*/
r_core_yank_set (core, R_CORE_FOREIGN_ADDR, buf, len);
res = R_TRUE;
} else if (res != addr) {
eprintf (
"ERROR: Unable to yank data from file: (loadaddr (0x%"
PFMT64x ") (addr (0x%"
PFMT64x ") > file_sz (0x%"PFMT64x ")\n", res, addr,
yank_file_sz );
} else if (actual_len == 0) {
eprintf (
"ERROR: Unable to yank from file: addr+len (0x%"
PFMT64x ") > file_sz (0x%"PFMT64x ")\n", addr+len,
yank_file_sz );
}
r_io_close (core->io, yankfd);
free (buf);
}
if (fd != -1) {
r_io_raise (core->io, fd);
core->switch_file_view = 1;
r_core_block_read (core, 0);
}
return res;
}
开发者ID:t35t12345,项目名称:radare2,代码行数:95,代码来源:yank.c
注:本文中的r_io_read_at函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论