Fix wao nocj and so? and rename swap-jcmp to recj

This commit is contained in:
pancake 2018-01-26 17:33:18 +01:00
parent e882b810bf
commit db76ab25af
4 changed files with 26 additions and 16 deletions

View File

@ -223,7 +223,6 @@ R_API bool core_anal_bbs(RCore *core, const char* input) {
int invalid_instruction_barrier = -20000;
bool debug = r_config_get_i (core->config, "cfg.debug");
block_list = r_list_new ();
if (!block_list) {
eprintf ("Failed to create block_list\n");

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2017 - pancake */
/* radare - LGPL - Copyright 2009-2018 - pancake */
#include "r_types.h"
#include "r_config.h"
@ -635,7 +635,9 @@ static int cmd_seek(void *data, const char *input) {
break;
}
case 'o': // "so"
{
if (input[1] == '?') {
eprintf ("Usage: so [n-instructions]\n");
} else {
int val = 0, ret, i, n = r_num_math (core->num, input + 1);
if (n == 0) {
n = 1;

View File

@ -1279,9 +1279,11 @@ static int cmd_write(void *data, const char *input) {
case 'a': // "wa"
switch (input[1]) {
case 'o': // "wao"
if (input[2] == ' ')
r_core_hack (core, input+3);
else r_core_hack_help (core);
if (input[2] == ' ') {
r_core_hack (core, input + 3);
} else {
r_core_hack_help (core);
}
break;
case ' ':
case '*':

View File

@ -16,9 +16,9 @@ void r_core_hack_help(const RCore *core) {
"wao", " ret1", "make the current opcode return 1",
"wao", " ret0", "make the current opcode return 0",
"wao", " retn", "make the current opcode return -1",
"wao", " un-cjmp", "remove conditional operation to branch",
"wao", " nocj", "remove conditional operation from branch (make it unconditional)",
"wao", " trap", "make the current opcode a trap",
"wao", " swap-cjmp", "swap conditional branch",
"wao", " recj", "reverse (swap) conditional branch instruction",
"NOTE:", "", "those operations are only implemented for x86 and arm atm.", //TODO
NULL
};
@ -94,7 +94,7 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) {
eprintf ("ARM jnz hack not supported\n");
return false;
}
} else if (!strcmp (op, "un-cjmp")) {
} else if (!strcmp (op, "nocj")) {
// TODO: drop conditional bit instead of that hack
if (bits == 16) {
switch (b[1]) {
@ -114,7 +114,7 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) {
eprintf ("ARM un-cjmp hack not supported\n");
return false;
}
} else if (!strcmp (op, "swap-cjmp")) {
} else if (!strcmp (op, "recj")) {
eprintf ("TODO: use jnz or jz\n");
return false;
} else if (!strcmp (op, "ret1")) {
@ -169,16 +169,23 @@ R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) {
eprintf ("Current opcode is not conditional\n");
return false;
}
} else if (!strcmp (op, "un-cjmp")) {
if (b[0] >= 0x70 && b[0] <= 0x7f) {
r_core_cmd0 (core, "wx eb\n");
} else if (!strcmp (op, "nocj")) {
if (*b == 0xf) {
r_core_cmd0 (core, "wx 90e9");
} else if (b[0] >= 0x70 && b[0] <= 0x7f) {
r_core_cmd0 (core, "wx eb");
} else {
eprintf ("Current opcode is not conditional\n");
return false;
}
} else if (!strcmp (op, "swap-cjmp")) {
if (b[0] < 0x80 && b[0] >= 0x70){ // jo, jno, jb, jae, je, jne, jbe, ja, js, jns
r_core_cmdf (core, "wx %x\n", (b[0]%2)? b[0] - 1: b[0] + 1);
} else if (!strcmp (op, "recj")) {
int of = *b == 0xf;
if (b[of] < 0x80 && b[of] >= 0x70) { // jo, jno, jb, jae, je, jne, jbe, ja, js, jns
if (of) {
r_core_cmdf (core, "wx 0f%x\n", (b[1]%2)? b[1] - 1: b[1] + 1);
} else {
r_core_cmdf (core, "wx %x\n", (b[0]%2)? b[0] - 1: b[0] + 1);
}
} else {
eprintf ("Invalid opcode\n");
return false;