mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-20 22:34:39 +00:00
* Fix build of core
* Fix non-static plugins build in r_debug and r_io * Fix debug_ptrace - working with example but not in r2 * debug/t/main.c is now working correctly * Massive R_APIfication in r_io and r_util * Added r_io_read_i to read from memory as a ut64 in any endian - read4.c example uses this new function * Fix build of r_io static plugins * Some more checks at random places in r_io (more stable) - r_io_set_fd() simplifies fd and plugin setup * Added |pid command for ptrace io plugin * Added io->printf to avoid use of forced 'printf' * Add more lib_types names. fixes probable segfault * Added hg-ci hg-utils makefile target
This commit is contained in:
parent
6c28274aa0
commit
1ee0247b94
1
TODO
1
TODO
@ -8,6 +8,7 @@
|
||||
|
||||
<{include libr/TODO}>
|
||||
|
||||
* Rename io_lseek to io_seek ... l is for long..and radare uses ut64!
|
||||
* correct result (R_TRUFAE), but with warnings (implement r_errno and r_errstr in r_util?)
|
||||
- Quantic computation ftw \o/
|
||||
* Add r_th for threading help for w32/osx/linux/bsd/... .. use gthread? :P
|
||||
|
@ -1,3 +1,6 @@
|
||||
Not-much-updated graph of relationships between the libr APIs
|
||||
=============================================================
|
||||
|
||||
+--------+
|
||||
.-| config |
|
||||
/ +--------+
|
||||
|
@ -1666,9 +1666,11 @@ static int cmd_debug(void *data, const char *input)
|
||||
else fprintf(stderr, "TODO: List processes..\n");
|
||||
break;
|
||||
case 'h':
|
||||
if (input[1]==' ')
|
||||
r_debug_handle_set(&core->dbg, input+2);
|
||||
else r_debug_handle_list(&core->dbg);
|
||||
if (input[1]==' ') {
|
||||
char buf[1024];
|
||||
snprintf(buf, "dbg_%s", input+2);
|
||||
r_debug_handle_set(&core->dbg, buf);
|
||||
} else r_debug_handle_list(&core->dbg);
|
||||
break;
|
||||
default:
|
||||
r_cons_printf("Usage: d[sbhcrbo] [arg]\n"
|
||||
|
@ -151,6 +151,7 @@ R_API int r_core_init(struct r_core_t *core)
|
||||
r_core_cmd_init(core);
|
||||
r_flag_init(&core->flags);
|
||||
r_debug_init(&core->dbg);
|
||||
core->io.printf = r_cons_printf;
|
||||
core->dbg.printf = r_cons_printf;
|
||||
r_debug_set_io(&core->dbg, &__dbg_read, &__dbg_write, core);
|
||||
r_core_config_init(core);
|
||||
|
@ -1,4 +1,4 @@
|
||||
CFLAGS=-I../../include -Wall -fPIC -shared -Wl,-R..
|
||||
CFLAGS=-I../../include -Wall -fPIC -shared -Wl,-R.. -DCORELIB
|
||||
|
||||
foo: all
|
||||
|
||||
|
@ -12,11 +12,13 @@
|
||||
|
||||
static int r_debug_ptrace_step(int pid)
|
||||
{
|
||||
//ut32 addr = 0; /* should be eip */
|
||||
int ret;
|
||||
ut32 addr = 0; /* should be eip */
|
||||
//ut32 data = 0;
|
||||
printf("NATIVE STEP over PID=%d\n", pid);
|
||||
ptrace(PTRACE_SINGLESTEP, pid, 0, 0); //addr, data);
|
||||
perror("ptrace-singlestep");
|
||||
//printf("NATIVE STEP over PID=%d\n", pid);
|
||||
ret = ptrace(PTRACE_SINGLESTEP, pid, addr, 0); //addr, data);
|
||||
if (ret == -1)
|
||||
perror("ptrace-singlestep");
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
@ -45,9 +47,9 @@ static int r_debug_ptrace_continue(int pid)
|
||||
static int r_debug_ptrace_wait(int pid)
|
||||
{
|
||||
int ret, status = -1;
|
||||
printf("prewait\n");
|
||||
//printf("prewait\n");
|
||||
ret = waitpid(pid, &status, 0);
|
||||
printf("status=%d (return=%d)\n", status, ret);
|
||||
//printf("status=%d (return=%d)\n", status, ret);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
|
||||
#include <r_util.h>
|
||||
#include <r_debug.h>
|
||||
#include <r_io.h>
|
||||
@ -5,7 +7,8 @@
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
struct r_io_t *io = r_io_new();
|
||||
int tid, pid;
|
||||
struct r_io_t *io;
|
||||
struct r_dbg_t *dbg;
|
||||
|
||||
io = r_io_new();
|
||||
@ -21,19 +24,25 @@ int main(int argc, char **argv)
|
||||
|
||||
dbg = r_debug_new();
|
||||
printf("Supported debugger backends:\n");
|
||||
r_debug_handle_list (dbg);
|
||||
|
||||
ret = r_debug_handle_set (dbg, "dbg_ptrace");
|
||||
printf("Using 'dbg_ptrace' = %s\n", r_str_bool(ret));
|
||||
//r_debug_bp_add(dbg, 0x8048018);
|
||||
//r_debug_set_io
|
||||
ret = r_debug_start (dbg, "/bin/ls");
|
||||
if (!ret) {
|
||||
printf("Cannot create process\n");
|
||||
goto beach;
|
||||
}
|
||||
|
||||
tid = pid = r_io_system(io, -1, "pid");
|
||||
r_debug_select(dbg, pid, tid);
|
||||
|
||||
printf("--> regs pre step\n");
|
||||
r_io_system(io, -1, "reg");
|
||||
|
||||
printf("--> perform 2 steps (only 1 probably?\n");
|
||||
r_debug_step(dbg, 2);
|
||||
|
||||
printf("--> regs post step\n");
|
||||
r_io_system(io, -1, "reg");
|
||||
|
||||
printf("---\n");
|
||||
r_debug_continue (dbg);
|
||||
printf("---\n");
|
||||
|
||||
beach:
|
||||
r_io_free(io);
|
||||
|
@ -40,6 +40,7 @@ struct r_io_t {
|
||||
ut64 seek;
|
||||
char *redirect;
|
||||
/* write mask */
|
||||
void (*printf)(const char *str, ...);
|
||||
int write_mask_fd;
|
||||
ut8 *write_mask_buf;
|
||||
int write_mask_len;
|
||||
@ -79,38 +80,39 @@ struct r_io_list_t {
|
||||
};
|
||||
|
||||
/* io/handle.c */
|
||||
struct r_io_t *r_io_new();
|
||||
R_API struct r_io_t *r_io_new();
|
||||
R_API struct r_io_t *r_io_free(struct r_io_t *io);
|
||||
int r_io_handle_init(struct r_io_t *io);
|
||||
int r_io_handle_open(struct r_io_t *io, int fd, struct r_io_handle_t *plugin);
|
||||
int r_io_handle_close(struct r_io_t *io, int fd, struct r_io_handle_t *plugin);
|
||||
int r_io_handle_generate(struct r_io_t *io);
|
||||
int r_io_handle_add(struct r_io_t *io, struct r_io_handle_t *plugin);
|
||||
int r_io_handle_list(struct r_io_t *io);
|
||||
R_API int r_io_handle_init(struct r_io_t *io);
|
||||
R_API int r_io_handle_open(struct r_io_t *io, int fd, struct r_io_handle_t *plugin);
|
||||
R_API int r_io_handle_close(struct r_io_t *io, int fd, struct r_io_handle_t *plugin);
|
||||
R_API int r_io_handle_generate(struct r_io_t *io);
|
||||
R_API int r_io_handle_add(struct r_io_t *io, struct r_io_handle_t *plugin);
|
||||
R_API int r_io_handle_list(struct r_io_t *io);
|
||||
// TODO: _del ??
|
||||
struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filename);
|
||||
struct r_io_handle_t *r_io_handle_resolve_fd(struct r_io_t *io, int fd);
|
||||
R_API struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filename);
|
||||
R_API struct r_io_handle_t *r_io_handle_resolve_fd(struct r_io_t *io, int fd);
|
||||
|
||||
/* io/io.c */
|
||||
int r_io_init(struct r_io_t *io);
|
||||
int r_io_set_write_mask(struct r_io_t *io, int fd, const ut8 *buf, int len);
|
||||
int r_io_open(struct r_io_t *io, const char *file, int flags, int mode);
|
||||
int r_io_redirect(struct r_io_t *io, const char *file);
|
||||
int r_io_read(struct r_io_t *io, int fd, ut8 *buf, int len);
|
||||
int r_io_write(struct r_io_t *io, int fd, const ut8 *buf, int len);
|
||||
ut64 r_io_lseek(struct r_io_t *io, int fd, ut64 offset, int whence);
|
||||
int r_io_system(struct r_io_t *io, int fd, const char *cmd);
|
||||
int r_io_close(struct r_io_t *io, int fd);
|
||||
ut64 r_io_size(struct r_io_t *io, int fd);
|
||||
R_API int r_io_init(struct r_io_t *io);
|
||||
R_API int r_io_set_write_mask(struct r_io_t *io, int fd, const ut8 *buf, int len);
|
||||
R_API int r_io_open(struct r_io_t *io, const char *file, int flags, int mode);
|
||||
R_API int r_io_redirect(struct r_io_t *io, const char *file);
|
||||
R_API int r_io_read(struct r_io_t *io, int fd, ut8 *buf, int len);
|
||||
R_API ut64 r_io_read_i(struct r_io_t *io, int fd, ut64 addr, int sz, int endian);
|
||||
R_API int r_io_write(struct r_io_t *io, int fd, const ut8 *buf, int len);
|
||||
R_API ut64 r_io_lseek(struct r_io_t *io, int fd, ut64 offset, int whence);
|
||||
R_API int r_io_system(struct r_io_t *io, int fd, const char *cmd);
|
||||
R_API int r_io_close(struct r_io_t *io, int fd);
|
||||
R_API ut64 r_io_size(struct r_io_t *io, int fd);
|
||||
|
||||
/* io/map.c */
|
||||
void r_io_map_init(struct r_io_t *io);
|
||||
int r_io_map_rm(struct r_io_t *io, int fd);
|
||||
int r_io_map_list(struct r_io_t *io);
|
||||
int r_io_map(struct r_io_t *io, const char *file, ut64 offset);
|
||||
int r_io_map_read_at(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len);
|
||||
int r_io_map_read_rest(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len);
|
||||
int r_io_map_write_at(struct r_io_t *io, ut64 off, const ut8 *buf, ut64 len);
|
||||
R_API void r_io_map_init(struct r_io_t *io);
|
||||
R_API int r_io_map_rm(struct r_io_t *io, int fd);
|
||||
R_API int r_io_map_list(struct r_io_t *io);
|
||||
R_API int r_io_map(struct r_io_t *io, const char *file, ut64 offset);
|
||||
R_API int r_io_map_read_at(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len);
|
||||
R_API int r_io_map_read_rest(struct r_io_t *io, ut64 off, ut8 *buf, ut64 len);
|
||||
R_API int r_io_map_write_at(struct r_io_t *io, ut64 off, const ut8 *buf, ut64 len);
|
||||
|
||||
/* sections */
|
||||
struct r_io_section_t {
|
||||
@ -129,17 +131,17 @@ enum {
|
||||
R_IO_SECTION_X = 1,
|
||||
};
|
||||
|
||||
int r_io_section_rm(struct r_io_t *io, int idx);
|
||||
void r_io_section_add(struct r_io_t *io, ut64 from, ut64 to, ut64 vaddr, ut64 physical, int rwx, const char *comment);
|
||||
void r_io_section_set(struct r_io_t *io, ut64 from, ut64 to, ut64 vaddr, ut64 physical, int rwx, const char *comment);
|
||||
void r_io_section_list(struct r_io_t *io, ut64 addr, int rad);
|
||||
struct r_io_section_t * r_io_section_get(struct r_io_t *io, ut64 addr);
|
||||
void r_io_section_list_visual(struct r_io_t *io, ut64 seek, ut64 len);
|
||||
ut64 r_io_section_get_vaddr(struct r_io_t *io, ut64 addr);
|
||||
struct r_io_section_t * r_io_section_get_i(struct r_io_t *io, int idx);
|
||||
void r_io_section_init(struct r_io_t *io);
|
||||
int r_io_section_overlaps(struct r_io_t *io, struct r_io_section_t *s);
|
||||
ut64 r_io_section_align(struct r_io_t *io, ut64 addr, ut64 vaddr, ut64 paddr);
|
||||
R_API int r_io_section_rm(struct r_io_t *io, int idx);
|
||||
R_API void r_io_section_add(struct r_io_t *io, ut64 from, ut64 to, ut64 vaddr, ut64 physical, int rwx, const char *comment);
|
||||
R_API void r_io_section_set(struct r_io_t *io, ut64 from, ut64 to, ut64 vaddr, ut64 physical, int rwx, const char *comment);
|
||||
R_API void r_io_section_list(struct r_io_t *io, ut64 addr, int rad);
|
||||
R_API struct r_io_section_t * r_io_section_get(struct r_io_t *io, ut64 addr);
|
||||
R_API void r_io_section_list_visual(struct r_io_t *io, ut64 seek, ut64 len);
|
||||
R_API ut64 r_io_section_get_vaddr(struct r_io_t *io, ut64 addr);
|
||||
R_API struct r_io_section_t * r_io_section_get_i(struct r_io_t *io, int idx);
|
||||
R_API void r_io_section_init(struct r_io_t *io);
|
||||
R_API int r_io_section_overlaps(struct r_io_t *io, struct r_io_section_t *s);
|
||||
R_API ut64 r_io_section_align(struct r_io_t *io, ut64 addr, ut64 vaddr, ut64 paddr);
|
||||
|
||||
#if 0
|
||||
#define CB_READ int (*cb_read)(struct r_io_t *user, int pid, ut64 addr, ut8 *buf, int len)
|
||||
|
@ -1,12 +1,13 @@
|
||||
NAME=r_io
|
||||
DEPS=r_lib
|
||||
DEPS=r_lib r_util
|
||||
#DEPS=r_util
|
||||
CFLAGS+=-Wall -DCORELIB
|
||||
|
||||
foo: pre libr_io.so tests plugins
|
||||
|
||||
STATIC_OBJS=
|
||||
include ../config.mk
|
||||
include ${STATIC_DEBUG_PLUGINS}
|
||||
include ${STATIC_IO_PLUGINS}
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ)))
|
||||
OBJ=${STATIC_OBJS} io.o handle.o map.o section.o
|
||||
|
||||
|
@ -40,6 +40,10 @@ struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filenam
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &io->io_list) {
|
||||
struct r_io_list_t *il = list_entry(pos, struct r_io_list_t, list);
|
||||
if (il->plugin == NULL)
|
||||
continue;
|
||||
if (il->plugin->handle_open == NULL)
|
||||
continue;
|
||||
if (il->plugin->handle_open(io, filename))
|
||||
return il->plugin;
|
||||
}
|
||||
@ -62,6 +66,7 @@ struct r_io_handle_t *r_io_handle_resolve_fd(struct r_io_t *io, int fd)
|
||||
|
||||
int r_io_handle_generate(struct r_io_t *io)
|
||||
{
|
||||
// TODO: ensure srand here (( implement in r_util a decent random helper
|
||||
return (rand()%666)+1024;
|
||||
}
|
||||
|
||||
@ -107,10 +112,10 @@ int r_io_handle_list(struct r_io_t *io)
|
||||
{
|
||||
int n = 0;
|
||||
struct list_head *pos;
|
||||
printf("IO handlers:\n");
|
||||
io->printf("IO handlers:\n");
|
||||
list_for_each_prev(pos, &io->io_list) {
|
||||
struct r_io_list_t *il = list_entry(pos, struct r_io_list_t, list);
|
||||
printf(" - %s\n", il->plugin->name);
|
||||
io->printf(" - %s\n", il->plugin->name);
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
|
79
libr/io/io.c
79
libr/io/io.c
@ -9,6 +9,7 @@ R_API int r_io_init(struct r_io_t *io)
|
||||
io->write_mask_fd = -1;
|
||||
io->last_align = 0;
|
||||
io->redirect = NULL;
|
||||
io->printf = printf;
|
||||
r_io_map_init(io);
|
||||
r_io_section_init(io);
|
||||
r_io_handle_init(io);
|
||||
@ -53,6 +54,9 @@ R_API int r_io_open(struct r_io_t *io, const char *file, int flags, int mode)
|
||||
}
|
||||
if (fd != -1)
|
||||
r_io_handle_open(io, fd, plugin);
|
||||
if (fd != io->fd)
|
||||
io->plugin = plugin;
|
||||
io->fd = fd;
|
||||
return fd;
|
||||
}
|
||||
break;
|
||||
@ -61,13 +65,23 @@ R_API int r_io_open(struct r_io_t *io, const char *file, int flags, int mode)
|
||||
return open(file, flags, mode);
|
||||
}
|
||||
|
||||
int r_io_read(struct r_io_t *io, int fd, ut8 *buf, int len)
|
||||
R_API int r_io_set_fd(struct r_io_t *io, int fd)
|
||||
{
|
||||
if (fd == -1)
|
||||
fd = io->fd;
|
||||
else if (fd != io->fd) {
|
||||
io->plugin = r_io_handle_resolve_fd(io, fd);
|
||||
io->fd = fd;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
R_API int r_io_read(struct r_io_t *io, int fd, ut8 *buf, int len)
|
||||
{
|
||||
fd = r_io_set_fd(io, fd);
|
||||
if (r_io_map_read_at(io, io->seek, buf, len) != 0)
|
||||
return len;
|
||||
if (fd != io->fd)
|
||||
io->plugin = r_io_handle_resolve_fd(io, fd);
|
||||
if (io->plugin) {
|
||||
if (io->plugin && io->plugin->read) {
|
||||
io->fd = fd;
|
||||
if (io->plugin->read != NULL)
|
||||
return io->plugin->read(io, fd, buf, len);
|
||||
@ -76,13 +90,32 @@ int r_io_read(struct r_io_t *io, int fd, ut8 *buf, int len)
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
|
||||
int r_io_resize(struct r_io_t *io, const char *file, int flags, int mode)
|
||||
R_API ut64 r_io_read_i(struct r_io_t *io, int fd, ut64 addr, int sz, int endian)
|
||||
{
|
||||
ut64 ret = 0LL;
|
||||
int err;
|
||||
char buf[128], dst[128];
|
||||
if (sz > 8) sz = 8;
|
||||
if (sz < 0) sz = 1;
|
||||
err = r_io_lseek(io, fd, addr, R_IO_SEEK_SET);
|
||||
// XXX do something with err
|
||||
err = r_io_read(io, fd, buf, sz);
|
||||
if (err != sz) {
|
||||
perror("Cannot read");
|
||||
} else {
|
||||
r_mem_copyendian(&ret, buf, sz, endian);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_io_resize(struct r_io_t *io, int fd, const char *file, int flags, int mode)
|
||||
{
|
||||
fd = r_io_set_fd(io, fd);
|
||||
#if 0
|
||||
/* TODO */
|
||||
struct r_io_handle_t *plugin = r_io_handle_resolve(file);
|
||||
if (plugin) {
|
||||
int fd = plugin->open(file, flags, mode);
|
||||
if (plugin && io->plugin->resize) {
|
||||
int fd = plugin->resize(file, flags, mode);
|
||||
if (fd != -1)
|
||||
r_io_handle_open(fd, plugin);
|
||||
return fd;
|
||||
@ -91,9 +124,10 @@ int r_io_resize(struct r_io_t *io, const char *file, int flags, int mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int r_io_set_write_mask(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
R_API int r_io_set_write_mask(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
{
|
||||
int ret;
|
||||
fd = r_io_set_fd(io, fd);
|
||||
if (len) {
|
||||
io->write_mask_fd = fd;
|
||||
io->write_mask_buf = (ut8 *)malloc(len);
|
||||
@ -107,9 +141,10 @@ int r_io_set_write_mask(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int r_io_write(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
R_API int r_io_write(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
{
|
||||
int i, ret = -1;
|
||||
fd = r_io_set_fd(io, fd);
|
||||
|
||||
/* apply write binary mask */
|
||||
if (io->write_mask_fd != -1) {
|
||||
@ -126,8 +161,6 @@ int r_io_write(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
|
||||
if (r_io_map_write_at(io, io->seek, buf, len) != 0)
|
||||
return len;
|
||||
if (fd != io->fd)
|
||||
io->plugin = r_io_handle_resolve_fd(io, fd);
|
||||
if (io->plugin) {
|
||||
io->fd = fd;
|
||||
if (io->plugin->write)
|
||||
@ -138,9 +171,11 @@ int r_io_write(struct r_io_t *io, int fd, const ut8 *buf, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ut64 r_io_lseek(struct r_io_t *io, int fd, ut64 offset, int whence)
|
||||
R_API ut64 r_io_lseek(struct r_io_t *io, int fd, ut64 offset, int whence)
|
||||
{
|
||||
int posix_whence = 0;
|
||||
fd = r_io_set_fd(io, fd);
|
||||
|
||||
if (whence == SEEK_SET)
|
||||
offset = r_io_section_align(io, offset, 0, 0);
|
||||
|
||||
@ -160,8 +195,6 @@ ut64 r_io_lseek(struct r_io_t *io, int fd, ut64 offset, int whence)
|
||||
break;
|
||||
}
|
||||
|
||||
if (fd != io->fd)
|
||||
io->plugin = r_io_handle_resolve_fd(io, fd);
|
||||
if (io->plugin && io->plugin->lseek) {
|
||||
io->fd = fd;
|
||||
return io->plugin->lseek(io, fd, offset, whence);
|
||||
@ -170,30 +203,28 @@ ut64 r_io_lseek(struct r_io_t *io, int fd, ut64 offset, int whence)
|
||||
return lseek(fd, offset, posix_whence);
|
||||
}
|
||||
|
||||
ut64 r_io_size(struct r_io_t *io, int fd)
|
||||
R_API ut64 r_io_size(struct r_io_t *io, int fd)
|
||||
{
|
||||
ut64 size, here = r_io_lseek(io, fd, 0, R_IO_SEEK_CUR);
|
||||
ut64 size, here;
|
||||
fd = r_io_set_fd(io, fd);
|
||||
here = r_io_lseek(io, fd, 0, R_IO_SEEK_CUR);
|
||||
size = r_io_lseek(io, fd, 0, R_IO_SEEK_END);
|
||||
r_io_lseek(io, fd, here, R_IO_SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
int r_io_system(struct r_io_t *io, int fd, const char *cmd)
|
||||
R_API int r_io_system(struct r_io_t *io, int fd, const char *cmd)
|
||||
{
|
||||
if (fd != io->fd)
|
||||
io->plugin = r_io_handle_resolve_fd(io, fd);
|
||||
fd = r_io_set_fd(io, fd);
|
||||
if (io->plugin && io->plugin->system) {
|
||||
io->fd = fd;
|
||||
return io->plugin->system(io, fd, cmd);
|
||||
}
|
||||
//return system(cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int r_io_close(struct r_io_t *io, int fd)
|
||||
R_API int r_io_close(struct r_io_t *io, int fd)
|
||||
{
|
||||
if (fd != io->fd)
|
||||
io->plugin = r_io_handle_resolve_fd(io, fd);
|
||||
fd = r_io_set_fd(io, fd);
|
||||
if (io->plugin) {
|
||||
io->fd = fd;
|
||||
r_io_handle_close(io, fd, io->plugin);
|
||||
|
@ -1,4 +1,4 @@
|
||||
CFLAGS=-I../../include -Wall -DWORDSIZE=64 -fPIC -shared -Wl,-R..
|
||||
CFLAGS=-I../../include -Wall -DWORDSIZE=64 -fPIC -shared -Wl,-R.. -DCORELIB
|
||||
|
||||
foo: all
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
include ../../../config-user.mk
|
||||
|
||||
OBJ_DBG=io_dbg.o
|
||||
OBJ_IODBG=io_dbg.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_DBG}
|
||||
TARGET_DBG=io_dbg.so
|
||||
STATIC_OBJ+=${OBJ_IODBG}
|
||||
TARGET_IODBG=io_dbg.so
|
||||
|
||||
ALL_TARGETS+=${TARGET_DBG}
|
||||
ALL_TARGETS+=${TARGET_IODBG}
|
||||
|
||||
${TARGET_DBG}: ${OBJ_DBG}
|
||||
${CC} ${CFLAGS} -o ${TARGET_DBG} ${OBJ_DBG}
|
||||
${TARGET_IODBG}: ${OBJ_IODBG}
|
||||
${CC} ${CFLAGS} -o ${TARGET_IODBG} ${OBJ_IODBG}
|
||||
|
@ -188,40 +188,44 @@ static int __system(struct r_io_t *io, int fd, const char *cmd)
|
||||
#include <sys/user.h>
|
||||
#include <limits.h>
|
||||
/* XXX ugly hack for testing purposes */
|
||||
if (!strcmp(cmd, "pid")) {
|
||||
printf("PID=%d\n", io->fd);
|
||||
return io->fd;
|
||||
} else
|
||||
if (!strcmp(cmd, "reg")) {
|
||||
struct user_regs_struct regs;
|
||||
memset(®s,0, sizeof(regs));
|
||||
// TODO: swap 3-4 args in powerpc
|
||||
ptrace(PTRACE_GETREGS, fd, 0, ®s);
|
||||
#if __WORDSIZE == 64
|
||||
r_cons_printf("f rax @ 0x%08lx\n", regs.rax);
|
||||
r_cons_printf("f rbx @ 0x%08lx\n", regs.rbx);
|
||||
r_cons_printf("f rcx @ 0x%08lx\n", regs.rcx);
|
||||
r_cons_printf("f rdx @ 0x%08lx\n", regs.rdx);
|
||||
r_cons_printf("f r8 @ 0x%08lx\n", regs.r8);
|
||||
r_cons_printf("f r9 @ 0x%08lx\n", regs.r9);
|
||||
r_cons_printf("f r10 @ 0x%08lx\n", regs.r10);
|
||||
r_cons_printf("f r11 @ 0x%08lx\n", regs.r11);
|
||||
r_cons_printf("f r12 @ 0x%08lx\n", regs.r12);
|
||||
r_cons_printf("f r13 @ 0x%08lx\n", regs.r13);
|
||||
r_cons_printf("f r14 @ 0x%08lx\n", regs.r14);
|
||||
r_cons_printf("f r15 @ 0x%08lx\n", regs.r15);
|
||||
r_cons_printf("f rsi @ 0x%08lx\n", regs.rsi);
|
||||
r_cons_printf("f rdi @ 0x%08lx\n", regs.rdi);
|
||||
r_cons_printf("f rsp @ 0x%08lx\n", regs.rsp);
|
||||
r_cons_printf("f rbp @ 0x%08lx\n", regs.rbp);
|
||||
r_cons_printf("f rip @ 0x%08lx\n", regs.rip);
|
||||
io->printf("f rax @ 0x%08lx\n", regs.rax);
|
||||
io->printf("f rbx @ 0x%08lx\n", regs.rbx);
|
||||
io->printf("f rcx @ 0x%08lx\n", regs.rcx);
|
||||
io->printf("f rdx @ 0x%08lx\n", regs.rdx);
|
||||
io->printf("f r8 @ 0x%08lx\n", regs.r8);
|
||||
io->printf("f r9 @ 0x%08lx\n", regs.r9);
|
||||
io->printf("f r10 @ 0x%08lx\n", regs.r10);
|
||||
io->printf("f r11 @ 0x%08lx\n", regs.r11);
|
||||
io->printf("f r12 @ 0x%08lx\n", regs.r12);
|
||||
io->printf("f r13 @ 0x%08lx\n", regs.r13);
|
||||
io->printf("f r14 @ 0x%08lx\n", regs.r14);
|
||||
io->printf("f r15 @ 0x%08lx\n", regs.r15);
|
||||
io->printf("f rsi @ 0x%08lx\n", regs.rsi);
|
||||
io->printf("f rdi @ 0x%08lx\n", regs.rdi);
|
||||
io->printf("f rsp @ 0x%08lx\n", regs.rsp);
|
||||
io->printf("f rbp @ 0x%08lx\n", regs.rbp);
|
||||
io->printf("f rip @ 0x%08lx\n", regs.rip);
|
||||
#else
|
||||
r_cons_printf("f eax @ 0x%08x\n", regs.eax);
|
||||
r_cons_printf("f ebx @ 0x%08x\n", regs.ebx);
|
||||
r_cons_printf("f ecx @ 0x%08x\n", regs.ecx);
|
||||
r_cons_printf("f edx @ 0x%08x\n", regs.edx);
|
||||
r_cons_printf("f eip @ 0x%08x\n", regs.eip);
|
||||
r_cons_printf("f ebp @ 0x%08x\n", regs.ebp);
|
||||
r_cons_printf("f esp @ 0x%08x\n", regs.esp);
|
||||
io->printf("f eax @ 0x%08x\n", regs.eax);
|
||||
io->printf("f ebx @ 0x%08x\n", regs.ebx);
|
||||
io->printf("f ecx @ 0x%08x\n", regs.ecx);
|
||||
io->printf("f edx @ 0x%08x\n", regs.edx);
|
||||
io->printf("f eip @ 0x%08x\n", regs.eip);
|
||||
io->printf("f ebp @ 0x%08x\n", regs.ebp);
|
||||
io->printf("f esp @ 0x%08x\n", regs.esp);
|
||||
#endif
|
||||
} else {
|
||||
printf("Try: '|reg'\n");
|
||||
printf("Try: '|reg' or '|pid'\n");
|
||||
}
|
||||
#endif
|
||||
return R_TRUE;
|
||||
|
@ -1,10 +1,10 @@
|
||||
all: cat read4
|
||||
|
||||
cat:
|
||||
${CC} -I ../../include cat.c ../*.o -o cat
|
||||
${CC} -I ../../include cat.c ../*.o -lr_util -g -o cat
|
||||
|
||||
read4:
|
||||
${CC} -I ../../include read4.c ../*.o -o read4
|
||||
${CC} -I ../../include read4.c ../*.o -lr_util -g -o read4
|
||||
|
||||
clean:
|
||||
rm -f cat read4
|
||||
|
@ -2,17 +2,19 @@
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char buf[4];
|
||||
char buf[1024];
|
||||
int fd;
|
||||
struct r_io_t io;
|
||||
|
||||
r_io_init(&io);
|
||||
|
||||
fd = r_io_open(&io, argc>1?argv[1]:"/etc/issue", R_IO_READ, 0);
|
||||
fd = r_io_open(&io, argc>1?argv[1]:"/bin/ls", R_IO_READ, 0);
|
||||
printf("FD = %d\n", fd);
|
||||
r_io_lseek(&io, fd, 1, R_IO_SEEK_SET);
|
||||
memset(buf, '\0', 4);
|
||||
r_io_read(&io, fd, buf, 4);
|
||||
memset(buf, '\0', sizeof(buf));
|
||||
r_io_read(&io, -1, buf, 4);
|
||||
buf[4]='\0';
|
||||
printf("%llx\n", r_io_read_i(&io, fd, 0LL, 4, 0));
|
||||
|
||||
puts(buf);
|
||||
|
||||
|
@ -24,7 +24,8 @@
|
||||
#endif
|
||||
|
||||
const char *r_lib_types[] = {
|
||||
"io", "dbg", "lang", "asm", "anal", "parse", "bin", "bininfo", NULL
|
||||
"io", "dbg", "lang", "asm", "anal", "parse", "bin", "bininfo",
|
||||
"bp", "syscall", "fastcall", NULL
|
||||
};
|
||||
|
||||
const char *r_lib_types_get(int idx)
|
||||
|
@ -12,7 +12,7 @@
|
||||
(((x) & 0x000000000000ff00LL) << 40) | \
|
||||
(((x) & 0x00000000000000ffLL) << 56))
|
||||
|
||||
ut64 r_num_htonq(ut64 value) {
|
||||
R_API ut64 r_num_htonq(ut64 value) {
|
||||
ut64 ret = value;
|
||||
#if LIL_ENDIAN
|
||||
endian_memcpy_e((ut8*)&ret, (ut8*)&value, 8, 0);
|
||||
@ -20,7 +20,13 @@ ut64 r_num_htonq(ut64 value) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void r_num_minmax_swap(ut64 *a, ut64 *b)
|
||||
R_API int r_num_rand(int max)
|
||||
{
|
||||
// TODO: add srand here for security and so on
|
||||
return rand(max);
|
||||
}
|
||||
|
||||
R_API void r_num_minmax_swap(ut64 *a, ut64 *b)
|
||||
{
|
||||
if (*a>*b) {
|
||||
ut64 tmp = *a;
|
||||
@ -29,7 +35,7 @@ void r_num_minmax_swap(ut64 *a, ut64 *b)
|
||||
}
|
||||
}
|
||||
|
||||
void r_num_minmax_swap_i(int *a, int *b)
|
||||
R_API void r_num_minmax_swap_i(int *a, int *b)
|
||||
{
|
||||
if (*a>*b) {
|
||||
ut64 tmp = *a;
|
||||
@ -38,14 +44,14 @@ void r_num_minmax_swap_i(int *a, int *b)
|
||||
}
|
||||
}
|
||||
|
||||
void r_num_init(struct r_num_t *num)
|
||||
R_API void r_num_init(struct r_num_t *num)
|
||||
{
|
||||
num->callback = NULL;
|
||||
num->userptr = NULL;
|
||||
num->value = 0LL;
|
||||
}
|
||||
|
||||
struct r_num_t *r_num_new(ut64 (*cb)(void*,const char *,int*), void *ptr)
|
||||
R_API struct r_num_t *r_num_new(ut64 (*cb)(void*,const char *,int*), void *ptr)
|
||||
{
|
||||
struct r_num_t *num;
|
||||
num = (struct r_num_t*) malloc(sizeof(struct r_num_t));
|
||||
@ -114,7 +120,7 @@ R_API ut64 r_num_get(struct r_num_t *num, const char *str)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ut64 r_num_op(char op, ut64 a, ut64 b)
|
||||
R_API ut64 r_num_op(char op, ut64 a, ut64 b)
|
||||
{
|
||||
IFDBG printf("r_num_op: %lld %c %lld\n", a,op,b);
|
||||
switch(op) {
|
||||
@ -129,7 +135,7 @@ ut64 r_num_op(char op, ut64 a, ut64 b)
|
||||
return b;
|
||||
}
|
||||
|
||||
static ut64 r_num_math_internal(struct r_num_t *num, char *s)
|
||||
R_API static ut64 r_num_math_internal(struct r_num_t *num, char *s)
|
||||
{
|
||||
ut64 ret = 0LL;
|
||||
char *p = s;
|
||||
@ -156,7 +162,7 @@ static ut64 r_num_math_internal(struct r_num_t *num, char *s)
|
||||
return r_num_op(op, ret, r_num_get(num, p));
|
||||
}
|
||||
|
||||
ut64 r_num_math(struct r_num_t *num, const char *str)
|
||||
R_API ut64 r_num_math(struct r_num_t *num, const char *str)
|
||||
{
|
||||
ut64 ret = 0LL;
|
||||
char op = '+';
|
||||
|
@ -3,29 +3,32 @@
|
||||
[CCode (cheader_filename="r_io.h", cprefix="r_io", lower_case_cprefix="r_io_")]
|
||||
namespace Radare
|
||||
{
|
||||
class Io {
|
||||
public static bool init();
|
||||
public static bool set_write_mask(int fd, uint8 *buf, int len);
|
||||
public static int open(string uri, int flags, int mode);
|
||||
public static int read(int fd, out uint8 *buf, int len);
|
||||
public static int write(int fd, uint8 *buf, int len);
|
||||
public static uint64 lseek(int fd, ut64 addr, int whence);
|
||||
public static int system(int fd, string cmd);
|
||||
public static int close(int fd);
|
||||
public static ut64 size(int fd);
|
||||
[Compact]
|
||||
[CCode (cname="struct r_io_t", free_function="r_io_free", cprefix="r_io_")]
|
||||
public class Io {
|
||||
public Io();
|
||||
public Io* free();
|
||||
public bool init();
|
||||
public bool set_write_mask(int fd, uint8 *buf, int len);
|
||||
public int open(string uri, int flags, int mode);
|
||||
public int read(int fd, out uint8 *buf, int len);
|
||||
public int write(int fd, uint8 *buf, int len);
|
||||
public uint64 lseek(int fd, ut64 addr, int whence);
|
||||
public int system(int fd, string cmd);
|
||||
public int close(int fd);
|
||||
public ut64 size(int fd);
|
||||
}
|
||||
|
||||
[Compact]
|
||||
//[Compact]
|
||||
[CCode (cprefix="r_io_handle_")]
|
||||
public struct Handle {
|
||||
public static bool init();
|
||||
|
||||
}
|
||||
|
||||
[Compact]
|
||||
//[Compact]
|
||||
[CCode (cprefix="r_io_map_")]
|
||||
public struct Map {
|
||||
public static bool init();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,3 +19,7 @@ hg-help:
|
||||
@echo "hg-miss | list interesting missing files"
|
||||
@echo "hg-locdiff | count the difference of LOCs for current commit or FILES"
|
||||
@echo " $$ hg-locdiff \"FILES=Makefile foo.c\""
|
||||
|
||||
hg-ci:
|
||||
@hg diff > /tmp/diff
|
||||
@hg ci
|
||||
|
Loading…
x
Reference in New Issue
Block a user