Rizin
unix-like reverse engineering framework and cli tools
asm_arm_as.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_types.h>
5 #include <rz_util.h>
6 #include <rz_lib.h>
7 #include <rz_asm.h>
8 #include "../binutils_as.h"
9 
10 #define ASSEMBLER32 "RZ_ARM32_AS"
11 #define ASSEMBLER64 "RZ_ARM64_AS"
12 
13 static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) {
14  int bits = a->bits;
15  char *as = "";
16 #if __arm__
17  if (bits <= 32) {
18  as = "as";
19  }
20 #elif __aarch64__
21  if (bits == 64) {
22  as = "as";
23  }
24 #endif
25  char cmd_opt[4096];
26  snprintf(cmd_opt, sizeof(cmd_opt), "%s %s",
27  bits == 16 ? "-mthumb" : "",
28  a->big_endian ? "-EB" : "-EL");
29  return binutils_assemble(a, op, buf, as,
30  bits == 64 ? ASSEMBLER64 : ASSEMBLER32,
31  bits <= 32 ? ".syntax unified\n" : "", cmd_opt);
32 }
33 
35  .name = "arm.as",
36  .desc = "as ARM Assembler (use " ASSEMBLER32 " and " ASSEMBLER64 " environment)",
37  .arch = "arm",
38  .author = "pancake",
39  .license = "LGPL3",
40  .bits = 16 | 32 | 64,
42  .assemble = &assemble,
43 };
44 
45 #ifndef RZ_PLUGIN_INCORE
48  .data = &rz_asm_plugin_arm_as,
50 };
51 #endif
#define ASSEMBLER64
Definition: asm_arm_as.c:11
RZ_API RzLibStruct rizin_plugin
Definition: asm_arm_as.c:46
#define ASSEMBLER32
Definition: asm_arm_as.c:10
RzAsmPlugin rz_asm_plugin_arm_as
Definition: asm_arm_as.c:34
static int assemble(RzAsm *a, RzAsmOp *op, const char *buf)
Definition: asm_arm_as.c:13
int binutils_assemble(RzAsm *a, RzAsmOp *op, const char *buf, const char *as, const char *env, const char *header, const char *cmd_opt)
Definition: binutils_as.c:7
int bits(struct state *s, int need)
Definition: blast.c:72
#define RZ_API
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32