Better ls. Add support for cd - and handle BR arm64 instruction

- Analysis with eobjmp has changed a bit, but its still buggy
This commit is contained in:
pancake 2015-08-18 02:44:59 +02:00
parent aa134787e9
commit 8a5723eb2a
4 changed files with 47 additions and 6 deletions

View File

@ -7,7 +7,7 @@
#define FCN_DEPTH 16
#define JMP_IS_EOB 0
#define JMP_IS_EOB 1
#define JMP_IS_EOB_RANGE 32
#define CALL_IS_EOB 0
@ -424,6 +424,14 @@ repeat:
}
break;
case R_ANAL_OP_TYPE_JMP:
if (anal->eobjmp) {
FITFCNSZ();
op.jump = UT64_MAX;
//recurseAt (op.jump);
//recurseAt (op.fail);
gotoBeachRet ();
return R_ANAL_RET_END;
}
if (anal->bbsplit) {
(void) r_anal_fcn_xref_add (anal, fcn, op.addr, op.jump, R_ANAL_REF_TYPE_CODE);
if (!overlapped) {

View File

@ -537,6 +537,10 @@ static void anop64 (RAnalOp *op, cs_insn *insn) {
op->jump = IMM64(1);
op->fail = addr+op->size;
break;
case ARM64_INS_BR:
op->type = R_ANAL_OP_TYPE_UJMP;
op->eob = 1;
break;
case ARM64_INS_B:
// BX LR == RET
if (insn->detail->arm64.operands[0].reg == ARM64_REG_LR) {

View File

@ -329,6 +329,7 @@ static int cmd_cmp_disasm(RCore *core, const char *input, int mode) {
}
static int cmd_cmp(void *data, const char *input) {
static char *oldcwd = NULL;
RCore *core = data;
ut64 val = UT64_MAX;
ut8 *buf;
@ -394,17 +395,37 @@ static int cmd_cmp(void *data, const char *input) {
case 'd':
while (input[1]==' ') input++;
if (input[1]) {
if (input[1]=='~' && input[2]=='/') {
if (!strcmp (input+1, "-")) {
if (oldcwd) {
char *newdir = oldcwd;
oldcwd = r_sys_getdir ();
if (r_sandbox_chdir (newdir)==-1) {
eprintf ("Cannot chdir to %s\n", newdir);
free (oldcwd);
oldcwd = newdir;
} else {
free (newdir);
}
} else {
// nothing to do here
}
} else if (input[1]=='~' && input[2]=='/') {
char *homepath = r_str_home (input+3);
if (homepath) {
if (*homepath)
if (*homepath) {
free (oldcwd);
oldcwd = r_sys_getdir ();
if (r_sandbox_chdir (homepath)==-1)
eprintf ("Cannot chdir to %s\n", homepath);
}
free (homepath);
} else eprintf ("Cannot find home\n");
} else {
if (r_sandbox_chdir (input+1)==-1)
free (oldcwd);
oldcwd = r_sys_getdir ();
if (r_sandbox_chdir (input+1)==-1) {
eprintf ("Cannot chdir to %s\n", input+1);
}
}
} else {
char* home = r_sys_getenv (R_SYS_HOME);

View File

@ -7,6 +7,8 @@
#define FMT_JSON 2
static int needs_newline = 0;
static void showfile(const int nth, const char *fpath, const char *name, int printfmt) {
#if __UNIX__
struct stat sb;
@ -31,7 +33,8 @@ static void showfile(const int nth, const char *fpath, const char *name, int pri
}
perm = isdir? 0755: 0644;
if (!printfmt) {
r_cons_printf ("%18s%s", nn, (nth%4)?" ":"\n");
needs_newline = ((nth+1)%4)? 1: 0;
r_cons_printf ("%18s%s", nn, needs_newline? " ": "\n");
free (nn);
return;
}
@ -95,6 +98,7 @@ R_API void r_core_syscmd_ls(const char *input) {
char *name;
char *dir;
int off;
int mode = 0;
if (!input || *input == '\0') return;
if (r_sandbox_enable (0)) {
eprintf ("Sandbox forbids listing directories\n");
@ -102,8 +106,10 @@ R_API void r_core_syscmd_ls(const char *input) {
}
if (input[1]==' ') {
if ((!strncmp (input+2, "-l", 2)) || (!strncmp (input+2, "-j", 2))) {
mode = 'l';
if (input[3]) {
printfmt = (input[3] == 'j') ? FMT_JSON : FMT_RAW;
mode = 'j';
path = input+4;
while (*path==' ') path++;
if (!*path) path = ".";
@ -156,16 +162,18 @@ R_API void r_core_syscmd_ls(const char *input) {
dir = r_str_concat (strdup (path), "/");
int nth = 0;
if (printfmt == FMT_JSON) r_cons_printf ("[");
needs_newline = 0;
r_list_foreach (files, iter, name) {
char *n = r_str_concat (strdup (dir), name);
if (!n) break;
if (r_str_glob(name, pattern)){
if (r_str_glob (name, pattern)) {
if (*n) showfile (nth, n, name, printfmt);
nth++;
}
free (n);
}
if (printfmt == FMT_JSON) r_cons_printf ("]");
if (needs_newline) r_cons_newline ();
free (dir);
free (d);
free (homepath);