Improve 2001/anonymous/README.md and try.me.sh
Fix typo fix and format fix in 2001/anonymous/README.md. Improve try.me.sh: test compile as 32-bit anonymous.ten.c and exit if it cannot be done as it will otherwise not truly work right. I also observed that this _might_ not be fixed completely. The binary _is_ modified and _does_ run after execution, will crash on 64-bit binaries (and it's not supposed to work on 64-bit binaries and probably anything other than 32-bit ELF binaries) but the author comments are not entirely clear to me. It might be that the program is supposed to be run. At the same time though the compilation is unclear to me too: the entry itself need not be compiled and the binary isn't compiled either (is it supposed to be?) so why is it there? The program is at least partially fixed in that it used to crash no matter what and it does in any case modify the binary which was supposed to be done (and this is why I'm still unsure about why it does anything with compilation). Perhaps it's time to bring back the C pre-processed code but I will find more out in the coming days I hope and if necessary I will add this entry back to bugs.md and then look at fixing it after some higher priority things are finished. The higher priority thing in particular has to do with issue #4 but I have a number of already modified files that I would like to get committed before I continue on that to make my repo a clean state. I might or might not do that before but it might be that there are numerous commits prior to the CSV file being worked on again.
This commit is contained in:
1 parent
6c07cc538d
commit
f49ec22306
2 files changed
+74
-52
No files matched your search
+45
-31
@@ -73,7 +73,8 @@ something funny if you run it on itself as well but see below :-)
|
|||||||
./try.me.sh
|
./try.me.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
What happens if the x86 program has already been modified by this program?
|
What happens if the x86 program has already been modified by this program? The
|
||||||
|
judges' remarks below might give you a hint!
|
||||||
|
|
||||||
What happens if you try it on another file like [anonymous.c](anonymous.c)? Can
|
What happens if you try it on another file like [anonymous.c](anonymous.c)? Can
|
||||||
you recompile it okay? What if you run it on `anonymous` itself? Can you run the
|
you recompile it okay? What if you run it on `anonymous` itself? Can you run the
|
||||||
@@ -90,37 +91,49 @@ quite a lot of bit twiddling.
|
|||||||
This program is an optimizing dynamic binary translator, allowing you to
|
This program is an optimizing dynamic binary translator, allowing you to
|
||||||
run x86 programs on any machine (x86 or otherwise).
|
run x86 programs on any machine (x86 or otherwise).
|
||||||
|
|
||||||
I have included a simple [10 green
|
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
|
Bottles](https://www.bbc.co.uk/teach/school-radio/nursery-rhymes-ten-green-bottles/zncyt39)
|
||||||
for the x86. The program 'ten', and its source (dull) are given as info
|
[program](anonymous.ten.c) (try `make anonymous.ten`), meant to be compiled in 32-bit.
|
||||||
files. Warning: note that the translator screws around with the binary
|
The program `anonymous.ten`, and its source (dull) are included as data
|
||||||
you run on it, *will* corrupt the binary to some extent, and may leave
|
files.
|
||||||
any program you run on it unusable.
|
|
||||||
|
|
||||||
The build script should give an example command to run.
|
### Warning
|
||||||
|
|
||||||
|
Note that the translator screws around with the binary you run on it and *might*
|
||||||
|
corrupt the binary to some extent and in so doing might leave any program you
|
||||||
|
run on it unusable.
|
||||||
|
|
||||||
|
The build script should give an example command to compile the program.
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
Basic Block Cache: Rather than translating each instruction individually
|
[Basic Block](https://en.wikipedia.org/wiki/Basic_block)
|
||||||
the dynamic binary translator generates a translation for an entire
|
[Cache](https://en.wikipedia.org/wiki/Cache_(computing)): Rather than
|
||||||
basic block of subject code. Having translated a block once, the target
|
translating each instruction individually the dynamic binary translator
|
||||||
code generated will be stored for the duration that the program is
|
generates a translation for an entire basic block of subject code. Having
|
||||||
running, so as a program runs its performance will improve, as it hits
|
translated a block once, the target code generated will be stored for the
|
||||||
cached blocks. This can be clearly observed in the example program,
|
duration that the program is running, so as a program runs its performance will
|
||||||
'ten'.
|
improve, as it hits cached blocks. This can be clearly observed in the example
|
||||||
|
program, [anonymous.ten](anonymous.ten.c) which must be compiled as a 32-bit
|
||||||
|
binary.
|
||||||
|
|
||||||
### Target Library Linking:
|
### Target Library Linking:
|
||||||
|
|
||||||
The program runs dynamically linked elf binaries, and when the subject
|
The program runs [dynamically
|
||||||
program attempts to make a call to a standard library, the translator
|
linked](https://en.wikipedia.org/wiki/Dynamic_linker) [ELF
|
||||||
attempts to make an appropriate call to the native system libraries on
|
binaries](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format), and
|
||||||
the target machine. This involves mangling between different calling
|
when the subject program attempts to make a call to a standard
|
||||||
conventions, etc.
|
[library](https://en.wikipedia.org/wiki/Library_(computing)), the translator
|
||||||
|
attempts to make an appropriate call to the native system libraries on the
|
||||||
|
target machine. This involves mangling between different calling conventions,
|
||||||
|
etc.
|
||||||
|
|
||||||
### Automatic Endian Detection/Reversal:
|
### Automatic Endian Detection/Reversal:
|
||||||
|
|
||||||
There are various problems raised when attempting to run little endian
|
There are various problems raised when attempting to run little
|
||||||
x86 code on a big endian chip, such as a PPC. These problems are dealt
|
[endian](https://en.wikipedia.org/wiki/Endianness)
|
||||||
|
[x86](https://en.wikipedia.org/wiki/X86) code on a big endian chip, such as a
|
||||||
|
[PPC](https://en.wikipedia.org/wiki/PowerPC). These problems are dealt
|
||||||
with in a manner that is entirely transparent to the user.
|
with in a manner that is entirely transparent to the user.
|
||||||
|
|
||||||
### Configuration:
|
### Configuration:
|
||||||
@@ -145,7 +158,7 @@ compiling the program without any optimization will allow it to run
|
|||||||
|
|
||||||
### Obfuscation
|
### Obfuscation
|
||||||
|
|
||||||
The most obvious part of the obfuscation is probably the mess of defines at the
|
The most obvious part of the obfuscation is probably the mess of `#define`s at the
|
||||||
top. This may seem a somewhat tired old obfuscation - however since many of
|
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
|
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
|
recompiled itself, they are only referenced within the source code from within
|
||||||
@@ -160,8 +173,8 @@ 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
|
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
|
macros is used to build pairs of functions of which only one has
|
||||||
local variables which shadow global variables; so one modifies the
|
local variables which shadow global variables: so one modifies the
|
||||||
global state, and the other doesn't.
|
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
|
There is also quite a nice trick where I wave a magic wand, and a chunk of code
|
||||||
@@ -173,12 +186,13 @@ on to the next line of code.
|
|||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|
||||||
Due to space limitations only a handful of instructions are supported;
|
Due to space limitations only a handful of instructions are supported; these
|
||||||
these instructions which are supported are supported in somewhat
|
instructions which are supported are supported in somewhat non-conventional
|
||||||
non-conventional ways: chunks of the architecture (e.g. flags) are just
|
ways: chunks of the architecture (e.g. flags) are just ignored, the ELF
|
||||||
ignored, the elf loader does not really load the elf binary, the target
|
[loader](https://en.wikipedia.org/wiki/Loader_(computing)) does not really load
|
||||||
library linking can only pass up to 3 parameters to the target library
|
the [ELF binary](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format),
|
||||||
function, etc.
|
the target [library linking](https://en.wikipedia.org/wiki/Linker_(computing))
|
||||||
|
can only pass up to 3 parameters to the target library function, etc.
|
||||||
|
|
||||||
In short, please consider this a full disclaimer for any bug that may
|
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.
|
turn up - yes the program is unsafe, but it's pretty cool anyway.
|
||||||
|
|||||||
+29
-21
@@ -1,24 +1,32 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
make clobber
|
make clobber
|
||||||
make all 2>/dev/null
|
|
||||||
echo "$ cp anonymous.ten anonymous.ten.bak" 1>2
|
if [[ $(make anonymous.ten >/dev/null 2>&1) ]]; then
|
||||||
cp anonymous.ten anonymous.ten.bak
|
|
||||||
echo "$ ./anonymous anonymous.ten" 1>&2
|
make anonymous 2>/dev/null
|
||||||
./anonymous anonymous.ten
|
echo "$ cp anonymous.ten anonymous.ten.bak" 1>&2
|
||||||
echo "$ ./anonymous.ten" 1>&2
|
cp anonymous.ten anonymous.ten.bak
|
||||||
./anonymous.ten
|
echo "$ ./anonymous anonymous.ten" 1>&2
|
||||||
echo "$ diff -s anonymous.ten anonymous.ten.bak" 1>&2
|
./anonymous anonymous.ten
|
||||||
diff -s anonymous.ten anonymous.ten.bak
|
echo "$ ./anonymous.ten" 1>&2
|
||||||
echo "$ od anonymous.ten > ten.od" 1>&2
|
./anonymous.ten
|
||||||
od anonymous.ten > ten.od
|
echo "$ diff -s anonymous.ten anonymous.ten.bak" 1>&2
|
||||||
echo "$ od anonymous.ten.bak > ten.bak.od" 1>&2
|
diff -s anonymous.ten anonymous.ten.bak
|
||||||
od anonymous.ten.bak > ten.bak.od
|
echo "$ od -t x1 anonymous.ten > ten.od" 1>&2
|
||||||
echo "$ diff ten.bak.od ten.od" 1>&2
|
od -t x1 anonymous.ten > ten.od
|
||||||
diff ten.bak.od ten.od
|
echo "$ od -t x1 anonymous.ten.bak > ten.bak.od" 1>&2
|
||||||
echo "$ ./anonymous.ten > ten.txt" 1>&2
|
od -t x1 anonymous.ten.bak > ten.bak.od
|
||||||
./anonymous.ten > ten.txt
|
echo "$ diff ten.bak.od ten.od" 1>&2
|
||||||
echo "$ ./anonymous.ten.bak > ten.bak.txt" 1>&2
|
diff ten.bak.od ten.od
|
||||||
./anonymous.ten.bak > ten.bak.txt
|
echo "$ ./anonymous.ten > ten.txt" 1>&2
|
||||||
echo "$ diff -s ten.txt ten.bak.txt" 1>&2
|
./anonymous.ten > ten.txt
|
||||||
diff -s ten.txt ten.bak.txt
|
echo "$ ./anonymous.ten.bak > ten.bak.txt" 1>&2
|
||||||
|
./anonymous.ten.bak > ten.bak.txt
|
||||||
|
echo "$ diff -s ten.txt ten.bak.txt" 1>&2
|
||||||
|
diff -s ten.txt ten.bak.txt
|
||||||
|
else
|
||||||
|
echo
|
||||||
|
echo "cannot compile anonymous.ten.c as 32-bit, sorry."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user