Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rparse to rcore binding for afen #346

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions afen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Install:

meson install -C build

## Running:
## Run:

r2 -e asm.pseudo=true <file>
r2 -e asm.parser=afen -e asm.pseudo=true <file>

## Usage:

Expand Down
54 changes: 31 additions & 23 deletions afen/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ static RList *old_names;
static RList *new_names;

// afen parser
static int r_afen_parse(RParse *p, const char *data, char *str) {
int res = true;
static int r_parse_afen(RParse *p, const char *data, char *str) {
char *input = strdup (data);

int n = r_list_length(old_names);
int n = r_list_length (old_names);

if (n){
if (n) {
RListIter *s_iter_old = NULL;
RListIter *s_iter_new = NULL;

Expand All @@ -24,64 +23,73 @@ static int r_afen_parse(RParse *p, const char *data, char *str) {
for (int i = 0; i < n; ++i) {
input = r_str_replace_all (input, s_iter_old->data, s_iter_new->data);

s_iter_old = r_list_iter_get_next(s_iter_old);
s_iter_new = r_list_iter_get_next(s_iter_new);
s_iter_old = r_list_iter_get_next (s_iter_old);
s_iter_new = r_list_iter_get_next (s_iter_new);
}

}

strcpy (str, input);
return res;
return true;
}

// RParse plugin Definition Info
RParsePlugin r_parse_plugin_afen = {
.name = "afen",
.desc = "Afen parse plugin",
.parse = r_parse_afen,
};

// sets afen parser
static int r_cmd_init(void *user, const char *input) {
static int r_core_init_afen(void *user, const char *input) {
RCmd *rcmd = (RCmd *) user;
RCore *core = (RCore *) rcmd->data;

r_parse_plugin_add (core->parser, &r_parse_plugin_afen);

old_names = r_list_new ();
new_names = r_list_new ();

core->parser->cur->parse = r_afen_parse;

return true;
}

static int r_cmd_fini(void *user, const char *input) {
r_list_free(old_names);
r_list_free(new_names);
static int r_core_fini_afen(void *user, const char *input) {
r_list_free (old_names);
r_list_free (new_names);

return true;
}

static int r_cmd_afen_client(void *user, const char *input) {
static int r_core_call_afen(void *user, const char *input) {
if (r_str_startswith (input, "afen")) {
int *argc = (int*) malloc(sizeof(int));
char **argv = r_str_argv(input, argc);
int *argc = (int*) malloc (sizeof (int));
char **argv = r_str_argv (input, argc);

if (*argc != 3) {
r_cons_printf("Usage: afen new_name old_name\n");
r_cons_printf ("Usage: afen new_name old_name\n");
return true;
}

r_list_append(new_names, argv[1]);
r_list_append(old_names, argv[2]);
r_list_append (new_names, argv[1]);
r_list_append (old_names, argv[2]);

return true;
}
return false;
}

// PLUGIN Definition Info

// RCore plugin Definition Info
RCorePlugin r_core_plugin_afen = {
.meta = {
.name = "core-afen",
.desc = "Rename expressions",
.author = "satk0",
.license = "GPLv3",
},
.call = r_cmd_afen_client,
.init = r_cmd_init,
.fini = r_cmd_fini
.call = r_core_call_afen,
.init = r_core_init_afen,
.fini = r_core_fini_afen
};


Expand Down
Loading