Fix fcn lines in disasm, minor fix in meta

Initial work to fix linux32 debugger on linux64
This commit is contained in:
pancake 2012-12-06 03:11:40 +01:00
parent 475372ec2c
commit 83da070d44
9 changed files with 77 additions and 47 deletions

View File

@ -1,6 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 */
/* nibble<.ds@gmail.com> */
/* pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 - pancake, nibble */
#include <r_anal.h>
#include <r_util.h>

View File

@ -105,7 +105,7 @@ static void cmd_debug_pid(RCore *core, const char *input) {
if (pid > 0) {
eprintf ("Sending signal '%d' to pid '%d'\n", sig, pid);
r_debug_kill (core->dbg, R_FALSE, sig);
} else eprintf ("Invalid arguments\n");
} else eprintf ("cmd_debug_pid: Invalid arguments (%s)\n", input);
break;
case 'n':
eprintf ("TODO: debug_fork: %d\n", r_debug_fork (core->dbg));

View File

@ -122,6 +122,7 @@ static int cmd_meta(void *data, const char *input) {
int n = 0, type = input[0];
t = strdup (input+2);
if (atoi (t)>0) {
RFlagItem *fi;
p = strchr (t, ' ');
if (p) {
*p = '\0';
@ -133,14 +134,14 @@ static int cmd_meta(void *data, const char *input) {
strncpy (name, t, sizeof (name)-1);
r_core_read_at (core, addr, (ut8*)name, sizeof (name));
break;
default: {
RFlagItem *fi = r_flag_get_i (core->flags, addr);
if (fi) strncpy (name, fi->name, sizeof (name)-1);
default:
fi = r_flag_get_i (core->flags, addr);
if (fi) {
strncpy (name, fi->name, sizeof (name)-1);
//else sprintf (name, "ptr_%08"PFMT64x"", addr);
else {
eprintf ("Invalid arguments\n");
return 1;
}
//} else {
// eprintf ("meta: Invalid arguments (%s)\n", input);
// return 1;
}
}
n = atoi (input+1);

View File

@ -115,7 +115,6 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
if (r_config_get_i (core->config, "asm.lineswide"))
linesopts |= R_ANAL_REFLINE_TYPE_WIDE;
lines = 0;
toro:
// uhm... is this necesary? imho can be removed
r_asm_set_pc (core->assembler, addr+idx);
@ -196,7 +195,8 @@ toro:
RAnalFunction *fun = r_anal_fcn_find (
core->anal, refi->addr,
R_ANAL_FCN_TYPE_NULL);
r_cons_printf ("%s%s", pre, refline);
r_cons_printf ("%c %s", ((f&&f->type==R_ANAL_FCN_TYPE_FCN)
&&f->addr==at)?' ':'|',refline);
if (show_color)
r_cons_printf (Color_TURQOISE"; %s XREF 0x%08"PFMT64x" (%s)"Color_RESET"\n",
refi->type==R_ANAL_REF_TYPE_CODE?"CODE (JMP)":
@ -365,7 +365,9 @@ toro:
/* XXX: This is really cpu consuming.. need to be fixed */
if (show_functions) {
if (f) {
//eprintf ("fun 0x%llx 0x%llx\n", at, f->addr+f->size-analop.length);
pre = " ";
if (f->addr == at) {
char *sign = r_anal_fcn_to_string (core->anal, f);
if (f->type == R_ANAL_FCN_TYPE_LOC) {
@ -383,13 +385,17 @@ toro:
free (sign);
pre = "| ";
stackptr = 0;
} else if (f->addr+f->size-analop.length== at) {
} else if (f->addr+f->size-analop.length == at) {
r_cons_printf ("\\ ");
} else if (at > f->addr && at < f->addr+f->size-1) {
r_cons_printf ("| ");
pre = "| ";
} else f = NULL;
} else r_cons_printf (" ");
} else {
f = NULL;
}
if (at == f->addr+f->size-analop.length) // HACK
pre = "\\ ";
} else pre = " "; //r_cons_printf (" ");
}
if (show_flags) {
flag = r_flag_get_i (core->flags, at);
@ -399,7 +405,7 @@ toro:
if (show_offset)
r_cons_printf ("; -------- ");
if (show_functions)
r_cons_printf ("%s:\n%s", flag->name, f?"| ":" ");
r_cons_printf ("%s:\n%s", flag->name, f?pre:"");
else r_cons_printf ("%s:\n", flag->name);
}
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 - pancake */
#include "r_core.h"

View File

@ -1,4 +1,4 @@
/* radare - Copyright 2009-2012 pancake+nibble */
/* radare - Copyright 2009-2012 - pancake, nibble */
#include "r_core.h"
#include "r_socket.h"

View File

@ -1,17 +1,7 @@
/* radare - LGPL - Copyright 2009-2011 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 - pancake */
#include "r_db.h"
#include "r_util.h"
/*
struct r_db_table_t *table = \
r_db_table_new("cities", "ziu", "name people postal");
*/
#if 0
/* r_fmt ??? */
int sizes[256];
sizes['i'] = 4;
#endif
struct r_db_table_t *r_db_table_new(const char *name, const char *fmt, const char *fields) {
int i;
@ -20,7 +10,7 @@ struct r_db_table_t *r_db_table_new(const char *name, const char *fmt, const cha
table->args = strdup (fields);
table->nelems = r_str_word_set0 (table->args);
if (table->nelems != strlen (fmt)) {
fprintf(stderr, "Invalid arguments\n");
eprintf ("r_db_table_new: Invalid arguments\n");
/* XXX: refactor */
free (table->args);
free (table);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 pancake */
#include <r_userconf.h>
#include <r_debug.h>
@ -169,6 +169,20 @@ ut32[16]
#include <sys/types.h>
#include <sys/wait.h>
#include <limits.h>
struct user_regs_struct_x86_64 {
ut64 r15; ut64 r14; ut64 r13; ut64 r12; ut64 rbp; ut64 rbx; ut64 r11;
ut64 r10; ut64 r9; ut64 r8; ut64 rax; ut64 rcx; ut64 rdx; ut64 rsi;
ut64 rdi; ut64 orig_rax; ut64 rip; ut64 cs; ut64 eflags; ut64 rsp;
ut64 ss; ut64 fs_base; ut64 gs_base; ut64 ds; ut64 es; ut64 fs; ut64 gs;
};
struct user_regs_struct_x86_32 {
ut32 ebx; ut32 ecx; ut32 edx; ut32 esi; ut32 edi; ut32 ebp; ut32 eax;
ut32 xds; ut32 xes; ut32 xfs; ut32 xgs; ut32 orig_eax; ut32 eip;
ut32 xcs; ut32 eflags; ut32 esp; ut32 xss;
};
#ifdef __ANDROID__
// #if __arm__
# define R_DEBUG_REG_T struct pt_regs
@ -1456,10 +1470,10 @@ eprintf ("++ EFL = 0x%08x %d\n", ctx.EFlags, r_offsetof (CONTEXT, EFlags));
/* TODO: allow to choose the thread */
gp_count = R_DEBUG_STATE_SZ;
if (tid <0 || tid>=inferior_thread_count) {
eprintf ("Tid out of range %d\n", inferior_thread_count);
return R_FALSE;
}
if (tid <0 || tid>=inferior_thread_count) {
eprintf ("Tid out of range %d\n", inferior_thread_count);
return R_FALSE;
}
// XXX: kinda spaguetti coz multi-arch
#if __i386__ || __x86_64__
if (dbg->bits== R_SYS_BITS_64) {
@ -1529,7 +1543,27 @@ if (tid <0 || tid>=inferior_thread_count) {
ret = ptrace (PTRACE_GETREGS, pid, &regs, NULL);
#else
/* linux/arm/x86/x64 */
ret = ptrace (PTRACE_GETREGS, pid, NULL, &regs);
if (dbg->bits & R_SYS_BITS_32) {
// XXX. this is wrong
#if 0
struct user_regs_struct_x86_64 r64;
ret = ptrace (PTRACE_GETREGS, pid, NULL, &r64);
eprintf (" EIP : 0x%x\n", r32.eip);
eprintf (" ESP : 0x%x\n", r32.esp);
#endif
#if 0
int i=0;
unsigned char *p = &r64;;
for(i=0;i< sizeof (r64); i++) {
printf ("%02x ", p[i]);
}
printf ("\n");
#endif
ret = ptrace (PTRACE_GETREGS, pid, NULL, &regs);
} else {
ret = ptrace (PTRACE_GETREGS, pid, NULL, &regs);
}
#endif
if (ret != 0)
return R_FALSE;
@ -1568,7 +1602,7 @@ static int r_debug_native_reg_write(RDebug *dbg, int type, const ut8* buf, int s
}
}
#else
return R_FALSE;
return R_FALSE;
#endif
#else
eprintf ("TODO: add support for write DRX registers\n");
@ -1629,14 +1663,14 @@ return R_FALSE;
R_DEBUG_STATE_T, (thread_state_t) regs, &gp_count);
#endif
//if (thread_set_state (inferior_threads[0], R_DEBUG_STATE_T, (thread_state_t) regs, gp_count) != KERN_SUCCESS) {
if (ret != KERN_SUCCESS) {
eprintf ("debug_setregs: Failed to set thread %d %d.error (%x). (%s)\n",
(int)pid, pid_to_task (pid), (int)ret, MACH_ERROR_STRING (ret));
perror ("thread_set_state");
return R_FALSE;
}
} else eprintf ("There are no threads!\n");
return sizeof (R_DEBUG_REG_T);
if (ret != KERN_SUCCESS) {
eprintf ("debug_setregs: Failed to set thread %d %d.error (%x). (%s)\n",
(int)pid, pid_to_task (pid), (int)ret, MACH_ERROR_STRING (ret));
perror ("thread_set_state");
return R_FALSE;
}
} else eprintf ("There are no threads!\n");
return sizeof (R_DEBUG_REG_T);
#else
#warning r_debug_native_reg_write not implemented
#endif

View File

@ -215,7 +215,7 @@ static int fork_and_ptraceme(int bits, const char *cmd) {
eprintf ("Success\n");
break;
case 22:
eprintf ("Invalid argument\n");
eprintf ("posix_spawnp: Invalid argument\n");
break;
case 86:
eprintf ("Unsupported architecture\n");
@ -268,6 +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) {
// TODO: get bits from ELF?
pid = fork_and_ptraceme (io->bits, file+6);
if (pid==-1)
return NULL;