1 /* radare - LGPL - Copyright 2011-2019 - pancake */
2 
3 #include <r_asm.h>
4 #include <r_cons.h>
5 #include <r_debug.h>
6 
__rap_step(RDebug * dbg)7 static int __rap_step(RDebug *dbg) {
8 	r_io_system (dbg->iob.io, "ds");
9 	return true;
10 }
11 
__rap_reg_read(RDebug * dbg,int type,ut8 * buf,int size)12 static int __rap_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
13 	r_io_system (dbg->iob.io, "dr");
14 	return 0;
15 }
16 
__rap_reg_write(RDebug * dbg,int type,const ut8 * buf,int size)17 static int __rap_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) {
18 	return false; // XXX Error check
19 }
20 
__rap_continue(RDebug * dbg,int pid,int tid,int sig)21 static int __rap_continue(RDebug *dbg, int pid, int tid, int sig) {
22 	r_io_system (dbg->iob.io, "dc");
23 	return true;
24 }
25 
__rap_wait(RDebug * dbg,int pid)26 static int __rap_wait(RDebug *dbg, int pid) {
27 	/* do nothing */
28 	return true;
29 }
30 
__rap_attach(RDebug * dbg,int pid)31 static int __rap_attach(RDebug *dbg, int pid) {
32 // XXX TODO PID must be a socket here !!1
33 	RIODesc *d = dbg->iob.io->desc;
34 	if (d && d->plugin && d->plugin->name) {
35 		if (!strcmp ("rap", d->plugin->name)) {
36 			eprintf ("SUCCESS: rap attach with inferior rap rio worked\n");
37 		} else {
38 			eprintf ("ERROR: Underlying IO descriptor is not a rap one..\n");
39 		}
40 	}
41 	return true;
42 }
43 
__rap_detach(RDebug * dbg,int pid)44 static int __rap_detach(RDebug *dbg, int pid) {
45 // XXX TODO PID must be a socket here !!1
46 //	close (pid);
47 	//XXX Maybe we should continue here?
48 	return true;
49 }
50 
__rap_reg_profile(RDebug * dbg)51 static char *__rap_reg_profile(RDebug *dbg) {
52 	char *out, *tf = r_file_temp ("rap.XXXXXX");
53 	int fd = r_cons_pipe_open (tf, 1, 0);
54 	r_io_system (dbg->iob.io, "drp");
55 	r_cons_flush ();
56 	r_cons_pipe_close (fd);
57 	out = r_file_slurp (tf, NULL);
58 	r_file_rm (tf);
59 	free (tf);
60 	return out;
61 }
62 
__rap_breakpoint(RBreakpoint * bp,RBreakpointItem * b,bool set)63 static int __rap_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) {
64 	//r_io_system (dbg->iob.io, "db");
65 	return false;
66 }
67 
68 RDebugPlugin r_debug_plugin_rap = {
69 	.name = "rap",
70 	.license = "LGPL3",
71 	.arch = "any",
72 	.bits = R_SYS_BITS_32,
73 	.step = __rap_step,
74 	.cont = __rap_continue,
75 	.attach = &__rap_attach,
76 	.detach = &__rap_detach,
77 	.wait = &__rap_wait,
78 	.breakpoint = __rap_breakpoint,
79 	.reg_read = &__rap_reg_read,
80 	.reg_write = &__rap_reg_write,
81 	.reg_profile = (void *)__rap_reg_profile,
82 	//.bp_write = &__rap_bp_write,
83 	//.bp_read = &__rap_bp_read,
84 };
85 
86 #ifndef R2_PLUGIN_INCORE
87 R_API RLibStruct radare_plugin = {
88 	.type = R_LIB_TYPE_DBG,
89 	.data = &r_debug_plugin_rap,
90 	.version = R2_VERSION
91 };
92 #endif
93