* Added 'om' command to create, destroy and list IO maps

* Upgrade configure script to acr 0.8.8
  - Use proper --libdir LDFLAGS for OSX
  - Honor CPPFLAGS
* Fix help msg of 'yt' command
* Use RList in r_io (rudi_s)
* Fix HOME/END keys in xrvt-unicode
* Add dummy install-cxx target in r2-bindings
This commit is contained in:
pancake 2012-02-07 01:51:56 +01:00
parent d2ac74699b
commit 227c985a08
7 changed files with 132 additions and 58 deletions

23
configure vendored
View File

@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v0.8.6
# This script was automatically generated by ACR v0.8.8
# @author: pancake <youterm.com>
# @url: http://www.nopcode.org
# @repo: hg clone http://hg.youterm.com/acr
@ -64,8 +64,8 @@ if [ -e "${VPATH}/config.guess" ]; then
sh ${VPATH}/config.guess
return
fi
CPU="`uname -m|sed -e 's, ,,g'`"
OS="`uname -s|tr '[A-Z]' '[a-z]'`"
CPU="`uname -m|sed -e 's, ,,g'|cut -d - -f 1`"
OS="`uname -s|tr A-Z a-z`"
GNU="`uname --help 2>&1 | grep gnu`"
[ "${GNU}" ] && OS="${OS}-gnu"
[ "${CPU}" = ppc ] && CPU="powerpc"
@ -166,6 +166,7 @@ printf "
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
CPPFLAGS C preprocessor flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have
@ -186,7 +187,7 @@ take_environ() {
}
show_version() {
echo "radare2-0.9.1hg configuration script done with acr v0.8.6.
echo "radare2-0.9.1hg configuration script done with acr v0.8.8.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <youterm.com>."
exit 0
@ -197,6 +198,12 @@ flag=`echo $1| cut -d = -f 1`
value=`echo $1| awk 'BEGIN{FS="=";}{print $2}'`
flag2=`echo $flag|cut -f2- -d -| sed -e 's,-,_,g' -e 's,^_,,g'|tr '[a-z]' '[A-Z]'`
if [ "${TARGET_OS}" = "darwin" ]; then
LIBPATH=-Wl,-install_name,
else
LIBPATH=-Wl,-R
fi
case $flag in
"-h"|"--help"|"--hel"|"--h"|"--he"|"-help")
show_usage ; ;;
@ -243,7 +250,7 @@ echo "FLAGS: --without-debugger --with-sysmagic --without-ewf --without-gmp
"--localstatedir")
LOCALSTATEDIR="$value"; ;;
"--libdir")
LIBDIR="$value"; LDFLAGS="${LDFLAGS} -L$value -Wl,-R$value"; ;;
LIBDIR="$value"; LDFLAGS="${LDFLAGS} -L$value ${LIBPATH}$value"; ;;
"--includedir")
INCLUDEDIR="$value"; CFLAGS="${CFLAGS} -I$value"; ;;
"--infodir")
@ -280,7 +287,7 @@ parse_options $1
shift
done
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS LIL_ENDIAN BIG_ENDIAN BYTEORDER HAVE_LIB_MAGIC USE_MAGIC USE_LIB_MAGIC LIBMAGIC HAVE_LIB_EWF EWF_CFLAGS EWF_LDFLAGS HAVE_PKGCFG_LIBEWF HAVE_EWF HAVE_LIB_GMP HAVE_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL HAVE_LILEND HAVE_BIGEND HAVE_LIB_LUA5_1 HAVE_LIB_TCC USERCC USEROSTYPE WITHPIC WITHNONPIC LIBVERSION"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS LIL_ENDIAN BIG_ENDIAN BYTEORDER HAVE_LIB_MAGIC USE_MAGIC USE_LIB_MAGIC LIBMAGIC HAVE_LIB_EWF EWF_CFLAGS EWF_LDFLAGS HAVE_PKGCFG_LIBEWF HAVE_EWF HAVE_LIB_GMP HAVE_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL HAVE_LILEND HAVE_BIGEND HAVE_LIB_LUA5_1 HAVE_LIB_TCC USERCC USEROSTYPE WITHPIC WITHNONPIC LIBVERSION"
create_environ
@ -305,7 +312,7 @@ if [ "${CROSSBUILD}" = 1 ]; then
if [ $? = 0 ]; then CC="${HOST}-${CC}"; fi
fi
echo "main(){}" > test.c
(exec ${CC} ${CFLAGS} ${LDFLAGS} test.c >/dev/null 2>&1)
(exec ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} test.c >/dev/null 2>&1)
if [ $? = 0 ]; then echo ${CC}; else
echo no ; HAVE_LANG_C=0
do_remove
@ -347,7 +354,7 @@ _CHKLIB_NAME=$2
_CHKLIB_LIBS=$(echo "-l${_CHKLIB_NAME}" | sed 's,\+, -l,g')
printf "checking for lib${_CHKLIB_NAME} ... "
echo "main(){ }" > test.c
eval ${S}${COMPILER} ${CFLAGS} ${CXXFLAGS} ${LDFLAGS} ${_CHKLIB_LIBS} test.c >/dev/null 2>&1
eval ${S}${COMPILER} ${CFLAGS} ${CPPFLAGS} ${CXXFLAGS} ${LDFLAGS} ${_CHKLIB_LIBS} test.c >/dev/null 2>&1
if [ $? = 0 ]; then
eval ${VAR}=1
echo yes

