mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 10:22:37 +00:00
SImplify a bit asm.pseudo
This commit is contained in:
parent
8530822050
commit
cfe74d9aac
@ -38,6 +38,7 @@ typedef struct r_parse_plugin_t {
|
||||
int (*assemble)(RParse *p, char *data, char *str);
|
||||
int (*filter)(RParse *p, RFlag *f, char *data, char *str, int len);
|
||||
int (*varsub)(RParse *p, RAnalFunction *f, char *data, char *str, int len);
|
||||
int (*replace)(int argc, const char *argv[], char *newstr);
|
||||
struct list_head list;
|
||||
} RParsePlugin;
|
||||
|
||||
|
@ -153,44 +153,12 @@ static int parse(RParse *p, const char *data, char *str) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int assemble(RParse *p, char *data, char *str) {
|
||||
char *ptr;
|
||||
printf ("---> assembling '%s' to generate real asm code\n", str);
|
||||
ptr = strchr (str, '=');
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
sprintf (data, "mov %s, %s", str, ptr+1);
|
||||
} else strcpy (data, str);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
|
||||
#if USE_VARSUBS
|
||||
char *ptr, *ptr2;
|
||||
int i;
|
||||
strncpy (str, data, len);
|
||||
for (i = 0; i < R_ANAL_VARSUBS; i++)
|
||||
if (f->varsubs[i].pat[0] != '\0' && f->varsubs[i].sub[0] != '\0' &&
|
||||
(ptr = strstr (data, f->varsubs[i].pat))) {
|
||||
*ptr = '\0';
|
||||
ptr2 = ptr + strlen (f->varsubs[i].pat);
|
||||
snprintf (str, len, "%s%s%s", data, f->varsubs[i].sub, ptr2);
|
||||
}
|
||||
return R_TRUE;
|
||||
#else
|
||||
strncpy (str, data, len);
|
||||
return R_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct r_parse_plugin_t r_parse_plugin_att2intel = {
|
||||
.name = "att2intel",
|
||||
.desc = "X86 att 2 intel plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.parse = &parse,
|
||||
.assemble = &assemble,
|
||||
.varsub = &varsub,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -270,46 +270,12 @@ static int parse(RParse *p, const char *data, char *str) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int assemble(RParse *p, char *data, char *str) {
|
||||
char *ptr;
|
||||
printf ("assembling '%s' to generate real asm code\n", str);
|
||||
ptr = strchr (str, '=');
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
// TODO not yet implemented
|
||||
sprintf (data, "move %s, %s", str, ptr+1);
|
||||
} else strcpy (data, str);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
|
||||
#if USE_VARSUBS
|
||||
char *ptr, *ptr2;
|
||||
int i;
|
||||
|
||||
strncpy (str, data, len);
|
||||
for (i = 0; i < R_ANAL_VARSUBS; i++)
|
||||
if (f->varsubs[i].pat[0] != '\0' && f->varsubs[i].sub[0] != '\0' &&
|
||||
(ptr = strstr (data, f->varsubs[i].pat))) {
|
||||
*ptr = '\0';
|
||||
ptr2 = ptr + strlen (f->varsubs[i].pat);
|
||||
snprintf (str, len, "%s%s%s", data, f->varsubs[i].sub, ptr2);
|
||||
}
|
||||
return R_TRUE;
|
||||
#else
|
||||
strncpy (str, data, len);
|
||||
return R_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct r_parse_plugin_t r_parse_plugin_dalvik_pseudo = {
|
||||
.name = "dalvik.pseudo",
|
||||
.desc = "DALVIK pseudo syntax",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.parse = parse,
|
||||
.assemble = &assemble,
|
||||
.varsub = &varsub,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -206,44 +206,12 @@ static int parse(RParse *p, const char *data, char *str) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int assemble(RParse *p, char *data, char *str) {
|
||||
char *ptr;
|
||||
printf ("assembling '%s' to generate real asm code\n", str);
|
||||
ptr = strchr (str, '=');
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
sprintf (data, "mov %s, %s", str, ptr+1);
|
||||
} else strcpy (data, str);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
|
||||
#if USE_VARSUBS
|
||||
char *ptr, *ptr2;
|
||||
int i;
|
||||
strncpy (str, data, len);
|
||||
for (i = 0; i < R_ANAL_VARSUBS; i++)
|
||||
if (f->varsubs[i].pat[0] != '\0' && f->varsubs[i].sub[0] != '\0' &&
|
||||
(ptr = strstr (data, f->varsubs[i].pat))) {
|
||||
*ptr = '\0';
|
||||
ptr2 = ptr + strlen (f->varsubs[i].pat);
|
||||
snprintf (str, len, "%s%s%s", data, f->varsubs[i].sub, ptr2);
|
||||
}
|
||||
return R_TRUE;
|
||||
#else
|
||||
strncpy (str, data, len);
|
||||
return R_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct r_parse_plugin_t r_parse_plugin_mips_pseudo = {
|
||||
.name = "mips.pseudo",
|
||||
.desc = "MIPS pseudo syntax",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.parse = parse,
|
||||
.assemble = &assemble,
|
||||
.varsub = &varsub,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
|
@ -17,21 +17,50 @@ struct mreplace_t {
|
||||
};
|
||||
|
||||
static int parse(RParse *p, const char *data, char *str) {
|
||||
struct mreplace_t *sdata = (struct mreplace_t*)data;
|
||||
const struct mreplace_t *sdata = (struct mreplace_t*)data;
|
||||
char *buf = treplace (sdata->data, sdata->search, sdata->replace);
|
||||
memcpy (str, buf, R_PARSE_STRLEN);
|
||||
free (buf);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int assemble(RParse *p, char *data, char *str) {
|
||||
char *ptr = strchr (str, '=');
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
sprintf (data, "mov %s, %s", str, ptr+1);
|
||||
} else strcpy (data, str);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int varsub(RParse *p, RAnalFunction *f, char *data, char *str, int len) {
|
||||
#if USE_VARSUBS
|
||||
char *ptr, *ptr2;
|
||||
int i;
|
||||
strncpy (str, data, len);
|
||||
for (i = 0; i < R_ANAL_VARSUBS; i++)
|
||||
if (f->varsubs[i].pat[0] != '\0' && f->varsubs[i].sub[0] != '\0' &&
|
||||
(ptr = strstr (data, f->varsubs[i].pat))) {
|
||||
*ptr = '\0';
|
||||
ptr2 = ptr + strlen (f->varsubs[i].pat);
|
||||
snprintf (str, len, "%s%s%s", data, f->varsubs[i].sub, ptr2);
|
||||
}
|
||||
return R_TRUE;
|
||||
#else
|
||||
strncpy (str, data, len);
|
||||
return R_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct r_parse_plugin_t r_parse_plugin_mreplace = {
|
||||
.name = "mreplace",
|
||||
.desc = "mreplace parsing plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.parse = parse,
|
||||
.assemble = NULL,
|
||||
.filter = NULL
|
||||
.parse = &parse,
|
||||
.assemble = &assemble,
|
||||
.varsub = &varsub,
|
||||
.filter = NULL,
|
||||
};
|
||||
|
||||
#else
|
||||
|
@ -144,17 +144,6 @@ static int parse(RParse *p, const char *data, char *str) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static int assemble(RParse *p, char *data, char *str) {
|
||||
char *ptr;
|
||||
printf ("assembling '%s' to generate real asm code\n", str);
|
||||
ptr = strchr (str, '=');
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
sprintf (data, "mov %s, %s", str, ptr+1);
|
||||
} else strcpy (data, str);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static inline int ishexch (char c) {
|
||||
if (c>=0 && c<=9) return 1;
|
||||
@ -248,8 +237,7 @@ struct r_parse_plugin_t r_parse_plugin_x86_pseudo = {
|
||||
.desc = "X86 pseudo syntax",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.parse = parse,
|
||||
.assemble = &assemble,
|
||||
.parse = &parse,
|
||||
.filter = NULL,
|
||||
.varsub = &varsub,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user