2017-03-10 09:24:43 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
IFILE="$1"
|
|
|
|
P=`readlink $0`
|
|
|
|
[ -z "$P" ] && P="$0"
|
|
|
|
cd `dirname $P`/..
|
|
|
|
CWD="$PWD"
|
|
|
|
if [ "`echo $IFILE | cut -c 1`" != / ]; then
|
|
|
|
IFILE="$OLDPWD/$IFILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
showHelp() {
|
2017-03-24 21:24:04 +00:00
|
|
|
echo "Usage: r2-docker [-pudlsr] [file] [...]"
|
|
|
|
echo " -p pull latest radare2 docker image from docker hub"
|
|
|
|
echo " -u build the radare2 docker image"
|
2017-03-12 23:31:28 +00:00
|
|
|
echo " -d debug program (linux-x86-32/64)"
|
2017-03-10 09:24:43 +00:00
|
|
|
echo " -l list radare2 docker images"
|
|
|
|
echo " -s enter the shell"
|
2017-03-12 23:31:28 +00:00
|
|
|
echo " -r remove radare2 docker image"
|
2017-03-10 09:24:43 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2017-03-24 21:24:04 +00:00
|
|
|
# Check if docker is present
|
2018-02-05 18:46:35 +00:00
|
|
|
[ -z "$(command -v docker)" ] && (
|
2017-03-24 21:24:04 +00:00
|
|
|
echo "You must install docker first. (see https://docs.docker.com/engine/installation/)"
|
|
|
|
) && exit 1
|
|
|
|
|
|
|
|
# Add capatibility to use ptrace with radare2
|
2017-03-15 09:38:55 +00:00
|
|
|
ALLOW_DEBUG="--cap-add=SYS_PTRACE"
|
2017-03-24 21:24:04 +00:00
|
|
|
|
2019-06-20 04:45:00 +00:00
|
|
|
# Remove by default all capabilities
|
2017-03-24 21:24:04 +00:00
|
|
|
DEFAULT_CAP="--cap-drop=ALL"
|
2017-03-12 23:31:28 +00:00
|
|
|
|
2017-03-10 09:24:43 +00:00
|
|
|
case "$1" in
|
2017-03-24 21:24:04 +00:00
|
|
|
-p)
|
|
|
|
docker pull radare/radare2:latest
|
|
|
|
# Tag image to preserve old reference
|
|
|
|
docker tag radare/radare2:latest radare2:latest
|
|
|
|
;;
|
2017-03-12 23:31:28 +00:00
|
|
|
-r)
|
2017-03-24 21:24:04 +00:00
|
|
|
# Delete all radare2 containers
|
|
|
|
docker rm -f $(docker ps -a | grep radare2 | awk '{print $1}') 2> /dev/null
|
|
|
|
# Delete tag to preserve old reference
|
|
|
|
docker rmi radare2:latest 2> /dev/null
|
|
|
|
docker rmi radare/radare2:latest 2> /dev/null
|
2017-03-12 23:31:28 +00:00
|
|
|
;;
|
|
|
|
-d)
|
|
|
|
R2FLAGS=-d $0 $2
|
|
|
|
;;
|
2017-03-10 09:24:43 +00:00
|
|
|
-u)
|
2017-03-24 21:24:04 +00:00
|
|
|
docker build -t radare/radare2:latest .
|
|
|
|
# Tag image to preserve old reference
|
|
|
|
docker tag radare/radare2:latest radare2:latest
|
2017-03-10 09:24:43 +00:00
|
|
|
;;
|
|
|
|
-l)
|
|
|
|
docker images | grep radare2
|
|
|
|
;;
|
|
|
|
shell|sh|-s)
|
2017-03-24 21:24:04 +00:00
|
|
|
docker run ${ALLOW_DEBUG} ${DEFAULT_CAP} -v $PWD/dockervol:/mnt -ti radare/radare2:latest || echo "run r2-docker -u to update the docker image"
|
2017-03-10 09:24:43 +00:00
|
|
|
;;
|
|
|
|
-h|'')
|
|
|
|
showHelp
|
|
|
|
;;
|
|
|
|
/*|*)
|
|
|
|
if [ -f "$1" ]; then
|
|
|
|
F=`basename $1`
|
|
|
|
D=`dirname $1`
|
|
|
|
# bypass home restriction
|
|
|
|
rm -rf dockervol
|
|
|
|
mkdir -p dockervol
|
|
|
|
cp -f "$1" "dockervol/$F"
|
2017-03-24 21:24:04 +00:00
|
|
|
docker run ${ALLOW_DEBUG} ${DEFAULT_CAP} -v $PWD/dockervol:/mnt -p 9090:9090 -ti radare/radare2:latest r2 ${R2FLAGS} /mnt/$F
|
2017-03-10 09:24:43 +00:00
|
|
|
rm -rf dockervol
|
|
|
|
else
|
2017-03-24 21:24:04 +00:00
|
|
|
docker run ${ALLOW_DEBUG} ${DEFAULT_CAP} -v $PWD/dockervol:/mnt -p 9090:9090 -ti radare/radare2:latest r2 ${R2FLAGS} $1
|
2017-03-10 09:24:43 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|