OPTS = -f elf -DLINUX -Dstand_alone

# change o to name your output file
o = sishell

# don't change these
name = sishell
version = 0.1
files = $(name).asm scprocessor.c brutebrand.c Makefile README COPYING poc


none:
	@echo "syntax:"
	@echo "make freebsd-sa  - FreeBSD stand alone executable"
	@echo "make netbsd-sa   - NetBSD stand alone executable"
	@echo "make openbsd-sa	- OpenBSD stand alone executable"
	@echo "make linux-sa    - Linux stand alone executable"
	@echo "make bsd         - *BSD shellcode (for {Free,Net,Open}BSD)"
	@echo "make linux       - Linux shellcode"

freebsd-sa: clean mk-standalone-freebsd strip brutebrand-freebsd scp dumpco
netbsd-sa: clean mk-standalone-netbsd strip brutebrand-netbsd scp dumpco
#openbsd-sa: clean mk-standalone-openbsd strip brutebrand-openbsd scp dumpco
openbsd-sa:
	@echo "Sorry, I have not succeeded in creating an executable for OpenBSD yet."
	@echo "I need to do more research. If you have a working solution or want to"
	@echo "do some testing, send an e-mail to shadowinteger@sentinix.org."
linux-sa: clean mk-standalone-linux strip brutebrand-linux scp dumpco

bsd: clean mk-bsd scp dumpc
linux: clean mk-linux scp dumpc


mk-standalone-freebsd:
	@echo "[+] making x86 FreeBSD stand alone executable"
	nasm -f elf -DFREEBSD -Dstand_alone $(name).asm
	ld -s -o $(o) $(name).o

mk-standalone-netbsd:
	@echo "[+] making x86 NetBSD stand alone executable"
	nasm -f elf -DNETBSD -Dstand_alone $(name).asm
	ld -s -o $(o) $(name).o

mk-standalone-openbsd:
	@echo "[+] making x86 OpenBSD stand alone executable"
	nasm -f elf -DOPENBSD -Dstand_alone $(name).asm
	ld -s -o $(o) $(name).o

mk-standalone-linux:
	@echo "[+] making x86 Linux stand alone executable"
	nasm -f elf -DLINUX -Dstand_alone $(name).asm
	ld -s -o $(o) $(name).o


mk-bsd:
	@echo "[+] making x86 *BSD shellcode"
	nasm -f bin -DBSD -o $(o) $(name).asm

mk-linux:
	@echo "[+] making x86 Linux shellcode"
	nasm -f bin -DLINUX -o $(o) $(name).asm

bbc:
	gcc -Wall -o brutebrand brutebrand.c
brutebrand-freebsd: bbc
	./brutebrand -t freebsd $(o)
	file $(o)
brutebrand-netbsd: bbc
	./brutebrand -t netbsd $(o)
	file $(o)
brutebrand-openbsd: bbc
	./brutebrand -t openbsd $(o)
	file $(o)
brutebrand-linux: bbc
	./brutebrand -t linux $(o)
	file $(o)

scp:
	gcc -Wall -s -o scprocessor scprocessor.c

dumpc:
	@./scprocessor -qp -c "shadowinteger's sishell" $(o)
	@./scprocessor -pE -c "shadowinteger's sishell" $(o) > example.c
	@echo "[i] see example.c for example source"
dumpco:
	@./scprocessor -pOE -c "shadowinteger's sishell" $(o) > example_ascii_octal.c
	@echo "[i] see example_ascii_octal.c for example source"

strip:
	strip -R .comment -R .bss -R .data $(o)


clean:
	rm -f $(o) brutebrand scprocessor *.o
distclean: clean

dist:
	@echo "[i] making tarball..."
	make -C poc clean
	mkdir $(name)-$(version)
	tar --exclude CVS -cf temporaryplace-$(version).tar $(files)
	tar -C $(name)-$(version) -xf temporaryplace-$(version).tar
	rm -f $(name)-$(version).tar.gz
	tar -czf $(name)-$(version).tar.gz $(name)-$(version)
	rm -rf $(name)-$(version)
	rm -rf temporaryplace-$(version).tar
	@echo "[i] done"

#
# extras, old stuff
#

hexdump: hex octal

hex:
	@echo "/* this is for inclusion in C source */"
	@hexdump -v -e '16/1 "|x%02x" "\n"' $(o) | sed -e 's/|/\\/g' -e 's/\\x  //g'

octal:
	@echo "/* this is for inclusion in C source, it'll produce ASCII-octal-encoded output."
	@echo " * this can be dumped into binary format using:"
	@echo " * perl -e \"print \\\"<thisdata>\\\"\""
	@echo " * or: printf \"<thisdata>\""
	@echo " * this is supposed to be ASCII, not binary! */"
	@hexdump -v -e '12/1 "|%03o" "\n"' $(o) | sed -e 's/|/\\\\/g' -e 's/\\\\   //g'
