From f5ca4825ca9381ad3c9ff32141ce042088b3c38c Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 1 Feb 2024 07:56:57 -0800 Subject: [PATCH] Improve 2020/yang/try.sh The make clobber now removes decoded, code.c and encoded.c which try.sh creates. --- 2020/yang/Makefile | 2 +- 2020/yang/try.sh | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/2020/yang/Makefile b/2020/yang/Makefile index 95d95d9e0..312d1b030 100644 --- a/2020/yang/Makefile +++ b/2020/yang/Makefile @@ -208,7 +208,7 @@ clean: clobber: clean ${RM} -f ${TARGET} ${ALT_TARGET} - ${RM} -rf *.dSYM + ${RM} -rf *.dSYM decoded code.c encoded.c @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ echo 'ate sandwich'; \ diff --git a/2020/yang/try.sh b/2020/yang/try.sh index 92f16c1f2..225d26c37 100755 --- a/2020/yang/try.sh +++ b/2020/yang/try.sh @@ -15,6 +15,9 @@ make CC="$CC" all >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear +# remove code we generate and compile +rm -f decoded code.c encoded.c + # we will use hexdump later if it's installed HEXDUMP="$(type -P hexdump)" @@ -31,57 +34,62 @@ 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 +less -rEXFK code.c echo 1>&2 # compile without a PIN -echo "Trying to compile without a PIN:" +read -r -n 1 -p "Press any key to compile without a PIN ($CC code.c -o decode): " echo 1>&2 -echo "$ cc code.c -o decode" 1>&2 -cc code.c -o decode +"$CC" code.c -o decode echo 1>&2 echo "As you can see, you must compile with -DPIN=" 1>&2 +# if hexdump is installed we will use hexdump on the wrong code compiled 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 "Press any key to compile with wrong PIN 555 ($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 | $HEXDUMP -C: " echo 1>&2 ./wrongcoded | "$HEXDUMP" -C +else + echo 1>&2 + echo "Press any key to compile with wrong PIN 555 ($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 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 compile with good PIN 23209 ($CC -DPIN=23209 code.c -o decoded): " +echo 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 +read -r -n 1 -p "Press any key to run: echo \"Hello, world!\" | ./prog 56789 > encoded.c: " +echo 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 +less -rEXFK encoded.c echo 1>&2 -read -r -n 1 -p "Press any key to compile with PIN 56789: " +read -r -n 1 -p "Press any key to compile with good PIN 56789 ($CC -DPIN=56789 encoded.c -o decoded): " echo 1>&2 -echo "$ cc -DPIN=56789 encoded.c -o decoded" 1>&2 -cc -DPIN=56789 encoded.c -o decoded +"$CC" -DPIN=56789 encoded.c -o decoded echo 1>&2 -read -r -n 1 -p "Press any key to run decoded: " +read -r -n 1 -p "Press any key to run ./decoded: " echo 1>&2 -echo "$ ./decoded" 1>&2 ./decoded +echo 1>&2 rm -f decoded code.c encoded.c