mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-30 00:20:52 +00:00
* Add the possibility to import/export regs from vm to debugger
* Parse rap:// in a different way, so we can now connect without opening any file. code is hardly simplified
This commit is contained in:
parent
eb0ce8208d
commit
b07bf785be
8
TODO
8
TODO
@ -61,14 +61,12 @@ TODO edu
|
||||
|
||||
TODO pancake
|
||||
------------
|
||||
* implement = command as in r1
|
||||
* implement rap:// upload/download protocol commands (maybe just system() with rsc2+wget?
|
||||
* rap:// system() doesnt works
|
||||
* rap:// server-system does not works and client-system is not proxied
|
||||
* Record register status for each function when running
|
||||
* Import r_vm register values from flags or from r_debug->r_reg
|
||||
- r_vm must use mmu cache when emulating code
|
||||
- use the one from r_io? and deprecate vm->mmu_cache?
|
||||
* implement = command as in r1
|
||||
* implement rap:// upload/download protocol commands (maybe just system() with rsc2+wget?
|
||||
* Record trace of register status for each function when running
|
||||
{
|
||||
* Implement RAnalCall (analyze function arguments, return values, propagate types..)
|
||||
- define number of arguments for given function
|
||||
|
@ -1669,6 +1669,22 @@ static int var_cmd(RCore *core, const char *str) {
|
||||
|
||||
#endif
|
||||
|
||||
// dir=0: import, dir=1: export
|
||||
static void vmimport(RCore *core, int dir) {
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &core->vm->regs) {
|
||||
struct r_vm_reg_t *r = list_entry(pos, struct r_vm_reg_t, list);
|
||||
if (dir) {
|
||||
r_cons_printf ("ave %s=0x%"PFMT64x"\n", r->name, r->value);
|
||||
r_cons_printf ("f vm.%s=0x%"PFMT64x"\n", r->name, r->value);
|
||||
} else {
|
||||
//ut64 value = r_num_math (core->num, r->name);
|
||||
ut64 value = r_debug_reg_get (core->dbg, r->name);
|
||||
r_cons_printf ("ave %s=0x%"PFMT64x"\n", r->name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int cmd_anal(void *data, const char *input) {
|
||||
const char *ptr;
|
||||
RCore *core = (RCore *)data;
|
||||
@ -2024,13 +2040,13 @@ static int cmd_anal(void *data, const char *input) {
|
||||
else r_vm_cmd_reg (core->vm, input+2);
|
||||
break;
|
||||
case 'I':
|
||||
r_vm_import(core->vm, 1);
|
||||
vmimport (core, 1);
|
||||
break;
|
||||
case 'i':
|
||||
r_vm_import(core->vm, 0);
|
||||
vmimport (core, 0);
|
||||
break;
|
||||
case '-':
|
||||
r_vm_init(core->vm, 1);
|
||||
r_vm_init (core->vm, 1);
|
||||
break;
|
||||
case 'o':
|
||||
if (input[2]=='\0')
|
||||
|
@ -95,66 +95,25 @@ static int rap__plugin_open(struct r_io_t *io, const char *pathname) {
|
||||
}
|
||||
|
||||
static int rap__open(struct r_io_t *io, const char *pathname, int flags, int mode) {
|
||||
int i;
|
||||
char *file, *port, *ptr;
|
||||
char buf[1024];
|
||||
char *ptr = buf;
|
||||
int i, p, listenmode;
|
||||
|
||||
strncpy (buf, pathname, 1000);
|
||||
|
||||
if (!memcmp (ptr , "rap://", 6)) {
|
||||
ptr = ptr+6;
|
||||
if (strchr (ptr, '/')) {
|
||||
// connect
|
||||
char *file, *port = strchr(buf+6, ':');
|
||||
if (port == NULL) {
|
||||
eprintf("No port defined.\n");
|
||||
return -1;
|
||||
}
|
||||
port[0] = '\0';
|
||||
|
||||
// file
|
||||
file = strchr (pathname+6,'/');
|
||||
if (file == NULL) {
|
||||
eprintf ("No remote file specified.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rap_fd = r_socket_connect (ptr, atoi (port+1));
|
||||
if (rap_fd>=0)
|
||||
eprintf ("Connected to: %s at port %d\n", ptr, atoi(port+1));
|
||||
else {
|
||||
eprintf ("Cannot connect to '%s' (%d)\n", ptr, atoi(port+1));
|
||||
return -1;
|
||||
}
|
||||
// send
|
||||
buf[0] = RMT_OPEN;
|
||||
buf[1] = flags;
|
||||
buf[2] = (ut8)strlen(file)-1;
|
||||
memcpy (buf+3, file+1, buf[2]);
|
||||
r_socket_write (rap_fd, buf, 3+buf[2]);
|
||||
//eprintf("OPENFILE(%s)\n", file+1);
|
||||
// read
|
||||
eprintf ("waiting... ");
|
||||
read (rap_fd, (ut8*)buf, 5);
|
||||
if (buf[0] != (char)(RMT_OPEN|RMT_REPLY))
|
||||
return -1;
|
||||
|
||||
r_mem_copyendian ((ut8 *)&i, (ut8*)buf+1, 4, endian);
|
||||
if (i>0) eprintf ("ok\n");
|
||||
// ???
|
||||
//io->fd = rap_fd;
|
||||
is_listener = R_FALSE;
|
||||
return rap_fd;
|
||||
} else {
|
||||
// listen
|
||||
char *port = strchr (ptr, ':');
|
||||
int p;
|
||||
if (port == NULL) {
|
||||
eprintf ("No port defined.\n");
|
||||
return -1;
|
||||
}
|
||||
buf[0] = '\0';
|
||||
p = atoi (port+1);
|
||||
strncpy (buf, pathname, sizeof (buf)-1);
|
||||
if (!memcmp (buf, "rap://", 6)) {
|
||||
ptr = buf + 6;
|
||||
if (!(port = strchr (ptr, ':'))) {
|
||||
eprintf ("rap: wrong uri\n");
|
||||
return -1;
|
||||
}
|
||||
listenmode = (*ptr==':');
|
||||
*port = 0;
|
||||
p = atoi (port+1);
|
||||
if ((file = strchr (port+1, '/'))) {
|
||||
*file = 0;
|
||||
file++;
|
||||
}
|
||||
if (listenmode) {
|
||||
if (p<=0) {
|
||||
eprintf ("rap: cannot listen here. Try rap://:9999\n");
|
||||
return -1;
|
||||
@ -163,6 +122,28 @@ static int rap__open(struct r_io_t *io, const char *pathname, int flags, int mod
|
||||
eprintf ("rap: listening at port %d\n", p);
|
||||
is_listener = R_TRUE;
|
||||
return r_socket_listen (p);
|
||||
} else {
|
||||
if ((rap_fd=r_socket_connect (ptr, p))==-1) {
|
||||
eprintf ("Cannot connect to '%s' (%d)\n", ptr, p);
|
||||
return -1;
|
||||
} else eprintf ("Connected to: %s at port %d\n", ptr, p);
|
||||
if (file&&*file) {
|
||||
// send
|
||||
buf[0] = RMT_OPEN;
|
||||
buf[1] = flags;
|
||||
buf[2] = (ut8)strlen(file);
|
||||
memcpy (buf+3, file, buf[2]);
|
||||
r_socket_write (rap_fd, buf, 3+buf[2]);
|
||||
// read
|
||||
eprintf ("waiting... ");
|
||||
read (rap_fd, (ut8*)buf, 5);
|
||||
if (buf[0] != (char)(RMT_OPEN|RMT_REPLY))
|
||||
return -1;
|
||||
r_mem_copyendian ((ut8 *)&i, (ut8*)buf+1, 4, endian);
|
||||
if (i>0) eprintf ("ok\n");
|
||||
}
|
||||
is_listener = R_FALSE;
|
||||
return rap_fd;
|
||||
}
|
||||
}
|
||||
return rap_fd;
|
||||
@ -194,7 +175,7 @@ static int rap__system(RIO *io, int fd, const char *command) {
|
||||
return -1;
|
||||
}
|
||||
if (buf[0] != (RMT_SYSTEM | RMT_REPLY)) {
|
||||
eprintf("Unexpected system reply\n");
|
||||
eprintf ("Unexpected system reply\n");
|
||||
return -1;
|
||||
}
|
||||
r_mem_copyendian ((ut8*)&i, buf+1, 4, !endian);
|
||||
|
@ -1,4 +1,6 @@
|
||||
avo mov $1=$2
|
||||
avo inc $1+=1
|
||||
avo dec $1-=1
|
||||
avo lea $1=$2
|
||||
avo add $1=$1+$2
|
||||
avo sub $1=$1-$2
|
||||
@ -25,6 +27,6 @@ avr+ al int8
|
||||
avr+ ah int8
|
||||
avra al al=eax&0xff al=al&0xff,eax=eax>16,eax=eax<16,eax=eax|al
|
||||
avra ah ah=eax&0xff00,ah=ah>8 eax=eax&0xFFFF00ff,ah=ah<8,eax=eax|ah,ah=ah>8
|
||||
avrr eax
|
||||
avrc eip esp ebp
|
||||
avrf zf
|
||||
avrr eax
|
||||
|
@ -131,11 +131,11 @@ R_API int r_vm_cmd_eval(RVm *vm, const char *cmd) {
|
||||
*next=0;
|
||||
next++;
|
||||
}
|
||||
if (strlen(cmd)>2)
|
||||
if (strlen(cmd)>2 && !memcmp (cmd, "av", 2))
|
||||
r_vm_cmd_reg (vm, cmd+2);
|
||||
cmd = next;
|
||||
} while (next);
|
||||
return 1;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_vm_cmd_reg(struct r_vm_t *vm, const char *_str) {
|
||||
|
12
libr/vm/vm.c
12
libr/vm/vm.c
@ -152,17 +152,19 @@ R_API ut64 r_vm_reg_get(struct r_vm_t *vm, const char *name) {
|
||||
return -1LL;
|
||||
}
|
||||
|
||||
// XXX: deprecate
|
||||
R_API int r_vm_import(struct r_vm_t *vm, int in_vm) {
|
||||
char name[64];
|
||||
struct list_head *pos;
|
||||
|
||||
eprintf ("Importing register values\n");
|
||||
//eprintf ("Importing register values\n");
|
||||
list_for_each(pos, &vm->regs) {
|
||||
struct r_vm_reg_t *r = list_entry(pos, struct r_vm_reg_t, list);
|
||||
snprintf(name, 63, "vm.%s", r->name);
|
||||
if (in_vm) {
|
||||
char name[64];
|
||||
snprintf(name, 63, "vm.%s", r->name);
|
||||
r->value = r_num_get(NULL, name); // XXX doesnt work for eflags and so
|
||||
} else r->value = r_num_get(NULL, r->name); // XXX doesnt work for eflags and so
|
||||
r->value = r_num_get (NULL, name); // XXX doesnt work for eflags and so
|
||||
} else r->value = r_num_get (NULL, r->name); // XXX doesnt work for eflags and so
|
||||
vm->printf ("f %s @ 0x%08llx\n", name, r->value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user