2009-04-13 22:47:02 +00:00
|
|
|
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
|
|
|
|
|
|
|
#include <r_types.h>
|
|
|
|
#include <r_util.h>
|
|
|
|
#include <r_lib.h>
|
|
|
|
#include <r_asm.h>
|
|
|
|
|
2009-08-14 00:37:18 +00:00
|
|
|
#include "fastcall_x86.h"
|
|
|
|
|
2009-04-13 22:47:02 +00:00
|
|
|
#if 0
|
2009-07-08 13:49:55 +02:00
|
|
|
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len)
|
2009-04-13 22:47:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-21 20:24:28 +01:00
|
|
|
static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char *buf) {
|
2009-04-13 22:47:02 +00:00
|
|
|
int len = 0;
|
2009-04-16 19:20:03 +02:00
|
|
|
char cmd[R_ASM_BUFSIZE];
|
2009-07-08 13:49:55 +02:00
|
|
|
ut8 *out;
|
2009-04-14 15:21:19 +02:00
|
|
|
sprintf(cmd, "nasm /dev/stdin -o /dev/stdout <<__\nBITS %i\nORG 0x%llx\n%s\n__", a->bits, a->pc, buf);
|
2009-07-08 13:49:55 +02:00
|
|
|
out = (ut8 *)r_sys_cmd_str(cmd, "", &len);
|
2009-04-13 22:47:02 +00:00
|
|
|
if (out) {
|
2009-04-16 19:20:03 +02:00
|
|
|
memcpy(aop->buf, out, len<=R_ASM_BUFSIZE?len:R_ASM_BUFSIZE);
|
2009-04-13 22:47:02 +00:00
|
|
|
free(out);
|
|
|
|
}
|
|
|
|
aop->inst_len = len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct r_asm_handle_t r_asm_plugin_x86_nasm = {
|
2009-09-24 12:29:05 +02:00
|
|
|
.name = "x86.nasm",
|
2009-04-13 22:47:02 +00:00
|
|
|
.desc = "X86 nasm assembler plugin",
|
|
|
|
.arch = "x86",
|
|
|
|
.bits = (int[]){ 16, 32, 64, 0 },
|
|
|
|
.init = NULL,
|
|
|
|
.fini = NULL,
|
|
|
|
.disassemble = NULL, /*&disassemble,*/
|
|
|
|
.assemble = &assemble,
|
2009-08-14 00:37:18 +00:00
|
|
|
.fastcall = fastcall,
|
2009-04-13 22:47:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef CORELIB
|
|
|
|
struct r_lib_struct_t radare_plugin = {
|
|
|
|
.type = R_LIB_TYPE_ASM,
|
|
|
|
.data = &r_asm_plugin_x86_nasm
|
|
|
|
};
|
|
|
|
#endif
|
2009-08-14 00:37:18 +00:00
|
|
|
|
|
|
|
#if TEST
|
2010-02-21 20:24:28 +01:00
|
|
|
main() {
|
2009-08-14 00:37:18 +00:00
|
|
|
struct r_asm_fastcall_t *f;
|
|
|
|
//f = r_asm_plugin_x86_nasm.fastcall;
|
|
|
|
printf("fastcall=%p\n", *r_asm_plugin_x86_nasm.fastcall);
|
|
|
|
printf("fastcall=%p\n", fastcall);
|
|
|
|
f = fastcall;//r_asm_plugin_x86_nasm.fastcall;
|
|
|
|
printf("f=%p (%s)\n", f, f);
|
|
|
|
printf("f[0]=%p (%s)\n", f[0], f[0]);
|
|
|
|
printf("f[3].arg[1]=%s\n", f[3].arg[1]);
|
|
|
|
}
|
|
|
|
#endif
|