View File

@ -767,7 +767,7 @@ static int cmd_yank(void *data, const char *input) {
" y 16 @ 0x200 ; copy 16 bytes into clipboard from 0x200\n"
" yp ; print contents of clipboard\n"
" yx ; print contents of clipboard in hexadecimal\n"
" yt 0x200 ; paste clipboard to 0x200\n"
" yt 64 0x200 ; copy 64 bytes from current seek to 0x200\n"
" yy 0x3344 ; paste clipboard\n");
break;
}
@ -4425,18 +4425,70 @@ static int cmd_open(void *data, const char *input) {
eprintf ("Unable to find filedescriptor %d\n", atoi (input+1));
r_core_block_read (core, 0);
break;
case 'm':
switch (input[1]) {
case '?':
r_cons_printf ("Usage: om[-] [arg] file maps\n");
r_cons_printf ("om list all defined IO maps\n");
r_cons_printf ("om-0x10000 remove the map at given address\n");
r_cons_printf ("om 0x10000 remove the map at given address\n");
break;
case ' ':
// i need to parse delta, offset, size
{
ut64 fd = 0LL;
ut64 addr = 0LL;
ut64 size = 0LL;
ut64 delta = 0LL;
char *s = strdup (input+2);
char *p = strchr (s, ' ');
if (p) {
char *q = strchr (p+1, ' ');
*p = 0;
fd = r_num_math (core->num, s);
if (q) {
char *r = strchr (q+1, ' ');
*q = 0;
addr = r_num_math (core->num, p+1);
if (r) {
*r = 0;
size = r_num_math (core->num, q+1);
delta = r_num_math (core->num, r+1);
} else size = r_num_math (core->num, q+1);
r_io_map_add (core->io, fd, 0, delta, addr, size);
} else eprintf ("Usage: om fd addr size [delta]\n");
} else eprintf ("Usage: om fd addr size [delta]\n");
free (s);
}
break;
case '-':
r_io_map_del_at (core->io, r_num_math (core->num, input+2));
break;
case '\0':
{
RIOMap *im = NULL;
RListIter *iter;
r_list_foreach (core->io->maps, iter, im) { // _prev?
r_cons_printf (
"%d 0x%08"PFMT64x" 0x%08"PFMT64x" - 0x%08"PFMT64x"\n",
im->fd, im->delta, im->from, im->to);
}
}
}
break;
case 'o':
r_core_file_reopen (core, input+2);
break;
case '?':
default:
eprintf ("Usage: o[o-] [file] ([offset])\n"
" o ; list opened files\n"
" oo ; reopen current file (kill+fork in debugger)\n"
" o /bin/ls ; open /bin/ls file\n"
" o /bin/ls 0x8048000 ; map file\n"
" o 4 ; priorize io on fd 4 (bring to front)\n"
" o-1 ; close file index 1\n");
" o list opened files\n"
" oo reopen current file (kill+fork in debugger)\n"
" o /bin/ls open /bin/ls file\n"
" o /bin/ls 0x8048000 map file\n"
" om list all maps\n"
" o 4 priorize io on fd 4 (bring to front)\n"
" o-1 close file index 1\n");
break;
}
return 0;

