mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-11 23:16:05 +00:00
Fix overflow in r_asm_disassemble() and implement rip-relative refs in anal.x86.cs
This commit is contained in:
parent
f024521b7d
commit
a9eb8da77b
@ -24,10 +24,13 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
|
||||
(a->bits==32)? CS_MODE_32:
|
||||
(a->bits==16)? CS_MODE_16: 0;
|
||||
int n, ret = cs_open (CS_ARCH_X86, mode, &handle);
|
||||
memset (op, '\0', sizeof (RAnalOp));
|
||||
op->type = R_ANAL_OP_TYPE_NULL;
|
||||
op->jump = UT64_MAX;
|
||||
op->fail = UT64_MAX;
|
||||
op->ptr = op->val = UT64_MAX;
|
||||
op->src[0] = NULL;
|
||||
op->src[1] = NULL;
|
||||
op->size = 0;
|
||||
op->delay = 0;
|
||||
r_strbuf_init (&op->esil);
|
||||
@ -97,12 +100,18 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
|
||||
switch (INSOP(0).type) {
|
||||
case X86_OP_MEM:
|
||||
op->ptr = INSOP(0).mem.disp;
|
||||
if (INSOP(0).mem.base == X86_REG_RIP) {
|
||||
op->ptr += addr + insn->size;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (INSOP(1).type) {
|
||||
case X86_OP_MEM:
|
||||
op->ptr = INSOP(1).mem.disp;
|
||||
if (INSOP(1).mem.base == X86_REG_RIP) {
|
||||
op->ptr += addr + insn->size;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -305,6 +305,8 @@ R_API int r_asm_set_pc(RAsm *a, ut64 pc) {
|
||||
R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
int oplen, ret = op->payload = 0;
|
||||
op->size = 4;
|
||||
if (len<1)
|
||||
return 0;
|
||||
if (a->cur && a->cur->disassemble)
|
||||
ret = a->cur->disassemble (a, op, buf, len);
|
||||
oplen = r_asm_op_get_size (op);
|
||||
@ -318,6 +320,8 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
||||
} else ret = 0;
|
||||
r_mem_copyendian (op->buf, buf, oplen, !a->big_endian);
|
||||
*op->buf_hex = 0;
|
||||
if ((oplen*4)>=sizeof(op->buf_hex))
|
||||
oplen = (sizeof(op->buf_hex)/4)-1;
|
||||
r_hex_bin2str (buf, oplen, op->buf_hex);
|
||||
return ret;
|
||||
}
|
||||
|
@ -87,6 +87,8 @@ R_API int r_hex_pair2bin(const char *arg) {
|
||||
R_API int r_hex_bin2str(const ut8 *in, int len, char *out) {
|
||||
int i, idx;
|
||||
char tmp[5];
|
||||
if (len<0)
|
||||
return 0;
|
||||
for (idx=i=0; i<len; i++,idx+=2) {
|
||||
snprintf (tmp, sizeof (tmp), "%02x", in[i]);
|
||||
memcpy (out+idx, tmp, 2);
|
||||
|
Loading…
Reference in New Issue
Block a user