12 const char *help_msg[] = {
13 "wao",
" [op]",
"performs a modification on current opcode",
14 "wao",
" nop",
"nop current opcode",
15 "wao",
" jinf",
"assemble an infinite loop",
16 "wao",
" jz",
"make current opcode conditional (zero)",
17 "wao",
" jnz",
"make current opcode conditional (not zero)",
18 "wao",
" ret1",
"make the current opcode return 1",
19 "wao",
" ret0",
"make the current opcode return 0",
20 "wao",
" retn",
"make the current opcode return -1",
21 "wao",
" nocj",
"remove conditional operation from branch (make it unconditional)",
22 "wao",
" trap",
"make the current opcode a trap",
23 "wao",
" recj",
"reverse (swap) conditional branch instruction",
24 "WIP:",
"",
"not all archs are supported and not all commands work on all archs",
31 if (!strcmp(
op,
"nop")) {
33 }
else if (!strcmp(
op,
"ret2")) {
35 }
else if (!strcmp(
op,
"jinf")) {
37 }
else if (!strcmp(
op,
"ret1")) {
39 }
else if (!strcmp(
op,
"ret0")) {
42 eprintf(
"Unsupported operation '%s'\n",
op);
49 if (!strcmp(
op,
"nop")) {
51 }
else if (!strcmp(
op,
"ret")) {
53 }
else if (!strcmp(
op,
"trap")) {
55 }
else if (!strcmp(
op,
"jz")) {
56 eprintf(
"ARM jz hack not supported\n");
58 }
else if (!strcmp(
op,
"jinf")) {
60 }
else if (!strcmp(
op,
"jnz")) {
61 eprintf(
"ARM jnz hack not supported\n");
63 }
else if (!strcmp(
op,
"nocj")) {
64 eprintf(
"ARM jnz hack not supported\n");
66 }
else if (!strcmp(
op,
"recj")) {
67 eprintf(
"TODO: use jnz or jz\n");
69 }
else if (!strcmp(
op,
"ret1")) {
71 }
else if (!strcmp(
op,
"ret0")) {
73 }
else if (!strcmp(
op,
"retn")) {
86 if (!strcmp(
op,
"nop")) {
87 const int nopsize = (
bits == 16) ? 2 : 4;
88 const char *nopcode = (
bits == 16) ?
"00bf" :
"0000a0e1";
94 eprintf(
"Invalid nopcode size\n");
102 for (
i = 0;
i <
len;
i += nopsize) {
108 }
else if (!strcmp(
op,
"jinf")) {
110 }
else if (!strcmp(
op,
"trap")) {
112 }
else if (!strcmp(
op,
"jz")) {
125 eprintf(
"Current opcode is not conditional\n");
129 eprintf(
"ARM jz hack not supported\n");
132 }
else if (!strcmp(
op,
"jnz")) {
145 eprintf(
"Current opcode is not conditional\n");
149 eprintf(
"ARM jnz hack not supported\n");
152 }
else if (!strcmp(
op,
"nocj")) {
165 eprintf(
"Current opcode is not conditional\n");
169 eprintf(
"ARM un-cjmp hack not supported\n");
172 }
else if (!strcmp(
op,
"recj")) {
173 eprintf(
"TODO: use jnz or jz\n");
175 }
else if (!strcmp(
op,
"ret1")) {
181 }
else if (!strcmp(
op,
"ret0")) {
187 }
else if (!strcmp(
op,
"retn")) {
194 eprintf(
"Invalid operation\n");
203 if (!strcmp(
op,
"nop")) {
217 }
else if (!strcmp(
op,
"trap")) {
219 }
else if (!strcmp(
op,
"jz")) {
223 eprintf(
"Current opcode is not conditional\n");
226 }
else if (!strcmp(
op,
"jinf")) {
228 }
else if (!strcmp(
op,
"jnz")) {
232 eprintf(
"Current opcode is not conditional\n");
235 }
else if (!strcmp(
op,
"nocj")) {
238 }
else if (
b[0] >= 0x70 &&
b[0] <= 0x7f) {
241 eprintf(
"Current opcode is not conditional\n");
244 }
else if (!strcmp(
op,
"recj")) {
246 if (
b[0] < 0x80 &&
b[0] >= 0x70) {
247 char *opcode =
rz_str_newf(
"%x", (
b[0] % 2) ?
b[0] - 1 :
b[0] + 1);
250 }
else if (
is_near &&
b[1] < 0x90 &&
b[1] >= 0x80) {
251 char *opcode =
rz_str_newf(
"0f%x", (
b[1] % 2) ?
b[1] - 1 :
b[1] + 1);
255 eprintf(
"Invalid conditional jump opcode\n");
258 }
else if (!strcmp(
op,
"ret1")) {
260 }
else if (!strcmp(
op,
"ret0")) {
262 }
else if (!strcmp(
op,
"retn")) {
285 const int asmbits = core->
rasm->
bits;
290 if (strstr(asmarch,
"x86")) {
292 }
else if (strstr(asmarch,
"dalvik")) {
294 }
else if (strstr(asmarch,
"arm")) {
301 eprintf(
"TODO: write hacks are only for x86\n");
static int is_near(const RzANode *n, int x, int y, int is_next)
static int analop(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
int bits(struct state *s, int need)
RZ_API int rz_core_write_hexpair(RzCore *core, ut64 addr, const char *pairs)
RZ_API int rz_core_write_assembly(RzCore *core, ut64 addr, RZ_NONNULL const char *instructions)
Assembles instructions and writes the resulting data at the given offset.
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API bool rz_core_hack_dalvik(RzCore *core, const char *op, const RzAnalysisOp *analop)
RZ_API bool rz_core_hack_arm64(RzCore *core, const char *op, const RzAnalysisOp *analop)
RZ_API void rz_core_hack_help(const RzCore *core)
RZ_API bool rz_core_hack(RzCore *core, const char *op)
Write/Modify instructions at current offset based on op.
RZ_API bool rz_core_hack_x86(RzCore *core, const char *op, const RzAnalysisOp *analop)
RZ_API bool rz_core_hack_arm(RzCore *core, const char *op, const RzAnalysisOp *analop)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
@ RZ_ANALYSIS_OP_MASK_BASIC
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1