Fix some bugs appeeared during the training course

Fix segfault in "rasm2 'xor e'"
Fix overflow in 'ad@esp' when long strings are analyzed
Fix null pointer check in r_num
This commit is contained in:
pancake 2013-03-07 13:08:05 +01:00
parent 7e7be66fca
commit 5f4623ed46
7 changed files with 34 additions and 22 deletions

View File

@ -13,6 +13,8 @@ Broken stuff to fixe before release
0.9.4
=====
* implementar cmovz
* rafind2 : add support for unicode/widestring search
* e dbg.hwbp para evitar q use hwbps
* .dr- # documented... but not working
* libr/debug/p/drx.c <- not used .. debug must have a hw reg api for drx and gpio

View File

@ -62,29 +62,31 @@ static int is_bin(const ut8 *buf) {
// XXX: optimize by removing all strlens here
R_API char *r_anal_data_to_string (RAnalData *d) {
int i;
char *line = malloc (128);
sprintf (line, "0x%08"PFMT64x" ", d->addr);
for (i=0;i<d->len; i++)
sprintf (line+strlen (line), "%02x", d->buf[i]);
int i, idx;
int mallocsz = 256;
ut32 n32 = (ut32)d->ptr;
char *line = malloc (mallocsz);
snprintf (line, mallocsz, "0x%08"PFMT64x" ", d->addr);
for (i=0, idx = strlen (line); i<d->len; i++) {
snprintf (line+idx, mallocsz-idx, "%02x", d->buf[i]);
idx += 2;
}
strcat (line, " ");
if ((mallocsz-idx)>12)
switch (d->type) {
case R_ANAL_DATA_TYPE_STRING:
// XXX: overflow
sprintf (line+strlen (line), "string \"%s\"", d->str);
snprintf (line+idx, mallocsz-idx, "string \"%s\"", d->str);
idx = strlen (line);
break;
case R_ANAL_DATA_TYPE_WIDE_STRING:
strcat (line, "wide string");
break;
case R_ANAL_DATA_TYPE_NUMBER:
{
ut32 n32 = (ut32)d->ptr;
strcat (line, "number ");
if (n32 == d->ptr)
sprintf (line+strlen (line), " %d 0x%x", n32, n32);
else sprintf (line+strlen (line), " %"PFMT64d" 0x%"PFMT64x,
snprintf (line+idx, mallocsz-idx, " %d 0x%x", n32, n32);
else snprintf (line+idx, mallocsz-idx, " %"PFMT64d" 0x%"PFMT64x,
d->ptr, d->ptr);
}
break;
case R_ANAL_DATA_TYPE_POINTER:
strcat (line, "pointer ");
@ -120,7 +122,7 @@ R_API RAnalData *r_anal_data_new_string (ut64 addr, const char *p, int len, int
ad->str = malloc (len+1);
memcpy (ad->str, p, len);
ad->str[len] = 0;
ad->buf = malloc (len);
ad->buf = malloc (len+1);
memcpy (ad->buf, ad->str, len+1);
ad->len = len+1; // string length + \x00
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2008-2012 - pancake */
/* Copyright (C) 2008-2013 - pancake */
#include <stdio.h>
#include <string.h>
@ -62,7 +62,7 @@ static int bits8 (const char *p) {
static ut8 getreg(const char *str) {
int i;
const char *regs[] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", NULL };
const char *regs16[] = { "al", "ah", "cl", "ch", "dl", "dh", "bl", "bh" };
const char *regs16[] = { "al", "ah", "cl", "ch", "dl", "dh", "bl", "bh", NULL };
const char *regs64[] = { "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", NULL };
if (!str)
return 0xff;

View File

@ -10,6 +10,7 @@ typedef struct {
ut8 buf[128];
RAsmCode *acode;
int blocklen;
ut64 off;
} RCoreVisualAsm;
static int readline_callback(void *_a, const char *str) {
@ -38,23 +39,25 @@ static int readline_callback(void *_a, const char *str) {
strcpy (a->codebuf, a->blockbuf);
memcpy (a->codebuf, a->acode->buf_hex, xlen);
}
r_core_cmdf (a->core, "pd 7@b:%s", a->codebuf);
r_core_cmdf (a->core, "pd 7@b:%s @0x%"PFMT64x, a->codebuf, a->off);
}
r_cons_flush ();
return 1;
}
R_API void r_core_visual_asm(RCore *core) {
R_API void r_core_visual_asm(RCore *core, ut64 off) {
RCoreVisualAsm cva = {0};
cva.core = core;
cva.off = off;
r_io_read_at (core->io, core->offset, cva.buf, sizeof (cva.buf));
r_io_read_at (core->io, off, cva.buf, sizeof (cva.buf));
cva.blocklen = r_hex_bin2str (cva.buf, sizeof (cva.buf), cva.blockbuf);
r_line_readline_cb (readline_callback, &cva);
if (cva.acode && cva.acode->len>0)
if (r_cons_yesno ('y', "Save changes? (Y/n)"))
r_core_cmdf (core, "wx %s", cva.acode->buf_hex);
r_core_cmdf (core, "wx %s @ 0x%"PFMT64x,
cva.acode->buf_hex, off);
r_asm_code_free (cva.acode);
}

View File

@ -275,7 +275,11 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
r_core_seek_previous (core, r_config_get (core->config, "scr.nkey"));
break;
case 'A':
r_core_visual_asm (core);
{ int oc = curset;
curset = 0;
r_core_visual_asm (core, curset? core->offset+cursor : core->offset);
curset = oc;
}
break;
case 'a':
if (core->file && !(core->file->rwx & 2)) {

View File

@ -179,7 +179,7 @@ R_API int r_core_block_size(RCore *core, int bsize);
R_API int r_core_read_at(RCore *core, ut64 addr, ut8 *buf, int size);
R_API int r_core_visual(RCore *core, const char *input);
R_API int r_core_visual_cmd(RCore *core, int ch);
R_API void r_core_visual_asm(RCore *core);
R_API void r_core_visual_asm(RCore *core, ut64 addr);
R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback cb);
R_API int r_core_serve(RCore *core, RIODesc *fd);

View File

@ -76,6 +76,7 @@ R_API ut64 r_num_get(RNum *num, const char *str) {
char lch, len;
ut64 ret = 0LL;
if (!str) return 0;
for (; *str==' '; ) str++;
/* resolve string with an external callback */