2001/anonymous updates
Format fix in README.md. Add cpp.c which is the C pre-processed version cleaned up and somewhat commented as it heavily (ab)uses the ternary operator and recursion. Probably futile but it gave me something to do even if it was a waste of time (could have worked on other README.md files or a host of other things). This did indeed take a long time and a lot of effort! Updated bugs.md with more hints about this entry. I explained here how I came up with the C pre-processed version as it involves something of a hack because of the complicated build instructions. Updated anonymous.ten.c: #include <stdio.h> Added anonymous.ten rule to Makefile. Also disabled optimising level as the author stated that this makes it slower. I observed that the author is anonymous and yet the author information shows the country. I'm not sure if this is intended or not.
This commit is contained in:
1 parent
de0ad77672
commit
56a0711630
6 files changed
+513
-89
No files matched your search
+61
-56
@@ -1,7 +1,7 @@
|
||||
# Most likely to amaze
|
||||
|
||||
The author wishes to remain anonymous
|
||||
Great Britain
|
||||
The author wishes to remain anonymous
|
||||
Great Britain
|
||||
|
||||
## To build:
|
||||
|
||||
@@ -15,17 +15,21 @@ make
|
||||
./anonymous program
|
||||
```
|
||||
|
||||
NOTE: this entry seems to no longer work. [Cody Boone
|
||||
Ferguson](/winners.html#Cody_Boone_Ferguson) has offered some tips in the
|
||||
NOTE: [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed the
|
||||
supplementary program which is necessary to test the program. He C pre-processed
|
||||
and cleaned it up as well as commented it some as it heavily uses the ternary
|
||||
operator and recursive calls. It is not consistent but if you look at it you
|
||||
should understand why that is! Thank you Cody for your assistance! He notes
|
||||
however that this entry seems to no longer work and has offered some tips in the
|
||||
[bugs.md](/bugs.md) file for anyone who mights want to try and fix this but it
|
||||
seems to require a lot of parsing, debugging, an x86 system and possibly knowing
|
||||
the internals of the ELF format (x86 specific). You need to run the program on a
|
||||
binary to test. See the try section below for a program that, if you get the
|
||||
entry to work, would be okay to test it on. Thank you and we will happily credit
|
||||
you if you fix this.
|
||||
does seem to require a lot of parsing, debugging, an x86 system and possibly
|
||||
knowing the internals of the ELF format (x86 specific if there are any?). You
|
||||
need to run the program on a binary to test. See the try section below for the
|
||||
above mentioned program that you can test the entry on. Thank you and we will
|
||||
happily credit you if you fix this.
|
||||
|
||||
WARNING: if you do get this to work it will destroy files that it is used on.
|
||||
See the author's warning on this.
|
||||
WARNING: if you do get this to work **IT WILL _DESTROY FILES__ that it is used
|
||||
on!** See the author's warning on this.
|
||||
|
||||
|
||||
## Try:
|
||||
@@ -46,7 +50,8 @@ quite a lot of bit twiddling.
|
||||
This program is an optimizing dynamic binary translator, allowing you to
|
||||
run x86 programs on any machine (x86 or otherwise).
|
||||
|
||||
I have included a simple "10 green bottles" program, already compiled
|
||||
I have included a simple [10 green
|
||||
bottles](https://www.bbc.co.uk/teach/school-radio/nursery-rhymes-ten-green-bottles/zncyt39) program, already compiled
|
||||
for the x86. The program 'ten', and its source (dull) are given as info
|
||||
files. Warning: note that the translator screws around with the binary
|
||||
you run on it, *will* corrupt the binary to some extent, and may leave
|
||||
@@ -88,75 +93,75 @@ switches such that while compiling the program it generates one error
|
||||
compiler errors while it is running (yes, the program can generate
|
||||
compiler errors while it is running). If you do not wish to see this
|
||||
error, or if the program generates any further error when compiled using
|
||||
your C compiler please remove the "warning=..." line from the build
|
||||
script.
|
||||
your C compiler please remove the `-Dwarning='-Dprocessor'` line and the
|
||||
`$$warning` from the compiler invocation.
|
||||
|
||||
### Optimization:
|
||||
### Optimization
|
||||
|
||||
The build script contains a "-O1" switch for the compiler. Increasing
|
||||
The build script contains a `-O1` switch for the compiler. Increasing
|
||||
the optimization level will make the program run *slower*, while
|
||||
compiling the program without any optimization will allow it to run
|
||||
*faster*.
|
||||
|
||||
### Obfuscation:
|
||||
### Obfuscation
|
||||
|
||||
The most obvious part of the obfuscation is probably the mess of defines
|
||||
at the top. This may seem a somewhat tired old obfuscation - however
|
||||
since many of these macros are (sometimes only) used by the program once
|
||||
it has dynamically recompiled itself, they are only referenced within
|
||||
the source code from within strings - and therefore the macros cannot be
|
||||
expanded. Furthermore, some of these strings of code are not given as
|
||||
strings, but instead are wrapped up in macros that use the "#"
|
||||
preprocessor operator to turn them into strings. In the hope throwing a
|
||||
few C beautifiers the macro to generate the strings is not contained
|
||||
within the source code but instead is passed in on the command line.
|
||||
The most obvious part of the obfuscation is probably the mess of defines at the
|
||||
top. This may seem a somewhat tired old obfuscation - however since many of
|
||||
these macros are (sometimes only) used by the program once it has dynamically
|
||||
recompiled itself, they are only referenced within the source code from within
|
||||
strings - and therefore the macros cannot be expanded. Furthermore, some of
|
||||
these strings of code are not given as strings, but instead are wrapped up in
|
||||
macros that use the `#` preprocessor operator to turn them into strings. In the
|
||||
hope of throwing off a few C beautifiers the macro to generate the strings is
|
||||
not contained within the source code but instead is passed in on the command
|
||||
line.
|
||||
|
||||
Buried under all this, and the fact that the entire program is just a
|
||||
call to exit, there are some nice subtle little obfuscations. For
|
||||
call to `exit()`, there are some nice subtle little obfuscations. For
|
||||
example, you may notice that there are a couple of macros that use the
|
||||
"##" preprocessor operator to build pairs of functions. One of these
|
||||
`##` preprocessor operator to build pairs of functions. One of these
|
||||
macros is used to build to pairs of functions of which only one has
|
||||
local variables which shadow global variables; so one modifies the
|
||||
global state, and the other doesn't.
|
||||
|
||||
There is also quite a nice trick where I wave a magic wand, and a chunk
|
||||
of code which should only be run when the program is run for the first
|
||||
time (setting the PC to point at main, etc) gets turned into a
|
||||
frog^M^M^M^Mstring. The C compiler sees a string by itself in the code,
|
||||
thinks "yup, that's a valid C expression", and quietly moves on to the
|
||||
next line of code.
|
||||
There is also quite a nice trick where I wave a magic wand, and a chunk of code
|
||||
which should only be run when the program is run for the first time (setting the
|
||||
[PC / IP](https://en.wikipedia.org/wiki/Program_counter) to point at `main()`,
|
||||
etc) gets turned into a `frog^M^M^M^Mstring`. The C compiler sees a string by
|
||||
itself in the code, thinks "yup, that's a valid C expression", and quietly moves
|
||||
on to the next line of code.
|
||||
|
||||
### Limitations:
|
||||
### Limitations
|
||||
|
||||
Due to space limitations only a handful of instructions are supported,
|
||||
those instructions which are supported may supported in somewhat
|
||||
non-conventional ways, chunks of the architecture (e.g. flags) are just
|
||||
Due to space limitations only a handful of instructions are supported;
|
||||
these instructions which are supported are supported in somewhat
|
||||
non-conventional ways: chunks of the architecture (e.g. flags) are just
|
||||
ignored, the elf loader does not really load the elf binary, the target
|
||||
library linking can only pass up to 3 parameters to the target library
|
||||
function, etc, etc, etc.
|
||||
function, etc.
|
||||
|
||||
In short, please consider this a full disclaimer for any bug that may
|
||||
turn up - yes the program is unsafe, but it's pretty cool anyway.
|
||||
|
||||
Despite all this, the translator is not exclusively limited to running
|
||||
the 'ten' program. Other trivial x86 programs may run on the translator
|
||||
\- and I have successfully run a wide range of HelloWorld programs,
|
||||
including one of last years IOCCC winners, 'tomx'.
|
||||
Despite all this, the translator is not exclusively limited to running the
|
||||
[anonymous.ten](anonymous.ten.c) program. Other trivial **_x86_** programs may
|
||||
run on the translator \- and I have successfully run a wide range of "Hello
|
||||
World" programs, including one of last years IOCCC winners,
|
||||
[tomx](/2000/tomx/tomx.c).
|
||||
|
||||
### Complete Program:
|
||||
### Complete Program
|
||||
|
||||
The fact that the program makes calls to system and execv may imply that
|
||||
it is not a complete program in its own right, as it relies on other
|
||||
programs. The call to system is a call to ask gcc to recompile the
|
||||
translator with a new set of switches, and the call to execv asks for
|
||||
the newly compiled program to be executed. I would point out that
|
||||
almost every other entry to this competition also require a C compiler
|
||||
(well, the published winners at any rate, and I recognize that a few
|
||||
don't). There is little real difference between this program and one
|
||||
like last years entry 'dhyang'; both are just C programs that generate C
|
||||
code as their output.
|
||||
The fact that the program makes calls to `system()` and `execv()` may imply that
|
||||
it is not a complete program in its own right, as it relies on other programs.
|
||||
The call to `system()` is a call to ask gcc to recompile the translator with a
|
||||
new set of switches, and the call to `execv()` asks for the newly compiled
|
||||
program to be executed. I would point out that almost every other entry to this
|
||||
competition also require a C compiler (well, the published winners at any rate,
|
||||
and I recognize that a few don't). There is little real difference between this
|
||||
program and one like last years entry [dhyang](/2000/dhyang/dhyang.c); both are
|
||||
just C programs that generate C code as their output.
|
||||
|
||||
Enjoy, thanks!
|
||||
Enjoy and thanks!
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
|
||||
Reference in new issue
Block a user