Improve 2020/yang/try.sh
The make clobber now removes decoded, code.c and encoded.c which try.sh creates.
This commit is contained in:
1 parent
5574f865cf
commit
f5ca4825ca
2 files changed
+28
-20
No files matched your search
+1
-1
@@ -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'; \
|
||||
|
||||
+27
-19
@@ -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=<number>" 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
|
||||
Reference in new issue
Block a user