include config.mak

ifndef OUT
$(error You need to run ./configure.pl before make)
endif

export ARCH
export CFLAGS
export ASM_STYLE
export ELF_BASE
export ELF_ALIGN
export ELF_ADDRSIZE
export OBJDUMP
export OUT
export READELF
export TMP
export UNAME
export XML_DCL

TODAY := $(shell date "+%Y-%m-%d")
PWD := $(shell pwd)
DIRNAME := $(shell basename "$(PWD)")
HTML := file://$(PWD)/_html/index.html
DVI := file://$(PWD)/_dvi/$(DIRNAME).dvi

DSL = etc/ldp.dsl
SCANNER_BIG = '' /bin /sbin /usr/bin /usr/sbin /usr/lib
SCANNER_SMALL = _infected $(TMP)

SED_ELF_MAGIC = sed \
	-e 's/ELF_MAGIC/$(ELF_MAGIC)/g' \
	-e 's/ELF_BASE/$(ELF_BASE)/g'

.SUFFIXES: .inc .gdb .asm

all: infection scanner

mkdir: ; etc/mkdir.sh | xargs mkdir -p 2> /dev/null

infection: \
	mkdir \
	magic_elf \
	evil_magic \
	$(OUT)/readelf/segments \
	$(OUT)/readelf/evil_magic \
	entry_point \
	infection_$(ARCH) \

infection_ppc:
infection_alpha:
infection_sparc:
infection_i386: \
	one_step_closer \
	additional_cs \
	doing_it_in_c  \
	stub_revisited \
	suspicious_code

scanner: \
	infection \
	$(OUT)/scanner/dist_big \
	$(OUT)/scanner/entry_point_big \
	$(OUT)/scanner/dist_small \
	$(OUT)/scanner/entry_point_small

magic_elf: \
	$(OUT)/magic_elf/magic_elf \
	$(OUT)/magic_elf/magic_elf_static \
	$(OUT)/magic_elf/strings \
	$(OUT)/magic_elf/od \
	$(OUT)/magic_elf/gdb \
	$(OUT)/magic_elf/addr_of_main \
	$(OUT)/magic_elf/other_perl \
	$(OUT)/magic_elf/other_exe \
	$(OUT)/magic_elf/other_mem \
	$(OUT)/magic_elf/objdump \
	magic_elf_$(ARCH) \
	magic_elf_$(UNAME)

magic_elf_sparc: 
magic_elf_i386: \
	$(OUT)/magic_elf/disasm
magic_elf_SunOS:
magic_elf_FreeBSD \
magic_elf_Linux: \
	$(OUT)/magic_elf/hexdump

evil_magic: \
	$(OUT)/evil_magic/static_main.gdb \
	$(OUT)/evil_magic/static_write.gdb \
	$(OUT)/evil_magic/$(ASM_STYLE) \
	$(OUT)/evil_magic/od \
	$(OUT)/evil_magic/ofs_entry \
	$(OUT)/evil_magic/evil_magic.asm \
	$(OUT)/evil_magic/evil_magic.c \
	$(OUT)/evil_magic/cc

entry_point: \
	$(OUT)/entry_point/sh.gdb \
	$(OUT)/entry_point/sh.disasm \
	$(OUT)/entry_point/ldd \
	$(OUT)/entry_point/nm \
	src/entry_point/__libc_start_main \
	$(OUT)/entry_point/sections \
	entry_point_$(ARCH)

entry_point_sparc:
entry_point_i386: \
	$(OUT)/entry_point/scan \
	$(OUT)/entry_point/e2.disasm \
	$(OUT)/entry_point/e3.disasm \
	$(OUT)/entry_point/entry_point \
	$(OUT)/entry_point/segments

one_step_closer: \
	$(OUT)/one_step_closer/test-e1i1 \
	$(OUT)/one_step_closer/test-e2i1 \
	$(OUT)/one_step_closer/test-e3i1

additional_cs: \
	$(OUT)/additional_cs/hexdump \
	$(OUT)/additional_cs/test \
	$(OUT)/additional_cs/segments \
	$(OUT)/additional_cs/scan

