2013-04-09 20:54:04 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
|
2009-02-18 21:10:47 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <r_types.h>
|
|
|
|
#include <r_lib.h>
|
|
|
|
#include <r_asm.h>
|
|
|
|
|
|
|
|
#include "x86/ollyasm/disasm.h"
|
|
|
|
|
2015-03-21 01:04:49 +00:00
|
|
|
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
|
2009-02-18 21:10:47 +00:00
|
|
|
t_disasm disasm_obj;
|
|
|
|
|
2013-12-06 04:18:57 +00:00
|
|
|
op->size = Disasm_olly(buf, len, a->pc, &disasm_obj, DISASM_FILE);
|
2011-02-24 15:50:29 +00:00
|
|
|
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s", disasm_obj.result);
|
2009-02-18 21:10:47 +00:00
|
|
|
|
2013-12-06 04:18:57 +00:00
|
|
|
return op->size;
|
2009-02-18 21:10:47 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 01:04:49 +00:00
|
|
|
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
2014-07-31 01:37:38 +00:00
|
|
|
char buf_err[128];
|
2009-02-26 14:15:19 +00:00
|
|
|
static t_asmmodel asm_obj;
|
2009-04-14 23:19:42 +00:00
|
|
|
int attempt, constsize, oattempt = 0, oconstsize = 0, ret = 0, oret = 0xCAFE;
|
2009-02-18 21:10:47 +00:00
|
|
|
|
|
|
|
/* attempt == 0: First attempt */
|
2009-04-14 13:21:19 +00:00
|
|
|
/* constsize == 0: Address constants and inmediate data of 16/32b */
|
2009-04-14 23:19:42 +00:00
|
|
|
for (constsize = 0; constsize < 4; constsize++) {
|
2009-04-20 09:37:54 +00:00
|
|
|
for (attempt = 0; ret > 0; attempt++) {
|
2014-07-31 01:37:38 +00:00
|
|
|
ret = Assemble((char*)buf, a->pc, &asm_obj, attempt, constsize, buf_err);
|
2009-04-14 23:19:42 +00:00
|
|
|
if (ret > 0 && ret < oret) {
|
|
|
|
oret = ret;
|
|
|
|
oattempt = attempt;
|
|
|
|
oconstsize = constsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-31 01:37:38 +00:00
|
|
|
op->size = R_MAX (0, Assemble((char*)buf, a->pc, &asm_obj, oattempt, oconstsize, buf_err));
|
2013-12-06 04:18:57 +00:00
|
|
|
if (op->size > 0)
|
2015-02-01 20:28:21 +00:00
|
|
|
memcpy (op->buf, asm_obj.code, R_MIN(R_MIN(op->size, (R_ASM_BUFSIZE-1)), MAXCMDSIZE-1));
|
2013-12-06 04:18:57 +00:00
|
|
|
return op->size;
|
2009-02-18 21:10:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 23:42:22 +00:00
|
|
|
RAsmPlugin r_asm_plugin_x86_olly = {
|
2009-09-24 10:29:05 +00:00
|
|
|
.name = "x86.olly",
|
2013-12-02 03:44:26 +00:00
|
|
|
.license = "GPL2",
|
2014-02-25 16:03:12 +00:00
|
|
|
.desc = "OllyDBG X86 disassembler",
|
2009-04-11 21:22:20 +00:00
|
|
|
.arch = "x86",
|
2013-12-05 17:41:13 +00:00
|
|
|
.bits = 32,
|
2009-02-18 21:10:47 +00:00
|
|
|
.init = NULL,
|
|
|
|
.fini = NULL,
|
|
|
|
.disassemble = &disassemble,
|
2009-08-14 00:37:18 +00:00
|
|
|
.assemble = &assemble,
|
2009-02-18 21:10:47 +00:00
|
|
|
};
|
|
|
|
|
2009-03-10 01:49:24 +00:00
|
|
|
#ifndef CORELIB
|
2009-02-18 21:10:47 +00:00
|
|
|
struct r_lib_struct_t radare_plugin = {
|
|
|
|
.type = R_LIB_TYPE_ASM,
|
2009-02-19 15:41:51 +00:00
|
|
|
.data = &r_asm_plugin_x86_olly
|
2009-02-18 21:10:47 +00:00
|
|
|
};
|
2009-03-10 01:49:24 +00:00
|
|
|
#endif
|