diff --git a/libr/debug/p/gdb.mk b/libr/debug/p/gdb.mk index c266b551b8..2be8ef2d9e 100644 --- a/libr/debug/p/gdb.mk +++ b/libr/debug/p/gdb.mk @@ -8,7 +8,10 @@ ifeq (${OSTYPE},solaris) LDFLAGS+=-lsocket endif -OBJ_GDB=debug_gdb.o libgdbwrap/gdbwrapper.c +OBJ_GDB=debug_gdb.o libgdbwrap/gdbwrapper.o + +libgdbwrap/gdbwrapper.o: + ${CC} -c ${CFLAGS} -o libgdbwrap/gdbwrapper.o libgdbwrap/gdbwrapper.c STATIC_OBJ+=${OBJ_GDB} TARGET_GDB=debug_gdb.${EXT_SO} diff --git a/libr/debug/p/libgdbwrap/include/gdbwrapper.h b/libr/debug/p/libgdbwrap/include/gdbwrapper.h index 4b3b50e17a..c956fde541 100644 --- a/libr/debug/p/libgdbwrap/include/gdbwrapper.h +++ b/libr/debug/p/libgdbwrap/include/gdbwrapper.h @@ -1,5 +1,6 @@ /* File to include to use the wrapper. */ +#include "r_types.h" #if __UNIX__ #include #include diff --git a/libr/include/r_array.h b/libr/include/r_array.h index 4240db3f3f..ab0766fc79 100644 --- a/libr/include/r_array.h +++ b/libr/include/r_array.h @@ -5,12 +5,13 @@ #define r_array_t void** #define rArray void** +#define r_array_iterator(x) x #define r_array_get(x) *(x++) #define r_array_free(x) x #define r_array_cur(x) *x #define r_array_arrayator(x) x #define r_array_next(x) (*x!=0) -#define r_array_rewind(x) (x=r_array_first(x)+1) +#define r_array_rewind(x) (x=r_array_first(x)) #ifdef R_API #if R_ITER_CPP @@ -20,7 +21,7 @@ #define r_array_prev(x) (--it==*it)?0:it #define r_array_delete(x) for(;*x;x++)*x=*(x+1) R_API void **r_array_new(int n); -R_API void **r_array_init(void **ptr, int n); +R_API rArray r_array_init(rArray ptr, int n); R_API void **r_array_first(void **it); R_API void r_array_foreach(void **it, int (*callback)(void *, void *), void *user); R_API void **r_array_free(void **ptr); diff --git a/libr/include/r_userconf.h.acr b/libr/include/r_userconf.h.acr index 785f319fb6..a238fbe196 100644 --- a/libr/include/r_userconf.h.acr +++ b/libr/include/r_userconf.h.acr @@ -2,6 +2,10 @@ #define _INCLUDE_R_CONFIGURE_H_ #define DEBUGGER @DEBUGGER@ + +#ifdef PREFIX +#undef PREFIX +#endif #define PREFIX "@PREFIX@" #endif diff --git a/libr/socket/proc.c b/libr/socket/proc.c index 067adaf54a..cdef4afd60 100644 --- a/libr/socket/proc.c +++ b/libr/socket/proc.c @@ -12,32 +12,37 @@ R_API struct r_socket_proc_t *r_socket_proc_open(char *const argv[]) { #if __UNIX__ struct r_socket_proc_t *sp = MALLOC_STRUCT(struct r_socket_proc_t); - int flags = O_CLOEXEC; //O_NONBLOCK|O_CLOEXEC; + const int flags = O_CLOEXEC; //O_NONBLOCK|O_CLOEXEC; - if (pipe2(sp->fd0, flags)==-1) { + if (pipe (sp->fd0)==-1) { perror("pipe"); free(sp); return NULL; } - if (pipe2(sp->fd1, flags)==-1) { + fcntl (sp->fd0[0], flags); + fcntl (sp->fd0[1], flags); + + if (pipe (sp->fd1)==-1) { perror("pipe"); free(sp); return NULL; } + fcntl (sp->fd1[0], flags); + fcntl (sp->fd1[1], flags); - sp->pid = fork(); - switch(sp->pid) { + sp->pid = fork (); + switch (sp->pid) { case 0: - close(0); - dup2(sp->fd0[0], 0); - close(1); - dup2(sp->fd1[1], 1); - execv(argv[0], argv); - exit(1); + close (0); + dup2 (sp->fd0[0], 0); + close (1); + dup2 (sp->fd1[1], 1); + execv (argv[0], argv); + exit (1); case -1: - perror("fork"); - r_socket_proc_close(sp); - free(sp); + perror ("fork"); + r_socket_proc_close (sp); + free (sp); break; //r_socket_block(sp, R_FALSE); } diff --git a/libr/util/Makefile b/libr/util/Makefile index 8d8cac28bf..d6f392afd1 100644 --- a/libr/util/Makefile +++ b/libr/util/Makefile @@ -1,6 +1,6 @@ NAME=r_util include ../config.mk OBJ=mem.o pool.o num.o str.o re.o hex.o file.o alloca.o -OBJ+=float.o prof.o cache.o sys.o btree.o iter.o buf.o list.o +OBJ+=float.o prof.o cache.o sys.o btree.o array.o buf.o list.o include ../rules.mk diff --git a/libr/util/array.c b/libr/util/array.c new file mode 100644 index 0000000000..856e6f21b4 --- /dev/null +++ b/libr/util/array.c @@ -0,0 +1,111 @@ +/* radare - LGPL - Copyright 2009-2010 pancake */ + +#include "r_util.h" + +R_API void **r_array_init(void **ptr, int n) +{ + *ptr = ptr; + memset (++ptr, 0, n * sizeof(void*)); + return ptr; +} + +R_API void **r_array_new(int n) +{ + void **ptr = (void **)malloc((n+1) * sizeof(void*)); + return r_array_init (ptr, n); +} + +R_API void r_array_set(void **ptr, int idx, void *data) +{ + ptr[idx] = data; +} + +// previously named r_array_get +#if 0 +R_API void *r_array_cur(void **ptr) +{ + return *ptr; +} + +// previously named r_array_next +R_API void **r_array_get(void **it) +{ + return it+1; +} +#endif + +R_API void **r_array_get_n(void **ptr, int idx) +{ + return ptr+idx; +} + +R_API void **r_array_prev(void **it) +{ + return --it, (it==*it)?NULL:it; +} + +R_API void r_array_delete(void **it) +{ + for(; *it; it++) + *it = *(it+1); +} + +#if 0 +/* previously named _last */ +R_API int r_array_next(void **it) +{ + return (*it == NULL); +} +#endif + +R_API void **r_array_first(void **it) +{ + void **p = it; + // TODO: better code + while (1) { + it = r_array_prev(p); + if (!it) break; + p = it; + } + return p; +} + +R_API void r_array_foreach(void **it, int (*callback)(void *, void *), void *user) +{ + r_array_t i = r_array_iterator (it); + while (r_array_next (i)) + callback (r_array_get (i), user); +} + +#if 0 +R_API void **r_array_free(void *ptr) +{ + void **p = r_array_first(ptr); + if (p) free (p-1); + return NULL; +} +#endif + +#if TEST +int main() +{ + int i = 0; + void **it = r_array_new(3); + void **iter = NULL; + + r_array_set(it, 0, "foo"); + r_array_set(it, 1, "bar"); + r_array_set(it, 2, "cow"); + + r_array_delete(r_array_get(it, 1)); + it = r_array_first(r_array_next(it)); + + for(iter = it; r_array_get(iter); iter = r_array_next(iter)) { + printf("%d %s\n", i++, (char *)r_array_get(iter)); + } + + r_array_free(it); + + return 0; +} +#endif diff --git a/libr/util/iter.c b/libr/util/iter.c deleted file mode 100644 index 16f139be7f..0000000000 --- a/libr/util/iter.c +++ /dev/null @@ -1,111 +0,0 @@ -/* radare - LGPL - Copyright 2009-2010 pancake */ - -#include "r_util.h" - -R_API void **r_iter_init(void **ptr, int n) -{ - *ptr = ptr; - memset (++ptr, 0, n * sizeof(void*)); - return ptr; -} - -R_API void **r_iter_new(int n) -{ - void **ptr = (void **)malloc((n+1) * sizeof(void*)); - return r_iter_init (ptr, n); -} - -R_API void r_iter_set(void **ptr, int idx, void *data) -{ - ptr[idx] = data; -} - -// previously named r_iter_get -#if 0 -R_API void *r_iter_cur(void **ptr) -{ - return *ptr; -} - -// previously named r_iter_next -R_API void **r_iter_get(void **it) -{ - return it+1; -} -#endif - -R_API void **r_iter_get_n(void **ptr, int idx) -{ - return ptr+idx; -} - -R_API void **r_iter_prev(void **it) -{ - return --it, (it==*it)?NULL:it; -} - -R_API void r_iter_delete(void **it) -{ - for(; *it; it++) - *it = *(it+1); -} - -#if 0 -/* previously named _last */ -R_API int r_iter_next(void **it) -{ - return (*it == NULL); -} -#endif - -R_API void **r_iter_first(void **it) -{ - void **p = it; - // TODO: better code - while (1) { - it = r_iter_prev(p); - if (!it) break; - p = it; - } - return p; -} - -R_API void r_iter_foreach(void **it, int (*callback)(void *, void *), void *user) -{ - r_iter_t i = r_iter_iterator (it); - while (r_iter_next (i)) - callback (r_iter_get (i), user); -} - -#if 0 -R_API void **r_iter_free(void *ptr) -{ - void **p = r_iter_first(ptr); - if (p) free (p-1); - return NULL; -} -#endif - -#if TEST -int main() -{ - int i = 0; - void **it = r_iter_new(3); - void **iter = NULL; - - r_iter_set(it, 0, "foo"); - r_iter_set(it, 1, "bar"); - r_iter_set(it, 2, "cow"); - - r_iter_delete(r_iter_get(it, 1)); - it = r_iter_first(r_iter_next(it)); - - for(iter = it; r_iter_get(iter); iter = r_iter_next(iter)) { - printf("%d %s\n", i++, (char *)r_iter_get(iter)); - } - - r_iter_free(it); - - return 0; -} -#endif diff --git a/libr/util/t/Makefile b/libr/util/t/Makefile index fc46f6d9a5..0bf5b84316 100644 --- a/libr/util/t/Makefile +++ b/libr/util/t/Makefile @@ -5,7 +5,7 @@ FLAGS=-I../../include -Wl,-R.. -L.. -lr_util -g -DVERSION=\"${VERSION}\" BINS=test${EXT_EXE} BINS+=rax2${EXT_EXE} BINS+=ralloc${EXT_EXE} -BINS+=iter${EXT_EXE} +BINS+=array${EXT_EXE} BINS+=file_slurp_hexpairs${EXT_EXE} BINS+=pool${EXT_EXE} BINS+=test_sys${EXT_EXE} @@ -31,8 +31,8 @@ pool${EXT_EXE}: rax2${EXT_EXE}: ${CC} ${FLAGS} rax2.c -o rax2${EXT_EXE} -iter${EXT_EXE}: - ${CC} ${FLAGS} iter.c -o iter${EXT_EXE} +array${EXT_EXE}: + ${CC} ${FLAGS} array.c -o array${EXT_EXE} file_slurp_hexpairs${EXT_EXE}: ${CC} ${FLAGS} test_file_slurp_hexpairs.c -o file_slurp_hexpairs${EXT_EXE} diff --git a/libr/util/t/array.c b/libr/util/t/array.c new file mode 100644 index 0000000000..0ac9ae422f --- /dev/null +++ b/libr/util/t/array.c @@ -0,0 +1,53 @@ +/* radare - LGPL - Copyright 2009 pancake */ +#include "r_util.h" + +void test_array_new () { + int i = 0; + void **iter, **it = r_array_new (3); + + r_array_set (it, 0, "foo"); + r_array_set (it, 1, "bar"); + r_array_set (it, 2, "cow"); + + r_array_delete (r_array_get_n (it, 1)); + /* NOOP test */ + //it = r_array_first (r_array_get (it)); + //iter = r_array_iterator (it); + r_array_rewind (it); + + for(iter = it; r_array_next (iter); ) { + char *str = r_array_get (iter); + printf ("%d %s\n", i++, str); + } + + r_array_free(it); +} + +void test_array_static () { + int i = 0; + void *data[10]; + rArray iter; + rArray it = (rArray) &data; + + it = (rArray) r_array_init (it, 9); + + r_array_set (it, 0, "foo"); + r_array_set (it, 1, "bar"); + r_array_set (it, 2, "cow"); + + r_array_delete (r_array_get_n (it, 1)); + r_array_rewind (it); + + for(iter = it; r_array_next (iter); ) { + char *str = r_array_get (iter); + printf ("%d %s\n", i++, str); + } +} + +int main() +{ + test_array_new (); + test_array_static (); + + return 0; +} diff --git a/libr/util/t/iter.c b/libr/util/t/iter.c deleted file mode 100644 index e8f9181807..0000000000 --- a/libr/util/t/iter.c +++ /dev/null @@ -1,51 +0,0 @@ -/* radare - LGPL - Copyright 2009 pancake */ -#include "r_util.h" - -void test_iter_new () { - int i = 0; - void **iter, **it = r_iter_new (3); - - r_iter_set (it, 0, "foo"); - r_iter_set (it, 1, "bar"); - r_iter_set (it, 2, "cow"); - - r_iter_delete (r_iter_get_n (it, 1)); - /* NOOP test */ - it = r_iter_first (r_iter_get (it)); - - for(iter = it; r_iter_cur (iter); iter = r_iter_get (iter)) { - printf ("%d %s\n", i++, (char *)r_iter_cur (iter)); - } - - r_iter_free(it); -} - -void test_iter_static () { - int i = 0; - void *data[10]; - r_iter_t it = (r_iter_t) &data; - r_iter_t iter; - - it = (r_iter_t) r_iter_init (it, 9); - - r_iter_set (it, 0, "foo"); - r_iter_set (it, 1, "bar"); - r_iter_set (it, 2, "cow"); - - r_iter_delete (r_iter_get_n (it, 1)); - /* NOOP test */ - it = r_iter_first (r_iter_get (it)); - - for(iter = it; r_iter_cur (iter); iter = r_iter_get (iter)) { - printf ("%d %s\n", i++, (char *)r_iter_cur (iter)); - } -} - -int main() -{ - - test_iter_new (); - test_iter_static (); - - return 0; -} diff --git a/libr/vapi/r_bin.vapi b/libr/vapi/r_bin.vapi index 07c5b7319f..4d8f98cee8 100644 --- a/libr/vapi/r_bin.vapi +++ b/libr/vapi/r_bin.vapi @@ -19,9 +19,9 @@ namespace Radare { // TODO: deprecate public rList symbols; - public rArray get_sections(); - public rArray get_symbols(); - public rArray get_imports(); + //public rArray get_sections(); + //public rArray get_symbols(); + //public rArray get_imports(); public Info* get_info(); public uint64 get_section_offset(string name); diff --git a/libr/vapi/t/Makefile b/libr/vapi/t/Makefile index 7a32d9f7fb..4f9cdaf010 100644 --- a/libr/vapi/t/Makefile +++ b/libr/vapi/t/Makefile @@ -1,4 +1,5 @@ -all: core regs hash sc socket asm search bin db io array list +# bin is broken..waiting for the new api +all: core regs hash sc socket asm search db io array list @true bintest: diff --git a/libr/vapi/t/list_c.c b/libr/vapi/t/list_c.c deleted file mode 100644 index d3fc4e6c69..0000000000 --- a/libr/vapi/t/list_c.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include - -struct list_head head; - -struct foo { - char *name; - struct list_head list; -}; - -struct list_head *get_list() { - INIT_LIST_HEAD(&head); - struct foo *a = malloc(sizeof(struct foo)); - a->name = strdup("hello"); - list_add(&a->list, &head); - struct foo *b = malloc(sizeof(struct foo)); - b->name = strdup("world"); - list_add(&b->list, &head); - return &head; -} - -#if TEST -main() { - struct list_head *list = get_list(); - struct list_head *pos; - list_for_each_prev(pos, list) { - struct foo *p = list_entry(pos, struct foo, list); - printf("%s\n", p->name); - } -} -#endif diff --git a/libr/vapi/t/list_c.h b/libr/vapi/t/list_c.h deleted file mode 100644 index 2fff8fcd99..0000000000 --- a/libr/vapi/t/list_c.h +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -struct list_head head; - -typedef struct foo { - char *name; - struct list_head list; -} foo; - -#define list_entry_vala(pos, type, member) ((type) ((char*)pos -(unsigned long)(&((type)0)->member))) - -#define ralist_iterator(x) x->next -//#define ralist_get(x) list_entry(x, struct foo, list); x=x->next -#define ralist_get(x,y) list_entry_vala(x, y, list); x=x->next -#define ralist_next(x) (x=x->next, (x != head)) -#define ralist_free(x) (x) -//#define foo_free(x) x -//void *ralist_free_(void *a) { return NULL; } diff --git a/libr/vapi/t/socket.vala b/libr/vapi/t/socket.vala index b1b3a4b503..a480791b35 100644 --- a/libr/vapi/t/socket.vala +++ b/libr/vapi/t/socket.vala @@ -7,14 +7,8 @@ using Radare; public static void main(string[] args) { string str = (string) new char[4096]; -#if POSIX - unowned GLib.FILE stdin = &Posix.stdin; - unowned GLib.FILE stdout = &Posix.stdout; -#else - // XXX: not yet supported by vala unowned GLib.FileStream stdin = GLib.stdin; unowned GLib.FileStream stdout = GLib.stdout; -#endif rSocket fd; if (args.length>2) @@ -26,26 +20,28 @@ public static void main(string[] args) printf("Cannot connect\n"); return; } - print("Connected\n"); + print ("Connected\n"); - stdout.printf("[-] waiting for output\n"); - //while(!fd.ready(0,0)); + print ("[-] waiting for output\n"); +/// while (!fd.ready(0,0)); - print("[-] reading data\n"); - //fd.printf("GET /\r\n\r\n"); + print ("[-] reading data\n"); + fd.printf ("GET /\r\n\r\n"); +/* do { string s = (string) new char[1024]; - stdin.scanf("%s", s); - stdout.printf("==> (%s)\n", s); - print("length is = %d\n", (int)s.size()); - fd.printf("GET %s HTTP/1.1\r\nHost: radare.org\r\n\r\n", s); - if (fd.gets(str, 1024)>0) - printf(str+"\n"); + //stdin.scanf("%s", s); + //stdout.printf("==> (%s)\n", s); + print ("length is = %d\n", (int)s.size()); + fd.printf ("GET %s HTTP/1.1\r\nHost: radare.org\r\n\r\n", s); + if (fd.gets (str, 1024)>0) + printf (str+"\n"); else break; - } while(true); + } while (true); +*/ - //while(fd.gets(str, 1024)>0) { - // printf(str+"\n"); - //} + while (fd.gets (str, 1024)>0) { + printf (str+"\n"); + } fd.close(); }