From 93684cfc199d0e238bf29c9602d19dadf85748ef Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sun, 21 May 2023 09:09:54 -0700 Subject: [PATCH] Add another program for 2001/anonymous This sings a different counting song, Ten in the Bed. It uses another C feature (a char *[]) that the Ten Green Bottles does not use. This is for fun as well as to show another program (with a different C feature) that the program works on, again assuming -m32 is allowed. Instead of using numbers it uses strings (as expected with a char *[]) in the singing. This was for fun (and to see if the program would work on arrays) after I remembered the song in a comment on GitHub - about the Ten Green Bottles song. --- 2001/anonymous/.gitignore | 2 ++ 2001/anonymous/Makefile | 25 +++++++++++++++++++++++-- 2001/anonymous/README.md | 16 ++++++++++++++++ 2001/anonymous/anonymous.bed.c | 23 +++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 2001/anonymous/anonymous.bed.c diff --git a/2001/anonymous/.gitignore b/2001/anonymous/.gitignore index f596565bd..a7a430248 100644 --- a/2001/anonymous/.gitignore +++ b/2001/anonymous/.gitignore @@ -6,3 +6,5 @@ ten.bak.txt ten.od ten.txt anonymous.ten.64 +anonymous.bed +anonymous.bed.64 diff --git a/2001/anonymous/Makefile b/2001/anonymous/Makefile index 7937aa85f..ff74cbde9 100644 --- a/2001/anonymous/Makefile +++ b/2001/anonymous/Makefile @@ -117,7 +117,7 @@ PROG= ${ENTRY} # OBJ= ${PROG}.o DATA= -TARGET= ${PROG} ${PROG}.ten ${PROG}.ten.64 +TARGET= ${PROG} ${PROG}.ten ${PROG}.ten.64 ${PROG}.bed ${PROG}.bed.64 # ALT_OBJ= ${PROG}.ten.64.o ALT_TARGET= ${PROG}.ten.64 @@ -150,7 +150,7 @@ ${PROG}.ten: ${PROG}.ten.c @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 " make anonymous.ten.64" @echo @echo "but running ${PROG} on the resulting binary will crash." @echo @@ -162,6 +162,27 @@ ${PROG}.ten.64: ${PROG}.ten.c @echo "lets you see the supplementary program in action." ${CC} ${CFLAGS} $< -o $@ ${LIBS} +${PROG}.bed: ${PROG}.bed.c + @echo "WARNING: ${PROG}.bed.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 " make anonymous.bed.64" + @echo + @echo "but running ${PROG} on the resulting binary will crash." + @echo + ${CC} ${CFLAGS} -m32 $< -o $@ ${LIBS} + +${PROG}.bed.64: ${PROG}.bed.c + @echo "WARNING: the file created by this rule will NOT work with the entry itself;" + @echo "this is because it works ONLY on 32-bit ELF binaries! This however at least" + @echo "lets you see the supplementary program in action." + ${CC} ${CFLAGS} $< -o $@ ${LIBS} + + # alternative executable # alt: data ${ALT_TARGET} diff --git a/2001/anonymous/README.md b/2001/anonymous/README.md index 8095eebd6..3ef53e46a 100644 --- a/2001/anonymous/README.md +++ b/2001/anonymous/README.md @@ -67,12 +67,28 @@ Finally to see from start to finish: git diff d2a42f42e8f477f29e9d5ed09ce2bb349eaf7397..4bc03de321612869aebf855850c6500df95cb6ef anonymous.c ``` +Cody also added a [program](anonymous.bed.c) like [anonymous.ten.c](anonymous.ten.c) +[Ten Green Bottles](https://en.wikipedia.org/wiki/Ten_Green_Bottles) but which +sings [Ten in the Bed](https://allnurseryrhymes.com/ten-in-the-bed/). Why? For +fun and so that there's another program that is a bit different (it uses a `char +*[]` array for example) that this program will still work on. To use: + +```sh +make anonymous.bed # if able to use -m32 +./anonymous anonymous.bed + +make anonymous.bed.64 # if unable to use -m32 +./anonymous.bed.64 +``` + Thank you Cody for your assistance! ## Try: ```sh ./try.me.sh + +./anonymous anonymous.bed # if able to use -m32 ``` What happens if the x86 program has already been modified by this program? The diff --git a/2001/anonymous/anonymous.bed.c b/2001/anonymous/anonymous.bed.c new file mode 100644 index 000000000..348ce4c96 --- /dev/null +++ b/2001/anonymous/anonymous.bed.c @@ -0,0 +1,23 @@ +#include + +char *bed[] = { "TEN", "NINE", "EIGHT", "SEVEN", "SIX", "FIVE", "FOUR", "THREE", "TWO", "ONE" }; + +void sing(int persons) { + printf("There %s %s in the bed and the little one said, '%s'\n", + persons==9?"was":"were", + bed[persons],persons==9?"Good night!":"Roll over, roll over!"); + if (persons != 9) + printf("So they all rolled over and one fell out...\n"); +} + +int main() { + int persons = 0; + + while(persons<10) { + sing(persons++); + puts(""); + } + + + return 0; +}