doing_it_in_c: \
	$(OUT)/doing_it_in_c/get_relocate_ofs.disasm \
	$(OUT)/doing_it_in_c/i1/infection.inc \
	$(OUT)/doing_it_in_c/begin.disasm \
	$(OUT)/doing_it_in_c/addr \
	$(OUT)/doing_it_in_c/e3i1.disasm \
	$(OUT)/doing_it_in_c/e3i2.disasm \
	$(OUT)/doing_it_in_c/e3i3.disasm \
	$(OUT)/doing_it_in_c/test-e3i1 \
	$(OUT)/doing_it_in_c/test-e3i2 \
	$(OUT)/doing_it_in_c/test-e3i3

stub_revisited: \
	$(OUT)/stub_revisited/magic_elf.disasm \
	$(OUT)/stub_revisited/sh.disasm \
	$(OUT)/stub_revisited/sh_ret.disasm \
	$(OUT)/stub_revisited/sh_infected.disasm \
	$(OUT)/stub_revisited/stack \
	src/stub_revisited/__libc_start_main

suspicious_code: \
	$(OUT)/suspicious_code/disasm

clean:
	rm -rf config.* tmp/ out/ _* $(DIRNAME).junk
	find . -type f \
		-name '*.bak' \
		-o -name '*.orig' \
		-o -name '*~' \
		-o -name '*.fot' \
		-o -name '*infected' \
		-o -name '*.core' \
		-o -name 'core.*' \
		-o -name core \
	| xargs rm -f

$(OUT_XML)/ulink.xml: etc/ulink.pl etc/http.dat etc/ftp.dat
	etc/ulink.pl -PROTO=http -DIR=$(OUT_XML) etc/http.dat > $@
	etc/ulink.pl -PROTO=ftp -DIR=$(OUT_XML) etc/ftp.dat >> $@

# This really depends on 'all', but then XML rendering is done
# on another machine with different date and time.
$(OUT_XML)/calc.xml: /bin/sh src/calc.pl 
	src/calc.pl "-xml=$@"
calc: $(OUT_XML)/calc.xml

html_deps: mkdir $(OUT_XML)/ulink.xml $(OUT_XML)/calc.xml

dsl: $(DSL) etc/patch_dsl.pl
	etc/patch_dsl.pl -dsl=$(DSL)

intro: html_deps
	etc/mkhtml.sh _html ../$(DSL) ../$@
platform: html_deps
	etc/mkhtml.sh _html/$(OS_CODE) ../../$(DSL) ../../$@
html: html_deps dsl intro platform

dvi: html_deps
	- [ -d _dvi ] && rm -r _dvi
	mkdir _$@
	cd _$@; jw -f docbook -b dvi ../intro/main.xml

mozilla:
	mozilla $(HTML) &
netscape:
	netscape $(HTML) &
links:
	links $(HTML)
xdvi: dvi
	xdvi $(DVI)

fileref:
	etc/fileref.pl `find intro platform -type f -name '*.xml'`

dist_html:
	tar -C .. -zcf $(DIRNAME)-$(TODAY).html.tar.gz \
		$(DIRNAME)/_html \
		--exclude-from=etc/tar-exclude
dist_src: clean
	tar -C .. -zcf $(DIRNAME)-$(TODAY).tar.gz \
		$(DIRNAME) \
		--exclude-from=etc/tar-exclude
dist: dist_html dist_src

$(OUT)/magic_elf/magic_elf.c: \
	src/magic_elf/magic_elf.c
	$(SED_ELF_MAGIC) $? > $@
$(TMP)/magic_elf/magic_elf \
$(OUT)/magic_elf/magic_elf: \
	$(OUT)/magic_elf/magic_elf.c \
	src/magic_elf/cc.sh
	src/magic_elf/cc.sh > $(OUT)/magic_elf/magic_elf 2>&1
$(OUT)/magic_elf/magic_elf_static: \
	$(OUT)/magic_elf/magic_elf.c \
	src/magic_elf/cc_static.sh
	src/magic_elf/cc_static.sh > $@ 2>&1
$(OUT)/magic_elf/strings: \
	$(TMP)/magic_elf/magic_elf \
	src/magic_elf/strings.sh
	src/magic_elf/strings.sh > $@ 2>&1
$(OUT)/magic_elf/od: \
	$(OUT)/magic_elf/magic_elf \
	src/magic_elf/od/$(UNAME).sh
	src/magic_elf/od/$(UNAME).sh > $@ 2>&1
$(OUT)/magic_elf/hexdump: \
	$(OUT)/magic_elf/magic_elf \
	src/magic_elf/hexdump.sh \
	src/format.hex
	src/magic_elf/hexdump.sh > $@ 2>&1
