* Added osxtest.r and adapt rarc2-tool to support rasm2 and rabin2 -c

- rarc2-tool can now create tiny executables!
* Fix segmentation fault in bad use of r_bin_create api
This commit is contained in:
pancake 2011-07-26 00:30:45 +02:00
parent a6b94842f3
commit 041751e029
4 changed files with 57 additions and 13 deletions

View File

@ -14,6 +14,11 @@ config.h:
rarc2${EXT_EXE}: ${OBJS}
${CC} ${LDFLAGS} -I. ${OBJS} -o rarc2${EXT_EXE}
osx:
./rarc2 -ax86 osxtest.r > osxtest.asm
rasm2 -a x86.olly -f osxtest.asm > osxtest.hex
rabin2 -c mach0:$(shell cat osxtest.hex) osxtest
test:
# only works with att mode
./rarc2 t/hello.r > t/hello.S

22
binr/rarc2/osxtest.r Normal file
View File

@ -0,0 +1,22 @@
# This is a rlang test for osx x86-32
# --pancake
main@global(128) {
# puts("Hello World");
exit(42);
}
# XXX: this function without inline doesnt works
exit@global(4) {
: mov eax, 1
: push `.arg0`
: sub esp, 4
: int 0x80
}
/*
puts(4) {
.var0 = strlen(.arg0);
write(1, .arg0, .var0);
}
*/

View File

@ -1,7 +1,6 @@
#!/bin/sh
# pancake / nopcode.org
# radare2 -- 2010-2011 -- pancake / nopcode.org
# TODO: execute in this way? rasc -s $bytes -X
# TODO: use rasm2 instead of gas
[ -z "${ARCH}" ] && ARCH=`rarc2 -A`
[ -z "${CC}" ] && CC=gcc
@ -19,29 +18,45 @@ compile() {
help() {
cat << EOF
Usage: rarc2-tool [-flag] [file]
-b dump bytes
-n use nasm
-x execute
-c compile against libc
-S only generate .S 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 nbSxc o ; do
while getopts rnbSxc: o ; do
[ "$o" = "?" ] && help
eval $o=1
case "$o" in
c) r=1; c="$OPTARG" ;;
*) eval $o=1 ;;
esac
done
shift $((${OPTIND}-1))
if [ -n "`echo $@`" ]; then
if [ -n "$n" ]; then
if [ -n "$r" ]; then
RF=""
ARCH=x86
n=1
elif [ -n "$n" ]; then
RF=""
fi
compile $@
if [ -n "$n" ]; then
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|^\.||' | \
@ -51,8 +66,8 @@ if [ -n "`echo $@`" ]; then
mv .a.S2 .a.S
nasm -f elf .a.S
ld -e main .a.o -o .a.out
# exit 0
else
# gcc (default)
if [ -n "$c" ]; then
${CC} .a.S -o .a.out
else
@ -70,7 +85,7 @@ if [ -n "`echo $@`" ]; then
fi
fi
fi
rm -f .a.S .a.out
rm -f .a.S .a.x .a.out
else
help
fi

View File

@ -422,6 +422,8 @@ R_API void r_bin_bind (RBin *bin, RBinBind *b) {
R_API RBuffer *r_bin_create (RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen) {
RBinArch *a = &bin->curarch;
if (codelen<0) codelen = 0;
if (datalen<0) datalen = 0;
if (a && a->curplugin && a->curplugin->create)
return a->curplugin->create (bin, code, codelen, data, datalen);
return NULL;