Skip to content

Commit

Permalink
Renamed windbg plugin (#8117)
Browse files Browse the repository at this point in the history
  • Loading branch information
xarkes authored and radare committed Aug 3, 2017
1 parent e0f0c89 commit 3d681b0
Show file tree
Hide file tree
Showing 32 changed files with 1,296 additions and 1,217 deletions.
2 changes: 1 addition & 1 deletion binr/blob/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ LDFLAGS+=../../shlr/grub/libgrubfs.a
LDFLAGS+=../../shlr/capstone/libcapstone.a
LDFLAGS+=../../shlr/sdb/src/libsdb.a
LDFLAGS+=../../shlr/gdb/lib/libgdbr.a
LDFLAGS+=../../shlr/wind/libr_wind.a
LDFLAGS+=../../shlr/windbg/libr_windbg.a
LDFLAGS+=../../shlr/java/libr_java.a
LDFLAGS+=-lm
LDFLAGS+=../../libr/socket/libr_socket.a
Expand Down
2 changes: 1 addition & 1 deletion binr/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LDFLAGS+=$(shell for a in ${BINDEPS} ; do b=`echo $$a |sed -e s,r_,,g`; echo ../
LDFLAGS+=../../shlr/sdb/src/libsdb.a
LDFLAGS+=../../shlr/grub/libgrubfs.a
LDFLAGS+=../../shlr/gdb/lib/libgdbr.a
LDFLAGS+=../../shlr/wind/libr_wind.a
LDFLAGS+=../../shlr/windbg/libr_windbg.a
LDFLAGS+=../../shlr/capstone/libcapstone.a
LDFLAGS+=../../shlr/java/libr_java.a
LDFLAGS+=../../libr/socket/libr_socket.a
Expand Down
4 changes: 2 additions & 2 deletions doc/debug-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ See doc/qnx

See doc/rap

### libr/debug/p/debug_wind.c
### libr/debug/p/debug_windbg.c

A debugger plugin that enables debugging code remotely via WinDbg protocol. WinDbg protocol
parser is located in shlr/wind. Corresponding IO plugin located in libr/io/p/io_windbg.c
parser is located in shlr/windbg. Corresponding IO plugin located in libr/io/p/io_windbg.c
See doc/windbg

## Conclusion
Expand Down
14 changes: 7 additions & 7 deletions doc/windbg
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Enable WinDBG support on Windows Vista and higher like this:

Or like this for Windows XP:
Open boot.ini and add /debug /debugport=COM1 /baudrate=115200:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Debugging with Cable" /fastdetect /debug /debugport=COM1 /baudrate=57600


Configure the VirtualBox Machine like this:

Expand All @@ -42,18 +42,18 @@ Or just spawn the VM with qemu like this:

$ qemu-system-x86_64 -chardev socket,id=serial0,\
path=/tmp/windbg.pipe,nowait,server \
-serial chardev:serial0 -hda Windows7-VM.vdi
-serial chardev:serial0 -hda Windows7-VM.vdi


Radare2 will use the 'windbg' io plugin to connect to a socket file
created by virtualbox or qemu. Also, the 'wind' debugger plugin and
created by virtualbox or qemu. Also, the 'windbg' debugger plugin and
we should specify the x86-32 too. (32 and 64 bit debugging is supported)

$ r2 -a x86 -b 32 -D wind windbg:///tmp/windbg.pipe
$ r2 -a x86 -b 32 -D windbg windbg:///tmp/windbg.pipe

On Windows you should run the following line:

$ radare2 -D wind windbg://\\.\pipe\com_1
$ radare2 -D windbg windbg://\\.\pipe\com_1

At this point, we will get stuck here:

Expand All @@ -76,6 +76,6 @@ In order to skip that trap we will need to change eip and run 'dc' twice:
Now the Windows VM will be interactive again. We will need to kill r2 and
attach again to get back to control the kernel.

In addition, the `dp` command can be used to list all processes, and
In addition, the `dp` command can be used to list all processes, and
`dpa` or `dp=` to attach to the process. This will display the base
address of the process in the physical memory layout.
2 changes: 1 addition & 1 deletion libr/bin/p/bflt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LINK+=../../util/libr_util.${EXT_AR}
LINK+=../../magic/libr_magic.${EXT_AR}
LINK+=../../socket/libr_socket.${EXT_AR}
LINK+=../../../shlr/gdb/lib/libgdbr.${EXT_AR}
LINK+=../../../shlr/wind/libr_wind.${EXT_AR}
LINK+=../../../shlr/windbg/libr_windbg.${EXT_AR}
LINK+=../../../shlr/qnx/lib/libqnxr.${EXT_AR}
LINK+=../../../shlr/bochs/lib/libbochs.${EXT_AR}
LINK+=../../../shlr/java/libr_java.${EXT_AR}
Expand Down
4 changes: 2 additions & 2 deletions libr/core/p/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include ../../../shlr/zip/deps.mk

CFLAGS+=-I../../include -Wall -shared ${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
CFLAGS+=-L../../util -lr_util -L../../reg -lr_reg -L.. -lr_core
#CFLAGS+=-L../../db -lr_db
#CFLAGS+=-L../../db -lr_db
CFLAGS+=-L../../cons -lr_cons -L../../bin -lr_bin
CFLAGS+=-L../../parse -lr_parse -L../../io -lr_io -L../../fs -lr_fs
CFLAGS+=-L../../magic -lr_magic -L../../hash -lr_hash -L../../config -lr_config
Expand All @@ -18,7 +18,7 @@ CFLAGS+=-L../../bp -lr_bp -L../../reg -lr_reg -L../../asm -lr_asm
LDFLAGS+=$(STOP)/sdb/src/libsdb.a
include $(STOP)/java/deps.mk
include $(STOP)/gdb/deps.mk
include $(STOP)/wind/deps.mk
include $(STOP)/windbg/deps.mk
#CFLAGS+=-L../../anal -lr_anal -L../../core -lr_core
LDFLAGS+=${LINK}

Expand Down
2 changes: 1 addition & 1 deletion libr/debug/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ files=[
'p/debug_native.c',
#'p/debug_qnx.c',
'p/debug_rap.c',
#'p/debug_wind.c',
#'p/debug_windbg.c',
#'p/native/arm.c',
#'p/native/bt/fuzzy-all.c',
#'p/native/bt/generic-x64.c',
Expand Down
2 changes: 1 addition & 1 deletion libr/debug/p/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CFLAGS+=-I../../include -Wall ${PIC_FLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
foo: all

ALL_TARGETS=
DEBUGS=native.mk gdb.mk qnx.mk wind.mk bochs.mk
DEBUGS=native.mk gdb.mk qnx.mk windbg.mk bochs.mk
include $(DEBUGS)

all: ${ALL_TARGETS}
Expand Down
92 changes: 46 additions & 46 deletions libr/debug/p/debug_wind.c → libr/debug/p/debug_windbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

#include <r_asm.h>
#include <r_debug.h>
#include <wind.h>
#include <windbg.h>
#include <kd.h>

static WindCtx *wctx = NULL;
static bool dbreak = false;

static int r_debug_wind_step (RDebug *dbg) {
static int r_debug_windbg_step (RDebug *dbg) {
return true;
}

static int r_debug_wind_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
static int r_debug_windbg_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
(void)type;
int ret = wind_read_reg(wctx, buf, size);
int ret = windbg_read_reg(wctx, buf, size);
if (!ret || size != ret) {
return -1;
}
Expand All @@ -36,7 +36,7 @@ static int r_debug_wind_reg_read (RDebug *dbg, int type, ut8 *buf, int size) {
return 0;
}

static int r_debug_wind_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) {
static int r_debug_windbg_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) {
(void)buf;
(void)size;
if (!dbg->reg) {
Expand All @@ -48,32 +48,32 @@ static int r_debug_wind_reg_write(RDebug *dbg, int type, const ut8 *buf, int siz
eprintf ("Could not retrieve the register arena!\n");
return false;
}
int ret = wind_write_reg (wctx, arena, arena_size);
int ret = windbg_write_reg (wctx, arena, arena_size);
free (arena);
return ret;
}

static int r_debug_wind_continue(RDebug *dbg, int pid, int tid, int sig) {
return wind_continue(wctx);
static int r_debug_windbg_continue(RDebug *dbg, int pid, int tid, int sig) {
return windbg_continue(wctx);
}

static void wstatic_debug_break(void *u) {
dbreak = true;
wind_break_read (wctx);
windbg_break_read (wctx);
}

static int r_debug_wind_wait (RDebug *dbg, int pid) {
static int r_debug_windbg_wait (RDebug *dbg, int pid) {
# define STATE_EXCEPTION 0x3030
kd_packet_t *pkt;
kd_stc_64 *stc;
int ret;
dbreak = false;
r_cons_break_push (wstatic_debug_break, dbg);
for (;;) {
ret = wind_wait_packet (wctx, KD_PACKET_TYPE_STATE_CHANGE, &pkt);
ret = windbg_wait_packet (wctx, KD_PACKET_TYPE_STATE_CHANGE, &pkt);
if (dbreak) {
dbreak = false;
wind_break (wctx);
windbg_break (wctx);
continue;
}
if (ret != KD_E_OK || !pkt) {
Expand All @@ -82,23 +82,23 @@ static int r_debug_wind_wait (RDebug *dbg, int pid) {
stc = (kd_stc_64 *)pkt->data;
// Handle exceptions only
if (stc->state == STATE_EXCEPTION) {
wind_set_cpu (wctx, stc->cpu);
windbg_set_cpu (wctx, stc->cpu);
dbg->reason.type = R_DEBUG_REASON_INT;
dbg->reason.addr = stc->pc;
dbg->reason.tid = stc->kthread;
dbg->reason.signum = stc->state;
free (pkt);
break;
}
wind_continue (wctx);
windbg_continue (wctx);
free (pkt);
}
r_cons_break_pop ();
// TODO : Set the faulty process as target
return true;
}

static int r_debug_wind_attach (RDebug *dbg, int pid) {
static int r_debug_windbg_attach (RDebug *dbg, int pid) {
RIODesc *desc = dbg->iob.io->desc;

if (!desc || !desc->plugin || !desc->plugin->name || !desc->data) {
Expand All @@ -117,26 +117,26 @@ static int r_debug_wind_attach (RDebug *dbg, int pid) {
}

// Handshake
if (!wind_sync(wctx)) {
if (!windbg_sync(wctx)) {
eprintf("Could not connect to windbg\n");
wind_ctx_free(wctx);
windbg_ctx_free(wctx);
return false;
}

if (!wind_read_ver(wctx)) {
wind_ctx_free(wctx);
if (!windbg_read_ver(wctx)) {
windbg_ctx_free(wctx);
return false;
}
// Make r_debug_is_dead happy
dbg->pid = 0;
return true;
}

static int r_debug_wind_detach (RDebug *dbg, int pid) {
static int r_debug_windbg_detach (RDebug *dbg, int pid) {
return true;
}

static char *r_debug_wind_reg_profile(RDebug *dbg) {
static char *r_debug_windbg_reg_profile(RDebug *dbg) {
if (!dbg) return NULL;
if (dbg->arch && strcmp (dbg->arch, "x86"))
return NULL;
Expand All @@ -148,19 +148,19 @@ static char *r_debug_wind_reg_profile(RDebug *dbg) {
return NULL;
}

static int r_debug_wind_breakpoint (RBreakpointItem *bp, int set, void *user) {
static int r_debug_windbg_breakpoint (RBreakpointItem *bp, int set, void *user) {
int *tag;
if (!bp) return false;
// Use a 32 bit word here to keep this compatible with 32 bit hosts
tag = (int *)&bp->data;
return wind_bkpt (wctx, bp->addr, set, bp->hw, tag);
return windbg_bkpt (wctx, bp->addr, set, bp->hw, tag);
}

static int r_debug_wind_init(RDebug *dbg) {
static int r_debug_windbg_init(RDebug *dbg) {
return true;
}

static RList *r_debug_wind_pids (RDebug *dbg, int pid) {
static RList *r_debug_windbg_pids (RDebug *dbg, int pid) {
RListIter *it;
WindProc *p;

Expand All @@ -169,7 +169,7 @@ static RList *r_debug_wind_pids (RDebug *dbg, int pid) {
return NULL;
}

RList *pids = wind_list_process(wctx);
RList *pids = windbg_list_process(wctx);
if (!pids) {
return ret;
}
Expand All @@ -189,44 +189,44 @@ static RList *r_debug_wind_pids (RDebug *dbg, int pid) {
return ret;
}

static int r_debug_wind_select (int pid, int tid) {
ut32 old = wind_get_target (wctx);
int ret = wind_set_target (wctx, pid);
static int r_debug_windbg_select (int pid, int tid) {
ut32 old = windbg_get_target (wctx);
int ret = windbg_set_target (wctx, pid);
if (!ret) {
return false;
}
ut64 base = wind_get_target_base (wctx);
ut64 base = windbg_get_target_base (wctx);
if (!base) {
wind_set_target (wctx, old);
windbg_set_target (wctx, old);
return false;
}
eprintf ("Process base is 0x%"PFMT64x"\n", base);
return true;
}

RDebugPlugin r_debug_plugin_wind = {
.name = "wind",
RDebugPlugin r_debug_plugin_windbg = {
.name = "windbg",
.license = "LGPL3",
.arch = "x86",
.bits = R_SYS_BITS_32 | R_SYS_BITS_64,
.pids = r_debug_wind_pids,
.select = r_debug_wind_select,
.step = r_debug_wind_step,
.init = r_debug_wind_init,
.cont = r_debug_wind_continue,
.attach = &r_debug_wind_attach,
.detach = &r_debug_wind_detach,
.wait = &r_debug_wind_wait,
.breakpoint = &r_debug_wind_breakpoint,
.reg_read = &r_debug_wind_reg_read,
.reg_write = &r_debug_wind_reg_write,
.reg_profile = r_debug_wind_reg_profile,
.pids = r_debug_windbg_pids,
.select = r_debug_windbg_select,
.step = r_debug_windbg_step,
.init = r_debug_windbg_init,
.cont = r_debug_windbg_continue,
.attach = &r_debug_windbg_attach,
.detach = &r_debug_windbg_detach,
.wait = &r_debug_windbg_wait,
.breakpoint = &r_debug_windbg_breakpoint,
.reg_read = &r_debug_windbg_reg_read,
.reg_write = &r_debug_windbg_reg_write,
.reg_profile = r_debug_windbg_reg_profile,
};

#ifndef CORELIB
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_DBG,
.data = &r_debug_plugin_wind,
.data = &r_debug_plugin_winddbg,
.version = R2_VERSION
};
#endif
27 changes: 0 additions & 27 deletions libr/debug/p/wind.mk

This file was deleted.

Loading

0 comments on commit 3d681b0

Please sign in to comment.