Fixes and updates to 2001/anonymous
The alt target list now includes the supplementary program I added. There were some problems fixed in the README.md file that occurred when the (far superior) thanks-for-fixes.md file was introduced. The thanks file was updated as well.
This commit is contained in:
1 parent
0cd1b0b028
commit
bbb3d42bc2
3 files changed
+45
-40
No files matched your search
@@ -120,8 +120,8 @@ OBJ= ${PROG}.o
|
|||||||
DATA=
|
DATA=
|
||||||
TARGET= ${PROG} ${PROG}.ten ${PROG}.ten.64 ${PROG}.bed ${PROG}.bed.64
|
TARGET= ${PROG} ${PROG}.ten ${PROG}.ten.64 ${PROG}.bed ${PROG}.bed.64
|
||||||
#
|
#
|
||||||
ALT_OBJ= ${PROG}.ten.64.o
|
ALT_OBJ= ${PROG}.ten.64.o ${PROG}.bed.64.o
|
||||||
ALT_TARGET= ${PROG}.ten.64
|
ALT_TARGET= ${PROG}.ten.64 ${PROG}.bed.64
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|||||||
+27
-29
@@ -17,17 +17,6 @@ make
|
|||||||
./anonymous x86_program
|
./anonymous x86_program
|
||||||
```
|
```
|
||||||
|
|
||||||
For fun and so that there's another program that is a bit different (it uses a `char
|
|
||||||
*[]` array for example) that this program will still work on. To use:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
make anonymous.bed # if able to use -m32
|
|
||||||
./anonymous anonymous.bed
|
|
||||||
|
|
||||||
make anonymous.bed.64 # if unable to use -m32
|
|
||||||
./anonymous.bed.64
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
|
|
||||||
@@ -37,6 +26,20 @@ make anonymous.bed.64 # if unable to use -m32
|
|||||||
./anonymous anonymous.bed # if able to use -m32
|
./anonymous anonymous.bed # if able to use -m32
|
||||||
```
|
```
|
||||||
|
|
||||||
|
NOTE: if the 32-bit version cannot be compiled the script will at least compile
|
||||||
|
[anonymous.ten](anonymous.ten.c) as a 64-bit program and run it directly.
|
||||||
|
|
||||||
|
For fun and so that there's another program that is a bit different (it uses a `char
|
||||||
|
*[]` array for example) that this program will still work on:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make anonymous.bed # if able to use -m32
|
||||||
|
./anonymous anonymous.bed
|
||||||
|
|
||||||
|
make anonymous.bed.64 # if unable to use -m32
|
||||||
|
./anonymous.bed.64
|
||||||
|
```
|
||||||
|
|
||||||
What happens if the x86 program has already been modified by this program? The
|
What happens if the x86 program has already been modified by this program? The
|
||||||
judges' remarks below might give you a hint!
|
judges' remarks below might give you a hint!
|
||||||
|
|
||||||
@@ -44,14 +47,6 @@ 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
|
||||||
program successfully after it without recompiling?
|
program successfully after it without recompiling?
|
||||||
|
|
||||||
NOTE: if the 32-bit version cannot be compiled the script will at least run the
|
|
||||||
alternate version of the [anonymous.ten](anonymous.ten.c) program.
|
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
|
||||||
|
|
||||||
Is emulation the sincerest form of flattery? This small program does
|
|
||||||
quite a lot of bit twiddling.
|
|
||||||
|
|
||||||
### INABIAF - it's not a bug it's a feature! :-)
|
### INABIAF - it's not a bug it's a feature! :-)
|
||||||
|
|
||||||
@@ -64,19 +59,22 @@ that :-(
|
|||||||
If the program cannot be run (for instance under macOS as an ELF file) then
|
If the program cannot be run (for instance under macOS as an ELF file) then
|
||||||
the program will fail to execute it and might not even touch it.
|
the program will fail to execute it and might not even touch it.
|
||||||
|
|
||||||
### WARNING on note from the author
|
### A 2023 note about the warning from the author:
|
||||||
|
|
||||||
The author suggested that this will somewhat destroy the binaries this touches
|
The author suggested that this *might* somewhat destroy the binaries this
|
||||||
but others did not observe this. It does indeed modify the files as the script
|
touches but after the fix of 2023 this was not observed (yet?). It does indeed
|
||||||
below will show you (though not all files are modified: can you figure out why
|
modify the files (though not all files are modified: can you figure out why that
|
||||||
that is?) but others did not notice any problems in using them. Perhaps it's
|
is?) but using them after did not result in any problems. It could be that it's
|
||||||
something he's not aware of possibly including the fact that the modification
|
no longer known exactly what is supposed to happen and possibly that the
|
||||||
might or might not be complete. If you follow the try commands below you will
|
modification might not be entirely correct for that reason though it does appear
|
||||||
notice that although the binaries do differ it's not many differences and the
|
to be correct.
|
||||||
output of the supplementary program both before and after is the same. See the
|
|
||||||
author's warning about this in their remarks.
|
|
||||||
|
|
||||||
|
|
||||||
|
## Judges' remarks:
|
||||||
|
|
||||||
|
Is emulation the sincerest form of flattery? This small program does
|
||||||
|
quite a lot of bit twiddling.
|
||||||
|
|
||||||
## Author's remarks:
|
## Author's remarks:
|
||||||
|
|
||||||
This program is an optimizing dynamic binary translator, allowing you to
|
This program is an optimizing dynamic binary translator, allowing you to
|
||||||
|
|||||||
+16
-9
@@ -1005,9 +1005,9 @@ other version in.
|
|||||||
Cody fixed both the supplementary program and the program itself (both of which
|
Cody fixed both the supplementary program and the program itself (both of which
|
||||||
segfaulted and once that was fixed only the binary was modified; it was not run
|
segfaulted and once that was fixed only the binary was modified; it was not run
|
||||||
but according to the author's remarks it should be executed). He managed to do
|
but according to the author's remarks it should be executed). He managed to do
|
||||||
this with linux but it will not work with macOS Catalina (10.15). See
|
this with linux but it will not work with any system that does not allow one to
|
||||||
[bugs.md](/bugs.md) for why this is); _this is **not** a bug, it's a feature_
|
compile 32-bit binaries such as macOS. See [bugs.md](/bugs.md) for why this is;
|
||||||
inherent in what it does!
|
_this is **not** a bug, it's a feature_ inherent in what it does!
|
||||||
|
|
||||||
Below is what it took to fix.
|
Below is what it took to fix.
|
||||||
|
|
||||||
@@ -1022,14 +1022,17 @@ binary. But again see [bugs.md](/bugs.md) here.
|
|||||||
These also had to be done:
|
These also had to be done:
|
||||||
|
|
||||||
- when `open()`ing the file the file descriptor had to be saved so it could be
|
- when `open()`ing the file the file descriptor had to be saved so it could be
|
||||||
closed prior to executing the program.
|
closed prior to executing the program. This is the `f` variable which is of type
|
||||||
- `munmap()` also had to be called prior to executing the program.
|
`l`, a `#define` for `int *`.
|
||||||
|
- `munmap()` also had to be called prior to executing the program. This involved
|
||||||
|
a new `off_t N` so which was added in the `mmap()` call which was then used in
|
||||||
|
the `munmap()` call.
|
||||||
|
|
||||||
Without those changes the program was not executed after modification which it
|
Without those changes the program was not executed after modification which it
|
||||||
was supposed to do, instead reporting text file busy error.
|
was supposed to do; instead it reported text file busy error.
|
||||||
|
|
||||||
Notice that the location of the calls to `munmap()` and `close()` followed by
|
Notice that the location of `munmap()` and `close()` followed by `execv()` _does
|
||||||
`execv()` _does matter_!
|
matter_!
|
||||||
|
|
||||||
To get this to compile with clang, `main()` had to change from:
|
To get this to compile with clang, `main()` had to change from:
|
||||||
|
|
||||||
@@ -1044,7 +1047,8 @@ int main (int cka, char **k) { char *ck = (char *)cka; /* ... */ }
|
|||||||
```
|
```
|
||||||
|
|
||||||
The following change was also made to be more portable, in case the constants
|
The following change was also made to be more portable, in case the constants
|
||||||
`PROT_READ` and/or `PROT_WRITE` are not standardised:
|
`PROT_READ` and/or `PROT_WRITE` are not standardised or some platform does not
|
||||||
|
follow it:
|
||||||
|
|
||||||
Change `3` in the call to `mmap()` to be `PROT_READ|PROT_WRITE`: just in case
|
Change `3` in the call to `mmap()` to be `PROT_READ|PROT_WRITE`: just in case
|
||||||
`PROT_READ|PROT_WRITE` does not equal 3 (though it seems to be equal in both
|
`PROT_READ|PROT_WRITE` does not equal 3 (though it seems to be equal in both
|
||||||
@@ -1072,6 +1076,9 @@ Cody also added a [program](anonymous.bed.c) like [anonymous.ten.c](anonymous.te
|
|||||||
[Ten Green Bottles](https://en.wikipedia.org/wiki/Ten_Green_Bottles) but which
|
[Ten Green Bottles](https://en.wikipedia.org/wiki/Ten_Green_Bottles) but which
|
||||||
sings [Ten in the Bed](https://allnurseryrhymes.com/ten-in-the-bed/).
|
sings [Ten in the Bed](https://allnurseryrhymes.com/ten-in-the-bed/).
|
||||||
|
|
||||||
|
As well he added the [try.me.sh](2001/anonymous/try.me.sh) so that one can
|
||||||
|
attempt to use the program as it was designed but if compiling as 32-bit fails
|
||||||
|
it will at least run the supplementary program as a 64-bit program directly.
|
||||||
|
|
||||||
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md]))
|
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md]))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user