mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-08 02:53:29 +00:00
* apply rudi_s patch fixing multiple bugs
- Fix uninitialized variables and other GCC warnings - Remove unused variables, fix invalid heap ops - ?p print error if VA is not - Fix invalid write in r_io_cache_read(). * add support for 'mov reg, [addr]' in x86.nz[32]
This commit is contained in:
parent
1947f0dece
commit
65d1dddfd1
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2010-2011 pancake<@nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2010-2012 pancake<@nopcode.org> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -892,7 +892,7 @@ void opcode_0101(dis_buffer_t *dbuf, u_short opc)
|
||||
*/
|
||||
void opcode_branch(dis_buffer_t *dbuf, u_short opc)
|
||||
{
|
||||
int disp, sz;
|
||||
int disp;
|
||||
|
||||
if (IS_INST(BRA,opc))
|
||||
addstr(dbuf, "bra");
|
||||
@ -907,20 +907,17 @@ void opcode_branch(dis_buffer_t *dbuf, u_short opc)
|
||||
/* 16-bit signed displacement */
|
||||
disp = read16(dbuf->val + 1);
|
||||
dbuf->used++;
|
||||
sz = SIZE_WORD;
|
||||
addchar('w');
|
||||
} else if (disp == 0xff) {
|
||||
/* 32-bit signed displacement */
|
||||
disp = read32(dbuf->val + 1);
|
||||
dbuf->used += 2;
|
||||
sz = SIZE_LONG;
|
||||
addchar('l');
|
||||
} else {
|
||||
/* 8-bit signed displacement in opcode. */
|
||||
/* Needs to be sign-extended... */
|
||||
if (ISBITSET(disp,7))
|
||||
disp -= 256;
|
||||
sz = SIZE_BYTE;
|
||||
addchar('b');
|
||||
}
|
||||
addchar('\t');
|
||||
@ -3021,7 +3018,8 @@ void get_fpustdGEN(dis_buffer_t *dbuf, u_short ext, const char *name)
|
||||
void print_disp(dis_buffer_t *dbuf, int disp, int sz, int rel, int dd)
|
||||
{
|
||||
char *symname;
|
||||
u_long nv,diff;
|
||||
u_long nv = 0;
|
||||
u_long diff;
|
||||
|
||||
if (dbuf == NULL)
|
||||
return;
|
||||
|
@ -254,7 +254,6 @@ UBYTE OpcodeLen(ULONG p, const ut8 *Opcodes) {
|
||||
ULONG ParseOpcodes(ULONG adr, ut8 *Opcodes, int len) {
|
||||
int i;
|
||||
ULONG next;
|
||||
Boolean label = R_TRUE;
|
||||
|
||||
i = OpcodeLen (adr, Opcodes); // Länge vom Opcode ermitteln
|
||||
if (len<i)
|
||||
@ -313,11 +312,9 @@ ULONG ParseOpcodes(ULONG adr, ut8 *Opcodes, int len) {
|
||||
break;
|
||||
case 0xC3: // JP ????
|
||||
next = (Opcodes[adr+2]<<8) + Opcodes[adr+1];
|
||||
label = R_TRUE;
|
||||
break;
|
||||
case 0x18: // JR ??
|
||||
next = adr + 2 + (BYTE)Opcodes[adr+1];
|
||||
label = R_TRUE;
|
||||
break;
|
||||
case 0xCD: // CALL ????
|
||||
ParseOpcodes ((Opcodes[adr+2]<<8) + Opcodes[adr+1], Opcodes, len);
|
||||
|
@ -159,7 +159,7 @@ static void skipword (const char **pos, char delimiter) {
|
||||
|
||||
/* find any of the list[] entries as the start of ptr and return index */
|
||||
static int indx (const char **ptr, const char **list, int error, const char **expr) {
|
||||
int i, l;
|
||||
int i;
|
||||
*ptr = delspc (*ptr);
|
||||
if (!**ptr) {
|
||||
if (error) {
|
||||
@ -175,7 +175,6 @@ static int indx (const char **ptr, const char **list, int error, const char **ex
|
||||
int had_expr = 0;
|
||||
if (!list[i][0])
|
||||
continue;
|
||||
l = strlen (list[i]);
|
||||
while (*check) {
|
||||
if (*check == ' ') {
|
||||
input = delspc (input);
|
||||
@ -901,7 +900,6 @@ static int assemble (const char *str, unsigned char *_obuf) {
|
||||
/* continue assembling until the last input file is done */
|
||||
//for (file = 0; file < infilecount; ++file)
|
||||
do {
|
||||
int file_ended = 0;
|
||||
int cmd, cont = 1;
|
||||
if (havelist) {
|
||||
if (buffer && buffer[0] != 0) {
|
||||
@ -1587,7 +1585,6 @@ static int assemble (const char *str, unsigned char *_obuf) {
|
||||
}
|
||||
break;
|
||||
case END:
|
||||
file_ended = 1;
|
||||
break;
|
||||
case ORG:
|
||||
addr = rd_expr (&ptr, '\0', NULL, sp, 1) & 0xffff;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "m68k/m68k_disasm/m68k_disasm.h"
|
||||
|
||||
static int disassemble(RAsm *a, RAsmOp *aop, ut8 *buf, ut64 len) {
|
||||
static int disassemble(RAsm *a, RAsmOp *aop, const ut8 *buf, ut64 len) {
|
||||
m68k_word bof[4];
|
||||
m68k_word iaddr = (m68k_word)a->pc;
|
||||
char opcode[256];
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* * Copyright (C) 2008-2011 - pancake <nopcode.org> */
|
||||
/* Copyright (C) 2008-2012 - pancake <nopcode.org> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -20,12 +20,12 @@ BLA:
|
||||
static int jop (ut64 addr, ut8 *data, ut8 a, ut8 b, const char *arg) {
|
||||
ut32 dst32;
|
||||
int l = 0;
|
||||
int d, num = getnum (arg);
|
||||
int num = getnum (arg);
|
||||
if (!isnum (arg))
|
||||
return 0;
|
||||
dst32 = num - addr;
|
||||
d = num - addr; // obey sign
|
||||
#if 0
|
||||
d = num - addr; // obey sign
|
||||
if (d>-127 && d<127) {
|
||||
d-=2;
|
||||
data[l++] = a;
|
||||
@ -577,7 +577,7 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
if (r==4) { //ESP
|
||||
data[l++] = getreg (arg)<<3 | r | 0x40;
|
||||
data[l++] = 0x24;
|
||||
} else if (r== 5) { // EBP
|
||||
} else if (r==5) { // EBP
|
||||
data[l++] = getreg (arg)<<3 | r | 0x40;
|
||||
data[l++] = 0;
|
||||
} else data[l++] = getreg (arg) | r | 0x40;
|
||||
@ -590,7 +590,18 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
} else if (r== 5) { // EBP
|
||||
data[l++] = getreg (arg)<<3 | r | 0x40;
|
||||
data[l++] = 0;
|
||||
} else data[l++] = getreg (arg)<<3 | r;
|
||||
} else {
|
||||
if (r == 0xff) {
|
||||
ut32 n;
|
||||
ut8 *N = (ut8*)&n;
|
||||
data[l++] = getreg (arg)<<3|5;
|
||||
n = getnum (arg2);
|
||||
data[l++] = N[0];
|
||||
data[l++] = N[1];
|
||||
data[l++] = N[2];
|
||||
data[l++] = N[3];
|
||||
} else data[l++] = getreg (arg)<<3 | r;
|
||||
}
|
||||
}
|
||||
}
|
||||
return l;
|
||||
|
@ -49,7 +49,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
|
||||
ut64 at, toff = core->offset;
|
||||
ut8 *buf;
|
||||
char *tok, *tokens[1024], *code = NULL, *ptr;
|
||||
int idx, tidx, ret, len;
|
||||
int idx, tidx = 0, ret, len;
|
||||
int tokcount, matchcount;
|
||||
|
||||
if (!*input)
|
||||
|
@ -1188,15 +1188,19 @@ static int cmd_help(void *data, const char *input) {
|
||||
char *p;
|
||||
ut64 b = 0;
|
||||
ut32 r = UT32_MAX;
|
||||
if (input[1])
|
||||
if (input[1]) {
|
||||
strncpy (out, input+(input[1]==' '? 2: 1), sizeof (out)-1);
|
||||
else *out = 0;
|
||||
p = strchr (out+1, ' ');
|
||||
if (p) {
|
||||
*p = 0;
|
||||
b = (ut32)r_num_math (core->num, out);
|
||||
r = (ut32)r_num_math (core->num, p+1)-b;
|
||||
} else r = (ut32)r_num_math (core->num, out);
|
||||
p = strchr (out+1, ' ');
|
||||
if (p) {
|
||||
*p = 0;
|
||||
b = (ut32)r_num_math (core->num, out);
|
||||
r = (ut32)r_num_math (core->num, p+1)-b;
|
||||
} else {
|
||||
r = (ut32)r_num_math (core->num, out);
|
||||
}
|
||||
} else {
|
||||
r = 0LL;
|
||||
}
|
||||
if (r == 0)
|
||||
r = UT32_MAX>>1;
|
||||
core->num->value = (ut64) (b + r_num_rand (r));
|
||||
@ -1248,7 +1252,7 @@ static int cmd_help(void *data, const char *input) {
|
||||
r_cons_printf ("%s\n", out);
|
||||
} else eprintf ("Usage: \"?b value bitstring\"\n");
|
||||
free (p);
|
||||
} else eprintf ("Whitespace expected after '?b'\n");
|
||||
} else eprintf ("Whitespace expected after '?f'\n");
|
||||
break;
|
||||
case ' ':
|
||||
{
|
||||
@ -1347,12 +1351,15 @@ static int cmd_help(void *data, const char *input) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'p': {
|
||||
case 'p':
|
||||
if (core->io->va) {
|
||||
// physical address
|
||||
ut64 o, n = (input[0] && input[1])?
|
||||
r_num_math (core->num, input+2): core->offset;
|
||||
o = r_io_section_vaddr_to_offset (core->io, n);
|
||||
r_cons_printf ("0x%08"PFMT64x"\n", o);
|
||||
} else {
|
||||
eprintf ("Virtual addresses not enabled!\n");
|
||||
}
|
||||
break;
|
||||
case 'S': {
|
||||
@ -3814,14 +3821,12 @@ static int cmd_search(void *data, const char *input) {
|
||||
} else
|
||||
if (!strcmp (mode, "file")) {
|
||||
if (core->io->va) {
|
||||
ut64 vaddr = 0LL;
|
||||
RListIter *iter;
|
||||
RIOSection *s;
|
||||
from = core->offset;
|
||||
to = from;
|
||||
r_list_foreach (core->io->sections, iter, s) {
|
||||
if ((s->vaddr+s->size) > to && from>=s->vaddr) {
|
||||
vaddr = s->vaddr;
|
||||
to = s->vaddr+s->size;
|
||||
}
|
||||
}
|
||||
@ -5010,7 +5015,8 @@ static int r_core_cmd_subst(RCore *core, char *cmd) {
|
||||
for (i=0; str[i]; i++)
|
||||
if (str[i]=='\n')
|
||||
str[i]=' ';
|
||||
cmd = r_str_concat (strdup (cmd), r_str_concat (str, ptr2+1));
|
||||
str = r_str_concat (str, ptr2+1);
|
||||
cmd = r_str_concat (strdup (cmd), str);
|
||||
ret = r_core_cmd_subst (core, cmd);
|
||||
free (cmd);
|
||||
free (str);
|
||||
@ -5660,7 +5666,7 @@ static int cmd_debug(void *data, const char *input) {
|
||||
{
|
||||
int n = 0;
|
||||
int t = core->dbg->trace->enabled;
|
||||
RGraphNode *gn;
|
||||
/*RGraphNode *gn;*/
|
||||
core->dbg->trace->enabled = 0;
|
||||
r_graph_plant (core->dbg->graph);
|
||||
r_cons_break (static_debug_stop, core->dbg);
|
||||
@ -5701,7 +5707,7 @@ static int cmd_debug(void *data, const char *input) {
|
||||
// TODO: step into and check return address if correct
|
||||
// if not correct we are hijacking the control flow (exploit!)
|
||||
#endif
|
||||
gn = r_graph_pop (core->dbg->graph);
|
||||
/*gn =*/ r_graph_pop (core->dbg->graph);
|
||||
#if 0
|
||||
if (addr != gn->addr) {
|
||||
eprintf ("Oops. invalid return address 0x%08"PFMT64x
|
||||
|
@ -480,7 +480,7 @@ R_API int r_core_block_size(RCore *core, int bsize) {
|
||||
if (bsize == core->blocksize)
|
||||
return R_FALSE;
|
||||
if (bsize<1)
|
||||
bsize = R_TRUE;
|
||||
bsize = 1;
|
||||
else if (bsize> R_CORE_BLOCKSIZE_MAX)
|
||||
bsize = R_CORE_BLOCKSIZE_MAX;
|
||||
else ret = R_TRUE;
|
||||
@ -562,7 +562,7 @@ R_API RAnalOp *r_core_op_anal(RCore *core, ut64 addr) {
|
||||
|
||||
// TODO: move into core/io/rap? */
|
||||
R_API int r_core_serve(RCore *core, RIODesc *file) {
|
||||
ut8 cmd, flg, *ptr, buf[1024];
|
||||
ut8 cmd, flg, *ptr = NULL, buf[1024];
|
||||
int i, j, pipefd;
|
||||
ut64 x;
|
||||
RSocket *c, *fd;
|
||||
|
@ -38,7 +38,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l
|
||||
int counter = 0;
|
||||
int middle = 0;
|
||||
char str[128], strsub[128];
|
||||
char *line = NULL, *comment, *opstr, *osl = NULL; // old source line
|
||||
char *line = NULL, *comment = NULL, *opstr, *osl = NULL; // old source line
|
||||
char *refline = NULL;
|
||||
RAsmOp asmop;
|
||||
RAnalOp analop = {0};
|
||||
|
@ -19,7 +19,7 @@ static int marks_init = 0;
|
||||
static ut64 marks[UT8_MAX+1];
|
||||
|
||||
static int r_core_visual_hud(RCore *core) {
|
||||
char *res;
|
||||
char *res = NULL;
|
||||
char *p = 0;
|
||||
r_cons_show_cursor (R_TRUE);
|
||||
char *homehud = r_str_home("/.radare2/hud");
|
||||
|
@ -250,7 +250,7 @@ R_API int r_core_visual_comments (RCore *core) {
|
||||
int i, ch, option = 0;
|
||||
int format = 0;
|
||||
int found = 0;
|
||||
ut64 from, size;
|
||||
ut64 from = 0, size = 0;
|
||||
RListIter *iter;
|
||||
RAnalFcn *fcn;
|
||||
RMetaItem *d;
|
||||
|
@ -5,7 +5,7 @@
|
||||
static RBuffer *build (REgg *egg) {
|
||||
RBuffer *buf, *sc;
|
||||
ut8 aux[32], nkey;
|
||||
int l, i;
|
||||
int i;
|
||||
char *key = r_egg_option_get (egg, "key");
|
||||
|
||||
nkey = r_num_math (NULL, key);
|
||||
@ -56,7 +56,6 @@ static RBuffer *build (REgg *egg) {
|
||||
aux[5] = 0x5b; // pop ebx
|
||||
r_buf_set_bytes (buf, aux, 6);
|
||||
|
||||
l = buf->length;
|
||||
r_buf_append_bytes (buf, stub, STUBLEN);
|
||||
|
||||
for (i = 0; i<sc->length; i++) {
|
||||
|
@ -99,7 +99,7 @@ R_API int r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
RIOCache *c;
|
||||
|
||||
r_list_foreach (io->cache, iter, c) {
|
||||
if (r_range_overlap (addr, addr+len, c->from, c->to, &ret)) {
|
||||
if (r_range_overlap (addr, addr+len-1, c->from, c->to, &ret)) {
|
||||
if (ret>0) {
|
||||
da = ret;
|
||||
db = 0;
|
||||
|
@ -115,7 +115,7 @@ static RIODesc *ewf__open(RIO *io, const char *pathname, int rw, int mode) {
|
||||
filenames[0] = pathname + 6;
|
||||
filenames[1] = NULL;
|
||||
}
|
||||
ewf_h = libewf_open (&filenames, 1, rw?
|
||||
ewf_h = libewf_open ((char * const *)filenames, 1, rw?
|
||||
LIBEWF_OPEN_READ_WRITE: LIBEWF_OPEN_READ);
|
||||
if (ewf_h == NULL)
|
||||
return NULL;
|
||||
|
@ -38,7 +38,7 @@ typedef int ptrace_word; // int ptrace(int request, pid_t pid, caddr_t addr, i
|
||||
#else
|
||||
#define debug_read_raw(x,y) ptrace(PTRACE_PEEKTEXT, x, y, 0)
|
||||
#define debug_write_raw(x,y,z) ptrace(PTRACE_POKEDATA, x, y, z)
|
||||
typedef void* ptrace_word; // long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
|
||||
typedef long int ptrace_word; // long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
|
||||
#endif
|
||||
|
||||
static int debug_os_read_at(int pid, ut32 *buf, int sz, ut64 addr) {
|
||||
@ -68,7 +68,7 @@ static int ptrace_write_at(int pid, const ut8 *pbuf, int sz, ut64 addr) {
|
||||
ptrace_word *buf = (ptrace_word*)pbuf;
|
||||
ut32 words = sz / sizeof (ptrace_word);
|
||||
ut32 last = sz % sizeof (ptrace_word);
|
||||
ut32 x, *at = (ptrace_word*)(size_t)addr;
|
||||
ut32 x, *at = (ut32 *)(size_t)addr;
|
||||
ptrace_word lr;
|
||||
if (sz<1 || addr==UT64_MAX)
|
||||
return -1;
|
||||
|
@ -64,7 +64,7 @@ R_API void r_magic_setflags(RMagic* m, int f) {
|
||||
}
|
||||
|
||||
R_API int r_magic_load(RMagic* m, const char *f) {
|
||||
magic_load (m, f);
|
||||
return magic_load (m, f);
|
||||
}
|
||||
|
||||
R_API int r_magic_compile(RMagic* m, const char *x) {
|
||||
@ -76,7 +76,7 @@ R_API int r_magic_check(RMagic* m, const char *x) {
|
||||
}
|
||||
|
||||
R_API int r_magic_errno(RMagic* m) {
|
||||
return magic_error (m);
|
||||
return magic_errno (m);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -22,10 +22,10 @@ typedef struct {
|
||||
typedef enum {
|
||||
NAME, NUMBER, END, INC, DEC,
|
||||
PLUS='+', MINUS='-', MUL='*', DIV='/',
|
||||
//XOR='^', OR='|', AND='&',
|
||||
PRINT=';', ASSIGN='=', LP='(', RP=')'
|
||||
} Token;
|
||||
|
||||
|
||||
/* accessors */
|
||||
static inline NumValue Nset(ut64 v) { NumValue n; n.d = (double)v; n.n = v; return n; }
|
||||
static inline NumValue Nsetf(double v) { NumValue n; n.d = v; n.n = (ut64)v; return n; }
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> */
|
||||
|
||||
#include "r_util.h"
|
||||
|
||||
@ -38,6 +38,7 @@ R_API double r_prof_end(struct r_prof_t *p) {
|
||||
int sign;
|
||||
gettimeofday (&end, NULL);
|
||||
sign = timeval_subtract (&diff, begin, &end);
|
||||
p->result = R_ABS (((double)(diff.tv_sec) + ((double)diff.tv_usec / 1000000.)));
|
||||
return R_ABS(sign);
|
||||
p->result = R_ABS (((double)(diff.tv_sec)
|
||||
+ ((double)diff.tv_usec / 1000000.)));
|
||||
return R_ABS (sign);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user