mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-01 17:40:34 +00:00
Initial implementation of CC,
This commit is contained in:
parent
30b1fcc208
commit
ba74db8e3a
@ -532,23 +532,3 @@ R_API int r_meta_space_count_for(RAnal *a, int ctx) {
|
||||
r_meta_list_cb (a, type, 0, meta_count_cb, &mu);
|
||||
return mu.count;
|
||||
}
|
||||
|
||||
#if 0
|
||||
R_API char *r_anal_meta_bar (RAnal *anal, ut64 from, ut64 to, int blocks) {
|
||||
int i, n, blocksize;
|
||||
char *res;
|
||||
ut64 f, t;
|
||||
if (blocks<1 || from > to)
|
||||
return NULL;
|
||||
blocksize = (to-from)/blocks;
|
||||
res = malloc (blocks*4);
|
||||
for (i=0; i< blocks; i++) {
|
||||
f = from + (blocksize*i);
|
||||
t = f+blocksize;
|
||||
n = r_anal_fcn_count (anal, f, t);
|
||||
if (n>0) res[i++] = 'f';
|
||||
res[i++] = ',';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
@ -1,48 +1,20 @@
|
||||
/* radare - LGPL - Copyright 2009-2015 - pancake */
|
||||
#if 0
|
||||
static void filter_line(char *line) {
|
||||
char *a;
|
||||
|
||||
if (!line)
|
||||
return;
|
||||
|
||||
for (a=line; *a; a++) {
|
||||
switch (*a) {
|
||||
case '%':
|
||||
case '(':
|
||||
case ')':
|
||||
case '~':
|
||||
case '|':
|
||||
case '#':
|
||||
case ';':
|
||||
case '"':
|
||||
*a = '_';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int remove_meta_offset(RCore *core, ut64 offset) {
|
||||
int ret;
|
||||
char aoffset[64], *aoffsetptr;
|
||||
|
||||
aoffsetptr = sdb_itoa (offset, aoffset, 16);
|
||||
|
||||
char aoffset[64];
|
||||
char *aoffsetptr = sdb_itoa (offset, aoffset, 16);
|
||||
if (!aoffsetptr) {
|
||||
eprintf ("Failed to convert %"PFMT64x" to a key", offset);
|
||||
return -1;
|
||||
}
|
||||
ret = sdb_unset (core->bin->cur->sdb_addrinfo, aoffsetptr, 0);
|
||||
return ret;
|
||||
return sdb_unset (core->bin->cur->sdb_addrinfo, aoffsetptr, 0);
|
||||
}
|
||||
|
||||
static int print_meta_offset(RCore *core, ut64 offset) {
|
||||
static void print_meta_offset(RCore *core, ut64 offset) {
|
||||
int ret, line, line_old, i;
|
||||
char file[1024];
|
||||
|
||||
ret = r_bin_addr2line (core->bin, offset, file, sizeof (file)-1, &line);
|
||||
|
||||
if (ret) {
|
||||
r_cons_printf ("file %s\nline %d\n", file, line);
|
||||
line_old = line;
|
||||
@ -63,16 +35,10 @@ static int print_meta_offset(RCore *core, ut64 offset) {
|
||||
eprintf ("Cannot find meta information at 0x%08"
|
||||
PFMT64x"\n", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int remove_meta_fileline(RCore *core, const char *file_line) {
|
||||
int ret;
|
||||
|
||||
ret = sdb_unset (core->bin->cur->sdb_addrinfo, file_line, 0);
|
||||
|
||||
return ret;
|
||||
return sdb_unset (core->bin->cur->sdb_addrinfo, file_line, 0);
|
||||
}
|
||||
|
||||
static int print_meta_fileline(RCore *core, const char *file_line) {
|
||||
@ -245,6 +211,7 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
||||
"CC", "", "list all comments in human friendly form",
|
||||
"CC*", "", "list all comments in r2 commands",
|
||||
"CC.", "", "show comment at current offset",
|
||||
"CC,", " [file]", "show or set comment file",
|
||||
"CC", " or maybe not", "append comment at current address",
|
||||
"CC+", " same as above", "append comment at current address",
|
||||
"CC!", "", "edit comment using cfg.editor (vim, ..)",
|
||||
@ -254,6 +221,38 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
||||
NULL};
|
||||
r_core_cmd_help (core, help_msg);
|
||||
} break;
|
||||
case ',': // "CC,"
|
||||
if (input[2]=='?') {
|
||||
eprintf ("Usage: CC, [file]\n");
|
||||
} else if (input[2]==' ') {
|
||||
const char *fn = input+2;
|
||||
char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
||||
while (*fn== ' ')fn++;
|
||||
if (comment && *comment) {
|
||||
// append filename in current comment
|
||||
char *nc = r_str_newf ("%s ,(%s)", comment, fn);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc);
|
||||
free (nc);
|
||||
} else {
|
||||
char *comment = r_str_newf (",(%s)", fn);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, comment);
|
||||
free (comment);
|
||||
}
|
||||
} else {
|
||||
char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
||||
if (comment && *comment) {
|
||||
char *cmtfile = r_str_between (comment, ",(", ")");
|
||||
if (cmtfile && *cmtfile) {
|
||||
char *getcommapath(RCore *core);
|
||||
char *cwd = getcommapath (core);
|
||||
r_cons_printf ("%s"R_SYS_DIR"%s\n", cwd, cmtfile);
|
||||
free (cwd);
|
||||
}
|
||||
free (cmtfile);
|
||||
}
|
||||
free (comment);
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
{
|
||||
char *comment = r_meta_get_string (
|
||||
@ -524,7 +523,7 @@ static int cmd_meta(void *data, const char *input) {
|
||||
case 'L':
|
||||
cmd_meta_lineinfo (core, input + 1);
|
||||
break;
|
||||
case 'C':
|
||||
case 'C': // "CC"
|
||||
cmd_meta_comment (core, input);
|
||||
break;
|
||||
case 'h': /* comment */
|
||||
|
@ -678,35 +678,28 @@ void SetWindow(int Width, int Height) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/* retrieves string between ',<' and '>' */
|
||||
static char *getcommafile(const char *cmt) {
|
||||
char *c0, *c1;
|
||||
if (!cmt || !*cmt) return NULL;
|
||||
c0 = strstr (cmt, ",<");
|
||||
if (!c0) return NULL;
|
||||
c1 = strchr (c0+2, '>');
|
||||
if (!c1) return NULL;
|
||||
return r_str_ndup (c0+2, (c1-c0-2));
|
||||
}
|
||||
|
||||
static void visual_comma(RCore *core) {
|
||||
ut64 addr = core->offset; // + (ocursor!=-1)? ocursor: 0;
|
||||
char *comment, *cwd, *cmtfile;
|
||||
// unnecesarily public
|
||||
char *getcommapath(RCore *core) {
|
||||
char *cwd;
|
||||
const char *dir = r_config_get (core->config, "dir.projects");
|
||||
const char *prj = r_config_get (core->config, "file.project");
|
||||
if (curset) {
|
||||
addr += cursor;
|
||||
}
|
||||
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
||||
cmtfile = getcommafile (comment);
|
||||
if (dir && *dir && prj && *prj) {
|
||||
/* use prjdir as base directory for comma-ent files */
|
||||
cwd = r_str_newf ("%s"R_SYS_DIR"%s.d",
|
||||
r_file_abspath (dir), prj);
|
||||
} else {
|
||||
/* use cwd as base directory for comma-ent files */
|
||||
cwd = r_file_abspath (".");
|
||||
cwd = r_sys_getdir ();
|
||||
}
|
||||
return cwd;
|
||||
}
|
||||
|
||||
static void visual_comma(RCore *core) {
|
||||
ut64 addr = core->offset + curset? cursor: 0;
|
||||
char *comment, *cwd, *cmtfile;
|
||||
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr);
|
||||
cmtfile = r_str_between (comment, ",(", ")");
|
||||
cwd = getcommapath (core);
|
||||
if (!cmtfile) {
|
||||
char *fn;
|
||||
showcursor (core, true);
|
||||
@ -715,11 +708,11 @@ static void visual_comma(RCore *core) {
|
||||
if (fn && *fn) {
|
||||
cmtfile = strdup (fn);
|
||||
if (!comment || !*comment) {
|
||||
comment = r_str_newf (",<%s>", fn);
|
||||
comment = r_str_newf (",(%s)", fn);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, comment);
|
||||
} else {
|
||||
// append filename in current comment
|
||||
char *nc = r_str_newf ("%s ,<%s>", comment, fn);
|
||||
char *nc = r_str_newf ("%s ,(%s)", comment, fn);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc);
|
||||
free (nc);
|
||||
}
|
||||
@ -735,7 +728,7 @@ static void visual_comma(RCore *core) {
|
||||
free (odata);
|
||||
free (cwf);
|
||||
} else {
|
||||
eprintf ("NO CMTFILE\n");
|
||||
eprintf ("No commafile found.\n");
|
||||
}
|
||||
free (comment);
|
||||
}
|
||||
|
@ -583,6 +583,8 @@ R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen,
|
||||
R_API char *r_hex_from_c(const char *code);
|
||||
R_API bool r_str_glob (const char *str, const char *glob);
|
||||
R_API int r_str_binstr2bin(const char *str, ut8 *out, int outlen);
|
||||
R_API char *r_str_between(const char *str, const char *prefix, const char *suffix);
|
||||
|
||||
R_API int r_hex_pair2bin(const char *arg);
|
||||
R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask);
|
||||
R_API int r_hex_str2bin(const char *in, ut8 *out);
|
||||
|
@ -1912,3 +1912,13 @@ R_API void r_str_const_free() {
|
||||
R_FREE (consts);
|
||||
}
|
||||
}
|
||||
|
||||
R_API char *r_str_between(const char *cmt, const char *prefix, const char *suffix) {
|
||||
char *c0, *c1;
|
||||
if (!cmt || !prefix || !suffix || !cmt || !*cmt) return NULL;
|
||||
c0 = strstr (cmt, prefix);
|
||||
if (!c0) return NULL;
|
||||
c1 = strstr (c0 + strlen (prefix), suffix);
|
||||
if (!c1) return NULL;
|
||||
return r_str_ndup (c0 + strlen (prefix), (c1 - c0 - strlen (prefix)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user