1 /* radare - LGPL - Copyright 2010-2013 - pancake */
2
3 // XXX: All this stuff must be linked to the code injection api
4
5 #include <r_debug.h>
6
r_debug_desc_new(int fd,char * path,int perm,int type,int off)7 R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int off) {
8 RDebugDesc *desc = R_NEW (RDebugDesc);
9 if (desc) {
10 desc->fd = fd;
11 desc->path = strdup (path);
12 desc->perm = perm;
13 desc->type = type;
14 desc->off = off;
15 }
16 return desc;
17 }
18
r_debug_desc_free(RDebugDesc * p)19 R_API void r_debug_desc_free (RDebugDesc *p) {
20 if (p) {
21 if (p->path) {
22 free (p->path);
23 }
24 free (p);
25 }
26 }
27
r_debug_desc_open(RDebug * dbg,const char * path)28 R_API int r_debug_desc_open(RDebug *dbg, const char *path) {
29 if (dbg && dbg->h && dbg->h->desc.open) {
30 return dbg->h->desc.open (path);
31 }
32 return false;
33 }
34
r_debug_desc_close(RDebug * dbg,int fd)35 R_API int r_debug_desc_close(RDebug *dbg, int fd) {
36 if (dbg && dbg->h && dbg->h->desc.close) {
37 return dbg->h->desc.close (fd);
38 }
39 return false;
40 }
41
r_debug_desc_dup(RDebug * dbg,int fd,int newfd)42 R_API int r_debug_desc_dup(RDebug *dbg, int fd, int newfd) {
43 if (dbg && dbg->h && dbg->h->desc.dup) {
44 return dbg->h->desc.dup (fd, newfd);
45 }
46 return false;
47 }
48
r_debug_desc_read(RDebug * dbg,int fd,ut64 addr,int len)49 R_API int r_debug_desc_read(RDebug *dbg, int fd, ut64 addr, int len) {
50 if (dbg && dbg->h && dbg->h->desc.read) {
51 return dbg->h->desc.read (fd, addr, len);
52 }
53 return false;
54 }
55
r_debug_desc_seek(RDebug * dbg,int fd,ut64 addr)56 R_API int r_debug_desc_seek(RDebug *dbg, int fd, ut64 addr) {
57 if (dbg && dbg->h && dbg->h->desc.seek) {
58 return dbg->h->desc.seek (fd, addr);
59 }
60 return false;
61 }
62
r_debug_desc_write(RDebug * dbg,int fd,ut64 addr,int len)63 R_API int r_debug_desc_write(RDebug *dbg, int fd, ut64 addr, int len) {
64 if (dbg && dbg->h && dbg->h->desc.write) {
65 return dbg->h->desc.write (fd, addr, len);
66 }
67 return false;
68 }
69
r_debug_desc_list(RDebug * dbg,int rad)70 R_API int r_debug_desc_list(RDebug *dbg, int rad) {
71 int count = 0;
72 RList *list;
73 RListIter *iter;
74 RDebugDesc *p;
75
76 if (rad) {
77 if (dbg && dbg->cb_printf) {
78 dbg->cb_printf ("TODO \n");
79 }
80 } else {
81 if (dbg && dbg->h && dbg->h->desc.list) {
82 list = dbg->h->desc.list (dbg->pid);
83 r_list_foreach (list, iter, p) {
84 dbg->cb_printf ("%i 0x%"PFMT64x" %c%c%c %s\n", p->fd, p->off,
85 (p->perm & R_PERM_R)?'r':'-',
86 (p->perm & R_PERM_W)?'w':'-',
87 p->type, p->path);
88 }
89 r_list_purge (list);
90 free (list);
91 }
92 }
93 return count;
94 }
95