$(OUT)/magic_elf/addr_of_main.c: \
	src/magic_elf/addr_of_main.c
	$(SED_ELF_MAGIC) $? > $@
$(TMP)/magic_elf/addr_of_main: $(OUT)/magic_elf/addr_of_main.c
	$(CC) $(CFLAGS) -o $@ $?
$(OUT)/magic_elf/addr_of_main: $(TMP)/magic_elf/addr_of_main
	$? > $@ 2>&1
$(OUT)/magic_elf/disasm: \
	$(OUT)/magic_elf/magic_elf \
	$(OUT)/magic_elf/addr_of_main \
	src/magic_elf/$(ASM_STYLE).sh
	src/magic_elf/$(ASM_STYLE).sh > $@ 2>&1
$(OUT)/magic_elf/objdump: \
	$(OUT)/magic_elf/magic_elf \
	$(OUT)/magic_elf/addr_of_main \
	src/magic_elf/objdump.sh \
	src/magic_elf/objdump_format.sh
	src/magic_elf/objdump.sh > $@ 2>&1
$(OUT)/magic_elf/gdb: \
	$(OUT)/magic_elf/magic_elf \
	src/magic_elf/gdb.sh
	src/magic_elf/gdb.sh > $@ 2>&1

$(OUT)/evil_magic/static_main.gdb: \
	$(OUT)/magic_elf/magic_elf_static \
	src/magic_elf/gdb.sh
	src/magic_elf/gdb.sh "$(TMP)/magic_elf/magic_elf_static" \
	> $@ 2>&1
$(OUT)/evil_magic/static_write.gdb: \
	$(OUT)/magic_elf/magic_elf_static \
	src/magic_elf/gdb.sh
	src/magic_elf/gdb.sh \
		"$(TMP)/magic_elf/magic_elf_static" "__libc_write" \
	> $@ 2>&1
$(TMP)/evil_magic/$(ASM_STYLE) \
$(OUT)/evil_magic/$(ASM_STYLE): \
	src/evil_magic/$(ARCH)-$(UNAME).asm \
	src/evil_magic/$(ASM_STYLE).sh
	src/evil_magic/$(ASM_STYLE).sh > $(OUT)/evil_magic/$(ASM_STYLE) 2>&1
$(OUT)/evil_magic/od: \
	$(OUT)/evil_magic/$(ASM_STYLE) \
	src/evil_magic/od/$(UNAME).sh
	src/evil_magic/od/$(UNAME).sh > $@ 2>&1
$(TMP)/evil_magic/ofs_entry: \
	src/evil_magic/ofs_entry.c
	$(CC) $(CFLAGS) -o $@ $?
$(OUT)/evil_magic/ofs_entry: \
	$(TMP)/evil_magic/ofs_entry
	$? > $@
$(OUT)/evil_magic/dis-$(ASM_STYLE).sh: \
	$(TMP)/evil_magic/$(ASM_STYLE) \
	src/evil_magic/od/$(UNAME).sh \
	etc/mkdisasm.sh
	etc/mkdisasm.sh $@
$(OUT)/evil_magic/evil_magic.asm: \
	$(TMP)/evil_magic/$(ASM_STYLE) \
	$(OUT)/evil_magic/dis-$(ASM_STYLE).sh
	$(OUT)/evil_magic/dis-$(ASM_STYLE).sh > $@
$(OUT)/evil_magic/evil_magic.c: \
	$(OUT)/evil_magic/evil_magic.asm \
	src/platform/disasm.pl
	src/platform/disasm.pl \
		< $(OUT)/evil_magic/evil_magic.asm \
		> $@
$(OUT)/evil_magic/cc: \
	$(OUT)/evil_magic/evil_magic.c src/evil_magic/cc.sh
	src/evil_magic/cc.sh > $@ 2>&1
$(OUT)/magic_elf/other_perl.pl: src/magic_elf/other_perl.pl
	$(SED_ELF_MAGIC) $? > $@ && chmod 755 $@
$(OUT)/magic_elf/other_perl: $(OUT)/magic_elf/other_perl.pl
	$? > $@ 2>&1
$(OUT)/magic_elf/other_mem.sh: src/magic_elf/other_mem/$(UNAME).sh
	$(SED_ELF_MAGIC) $? > $@ && chmod 755 $@
