* Fix MZ check() (fixes PE64+ id in r_bin)

* Add io->bits into RIO class
* OSX r_io debug now honors io->bits
  $ r2 -b 32 ls  # debug 32bit ls
  $ r2 -b 64 ls  # debug 64bit ls
This commit is contained in:
pancake 2012-05-30 01:35:41 +02:00
parent 61e6e0a116
commit 637e8c92e5
6 changed files with 57 additions and 9 deletions

2
TODO
View File

@ -7,6 +7,8 @@
====[[ 0.9.1 ]]====
BUGS:
* If [0-9] keybindings in visual point to same address use same reference
* Make r_io happy with RList
* RBinCreate:

View File

@ -177,9 +177,7 @@ static int check(RBinArch *arch) {
if (b[0]=='M' && b[1]=='Z' && arch->buf->length>0x3d) {
idx = (b[0x3c]|(b[0x3d]<<8));
if (arch->buf->length>idx)
if (!memcmp (b, "\x4d\x5a", 2) &&
!memcmp (b+idx, "\x50\x45", 2) &&
!memcmp (b+idx+0x18, "\x0b\x01", 2))
if (!memcmp (b+idx, "\x50\x45", 2))
ret = R_FALSE;
} else ret = R_FALSE;
return ret;

View File

@ -173,6 +173,7 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int mode, ut64 loa
RIODesc *fd;
if (!strcmp (file, "-"))
file = "malloc://512";
r->io->bits = r->assembler->bits; // TODO: we need an api for this
fd = r_io_open (r->io, file, mode, 0644);
if (fd == NULL)
return NULL;

View File

@ -87,6 +87,7 @@ typedef struct r_io_t {
int enforce_rwx;
int enforce_seek;
int cached;
int bits;
int cached_read;
ut64 off;
int debug;

View File

@ -14,6 +14,7 @@ R_API struct r_io_t *r_io_new() {
io->write_mask_fd = -1;
io->redirect = NULL;
io->printf = (void*) printf;
io->bits = (sizeof(void*) == 8)? 64: 32;
io->va = -1;
io->plugin = NULL;
io->raised = -1;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2007-2012 pancake<nopcode.org> */
#include <r_io.h>
#include <r_lib.h>
@ -85,7 +85,7 @@ err_enable:
return err;
}
static int fork_and_ptraceme(const char *cmd) {
static int fork_and_ptraceme(int bits, const char *cmd) {
PROCESS_INFORMATION pi;
STARTUPINFO si = { sizeof (si) };
DEBUG_EVENT de;
@ -164,9 +164,9 @@ err_fork:
}
#else
static int fork_and_ptraceme(const char *cmd) {
static int fork_and_ptraceme(int bits, const char *cmd) {
char **argv;
int ret, status, pid = vfork ();
int ret, status, pid = fork ();
switch (pid) {
case -1:
perror ("fork_and_ptraceme");
@ -188,7 +188,52 @@ static int fork_and_ptraceme(const char *cmd) {
// TODO: Add support to redirect filedescriptors
// TODO: Configure process environment
argv = r_str_argv (cmd, NULL);
#if __APPLE__
#include <spawn.h>
{
posix_spawnattr_t attr = {0};
size_t copied = 1;
cpu_type_t cpu;
int ret;
pid_t p = -1;
posix_spawnattr_init (&attr);
posix_spawnattr_setflags (&attr, POSIX_SPAWN_SETEXEC);
#if __i386__ || __x86_64__
cpu = CPU_TYPE_I386;
if (bits == 64)
cpu |= CPU_ARCH_ABI64;
#else
cpu = CPU_TYPE_ANY;
#endif
posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &copied);
//ret = posix_spawnp (NULL, argv[0], NULL, &attr, argv, NULL);
ret = posix_spawnp (&p, argv[0], NULL, &attr, argv, NULL);
switch (ret) {
case 0:
eprintf ("Success\n");
break;
case 22:
eprintf ("Invalid argument\n");
break;
case 86:
eprintf ("Unsupported architecture\n");
break;
default:
eprintf ("posix_spawnp: unknown error %d\n", ret);
perror ("posix_spawnp");
break;
}
/* only required if no SETEXEC called
if (p != -1)
wait (p);
*/
exit (MAGIC_EXIT); /* error */
}
#else
execvp (argv[0], argv);
#endif
r_str_argv_free (argv);
perror ("fork_and_attach: execv");
@ -212,7 +257,7 @@ static int fork_and_ptraceme(const char *cmd) {
}
#endif
static int __plugin_open(struct r_io_t *io, const char *file) {
static int __plugin_open(RIO *io, const char *file) {
if (!memcmp (file, "dbg://", 6) && file[6])
return R_TRUE;
return R_FALSE;
@ -223,7 +268,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
if (__plugin_open (io, file)) {
int pid = atoi (file+6);
if (pid == 0) {
pid = fork_and_ptraceme (file+6);
pid = fork_and_ptraceme (io->bits, file+6);
if (pid==-1)
return NULL;
#if __WINDOWS__