* Added sys/ in order to ease build, deps and python /cc @hteso

* Some fixes in r_magic api to make r_lang/perl compile
This commit is contained in:
pancake 2011-09-10 02:19:06 +02:00
parent 323441c122
commit 2415d86fd6
23 changed files with 295 additions and 61 deletions

View file

@ -9,7 +9,7 @@ Crosscompilation
ArchLinux
---------
./configure --without-gmp --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows --without-magic --without-ssl
./configure --without-gmp --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows --without-ssl
make
make w32dist
@ -26,7 +26,7 @@ Crosscompilation
Ubuntu
------
sudo apt-get install mingw32
./configure --without-gmp --with-compiler=i586-mingw32msvc-gcc --with-ostype=windows --host=i586-unknown-windows --without-magic
./configure --without-gmp --with-compiler=i586-mingw32msvc-gcc --with-ostype=windows --host=i586-unknown-windows
make
make w32dist

View file

@ -53,7 +53,7 @@
#define FILE_CHECK 1
#define FILE_COMPILE 2
struct magic {
struct r_magic {
/* Word 1 */
ut16 cont_level; /* level of ">" */
ut8 flag;
@ -218,7 +218,7 @@ struct magic {
/* list of magic entries */
struct mlist {
struct magic *magic; /* array of magic entries */
struct r_magic *magic; /* array of magic entries */
ut32 nmagic; /* number of entries in array */
int mapped; /* allocation type: 0 => apprentice_file
* 1 => apprentice_map + malloc

View file

@ -76,7 +76,7 @@
#endif
struct r_magic_entry {
struct magic *mp;
struct r_magic *mp;
uint32_t cont_count;
uint32_t max_count;
};
@ -86,7 +86,7 @@ const size_t file_nformats = FILE_NAMES_SIZE;
const char *file_names[FILE_NAMES_SIZE];
const size_t file_nnames = FILE_NAMES_SIZE;
static int getvalue(struct r_magic_set *ms, struct magic *, const char **, int);
static int getvalue(struct r_magic_set *ms, struct r_magic *, const char **, int);
static int hextoint(int);
static const char *getstr(struct r_magic_set *, const char *, char *, int,
int *, int);
@ -96,26 +96,26 @@ static int parse_mime(struct r_magic_set *, struct r_magic_entry **, uint32_t *,
const char *);
static void eatsize(const char **);
static int apprentice_1(struct r_magic_set *, const char *, int, struct mlist *);
static size_t apprentice_r_magic_strength(const struct magic *);
static size_t apprentice_r_magic_strength(const struct r_magic *);
static int apprentice_sort(const void *, const void *);
static int apprentice_load(struct r_magic_set *, struct magic **, uint32_t *,
static int apprentice_load(struct r_magic_set *, struct r_magic **, uint32_t *,
const char *, int);
static void byteswap(struct magic *, uint32_t);
static void bs1(struct magic *);
static void byteswap(struct r_magic *, uint32_t);
static void bs1(struct r_magic *);
static uint16_t swap2(uint16_t);
static uint32_t swap4(uint32_t);
static uint64_t swap8(uint64_t);
static void mkdbname(const char *, char **, int);
static int apprentice_map(struct r_magic_set *, struct magic **, uint32_t *,
static int apprentice_map(struct r_magic_set *, struct r_magic **, uint32_t *,
const char *);
static int apprentice_compile(struct r_magic_set *, struct magic **, uint32_t *,
static int apprentice_compile(struct r_magic_set *, struct r_magic **, uint32_t *,
const char *);
static int check_format_type(const char *, int);
static int check_format(struct r_magic_set *, struct magic *);
static int check_format(struct r_magic_set *, struct r_magic *);
static int get_op(char);
static size_t maxmagic = 0;
static size_t magicsize = sizeof(struct magic);
static size_t magicsize = sizeof(struct r_magic);
static const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc";
static const char mime_marker[] = "!:mime";
@ -244,7 +244,7 @@ static int
apprentice_1(struct r_magic_set *ms, const char *fn, int action,
struct mlist *mlist)
{
struct magic *magic = NULL;
struct r_magic *magic = NULL;
uint32_t nmagic = 0;
struct mlist *ml;
int rv = -1;
@ -302,7 +302,7 @@ apprentice_1(struct r_magic_set *ms, const char *fn, int action,
}
void
file_delmagic(struct magic *p, int type, size_t entries)
file_delmagic(struct r_magic *p, int type, size_t entries)
{
if (p == NULL)
return;
@ -377,7 +377,7 @@ file_apprentice(struct r_magic_set *ms, const char *fn, int action)
* Get weight of this magic entry, for sorting purposes.
*/
static size_t
apprentice_r_magic_strength(const struct magic *m)
apprentice_r_magic_strength(const struct r_magic *m)
{
#define MULT 10
size_t val = 2 * MULT; /* baseline strength */
@ -503,7 +503,7 @@ apprentice_sort(const void *a, const void *b)
}
static void
set_test_type(struct magic *mstart, struct magic *m)
set_test_type(struct r_magic *mstart, struct r_magic *m)
{
switch (m->type) {
case FILE_BYTE:
@ -612,7 +612,7 @@ load_1(struct r_magic_set *ms, int action, const char *fn, int *errs,
* const char *fn: name of magic file or directory
*/
static int
apprentice_load(struct r_magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
apprentice_load(struct r_magic_set *ms, struct r_magic **magicp, uint32_t *nmagicp,
const char *fn, int action)
{
int errs = 0;
@ -743,7 +743,7 @@ out:
* extend the sign bit if the comparison is to be signed
*/
uint64_t
file_signextend(struct r_magic_set *ms, struct magic *m, uint64_t v)
file_signextend(struct r_magic_set *ms, struct r_magic *m, uint64_t v)
{
if (!(m->flag & UNSIGNED)) {
switch(m->type) {
@ -810,7 +810,7 @@ file_signextend(struct r_magic_set *ms, struct magic *m, uint64_t v)
}
static int
string_modifier_check(struct r_magic_set *ms, struct magic *m)
string_modifier_check(struct r_magic_set *ms, struct r_magic *m)
{
if ((ms->flags & R_MAGIC_CHECK) == 0)
return 0;
@ -970,7 +970,7 @@ parse(struct r_magic_set *ms, struct r_magic_entry **mentryp, uint32_t *nmentryp
#endif
size_t i;
struct r_magic_entry *me;
struct magic *m;
struct r_magic *m;
const char *l = line;
char *t;
int op;
@ -999,7 +999,7 @@ parse(struct r_magic_set *ms, struct r_magic_entry **mentryp, uint32_t *nmentryp
}
me = &(*mentryp)[*nmentryp - 1];
if (me->cont_count == me->max_count) {
struct magic *nm;
struct r_magic *nm;
size_t cnt = me->max_count + ALLOC_CHUNK;
if ((nm = realloc(me->mp, sizeof(*nm) * cnt)) == NULL) {
file_oomem(ms, sizeof(*nm) * cnt);
@ -1343,7 +1343,7 @@ parse_mime(struct r_magic_set *ms, struct r_magic_entry **mentryp,
{
size_t i;
const char *l = line;
struct magic *m;
struct r_magic *m;
struct r_magic_entry *me;
if (*nmentryp == 0) {
@ -1509,7 +1509,7 @@ check_format_type(const char *ptr, int type)
* the type of the magic.
*/
static int
check_format(struct r_magic_set *ms, struct magic *m)
check_format(struct r_magic_set *ms, struct r_magic *m)
{
char *ptr;
@ -1565,7 +1565,7 @@ check_format(struct r_magic_set *ms, struct magic *m)
* just after the number read. Return 0 for success, non-zero for failure.
*/
static int
getvalue(struct r_magic_set *ms, struct magic *m, const char **p, int action)
getvalue(struct r_magic_set *ms, struct r_magic *m, const char **p, int action)
{
int slen;
@ -1874,7 +1874,7 @@ eatsize(const char **p)
* handle a compiled file.
*/
static int
apprentice_map(struct r_magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
apprentice_map(struct r_magic_set *ms, struct r_magic **magicp, uint32_t *nmagicp,
const char *fn)
{
int fd;
@ -1941,7 +1941,7 @@ apprentice_map(struct r_magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
VERSIONNO, dbname, version);
goto error1;
}
*nmagicp = (uint32_t)(st.st_size / sizeof(struct magic));
*nmagicp = (uint32_t)(st.st_size / sizeof(struct r_magic));
if (*nmagicp > 0)
(*nmagicp)--;
(*magicp)++;
@ -1975,7 +1975,7 @@ static const uint32_t ar[] = {
* handle an mmaped file.
*/
static int
apprentice_compile(struct r_magic_set *ms, struct magic **magicp,
apprentice_compile(struct r_magic_set *ms, struct r_magic **magicp,
uint32_t *nmagicp, const char *fn)
{
int fd;
@ -1997,14 +1997,14 @@ apprentice_compile(struct r_magic_set *ms, struct magic **magicp,
goto out;
}
if (lseek(fd, (off_t)sizeof(struct magic), SEEK_SET)
!= sizeof(struct magic)) {
if (lseek(fd, (off_t)sizeof(struct r_magic), SEEK_SET)
!= sizeof(struct r_magic)) {
file_error(ms, errno, "error seeking `%s'", dbname);
goto out;
}
if (write(fd, *magicp, (sizeof(struct magic) * *nmagicp))
!= (ssize_t)(sizeof(struct magic) * *nmagicp)) {
if (write(fd, *magicp, (sizeof(struct r_magic) * *nmagicp))
!= (ssize_t)(sizeof(struct r_magic) * *nmagicp)) {
file_error(ms, errno, "error writing `%s'", dbname);
goto out;
}
@ -2040,7 +2040,7 @@ mkdbname(const char *fn, char **buf, int strip)
* Byteswap an mmap'ed file if needed
*/
static void
byteswap(struct magic *magic, uint32_t nmagic)
byteswap(struct r_magic *magic, uint32_t nmagic)
{
uint32_t i;
for (i = 0; i < nmagic; i++)
@ -2112,7 +2112,7 @@ swap8(uint64_t sv)
* byteswap a single magic entry
*/
static void
bs1(struct magic *m)
bs1(struct r_magic *m)
{
m->cont_level = swap2(m->cont_level);
m->offset = swap4((uint32_t)m->offset);

View file

@ -68,16 +68,16 @@ int file_ascmagic(struct r_magic_set *, const unsigned char *, size_t);
int file_is_tar(struct r_magic_set *, const unsigned char *, size_t);
int file_softmagic(struct r_magic_set *, const unsigned char *, size_t, int);
struct mlist *file_apprentice(struct r_magic_set *, const char *, int);
ut64 file_signextend(struct r_magic_set *, struct magic *,
ut64 file_signextend(struct r_magic_set *, struct r_magic *,
ut64);
void file_delmagic(struct magic *, int type, size_t entries);
void file_delmagic(struct r_magic *, int type, size_t entries);
void file_badread(struct r_magic_set *);
void file_badseek(struct r_magic_set *);
void file_oomem(struct r_magic_set *, size_t);
void file_error(struct r_magic_set *, int, const char *, ...);
void file_magerror(struct r_magic_set *, const char *, ...);
void file_magwarn(struct r_magic_set *, const char *, ...);
void file_mdump(struct magic *);
void file_mdump(struct r_magic *);
void file_showstr(FILE *, const char *, size_t);
size_t file_mbswidth(const char *);
const char *file_getbuffer(struct r_magic_set *);

View file

@ -45,7 +45,7 @@
#ifndef COMPILE_ONLY
void
file_mdump(struct magic *m)
file_mdump(struct r_magic *m)
{
static const char optyp[] = { FILE_OPS };

View file

@ -37,21 +37,21 @@
#include <time.h>
static int match(struct r_magic_set *, struct magic *, uint32_t,
static int match(struct r_magic_set *, struct r_magic *, uint32_t,
const unsigned char *, size_t, int);
static int mget(struct r_magic_set *, const unsigned char *,
struct magic *, size_t, unsigned int);
static int magiccheck(struct r_magic_set *, struct magic *);
static int32_t mprint(struct r_magic_set *, struct magic *);
struct r_magic *, size_t, unsigned int);
static int magiccheck(struct r_magic_set *, struct r_magic *);
static int32_t mprint(struct r_magic_set *, struct r_magic *);
static void mdebug(uint32_t, const char *, size_t);
static int mcopy(struct r_magic_set *, union VALUETYPE *, int, int,
const unsigned char *, uint32_t, size_t, size_t);
static int mconvert(struct r_magic_set *, struct magic *);
static int mconvert(struct r_magic_set *, struct r_magic *);
static int print_sep(struct r_magic_set *, int);
static void cvt_8(union VALUETYPE *, const struct magic *);
static void cvt_16(union VALUETYPE *, const struct magic *);
static void cvt_32(union VALUETYPE *, const struct magic *);
static void cvt_64(union VALUETYPE *, const struct magic *);
static void cvt_8(union VALUETYPE *, const struct r_magic *);
static void cvt_16(union VALUETYPE *, const struct r_magic *);
static void cvt_32(union VALUETYPE *, const struct r_magic *);
static void cvt_64(union VALUETYPE *, const struct r_magic *);
/*
* Macro to give description string according to whether we want plain
@ -104,7 +104,7 @@ file_softmagic(struct r_magic_set *ms, const unsigned char *buf, size_t nbytes,
* so that higher-level continuations are processed.
*/
static int
match(struct r_magic_set *ms, struct magic *magic, uint32_t nmagic,
match(struct r_magic_set *ms, struct r_magic *magic, uint32_t nmagic,
const unsigned char *s, size_t nbytes, int mode)
{
uint32_t magindex = 0;
@ -119,7 +119,7 @@ match(struct r_magic_set *ms, struct magic *magic, uint32_t nmagic,
for (magindex = 0; magindex < nmagic; magindex++) {
int flush;
struct magic *m = &magic[magindex];
struct r_magic *m = &magic[magindex];
if ((m->flag & BINTEST) != mode) {
/* Skip sub-tests */
@ -276,7 +276,7 @@ match(struct r_magic_set *ms, struct magic *magic, uint32_t nmagic,
}
static int
check_fmt(struct r_magic_set *ms, struct magic *m)
check_fmt(struct r_magic_set *ms, struct r_magic *m)
{
regex_t rx;
int rc;
@ -317,7 +317,7 @@ strndup(const char *str, size_t n)
#endif /* HAVE_STRNDUP */
static int32_t
mprint(struct r_magic_set *ms, struct magic *m)
mprint(struct r_magic_set *ms, struct r_magic *m)
{
uint64_t v;
float vf;
@ -573,25 +573,25 @@ mprint(struct r_magic_set *ms, struct magic *m)
p->fld = ~p->fld \
static void
cvt_8(union VALUETYPE *p, const struct magic *m)
cvt_8(union VALUETYPE *p, const struct r_magic *m)
{
DO_CVT(b, (uint8_t));
}
static void
cvt_16(union VALUETYPE *p, const struct magic *m)
cvt_16(union VALUETYPE *p, const struct r_magic *m)
{
DO_CVT(h, (uint16_t));
}
static void
cvt_32(union VALUETYPE *p, const struct magic *m)
cvt_32(union VALUETYPE *p, const struct r_magic *m)
{
DO_CVT(l, (uint32_t));
}
static void
cvt_64(union VALUETYPE *p, const struct magic *m)
cvt_64(union VALUETYPE *p, const struct r_magic *m)
{
DO_CVT(q, (uint64_t));
}
@ -614,13 +614,13 @@ cvt_64(union VALUETYPE *p, const struct magic *m)
} \
static void
cvt_float(union VALUETYPE *p, const struct magic *m)
cvt_float(union VALUETYPE *p, const struct r_magic *m)
{
DO_CVT2(f, (float));
}
static void
cvt_double(union VALUETYPE *p, const struct magic *m)
cvt_double(union VALUETYPE *p, const struct r_magic *m)
{
DO_CVT2(d, (double));
}
@ -631,7 +631,7 @@ cvt_double(union VALUETYPE *p, const struct magic *m)
* (unless you have a better idea)
*/
static int
mconvert(struct r_magic_set *ms, struct magic *m)
mconvert(struct r_magic_set *ms, struct r_magic *m)
{
union VALUETYPE *p = &ms->ms_value;
@ -884,7 +884,7 @@ mcopy(struct r_magic_set *ms, union VALUETYPE *p, int type, int indir,
static int
mget(struct r_magic_set *ms, const unsigned char *s,
struct magic *m, size_t nbytes, unsigned int cont_level)
struct r_magic *m, size_t nbytes, unsigned int cont_level)
{
uint32_t offset = ms->offset;
uint32_t count = m->str_range;
@ -1505,7 +1505,7 @@ file_strncmp16(const char *a, const char *b, size_t len, uint32_t flags)
}
static int
magiccheck(struct r_magic_set *ms, struct magic *m)
magiccheck(struct r_magic_set *ms, struct r_magic *m)
{
uint64_t l = m->value.q;
uint64_t v;

3
sys/CONFIG Normal file
View file

@ -0,0 +1,3 @@
PYTHON_VERSION=2.7
#TODO: PREFIX=/usr

3
sys/README Normal file
View file

@ -0,0 +1,3 @@
This directory contains the scripts used to ease updates,
compilation, and dependency fixes required to maintain
a system wide installation of radare2.

17
sys/a Normal file
View file

@ -0,0 +1,17 @@
CONFIG
README
a
all.sh
clean.sh
full-uninstall.sh
gtkaml.sh
install.sh
mingw32-deps.sh
mingw32.sh
python-deps.sh
python.sh
swig.sh
uninstall.sh
update.sh
vala.sh
valabind.sh

12
sys/all.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0` ; cd ..
run() {
[ ! -x sys/.mark_$1 ] && sys/$1.sh
}
run install
run python-deps
run python

2
sys/clean.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
rm -f .mark*

6
sys/full-uninstall.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0` ; cd ..
make purge

18
sys/gtkaml.sh Executable file
View file

@ -0,0 +1,18 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0`
mkdir -p _work
cd _work
if [ -d gtkaml ]; then
cd gtkaml
svn up
else
svn co https://gtkaml.googlecode.com/svn/trunk gtkaml
cd gtkaml
fi
sh autogen.sh --prefix=/usr && \
make && \
sudo make install

24
sys/install.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0` ; cd ..
# update
if [ -d .hg ]; then
hg pull -u
elif [ -d .git ]; then
git pull
fi
ccache --help 2>&1 > /dev/null
if [ $? = 0 ]; then
[ -z "${CC}" ] && CC=gcc
CC="ccache ${CC}"
export CC
fi
# build
make mrproper && \
./configure --prefix=/usr && \
make -j 4 && \
sudo make symstall

12
sys/mingw32-deps.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/sh
if [ -x /usr/bin/pacman ]; then
sudo pacman -S mingw32-gcc
elif [ -x /usr/bin/apt-get ]; then
sudo apt-get install mingw32
elif [ -x /opt/local/bin/port ]; then
sudo port install i386-mingw32-gcc
else
echo "ubuntu/debian or archlinux required."
exit 1
fi

15
sys/mingw32.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
if [ -x /usr/bin/pacman ]; then
make clean
./configure --without-gmp --with-compiler=i486-mingw32-gcc --with-ostype=windows --host=i486-unknown-windows --without-ssl && \
make && \
make w32dist
elif [ -x /usr/bin/apt-get ]; then
./configure --without-gmp --with-compiler=i586-mingw32msvc-gcc --with-ostype=windows --host=i586-unknown-windows && \
make && \
make w32dist
else
echo "ubuntu/debian or archlinux required."
exit 1
fi

13
sys/python-deps.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0`
. ./CONFIG
./swig.sh
./vala.sh
./valabind.sh
#apt-get install ${PYTHON_VERSION}
:> .mark_python-deps

15
sys/python.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0` ; cd ..
. ./sys/CONFIG
export PYTHON_CONFIG
cd r2-bindings
./configure --prefix=/usr --enable-devel --enable=python
cd python
make clean
make
sudo make install

13
sys/swig.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0`
if [ -x /opt/local/bin/port ]; then
sudo port install i386-mingw32-gcc
elif [ -x /usr/bin/pacman ]; then
sudo pacman -S swig
elif [ -x /usr/bin/apt-get ]; then
sudo apt-get install swig
fi
:>.mark_swig

6
sys/uninstall.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0` ; cd ..
make deinstall

23
sys/update.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0` ; cd ..
# update
if [ -d .hg ]; then
hg pull -u
elif [ -d .git ]; then
git pull
fi
ccache --help 2>&1 > /dev/null
if [ $? = 0 ]; then
[ -z "${CC}" ] && CC=gcc
CC="ccache ${CC}"
export CC
fi
# build
./configure --prefix=/usr && \
make -j 4 && \
sudo make symstall

35
sys/vala.sh Executable file
View file

@ -0,0 +1,35 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0`
mkdir -p _work
cd _work
valac --help 2>&1 >/dev/null
if [ ! $? = 0 ]; then
# must install from tarball
VV=0.13.4
SV=$(echo ${VV}|cut -d . -f 1,2)
if [ ! -d vala-${VV} ]; then
wget http://download.gnome.org/sources/vala/${SV}/vala-${VV}.tar.bz2
tar xjvf vala-${VV}.tar.bz2
fi
cd vala-${VV}
./configure --prefix=/usr && \
make && \
sudo make install
cd ..
fi
if [ -d vala ]; then
cd vala
sudo make uninstall
git pull
else
git clone git://git.gnome.org/vala
fi
sh autogen.sh --prefix=/usr
make
sudo make install
cd ..

17
sys/valabind.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
# find root
cd `dirname $PWD/$0`
mkdir -p _work
cd _work
if [ -d valabind ]; then
cd valabind
hg pull -u
else
hg clone http://hg.youterm.com/valabind
cd valabind
fi
make
sudo make install