$(OUT)/magic_elf/other_mem: $(OUT)/magic_elf/other_mem.sh
	$? > $@ 2>&1
$(OUT)/magic_elf/other_exe.sh: src/magic_elf/other_exe.sh
	sed 's#PROC_EXE#$(PROC_EXE)#g' $? > $@ 2>&1
	chmod 755 $@
$(OUT)/magic_elf/other_exe: $(OUT)/magic_elf/other_exe.sh
	$? > $@ 2>&1

$(OUT)/readelf/evil_magic: \
	$(TMP)/evil_magic \
	src/readelf/evil_magic.sh
	src/readelf/evil_magic.sh > $@
$(OUT)/readelf/segments: src/readelf/segments.sh
	$? > $@ 2>&1

$(OUT)/scanner/dist_big: \
	src/scanner/driver.sh \
	src/scanner/dist.pl
	src/scanner/driver.sh $@ src/scanner/dist.pl $(SCANNER_BIG)
$(OUT)/scanner/entry_point_big: \
	src/scanner/driver.sh \
	src/scanner/entry_point.pl
	src/scanner/driver.sh $@ src/scanner/entry_point.pl $(SCANNER_BIG)
$(OUT)/scanner/dist_small: \
	src/scanner/driver.sh \
	src/scanner/dist.pl
	src/scanner/driver.sh $@ src/scanner/dist.pl $(SCANNER_SMALL)
$(OUT)/scanner/entry_point_small: \
	src/scanner/driver.sh \
	src/scanner/entry_point.pl
	src/scanner/driver.sh $@ src/scanner/entry_point.pl $(SCANNER_SMALL)

$(OUT)/one_step_closer/i1/infection.inc: \
	src/one_step_closer/i1/$(ARCH)-$(UNAME).asm \
	src/platform/disasm.pl \
	src/one_step_closer/$(ASM_STYLE).sh
	src/one_step_closer/$(ASM_STYLE).sh $@
$(TMP)/one_step_closer/e1i1/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/one_step_closer/i1/infection.inc
	src/one_step_closer/cc.sh one_step_closer e1 i1 \
	> $(OUT)/one_step_closer/e1i1/cc 2>&1

$(OUT)/one_step_closer/test-e1i1.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/one_step_closer/test-e1i1: \
	$(TMP)/one_step_closer/e1i1/sh_infected \
	$(OUT)/one_step_closer/test-e1i1.sh
	-$(OUT)/one_step_closer/test-e1i1.sh > $@ 2>&1
$(TMP)/one_step_closer/e2i1/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/one_step_closer/i1/infection.inc
	src/one_step_closer/cc.sh one_step_closer e2 i1 \
	> $(OUT)/one_step_closer/e2i1/cc 2>&1
$(OUT)/one_step_closer/test-e2i1.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/one_step_closer/test-e3i1.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/one_step_closer/test-e2i1: \
	$(TMP)/one_step_closer/e2i1/sh_infected \
	$(OUT)/one_step_closer/test-e2i1.sh
	-$(OUT)/one_step_closer/test-e2i1.sh > $@ 2>&1
$(TMP)/one_step_closer/e3i1/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/one_step_closer/i1/infection.inc
	src/one_step_closer/cc.sh one_step_closer e3 i1 \
	> $(OUT)/one_step_closer/e3i1/cc 2>&1
$(OUT)/one_step_closer/test-e3i1: \
	$(TMP)/one_step_closer/e3i1/sh_infected \
	$(OUT)/one_step_closer/test-e3i1.sh
	-$(OUT)/one_step_closer/test-e3i1.sh > $@ 2>&1

$(OUT)/entry_point/segments: \
	$(TMP)/one_step_closer/e1i1/sh_infected \
	src/entry_point/segments.sh
	src/entry_point/segments.sh > $@ 2>&1
$(OUT)/entry_point/scan: \
	$(TMP)/one_step_closer/e1i1/sh_infected \
	src/entry_point/scan_dist.sh 
	src/entry_point/scan_dist.sh > $@ 2>&1
$(OUT)/entry_point/sh.gdb: \
	src/entry_point/gdb-core.sh \
	src/magic_elf/gdb-format.sh
	src/entry_point/gdb-core.sh | src/magic_elf/gdb-format.sh > $@
