radare2/libr/asm/p/asm_x86.c
pancake 65da25d4c0 * Implement STATIC PLUGIN support for r_parse
- Use the new 'asm-like' build system for r_parse plugins
  - Added new callback to 'assemble' parseable expressions
    into compilable asm code
  - Refactorize and remove warnings in parse_mreplace
* Added r_str_char_count() in r_util
* Some fixups in the fastcall code in r_asm

--HG--
rename : libr/parse/p/mreplace/mmemory.c => libr/parse/p/parse_mreplace/mmemory.c
rename : libr/parse/p/mreplace/mmemory.h => libr/parse/p/parse_mreplace/mmemory.h
rename : libr/parse/p/mreplace/mreplace.c => libr/parse/p/parse_mreplace/mreplace.c
rename : libr/parse/p/mreplace/mreplace.h => libr/parse/p/parse_mreplace/mreplace.h
2009-08-14 01:44:12 +00:00

54 lines
1.2 KiB
C

/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
#include <stdio.h>
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_asm.h>
#include "fastcall_x86.h"
#include "x86/udis86/types.h"
#include "x86/udis86/extern.h"
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len)
{
static ud_t disasm_obj;
ud_init(&disasm_obj);
if (a->syntax == R_ASM_SYN_ATT)
ud_set_syntax(&disasm_obj, UD_SYN_ATT);
else
ud_set_syntax(&disasm_obj, UD_SYN_INTEL);
ud_set_mode(&disasm_obj, a->bits);
ud_set_pc(&disasm_obj, a->pc);
ud_set_input_buffer(&disasm_obj, buf, len);
ud_disassemble(&disasm_obj);
aop->disasm_obj = &disasm_obj;
aop->inst_len = ud_insn_len(&disasm_obj);
snprintf(aop->buf_asm, R_ASM_BUFSIZE, "%s", ud_insn_asm(&disasm_obj));
return aop->inst_len;
}
struct r_asm_handle_t r_asm_plugin_x86 = {
.name = "asm_x86",
.desc = "X86 disassembly plugin",
.arch = "x86",
.bits = (int[]){ 16, 32, 64, 0 },
.init = NULL,
.fini = NULL,
.disassemble = &disassemble,
.assemble = NULL,
.fastcall = fastcall,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_x86
};
#endif