Add 2012/hamano/try.sh + format/typo checks
This commit is contained in:
1 parent
a6d1c17e98
commit
81d972a20f
3 files changed
+72
-15
No files matched your search
+16
-15
@@ -15,23 +15,21 @@ make
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./hamano < README.md > hint.pdf
|
||||
./try.sh
|
||||
```
|
||||
|
||||
You can read `hint.pdf` with a PDF reader like `acroread hint.pdf` or `evince
|
||||
hint.pdf`. With macOS you can do `open hint.pdf` which by default will open
|
||||
`Preview.app`. You may of course use your pdf view to open the file directly
|
||||
instead.
|
||||
The script will generate a number of PDF files and it will suggest you look at
|
||||
them as well. You can read `hint.pdf` with a PDF reader like `acroread hint.pdf`
|
||||
or `evince hint.pdf`. With macOS you can do `open hint.pdf` which by default
|
||||
will open `Preview.app`. You may of course use your pdf viewer to open the file
|
||||
directly instead.
|
||||
|
||||
One of the PDF files generated is this README.md file as a PDF, obfuscated, and
|
||||
the PDF file will then be compiled as C (itself!) and executed so that it shows
|
||||
README.md!
|
||||
|
||||
To deobfuscate:
|
||||
|
||||
```sh
|
||||
cc -xc hint.pdf -o hint
|
||||
./hint
|
||||
```
|
||||
|
||||
Of course, You can also obfuscate C code:
|
||||
Another PDF file generated is obfuscated C code. Once this is done it will
|
||||
compile the PDF as if it was C and then run it like:
|
||||
|
||||
```sh
|
||||
echo 'int main(){puts("Hello World!");}' | ./hamano > hello.pdf
|
||||
@@ -53,7 +51,8 @@ is the font?), and the submitted entry created PDF files that left Ghostscript
|
||||
confused.
|
||||
|
||||
The results can be viewed with Acrobat Reader,
|
||||
[evince](http://en.wikipedia.org/wiki/Evince) and Apple's Preview.
|
||||
[evince](http://en.wikipedia.org/wiki/Evince) and Apple's
|
||||
[Preview](https://en.wikipedia.org/wiki/Preview_(macOS)).
|
||||
|
||||
The updated version can also be viewed using Ghostscript.
|
||||
|
||||
@@ -63,7 +62,9 @@ you might draw is too elementary. :-)
|
||||
|
||||
So what do those flags really mean?
|
||||
|
||||
The [Dancing men algorithm][1] might be useful.
|
||||
The [Dancing men
|
||||
algorithm](http://en.wikipedia.org/wiki/The_Adventure_of_the_Dancing_Men) might
|
||||
be useful.
|
||||
|
||||
Don't forget to take a look at the generated PDF. Perhaps you might even want
|
||||
to compile the output with a C compiler. When you run it, what does it
|
||||
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2012/hamano
|
||||
#
|
||||
|
||||
# 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
|
||||
|
||||
read -r -n 1 -p "Press any key to obfuscate README.md, writing to hint.pdf: "
|
||||
echo 1>&2
|
||||
echo "$ ./hamano < README.md > hint.pdf" 1>&2
|
||||
./hamano < README.md > hint.pdf
|
||||
|
||||
echo "Now try opening it in a pdf viewer before proceeding." 1>&2
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
|
||||
echo 1>&2
|
||||
echo "$ ${CC} -xc hint.pdf -o hint" 1>&2
|
||||
${CC} -xc hint.pdf -o hint
|
||||
echo 1>&2
|
||||
read -r -n 1 -p "Press any key to run: ./hint | less (space = next page, q = quit): "
|
||||
./hint | less
|
||||
|
||||
echo 1>&2
|
||||
|
||||
echo "Will obfuscate the following code: " 1>&2
|
||||
echo 1>&2
|
||||
echo " int main(){puts("Hello World!");}"
|
||||
echo 1>&2
|
||||
echo "writing to hello.pdf" 1>&2
|
||||
echo 'int main(){puts("Hello World!");}' | ./hamano > hello.pdf
|
||||
echo 1>&2
|
||||
echo "Now open hello.pdf in a pdf viewer before continuing." 1>&2
|
||||
echo 1>&2
|
||||
read -r -n 1 -p "Press any key to continue to deobfuscate and compile hello.pdf: "
|
||||
echo 1>&2
|
||||
echo "$ ${CC} -Wno-implicit-function-declaration -xc hello.pdf -o hello2" 1>&2
|
||||
${CC} -Wno-implicit-function-declaration -xc hello.pdf -o hello2
|
||||
echo "$ ./hello2 | ${CC} -Wno-implicit-function-declaration -xc - -o ./hello3" 1>&2
|
||||
./hello2 | ${CC} -Wno-implicit-function-declaration -xc - -o ./hello3
|
||||
echo "$ ./hello3" 1>&2
|
||||
./hello3
|
||||
@@ -3349,6 +3349,11 @@ Cody fixed a typo in the ruby script
|
||||
Cody restored the original code from the archive.
|
||||
|
||||
|
||||
## [2012/hamano](2012/hamano/hamano.c) ([README.md](2012/hamano/README.md]))
|
||||
|
||||
Cody added the [try.sh](2012/hamano/try.sh) script.
|
||||
|
||||
|
||||
## [2012/hou](2012/hou/hou.c) ([README.md](2012/hou/README.md]))
|
||||
|
||||
Cody added the [try.sh](2012/hou/try.sh) script and restored the original [hint
|
||||
|
||||
Reference in new issue
Block a user