Improve .fill and rasm2 -hh with documented directives ##asm

This commit is contained in:
pancake 2021-02-04 00:51:53 +01:00 committed by pancake
parent 3a262b31ea
commit 8413fd630a
4 changed files with 61 additions and 38 deletions

View File

@ -71,4 +71,4 @@ R_API char* r_asm_code_get_hex(RAsmCode *acode) {
r_hex_bin2str (acode->bytes, acode->len, str);
}
return str;
}
}

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2020 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2021 - pancake, nibble */
#include <stdio.h>
#include <r_core.h>
@ -139,7 +139,18 @@ static inline int r_asm_pseudo_byte(RAsmOp *op, char *input) {
static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) {
int i, repeat = 0, size=0, value=0;
sscanf (input, "%d,%d,%d", &repeat, &size, &value); // use r_num?
if (strchr (input, ',')) {
int res = sscanf (input, "%d,%d,%d", &repeat, &size, &value); // use r_num?
if (res != 3) {
eprintf ("Invalid usage of .fill repeat,size,value\n");
eprintf ("for example: .fill 1,0x100,0\n");
return -1;
}
} else {
ut64 v = r_num_math (NULL, input);
size = (int)v;
repeat = 1;
}
size *= (sizeof (value) * repeat);
if (size > 0) {
ut8 *buf = malloc (size);
@ -921,6 +932,9 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) {
ret = r_asm_pseudo_bits (a, ptr+6);
} else if (!strncmp (ptr, ".fill ", 6)) {
ret = r_asm_pseudo_fill (&op, ptr+6);
if (ret == -1) {
goto fail;
}
} else if (!strncmp (ptr, ".kernel ", 8)) {
r_syscall_setup (a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 8);
} else if (!strncmp (ptr, ".cpu ", 5)) {

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2020 - pancake, nibble, maijin */
/* radare - LGPL - Copyright 2009-2021 - pancake, nibble, maijin */
#include <r_anal.h>
#include <r_asm.h>
@ -304,15 +304,48 @@ static int rasm_show_help(int v) {
" If '-l' value is greater than output length, output is padded with nops\n"
" If the last argument is '-' reads from stdin\n");
printf ("Environment:\n"
" RASM2_NOPLUGINS do not load shared plugins (speedup loading)\n"
" RASM2_ARCH same as rasm2 -a\n"
" RASM2_BITS same as rasm2 -b\n"
" R_DEBUG if defined, show error messages and crash signal\n"
" RASM2_NOPLUGINS do not load shared plugins (speedup loading)\n"
" RASM2_ARCH same as rasm2 -a\n"
" RASM2_BITS same as rasm2 -b\n"
" R2_DEBUG if defined, show error messages and crash signal\n"
" R2_DEBUG_ASSERT=1 lldb -- r2 to get proper backtrace of the runtime assert\n"
"");
}
if (v == 2) {
printf ("Supported Assembler directives:\n");
printf ("Preprocessor directives:\n");
r_asm_list_directives ();
printf ("Assembler directives:\n");
printf (".intel_syntax\n"
".att_syntax sets e asm.syntax=att to use AT&T syntax parser\n"
".endian [0,1] default endian is system endian, 0=little, 1=big\n"
".big_endian call e cfg.bigendian=true, same as .endian 1\n"
".lil_endian call e cfg.bigendian=false, same as .endian 0\n"
".asciz \"msg\" zero byte terminated string\n"
".string non-null terminated string\n"
".ascii same as .string\n"
".align force a specific alignment when writing code\n"
".arm set asm.bits=32 when asm.arch=arm\n"
".thumb set asm.bits=16 when asm.arch=arm\n"
".arch [mips] specify asm.arch\n"
".bits [32|64] specify 8,16,32,64 e asm.bits\n"
".fill [count] fill N bytes with zeroes\n"
".kernel [ios] set asm.os=linux,windows,macos,...\n"
".cpu [name] set asm.cpu=?\n"
".os [os] same as .kernel\n"
".hex 102030 set bytes in linear hexpair string, no endian applied\n"
".int16 [num] write int16 number honoring endian\n"
".int32 [num] same for 32bit\n"
".int64 [num] same for 64bit\n"
".size N/A\n"
".section N/A\n"
".byte 0x10,0x20 space or comma separated list of byte values\n"
".glob N/A\n"
".equ K=V define K to be replaced with V in the lines below\n"
".org change the PC=$$ to make relative instructions work\n"
".text tell the linker where the code starts\n"
".data tell the linker where the data starts\n"
".incbin foo.bin include binary file\n"
);
}
return 0;
}

View File

@ -72,36 +72,12 @@ Use hex dwords instead of hexpairs in the assembler output
.It Fl q
Quiet output (handy for -L, -v, ...)
.El
.Sh different than filename
.Sh DIRECTIVES
.Pp
List the supported assembler and preprocessor directives with:
.Pp
$rasm2 -hh
.Pp
.Bl -tag -width Fl
.It Fl .intel_syntax
Use intel syntax rather than att:w
.It Fl .att_syntax
Use ATT syntax rather than flu :w
dentify the region fof aslerrger
.It Fl string
dentify the region fof aslerrger
.It Fl .align
.It Fl .arch
.It Fl .arm
.It Fl .ascii
.It Fl .bits
.It Fl .data
.It Fl .equ
.It Fl .fill
.It Fl .glob
.It Fl .hex
.It Fl .int16
.It Fl .int32
.It Fl .int64
.It Fl .kernel
.It Fl .offset
.It Fl .org
.It Fl .os
.It Fl .short
.It Fl .text
.It Fl .thumb
.El
.Sh EXAMPLES
.Pp