mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-01 00:51:19 +00:00
* Fix build of bea asm plugin
* Fix build of gdbwrapper debug plugin * Fixes related to the r_iter -> r_array rename - rbin vapi is broken now.. waiting for major changes to sync * Fix build of socket/proc on non-gnu systems --HG-- rename : libr/util/iter.c => libr/util/array.c rename : libr/util/t/iter.c => libr/util/t/array.c
This commit is contained in:
parent
b0a48c14de
commit
d09720001f
@ -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}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/* File to include to use the wrapper. */
|
||||
|
||||
#include "r_types.h"
|
||||
#if __UNIX__
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.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);
|
||||
|
@ -2,6 +2,10 @@
|
||||
#define _INCLUDE_R_CONFIGURE_H_
|
||||
|
||||
#define DEBUGGER @DEBUGGER@
|
||||
|
||||
#ifdef PREFIX
|
||||
#undef PREFIX
|
||||
#endif
|
||||
#define PREFIX "@PREFIX@"
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
111
libr/util/array.c
Normal file
111
libr/util/array.c
Normal file
@ -0,0 +1,111 @@
|
||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
|
||||
#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
|
111
libr/util/iter.c
111
libr/util/iter.c
@ -1,111 +0,0 @@
|
||||
/* radare - LGPL - Copyright 2009-2010 pancake<nopcode.org> */
|
||||
|
||||
#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
|
@ -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}
|
||||
|
53
libr/util/t/array.c
Normal file
53
libr/util/t/array.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
#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;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
#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;
|
||||
}
|
@ -19,9 +19,9 @@ namespace Radare {
|
||||
// TODO: deprecate
|
||||
public rList<rBin.Symbol*> symbols;
|
||||
|
||||
public rArray<rBin.Section> get_sections();
|
||||
public rArray<rBin.Symbol> get_symbols();
|
||||
public rArray<rBin.Import> get_imports();
|
||||
//public rArray<rBin.Section> get_sections();
|
||||
//public rArray<rBin.Symbol> get_symbols();
|
||||
//public rArray<rBin.Import> get_imports();
|
||||
|
||||
public Info* get_info();
|
||||
public uint64 get_section_offset(string name);
|
||||
|
@ -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:
|
||||
|
@ -1,33 +0,0 @@
|
||||
#include <list.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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
|
@ -1,21 +0,0 @@
|
||||
#include <list.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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; }
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user