radare2/libr/asm/p/asm_x86_olly.c

62 lines
1.6 KiB
C
Raw Normal View History

/* radare - LGPL - Copyright 2009-2013 - pancake, nibble */
#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) {
t_disasm disasm_obj;
2013-12-06 04:18:57 +00:00
op->size = Disasm_olly(buf, len, a->pc, &disasm_obj, DISASM_FILE);
snprintf(op->buf_asm, R_ASM_BUFSIZE, "%s", disasm_obj.result);
2013-12-06 04:18:57 +00:00
return op->size;
}
2015-03-21 01:04:49 +00:00
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
char buf_err[128];
static t_asmmodel asm_obj;
int attempt, constsize, oattempt = 0, oconstsize = 0, ret = 0, oret = 0xCAFE;
/* attempt == 0: First attempt */
/* constsize == 0: Address constants and inmediate data of 16/32b */
for (constsize = 0; constsize < 4; constsize++) {
for (attempt = 0; ret > 0; attempt++) {
ret = Assemble((char*)buf, a->pc, &asm_obj, attempt, constsize, buf_err);
if (ret > 0 && ret < oret) {
oret = ret;
oattempt = attempt;
oconstsize = constsize;
}
}
}
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;
}
RAsmPlugin r_asm_plugin_x86_olly = {
.name = "x86.olly",
2013-12-02 03:44:26 +00:00
.license = "GPL2",
.desc = "OllyDBG X86 disassembler",
.arch = "x86",
.bits = 32,
.init = NULL,
.fini = NULL,
.disassemble = &disassemble,
.assemble = &assemble,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_x86_olly
};
#endif