radare2/binr/old.rarc2/rarc2-tool

92 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
# radare2 -- 2010-2011 -- pancake / nopcode.org
# TODO: execute in this way? rasc -s $bytes -X
[ -z "${ARCH}" ] && ARCH=`rarc2 -A`
[ -z "${CC}" ] && CC=gcc
RF="-s"
compile() {
spp -h >/dev/null 2>&1
if [ $? = 0 ]; then
spp -Darch=${ARCH} $@ | rarc2 $RF -a${ARCH} > .a.S || exit $?
else
rarc2 $RF -a${ARCH} $@ > .a.S || exit $?
fi
}
help() {
cat << EOF
Usage: rarc2-tool [-flag] [file]
-b dump bytes
-n use nasm instead of gas
-x execute
-c [elf,mach0,pe] - select output format (-r is implicit)
-r use intel syntax and rasm2 to display hexpairs
-c compile against libc
-S only generate .S file
ARCH: environ to set architecture: arm, x86, x64
EOF
exit 1
}
while getopts rnbSxc: o ; do
[ "$o" = "?" ] && help
case "$o" in
c) r=1; c="$OPTARG" ;;
*) eval $o=1 ;;
esac
done
shift $((${OPTIND}-1))
if [ -n "`echo $@`" ]; then
if [ -n "$r" ]; then
RF=""
ARCH=x86
n=1
elif [ -n "$n" ]; then
RF=""
fi
compile $@
if [ -n "$c" ]; then
# rasm2 and rabin2
rasm2 -a x86.olly -f .a.S > .a.x
rabin2 -a x86_32 -c $c:$(cat .a.x) $1.out
elif [ -n "$r" ]; then
rasm2 -a x86.olly -f .a.S
elif [ -n "$n" ]; then
# nasm
cat .a.S | grep -v '^#' | sed -e 's, ptr , ,g' | \
grep -v 'intel_syntax' | \
sed -e 's|^\.||' | \
awk '{if (/^equ /){gsub(","," ");/(.*) (.*) (.*)/;print $2" equ "$3;}else {print}}' | \
sed -e 's|lea eax, dword|lea eax, |g' > .a.S2
#echo 'section .text' > .a.S
mv .a.S2 .a.S
nasm -f elf .a.S
ld -e main .a.o -o .a.out
else
# gcc (default)
if [ -n "$c" ]; then
${CC} .a.S -o .a.out
else
${CC} -nostdlib .a.S -o .a.out
fi
fi
if [ -e .a.out ]; then
if [ -n "$b" ]; then
rabin2 -O d/S/.text .a.out
else
if [ -n "$x" ]; then
./.a.out
else
cp .a.out $1.out
fi
fi
fi
rm -f .a.S .a.x .a.out
else
help
fi