$(OUT)/entry_point/sh.disasm: \
	src/entry_point/$(ASM_STYLE).sh \
	src/magic_elf/objdump_format.sh
	src/entry_point/$(ASM_STYLE).sh > $@ 2>&1
$(OUT)/entry_point/entry_point: \
	src/entry_point/entry_point.sh \
	$(TMP)/one_step_closer/e1i1/sh_infected \
	$(TMP)/one_step_closer/e2i1/sh_infected
	src/entry_point/entry_point.sh > $@ 2>&1
$(OUT)/entry_point/e2.disasm: \
	src/entry_point/$(ASM_STYLE).sh \
	$(TMP)/one_step_closer/e2i1/sh_infected
	src/entry_point/$(ASM_STYLE).sh \
	$(TMP)/one_step_closer/e2i1/sh_infected \
	> $@ 2>&1
$(OUT)/entry_point/ldd: \
	src/entry_point/ldd.sh
	$?  > $@ 2>&1
$(OUT)/entry_point/nm: \
	src/entry_point/nm.sh
	$?  > $@ 2>&1
src/entry_point/__libc_start_main: \
	$(OUT)/entry_point/nm \
	src/entry_point/get_libc_start_main.sh
	src/entry_point/get_libc_start_main.sh $@
$(OUT)/entry_point/e3.disasm: \
	src/entry_point/$(ASM_STYLE).sh \
	$(TMP)/one_step_closer/e3i1/sh_infected
	src/entry_point/$(ASM_STYLE).sh \
	$(TMP)/one_step_closer/e3i1/sh_infected \
	> $@ 2>&1
$(OUT)/entry_point/sections: \
	src/entry_point/sections.sh
	$? > $@ 2>&1

$(OUT)/additional_cs/hexdump: \
	src/additional_cs/hexdump.sh \
	src/format.hex
	src/additional_cs/hexdump.sh > $@ 2>&1
$(OUT)/additional_cs/i1: \
	$(OUT)/one_step_closer/i1/infection.inc
	-ln -s ../one_step_closer/i1 $@
$(TMP)/additional_cs/e3i1/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/additional_cs/i1
	src/one_step_closer/cc.sh additional_cs e3 i1 \
	> $(OUT)/additional_cs/cc 2>&1
$(OUT)/additional_cs/test-e3i1.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/additional_cs/test: \
	$(TMP)/additional_cs/e3i1/sh_infected \
	$(OUT)/additional_cs/test-e3i1.sh
	-$(OUT)/additional_cs/test-e3i1.sh > $@ 2>&1
$(OUT)/additional_cs/segments: \
	$(TMP)/additional_cs/e3i1/sh_infected
	( ls -l $?; $(READELF) -l $? ) > $@
$(OUT)/additional_cs/scan: \
	$(TMP)/additional_cs/e3i1/sh_infected \
	src/additional_cs/scan_dist.sh
	src/additional_cs/scan_dist.sh > $@ 2>&1

$(OUT)/doing_it_in_c/i1/infection.inc: \
	src/doing_it_in_c/i1/$(ARCH)-$(UNAME).asm \
	src/one_step_closer/$(ASM_STYLE).sh
	src/one_step_closer/$(ASM_STYLE).sh $@ 2>&1
$(TMP)/doing_it_in_c/e3i1/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/doing_it_in_c/i1/infection.inc
	src/one_step_closer/cc.sh doing_it_in_c e3 i1 \
	> $(OUT)/doing_it_in_c/e3i1/cc 2>&1
$(OUT)/doing_it_in_c/test-e3i1.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/doing_it_in_c/test-e3i1: \
	$(TMP)/doing_it_in_c/e3i1/sh_infected \
	$(OUT)/doing_it_in_c/test-e3i1.sh
	-$(OUT)/doing_it_in_c/test-e3i1.sh > $@ 2>&1

$(OUT)/doing_it_in_c/i2/infection.inc: \
	src/doing_it_in_c/i2/$(ARCH)-$(UNAME).asm \
	src/one_step_closer/$(ASM_STYLE).sh
	src/one_step_closer/$(ASM_STYLE).sh $@ 2>&1
$(TMP)/doing_it_in_c/e3i2/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/doing_it_in_c/i2/infection.inc
	src/one_step_closer/cc.sh doing_it_in_c e3 i2 \
	> $(OUT)/doing_it_in_c/e3i2/cc 2>&1
