diff --git a/2001/anonymous/.gitignore b/2001/anonymous/.gitignore index 67f3bd25f..49b1e5d70 100644 --- a/2001/anonymous/.gitignore +++ b/2001/anonymous/.gitignore @@ -1,2 +1,6 @@ anonymous anonymous.ten +ten.bak.od +ten.bak.txt +ten.od +ten.txt diff --git a/2001/anonymous/Makefile b/2001/anonymous/Makefile index fcefba8b8..eb0530ae1 100644 --- a/2001/anonymous/Makefile +++ b/2001/anonymous/Makefile @@ -117,7 +117,7 @@ PROG= ${ENTRY} # OBJ= ${PROG}.o DATA= -TARGET= ${PROG} +TARGET= ${PROG} ${PROG}.ten # ALT_OBJ= ALT_TARGET= @@ -135,7 +135,6 @@ all: data ${TARGET} supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c - @echo "NOTE: this entry seems to no longer work." magic='${CC} ${CFLAGS}'; \ X='-DA(X)=#X'; \ warning='-Dprocessor'; \ @@ -144,12 +143,17 @@ ${PROG}: ${PROG}.c ${PROG}.ten: ${PROG}.ten.c - @echo "NOTE: this program must be compiled as 32-bit to use with the entry itself." - @echo "if you want to use it where this is not possible e.g. with a Mac try, say to" + @echo "WARNING: ${PROG}.ten.c must be compiled as 32-bit to use with the entry itself;" + @echo "this is because the program works on 32-bit binaries. If you cannot use -m32 this" + @echo "will NOT work!" + @echo + @echo "If you want to use it where this is not possible e.g. with a Mac, say to" @echo "use by itself, try:" @echo @echo " ${CC} $< -o $@" @echo + @echo "but running ${PROG} on the resulting binary will crash." + @echo ${CC} ${CFLAGS} -m32 $< -o $@ ${LIBS} # alternative executable @@ -181,6 +185,7 @@ clean: clobber: clean ${RM} -f ${TARGET} ${ALT_TARGET} + ${RM} -f anonymous.ten.bak ten.od ten.od.bak ten.txt ten.bak.txt @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ echo 'ate sandwich'; \ diff --git a/2001/anonymous/README.md b/2001/anonymous/README.md index f2c32baf1..50b503455 100644 --- a/2001/anonymous/README.md +++ b/2001/anonymous/README.md @@ -15,25 +15,53 @@ make ./anonymous x86_program ``` -NOTE: [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed both the +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed both the supplementary program and the program itself, both of which segfaulted. He -managed to do this with linux but it will not work with macOS (see below why); -this is not a bug but a feature inherent in what it does. He said this took -serious debugging and skill (shameless self promotion but it's true :-) ) and we -thank him _very much_! +managed to do this with linux but it will not work with macOS (see +[bugs.md](/bugs.md) for why this is); this is not a bug but a feature inherent +in what it does. He said this took serious debugging and skill (shameless self +promotion but it's true :-) ) and we thank him _very much_! But what needed to +be changed? Although it took a fair bit of debugging it turns out all that +needed to be changed was: -Why does this not work on macOS? Because Apple has made it very hard to compile -32-bit programs. It's even harder with the Apple silicon chip. Thus this will -have to remain for linux only. BSD was not tested. +- `#include ` for `mmap()`. +- have `main()` call another function which is the recursive function; this +prevented `main()` from entering an infinite loop. -WARNING: this will somewhat destroy files that it is used on. See the author's -warning about this. +Without either of these it would crash and prevent modification of the 32-bit +[ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) (not elf :-) +) binary. The following change was also made to be more portable, in case the +constants `PROT_READ` and/or `PROT_WRITE` are not standardised: + +Change `3` in the call to `mmap()` to be `PROT_READ|PROT_WRITE`: just in case +`PROT_READ|PROT_WRITE` does not equal 3 (though it seems to be equal in both +macOS and linux). + +NOTE: there might be educational value to see the progress of this fix; if you +wish to see, try: + +```sh +git diff d2a42f42e8f477f29e9d5ed09ce2bb349eaf7397..93aa8d79f208dcccc3c5a2370a727b5cf64e9c53 anonymous.c +git diff 93aa8d79f208dcccc3c5a2370a727b5cf64e9c53..c48629017117379a52b1a512ef8f2593ca9569c8 anonymous.c +git diff c48629017117379a52b1a512ef8f2593ca9569c8..efdee208a2bc650256637b9357ddfd0de82d2f41 anonymous.c +git diff efdee208a2bc650256637b9357ddfd0de82d2f41..e9a3f77ea3b209e63ac3f9c06bb84ad86e5ea706 anonymous.c +``` + +### WARNING on note from the author + +The author suggested that this will somewhat destroy the binaries this touches +but Cody did not observe this. It does indeed modify the files as the script +below will show you (though not all files are modified: can you figure out why +that is?) but Cody did not notice any problems in using them. Perhaps it's +something he's not aware of. If you follow the try commands below you will +notice that although the binaries do differ it's not many differences. See the +author's warning about this. ### INABIAF - it's not a bug it's a feature! :-) This entry will not work on 64-bit binaries! The program itself can be compiled -as 64-bit but the files it processes must be 32-bit binaries. Not doing this -will likely cause a crash or cause your computer [halt and catch +as 64-bit but the files it processes must be 32-bit ELF binaries. Not doing this +will likely cause a crash or cause your computer to [halt and catch fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing)! :-) This entry will also very likely crash if no arg is specified. It might do @@ -42,8 +70,7 @@ something funny if you run it on itself as well but see below :-) ## Try: ```sh -make anonymous.ten -./anonymous anonymous.ten +./try.me.sh ``` What happens if the x86 program has already been modified by this program? @@ -53,7 +80,6 @@ you recompile it okay? What if you run it on `anonymous` itself? Can you run the program successfully after it without recompiling? - ## Judges' remarks: Is emulation the sincerest form of flattery? This small program does diff --git a/2001/anonymous/try.me.sh b/2001/anonymous/try.me.sh new file mode 100755 index 000000000..4cc1af804 --- /dev/null +++ b/2001/anonymous/try.me.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +make clobber +make all 2>/dev/null +echo "$ cp anonymous.ten anonymous.ten.bak" 1>2 +cp anonymous.ten anonymous.ten.bak +echo "$ ./anonymous anonymous.ten" 1>&2 +./anonymous anonymous.ten +echo "$ ./anonymous.ten" 1>&2 +./anonymous.ten +echo "$ diff -s anonymous.ten anonymous.ten.bak" 1>&2 +diff -s anonymous.ten anonymous.ten.bak +echo "$ od anonymous.ten > ten.od" 1>&2 +od anonymous.ten > ten.od +echo "$ od anonymous.ten.bak > ten.bak.od" 1>&2 +od anonymous.ten.bak > ten.bak.od +echo "$ diff ten.bak.od ten.od" 1>&2 +diff ten.bak.od ten.od +echo "$ ./anonymous.ten > ten.txt" 1>&2 +./anonymous.ten > ten.txt +echo "$ ./anonymous.ten.bak > ten.bak.txt" 1>&2 +./anonymous.ten.bak > ten.bak.txt +echo "$ diff -s ten.txt ten.bak.txt" 1>&2 +diff -s ten.txt ten.bak.txt diff --git a/bugs.md b/bugs.md index c79202063..28fce88b5 100644 --- a/bugs.md +++ b/bugs.md @@ -195,6 +195,8 @@ Please help us by writing alternative code! ## STATUS: main() function args not allowed - please help us fix +At this time all of these have been fixed but the below is what it's all about. + Entries with this status have a problem in that the args to main() are not of a specific type due to this being allowed in earlier C. Some compilers like clang have a deficiency where they do not allow this so these entries do not work with @@ -1051,6 +1053,24 @@ fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing))! :-) ). # 2001 +## [2001/anonymous](2001/anonymous/anonymous.c) ([README.md](2001/anonymous/README.md)) +## STATUS: INABIAF - please **DO NOT** fix + +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this so that it +works in modern systems but he notes that the program +[anonymous.ten.c](2001/anonymous/anonymous.ten.c) **MUST** be compiled as a +32-bit ELF binary! This because the program acts on 32-bit ELF binaries. If you +cannot use `-m32` on this file the program **will** almost certainly crash but +in no case will it work properly. + +This means that for macOS it will not work. Why will this not work in macOS? +Because Apple saw to it to make it very hard to compile 32-bit binaries (thanks +Apple for ruining some IOCCC entries! :-) :-( ). This appears to be even harder +with the Apple silicon chip. Thus this entry will not work with macOS unless you +have an older, out of date version. + +Other BSD Unices were not tested. + ## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md)) ## STATUS: doesn't work with some platforms - please help us fix