mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-24 16:23:49 +00:00
* r_asm
- Added label support using r_flags * r_util_str - Added macro isseparator - r_str_word_* functions use isseparator now
This commit is contained in:
parent
14ef1cf602
commit
f87525173a
@ -1,5 +1,5 @@
|
||||
NAME=r_asm
|
||||
DEPS=r_lib r_util r_cmd
|
||||
DEPS=r_lib r_util r_cmd r_flags
|
||||
|
||||
foo: pre libr_asm.so plugins
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_cmd.h>
|
||||
#include <r_flags.h>
|
||||
#include <r_asm.h>
|
||||
#include <list.h>
|
||||
#include "../config.h"
|
||||
@ -203,7 +204,10 @@ R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char
|
||||
|
||||
R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
{
|
||||
char *lbuf=NULL, *ptr = NULL, *tokens[1024], buf_hex[1024];
|
||||
struct r_flag_t flags;
|
||||
struct r_flag_item_t *fi;
|
||||
char *lbuf = NULL, *ptr = NULL, *ptr2 = NULL, *tokens[1024],
|
||||
buf_hex[1024], buf_asm[1024], *symbol = NULL;
|
||||
u8 buf_bin[1024];
|
||||
int ret, idx, ctr, i, j;
|
||||
|
||||
@ -216,9 +220,26 @@ R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
tokens[++ctr] = ptr+1)
|
||||
*ptr = '\0';
|
||||
|
||||
r_flag_init(&flags);
|
||||
r_cmd_set_data(&a->cmd, &aop);
|
||||
for (ret = idx = i = 0, *buf_hex='\0'; i <= ctr; i++, idx+=ret) {
|
||||
r_asm_set_pc(a, a->pc + ret);
|
||||
while ((ptr = strchr(tokens[i], '_'))) { /* Symbol */
|
||||
if ((symbol = r_str_word_get_first(ptr))) {
|
||||
for (ptr2 = tokens[i];*ptr2&&isseparator(*ptr2);ptr2++);
|
||||
if ((ptr == ptr2)) { /* set */
|
||||
r_flag_set(&flags, symbol, a->pc, 0, 0);
|
||||
tokens[i]+=strlen(symbol)+1;
|
||||
} else { /* get */
|
||||
*ptr = '\0';
|
||||
fi = r_flag_get(&flags, symbol);
|
||||
sprintf(buf_asm, "%s0x%llx%s",
|
||||
ptr2, fi->offset, ptr+strlen(symbol));
|
||||
tokens[i] = buf_asm;
|
||||
}
|
||||
free(symbol);
|
||||
}
|
||||
}
|
||||
if ((ptr = strchr(tokens[i], '.'))) /* Pseudo */
|
||||
ret = r_cmd_call_long(&a->cmd, ptr+1);
|
||||
else /* Instruction */
|
||||
|
@ -1,6 +1,6 @@
|
||||
OBJ=rasm2.o
|
||||
BIN=rasm2
|
||||
BINDEPS=r_util r_lib r_asm
|
||||
BINDEPS=r_util r_lib r_asm r_cmd r_flags
|
||||
LIBS+=-ldl
|
||||
|
||||
include ../../rules.mk
|
||||
|
@ -61,12 +61,15 @@ void r_num_init(struct r_num_t *num);
|
||||
#define strnull(x) (!x||!*x)
|
||||
#define iswhitechar(x) (x==' '||x=='\t'||x=='\n'||x=='\r')
|
||||
#define iswhitespace(x) (x==' '||x=='\t')
|
||||
#define isseparator(x) (x==' '||x=='\t'||x=='.'||x==','||x==';'||\
|
||||
x==':'||x=='['||x==']'||x=='('||x==')'||x=='{'||x=='}')
|
||||
#define ishexchar(x) ((x>='0'&&x<='9') || (x>='a'&&x<='f') || (x>='A'&&x<='F')) {
|
||||
|
||||
/* stabilized */
|
||||
int r_str_word_count(const char *string);
|
||||
int r_str_word_set0(char *str);
|
||||
const char *r_str_word_get0(const char *str, int idx);
|
||||
char *r_str_word_get_first(const char *string);
|
||||
|
||||
char *r_str_chop(char *str);
|
||||
R_API const char *r_str_chop_ro(const char *str);
|
||||
|
@ -81,12 +81,12 @@ R_API int r_str_word_count(const char *string)
|
||||
char *tmp = (char *)string;
|
||||
int word = 0;
|
||||
|
||||
for(;(*text)&&(iswhitespace(*text));text=text+1);
|
||||
for(;(*text)&&(isseparator(*text));text=text+1);
|
||||
|
||||
for(word = 0; *text; word++) {
|
||||
for(;*text && !iswhitespace(*text);text = text +1);
|
||||
for(;*text && !isseparator(*text);text = text +1);
|
||||
tmp = text;
|
||||
for(;*text &&iswhitespace(*text);text = text +1);
|
||||
for(;*text &&isseparator(*text);text = text +1);
|
||||
if (tmp == text)
|
||||
word-=1;
|
||||
}
|
||||
@ -213,9 +213,9 @@ char *r_str_word_get_first(const char *string)
|
||||
char *ret = NULL;
|
||||
int len = 0;
|
||||
|
||||
for(;*text &&iswhitespace(*text);text = text + 1);
|
||||
for(;*text &&isseparator(*text);text = text + 1);
|
||||
start = text;
|
||||
for(;*text &&!iswhitespace(*text);text = text + 1) len++;
|
||||
for(;*text &&!isseparator(*text);text = text + 1) len++;
|
||||
|
||||
/* strdup */
|
||||
ret = (char *)malloc(len+1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user