* Added initial untested support for native gdb debugger mode

- r2 -d gdb://<host>:<port>
  - register maps not yet implemented
  - some basic step/continue should work in cfg.debug=true
  - gdbwrap instance is shared between RIO and RDebug
* RDebug is now arch-sensitive
  - Plugins describe which architectures and register sizes are supported
  - Native debugger is restricted to local CPU
  - Remote debugger (GDB) arch can be specified with -e asm.arch=arm
* Fix some random warnings
* Move R_ASM_ARCH into R_SYS_ARCH
  - Helper functions to translate id to string and string to id
    are now in util/sys.c (r_util)
  - Move all R_SYS_* from r_util to r_types
    - Endianness, OS, CPU and regsize is now 'global'
This commit is contained in:
pancake 2011-05-06 00:59:10 +02:00
parent bae9673ac4
commit 3f2677ab7f
22 changed files with 249 additions and 121 deletions

2
TODO
View File

@ -4,6 +4,8 @@
|__\__|_|__|___/__|__|_\__\___/ |____(_)____/
* x86/32-x86/64 the -e asm.bits should
* memset0 the op before calling the plugin analysis
* Make r_io happy with RList
* We need a 64 bit x86 assembler working!! nasm fails

View File

@ -85,6 +85,7 @@ int main(int argc, char **argv) {
ut64 seek = 0;
char file[1024];
char *cmdfile = NULL;
int is_gdb = R_FALSE;
if (argc<2)
return main_help (1);
@ -148,7 +149,9 @@ int main(int argc, char **argv) {
if (debug) {
r_config_set (r.config, "io.va", "false"); // implicit?
r_config_set (r.config, "cfg.debug", "true");
strcpy (file, "dbg://");
is_gdb = (!memcmp (argv[optind], "gdb://", 6));
if (!is_gdb)
strcpy (file, "dbg://");
if (optind < argc) {
char *ptr = r_file_path (argv[optind]);
if (ptr) {
@ -165,8 +168,13 @@ int main(int argc, char **argv) {
}
fh = r_core_file_open (&r, file, perms, 0LL);
// TODO: move into if (debug) ..
r_debug_use (r.dbg, "native");
if (fh != NULL) {
const char *arch = r_config_get (&r, "asm.arch");
// TODO: move into if (debug) ..
eprintf ("ARCH = %s\n", arch);
if (is_gdb) r_debug_use (r.dbg, "gdb");
else r_debug_use (r.dbg, "native");
}
} else {
if (optind<argc) {
while (optind < argc)
@ -213,7 +221,8 @@ int main(int argc, char **argv) {
int *p = r.file->fd->data;
int pid = *p; // 1st element in debugger's struct must be int
r_core_cmd (&r, "e io.ffio=true", 0);
r_core_cmd (&r, "dh native", 0);
if (is_gdb) r_core_cmd (&r, "dh gdb", 0);
else r_core_cmd (&r, "dh native", 0);
r_core_cmdf (&r, "dpa %d", pid);
r_core_cmdf (&r, "dp=%d", pid);
r_core_cmd (&r, ".dr*", 0);

View File

@ -38,7 +38,7 @@ install-symlink:
mkdir -p ${PFX}/include
mkdir -p ${PFX}/lib/pkgconfig
mkdir -p ${PFX}/lib/radare2/${VERSION}
rm -f ${PFX}/include/libr && ln -fs ${PWD}/include ${PFX}/include/libr
rm -rf ${PFX}/include/libr && ln -fs ${PWD}/include ${PFX}/include/libr
cd ../pkgcfg && for a in *.pc ; do \
if [ -e ${PWD}/../pkgcfg/$${a} ] ; then \
ln -fs ${PWD}/../pkgcfg/$${a} ${PFX}/lib/pkgconfig/$${a} ; \

View File

@ -50,7 +50,7 @@ static int avr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len)
//eprintf("addr: %x inst: %x ofst: %d dest: %x fail:%x\n", op->addr, *ins, ofst, op->jump, op->fail);
} else
if (*ins == 0x9508) { // ret
//eprintf("fucking ret at addr: %x\n", addr);
//eprintf("ret at addr: %x\n", addr);
op->type = R_ANAL_OP_TYPE_RET;
op->eob = R_TRUE;
//op->stackptr =

View File

@ -316,7 +316,7 @@ R_API int r_core_init(RCore *core) {
core->flags = r_flag_new ();
core->dbg = r_debug_new (R_TRUE);
core->dbg->anal = core->anal; // XXX: dupped instance.. can cause lost pointerz
r_debug_use (core->dbg, "native");
//r_debug_use (core->dbg, "native");
r_reg_arena_push (core->dbg->reg); // create a 2 level register state stack
// core->dbg->anal->reg = core->anal->reg; // XXX: dupped instance.. can cause lost pointerz
core->sign->printf = r_cons_printf;

View File

@ -27,6 +27,9 @@ static int r_debug_recoil(RDebug *dbg) {
R_API RDebug *r_debug_new(int hard) {
RDebug *dbg = R_NEW (RDebug);
if (dbg) {
// R_SYS_ARCH
dbg->arch = 0; // 0 is native by default
dbg->bits = R_SYS_BITS;
dbg->anal = NULL;
dbg->pid = -1;
dbg->tid = -1;
@ -59,10 +62,10 @@ R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg) {
return NULL;
}
R_API int r_debug_attach(struct r_debug_t *dbg, int pid) {
R_API int r_debug_attach(RDebug *dbg, int pid) {
int ret = R_FALSE;
if (dbg && dbg->h && dbg->h->attach) {
ret = dbg->h->attach (pid);
ret = dbg->h->attach (dbg, pid);
if (ret != -1) {
eprintf ("pid = %d tid = %d\n", pid, ret);
// TODO: get arch and set io pid
@ -77,6 +80,17 @@ R_API int r_debug_attach(struct r_debug_t *dbg, int pid) {
return ret;
}
R_API int r_debug_set_arch(RDebug *dbg, int arch, int bits) {
if (dbg && dbg->h) {
if (arch & dbg->h->arch) {
eprintf ("arch supported by debug backend\n");
return R_TRUE;
}
}
eprintf ("arch not supported by debug backend (%s)\n", dbg->h->name);
return R_FALSE;
}
/*
* Save 4096 bytes from %esp
* TODO: Add support for reverse stack architectures

View File

@ -4,6 +4,16 @@
#include <r_debug.h>
#include "libgdbwrap/include/gdbwrapper.h"
/* XXX: hacky copypasta from io/p/io_gdb */
typedef struct {
RSocket *fd;
gdbwrap_t *desc;
} RIOGdb;
#define RIOGDB_FD(x) (((RIOGdb*)(x))->fd)
#define RIOGDB_DESC(x) (((RIOGdb*)(x->data))->desc)
#define RIOGDB_IS_VALID(x) (x && x->plugin==&r_io_plugin_gdb && x->data)
#define NUM_REGS 28
/* TODO: The IO stuff must be communicated with the r_dbg */
/* a transplant sometimes requires to change the IO */
/* so, for here, we need r_io_plugin_gdb */
@ -16,23 +26,9 @@ static int r_debug_gdb_step(RDebug *dbg) {
}
static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
#if 0
struct r_debug_regset *r = NULL;
/* only for x86-32 */
gdbwrap_gdbreg32 *reg = gdbwrap_readgenreg(desc);
r = r_debug_regset_new(9);
r_debug_regset_set(r, 0, "eax", reg->eax);
r_debug_regset_set(r, 1, "ebx", reg->ebx);
r_debug_regset_set(r, 2, "ecx", reg->ecx);
r_debug_regset_set(r, 3, "edx", reg->edx);
r_debug_regset_set(r, 4, "esi", reg->esi);
r_debug_regset_set(r, 5, "edi", reg->edi);
r_debug_regset_set(r, 6, "esp", reg->esp);
r_debug_regset_set(r, 7, "ebp", reg->ebp);
r_debug_regset_set(r, 8, "eip", reg->eip);
return r;
#endif
return NULL;
ut8 *p = gdbwrap_readgenreg (desc);
memcpy (buf, p, size);
return size;
}
static int r_debug_gdb_reg_write(int pid, int tid, int type, const ut8 *buf, int size) {
@ -50,29 +46,73 @@ static int r_debug_gdb_wait(int pid) {
return R_TRUE;
}
static int r_debug_gdb_attach(int pid) {
static int r_debug_gdb_attach(RDebug *dbg, int pid) {
// XXX TODO PID must be a socket here !!1
desc = gdbwrap_init (pid , 9, 4); //Only x86
RIODesc *d = dbg->iob.io->fd;
if (d && d->plugin && d->plugin->name) {
if (!strcmp ("gdb", d->plugin->name)) {
RIOGdb *g = d->data;
desc = g->desc;
//desc = gdbwrap_init (pid , 9, 4); //Only x86
eprintf ("SUCCESS: gdb attach with inferior gdb rio worked\n");
} else {
eprintf ("ERROR: Underlaying IO descriptor is not a GDB one..\n");
}
}
return R_TRUE;
}
static int r_debug_gdb_detach(int pid) {
// XXX TODO PID must be a socket here !!1
close (pid);
// close (pid);
return R_TRUE;
}
static const char *r_debug_gdb_reg_profile(RDebug *dbg) {
switch (dbg->arch) {
case R_SYS_ARCH_X86:
return strdup (
"=pc eip\n"
"gpr eip .32 0 0\n"
"gpr eax .32 8 0\n"
);
case R_SYS_ARCH_ARM:
return strdup (
"=pc r15\n"
"gpr eip .32 0 0\n"
"gpr eax .32 8 0\n"
);
case R_SYS_ARCH_SH:
return strdup (
"=pc r15\n"
"gpr eip .32 0 0\n"
"gpr eax .32 8 0\n"
);
}
return NULL;
}
struct r_debug_plugin_t r_dbg_plugin_gdb = {
.name = "gdb",
.arch = R_ASM_ARCH_X86, // TODO: add bitmask for ARM and SH4
/* TODO: Add support for more architectures here */
.arch = R_SYS_ARCH_X86 | R_SYS_ARCH_ARM | R_SYS_ARCH_SH,
.bits = R_SYS_BITS_32,
.init = NULL,
.step = r_debug_gdb_step,
.cont = r_debug_gdb_continue,
.attach = &r_debug_gdb_attach,
.detach = &r_debug_gdb_detach,
.wait = &r_debug_gdb_wait,
.pids = NULL,
.tids = NULL,
.threads = NULL,
.kill = NULL,
.frames = NULL,
.map_get = NULL,
.breakpoint = NULL,
.reg_read = &r_debug_gdb_reg_read,
.reg_write = &r_debug_gdb_reg_write,
.reg_profile = (void *)r_debug_gdb_reg_profile,
//.bp_write = &r_debug_gdb_bp_write,
//.bp_read = &r_debug_gdb_bp_read,
};

View File

@ -212,7 +212,7 @@ static int r_debug_native_step(RDebug *dbg) {
}
// return thread id
static int r_debug_native_attach(int pid) {
static int r_debug_native_attach(RDebug *dbg, int pid) {
int ret = -1;
#if __WINDOWS__
HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
@ -273,7 +273,7 @@ static int r_debug_native_continue(RDebug *dbg, int pid, int tid, int sig) {
return 0;
#elif __APPLE__
ut64 rip = r_debug_reg_get (dbg, "pc");
ptrace (PT_CONTINUE, pid, rip, 0); // 0 = send no signal TODO !! implement somewhere else
ptrace (PT_CONTINUE, pid, (void*)(size_t)rip, 0); // 0 = send no signal TODO !! implement somewhere else
return 0;
#elif __BSD__
ut64 pc = r_debug_reg_get (dbg, "pc");
@ -1547,7 +1547,7 @@ struct r_debug_plugin_t r_debug_plugin_native = {
.threads = &r_debug_native_threads,
.wait = &r_debug_native_wait,
.kill = &r_debug_native_kill,
.frames = &r_debug_native_frames,
.frames = &r_debug_native_frames, // rename to backtrace ?
.reg_profile = (void *)r_debug_native_reg_profile,
.reg_read = &r_debug_native_reg_read,
.reg_write = (void *)&r_debug_native_reg_write,

View File

@ -48,6 +48,15 @@ R_API int r_debug_use(RDebug *dbg, const char *str) {
r_reg_set_profile_string (dbg->reg, p);
}
}
if (dbg->h && dbg->anal && dbg->anal->cur) {
const char *arch = dbg->anal->cur->name;
int archid = r_sys_arch_id (dbg->anal->cur->name);
if (dbg->h->arch & archid) {
dbg->arch = archid;
eprintf ("DebugUse: backend forced to use %s\n", arch);
} else eprintf ("DebugUse: arch not supported for this backend (%s) (%s)\n",
arch, dbg->h->name);
}
return (dbg->h != NULL);
}

View File

@ -829,7 +829,7 @@ iterate (const char *filename,
info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
grub_free (node);
return c->hook?c->hook (filename, &info, c->closure):NULL;
return (c->hook != NULL)? c->hook (filename, &info, c->closure): 0;
}
static grub_err_t

View File

@ -420,7 +420,7 @@ call_hook (grub_uint64_t ino, char *filename,
return c->hook (filename,
grub_xfs_mode_to_filetype (fdiro->inode.mode),
fdiro, c->closure);
return NULL;
return 0;
}
static int

View File

@ -9,22 +9,20 @@
#define R_ASM_BUFSIZE 1024
enum {
R_ASM_ARCH_NONE = 0,
R_ASM_ARCH_X86 = 0x1,
R_ASM_ARCH_ARM = 0x2,
R_ASM_ARCH_PPC = 0x4,
R_ASM_ARCH_M68K = 0x8,
R_ASM_ARCH_JAVA = 0x10,
R_ASM_ARCH_MIPS = 0x20,
R_ASM_ARCH_SPARC = 0x40,
R_ASM_ARCH_CSR = 0x80,
R_ASM_ARCH_MSIL = 0x100,
R_ASM_ARCH_OBJD = 0x200,
R_ASM_ARCH_BF = 0x400,
R_ASM_ARCH_SH = 0x800
};
/* backward compatibility */
#define R_ASM_ARCH_NONE R_SYS_ARCH_NONE
#define R_ASM_ARCH_X86 R_SYS_ARCH_X86
#define R_ASM_ARCH_ARM R_SYS_ARCH_ARM
#define R_ASM_ARCH_PPC R_SYS_ARCH_PPC
#define R_ASM_ARCH_M68K R_SYS_ARCH_M68K
#define R_ASM_ARCH_JAVA R_SYS_ARCH_JAVA
#define R_ASM_ARCH_MIPS R_SYS_ARCH_MIPS
#define R_ASM_ARCH_SPARC R_SYS_ARCH_SPARC
#define R_ASM_ARCH_CSR R_SYS_ARCH_CSR
#define R_ASM_ARCH_MSIL R_SYS_ARCH_MSIL
#define R_ASM_ARCH_OBJD R_SYS_ARCH_OBJD
#define R_ASM_ARCH_BF R_SYS_ARCH_BF
#define R_ASM_ARCH_SH R_SYS_ARCH_SH
enum {
R_ASM_SYNTAX_NONE = 0,

View File

@ -101,6 +101,8 @@ typedef struct r_debug_tracepoint_t {
} RDebugTracepoint;
typedef struct r_debug_t {
int arch;
int bits; /// XXX: MUST SET ///
int pid; /* selected process id */
int tid; /* selected thread id */
int swstep; /* steps with software traps */
@ -145,7 +147,7 @@ typedef struct r_debug_plugin_t {
ut64 arch;
/* life */
int (*startv)(int argc, char **argv);
int (*attach)(int pid);
int (*attach)(RDebug *dbg, int pid);
int (*detach)(int pid);
int (*select)(int pid, int tid);
RList *(*threads)(int pid);

View File

@ -149,7 +149,7 @@ typedef int (*RIOWriteAt)(RIO *io, ut64 addr, const ut8 *buf, int size);
typedef struct r_io_bind_t {
int init;
RIO *io;
RIOSetFd set_fd;
RIOSetFd set_fd; // XXX : this is conceptually broken with the new RIODesc foo
RIOReadAt read_at;
RIOWriteAt write_at;
} RIOBind;

View File

@ -128,6 +128,71 @@ typedef void (*PrintfCallback)(const char *str, ...);
#define PFMT64o "llo"
#endif
/* arch */
#if __i386__
#define R_SYS_ARCH "x86"
#define R_SYS_BITS R_SYS_BITS_32
#elif __x86_64__
#define R_SYS_ARCH "x86"
#define R_SYS_BITS (R_SYS_BITS_32 | R_SYS_BITS_64)
#elif __POWERPC__
#define R_SYS_ARCH "ppc"
#define R_SYS_BITS R_SYS_BITS_32
#elif __arm__
#define R_SYS_ARCH "arm"
#define R_SYS_BITS R_SYS_BITS_32
#elif __sparc__
#define R_SYS_ARCH "sparc"
#define R_SYS_BITS R_SYS_BITS_32
#elif __mips__
#define R_SYS_ARCH "mips"
#define R_SYS_BITS R_SYS_BITS_32
#else
#define R_SYS_ARCH "unknown"
#define R_SYS_BITS R_SYS_BITS_32
#endif
enum {
R_SYS_ARCH_NONE = 0,
R_SYS_ARCH_X86 = 0x1,
R_SYS_ARCH_ARM = 0x2,
R_SYS_ARCH_PPC = 0x4,
R_SYS_ARCH_M68K = 0x8,
R_SYS_ARCH_JAVA = 0x10,
R_SYS_ARCH_MIPS = 0x20,
R_SYS_ARCH_SPARC = 0x40,
R_SYS_ARCH_CSR = 0x80,
R_SYS_ARCH_MSIL = 0x100,
R_SYS_ARCH_OBJD = 0x200,
R_SYS_ARCH_BF = 0x400,
R_SYS_ARCH_SH = 0x800,
R_SYS_ARCH_AVR = 0x1000
};
/* os */
#if __APPLE__
#define R_SYS_OS "darwin"
#elif __linux__
#define R_SYS_OS "linux"
#elif __WIN32__ || __CYGWIN__ || MINGW32
#define R_SYS_OS "windows"
#elif __NetBSD__
#define R_SYS_OS "netbsd"
#elif __OpenBSD__
#define R_SYS_OS "openbsd"
#elif __FreeBSD__ || __FreeBSD_kernel__
#define R_SYS_OS "freebsd"
#else
#define R_SYS_OS "unknown"
#endif
/* endian */
#if LIL_ENDIAN
#define R_SYS_ENDIAN "little"
#else
#define R_SYS_ENDIAN "big"
#endif
#endif
// Usage: R_DEFINE_OBJECT(r_asm);

View File

@ -152,55 +152,6 @@ typedef struct r_mixed_t {
R_API RMmap *r_file_mmap (const char *file, boolt rw);
R_API void r_file_mmap_free (RMmap *m);
/* arch */
// TODO: This must deprecate DEFAULT_ARCH??
#if __i386__
#define R_SYS_ARCH "x86"
#define R_SYS_BITS R_SYS_BITS_32
#elif __x86_64__
#define R_SYS_ARCH "x86"
#define R_SYS_BITS (R_SYS_BITS_32 | R_SYS_BITS_64)
#elif __POWERPC__
#define R_SYS_ARCH "ppc"
#define R_SYS_BITS R_SYS_BITS_32
#elif __arm__
#define R_SYS_ARCH "arm"
#define R_SYS_BITS R_SYS_BITS_32
#elif __sparc__
#define R_SYS_ARCH "sparc"
#define R_SYS_BITS R_SYS_BITS_32
#elif __mips__
#define R_SYS_ARCH "mips"
#define R_SYS_BITS R_SYS_BITS_32
#else
#define R_SYS_ARCH "unknown"
#define R_SYS_BITS R_SYS_BITS_32
#endif
/* os */
#if __APPLE__
#define R_SYS_OS "darwin"
#elif __linux__
#define R_SYS_OS "linux"
#elif __WIN32__ || __CYGWIN__ || MINGW32
#define R_SYS_OS "windows"
#elif __NetBSD__
#define R_SYS_OS "netbsd"
#elif __OpenBSD__
#define R_SYS_OS "openbsd"
#elif __FreeBSD__ || __FreeBSD_kernel__
#define R_SYS_OS "freebsd"
#else
#define R_SYS_OS "unknown"
#endif
/* endian */
#if LIL_ENDIAN
#define R_SYS_ENDIAN "little"
#else
#define R_SYS_ENDIAN "big"
#endif
// TODO: find better names and write vapis
#define ut8p_b(x) ((x)[0])
#define ut8p_bw(x) ((x)[0]|((x)[1]<<8))
@ -349,6 +300,8 @@ R_API int r_file_mkstemp(const char *prefix, char **oname);
R_API const char *r_file_tmpdir();
R_API ut64 r_sys_now();
R_API const char *r_sys_arch_str(int arch);
R_API int r_sys_arch_id(const char *arch);
R_API RList *r_sys_dir(const char *path);
R_API void r_sys_perror(const char *fun);
#if __WINDOWS__

View File

@ -231,7 +231,7 @@ static int __plugin_open(struct r_io_t *io, const char *file) {
return R_FALSE;
}
static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) {
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
char uri[1024];
if (__plugin_open (io, file)) {
int pid = atoi (file+6);

View File

@ -38,7 +38,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
if (r_socket_connect_tcp (_fd, host, port+1)) {
riog = R_NEW (RIOGdb);
riog->fd = _fd;
riog->desc = gdbwrap_init (_fd->fd,NUM_REGS,4);
riog->desc = gdbwrap_init (_fd->fd, NUM_REGS, 4);
return r_io_desc_new (&r_io_plugin_gdb, _fd->fd, file, rw, mode, riog);
}
}
@ -77,20 +77,20 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) {
if(!strcmp(cmd,"regs")){
int i;
gdbwrap_readgenreg (RIOGDB_DESC (fd));
for(i=0;i<NUM_REGS;i++){
ut32 v = gdbwrap_getreg(RIOGDB_DESC(fd),i) & 0xFFFFFFFF;
printf("Reg #%d - %#x\n", i, v);
for (i=0; i<NUM_REGS; i++){
ut32 v = gdbwrap_getreg (RIOGDB_DESC(fd),i) & 0xFFFFFFFF;
printf ("Reg #%d - %#x\n", i, v);
}
} else if ( !strcmp(cmd,"stepi") ){
gdbwrap_stepi(RIOGDB_DESC(fd)) ;
} else if ( !strcmp(cmd,"cont") ){
gdbwrap_continue(RIOGDB_DESC(fd));
} else if ( !strncmp(cmd,"bp",2) && r_str_word_count(cmd)==2 ){
char *saddr = strrchr(cmd,' '); //Assuming only spaces as separator, get last space
if(saddr){
} else if ( !strcmp(cmd,"stepi") ) {
gdbwrap_stepi (RIOGDB_DESC (fd));
} else if ( !strcmp(cmd,"cont") ) {
gdbwrap_continue (RIOGDB_DESC (fd));
} else if (!strncmp (cmd,"bp", 2) && r_str_word_count (cmd)==2) {
char *saddr = strrchr (cmd, ' '); //Assuming only spaces as separator, get last space
if (saddr) {
int addr;
r_hex_str2bin(saddr,(unsigned char *)&addr); //TODO handle endianness local machine
gdbwrap_simplesetbp( RIOGDB_DESC(fd), addr);
r_hex_str2bin (saddr, (ut8*)&addr); //TODO handle endianness local machine
gdbwrap_simplesetbp (RIOGDB_DESC (fd), addr);
}
}
return -1;

View File

@ -72,10 +72,10 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) {
}
static int mach_write_at(RIOMach *riom, const void *buff, int len, ut64 addr) {
kern_return_t err;
task_t task = riom->task;
#if 0
/* get paVM_PROT_EXECUTEge perms */
kern_return_t err;
int ret, _basic64[VM_REGION_BASIC_INFO_COUNT_64];
vm_region_basic_info_64_t basic64 = (vm_region_basic_info_64_t)_basic64;
mach_msg_type_number_t infocnt;
@ -83,7 +83,6 @@ const int pagesize = 4096;
vm_offset_t addrbase;
mach_port_t objname;
vm_size_t size = pagesize;
#if 0
eprintf (" 0x%llx\n", addr);
infocnt = VM_REGION_BASIC_INFO_COUNT_64;

View File

@ -93,7 +93,10 @@ static const struct {
* modified by the user.
*/
static RHashTableEntry* r_hashtable_search(RHashTable *ht, ut32 hash) {
ut32 double_hash, hash_address = hash % ht->size;
ut32 double_hash, hash_address;
if (ht == NULL)
return NULL;
hash_address = hash % ht->size;
do {
RHashTableEntry *entry = ht->table + hash_address;
if (entry_is_free (entry))

View File

@ -335,3 +335,37 @@ R_API void r_sys_perror(const char *fun) {
LocalFree (lpDisplayBuf);
#endif
}
R_API int r_sys_arch_id(const char *arch) {
if (!strcmp (arch, "x86")) return R_SYS_ARCH_X86;
if (!strcmp (arch, "arm")) return R_SYS_ARCH_ARM;
if (!strcmp (arch, "ppc")) return R_SYS_ARCH_PPC;
if (!strcmp (arch, "m68k")) return R_SYS_ARCH_M68K;
if (!strcmp (arch, "java")) return R_SYS_ARCH_JAVA;
if (!strcmp (arch, "mips")) return R_SYS_ARCH_MIPS;
if (!strcmp (arch, "sparc")) return R_SYS_ARCH_SPARC;
if (!strcmp (arch, "csr")) return R_SYS_ARCH_CSR;
if (!strcmp (arch, "msil")) return R_SYS_ARCH_MSIL;
if (!strcmp (arch, "objd")) return R_SYS_ARCH_OBJD;
if (!strcmp (arch, "bf")) return R_SYS_ARCH_BF;
if (!strcmp (arch, "sh")) return R_SYS_ARCH_SH;
if (!strcmp (arch, "avr")) return R_SYS_ARCH_AVR;
return 0;
}
R_API const char *r_sys_arch_str(int arch) {
if (arch & R_SYS_ARCH_X86) return "x86";
if (arch & R_SYS_ARCH_ARM) return "arm";
if (arch & R_SYS_ARCH_PPC) return "ppc";
if (arch & R_SYS_ARCH_M68K) return "m68k";
if (arch & R_SYS_ARCH_JAVA) return "java";
if (arch & R_SYS_ARCH_MIPS) return "mips";
if (arch & R_SYS_ARCH_SPARC) return "sparc";
if (arch & R_SYS_ARCH_CSR) return "csr";
if (arch & R_SYS_ARCH_MSIL) return "msil";
if (arch & R_SYS_ARCH_OBJD) return "objd";
if (arch & R_SYS_ARCH_BF) return "bf";
if (arch & R_SYS_ARCH_SH) return "sh";
if (arch & R_SYS_ARCH_AVR) return "avr";
return "none";
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2010 pancake<@nopcode.org> */
/* radare - LGPL - Copyright 2010-2011 pancake<@nopcode.org> */
/* this vapi is broken as shit... we need to rename some stuff here ..
if we can just avoid to use cname CCode attribute... */