View File

@ -4,7 +4,6 @@
#include <r_types.h>
#include <r_util.h>
#include <r_socket.h>
#include <list.h>
#define R_IO_READ 4
#define R_IO_WRITE 2
@ -106,7 +105,7 @@ typedef struct r_io_t {
/* maps */
RList *maps; /*<RIOMap>*/
RList *desc;
struct list_head cache;
RList *cache;
//XXX: Need by rap
void *user;
int (*core_cmd_cb)(void *user, const char *str);
@ -230,7 +229,7 @@ R_API ut64 r_io_seek(RIO *io, ut64 offset, int whence);
R_API int r_io_system(RIO *io, const char *cmd);
R_API int r_io_close(RIO *io, RIODesc *fd);
R_API ut64 r_io_size(RIO *io); //, int fd);
R_API int r_io_resize(struct r_io_t *io, ut64 newsize);
R_API int r_io_resize(RIO *io, ut64 newsize);
R_API int r_io_accept(RIO *io, int fd);
R_API int r_io_shift(RIO *io, ut64 start, ut64 end, st64 move);
@ -250,6 +249,7 @@ R_API int r_io_bind(RIO *io, struct r_io_bind_t *bnd);
/* io/map.c */
R_API void r_io_map_init(RIO *io);
R_API RIOMap *r_io_map_add(RIO *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size);
R_API int r_io_map_del_at(struct r_io_t *io, ut64 addr);
R_API int r_io_map_del(RIO *io, int fd);
R_API int r_io_map(RIO *io, const char *file, ut64 offset);
R_API int r_io_map_select(RIO *io, ut64 off);

View File

@ -1,16 +1,23 @@
/* radare - LGPL - Copyright 2008-2011 pancake<nopcode.org> */
// TODO: USE RList here
// r_io_cache_t has not been defined
// TODO: implement a more inteligent way to store cached memory
// TODO: define limit of max mem to cache
#include "r_io.h"
static void cache_free(RIOCache *cache) {
if (!cache)
return;
if (cache->data)
free (cache->data);
free (cache);
}
R_API void r_io_cache_init(RIO *io) {
io->cache = r_list_new ();
io->cache->free = (RListFree)cache_free;
io->cached = R_FALSE; // cache write ops
io->cached_read = R_FALSE; // cached read ops
INIT_LIST_HEAD (&io->cache);
}
R_API void r_io_cache_enable(RIO *io, int read, int write) {
@ -19,11 +26,12 @@ R_API void r_io_cache_enable(RIO *io, int read, int write) {
}
R_API void r_io_cache_commit(RIO *io) {
struct list_head *pos, *n;
RListIter *iter;
RIOCache *c;
if (io->cached) {
io->cached = R_FALSE;
list_for_each_safe (pos, n, &io->cache) {
RIOCache *c = list_entry (pos, RIOCache, list);
r_list_foreach (io->cache, iter, c) {
if (!r_io_write_at (io, c->from, c->data, c->size))
eprintf ("Error writing change at 0x%08"PFMT64x"\n", c->from);
}
@ -33,39 +41,30 @@ R_API void r_io_cache_commit(RIO *io) {
}
R_API void r_io_cache_reset(RIO *io, int set) {
struct list_head *pos, *n;
io->cached = set;
list_for_each_safe(pos, n, &io->cache) {
RIOCache *c = list_entry (pos, RIOCache, list);
free (c->data);
free (c);
list_del (pos);
}
// is this necessary at all?
INIT_LIST_HEAD (&io->cache);
r_list_purge (io->cache);
}
R_API int r_io_cache_invalidate(RIO *io, ut64 from, ut64 to) {
int ret = R_FALSE;
struct list_head *pos, *n;
if (from<to)
list_for_each_safe(pos, n, &io->cache) {
RIOCache *c = list_entry (pos, RIOCache, list);
RListIter *iter;
RIOCache *c;
if (from>=to) return R_FALSE;
r_list_foreach (io->cache, iter, c) {
if (c->from >= from && c->to <= to) {
/* REMOVE ITEM */
free (c->data);
free (c);
list_del (pos);
r_list_delete (io->cache, iter);
}
}
return ret;
return R_FALSE;
}
R_API int r_io_cache_list(RIO *io, int rad) {
int i, j = 0;
struct list_head *pos, *n;
list_for_each_safe (pos, n, &io->cache) {
RIOCache *c = list_entry (pos, RIOCache, list);
RListIter *iter;
RIOCache *c;
r_list_foreach (io->cache, iter, c) {
if (rad) {
io->printf ("wx ");
for (i=0; i<c->size; i++)
@ -89,23 +88,23 @@ R_API int r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) {
ch->size = len;
ch->data = (ut8*)malloc (len);
memcpy (ch->data, buf, len);
list_add_tail (&(ch->list), &io->cache);
r_list_append (io->cache, ch);
return len;
}
R_API int r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
int l, ret, da, db;
struct list_head *pos;
RListIter *iter;
RIOCache *c;
list_for_each (pos, &io->cache) {
RIOCache *c = list_entry (pos, RIOCache, list);
r_list_foreach (io->cache, iter, c) {
if (r_range_overlap (addr, addr+len, c->from, c->to, &ret)) {
if (ret>0) {
da = ret;
db = 0;
l = c->size;
} else
if (ret<0) {
} else if (ret<0) {
da = 0;
db = -ret;
l = c->size-db;

View File

@ -32,7 +32,19 @@ R_API int r_io_map_del(struct r_io_t *io, int fd) {
return R_FALSE;
}
R_API RIOMap *r_io_map_add(struct r_io_t *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size) {
R_API int r_io_map_del_at(RIO *io, ut64 addr) {
RIOMap *map;
RListIter *iter;
r_list_foreach (io->maps, iter, map) {
if (map->from == addr) {
r_list_delete (io->maps, iter);
return R_TRUE;
}
}
return R_FALSE;
}
R_API RIOMap *r_io_map_add(RIO *io, int fd, int flags, ut64 delta, ut64 offset, ut64 size) {
RIOMap *im = R_NEW (RIOMap);
if (!im) return NULL;
im->fd = fd;
@ -47,7 +59,7 @@ R_API RIOMap *r_io_map_add(struct r_io_t *io, int fd, int flags, ut64 delta, ut6
R_API int r_io_map_select(RIO *io, ut64 off) {
//ut64 delta = 0;
ut64 fd = -1;//io->fd;
st32 delta = 0;
st32 delta = 0;
RIOMap *im = NULL;
RListIter *iter;
r_list_foreach (io->maps, iter, im) { // _prev?

View File

@ -479,13 +479,14 @@ R_API char *r_line_readline() {
}
r_cons_set_raw (1);
break;
case 0x37: // HOME
case 0x37: // HOME xrvt-unicode
r_cons_readchar ();
case 0x48: // HOME
I.buffer.index = 0;
break;
case 0x34:
case 0x34: // END
case 0x38: // END xrvt-unicode
r_cons_readchar ();
case 0x38: // END
case 0x46: // END
I.buffer.index = I.buffer.length;
break;

View File

@ -126,10 +126,13 @@ PYTHON_VERSION?=`${PYTHON} --version 2>&1 | cut -d ' ' -f 2 | cut -d . -f 1,2`
PYTHON_PKGDIR=$(shell ${PYTHON} mp.py)
PYTHON_INSTALL_DIR=${DESTDIR}/${PYTHON_PKGDIR}/r2
.PHONY: purge purge-python
.PHONY: purge purge-python install-cxx
purge: purge-python
install-cxx:
@echo TODO: install-cxx
purge-python:
[ -n "${PYTHON_PKGDIR}" ] && \
rm -rf ${DESTDIR}/${LIBDIR}/python${PYTHON_VERSION}/*-packages/r2