mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-22 05:37:06 +00:00
Lot of bugfixes in r_asm, x86 assembler and ragg2 -x
- Thanks Ripe for reporting - Handle $pc in r_asm assemble - New ops for x86.nz: sar, shl, shr, shl, rcr, rcl, ror, rol - Fix disassembler indentation for functions - Fix memory align issue in r_sys_run()
This commit is contained in:
parent
5ef42734ab
commit
6ad7ed7925
@ -421,6 +421,13 @@ R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf) {
|
||||
r_str_replace_char (lbuf, ';', '#');
|
||||
}
|
||||
}
|
||||
// XXX: ops like mov eax, $pc+33 fail coz '+' is nov alid number!!!
|
||||
// XXX: must be handled here to be global.. and not arch-specific
|
||||
{
|
||||
char val[32];
|
||||
snprintf (val, sizeof (val), "0x%"PFMT64x, a->pc);
|
||||
lbuf = r_str_replace (lbuf, "$pc", val, 1);
|
||||
}
|
||||
|
||||
if (strchr (lbuf, ':'))
|
||||
labels = 1;
|
||||
|
@ -21,7 +21,26 @@ BLA:
|
||||
static int getnum(RAsm *a, const char *s) {
|
||||
if (!s) return 0;
|
||||
if (*s=='$') s++;
|
||||
return r_num_get (a->num, s);
|
||||
return r_num_math (a->num, s);
|
||||
}
|
||||
|
||||
static ut8 getshop(const char *s) {
|
||||
int i;
|
||||
const char *ops = \
|
||||
"sar\xf8" \
|
||||
"shl\xf0" \
|
||||
"shr\xe8" \
|
||||
"shl\xe0" \
|
||||
"rcr\xd8" \
|
||||
"rcl\xd0" \
|
||||
"ror\xc8" \
|
||||
"rol\xc0";
|
||||
if (strlen (s<3))
|
||||
return 0;
|
||||
for (i=0; i<strlen (ops); i+=4)
|
||||
if (!memcmp (s, ops+i, 3))
|
||||
return (ut8)ops[3];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jop (RAsm *a, ut8 *data, ut8 x, ut8 b, const char *arg) {
|
||||
@ -85,7 +104,7 @@ static int isnum(RAsm *a, const char *str) {
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
ut64 offset = a->pc;
|
||||
ut8 *data = ao->buf;
|
||||
ut8 t, *data = ao->buf;
|
||||
char *arg, op[128];
|
||||
int l = 0;
|
||||
|
||||
@ -596,15 +615,20 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
|
||||
}
|
||||
} else eprintf ("Invalid args for lea?\n");
|
||||
return l;
|
||||
} else if (!strcmp (op, "sar")) {
|
||||
} else if ((t=getshop (op))) { // sar, shl, shr, rcr, rcl, ror, rol
|
||||
if (arg[1]=='l') { // 8bits
|
||||
data[l++] = 0xc0;
|
||||
data[l++] = t | getreg (arg);
|
||||
data[l++] = getnum (a, arg2);
|
||||
} else
|
||||
if (*arg=='r') { // 64bits
|
||||
data[l++] = 0x48;
|
||||
data[l++] = 0xc1;
|
||||
data[l++] = 0xf8 | getreg (arg);
|
||||
data[l++] = t | getreg (arg);
|
||||
data[l++] = getnum (a, arg2);
|
||||
} else { // 32bits
|
||||
data[l++] = 0xc1;
|
||||
data[l++] = 0xf8 | getreg (arg);
|
||||
data[l++] = t | getreg (arg);
|
||||
data[l++] = getnum (a, arg2);
|
||||
}
|
||||
return l;
|
||||
|
@ -249,6 +249,7 @@ toro:
|
||||
}
|
||||
}
|
||||
|
||||
// else r_cons_printf (" ");
|
||||
/* show comment at right? */
|
||||
show_comment_right = 0;
|
||||
if (show_comments) {
|
||||
@ -321,26 +322,23 @@ toro:
|
||||
sprintf (asmop.buf_hex, "%02x", buf[idx]);
|
||||
} else {
|
||||
lastfail = 0;
|
||||
if (hint && hint->length)
|
||||
oplen = hint->length;
|
||||
else oplen = r_asm_op_get_size (&asmop);
|
||||
oplen = (hint && hint->length)?
|
||||
hint->length: r_asm_op_get_size (&asmop);
|
||||
}
|
||||
if (acase)
|
||||
r_str_case (asmop.buf_asm, 1);
|
||||
if (atabs) {
|
||||
int i = 0;
|
||||
char *b = asmop.buf_asm;
|
||||
int n, i = 0;
|
||||
char *t, *b = asmop.buf_asm;
|
||||
for (;*b;b++,i++) {
|
||||
if (*b==' ') {
|
||||
//*b = '\t';
|
||||
int n = (10-i);
|
||||
char *t = strdup (b+1); //XXX slow!
|
||||
if (n<1) n = 1;
|
||||
memset (b, ' ', n);
|
||||
b += n;
|
||||
strcpy (b, t);
|
||||
free (t);
|
||||
}
|
||||
if (*b!=' ') continue;
|
||||
n = (10-i);
|
||||
*t = strdup (b+1); //XXX slow!
|
||||
if (n<1) n = 1;
|
||||
memset (b, ' ', n);
|
||||
b += n;
|
||||
strcpy (b, t);
|
||||
free (t);
|
||||
}
|
||||
}
|
||||
// TODO: store previous oplen in core->dec
|
||||
@ -407,10 +405,9 @@ toro:
|
||||
core->reflines, at, analop.length);
|
||||
/* XXX: This is really cpu consuming.. need to be fixed */
|
||||
if (show_functions) {
|
||||
pre = "__"; // ignored?
|
||||
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) {
|
||||
@ -436,7 +433,7 @@ toro:
|
||||
} else f = NULL;
|
||||
if (f && at == f->addr+f->size-analop.length) // HACK
|
||||
pre = "\\ ";
|
||||
} else pre = " "; //r_cons_printf (" ");
|
||||
} else r_cons_printf (" ");
|
||||
}
|
||||
if (show_flags) {
|
||||
flag = r_flag_get_i (core->flags, at);
|
||||
@ -446,7 +443,7 @@ toro:
|
||||
if (show_offset)
|
||||
r_cons_printf ("; -------- ");
|
||||
if (show_functions)
|
||||
r_cons_printf ("%s:\n%s", flag->name, f?pre:"");
|
||||
r_cons_printf ("%s:\n%s", flag->name, f?pre:" ");
|
||||
else r_cons_printf ("%s:\n", flag->name);
|
||||
}
|
||||
}
|
||||
|
@ -483,16 +483,20 @@ R_API const char *r_sys_arch_str(int arch) {
|
||||
|
||||
R_API int r_sys_run(const ut8 *buf, int len) {
|
||||
const int sz = 4096;
|
||||
int ret, (*cb)();
|
||||
int pdelta, ret, (*cb)();
|
||||
// TODO: define R_SYS_ALIGN_FORWARD in r_util.h
|
||||
ut8 *ptr, *p = malloc ((sz+len)<<1);
|
||||
ptr = (ut8*)R_MEM_ALIGN (p);
|
||||
ptr = p;
|
||||
pdelta = ((size_t)(p)) & (4096-1);
|
||||
if (pdelta)
|
||||
ptr += (4096-pdelta);
|
||||
if (!ptr) {
|
||||
free (p);
|
||||
return R_FALSE;
|
||||
}
|
||||
memcpy (ptr, buf, sz);
|
||||
r_mem_protect (ptr, sz, "rx");
|
||||
r_mem_protect (ptr, sz, "rwx"); // try, ignore if fail
|
||||
r_mem_protect (ptr, sz, "rx"));
|
||||
//r_mem_protect (ptr, sz, "rwx"); // try, ignore if fail
|
||||
cb = (void*)ptr;
|
||||
ret = cb ();
|
||||
free (p);
|
||||
|
Loading…
x
Reference in New Issue
Block a user