From 898ad573a7724ad311cae43e3797aefddf16c0c0 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 22 Dec 2023 11:24:15 -0800 Subject: [PATCH] Add 2020/yang/try.sh + format/typo checks The Makefile also has been updated with a new rule to compile the C++ code the author provided which can preprocess the output of the program to make it more acceptable to some compilers. Format/typo check README.md file. This should complete 2020! There might be another change in another year but besides that and the YYYY/README.md files the review of all entries can be mostly considered done (mostly because I will probably do a very quick pass but this pass is not important one way or another). --- 2020/yang/.gitignore | 1 + 2020/yang/Makefile | 4 ++ 2020/yang/README.md | 36 +++++++++--------- 2020/yang/try.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++ thanks-for-help.md | 9 +++++ 5 files changed, 118 insertions(+), 19 deletions(-) create mode 100755 2020/yang/try.sh diff --git a/2020/yang/.gitignore b/2020/yang/.gitignore index eb19e2f8d..0356271de 100644 --- a/2020/yang/.gitignore +++ b/2020/yang/.gitignore @@ -1,5 +1,6 @@ # # sort with: sort -d -u +cppp *.dSYM indent indent.c diff --git a/2020/yang/Makefile b/2020/yang/Makefile index b35685fb8..fcafb553b 100644 --- a/2020/yang/Makefile +++ b/2020/yang/Makefile @@ -133,6 +133,10 @@ all: data ${TARGET} ${PROG}: ${PROG}.c ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} +cppp: cppp.cc + ${C_PLUSPLUS} -std=c++11 $< -o $@ ${LDFLAGS} + + # alternative executable # alt: data ${ALT_TARGET} diff --git a/2020/yang/README.md b/2020/yang/README.md index 4140bd189..645ba86b8 100644 --- a/2020/yang/README.md +++ b/2020/yang/README.md @@ -15,24 +15,20 @@ make ### Try: ```sh -echo "International Obfuscated C Code Contest 2020" | ./prog 23209 > code.c - -# compile without a PIN -cc code.c -o decode -# yes, you must compile with -DPIN= - -# compile with the wrong pin -cc -DPIN=555 code.c -o wrongcoded # wait for it ... -./wrongcoded | hexdump -C -# Use the wrong PIN: You're gonna have a bad time. - -# compile with a PIN -cc -DPIN=23209 code.c -o decoded # wait for it ... -./decoded -# weeeeeeeeeeeeee! You are having a good time! +./try.sh ``` +The author provided the file [cppp.cc](cppp.cc) which can preprocess the +generated output to make them more acceptable to typical compilers. To build: + +```sh +make cppp +``` + +See the author's remarks for more details. + + ## Judges' remarks: You might think of this entry as code obfuscater with a code. @@ -65,22 +61,22 @@ where [PIN] is an integer in the range of 1..65535 ``` When run with an encoding PIN (first command line argument), Mile will -read bytes from stdin and generate C code on stdout. Example: +read bytes from `stdin` and generate C code on `stdout`. Example: ```sh echo "Hello, world!" | ./prog 56789 > encoded.c ``` -This generated code will reproduce the same input bytes on stdout when +This generated code will reproduce the same input bytes on `stdout` when executed, if it was compiled with the same encoding PIN. ```sh -gcc -DPIN=56789 encode.c -o decoded +gcc -DPIN=56789 encoded.c -o decoded ``` The generated code reconstructs all data at compile time by seeding a random number generator with the given PIN to reproduce the input bytes, -and simply does one fwrite() call at run time to print those bytes. Not +and simply does one `fwrite(3)` call at run time to print those bytes. Not specifying a PIN is a compile time error. Specify the wrong PIN and output code will still compile, but will likely produce garbage instead of the input bytes. If the original input was empty then any PIN works, but @@ -99,6 +95,7 @@ with that by producing C code filled with at least 98% preprocessor lines for any input. Now you too can enjoy long compile times with minimal effort. + ### Features + Output is randomized using system clock, so if you wait a second between @@ -115,6 +112,7 @@ effort. to nanomachines directly, which is exactly what programming in preprocessor feels like. + ### Compatibility Mile has been verified to work in these environments (also, compiles diff --git a/2020/yang/try.sh b/2020/yang/try.sh new file mode 100755 index 000000000..92f16c1f2 --- /dev/null +++ b/2020/yang/try.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2020/yang +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +# we will use hexdump later if it's installed +HEXDUMP="$(type -P hexdump)" + +echo "Getting usage:" +echo "$ ./prog" 1>&2 +./prog +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ echo \"International Obfuscated C Code Contest 2020\" | ./prog 23209 > code.c" 1>&2 +echo "International Obfuscated C Code Contest 2020" | ./prog 23209 > code.c +echo 1>&2 + +read -r -n 1 -p "Press any key to show code.c (space = next page, q = quit): " +echo 1>&2 +less -rEXF code.c +echo 1>&2 + +# compile without a PIN +echo "Trying to compile without a PIN:" +echo 1>&2 +echo "$ cc code.c -o decode" 1>&2 +cc code.c -o decode +echo 1>&2 +echo "As you can see, you must compile with -DPIN=" 1>&2 + +if [[ -n "$HEXDUMP" ]]; then + # compile with the wrong pin if hexdump is installed + echo 1>&2 + echo "Compiling with wrong PIN: cc -DPIN=555 code.c -o wrongcoded" 1>&2 + cc -DPIN=555 code.c -o wrongcoded # wait for it ... + read -r -n 1 -p "Press any key to run wrongcoded: " + echo 1>&2 + ./wrongcoded | "$HEXDUMP" -C +fi + +read -r -n 1 -p "Press any key to compile with a good PIN: " +echo 1>&2 +# compile with a PIN +echo "$ cc -DPIN=23209 code.c -o decoded" 1>&2 +cc -DPIN=23209 code.c -o decoded +read -r -n 1 -p "Press any key to run: ./decoded: " +echo 1>&2 +./decoded + + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ echo \"Hello, world!\" | ./prog 56789 > encoded.c" 1>&2 +echo "Hello, world!" | ./prog 56789 > encoded.c +echo 1>&2 + +read -r -n 1 -p "Press any key to show encoded.c (space = next page, q = quit): " +echo 1>&2 +less -rEXF encoded.c +echo 1>&2 + +read -r -n 1 -p "Press any key to compile with PIN 56789: " +echo 1>&2 +echo "$ cc -DPIN=56789 encoded.c -o decoded" 1>&2 +cc -DPIN=56789 encoded.c -o decoded +echo 1>&2 + +read -r -n 1 -p "Press any key to run decoded: " +echo 1>&2 +echo "$ ./decoded" 1>&2 +./decoded + +rm -f decoded code.c encoded.c diff --git a/thanks-for-help.md b/thanks-for-help.md index 3c62d1b81..7b1de0473 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -4459,6 +4459,15 @@ more at home for vi users. One might still end up cursing (see the README.md file) but probably a lot less :-) +## [2020/yang](/2020/yang/prog.c) ([README.md](/2020/yang/README.md)) + +[Cody](#cody) added the [try.sh](/2020/yang/try.sh) script. + +Cody also added a make rule (`make cppp`) for the author's provided C++ code +that can preprocess the generated output to make them more acceptable to typical +compilers. See the README.md for more details. + + # General thanks