mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-03 02:41:08 +00:00
Initial implementation of the V, comma-ents stuff
This commit is contained in:
parent
0d9e29bd26
commit
30b1fcc208
@ -2165,7 +2165,6 @@ static void handle_print_comments_right (RCore *core, RDisasmState *ds) {
|
||||
}
|
||||
r_cons_strcat (" ; ");
|
||||
}
|
||||
|
||||
//r_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';');
|
||||
r_cons_strcat (ds->comment);
|
||||
if (ds->show_color) {
|
||||
@ -2450,7 +2449,6 @@ toro:
|
||||
if (!(ds->show_comments && ds->show_comment_right && ds->comment)) {
|
||||
r_cons_newline ();
|
||||
}
|
||||
|
||||
if (ds->line) {
|
||||
if (ds->show_lines_ret && ds->analop.type == R_ANAL_OP_TYPE_RET) {
|
||||
if (strchr (ds->line, '>')) {
|
||||
|
@ -662,22 +662,84 @@ R_API int r_core_visual_xrefs_X (RCore *core) {
|
||||
|
||||
#if __WINDOWS__ && !__CYGWIN__
|
||||
void SetWindow(int Width, int Height) {
|
||||
COORD coord;
|
||||
coord.X = Width;
|
||||
coord.Y = Height;
|
||||
COORD coord;
|
||||
coord.X = Width;
|
||||
coord.Y = Height;
|
||||
|
||||
SMALL_RECT Rect;
|
||||
Rect.Top = 0;
|
||||
Rect.Left = 0;
|
||||
Rect.Bottom = Height - 1;
|
||||
Rect.Right = Width - 1;
|
||||
SMALL_RECT Rect;
|
||||
Rect.Top = 0;
|
||||
Rect.Left = 0;
|
||||
Rect.Bottom = Height - 1;
|
||||
Rect.Right = Width - 1;
|
||||
|
||||
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleScreenBufferSize(Handle, coord);
|
||||
SetConsoleWindowInfo(Handle, TRUE, &Rect);
|
||||
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleScreenBufferSize(Handle, coord);
|
||||
SetConsoleWindowInfo(Handle, TRUE, &Rect);
|
||||
}
|
||||
#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;
|
||||
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 (".");
|
||||
}
|
||||
if (!cmtfile) {
|
||||
char *fn;
|
||||
showcursor (core, true);
|
||||
fn = r_cons_input ("<commant-file> ");
|
||||
showcursor (core, false);
|
||||
if (fn && *fn) {
|
||||
cmtfile = strdup (fn);
|
||||
if (!comment || !*comment) {
|
||||
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);
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc);
|
||||
free (nc);
|
||||
}
|
||||
}
|
||||
free (fn);
|
||||
}
|
||||
if (cmtfile) {
|
||||
char *cwf = r_str_newf ("%s"R_SYS_DIR"%s", cwd, cmtfile);
|
||||
char *odata = r_file_slurp (cwf, NULL);
|
||||
char *data = r_core_editor (core, NULL, odata);
|
||||
r_file_dump (cwf, (const ut8*)data, -1, 0);
|
||||
free (data);
|
||||
free (odata);
|
||||
free (cwf);
|
||||
} else {
|
||||
eprintf ("NO CMTFILE\n");
|
||||
}
|
||||
free (comment);
|
||||
}
|
||||
|
||||
R_API int r_core_visual_cmd(RCore *core, int ch) {
|
||||
RAsmOp op;
|
||||
ut64 offset = core->offset;
|
||||
@ -887,6 +949,9 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
|
||||
} }
|
||||
showcursor (core, false);
|
||||
break;
|
||||
case ',':
|
||||
visual_comma (core);
|
||||
break;
|
||||
case 'T':
|
||||
if (r_sandbox_enable (0)) {
|
||||
eprintf ("sandbox not enabled\n");
|
||||
@ -1444,7 +1509,6 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
|
||||
ut64 addr = core->offset;
|
||||
if (curset) {
|
||||
addr += cursor;
|
||||
|
||||
r_core_seek (core, addr, 0);
|
||||
r_core_cmdf (core, "s 0x%"PFMT64x, addr);
|
||||
}
|
||||
|
@ -115,11 +115,14 @@ R_API int r_file_is_abspath(const char *file) {
|
||||
}
|
||||
|
||||
R_API char *r_file_abspath(const char *file) {
|
||||
if (strstr (file, "://") != NULL) {
|
||||
char *cwd, *ret = NULL;
|
||||
if (!file || !strcmp (file, ".") || !strcmp (file, "./")) {
|
||||
return r_sys_getdir ();
|
||||
}
|
||||
if (strstr (file, "://")) {
|
||||
return strdup (file);
|
||||
}
|
||||
char *ret = NULL;
|
||||
char *cwd = r_sys_getdir ();
|
||||
cwd = r_sys_getdir ();
|
||||
if (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) {
|
||||
ret = r_str_home (file+2);
|
||||
} else {
|
||||
@ -430,6 +433,7 @@ R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append) {
|
||||
eprintf ("Cannot open '%s' for writing\n", file);
|
||||
return R_FALSE;
|
||||
}
|
||||
if (len<0) len = strlen ((const char *)buf);
|
||||
ret = fwrite (buf, 1, len, fd) == len;
|
||||
if (!ret) eprintf ("r_file_dump: fwrite: error\n");
|
||||
fclose (fd);
|
||||
|
Loading…
Reference in New Issue
Block a user