From d7b2f85c891d5b1706fcae134876ae4e7ffc87ae Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:55:47 +0800 Subject: [PATCH] Remove RzIO brainfuck/rzweb/rzpipe & RzDebug brainfuck (#5810) --- doc/brainfuck.md | 37 ---- librz/debug/meson.build | 3 - librz/debug/p/bfvm.c | 315 ------------------------------ librz/debug/p/bfvm.h | 46 ----- librz/debug/p/debug_bf.c | 211 -------------------- librz/io/meson.build | 6 - librz/io/p/io_bfdbg.c | 218 --------------------- librz/io/p/io_rzpipe.c | 199 ------------------- librz/io/p/io_rzweb.c | 178 ----------------- test/db/archos/linux-x64/cmd_list | 23 +-- test/db/archos/linux-x64/dbg_dl | 17 +- test/db/cmd/cmd_list | 24 +-- 12 files changed, 24 insertions(+), 1253 deletions(-) delete mode 100644 doc/brainfuck.md delete mode 100644 librz/debug/p/bfvm.c delete mode 100644 librz/debug/p/bfvm.h delete mode 100644 librz/debug/p/debug_bf.c delete mode 100644 librz/io/p/io_bfdbg.c delete mode 100644 librz/io/p/io_rzpipe.c delete mode 100644 librz/io/p/io_rzweb.c diff --git a/doc/brainfuck.md b/doc/brainfuck.md deleted file mode 100644 index c813265eab..0000000000 --- a/doc/brainfuck.md +++ /dev/null @@ -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 -``` diff --git a/librz/debug/meson.build b/librz/debug/meson.build index ef3a0e314e..c52ef3aa93 100644 --- a/librz/debug/meson.build +++ b/librz/debug/meson.build @@ -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', diff --git a/librz/debug/p/bfvm.c b/librz/debug/p/bfvm.c deleted file mode 100644 index 5f2ca0b15b..0000000000 --- a/librz/debug/p/bfvm.c +++ /dev/null @@ -1,315 +0,0 @@ -// SPDX-FileCopyrightText: 2008-2011 pancake -// 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); - } -} diff --git a/librz/debug/p/bfvm.h b/librz/debug/p/bfvm.h deleted file mode 100644 index 1eac24b558..0000000000 --- a/librz/debug/p/bfvm.h +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-FileCopyrightText: 2008-2011 pancake -// SPDX-License-Identifier: LGPL-3.0-only - -#ifndef _R_BFVM_INCLUDE_ -#define _R_BFVM_INCLUDE_ - -#include -#include - -#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 diff --git a/librz/debug/p/debug_bf.c b/librz/debug/p/debug_bf.c deleted file mode 100644 index 7e8b189345..0000000000 --- a/librz/debug/p/debug_bf.c +++ /dev/null @@ -1,211 +0,0 @@ -// SPDX-FileCopyrightText: 2022 deroad -// SPDX-FileCopyrightText: 2011-2019 pancake -// SPDX-License-Identifier: LGPL-3.0-only - -#include -#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 /**/ *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 diff --git a/librz/io/meson.build b/librz/io/meson.build index 6fbd165718..041f97f8a5 100644 --- a/librz/io/meson.build +++ b/librz/io/meson.build @@ -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', diff --git a/librz/io/p/io_bfdbg.c b/librz/io/p/io_bfdbg.c deleted file mode 100644 index f829bc41be..0000000000 --- a/librz/io/p/io_bfdbg.c +++ /dev/null @@ -1,218 +0,0 @@ -// SPDX-FileCopyrightText: 2011-2013 pancake -// SPDX-License-Identifier: LGPL-3.0-only - -#include -#include -#include -#include -#include -#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 diff --git a/librz/io/p/io_rzpipe.c b/librz/io/p/io_rzpipe.c deleted file mode 100644 index 398d3d7504..0000000000 --- a/librz/io/p/io_rzpipe.c +++ /dev/null @@ -1,199 +0,0 @@ -// SPDX-FileCopyrightText: 2015-2019 pancake -// SPDX-License-Identifier: LGPL-3.0-only - -#include -#include -#include -#include -#include -#include - -#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 diff --git a/librz/io/p/io_rzweb.c b/librz/io/p/io_rzweb.c deleted file mode 100644 index e2ce920751..0000000000 --- a/librz/io/p/io_rzweb.c +++ /dev/null @@ -1,178 +0,0 @@ -// SPDX-FileCopyrightText: 2015 pancake -// SPDX-License-Identifier: LGPL-3.0-only - -#include -#include -#include -#include -#include -#include - -#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 diff --git a/test/db/archos/linux-x64/cmd_list b/test/db/archos/linux-x64/cmd_list index 21d7a9d0cb..e110396915 100644 --- a/test/db/archos/linux-x64/cmd_list +++ b/test/db/archos/linux-x64/cmd_list @@ -4,15 +4,14 @@ NAME=Print the debug plugins FILE== CMDS=Ld EXPECT=<