mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-23 21:29:49 +00:00
* Added libr target to generate libr.a and libr.so
* Build libr_${NAME}.a by default (with PIC objects..) * iter.h -> r_iter.h * Initial import of r_list * Fix name of io.debug plugin --HG-- rename : libr/include/iter.h => libr/include/r_iter.h
This commit is contained in:
parent
b3bf9db87a
commit
882e3e28c6
@ -16,13 +16,27 @@ LIBLIST=util lib io meta lang flags bin bininfo macro hash line cons print confi
|
||||
#LIBSO=libr.so
|
||||
#LIBAR=libr.a
|
||||
|
||||
all:
|
||||
all: libs libr
|
||||
|
||||
libs:
|
||||
@echo PREFIX=${PREFIX}
|
||||
@for lib in ${LIBLIST}; do ( cd $${lib} && ${MAKE} all ); done
|
||||
@echo Build done for: ${LIBLIST}
|
||||
|
||||
libr: .objs libr.a libr.so
|
||||
|
||||
libr.a:
|
||||
ar -r libr.a .objs/*.o
|
||||
|
||||
libr.so:
|
||||
${CC} -shared util/libr_util.so asm/libr_asm.so -o libr.so
|
||||
${CC} -shared -fPIC .objs/*.o -o libr.so
|
||||
|
||||
# XXX needs autodetection of deps to remake and so..
|
||||
.objs:
|
||||
mkdir -p .objs
|
||||
for a in ${LIBLIST} ; do \
|
||||
(cd .objs && ar x ../$$a/libr_$$a.a) ; \
|
||||
done
|
||||
|
||||
pkgcfg:
|
||||
for lib in ${LIBLIST}; do ( cd $${lib} && ${MAKE} pkgcfg ); done
|
||||
@ -100,6 +114,7 @@ todo:
|
||||
clean:
|
||||
for lib in ${LIBLIST}; do ( cd $${lib} && ${MAKE} clean ); done
|
||||
cd vapi/t && ${MAKE} clean
|
||||
rm -rf .objs
|
||||
|
||||
mrproper: clean
|
||||
rm -f libr.pc
|
||||
@ -107,4 +122,4 @@ mrproper: clean
|
||||
sloc:
|
||||
${MAKE} -C .. sloc SLOCDIR=libr
|
||||
|
||||
.PHONY: mrproper clean todo all pkgcfg install deinstall uninstall
|
||||
.PHONY: mrproper clean todo all pkgcfg install deinstall uninstall libr
|
||||
|
@ -2,7 +2,7 @@ NAME=r_asm
|
||||
DEPS=r_lib r_util
|
||||
CFLAGS+=-DCORELIB -Iarch/include -Iarch
|
||||
|
||||
foo: pre libr_asm.so plugins
|
||||
foo: pre ${LIBSO} ${LIBAR} plugins
|
||||
|
||||
include ../config.mk
|
||||
include ${STATIC_ASM_PLUGINS}
|
||||
|
@ -2,11 +2,11 @@ NAME=r_debug
|
||||
DEPS=r_reg r_bp
|
||||
CFLAGS+=-DCORELIB
|
||||
|
||||
foo: pre libr_debug.so tests plugins
|
||||
foo: pre libs tests plugins
|
||||
|
||||
include ../config.mk
|
||||
include ${STATIC_DEBUG_PLUGINS}
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst dbg_,p/dbg_,$(STATIC_OBJ)))
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst debug_,p/debug_,$(STATIC_OBJ)))
|
||||
OBJ=debug.o handle.o pid.o reg.o ${STATIC_OBJS}
|
||||
|
||||
pre:
|
||||
@ -19,3 +19,5 @@ plugins:
|
||||
cd p && ${MAKE} all
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
libs: ${LIBSO} ${LIBAR}
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_io.h>
|
||||
#include <iter.h>
|
||||
#include <r_iter.h>
|
||||
#include <r_list.h>
|
||||
#include <list.h>
|
||||
|
||||
#define R_BIN_SCN_EXECUTABLE(x) x & 0x1
|
||||
|
43
libr/include/r_list.h
Normal file
43
libr/include/r_list.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef _INCLUDE_R_LIST_H_
|
||||
#define _INCLUDE_R_LIST_H_
|
||||
|
||||
typedef void (*rListFree)(void *ptr);
|
||||
|
||||
typedef struct r_list_item_t {
|
||||
void *data;
|
||||
struct r_list_item_t *next, *prev;
|
||||
} rListItem;
|
||||
|
||||
typedef struct r_list_iter_t {
|
||||
struct r_list_item_t *cur;
|
||||
} rListIter;
|
||||
|
||||
typedef struct r_list_t {
|
||||
struct r_list_item_t *head;
|
||||
struct r_list_item_t *tail;
|
||||
rListFree free;
|
||||
} rList;
|
||||
|
||||
#define r_list_iterator(x) r_list_iter_new(x)
|
||||
#define r_list_iter_free(x) free(x)
|
||||
#define r_list_item_free(x) free(x)
|
||||
#define r_list_free(x) free(x)
|
||||
|
||||
#ifdef R_API
|
||||
R_API void r_list_init(rList *list);
|
||||
R_API void r_list_delete (rList *list, rListItem *item);
|
||||
R_API rList *r_list_new();
|
||||
R_API void r_list_iter_init (rListIter *iter, rList *list);
|
||||
R_API rListIter *r_list_iter_new(rList *list);
|
||||
R_API int r_list_empty(rList *list);
|
||||
R_API void *r_list_iter_get(rListIter *iter);
|
||||
R_API void r_list_destroy (rList *list);
|
||||
R_API rListItem *r_list_item_new (void *data);
|
||||
R_API rListItem *r_list_append(rList *list, void *data);
|
||||
R_API rListItem *r_list_head(rList *list);
|
||||
R_API rListItem *r_list_tail(rList *list);
|
||||
R_API rListItem *r_list_prepend(rList *list, void *data);
|
||||
R_API int r_list_iter_next(rListIter *iter);
|
||||
#endif
|
||||
|
||||
#endif
|
@ -3,8 +3,9 @@
|
||||
|
||||
#include "r_types.h"
|
||||
#include <btree.h>
|
||||
#include "list.h"
|
||||
#include "iter.h"
|
||||
#include "r_list.h" // radare linked list
|
||||
#include "r_iter.h" // radare fixed pointer array iterators
|
||||
#include "list.h" // kernel linked list
|
||||
/* profiling */
|
||||
#include <sys/time.h>
|
||||
|
||||
|
@ -13,12 +13,8 @@ LDFLAGS+=$(subst r_,-L../../,$(BINDEPS))
|
||||
BOO=-Wl,-R../../
|
||||
LDFLAGS+=$(subst r_,${BOO},$(BINDEPS))
|
||||
|
||||
# Compiler
|
||||
#CC?=gcc
|
||||
#CFLAGS+=-fPIC
|
||||
#CC_LIB=${CC} -shared -o ${LIBSO}
|
||||
#CC_AR=ar -r ${LIBAR}
|
||||
#LINK?=
|
||||
# Compiler: see mk/gcc.mk
|
||||
# CC CFLAGS CC_LIB CC_AR LINK
|
||||
|
||||
# Debug
|
||||
CFLAGS+=-g -Wall
|
||||
@ -52,7 +48,7 @@ ifneq ($(NAME),)
|
||||
#include ../../mk/${COMPILER}.mk
|
||||
|
||||
CFLAGS+=-I../include
|
||||
real_all all: ${LIBSO} ${EXTRA_TARGETS}
|
||||
real_all all: ${LIBSO} ${LIBAR} ${EXTRA_TARGETS}
|
||||
@-if [ -e t/Makefile ]; then (cd t && ${MAKE} all) ; fi
|
||||
@-if [ -e p/Makefile ]; then (cd p && ${MAKE} all) ; fi
|
||||
@true
|
||||
|
@ -1,5 +1,5 @@
|
||||
NAME=r_util
|
||||
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
|
||||
OBJ+=float.o prof.o cache.o sys.o btree.o iter.o buf.o list.o
|
||||
|
||||
include ../rules.mk
|
||||
|
166
libr/util/list.c
Normal file
166
libr/util/list.c
Normal file
@ -0,0 +1,166 @@
|
||||
#include "r_util.h"
|
||||
|
||||
R_API void r_list_init(rList *list) {
|
||||
list->head = NULL;
|
||||
list->tail = NULL;
|
||||
list->free = NULL;
|
||||
}
|
||||
|
||||
R_API void r_list_delete (rList *list, rListItem *item) {
|
||||
if (list->head == item)
|
||||
list->head = item->next;
|
||||
if (list->tail == item)
|
||||
list->tail = item->prev;
|
||||
if (item->prev)
|
||||
item->prev->next = item->next;
|
||||
if (item->next)
|
||||
item->next->prev = item->prev;
|
||||
if (list->free && item->data) {
|
||||
list->free (item->data);
|
||||
item->data = NULL;
|
||||
}
|
||||
free (item);
|
||||
}
|
||||
|
||||
R_API rList *r_list_new() {
|
||||
rList *list = MALLOC_STRUCT (rList);
|
||||
r_list_init (list);
|
||||
return list;
|
||||
}
|
||||
|
||||
R_API void r_list_iter_init (rListIter *iter, rList *list) {
|
||||
iter->cur = list->head;
|
||||
}
|
||||
|
||||
R_API rListIter *r_list_iter_new(rList *list) {
|
||||
rListIter *iter = MALLOC_STRUCT (rListIter);
|
||||
r_list_iter_init (iter, list);
|
||||
return iter;
|
||||
}
|
||||
|
||||
R_API int r_list_empty(rList *list) {
|
||||
return (list->head == NULL && list->tail == NULL);
|
||||
}
|
||||
|
||||
R_API void *r_list_iter_get(rListIter *iter) {
|
||||
void *data = iter->cur->data;
|
||||
iter->cur = iter->cur->next;
|
||||
return data;
|
||||
}
|
||||
|
||||
R_API void r_list_destroy (rList *list) {
|
||||
/* TODO: free elements */
|
||||
if (list->free) {
|
||||
rListIter i = { list->head };
|
||||
while (i.cur) {
|
||||
rListItem *next = i.cur->next;
|
||||
r_list_delete (list, i.cur);
|
||||
i.cur = next;
|
||||
}
|
||||
}
|
||||
list->head = list->tail = NULL;
|
||||
//free (list);
|
||||
}
|
||||
|
||||
R_API rListItem *r_list_item_new (void *data) {
|
||||
rListItem *new = MALLOC_STRUCT (rListItem);
|
||||
new->data = data;
|
||||
return new;
|
||||
}
|
||||
|
||||
R_API rListItem *r_list_append(rList *list, void *data) {
|
||||
rListItem *new = MALLOC_STRUCT (rListItem);
|
||||
if (list->tail)
|
||||
list->tail->next = new;
|
||||
new->data = data;
|
||||
new->prev = list->tail;
|
||||
new->next = NULL;
|
||||
list->tail = new;
|
||||
if (list->head == NULL)
|
||||
list->head = new;
|
||||
return new;
|
||||
}
|
||||
|
||||
R_API rListItem *r_list_head(rList *list) {
|
||||
return list->head;
|
||||
}
|
||||
|
||||
R_API rListItem *r_list_tail(rList *list) {
|
||||
return list->tail;
|
||||
}
|
||||
|
||||
R_API rListItem *r_list_prepend(rList *list, void *data) {
|
||||
rListItem *new = MALLOC_STRUCT (rListItem);
|
||||
if (list->head)
|
||||
list->head->prev = new;
|
||||
new->data = data;
|
||||
new->next = list->head;
|
||||
new->prev = NULL;
|
||||
list->head = new;
|
||||
if (list->tail == NULL)
|
||||
list->tail = new;
|
||||
return new;
|
||||
}
|
||||
|
||||
R_API int r_list_iter_next(rListIter *iter) {
|
||||
return (iter->cur)?1:0;
|
||||
}
|
||||
|
||||
#if TEST
|
||||
int main () {
|
||||
struct r_list_item_t *it;
|
||||
struct r_list_iter_t *iter;
|
||||
struct r_list_t *l = r_list_new ();
|
||||
|
||||
r_list_append (l, "foo");
|
||||
r_list_append (l, "bar");
|
||||
r_list_append (l, "cow");
|
||||
r_list_prepend (l, "HEAD");
|
||||
r_list_prepend (l, "HEAD 00");
|
||||
it = r_list_append (l, "LAST");
|
||||
|
||||
r_list_delete (l, it);
|
||||
|
||||
iter = r_list_iterator (l);
|
||||
while (r_list_iter_next (iter)) {
|
||||
rListItem *cur = iter->cur;
|
||||
char *str = r_list_iter_get (iter);
|
||||
if (!strcmp (str, "bar"))
|
||||
r_list_delete (l, cur);
|
||||
}
|
||||
|
||||
iter = r_list_iterator (l);
|
||||
while (r_list_iter_next (iter)) {
|
||||
char *str = r_list_iter_get (iter);
|
||||
r_list_delete (list, iter);
|
||||
printf (" - %s\n", str);
|
||||
}
|
||||
|
||||
r_list_destroy (l);
|
||||
r_list_free (l);
|
||||
|
||||
/* ------------- */
|
||||
l = r_list_new ();
|
||||
|
||||
r_list_append (l, strdup ("one"));
|
||||
r_list_append (l, strdup ("two"));
|
||||
r_list_append (l, strdup ("tri"));
|
||||
it = r_list_append (l, strdup ("LAST"));
|
||||
|
||||
r_list_delete (l, it);
|
||||
|
||||
{
|
||||
rListIter i = { l->head };
|
||||
r_list_iter_init (&i, l);
|
||||
for (; i.cur; i.cur = i.cur->next) {
|
||||
char *str = i.cur->data;
|
||||
printf (" * %s\n", str);
|
||||
}
|
||||
}
|
||||
|
||||
l->free = free;
|
||||
r_list_destroy (l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -48,7 +48,7 @@ namespace Radare {
|
||||
}
|
||||
|
||||
[CCode (cname="struct r_asm_fastcall_t", destroy_function="" )]
|
||||
public class Fastcall {
|
||||
public struct Fastcall {
|
||||
public string arg[16];
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ namespace Radare {
|
||||
public int assemble(out Aop aop, string buf);
|
||||
public Code? mdisassemble(uint8 *buf, uint64 length);
|
||||
public Code? massemble(string buf);
|
||||
public Fastcall fastcall(int idx, int num);
|
||||
public static Fastcall fastcall(int idx, int num);
|
||||
//public int parse();
|
||||
// This is the destructor
|
||||
public void free();
|
||||
|
@ -37,7 +37,7 @@ public class rAsmExample
|
||||
|
||||
stdout.printf("Enumerate fastcall arguments:\n");
|
||||
for(int i=0;i<4;i++) {
|
||||
stdout.printf(" - %s\n", st.fastcall(i, 4));
|
||||
stdout.printf(" - %s\n", st.fastcall(i, 4).arg[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ bp.arm
|
||||
bp.x86
|
||||
crypto.aes
|
||||
debug.ptrace
|
||||
io.dbg
|
||||
io.debug
|
||||
io.malloc
|
||||
io.ptrace
|
||||
io.shm
|
||||
|
Loading…
Reference in New Issue
Block a user