int main () { int ret; RIODesc *fd; char buf[1024]; struct r_io_t *io; io = r_io_new(); r_io_plugin_list(io); //fd = r_io_open(io, "/bin/ls", R_IO_READ, 0); fd = r_io_open(io, "dbg:///bin/ls", R_IO_READ, 0); r_io_set_fd(io, fd); //r_io_map_add(io, fd, R_IO_READ, 0, 0xf00000, 0xffff); r_io_map_add(io, fd->fd, R_IO_READ, 0x8048000, 0, 0xffff); memset(buf, 0, 1024); //ret = r_io_read_at(io, 0xf00000, buf, 1024); // ret = r_io_seek(io, 0x8048000, R_IO_SEEK_SET); // printf("seek = 0x%"PFMT64x"\n", ret); ret = r_io_read_at (io, 0, (ut8*)buf, 64); //ret = r_io_read_at(io, 0x8048000, buf, 64); printf("%d = %02x %02x %02x %02x\n", ret, buf[0], buf[1], buf[2], buf[3]); r_io_free(io); return 0; }
bool test_r_io_pcache (void) { RIO *io = r_io_new (); ut8 buf[8]; int fd = r_io_fd_open (io, "malloc://3", R_PERM_RW, 0); r_io_map_add (io, fd, R_PERM_RW, 0LL, 0LL, 1); //8 r_io_map_add (io, fd, R_PERM_RW, 1, 1, 1); //= r_io_map_add (io, fd, R_PERM_RW, 1, 2, 1); //= r_io_map_add (io, fd, R_PERM_RW, 1, 3, 1); //= r_io_map_add (io, fd, R_PERM_RW, 1, 4, 1); //= r_io_map_add (io, fd, R_PERM_RW, 1, 5, 1); //= r_io_map_add (io, fd, R_PERM_RW, 2, 6, 1); //D io->p_cache = 2; io->va = true; r_io_fd_write_at (io, fd, 0, (const ut8*)"8=D", 3); r_io_read_at (io, 0x0, buf, 8); mu_assert_streq ((const char *)buf, "", "pcache read happened, but it shouldn't"); io->p_cache = 1; r_io_read_at (io, 0x0, buf, 8); mu_assert_streq ((const char *)buf, "8=====D", "expected an ascii-pn from pcache"); r_io_fd_write_at (io, fd, 0, (const ut8*)"XXX", 3); r_io_read_at (io, 0x0, buf, 8); mu_assert_streq ((const char *)buf, "8=====D", "expected an ascii-pn from pcache"); io->p_cache = 0; r_io_read_at (io, 0x0, buf, 8); mu_assert_streq ((const char *)buf, "XXXXXXX", "expected censorship of the ascii-pn"); r_io_free (io); mu_end; }