mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-26 17:15:38 +00:00
Fix mg infinite recursivity issue, add fq and fsq commands and handle /flags in fs.r2
This commit is contained in:
parent
95a8576360
commit
bb17e9acda
@ -725,11 +725,17 @@ R_API int r_core_run_script (RCore *core, const char *file) {
|
||||
}
|
||||
|
||||
static int cmd_ls(void *data, const char *input) {
|
||||
RCore *core = (RCore *)data;
|
||||
if (*input) {
|
||||
char *res = r_syscmd_ls (input + 1);
|
||||
if (res) {
|
||||
r_cons_print (res);
|
||||
free (res);
|
||||
const char *path = r_str_chop_ro (input + 1);
|
||||
if (r_fs_check (core->fs, path)) {
|
||||
r_core_cmdf (core, "md %s", path);
|
||||
} else {
|
||||
char *res = r_syscmd_ls (path);
|
||||
if (res) {
|
||||
r_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -2131,6 +2137,7 @@ next2:
|
||||
char *tmpeval = NULL;
|
||||
ut64 tmpoff = core->offset;
|
||||
char *tmpasm = NULL;
|
||||
int flgspc = -123;
|
||||
int tmpfd = -1;
|
||||
int sz, len;
|
||||
ut8 *buf;
|
||||
@ -2155,6 +2162,10 @@ repeat_arroba:
|
||||
} else if (ptr[0] && ptr[1] == ':' && ptr[2]) {
|
||||
usemyblock = true;
|
||||
switch (ptr[0]) {
|
||||
case 'F': // "@F:" // temporary flag space
|
||||
flgspc = r_flag_space_get (core->flags, ptr + 2);
|
||||
r_flag_space_set (core->flags, ptr + 2);
|
||||
break;
|
||||
case 'f': // "@f:" // slurp file in block
|
||||
f = r_file_slurp (ptr + 2, &sz);
|
||||
if (f) {
|
||||
@ -2399,6 +2410,10 @@ next_arroba:
|
||||
r_core_cmd0 (core, tmpeval);
|
||||
R_FREE (tmpeval);
|
||||
}
|
||||
if (flgspc != -123) {
|
||||
r_flag_space_set_i (core->flags, flgspc);
|
||||
flgspc = -123;
|
||||
}
|
||||
r_core_seek (core, tmpoff, 1);
|
||||
*ptr = '@';
|
||||
rc = ret;
|
||||
|
@ -407,16 +407,23 @@ static int cmd_cmp(void *data, const char *input) {
|
||||
case 'p':
|
||||
return cmd_cp (data, input);
|
||||
break;
|
||||
case 'a':
|
||||
case 'a': // "cat"
|
||||
if (input[1] == 't') {
|
||||
char *res = r_syscmd_cat (input + 1);
|
||||
if (res) {
|
||||
r_cons_print (res);
|
||||
free (res);
|
||||
const char *path = r_str_chop_ro (input + 2);
|
||||
if (r_fs_check (core->fs, path)) {
|
||||
r_core_cmdf (core, "mg %s", path);
|
||||
} else {
|
||||
char *res = r_syscmd_cat (path);
|
||||
if (res) {
|
||||
r_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'w': cmd_cmp_watcher (core, input + 1); break;
|
||||
case 'w':
|
||||
cmd_cmp_watcher (core, input + 1);
|
||||
break;
|
||||
case '*':
|
||||
if (!input[2]) {
|
||||
eprintf ("Usage: cx* 00..22'\n");
|
||||
|
@ -44,6 +44,7 @@ static const char *help_msg_f[] = {
|
||||
"fS","[on]","sort flags by offset or name",
|
||||
"fV","[*-] [nkey] [offset]","dump/restore visual marks (mK/'K)",
|
||||
"fx","[d]","show hexdump (or disasm) of flag:flagsize",
|
||||
"fq","","list flags in quiet mode",
|
||||
"fz","[?][name]","add named flag zone -name to delete. see fz?[name]",
|
||||
NULL
|
||||
};
|
||||
@ -67,6 +68,7 @@ static const char *help_msg_fs[] = {
|
||||
"fs","+foo","push previous flagspace and set",
|
||||
"fs","-","pop to the previous flagspace",
|
||||
"fs","-.","remove the current flagspace",
|
||||
"fsq","", "list flagspaces in quiet mode",
|
||||
"fsm"," [addr]","move flags at given address to the current flagspace",
|
||||
"fss","","display flagspaces stack",
|
||||
"fss*","","display flagspaces stack in r2 commands",
|
||||
@ -540,7 +542,7 @@ rep:
|
||||
case 'S':
|
||||
r_flag_sort (core->flags, (input[1]=='n'));
|
||||
break;
|
||||
case 's':
|
||||
case 's': // "fs"
|
||||
switch (input[1]) {
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg_fs);
|
||||
@ -580,6 +582,7 @@ rep:
|
||||
case 'j':
|
||||
case '\0':
|
||||
case '*':
|
||||
case 'q':
|
||||
r_flag_space_list (core->flags, input[1]);
|
||||
break;
|
||||
case ' ':
|
||||
@ -692,6 +695,7 @@ rep:
|
||||
case 'n': // "fn"
|
||||
case '*': // "f*"
|
||||
case 'j': // "fj"
|
||||
case 'q': // "fq"
|
||||
r_flag_list (core->flags, *input, input[0]? input + 1: "");
|
||||
break;
|
||||
case 'i': // "fi"
|
||||
|
@ -215,6 +215,14 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) {
|
||||
}
|
||||
|
||||
switch (rad) {
|
||||
case 'q':
|
||||
r_list_foreach (f->flags, iter, flag) {
|
||||
if (IS_IN_SPACE (f, flag)) {
|
||||
continue;
|
||||
}
|
||||
f->cb_printf ("%s\n", flag->name);
|
||||
}
|
||||
break;
|
||||
case 'j': {
|
||||
int first = 1;
|
||||
f->cb_printf ("[");
|
||||
|
@ -40,7 +40,7 @@ R_API int r_flag_space_push(RFlag *f, const char *name) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_flag_space_pop(RFlag *f) {
|
||||
R_API bool r_flag_space_pop(RFlag *f) {
|
||||
char *p = r_list_pop (f->spacestack);
|
||||
if (p) {
|
||||
if (*p) {
|
||||
@ -51,6 +51,17 @@ R_API int r_flag_space_pop(RFlag *f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_flag_space_set_i(RFlag *f, int idx) {
|
||||
int i;
|
||||
for (i = 0; i < R_FLAG_SPACES_MAX; i++) {
|
||||
if (f->spaces[i]) {
|
||||
f->space_idx = idx;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API int r_flag_space_set(RFlag *f, const char *name) {
|
||||
int i;
|
||||
if (!name || *name == '*') {
|
||||
@ -83,7 +94,7 @@ R_API int r_flag_space_unset(RFlag *f, const char *fs) {
|
||||
RListIter *iter;
|
||||
RFlagItem *fi;
|
||||
int i, count = 0;
|
||||
for (i = 0; i<R_FLAG_SPACES_MAX; i++) {
|
||||
for (i = 0; i < R_FLAG_SPACES_MAX; i++) {
|
||||
if (!f->spaces[i]) {
|
||||
continue;
|
||||
}
|
||||
@ -130,7 +141,9 @@ R_API int r_flag_space_list(RFlag *f, int mode) {
|
||||
continue;
|
||||
}
|
||||
count = r_flag_space_count (f, i);
|
||||
if (mode == 'j') {
|
||||
if (mode == 'q') {
|
||||
f->cb_printf ("%s\n", f->spaces[i]);
|
||||
} else if (mode == 'j') {
|
||||
f->cb_printf ("%s{\"name\":\"%s\",\"count\":%d,\"selected\":%s}",
|
||||
j? ",":"", f->spaces[i], count,
|
||||
(allSelected || i == f->space_idx)? "true":"false");
|
||||
|
40
libr/fs/fs.c
40
libr/fs/fs.c
@ -162,7 +162,7 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de
|
||||
return root;
|
||||
}
|
||||
|
||||
static inline int r_fs_match(const char* root, const char* path, int len) {
|
||||
static inline bool r_fs_match(const char* root, const char* path, int len) {
|
||||
return (!strncmp (path, root, len));
|
||||
}
|
||||
|
||||
@ -333,16 +333,28 @@ R_API int r_fs_dir_dump(RFS* fs, const char* path, const char* name) {
|
||||
strcpy (npath, path);
|
||||
strcat (npath, "/");
|
||||
strcat (npath, file->name);
|
||||
if (file->type != R_FS_FILE_TYPE_DIRECTORY) {
|
||||
switch (file->type) {
|
||||
// DONT FOLLOW MOUNTPOINTS
|
||||
case R_FS_FILE_TYPE_DIRECTORY:
|
||||
if (!r_fs_dir_dump (fs, npath, str)) {
|
||||
free (npath);
|
||||
free (str);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case R_FS_FILE_TYPE_REGULAR:
|
||||
item = r_fs_open (fs, npath);
|
||||
if (item) {
|
||||
r_fs_read (fs, item, 0, item->size);
|
||||
r_file_dump (str, item->data, item->size, 0);
|
||||
if (!r_file_dump (str, item->data, item->size, 0)) {
|
||||
free (npath);
|
||||
free (str);
|
||||
return false;
|
||||
}
|
||||
free (item->data);
|
||||
r_fs_close (fs, item);
|
||||
}
|
||||
} else {
|
||||
r_fs_dir_dump (fs, npath, str);
|
||||
break;
|
||||
}
|
||||
free (npath);
|
||||
free (str);
|
||||
@ -857,3 +869,21 @@ beach:
|
||||
R_API void r_fs_view(RFS* fs, int view) {
|
||||
fs->view = view;
|
||||
}
|
||||
|
||||
R_API bool r_fs_check(RFS *fs, const char *p) {
|
||||
RFSRoot *root;
|
||||
RListIter *iter;
|
||||
char* path = strdup (p);
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
r_str_chop_path (path);
|
||||
r_list_foreach (fs->roots, iter, root) {
|
||||
if (r_fs_match (path, root->path, strlen (root->path))) {
|
||||
free (path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
free (path);
|
||||
return false;
|
||||
}
|
||||
|
@ -17,14 +17,49 @@ typedef struct {
|
||||
static RFSFile *__cfg_cat(RFSRoot *root, const char *path);
|
||||
static RList *__root(RFSRoot *root, const char *path);
|
||||
static RList *__cfg(RFSRoot *root, const char *path);
|
||||
static RList *__flags(RFSRoot *root, const char *path);
|
||||
|
||||
static Routes routes[] = {
|
||||
{"/cfg", &__cfg, &__cfg_cat},
|
||||
{"/flags", NULL},
|
||||
{"/flags", &__flags},
|
||||
{"/", &__root},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static void append_file(RList *list, const char *name, int type, int time, ut64 size) {
|
||||
if (!list || !name || !*name) {
|
||||
return;
|
||||
}
|
||||
RFSFile *fsf = r_fs_file_new (NULL, name);
|
||||
if (!fsf) {
|
||||
return;
|
||||
}
|
||||
fsf->type = type;
|
||||
fsf->time = time;
|
||||
fsf->size = size;
|
||||
r_list_append (list, fsf);
|
||||
}
|
||||
|
||||
static RList *fscmd(RFSRoot *root, const char *cmd, int type) {
|
||||
char *res = root->cob.cmdstr (root->cob.core, cmd);
|
||||
if (res) {
|
||||
RList *list = r_list_newf (free);
|
||||
if (!list) {
|
||||
free (res);
|
||||
return NULL;
|
||||
}
|
||||
int i, count = 0;
|
||||
int *lines = r_str_split_lines (res, &count);
|
||||
for (i = 0; i < count; i++) {
|
||||
char *line = strdup (res + lines[i]);
|
||||
append_file (list, line, type, 0, 0);
|
||||
}
|
||||
free (res);
|
||||
return list;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static RFSFile* fs_r2_open(RFSRoot *root, const char *path) {
|
||||
int i;
|
||||
for (i = 0; routes[i].path; i++) {
|
||||
@ -45,20 +80,6 @@ static void fs_r2_close(RFSFile *file) {
|
||||
//fclose (file->ptr);
|
||||
}
|
||||
|
||||
static void append_file(RList *list, const char *name, int type, int time, ut64 size) {
|
||||
if (!list || !name || !*name) {
|
||||
return;
|
||||
}
|
||||
RFSFile *fsf = r_fs_file_new (NULL, name);
|
||||
if (!fsf) {
|
||||
return;
|
||||
}
|
||||
fsf->type = type;
|
||||
fsf->time = time;
|
||||
fsf->size = size;
|
||||
r_list_append (list, fsf);
|
||||
}
|
||||
|
||||
static RFSFile *__cfg_cat(RFSRoot *root, const char *path) {
|
||||
char *a = strdup (path + 5);
|
||||
r_str_replace_char (a, '/', '.');
|
||||
@ -73,6 +94,19 @@ static RFSFile *__cfg_cat(RFSRoot *root, const char *path) {
|
||||
return file;
|
||||
}
|
||||
|
||||
static RList *__flags(RFSRoot *root, const char *path) {
|
||||
const char *prefix = NULL;
|
||||
if (!strncmp (path, "/flags/", 7)) {
|
||||
prefix = path + 7;
|
||||
}
|
||||
char *cmd = prefix
|
||||
? r_str_newf ("fq@F:%s", prefix)
|
||||
: strdup ("fsq");
|
||||
RList *res = fscmd (root, cmd, prefix? 'f': 'd');
|
||||
free (cmd);
|
||||
return res;
|
||||
}
|
||||
|
||||
static RList *__cfg(RFSRoot *root, const char *path) {
|
||||
const char *prefix = NULL;
|
||||
if (!strncmp (path, "/cfg/", 5)) {
|
||||
|
@ -120,11 +120,12 @@ R_API int r_flag_space_get(RFlag *f, const char *name);
|
||||
R_API const char *r_flag_space_get_i(RFlag *f, int idx);
|
||||
R_API const char *r_flag_space_cur(RFlag *f);
|
||||
R_API int r_flag_space_set(RFlag *f, const char *name);
|
||||
R_API bool r_flag_space_set_i(RFlag *f, int idx);
|
||||
R_API int r_flag_count (RFlag *f, const char *name);
|
||||
R_API int r_flag_space_unset (RFlag *f, const char *fs);
|
||||
R_API int r_flag_space_list(RFlag *f, int mode);
|
||||
R_API int r_flag_space_rename (RFlag *f, const char *oname, const char *nname);
|
||||
R_API int r_flag_space_pop(RFlag *f);
|
||||
R_API bool r_flag_space_pop(RFlag *f);
|
||||
R_API int r_flag_space_push(RFlag *f, const char *name);
|
||||
R_API int r_flag_space_stack_list(RFlag *f, int mode);
|
||||
|
||||
|
@ -117,6 +117,7 @@ R_API RList *r_fs_find_off(RFS* fs, const char *name, ut64 off);
|
||||
R_API RList *r_fs_partitions(RFS* fs, const char *ptype, ut64 delta);
|
||||
R_API char *r_fs_name(RFS *fs, ut64 offset);
|
||||
R_API int r_fs_prompt(RFS *fs, const char *root);
|
||||
R_API bool r_fs_check(RFS *fs, const char *p);
|
||||
|
||||
/* file.c */
|
||||
R_API RFSFile *r_fs_file_new(RFSRoot *root, const char *path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user