Remove RzIO brainfuck/rzweb/rzpipe & RzDebug brainfuck (#5810)
This commit is contained in:
parent
2fe648f541
commit
d7b2f85c89
12 changed files with 24 additions and 1253 deletions
|
|
@ -1,37 +0,0 @@
|
|||
Brainfuck support for rizin
|
||||
========================
|
||||
|
||||
Plugins for brainfuck:
|
||||
- `asm.bf` - brainfuck assembler and disassembler
|
||||
- `debug.bf` - debugger using bfvm
|
||||
- `analysis.bf` - code analysis for brainfuck
|
||||
- `bp.bf` - breakpoints support (experimental)
|
||||
|
||||
To debug a brainfuck program:
|
||||
|
||||
rizin -D bf bfdbg:///tmp/bf
|
||||
|
||||
> dc # continue
|
||||
> x@scr # show screen buffer contents
|
||||
|
||||
The debugger creates virtual sections for code, data, screen and input.
|
||||
|
||||
TODO
|
||||
----
|
||||
- add support for comments, ignore invalid instructions as nops
|
||||
- enhance io and debugger plugins to generate sections and set arch opts
|
||||
|
||||
Hello World
|
||||
===========
|
||||
|
||||
```
|
||||
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]
|
||||
>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++
|
||||
.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
|
||||
```
|
||||
|
||||
```
|
||||
$ cat << EOF
|
||||
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.
|
||||
EOF
|
||||
```
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
debug_plugins_list = [
|
||||
'bf',
|
||||
'bochs',
|
||||
'dmp',
|
||||
'gdb',
|
||||
|
|
@ -33,10 +32,8 @@ rz_debug_sources = [
|
|||
'serialize_debug.c',
|
||||
'snap.c',
|
||||
'trace.c',
|
||||
'p/bfvm.c',
|
||||
'p/common_windows.c',
|
||||
'p/common_winkd.c',
|
||||
'p/debug_bf.c',
|
||||
'p/debug_bochs.c',
|
||||
'p/debug_dmp.c',
|
||||
'p/debug_gdb.c',
|
||||
|
|
|
|||
|
|
@ -1,315 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2008-2011 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include "bfvm.h"
|
||||
|
||||
static ut8 bfvm_op(BfvmCPU *c) {
|
||||
// XXX: this is slow :(
|
||||
ut8 buf[4] = { 0 };
|
||||
if (c && c->iob.read_at && !c->iob.read_at(c->iob.io, c->eip, buf, 4)) {
|
||||
return 0xff;
|
||||
}
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
RZ_API int bfvm_in_trap(BfvmCPU *c) {
|
||||
switch (bfvm_op(c)) {
|
||||
case 0x00:
|
||||
case 0xcc:
|
||||
case 0xff:
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RZ_API void bfvm_reset(BfvmCPU *c) {
|
||||
memset(c->mem, '\0', c->size);
|
||||
memset(c->input_buf, '\0', c->input_size);
|
||||
memset(c->screen_buf, '\0', c->screen_size);
|
||||
c->base = BFVM_DATA_ADDR;
|
||||
c->input = BFVM_INPUT_ADDR;
|
||||
c->input_idx = 0;
|
||||
c->screen = BFVM_SCREEN_ADDR;
|
||||
c->screen_idx = 0;
|
||||
c->eip = 0; // TODO look forward nops
|
||||
c->ptr = 0;
|
||||
c->esp = c->base;
|
||||
}
|
||||
|
||||
RZ_API int bfvm_init(BfvmCPU *c, ut32 size, int circular) {
|
||||
memset(c, '\0', sizeof(BfvmCPU));
|
||||
|
||||
/* data */
|
||||
c->mem = (ut8 *)malloc(size);
|
||||
if (!c->mem) {
|
||||
return 0;
|
||||
}
|
||||
memset(c->mem, '\0', size);
|
||||
|
||||
/* setup */
|
||||
c->circular = circular;
|
||||
c->size = size;
|
||||
|
||||
// TODO: use RzBuffer or so here.. this is spagueti
|
||||
/* screen */
|
||||
c->screen = BFVM_SCREEN_ADDR;
|
||||
c->screen_size = BFVM_SCREEN_SIZE;
|
||||
c->screen_buf = (ut8 *)malloc(c->screen_size);
|
||||
memset(c->screen_buf, '\0', c->screen_size);
|
||||
|
||||
/* input */
|
||||
c->input_size = BFVM_INPUT_SIZE;
|
||||
c->input_buf = (ut8 *)malloc(c->input_size);
|
||||
bfvm_reset(c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
RZ_API BfvmCPU *bfvm_new(RzIOBind *iob) {
|
||||
BfvmCPU *c = RZ_NEW0(BfvmCPU);
|
||||
bfvm_init(c, 4096, 1);
|
||||
memcpy(&c->iob, iob, sizeof(c->iob));
|
||||
return c;
|
||||
}
|
||||
|
||||
RZ_API BfvmCPU *bfvm_free(BfvmCPU *c) {
|
||||
free(c->mem);
|
||||
c->mem = 0;
|
||||
free(c->screen_buf);
|
||||
c->screen_buf = 0;
|
||||
free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API ut8 *bfvm_get_ptr_at(BfvmCPU *c, ut64 at) {
|
||||
if (at >= c->base) {
|
||||
at -= c->base;
|
||||
} else if (at >= c->size) {
|
||||
at = c->circular ? 0 : c->size - 1;
|
||||
}
|
||||
return c->mem + at;
|
||||
}
|
||||
|
||||
RZ_API ut8 *bfvm_get_ptr(BfvmCPU *c) {
|
||||
// return bfvm_cpu.mem;
|
||||
return bfvm_get_ptr_at(c, c->ptr);
|
||||
}
|
||||
|
||||
RZ_API ut8 bfvm_get(BfvmCPU *c) {
|
||||
ut8 *ptr = bfvm_get_ptr(c);
|
||||
return ptr ? *ptr : 0;
|
||||
}
|
||||
|
||||
RZ_API void bfvm_inc(BfvmCPU *c) {
|
||||
ut8 *mem = bfvm_get_ptr(c);
|
||||
if (mem != NULL) {
|
||||
mem[0]++;
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API void bfvm_dec(BfvmCPU *c) {
|
||||
ut8 *mem = bfvm_get_ptr(c);
|
||||
if (mem != NULL) {
|
||||
mem[0]--;
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API int bfvm_reg_set(BfvmCPU *c, const char *str) {
|
||||
char *ptr = strchr(str, ' ');
|
||||
if (!ptr) {
|
||||
return 0;
|
||||
}
|
||||
if (strstr(str, "eip")) {
|
||||
c->eip = rz_num_math(NULL, ptr + 1);
|
||||
} else if (strstr(str, "esp")) {
|
||||
c->esp = rz_num_math(NULL, ptr + 1);
|
||||
} else if (strstr(str, "ptr")) {
|
||||
c->ptr = rz_num_math(NULL, ptr + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* screen and input */
|
||||
RZ_API void bfvm_peek(BfvmCPU *c) {
|
||||
int idx = c->input_idx;
|
||||
ut8 *ptr = bfvm_get_ptr(c);
|
||||
|
||||
if (idx >= c->input_size) {
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
if (ptr) {
|
||||
*ptr = c->input_buf[idx];
|
||||
c->input_idx = idx + 1;
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API void bfvm_poke(BfvmCPU *c) {
|
||||
int idx = c->screen_idx;
|
||||
c->screen_buf[idx] = bfvm_get(c);
|
||||
c->screen_idx = idx + 1;
|
||||
}
|
||||
|
||||
RZ_API int bfvm_trace_op(BfvmCPU *c, ut8 op) {
|
||||
ut8 g;
|
||||
switch (op) {
|
||||
case '\0':
|
||||
eprintf(" ; trap (%02x)\n", op);
|
||||
// fallthrough
|
||||
case '.':
|
||||
case ',':
|
||||
case '+':
|
||||
case '-':
|
||||
case '>':
|
||||
case '<':
|
||||
eprintf("%c", op);
|
||||
break;
|
||||
case '[':
|
||||
case ']':
|
||||
g = bfvm_get(c);
|
||||
eprintf("%c ; [ptr] = %d\n", op, g);
|
||||
if (g != 0) {
|
||||
eprintf("[");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define T if (c->trace)
|
||||
/* debug */
|
||||
RZ_API int bfvm_step(BfvmCPU *c, int over) {
|
||||
ut8 op2, op = bfvm_op(c);
|
||||
|
||||
do {
|
||||
T bfvm_trace_op(c, op);
|
||||
switch (op) {
|
||||
case '\0':
|
||||
/* trap */
|
||||
return 1;
|
||||
case '.':
|
||||
// bfvm_get_ptr (c);
|
||||
bfvm_poke(c);
|
||||
break;
|
||||
case ',':
|
||||
bfvm_peek(c);
|
||||
/* TODO read */
|
||||
break;
|
||||
case '+':
|
||||
bfvm_inc(c);
|
||||
break;
|
||||
case '-':
|
||||
bfvm_dec(c);
|
||||
break;
|
||||
case '>':
|
||||
c->ptr++;
|
||||
break;
|
||||
case '<':
|
||||
c->ptr--;
|
||||
break;
|
||||
case '[':
|
||||
break;
|
||||
case ']':
|
||||
if (bfvm_get(c) != 0) {
|
||||
do {
|
||||
/* control underflow */
|
||||
if (c->eip < (c->eip - 1)) {
|
||||
c->eip = 0;
|
||||
break;
|
||||
}
|
||||
c->eip--;
|
||||
} while (bfvm_op(c) != '[');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
c->eip++;
|
||||
op2 = bfvm_op(c);
|
||||
} while (over && op == op2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
RZ_API int bfvm_contsc(BfvmCPU *c) {
|
||||
c->breaked = 0;
|
||||
while (!c->breaked) {
|
||||
bfvm_step(c, 0);
|
||||
if (bfvm_in_trap(c)) {
|
||||
eprintf("Trap instruction at 0x%08" PFMT64x "\n", c->eip);
|
||||
break;
|
||||
}
|
||||
switch (bfvm_op(c)) {
|
||||
case ',':
|
||||
eprintf("contsc: read from input trap\n");
|
||||
c->breaked = 1;
|
||||
continue;
|
||||
case '.':
|
||||
eprintf("contsc: print to screen trap\n");
|
||||
c->breaked = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RZ_API int bfvm_cont(BfvmCPU *c, ut64 until) {
|
||||
c->breaked = 0;
|
||||
while (!c->breaked && c->eip != until) {
|
||||
bfvm_step(c, 0);
|
||||
if (bfvm_in_trap(c)) {
|
||||
eprintf("Trap instruction at 0x%" PFMT64x "\n", c->eip);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RZ_API int bfvm_trace(BfvmCPU *c, ut64 until) {
|
||||
c->trace = 1;
|
||||
bfvm_cont(c, until);
|
||||
c->trace = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
RZ_API void bfvm_show_regs(BfvmCPU *c, int rad) {
|
||||
if (rad) {
|
||||
eprintf("fs regs\n");
|
||||
eprintf("f eip @ 0x%08" PFMT64x "\n", (ut64)c->eip);
|
||||
eprintf("f esp @ 0x%08" PFMT64x "\n", (ut64)c->esp);
|
||||
eprintf("f ptr @ 0x%08" PFMT64x "\n", (ut64)c->ptr + c->base);
|
||||
eprintf("fs *\n");
|
||||
} else {
|
||||
ut8 ch = bfvm_get(c);
|
||||
eprintf(" eip 0x%08" PFMT64x " esp 0x%08" PFMT64x "\n",
|
||||
(ut64)c->eip, (ut64)c->esp);
|
||||
eprintf(" ptr 0x%08x [ptr] %d = 0x%02x '%c'\n",
|
||||
(ut32)c->ptr, ch, ch, IS_PRINTABLE(ch) ? ch : ' ');
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API void bfvm_maps(BfvmCPU *c, int rad) {
|
||||
if (rad) {
|
||||
eprintf("fs sections\n");
|
||||
eprintf("e cmd.vprompt=px@screen\n");
|
||||
eprintf("f section_code @ 0x%08" PFMT64x "\n", (ut64)BFVM_CODE_ADDR);
|
||||
eprintf("f section_code_end @ 0x%08" PFMT64x "\n", (ut64)BFVM_CODE_ADDR + BFVM_CODE_SIZE);
|
||||
eprintf("f section_data @ 0x%08" PFMT64x "\n", (ut64)c->base);
|
||||
eprintf("f section_data_end @ 0x%08" PFMT64x "\n", (ut64)c->base + c->size);
|
||||
eprintf("f screen @ 0x%08" PFMT64x "\n", (ut64)c->screen);
|
||||
eprintf("f section_screen @ 0x%08" PFMT64x "\n", (ut64)c->screen);
|
||||
eprintf("f section_screen_end @ 0x%08" PFMT64x "\n", (ut64)c->screen + c->screen_size);
|
||||
eprintf("f input @ 0x%08" PFMT64x "\n", (ut64)c->input);
|
||||
eprintf("f section_input @ 0x%08" PFMT64x "\n", (ut64)c->input);
|
||||
eprintf("f section_input_end @ 0x%08" PFMT64x "\n", (ut64)c->input + c->input_size);
|
||||
eprintf("fs *\n");
|
||||
} else {
|
||||
eprintf("0x%08" PFMT64x " - 0x%08" PFMT64x " rwxu 0x%08" PFMT64x " .code\n",
|
||||
(ut64)0, (ut64)c->size, (ut64)c->size);
|
||||
eprintf("0x%08" PFMT64x " - 0x%08" PFMT64x " rw-- 0x%08" PFMT64x " .data\n",
|
||||
(ut64)c->base, (ut64)(c->base + c->size), (ut64)c->size);
|
||||
eprintf("0x%08" PFMT64x " - 0x%08" PFMT64x " rw-- 0x%08" PFMT64x " .screen\n",
|
||||
(ut64)c->screen, (ut64)(c->screen + c->screen_size), (ut64)c->screen_size);
|
||||
eprintf("0x%08" PFMT64x " - 0x%08" PFMT64x " rw-- 0x%08" PFMT64x " .input\n",
|
||||
(ut64)c->input, (ut64)(c->input + c->input_size), (ut64)c->input_size);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2008-2011 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#ifndef _R_BFVM_INCLUDE_
|
||||
#define _R_BFVM_INCLUDE_
|
||||
|
||||
#include <rz_io.h>
|
||||
#include <rz_util.h>
|
||||
|
||||
#define BFVM_SCREEN_ADDR 0x50000
|
||||
#define BFVM_SCREEN_SIZE 4096
|
||||
#define BFVM_INPUT_ADDR 0x10000
|
||||
#define BFVM_INPUT_SIZE 4096
|
||||
#define BFVM_DATA_ADDR 0xd00000
|
||||
#define BFVM_DATA_SIZE 4096
|
||||
#define BFVM_CODE_ADDR 0
|
||||
#define BFVM_CODE_SIZE 4096 /* XXX */
|
||||
|
||||
typedef struct bfvm_cpu_t {
|
||||
ut64 eip;
|
||||
ut64 esp;
|
||||
int ptr;
|
||||
int trace;
|
||||
int breaked;
|
||||
ut64 base;
|
||||
ut8 *mem;
|
||||
ut32 size;
|
||||
ut64 screen;
|
||||
int screen_idx;
|
||||
int screen_size;
|
||||
ut8 *screen_buf;
|
||||
ut64 input;
|
||||
int input_idx;
|
||||
int input_size;
|
||||
ut8 *input_buf;
|
||||
int circular; /* circular memory */
|
||||
RzIOBind iob;
|
||||
} BfvmCPU;
|
||||
|
||||
#ifdef RZ_API
|
||||
RZ_API BfvmCPU *bfvm_new(RzIOBind *iob);
|
||||
RZ_API BfvmCPU *bfvm_free(BfvmCPU *c);
|
||||
RZ_API int bfvm_step(BfvmCPU *c, int over);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,211 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2022 deroad <wargio@libero.it>
|
||||
// SPDX-FileCopyrightText: 2011-2019 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_debug.h>
|
||||
#undef RZ_API
|
||||
#define RZ_API static inline
|
||||
#include "bfvm.c"
|
||||
|
||||
typedef struct {
|
||||
int desc;
|
||||
ut8 *buf;
|
||||
ut32 size;
|
||||
BfvmCPU *bfvm;
|
||||
} RzIOBdescbg;
|
||||
|
||||
static bool brainfuck_is_valid_io(RzDebug *dbg) {
|
||||
if (!dbg->iob.io) {
|
||||
return false;
|
||||
}
|
||||
RzIODesc *d = dbg->iob.io->desc;
|
||||
if (d && d->plugin && d->plugin->name) {
|
||||
if (!strcmp("bfdbg", d->plugin->name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
eprintf("error: the iodesc data is not brainfuck friendly\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool brainfuck_step_over(RzDebug *dbg) {
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
int op, oop = 0;
|
||||
for (;;) {
|
||||
op = bfvm_op(o->bfvm);
|
||||
if (oop != 0 && op != oop) {
|
||||
break;
|
||||
}
|
||||
if (bfvm_in_trap(o->bfvm)) {
|
||||
break;
|
||||
}
|
||||
bfvm_step(o->bfvm, 0);
|
||||
oop = op;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool brainfuck_step(RzDebug *dbg) {
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
bfvm_step(o->bfvm, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void reg_set(RzReg *reg, const char *name, ut32 value) {
|
||||
RzRegItem *item = rz_reg_get(reg, name, -1);
|
||||
rz_reg_set_value(reg, item, value);
|
||||
}
|
||||
|
||||
static ut32 reg_get(RzReg *reg, const char *name) {
|
||||
RzRegItem *item = rz_reg_get(reg, name, -1);
|
||||
return rz_reg_get_value(reg, item);
|
||||
}
|
||||
|
||||
static bool brainfuck_sync_registers(RzDebug *dbg, RzReg *reg, bool to_debugger) {
|
||||
rz_return_val_if_fail(dbg && reg, false);
|
||||
if (!brainfuck_is_valid_io(dbg) || !dbg->iob.io->desc->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
|
||||
if (to_debugger) {
|
||||
o->bfvm->eip = reg_get(reg, "pc");
|
||||
o->bfvm->ptr = reg_get(reg, "ptr");
|
||||
o->bfvm->esp = reg_get(reg, "esp");
|
||||
o->bfvm->screen = reg_get(reg, "scr");
|
||||
o->bfvm->screen_idx = reg_get(reg, "scri");
|
||||
o->bfvm->input = reg_get(reg, "inp");
|
||||
o->bfvm->input_idx = reg_get(reg, "inpi");
|
||||
o->bfvm->base = reg_get(reg, "mem");
|
||||
o->bfvm->ptr = reg_get(reg, "memi");
|
||||
} else {
|
||||
reg_set(reg, "pc", o->bfvm->eip);
|
||||
reg_set(reg, "ptr", o->bfvm->ptr);
|
||||
reg_set(reg, "esp", o->bfvm->esp);
|
||||
reg_set(reg, "scr", o->bfvm->screen);
|
||||
reg_set(reg, "scri", o->bfvm->screen_idx);
|
||||
reg_set(reg, "inp", o->bfvm->input);
|
||||
reg_set(reg, "inpi", o->bfvm->input_idx);
|
||||
reg_set(reg, "mem", o->bfvm->base);
|
||||
reg_set(reg, "memi", o->bfvm->ptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int brainfuck_continue(RzDebug *dbg, int pid, int tid, int sig) {
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
bfvm_cont(o->bfvm, UT64_MAX);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int brainfuck_continue_syscall(RzDebug *dbg, int pid, int num) {
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
bfvm_contsc(o->bfvm);
|
||||
return true;
|
||||
}
|
||||
|
||||
static RzDebugReasonType brainfuck_wait(RzDebug *dbg, int pid) {
|
||||
/* do nothing */
|
||||
return RZ_DEBUG_REASON_NONE;
|
||||
}
|
||||
|
||||
static int brainfuck_attach(RzDebug *dbg, int pid) {
|
||||
if (!brainfuck_is_valid_io(dbg)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int brainfuck_detach(RzDebug *dbg, int pid) {
|
||||
// reset vm?
|
||||
return true;
|
||||
}
|
||||
|
||||
static char *brainfuck_reg_profile(RzDebug *dbg) {
|
||||
return rz_str_dup(
|
||||
"=PC pc\n"
|
||||
"=SP esp\n"
|
||||
"=BP ptr\n"
|
||||
"=A0 mem\n"
|
||||
"gpr pc .32 0 0\n"
|
||||
"gpr ptr .32 4 0\n"
|
||||
"gpr esp .32 8 0\n"
|
||||
"gpr scr .32 12 0\n"
|
||||
"gpr scri .32 16 0\n"
|
||||
"gpr inp .32 20 0\n"
|
||||
"gpr inpi .32 24 0\n"
|
||||
"gpr mem .32 28 0\n"
|
||||
"gpr memi .32 32 0\n");
|
||||
}
|
||||
|
||||
static int brainfuck_breakpoint(struct rz_bp_t *bp, RzBreakpointItem *b, bool set) {
|
||||
// rz_io_system (dbg->iob.io, "db");
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool brainfuck_kill(RzDebug *dbg, int pid, int tid, int sig) {
|
||||
if (!brainfuck_is_valid_io(dbg)) {
|
||||
return false;
|
||||
}
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
if (o) {
|
||||
bfvm_reset(o->bfvm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static RzList /*<RzDebugMap *>*/ *brainfuck_map_get(RzDebug *dbg) {
|
||||
if (!brainfuck_is_valid_io(dbg)) {
|
||||
return false;
|
||||
}
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
BfvmCPU *c = o->bfvm;
|
||||
RzList *list = rz_list_newf((RzListFree)rz_debug_map_free);
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
rz_list_append(list, rz_debug_map_new("code", 0, 4096, 6, 0));
|
||||
rz_list_append(list, rz_debug_map_new("memory", c->base, c->base + c->size, 6, 0));
|
||||
rz_list_append(list, rz_debug_map_new("screen", c->screen, c->screen + c->screen_size, 6, 0));
|
||||
rz_list_append(list, rz_debug_map_new("input", c->input, c->input + c->input_size, 6, 0));
|
||||
return list;
|
||||
}
|
||||
|
||||
static int brainfuck_stop(RzDebug *dbg) {
|
||||
if (!brainfuck_is_valid_io(dbg)) {
|
||||
return false;
|
||||
}
|
||||
RzIOBdescbg *o = dbg->iob.io->desc->data;
|
||||
BfvmCPU *c = o->bfvm;
|
||||
c->breaked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
RzDebugPlugin rz_debug_plugin_bf = {
|
||||
.name = "bf",
|
||||
.arch = "bf",
|
||||
.license = "LGPL3",
|
||||
.bits = RZ_SYS_BITS_32 | RZ_SYS_BITS_64,
|
||||
.step = brainfuck_step,
|
||||
.step_over = brainfuck_step_over,
|
||||
.cont = brainfuck_continue,
|
||||
.contsc = brainfuck_continue_syscall,
|
||||
.attach = &brainfuck_attach,
|
||||
.detach = &brainfuck_detach,
|
||||
.wait = &brainfuck_wait,
|
||||
.stop = brainfuck_stop,
|
||||
.kill = brainfuck_kill,
|
||||
.breakpoint = &brainfuck_breakpoint,
|
||||
.sync_registers = &brainfuck_sync_registers,
|
||||
.reg_profile = brainfuck_reg_profile,
|
||||
.map_get = brainfuck_map_get,
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct rizin_plugin = {
|
||||
.type = RZ_LIB_TYPE_DBG,
|
||||
.data = &rz_debug_plugin_bf,
|
||||
.version = RZ_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
io_plugins_list = [
|
||||
'ar',
|
||||
'fd',
|
||||
'bfdbg',
|
||||
'bochs',
|
||||
'debug',
|
||||
'default',
|
||||
|
|
@ -16,8 +15,6 @@ io_plugins_list = [
|
|||
'null',
|
||||
'procpid',
|
||||
'ptrace',
|
||||
'rzpipe',
|
||||
'rzweb',
|
||||
'self',
|
||||
'shm',
|
||||
'sparse',
|
||||
|
|
@ -59,7 +56,6 @@ rz_io_sources = [
|
|||
'serialize_io.c',
|
||||
'p/io_ar.c',
|
||||
'p/io_fd.c',
|
||||
'p/io_bfdbg.c',
|
||||
'p/io_bochs.c',
|
||||
'p/io_debug.c',
|
||||
'p/io_dmp.c',
|
||||
|
|
@ -73,8 +69,6 @@ rz_io_sources = [
|
|||
'p/io_null.c',
|
||||
'p/io_procpid.c',
|
||||
'p/io_ptrace.c',
|
||||
'p/io_rzpipe.c',
|
||||
'p/io_rzweb.c',
|
||||
'p/io_self.c',
|
||||
'p/io_shm.c',
|
||||
'p/io_sparse.c',
|
||||
|
|
|
|||
|
|
@ -1,218 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2011-2013 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_io.h>
|
||||
#include <rz_lib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#undef RZ_API
|
||||
#define RZ_API static inline
|
||||
#include "../debug/p/bfvm.h"
|
||||
#include "../debug/p/bfvm.c"
|
||||
|
||||
#include "rz_io_plugins.h"
|
||||
|
||||
typedef struct {
|
||||
ut32 magic;
|
||||
int fd;
|
||||
ut8 *buf;
|
||||
ut32 size;
|
||||
BfvmCPU *bfvm;
|
||||
} RzIOBfdbg;
|
||||
|
||||
#define RzIOBFDBG_FD(x) (((RzIOBfdbg *)(x)->data)->fd)
|
||||
#define RzIOBFDBG_SZ(x) (((RzIOBfdbg *)(x)->data)->size)
|
||||
#define RzIOBFDBG_BUF(x) (((RzIOBfdbg *)(x)->data)->buf)
|
||||
|
||||
static inline int is_in_screen(ut64 off, BfvmCPU *c) {
|
||||
return (off >= c->screen && off < c->screen + c->screen_size);
|
||||
}
|
||||
|
||||
static inline int is_in_input(ut64 off, BfvmCPU *c) {
|
||||
return (off >= c->input && off < c->input + c->input_size);
|
||||
}
|
||||
|
||||
static inline int is_in_base(ut64 off, BfvmCPU *c) {
|
||||
return (off >= c->base && off < c->base + c->size);
|
||||
}
|
||||
|
||||
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, size_t count) {
|
||||
RzIOBfdbg *riom;
|
||||
int sz;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
riom = fd->data;
|
||||
/* data base buffer */
|
||||
if (is_in_base(io->off, riom->bfvm)) {
|
||||
int n = io->off - riom->bfvm->base;
|
||||
if (n > count) {
|
||||
count = n;
|
||||
}
|
||||
memcpy(riom->bfvm->mem + n, buf, count);
|
||||
return count;
|
||||
}
|
||||
/* screen buffer */
|
||||
if (is_in_screen(io->off, riom->bfvm)) {
|
||||
int n = io->off - riom->bfvm->screen;
|
||||
if (n > count) {
|
||||
count = riom->bfvm->screen_size - n;
|
||||
}
|
||||
memcpy(riom->bfvm->screen_buf + n, buf, count);
|
||||
return count;
|
||||
}
|
||||
/* input buffer */
|
||||
if (is_in_input(io->off, riom->bfvm)) {
|
||||
int n = io->off - riom->bfvm->input;
|
||||
if (n > count) {
|
||||
count = riom->bfvm->input_size - n;
|
||||
}
|
||||
memcpy(riom->bfvm->input_buf + n, buf, count);
|
||||
return count;
|
||||
}
|
||||
/* read from file */
|
||||
sz = RzIOBFDBG_SZ(fd);
|
||||
if (io->off + count >= sz) {
|
||||
count = sz - io->off;
|
||||
}
|
||||
if (io->off >= sz) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(RzIOBFDBG_BUF(fd) + io->off, buf, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, size_t count) {
|
||||
RzIOBfdbg *riom;
|
||||
int sz;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
riom = fd->data;
|
||||
/* data base buffer */
|
||||
if (is_in_base(io->off, riom->bfvm)) {
|
||||
int n = io->off - riom->bfvm->base;
|
||||
if (n > count) {
|
||||
count = n;
|
||||
}
|
||||
memcpy(buf, riom->bfvm->mem + n, count);
|
||||
return count;
|
||||
}
|
||||
/* screen buffer */
|
||||
if (is_in_screen(io->off, riom->bfvm)) {
|
||||
int n = io->off - riom->bfvm->screen;
|
||||
if (n > count) {
|
||||
count = riom->bfvm->screen_size - n;
|
||||
}
|
||||
memcpy(buf, riom->bfvm->screen_buf + n, count);
|
||||
return count;
|
||||
}
|
||||
/* input buffer */
|
||||
if (is_in_input(io->off, riom->bfvm)) {
|
||||
int n = io->off - riom->bfvm->input;
|
||||
if (n > count) {
|
||||
count = riom->bfvm->input_size - n;
|
||||
}
|
||||
memcpy(buf, riom->bfvm->input_buf + n, count);
|
||||
return count;
|
||||
}
|
||||
/* read from file */
|
||||
sz = RzIOBFDBG_SZ(fd);
|
||||
if (io->off + count >= sz) {
|
||||
count = sz - io->off;
|
||||
}
|
||||
if (io->off >= sz) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(buf, RzIOBFDBG_BUF(fd) + io->off, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static int __close(RzIODesc *fd) {
|
||||
RzIOBfdbg *riom;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
riom = fd->data;
|
||||
bfvm_free(riom->bfvm);
|
||||
RZ_FREE(riom->buf);
|
||||
RZ_FREE(fd->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
|
||||
switch (whence) {
|
||||
case SEEK_SET: return offset;
|
||||
case SEEK_CUR: return io->off + offset;
|
||||
case SEEK_END: return RzIOBFDBG_SZ(fd);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
static bool __plugin_open(RzIO *io, const char *pathname, bool many) {
|
||||
return (!strncmp(pathname, "bfdbg://", 8));
|
||||
}
|
||||
|
||||
static inline int getmalfd(RzIOBfdbg *mal) {
|
||||
return 0xffff & (int)(size_t)mal->buf;
|
||||
}
|
||||
|
||||
static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) {
|
||||
char *out;
|
||||
if (__plugin_open(io, pathname, 0)) {
|
||||
RzIOBind iob;
|
||||
RzIOBfdbg *mal = RZ_NEW0(RzIOBfdbg);
|
||||
if (!mal) {
|
||||
return NULL;
|
||||
}
|
||||
rz_io_bind(io, &iob);
|
||||
mal->fd = getmalfd(mal);
|
||||
mal->bfvm = bfvm_new(&iob);
|
||||
if (!mal->bfvm) {
|
||||
free(mal);
|
||||
return NULL;
|
||||
}
|
||||
size_t rlen;
|
||||
out = rz_file_slurp(pathname + 8, &rlen);
|
||||
if (!out || rlen < 1) {
|
||||
free(mal);
|
||||
free(out);
|
||||
return NULL;
|
||||
}
|
||||
mal->size = (ut32)rlen;
|
||||
mal->buf = malloc(mal->size + 1);
|
||||
if (mal->buf != NULL) {
|
||||
memcpy(mal->buf, out, rlen);
|
||||
free(out);
|
||||
return rz_io_desc_new(io, &rz_io_plugin_bfdbg,
|
||||
pathname, rw, mal);
|
||||
}
|
||||
eprintf("Cannot allocate (%s) %" PFMT32u " byte(s)\n",
|
||||
pathname + 9, mal->size);
|
||||
free(mal);
|
||||
free(out);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RzIOPlugin rz_io_plugin_bfdbg = {
|
||||
.name = "bfdbg",
|
||||
.desc = "Attach to brainfuck Debugger instance",
|
||||
.license = "LGPL3",
|
||||
.uris = "bfdbg://",
|
||||
.open = __open,
|
||||
.close = __close,
|
||||
.read = __read,
|
||||
.check = __plugin_open,
|
||||
.lseek = __lseek,
|
||||
.write = __write,
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct rizin_plugin = {
|
||||
.type = RZ_LIB_TYPE_IO,
|
||||
.data = &rz_io_plugin_bfdbg,
|
||||
.version = RZ_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2015-2019 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_io.h>
|
||||
#include <rz_lib.h>
|
||||
#include <rz_socket.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "rz_io_plugins.h"
|
||||
|
||||
/* --------------------------------------------------------- */
|
||||
#define RZP(x) ((RzPipe *)(x)->data)
|
||||
|
||||
// TODO: add rzpipe_assert
|
||||
|
||||
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, size_t count) {
|
||||
char fmt[4096];
|
||||
char *bufn, bufnum[4096];
|
||||
int i, rv, rescount = -1;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
bufn = bufnum;
|
||||
*bufn = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
int bufn_sz = sizeof(bufnum) - (bufn - bufnum);
|
||||
snprintf(bufn, bufn_sz, "%s%d", i ? "," : "", buf[i]);
|
||||
bufn += strlen(bufn);
|
||||
}
|
||||
size_t len = snprintf(fmt, sizeof(fmt),
|
||||
"{\"op\":\"write\",\"address\":%" PFMT64d ",\"data\":[%s]}",
|
||||
io->off, bufnum);
|
||||
if (len >= sizeof(fmt)) {
|
||||
eprintf("rzpipe_write: error, fmt string has been truncated\n");
|
||||
return -1;
|
||||
}
|
||||
rv = rzpipe_write(RZP(fd), fmt);
|
||||
if (rv < 1) {
|
||||
eprintf("rzpipe_write: error\n");
|
||||
return -1;
|
||||
}
|
||||
rzpipe_read(RZP(fd));
|
||||
|
||||
/* TODO: parse json back */
|
||||
return rescount;
|
||||
}
|
||||
|
||||
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, size_t count) {
|
||||
char fmt[4096], num[128];
|
||||
int rv, rescount = -1;
|
||||
int bufi, numi;
|
||||
char *res, *r;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
if (count > 1024) {
|
||||
count = 1024;
|
||||
}
|
||||
snprintf(fmt, sizeof(fmt),
|
||||
"{\"op\":\"read\",\"address\":%" PFMT64d ",\"count\":%" PFMTSZd "}",
|
||||
io->off, count);
|
||||
rv = rzpipe_write(RZP(fd), fmt);
|
||||
if (rv < 1) {
|
||||
eprintf("rzpipe_write: error\n");
|
||||
return -1;
|
||||
}
|
||||
res = rzpipe_read(RZP(fd));
|
||||
|
||||
/* TODO: parse json back */
|
||||
r = strstr(res, "result");
|
||||
if (r) {
|
||||
rescount = atoi(r + 6 + 2);
|
||||
}
|
||||
r = strstr(res, "data");
|
||||
if (r) {
|
||||
char *arr = strchr(r, ':');
|
||||
if (!arr || arr[1] != '[') {
|
||||
goto beach;
|
||||
}
|
||||
arr += 2;
|
||||
for (num[0] = numi = bufi = 0; bufi < count && *arr; arr++) {
|
||||
switch (*arr) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
num[numi++] = *arr;
|
||||
num[numi] = 0;
|
||||
break;
|
||||
case ' ':
|
||||
case ',':
|
||||
case ']':
|
||||
if (num[0]) {
|
||||
buf[bufi++] = atoi(num);
|
||||
num[numi = 0] = 0;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
case 'u':
|
||||
case 'l':
|
||||
break;
|
||||
default:
|
||||
goto beach;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
beach:
|
||||
free(res);
|
||||
return rescount;
|
||||
}
|
||||
|
||||
static int __close(RzIODesc *fd) {
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
rzpipe_close(fd->data);
|
||||
fd->data = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
|
||||
switch (whence) {
|
||||
case SEEK_SET: return offset;
|
||||
case SEEK_CUR: return io->off + offset;
|
||||
case SEEK_END: return UT64_MAX;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
static bool __check(RzIO *io, const char *pathname, bool many) {
|
||||
return (!strncmp(pathname, "rzpipe://", 9));
|
||||
}
|
||||
|
||||
static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) {
|
||||
RzPipe *rzp = NULL;
|
||||
if (__check(io, pathname, 0)) {
|
||||
rzp = rzpipe_open(pathname + 9);
|
||||
}
|
||||
return rzp ? rz_io_desc_new(io, &rz_io_plugin_rzpipe,
|
||||
pathname, rw, rzp)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static char *__system(RzIO *io, RzIODesc *fd, const char *msg) {
|
||||
rz_return_val_if_fail(io && fd && msg, NULL);
|
||||
PJ *pj = pj_new();
|
||||
pj_o(pj);
|
||||
pj_ks(pj, "op", "system");
|
||||
pj_ks(pj, "cmd", msg);
|
||||
pj_end(pj);
|
||||
const char *fmt = pj_string(pj);
|
||||
int rv = rzpipe_write(RZP(fd), fmt);
|
||||
pj_free(pj);
|
||||
if (rv < 1) {
|
||||
eprintf("rzpipe_write: error\n");
|
||||
return NULL;
|
||||
}
|
||||
char *res = rzpipe_read(RZP(fd));
|
||||
// eprintf ("%s\n", res);
|
||||
/* TODO: parse json back */
|
||||
char *r = strstr(res, "result");
|
||||
if (r) {
|
||||
int rescount = atoi(r + 6 + 1);
|
||||
eprintf("RESULT %d\n", rescount);
|
||||
}
|
||||
free(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RzIOPlugin rz_io_plugin_rzpipe = {
|
||||
.name = "rzpipe",
|
||||
.desc = "rzpipe io plugin",
|
||||
.license = "MIT",
|
||||
.uris = "rzpipe://",
|
||||
.open = __open,
|
||||
.close = __close,
|
||||
.read = __read,
|
||||
.check = __check,
|
||||
.lseek = __lseek,
|
||||
.write = __write,
|
||||
.system = __system
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct rizin_plugin = {
|
||||
.type = RZ_LIB_TYPE_IO,
|
||||
.data = &rz_io_plugin_rzpipe,
|
||||
.version = RZ_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2015 pancake <pancake@nopcode.org>
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
|
||||
#include <rz_io.h>
|
||||
#include <rz_lib.h>
|
||||
#include <rz_socket.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "rz_io_plugins.h"
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
char *url;
|
||||
} RzIOR2Web;
|
||||
|
||||
#define rFD(x) (((RzIOR2Web *)(x)->data)->fd)
|
||||
#define rURL(x) (((RzIOR2Web *)(x)->data)->url)
|
||||
|
||||
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, size_t count) {
|
||||
int code, rlen;
|
||||
char *out, *url, *hexbuf;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
if (count * 3 < count) {
|
||||
return -1;
|
||||
}
|
||||
hexbuf = malloc(count * 3);
|
||||
if (!hexbuf) {
|
||||
return -1;
|
||||
}
|
||||
hexbuf[0] = 0;
|
||||
rz_hex_bin2str(buf, count, hexbuf);
|
||||
url = rz_str_newf("%s/wx%%20%s@%" PFMT64d,
|
||||
rURL(fd), hexbuf, io->off);
|
||||
out = rz_socket_http_get(url, &code, &rlen);
|
||||
free(out);
|
||||
free(url);
|
||||
free(hexbuf);
|
||||
return count;
|
||||
}
|
||||
|
||||
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, size_t count) {
|
||||
int code, rlen;
|
||||
char *out, *url;
|
||||
int ret = 0;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
url = rz_str_newf("%s/p8%%20%" PFMTSZd "@0x%" PFMT64x,
|
||||
rURL(fd), count, io->off);
|
||||
out = rz_socket_http_get(url, &code, &rlen);
|
||||
if (out && rlen > 0) {
|
||||
ut8 *tmp = calloc(1, rlen + 1);
|
||||
if (!tmp) {
|
||||
goto beach;
|
||||
}
|
||||
ret = rz_hex_str2bin(out, tmp);
|
||||
memcpy(buf, tmp, RZ_MIN(count, rlen));
|
||||
free(tmp);
|
||||
if (ret < 0) {
|
||||
ret = -ret;
|
||||
}
|
||||
}
|
||||
|
||||
beach:
|
||||
free(out);
|
||||
free(url);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __close(RzIODesc *fd) {
|
||||
RzIOR2Web *riom;
|
||||
if (!fd || !fd->data) {
|
||||
return -1;
|
||||
}
|
||||
riom = fd->data;
|
||||
RZ_FREE(riom->url);
|
||||
RZ_FREE(fd->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
|
||||
switch (whence) {
|
||||
case SEEK_SET: return offset;
|
||||
case SEEK_CUR: return io->off + offset;
|
||||
case SEEK_END: return UT64_MAX;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
static bool __plugin_open(RzIO *io, const char *pathname, bool many) {
|
||||
const char *uri = "rzweb://";
|
||||
return (!strncmp(pathname, uri, strlen(uri)));
|
||||
}
|
||||
|
||||
static inline int getmalfd(RzIOR2Web *mal) {
|
||||
return 0xfffffff & (int)(size_t)mal;
|
||||
}
|
||||
|
||||
static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) {
|
||||
char *out;
|
||||
int rlen, code;
|
||||
if (__plugin_open(io, pathname, 0)) {
|
||||
RzIOR2Web *mal = RZ_NEW0(RzIOR2Web);
|
||||
if (!mal) {
|
||||
return NULL;
|
||||
}
|
||||
char *path = rz_str_dup(pathname + 8);
|
||||
int path_len = strlen(path);
|
||||
if (path_len > 0) {
|
||||
if (path[path_len - 1] == '/') {
|
||||
path[path_len - 1] = 0;
|
||||
}
|
||||
}
|
||||
char *url = rz_str_newf("http://%s/?V", path);
|
||||
// eprintf ("URL:(%s)\n", url);
|
||||
out = rz_socket_http_get(url, &code, &rlen);
|
||||
// eprintf ("RES %d %d\n", code, rlen);
|
||||
// eprintf ("OUT(%s)\n", out);
|
||||
if (out && rlen > 0) {
|
||||
mal->fd = getmalfd(mal);
|
||||
mal->url = rz_str_newf("http://%s", path);
|
||||
free(path);
|
||||
free(out);
|
||||
free(url);
|
||||
return rz_io_desc_new(io, &rz_io_plugin_rzweb,
|
||||
pathname, rw, mal);
|
||||
}
|
||||
free(url);
|
||||
free(mal);
|
||||
free(out);
|
||||
free(path);
|
||||
eprintf("Error: Try http://localhost:9090/cmd/");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *__system(RzIO *io, RzIODesc *fd, const char *command) {
|
||||
if (!*command) {
|
||||
return NULL;
|
||||
}
|
||||
int code, rlen;
|
||||
char *cmd = rz_str_uri_encode(command);
|
||||
char *url = rz_str_newf("%s/%s", rURL(fd), cmd);
|
||||
char *out = rz_socket_http_get(url, &code, &rlen);
|
||||
if (out && rlen > 0) {
|
||||
io->cb_printf("%s", out);
|
||||
}
|
||||
free(out);
|
||||
free(url);
|
||||
free(cmd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RzIOPlugin rz_io_plugin_rzweb = {
|
||||
.name = "rzweb",
|
||||
.desc = "rzweb io client plugin",
|
||||
.uris = "rzweb://",
|
||||
.license = "LGPL3",
|
||||
.open = __open,
|
||||
.close = __close,
|
||||
.read = __read,
|
||||
.check = __plugin_open,
|
||||
.lseek = __lseek,
|
||||
.system = __system,
|
||||
.write = __write,
|
||||
};
|
||||
|
||||
#ifndef RZ_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct rizin_plugin = {
|
||||
.type = RZ_LIB_TYPE_IO,
|
||||
.data = &rz_io_plugin_rzweb,
|
||||
.version = RZ_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -4,15 +4,14 @@ NAME=Print the debug plugins
|
|||
FILE==
|
||||
CMDS=Ld
|
||||
EXPECT=<<EOF
|
||||
0 --- bf LGPL3
|
||||
1 --- bochs LGPL3
|
||||
2 --- dmp LGPL3
|
||||
3 --- gdb LGPL3
|
||||
4 --- io MIT
|
||||
5 dbg native LGPL3
|
||||
6 --- null MIT
|
||||
7 --- qnx LGPL3
|
||||
8 --- winkd LGPL3
|
||||
0 --- bochs LGPL3
|
||||
1 --- dmp LGPL3
|
||||
2 --- gdb LGPL3
|
||||
3 --- io MIT
|
||||
4 dbg native LGPL3
|
||||
5 --- null MIT
|
||||
6 --- qnx LGPL3
|
||||
7 --- winkd LGPL3
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
@ -26,12 +25,10 @@ Ldj~{[3]}
|
|||
Ldj~{[4]}
|
||||
Ldj~{[5]}
|
||||
Ldj~{[6]}
|
||||
Ldj~{[7]}
|
||||
Ldj~{[8].name}
|
||||
Ldj~{[8].license}
|
||||
Ldj~{[7].name}
|
||||
Ldj~{[7].license}
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
{"arch":"bf","name":"bf","bits":"32 64","license":"LGPL3","version":""}
|
||||
{"arch":"x86","name":"bochs","bits":"16 32 64","license":"LGPL3","version":""}
|
||||
{"arch":"x86,arm","name":"dmp","bits":"32 64","license":"LGPL3","version":""}
|
||||
{"arch":"x86,arm,sh,mips,avr,lm32,v850,ba2,tricore","name":"gdb","bits":"16 32 64","license":"LGPL3","version":""}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@ NAME=dbg.dll
|
|||
FILE=/bin/ls
|
||||
CMDS=dll
|
||||
EXPECT=<<EOF
|
||||
0 --- bf LGPL3
|
||||
1 --- bochs LGPL3
|
||||
2 --- dmp LGPL3
|
||||
3 --- gdb LGPL3
|
||||
4 --- io MIT
|
||||
5 dbg native LGPL3
|
||||
6 --- null MIT
|
||||
7 --- qnx LGPL3
|
||||
8 --- winkd LGPL3
|
||||
0 --- bochs LGPL3
|
||||
1 --- dmp LGPL3
|
||||
2 --- gdb LGPL3
|
||||
3 --- io MIT
|
||||
4 dbg native LGPL3
|
||||
5 --- null MIT
|
||||
6 --- qnx LGPL3
|
||||
7 --- winkd LGPL3
|
||||
EOF
|
||||
RUN
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@ Loq
|
|||
EOF
|
||||
EXPECT=<<EOF
|
||||
rw_ ar Open ar/lib files (LGPL3) ar://,lib:// xarkes
|
||||
rw_ bfdbg Attach to brainfuck Debugger instance (LGPL3) bfdbg://
|
||||
rwd bochs Attach to a BOCHS debugger instance (LGPL3) bochs://
|
||||
r_d debug Attach to native debugger instance (LGPL3) dbg://,pidof://,waitfor:// v0.2.0 pancake
|
||||
rw_ default Open local files (LGPL3) file://,nocache://
|
||||
|
|
@ -106,22 +105,20 @@ rw_ null Null plugin (LGPL3) null://
|
|||
rw_ procpid Open /proc/[pid]/mem io (LGPL3) procpid://
|
||||
rwd ptrace Ptrace and /proc/pid/mem (if available) io plugin (LGPL3) ptrace://,attach://
|
||||
rwd qnx Attach to QNX pdebug instance (LGPL3) qnx://
|
||||
rw_ rzpipe rzpipe io plugin (MIT) rzpipe://
|
||||
rw_ rzweb rzweb io client plugin (LGPL3) rzweb://
|
||||
rw_ self Read memory from self (LGPL3) self://
|
||||
rw_ shm Shared memory resources plugin (MIT) shm://
|
||||
rw_ sparse Sparse buffer allocation plugin (LGPL3) sparse://
|
||||
rw_ srec Motorola S-record file format (LGPL-3) srec://
|
||||
rw_ tcp Load files via TCP (listen or connect) (LGPL3) tcp://
|
||||
rw_ titxt Texas Instruments TI-TXT file format (LGPL-3) titxt://
|
||||
rw_ vfile Virtual Files provided by RzBin Files (LGPL) vfile://
|
||||
rwd winedbg Wine-dbg io and debug.io plugin (MIT) winedbg://
|
||||
rwd winkd Attach to a KD debugger (LGPL3) winkd://
|
||||
rw_ zip Open zip files (BSD) zip://,apk://,ipa://,jar://,zipall://,apkall://,ipaall://,jarall://
|
||||
[{"permissions":"rw_","name":"ar","description":"Open ar/lib files","license":"LGPL3","uris":["ar://","lib://"],"author":"xarkes"},{"permissions":"rw_","name":"bfdbg","description":"Attach to brainfuck Debugger instance","license":"LGPL3","uris":["bfdbg://"]},{"permissions":"rwd","name":"bochs","description":"Attach to a BOCHS debugger instance","license":"LGPL3","uris":["bochs://"]},{"permissions":"r_d","name":"debug","description":"Attach to native debugger instance","license":"LGPL3","uris":["dbg://","pidof://","waitfor://"],"version":"0.2.0","author":"pancake"},{"permissions":"rw_","name":"default","description":"Open local files","license":"LGPL3","uris":["file://","nocache://"]},{"permissions":"rw_","name":"dmp","description":"Debug a Windows DMP file","license":"LGPL3","uris":["dmp://"]},{"permissions":"rw_","name":"fd","description":"Local process filedescriptor IO","license":"MIT","uris":["fd://"]},{"permissions":"rwd","name":"gdb","description":"Attach to gdbserver instance","license":"LGPL3","uris":["gdb://"]},{"permissions":"rw_","name":"gzip","description":"Read/write gzipped files","license":"LGPL3","uris":["gzip://"]},{"permissions":"rw_","name":"http","description":"Make http get requests","license":"LGPL3","uris":["http://"]},{"permissions":"rw_","name":"ihex","description":"Open intel HEX file","license":"LGPL","uris":["ihex://"]},{"permissions":"r__","name":"mach","description":"mach debug io (unsupported in this platform)","license":"LGPL"},{"permissions":"rw_","name":"malloc","description":"Memory allocation plugin","license":"LGPL3","uris":["malloc://","hex://"]},{"permissions":"rw_","name":"null","description":"Null plugin","license":"LGPL3","uris":["null://"]},{"permissions":"rw_","name":"procpid","description":"Open /proc/[pid]/mem io","license":"LGPL3","uris":["procpid://"]},{"permissions":"rwd","name":"ptrace","description":"Ptrace and /proc/pid/mem (if available) io plugin","license":"LGPL3","uris":["ptrace://","attach://"]},{"permissions":"rwd","name":"qnx","description":"Attach to QNX pdebug instance","license":"LGPL3","uris":["qnx://"]},{"permissions":"rw_","name":"rzpipe","description":"rzpipe io plugin","license":"MIT","uris":["rzpipe://"]},{"permissions":"rw_","name":"rzweb","description":"rzweb io client plugin","license":"LGPL3","uris":["rzweb://"]},{"permissions":"rw_","name":"self","description":"Read memory from self","license":"LGPL3","uris":["self://"]},{"permissions":"rw_","name":"shm","description":"Shared memory resources plugin","license":"MIT","uris":["shm://"]},{"permissions":"rw_","name":"sparse","description":"Sparse buffer allocation plugin","license":"LGPL3","uris":["sparse://"]},{"permissions":"rw_","name":"srec","description":"Motorola S-record file format","license":"LGPL-3","uris":["srec://"]},{"permissions":"rw_","name":"tcp","description":"Load files via TCP (listen or connect)","license":"LGPL3","uris":["tcp://"]},{"permissions":"rw_","name":"vfile","description":"Virtual Files provided by RzBin Files","license":"LGPL","uris":["vfile://"]},{"permissions":"rwd","name":"winedbg","description":"Wine-dbg io and debug.io plugin","license":"MIT","uris":["winedbg://"]},{"permissions":"rwd","name":"winkd","description":"Attach to a KD debugger","license":"LGPL3","uris":["winkd://"]},{"permissions":"rw_","name":"zip","description":"Open zip files","license":"BSD","uris":["zip://","apk://","ipa://","jar://","zipall://","apkall://","ipaall://","jarall://"]}]
|
||||
[{"permissions":"rw_","name":"ar","description":"Open ar/lib files","license":"LGPL3","uris":["ar://","lib://"],"author":"xarkes"},{"permissions":"rwd","name":"bochs","description":"Attach to a BOCHS debugger instance","license":"LGPL3","uris":["bochs://"]},{"permissions":"r_d","name":"debug","description":"Attach to native debugger instance","license":"LGPL3","uris":["dbg://","pidof://","waitfor://"],"version":"0.2.0","author":"pancake"},{"permissions":"rw_","name":"default","description":"Open local files","license":"LGPL3","uris":["file://","nocache://"]},{"permissions":"rw_","name":"dmp","description":"Debug a Windows DMP file","license":"LGPL3","uris":["dmp://"]},{"permissions":"rw_","name":"fd","description":"Local process filedescriptor IO","license":"MIT","uris":["fd://"]},{"permissions":"rwd","name":"gdb","description":"Attach to gdbserver instance","license":"LGPL3","uris":["gdb://"]},{"permissions":"rw_","name":"gzip","description":"Read/write gzipped files","license":"LGPL3","uris":["gzip://"]},{"permissions":"rw_","name":"ihex","description":"Open intel HEX file","license":"LGPL","uris":["ihex://"]},{"permissions":"r__","name":"mach","description":"mach debug io (unsupported in this platform)","license":"LGPL"},{"permissions":"rw_","name":"malloc","description":"Memory allocation plugin","license":"LGPL3","uris":["malloc://","hex://"]},{"permissions":"rw_","name":"null","description":"Null plugin","license":"LGPL3","uris":["null://"]},{"permissions":"rw_","name":"procpid","description":"Open /proc/[pid]/mem io","license":"LGPL3","uris":["procpid://"]},{"permissions":"rwd","name":"ptrace","description":"Ptrace and /proc/pid/mem (if available) io plugin","license":"LGPL3","uris":["ptrace://","attach://"]},{"permissions":"rwd","name":"qnx","description":"Attach to QNX pdebug instance","license":"LGPL3","uris":["qnx://"]},{"permissions":"rw_","name":"self","description":"Read memory from self","license":"LGPL3","uris":["self://"]},{"permissions":"rw_","name":"shm","description":"Shared memory resources plugin","license":"MIT","uris":["shm://"]},{"permissions":"rw_","name":"sparse","description":"Sparse buffer allocation plugin","license":"LGPL3","uris":["sparse://"]},{"permissions":"rw_","name":"srec","description":"Motorola S-record file format","license":"LGPL-3","uris":["srec://"]},{"permissions":"rw_","name":"tcp","description":"Load files via TCP (listen or connect)","license":"LGPL3","uris":["tcp://"]},{"permissions":"rw_","name":"titxt","description":"Texas Instruments TI-TXT file format","license":"LGPL-3","uris":["titxt://"]},{"permissions":"rw_","name":"vfile","description":"Virtual Files provided by RzBin Files","license":"LGPL","uris":["vfile://"]},{"permissions":"rwd","name":"winedbg","description":"Wine-dbg io and debug.io plugin","license":"MIT","uris":["winedbg://"]},{"permissions":"rwd","name":"winkd","description":"Attach to a KD debugger","license":"LGPL3","uris":["winkd://"]},{"permissions":"rw_","name":"zip","description":"Open zip files","license":"BSD","uris":["zip://","apk://","ipa://","jar://","zipall://","apkall://","ipaall://","jarall://"]}]
|
||||
perm license name uri description
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------
|
||||
rw_ LGPL3 ar ar://,lib:// Open ar/lib files
|
||||
rw_ LGPL3 bfdbg bfdbg:// Attach to brainfuck Debugger instance
|
||||
rwd LGPL3 bochs bochs:// Attach to a BOCHS debugger instance
|
||||
r_d LGPL3 debug dbg://,pidof://,waitfor:// Attach to native debugger instance
|
||||
rw_ LGPL3 default file://,nocache:// Open local files
|
||||
|
|
@ -129,7 +126,6 @@ rw_ LGPL3 dmp dmp://
|
|||
rw_ MIT fd fd:// Local process filedescriptor IO
|
||||
rwd LGPL3 gdb gdb:// Attach to gdbserver instance
|
||||
rw_ LGPL3 gzip gzip:// Read/write gzipped files
|
||||
rw_ LGPL3 http http:// Make http get requests
|
||||
rw_ LGPL ihex ihex:// Open intel HEX file
|
||||
r__ LGPL mach mach debug io (unsupported in this platform)
|
||||
rw_ LGPL3 malloc malloc://,hex:// Memory allocation plugin
|
||||
|
|
@ -137,19 +133,17 @@ rw_ LGPL3 null null://
|
|||
rw_ LGPL3 procpid procpid:// Open /proc/[pid]/mem io
|
||||
rwd LGPL3 ptrace ptrace://,attach:// Ptrace and /proc/pid/mem (if available) io plugin
|
||||
rwd LGPL3 qnx qnx:// Attach to QNX pdebug instance
|
||||
rw_ MIT rzpipe rzpipe:// rzpipe io plugin
|
||||
rw_ LGPL3 rzweb rzweb:// rzweb io client plugin
|
||||
rw_ LGPL3 self self:// Read memory from self
|
||||
rw_ MIT shm shm:// Shared memory resources plugin
|
||||
rw_ LGPL3 sparse sparse:// Sparse buffer allocation plugin
|
||||
rw_ LGPL-3 srec srec:// Motorola S-record file format
|
||||
rw_ LGPL3 tcp tcp:// Load files via TCP (listen or connect)
|
||||
rw_ LGPL-3 titxt titxt:// Texas Instruments TI-TXT file format
|
||||
rw_ LGPL vfile vfile:// Virtual Files provided by RzBin Files
|
||||
rwd MIT winedbg winedbg:// Wine-dbg io and debug.io plugin
|
||||
rwd LGPL3 winkd winkd:// Attach to a KD debugger
|
||||
rw_ BSD zip zip://,apk://,ipa://,jar://,zipall://,apkall://,ipaall://,jarall:// Open zip files
|
||||
ar
|
||||
bfdbg
|
||||
bochs
|
||||
debug
|
||||
default
|
||||
|
|
@ -157,7 +151,6 @@ dmp
|
|||
fd
|
||||
gdb
|
||||
gzip
|
||||
http
|
||||
ihex
|
||||
mach
|
||||
malloc
|
||||
|
|
@ -165,13 +158,12 @@ null
|
|||
procpid
|
||||
ptrace
|
||||
qnx
|
||||
rzpipe
|
||||
rzweb
|
||||
self
|
||||
shm
|
||||
sparse
|
||||
srec
|
||||
tcp
|
||||
titxt
|
||||
vfile
|
||||
winedbg
|
||||
winkd
|
||||
|
|
@ -611,14 +603,12 @@ Ldj~{[0]}
|
|||
Ldj~{[1]}
|
||||
Ldj~{[2]}
|
||||
Ldj~{[3]}
|
||||
Ldj~{[4]}
|
||||
# Ldj~{[5]} - Native plugin. The arch field changes in each test environment and breaks it.
|
||||
# Ldj~{[4]} - Native plugin. The arch field changes in each test environment and breaks it.
|
||||
Ldj~{[5]}
|
||||
Ldj~{[6]}
|
||||
Ldj~{[7]}
|
||||
Ldt:name/ne/native:name/ne/winkd:name/ne/windbg:name/cols/selected/license/bits/arch
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
--- bf LGPL3
|
||||
--- bochs LGPL3
|
||||
--- dmp LGPL3
|
||||
--- gdb LGPL3
|
||||
|
|
@ -626,7 +616,6 @@ EXPECT=<<EOF
|
|||
dbg null MIT
|
||||
--- qnx LGPL3
|
||||
--- winkd LGPL3
|
||||
{"arch":"bf","name":"bf","bits":"32 64","license":"LGPL3","version":""}
|
||||
{"arch":"x86","name":"bochs","bits":"16 32 64","license":"LGPL3","version":""}
|
||||
{"arch":"x86,arm","name":"dmp","bits":"32 64","license":"LGPL3","version":""}
|
||||
{"arch":"x86,arm,sh,mips,avr,lm32,v850,ba2,tricore","name":"gdb","bits":"16 32 64","license":"LGPL3","version":""}
|
||||
|
|
@ -635,7 +624,6 @@ dbg null MIT
|
|||
{"arch":"x86,arm","name":"qnx","bits":"32 ","license":"LGPL3","version":""}
|
||||
name selected license bits arch
|
||||
--------------------------------------------------------------------------
|
||||
bf LGPL3 32 64 bf
|
||||
bochs LGPL3 16 32 64 x86
|
||||
dmp LGPL3 32 64 x86,arm
|
||||
gdb LGPL3 16 32 64 x86,arm,sh,mips,avr,lm32,v850,ba2,tricore
|
||||
|
|
|
|||
Loading…
Reference in a new issue