1 /* radare - LGPL - Copyright 2010-2019 - pancake */
2 
3 #include <r_types.h>
4 #include <r_util.h>
5 #include <r_lib.h>
6 #include <r_asm.h>
7 
assemble(RAsm * a,RAsmOp * op,const char * buf)8 static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
9 	int len = 0;
10 	ut8 *out;
11 	char *cmd = r_str_newf (
12 		"gas /dev/stdin -o /dev/stdout <<__\n"
13 		"BITS %i\nORG 0x%"PFMT64x"\n%s\n__",
14 		a->bits, a->pc, buf);
15 	ut8 *out = (ut8 *)r_sys_cmd_str (cmd, "", &len);
16 	if (out) {
17 		r_asm_op_set_buf (op, out, len);
18 		free (out);
19 	}
20 	op->size = len;
21 	free (cmd);
22 	return len;
23 }
24 
25 RAsmPlugin r_asm_plugin_x86_gas = {
26 	.name = "x86.gas",
27 	.license = "LGPL3",
28 	.desc = "GNU Assembler (gas)",
29 	.bits = 16|32|64,
30 	.endian = R_SYS_ENDIAN_LITTLE,
31 	.assemble = &assemble
32 };
33 
34 #ifndef R2_PLUGIN_INCORE
35 R_API RLibStruct radare_plugin = {
36 	.type = R_LIB_TYPE_ASM,
37 	.data = &r_asm_plugin_x86_gas,
38 	.version = R2_VERSION
39 };
40 #endif
41