$(OUT)/doing_it_in_c/test-e3i2.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/doing_it_in_c/test-e3i2: \
	$(TMP)/doing_it_in_c/e3i2/sh_infected \
	$(OUT)/doing_it_in_c/test-e3i2.sh
	-$(OUT)/doing_it_in_c/test-e3i2.sh > $@ 2>&1

$(OUT)/doing_it_in_c/i3/infection.inc: \
	src/doing_it_in_c/i3/$(ARCH)-$(UNAME).asm \
	src/one_step_closer/$(ASM_STYLE).sh
	src/one_step_closer/$(ASM_STYLE).sh $@ 2>&1
$(TMP)/doing_it_in_c/e3i3/sh_infected: \
	src/one_step_closer/cc.sh \
	$(OUT)/doing_it_in_c/i3/infection.inc
	src/one_step_closer/cc.sh doing_it_in_c e3 i3 \
	> $(OUT)/doing_it_in_c/e3i3/cc 2>&1
$(OUT)/doing_it_in_c/test-e3i3.sh: \
	src/one_step_closer/test.sh
	etc/mktest $@ < $?
$(OUT)/doing_it_in_c/test-e3i3: \
	$(TMP)/doing_it_in_c/e3i3/sh_infected \
	$(OUT)/doing_it_in_c/test-e3i3.sh
	-$(OUT)/doing_it_in_c/test-e3i3.sh > $@ 2>&1

$(OUT)/doing_it_in_c/get_relocate_ofs.disasm: \
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i1/sh_infected
	src/doing_it_in_c/$(ASM_STYLE).sh > $@ 2>&1
$(OUT)/doing_it_in_c/begin.disasm: \
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i1/sh_infected
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i1/infector "begin" > $@ 2>&1
$(OUT)/doing_it_in_c/addr: \
	src/doing_it_in_c/addr.c
	$(CC) $(CFLAGS) -o $(TMP)/doing_it_in_c/addr $? > $@ 2>&1 \
	&& $(TMP)/doing_it_in_c/addr >> $@ 2>&1
$(OUT)/doing_it_in_c/e3i1.disasm: \
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i1/sh_infected
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i1/infector infection 4 > $@ 2>&1
$(OUT)/doing_it_in_c/e3i2.disasm: \
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i2/sh_infected
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i2/infector infection 1 > $@ 2>&1
$(OUT)/doing_it_in_c/e3i3.disasm: \
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i3/sh_infected
	src/doing_it_in_c/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i3/infector infection 2 > $@ 2>&1

$(OUT)/stub_revisited/sh.disasm: \
	src/stub_revisited/$(ASM_STYLE).sh
	( $? 2>&1 ) | head > $@
$(OUT)/stub_revisited/sh_ret.disasm: \
	src/stub_revisited/$(ASM_STYLE).sh \
	src/stub_revisited/$(ASM_STYLE)_ret.sh
	src/stub_revisited/$(ASM_STYLE)_ret.sh > $@ 2>&1
$(OUT)/stub_revisited/magic_elf.disasm: \
	src/stub_revisited/$(ASM_STYLE).sh \
	$(TMP)/magic_elf/magic_elf
	( src/stub_revisited/$(ASM_STYLE).sh $(TMP)/magic_elf/magic_elf 2>&1 ) \
	| head \
	> $@
$(OUT)/stub_revisited/sh_infected.disasm: \
	src/stub_revisited/$(ASM_STYLE).sh \
	$(TMP)/doing_it_in_c/e3i1/sh_infected
	( src/stub_revisited/$(ASM_STYLE).sh \
		$(TMP)/doing_it_in_c/e3i1/sh_infected 2>&1 ) \
	| head \
	> $@
$(OUT)/stub_revisited/stack: \
	src/stub_revisited/stack.sh \
	$(TMP)/magic_elf/magic_elf
	src/stub_revisited/stack.sh > $@ 2>&1
src/stub_revisited/__libc_start_main: \
	$(OUT)/stub_revisited/stack \
	src/stub_revisited/get_libc_start_main.sh
	src/stub_revisited/get_libc_start_main.sh \
		$@ $(OUT)/stub_revisited/stack

$(OUT)/suspicious_code/disasm: \
	src/suspicious_code/dumpsection.pl \
	src/suspicious_code/$(ASM_STYLE).sh
	src/suspicious_code/$(ASM_STYLE).sh > $@ 2>&1
