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
@@ -1,2 +1,3 @@
|
|||||||
anonymous
|
anonymous
|
||||||
anonymous.ten
|
anonymous.ten
|
||||||
|
cpp
|
||||||
+11
-2
@@ -70,7 +70,7 @@ CINCLUDE=
|
|||||||
|
|
||||||
# Optimization
|
# Optimization
|
||||||
#
|
#
|
||||||
OPT= -O1
|
OPT=
|
||||||
|
|
||||||
# Default flags for ANSI C compilation
|
# Default flags for ANSI C compilation
|
||||||
#
|
#
|
||||||
@@ -116,7 +116,7 @@ ENTRY= anonymous
|
|||||||
PROG= ${ENTRY}
|
PROG= ${ENTRY}
|
||||||
#
|
#
|
||||||
OBJ= ${PROG}.o
|
OBJ= ${PROG}.o
|
||||||
DATA= anonymous.ten.c
|
DATA=
|
||||||
TARGET= ${PROG}
|
TARGET= ${PROG}
|
||||||
#
|
#
|
||||||
ALT_OBJ=
|
ALT_OBJ=
|
||||||
@@ -142,6 +142,15 @@ ${PROG}: ${PROG}.c
|
|||||||
$$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
$$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
||||||
$< -o $@ ${LIBS}
|
$< -o $@ ${LIBS}
|
||||||
|
|
||||||
|
${PROG}.ten: ${PROG}.ten.c
|
||||||
|
@echo "NOTE: this program must be compiled as 32-bit to use with the entry itself."
|
||||||
|
@echo "if you want to use it where this is not possible e.g. with a Mac try, say to"
|
||||||
|
@echo "use by itself, try:"
|
||||||
|
@echo
|
||||||
|
@echo " ${CC} $< -o $@"
|
||||||
|
@echo
|
||||||
|
${CC} ${CFLAGS} -m32 $< -o $@ ${LIBS}
|
||||||
|
|
||||||
# alternative executable
|
# alternative executable
|
||||||
#
|
#
|
||||||
alt: data ${ALT_TARGET}
|
alt: data ${ALT_TARGET}
|
||||||
|
|||||||
+61
-56
@@ -1,7 +1,7 @@
|
|||||||
# Most likely to amaze
|
# Most likely to amaze
|
||||||
|
|
||||||
The author wishes to remain anonymous
|
The author wishes to remain anonymous
|
||||||
Great Britain
|
Great Britain
|
||||||
|
|
||||||
## To build:
|
## To build:
|
||||||
|
|
||||||
@@ -15,17 +15,21 @@ make
|
|||||||
./anonymous program
|
./anonymous program
|
||||||
```
|
```
|
||||||
|
|
||||||
NOTE: this entry seems to no longer work. [Cody Boone
|
NOTE: [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed the
|
||||||
Ferguson](/winners.html#Cody_Boone_Ferguson) has offered some tips in 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
|
[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
|
does seem to require a lot of parsing, debugging, an x86 system and possibly
|
||||||
the internals of the ELF format (x86 specific). You need to run the program on a
|
knowing the internals of the ELF format (x86 specific if there are any?). You
|
||||||
binary to test. See the try section below for a program that, if you get the
|
need to run the program on a binary to test. See the try section below for the
|
||||||
entry to work, would be okay to test it on. Thank you and we will happily credit
|
above mentioned program that you can test the entry on. Thank you and we will
|
||||||
you if you fix this.
|
happily credit you if you fix this.
|
||||||
|
|
||||||
WARNING: if you do get this to work it will destroy files that it is used on.
|
WARNING: if you do get this to work **IT WILL _DESTROY FILES__ that it is used
|
||||||
See the author's warning on this.
|
on!** See the author's warning on this.
|
||||||
|
|
||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
@@ -46,7 +50,8 @@ 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 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
|
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
|
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
|
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 (yes, the program can generate
|
||||||
compiler errors while it is running). If you do not wish to see this
|
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
|
error, or if the program generates any further error when compiled using
|
||||||
your C compiler please remove the "warning=..." line from the build
|
your C compiler please remove the `-Dwarning='-Dprocessor'` line and the
|
||||||
script.
|
`$$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
|
the optimization level will make the program run *slower*, while
|
||||||
compiling the program without any optimization will allow it to run
|
compiling the program without any optimization will allow it to run
|
||||||
*faster*.
|
*faster*.
|
||||||
|
|
||||||
### Obfuscation:
|
### Obfuscation
|
||||||
|
|
||||||
The most obvious part of the obfuscation is probably the mess of defines
|
The most obvious part of the obfuscation is probably the mess of defines at the
|
||||||
at the top. This may seem a somewhat tired old obfuscation - however
|
top. This may seem a somewhat tired old obfuscation - however since many of
|
||||||
since many of these macros are (sometimes only) used by the program once
|
these macros are (sometimes only) used by the program once it has dynamically
|
||||||
it has dynamically recompiled itself, they are only referenced within
|
recompiled itself, they are only referenced within the source code from within
|
||||||
the source code from within strings - and therefore the macros cannot be
|
strings - and therefore the macros cannot be expanded. Furthermore, some of
|
||||||
expanded. Furthermore, some of these strings of code are not given as
|
these strings of code are not given as strings, but instead are wrapped up in
|
||||||
strings, but instead are wrapped up in macros that use the "#"
|
macros that use the `#` preprocessor operator to turn them into strings. In the
|
||||||
preprocessor operator to turn them into strings. In the hope throwing a
|
hope of throwing off a few C beautifiers the macro to generate the strings is
|
||||||
few C beautifiers the macro to generate the strings is not contained
|
not contained within the source code but instead is passed in on the command
|
||||||
within the source code but instead is passed in on the command line.
|
line.
|
||||||
|
|
||||||
Buried under all this, and the fact that the entire program is just a
|
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 to 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
|
There is also quite a nice trick where I wave a magic wand, and a chunk of code
|
||||||
of code which should only be run when the program is run for the first
|
which should only be run when the program is run for the first time (setting the
|
||||||
time (setting the PC to point at main, etc) gets turned into a
|
[PC / IP](https://en.wikipedia.org/wiki/Program_counter) to point at `main()`,
|
||||||
frog^M^M^M^Mstring. The C compiler sees a string by itself in the code,
|
etc) gets turned into a `frog^M^M^M^Mstring`. The C compiler sees a string by
|
||||||
thinks "yup, that's a valid C expression", and quietly moves on to the
|
itself in the code, thinks "yup, that's a valid C expression", and quietly moves
|
||||||
next line of code.
|
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;
|
||||||
those instructions which are supported may supported in somewhat
|
these instructions which are supported are supported in somewhat
|
||||||
non-conventional ways, chunks of the architecture (e.g. flags) are just
|
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
|
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
|
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
|
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.
|
||||||
|
|
||||||
Despite all this, the translator is not exclusively limited to running
|
Despite all this, the translator is not exclusively limited to running the
|
||||||
the 'ten' program. Other trivial x86 programs may run on the translator
|
[anonymous.ten](anonymous.ten.c) program. Other trivial **_x86_** programs may
|
||||||
\- and I have successfully run a wide range of HelloWorld programs,
|
run on the translator \- and I have successfully run a wide range of "Hello
|
||||||
including one of last years IOCCC winners, 'tomx'.
|
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
|
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
|
it is not a complete program in its own right, as it relies on other programs.
|
||||||
programs. The call to system is a call to ask gcc to recompile the
|
The call to `system()` is a call to ask gcc to recompile the translator with a
|
||||||
translator with a new set of switches, and the call to execv asks for
|
new set of switches, and the call to `execv()` asks for the newly compiled
|
||||||
the newly compiled program to be executed. I would point out that
|
program to be executed. I would point out that almost every other entry to this
|
||||||
almost every other entry to this competition also require a C compiler
|
competition also require a C compiler (well, the published winners at any rate,
|
||||||
(well, the published winners at any rate, and I recognize that a few
|
and I recognize that a few don't). There is little real difference between this
|
||||||
don't). There is little real difference between this program and one
|
program and one like last years entry [dhyang](/2000/dhyang/dhyang.c); both are
|
||||||
like last years entry 'dhyang'; both are just C programs that generate C
|
just C programs that generate C code as their output.
|
||||||
code as their output.
|
|
||||||
|
|
||||||
Enjoy, thanks!
|
Enjoy and thanks!
|
||||||
|
|
||||||
## Copyright and CC BY-SA 4.0 License:
|
## Copyright and CC BY-SA 4.0 License:
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <stdio.h>
|
||||||
#define PLURAL(bottles) bottles==1?"bottle":"bottles"
|
#define PLURAL(bottles) bottles==1?"bottle":"bottles"
|
||||||
|
|
||||||
void sing(int bottles) {
|
void sing(int bottles) {
|
||||||
|
|||||||
@@ -0,0 +1,346 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
#define l int*
|
||||||
|
#define F char
|
||||||
|
|
||||||
|
struct stat t;
|
||||||
|
#define c return
|
||||||
|
#define I (P+=4,*L(P-4,0))
|
||||||
|
#define G (signed F)E(*L(P++,0))
|
||||||
|
#define C(O,D) E (D[B+V(010)/4+O*10])
|
||||||
|
#define U R[4]=E(V(17)-4),*(l)V(021)=
|
||||||
|
|
||||||
|
char M [99],Q[99],b[15000],*ss,*d=b, *z;
|
||||||
|
|
||||||
|
#define O =(n=*(l)V(021),R[4]=E(V(17)+4),n)
|
||||||
|
#define p(a,b,c) system((sprintf(a,b,k[1]),c)),z
|
||||||
|
#define g (y/010&7)
|
||||||
|
#define R (B+13)
|
||||||
|
#define x86 (F*)index(ss+V(i ),0100)
|
||||||
|
|
||||||
|
#define D(y,n,a,m,i,c) d += \
|
||||||
|
sprintf(d, \
|
||||||
|
y,n,a,m,i,c ), \
|
||||||
|
(F* ) P
|
||||||
|
|
||||||
|
int* B,i,n,a,r,y,P ;
|
||||||
|
V(v){
|
||||||
|
return E(B[v]) /* end E() */;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int *Li(d,r)
|
||||||
|
{
|
||||||
|
return E (3[B+
|
||||||
|
V(010) /* end V() */
|
||||||
|
/4+r*10]
|
||||||
|
) &&
|
||||||
|
E (3 [B+
|
||||||
|
V(010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */
|
||||||
|
|
||||||
|
<=d ?
|
||||||
|
(int*)(((int)B) + d +
|
||||||
|
E(4[B+
|
||||||
|
V (010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */ -
|
||||||
|
E (3[B +
|
||||||
|
V(010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */
|
||||||
|
) :
|
||||||
|
(((int)B)^d)>>24&&--r?
|
||||||
|
Li(d,r) /* end Li() */:
|
||||||
|
(int*)d;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *L(d, r){
|
||||||
|
return r =
|
||||||
|
V(014 ) /* end V() */&
|
||||||
|
63,
|
||||||
|
Li(d,r) /* end Li() */
|
||||||
|
;
|
||||||
|
}
|
||||||
|
int *Runi(d,a)
|
||||||
|
{
|
||||||
|
return (ss = strcmp((char*)B+
|
||||||
|
E (4[B+
|
||||||
|
V(010)/* end V() *//4+
|
||||||
|
(V(12) /* end V() */
|
||||||
|
>>16)*10])+
|
||||||
|
E(0[B+
|
||||||
|
V(010) /* end V() */
|
||||||
|
/4+--r*10]), /* end E() */
|
||||||
|
".strtab") /* end strcmp() */ ?
|
||||||
|
ss:(char*)B+
|
||||||
|
E (4[B+
|
||||||
|
V(010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */ ,
|
||||||
|
E (1[B+
|
||||||
|
V(010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */ -
|
||||||
|
2) ?
|
||||||
|
Runi(d,r) :
|
||||||
|
0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *Run(d, a)
|
||||||
|
{
|
||||||
|
return r=
|
||||||
|
V(014 ) /* end V() */
|
||||||
|
&63,
|
||||||
|
Runi(d,a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Sca()
|
||||||
|
{
|
||||||
|
i=((a-=16)+
|
||||||
|
E (4[B +
|
||||||
|
V (010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */
|
||||||
|
|
||||||
|
)/4,
|
||||||
|
(V(-~i) /* end V() */
|
||||||
|
-P+2 ?
|
||||||
|
Sca() :
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
Scan()
|
||||||
|
{
|
||||||
|
a=
|
||||||
|
E(5[B+
|
||||||
|
V(010) /* end V() */
|
||||||
|
/4+r*10]) /* end E() */
|
||||||
|
, Sca();
|
||||||
|
}
|
||||||
|
ru()
|
||||||
|
{
|
||||||
|
i=((a-=16)+
|
||||||
|
E(4[B+
|
||||||
|
V(010) /* end V() */ /
|
||||||
|
4+r*10]) /* end E() */
|
||||||
|
)/4,
|
||||||
|
(strcmp(ss +
|
||||||
|
V(i),
|
||||||
|
"main") /* end strcmp() */ ?
|
||||||
|
ru() :
|
||||||
|
0)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
run(){
|
||||||
|
a=
|
||||||
|
E(5[B +
|
||||||
|
V(010) /* end V() in E() */
|
||||||
|
/4+r*10]) /* end E() */,
|
||||||
|
ru();
|
||||||
|
}
|
||||||
|
E(DX)
|
||||||
|
{
|
||||||
|
return *z /* z at this point appeared to be '\002' if I (Cody) recalls correctly */ ?
|
||||||
|
DX : DX <<030 |
|
||||||
|
(DX&65280)<<010 |
|
||||||
|
DX>>8 & 65280 |
|
||||||
|
DX>>24&0377;
|
||||||
|
}
|
||||||
|
|
||||||
|
int* K(k)
|
||||||
|
{
|
||||||
|
return L(
|
||||||
|
E(
|
||||||
|
k [
|
||||||
|
(int*)V(17) /* end V() in E() in L() */
|
||||||
|
]) /* end E() in L() */ ,
|
||||||
|
0) /* end L() */;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int cka, char **k) { char *ck = (char *)cka;
|
||||||
|
exit(
|
||||||
|
E((ck
|
||||||
|
?main((z?
|
||||||
|
(stat(M,&t)?
|
||||||
|
P+=a+'{'?0
|
||||||
|
:3
|
||||||
|
:execv(M,k),
|
||||||
|
|
||||||
|
a=(signed char)
|
||||||
|
E(
|
||||||
|
*L(P++,0)
|
||||||
|
),
|
||||||
|
i=P,
|
||||||
|
y=(signed char)
|
||||||
|
E(
|
||||||
|
*L(P++,0)
|
||||||
|
)&255,
|
||||||
|
sprintf(Q,y/'@'-3?"*L(V(%d+%d)+%d,0)":"R[%d]",(y&7),'\r',y/0100-1?0
|
||||||
|
:
|
||||||
|
(signed char)E(
|
||||||
|
*L(P++,0)
|
||||||
|
)),
|
||||||
|
(a+127 &&
|
||||||
|
a+'}' &&
|
||||||
|
a+1 ?
|
||||||
|
(a+61 &&
|
||||||
|
a + 24 &&
|
||||||
|
a +
|
||||||
|
025 ?
|
||||||
|
(P=a+'H' &&
|
||||||
|
a%061 <=0 ?
|
||||||
|
P :i ,
|
||||||
|
d += sprintf
|
||||||
|
(d,a>0 ?
|
||||||
|
" R[%d]=E(~-E(R[%d])),\0 U R[%d],\0 R[%d] O,\0 U %d,\0R[%d]=0,"+(a&'8')*3:a <- 'c'?" %d, %c%s = R[%d], \0 %d, *R=%c%s==R[%d], \0 R[%d]=(int)%c%s,"-a%'w'%'j'*5:"%d,%d,%s=%d,",
|
||||||
|
a>0 ?
|
||||||
|
a-'h' ?
|
||||||
|
a-49 ?
|
||||||
|
a&7 :
|
||||||
|
(y/010&7)
|
||||||
|
:(P +=4,
|
||||||
|
*L(P-4,0)
|
||||||
|
):(y/010&7),
|
||||||
|
a>0 ?
|
||||||
|
a&7 :
|
||||||
|
"& "[a%3%2+1],
|
||||||
|
a + 72 ?
|
||||||
|
Q :
|
||||||
|
"*R", a>0 | a<-99 ?
|
||||||
|
(y/010&7) :
|
||||||
|
(P+=4,
|
||||||
|
*L(P-4,0)),
|
||||||
|
0)
|
||||||
|
|
||||||
|
,(char*)P) :
|
||||||
|
(P=i,
|
||||||
|
i = a + 61 ?
|
||||||
|
a +21?
|
||||||
|
E((P+=4,
|
||||||
|
*L(P-4,0))) :
|
||||||
|
(signed char) E(
|
||||||
|
*L(P++,0)) :
|
||||||
|
0,
|
||||||
|
d += sprintf( d,a%' '+29+"P O,\0 U %d,P=%d,"
|
||||||
|
, P,
|
||||||
|
P+i,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0),
|
||||||
|
|
||||||
|
(char* )P,
|
||||||
|
system((
|
||||||
|
sprintf
|
||||||
|
(d,
|
||||||
|
"A'",
|
||||||
|
k[1]),
|
||||||
|
b)
|
||||||
|
),
|
||||||
|
z)
|
||||||
|
) :
|
||||||
|
(n =
|
||||||
|
(y/010&7) - 4
|
||||||
|
? (y/010&7)%
|
||||||
|
5-1 ?
|
||||||
|
a+127 ?
|
||||||
|
(signed char)E(
|
||||||
|
*L(P++,0)) :
|
||||||
|
(P+=4,
|
||||||
|
*L(P-4,0)
|
||||||
|
) : 0 :
|
||||||
|
(Scan(),
|
||||||
|
*(
|
||||||
|
(char*)index
|
||||||
|
(ss+
|
||||||
|
V(i ),
|
||||||
|
0100) ?
|
||||||
|
(char*) index (ss+
|
||||||
|
V(i ),
|
||||||
|
0100) : d) =
|
||||||
|
0,
|
||||||
|
(int) (ss+
|
||||||
|
V(i)
|
||||||
|
)),
|
||||||
|
(y/010&7) %
|
||||||
|
5<2 ?
|
||||||
|
d += sprintf(d,
|
||||||
|
(y/010&7) %
|
||||||
|
5
|
||||||
|
?" %s=E(~-E(%s)), \0 U %s," +
|
||||||
|
4*
|
||||||
|
(y/010&7):
|
||||||
|
"%s=E(E(%s)%c%d),",
|
||||||
|
Q,
|
||||||
|
Q,
|
||||||
|
"+ - "[(y/010&7)],
|
||||||
|
n,
|
||||||
|
0),
|
||||||
|
|
||||||
|
|
||||||
|
(char* )P :
|
||||||
|
( a= (signed char)E(
|
||||||
|
*L(P++,0) /* end *L() */
|
||||||
|
) /* end E */ -
|
||||||
|
'u' ?
|
||||||
|
'!' :
|
||||||
|
'=',
|
||||||
|
d +=
|
||||||
|
sprintf(d,
|
||||||
|
(y/010&7)
|
||||||
|
- 4
|
||||||
|
? "P=%d%c=%s?%d:%d,":
|
||||||
|
"*R=E(((int(*)(l,l,l))%s)(K(1),K(2),K(3))),P O,"
|
||||||
|
,n,a,Q,P,P+
|
||||||
|
(signed char)E(
|
||||||
|
*L(P++,0) /* end *L() */
|
||||||
|
) /* end E */
|
||||||
|
) /* end sprintf */
|
||||||
|
|
||||||
|
,(char* ) P,
|
||||||
|
system(
|
||||||
|
(sprintf (d,
|
||||||
|
"A'",
|
||||||
|
k[1]
|
||||||
|
),
|
||||||
|
b)) /* end system */
|
||||||
|
,z))))
|
||||||
|
:
|
||||||
|
(Run
|
||||||
|
((z=(char*)&ck,stat(k[1],&t),B=(int*)mmap(0,i=t.st_size,3,1,open(k[1],2),0))
|
||||||
|
) /* end Run() */
|
||||||
|
,((
|
||||||
|
(B+13)[4] =
|
||||||
|
E(B+i/4) /* end E() */
|
||||||
|
,run(), /* end run() */
|
||||||
|
P=V(-~i), /* end V() */
|
||||||
|
(B+13)[4] =
|
||||||
|
E (
|
||||||
|
V(17) /* end V() */
|
||||||
|
-4
|
||||||
|
), /* end E() */
|
||||||
|
*(int*)
|
||||||
|
V(021) /* end V() */
|
||||||
|
= 0)),
|
||||||
|
sprintf(M,
|
||||||
|
".%s%d",k[1],
|
||||||
|
P) /* end sprintf() */,
|
||||||
|
d +=
|
||||||
|
sprintf(d,"%s %s '-DX=A(%s)' -o %s '-Dmagic=","cpp -std=gnu99 -Wall -Wextra -pedantic -Winfinite-recursion -Wno-bitwise-conditional-parentheses -Wno-error -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-to-pointer-cast -Wno-macro-redefined -Wno-pedantic -Wno-pointer-to-int-cast -Wno-return-type -Wno-string-plus-int -Wno-bitwise-op-parentheses -Wno-format -Wno-format-extra-args -Wno-int-conversion -Wno-unused-parameter -Wno-unsequenced -ggdb3 -E \"-DA(X)=#X\"","anonymous.c","cpp -std=gnu99 -Wall -Wextra -pedantic -Winfinite-recursion -Wno-bitwise-conditional-parentheses -Wno-error -Wno-implicit-function-declaration -Wno-implicit-int -Wno-int-to-pointer-cast -Wno-macro-redefined -Wno-pedantic -Wno-pointer-to-int-cast -Wno-return-type -Wno-string-plus-int -Wno-bitwise-op-parentheses -Wno-format -Wno-format-extra-args -Wno-int-conversion -Wno-unused-parameter -Wno-unsequenced -ggdb3 -E \"-DA(X)=#X\"",
|
||||||
|
M,
|
||||||
|
fflush(0)
|
||||||
|
) /* end sprintf() */
|
||||||
|
|
||||||
|
,(char* )P)
|
||||||
|
),k):
|
||||||
|
system(
|
||||||
|
(sprintf(M,
|
||||||
|
"rm -f .%s*",
|
||||||
|
k[1]),
|
||||||
|
M)/* end sprintf() in system() */
|
||||||
|
),z,*(B+13)
|
||||||
|
) /* end ck?main()... in exit() */
|
||||||
|
) /* end E() in exit() */
|
||||||
|
); /* end exit() */
|
||||||
|
} /* end main() */
|
||||||
@@ -1042,34 +1042,80 @@ might or might not help but he too could not get it to work.
|
|||||||
|
|
||||||
Tips from Cody:
|
Tips from Cody:
|
||||||
|
|
||||||
- Try a beautifier on the original C code.
|
|
||||||
- Use cpp to make the functions easier to parse. For instance if you're in the
|
|
||||||
directory try `cpp -E anonymous.c > anonymous.cpp` and look at that file to see
|
|
||||||
the functions. It might or might not be helpful to use cpp on the beautified
|
|
||||||
source.
|
|
||||||
- After beautifying it try changing references of the macros (where not too
|
|
||||||
complicated) to their definitions. For instance in vim you might do:
|
|
||||||
`:%s/\<l\>/int */g` and then delete the line that was changed to `#define int *
|
|
||||||
int*` (or else do a range substitute so it's not changed). You might not need
|
|
||||||
this if you use the cpp. This might be useful anyway to more easily test things.
|
|
||||||
- If your system has a `setarch` tool that might or might not be of help (I'm
|
|
||||||
not too familiar with its internals).
|
|
||||||
- The code appears to do everything from one call to `exit(3)` but it makes use
|
|
||||||
of the ternary operator and possibly the comma operator.
|
|
||||||
- Check the Makefile for the defines but also observe that those are in the
|
|
||||||
source file. It appears that the entry might try compiling as well but that's
|
|
||||||
from a quick glance.
|
|
||||||
- The original main() started like: `main (char *ck, char **k)` but we made it
|
- The original main() started like: `main (char *ck, char **k)` but we made it
|
||||||
compilable for clang by changing it to be: `main (int cka, char **k) { char *ck
|
compilable for clang by changing it to be: `main (int cka, char **k) { char *ck
|
||||||
= (char *)cka;` which might or might not be good.
|
= (char *)cka;` which might or might not be good.
|
||||||
|
|
||||||
|
- `gcc` reports an infinite recursive call of `main()`. My (Cody's) guess is
|
||||||
|
that this is the root of the problem of the crash but it might be other things.
|
||||||
|
I'm not sure how to stop this from happening. This happens before and after the
|
||||||
|
above fix for `clang`!
|
||||||
|
|
||||||
|
- Try a beautifier on the original C code. This might or might not work; see
|
||||||
|
next point.
|
||||||
|
|
||||||
|
- Use `cpp -E` (see [cpp.c](2001/anonymous/cpp.c)) and clean it up first. I
|
||||||
|
(Cody) did this for convenience though there are still macros. This is because
|
||||||
|
it was done via a hackish make rule:
|
||||||
|
|
||||||
|
cpp: ${PROG}.c
|
||||||
|
@echo "NOTE: this entry seems to no longer work."
|
||||||
|
magic='cpp ${CFLAGS} -E'; \
|
||||||
|
X='-DA(X)=#X'; \
|
||||||
|
$$magic -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
||||||
|
$< ${LIBS} > anonymous.cpp.c
|
||||||
|
|
||||||
|
|
||||||
|
- (If beautifying) After beautifying it try changing references of the macros
|
||||||
|
(where not too complicated) to their definitions. For instance in vim you might
|
||||||
|
do: `:%s/\<l\>/int */g` and then delete the line that was changed to `#define
|
||||||
|
int * int*` (or else do a range substitute so it's not changed). You might not
|
||||||
|
need this if you use the cpp. This might be useful anyway to more easily test
|
||||||
|
things.
|
||||||
|
|
||||||
|
- If your system has a `setarch` tool that might or might not be of help (I'm
|
||||||
|
not too familiar with its internals).
|
||||||
|
|
||||||
|
- The code appears to do everything from one call to `exit(3)` but it makes use
|
||||||
|
of the ternary operator and possibly the comma operator Check the Makefile for
|
||||||
|
the defines but also observe that those are in the source file. It appears that
|
||||||
|
the entry might try compiling as well but that's from a quick glance.
|
||||||
|
|
||||||
- The author warns that only simple source (once compiled) would work so make
|
- The author warns that only simple source (once compiled) would work so make
|
||||||
use of the provided source file
|
use of the provided source file
|
||||||
[2001/anonymous/anonymous.ten.c](2001/anonymous/anonymous.ten.c). To compile try
|
[2001/anonymous/anonymous.ten.c](2001/anonymous/anonymous.ten.c). To compile try
|
||||||
`make anonymous.ten` from the entry directory which you can then run the entry
|
`make anonymous.ten` from the entry directory which you can then run the entry
|
||||||
on. Note that it needs to be compiled as a x86 program.
|
on. Note that it needs to be compiled as a x86 program.
|
||||||
- The program will to an extent destroy files it is used on. See the author's
|
|
||||||
warning in their comments on that.
|
|
||||||
|
|
||||||
|
- The `Tr` macro appears (at a glance when very tired) to create another
|
||||||
|
function and when C pre-processed it seems like at least the function `L()` is
|
||||||
|
there twice. However this is actually a bit different: one is `L##i()` and the
|
||||||
|
other is `L()`. `L##i()` calls itself and `L()` calls `L##i()`. You might have luck
|
||||||
|
renaming it e.g. `Li()` instead but I (Cody) had some problems renaming some of
|
||||||
|
these functions (some but not all).
|
||||||
|
|
||||||
|
- Pray, cast a spell or just wish yourself good luck, depending on your
|
||||||
|
beliefs/personality/whatever! :-) It seems you'll need it! :-) (and also :-( )
|
||||||
|
|
||||||
|
Here are some additional warnings on different platforms:
|
||||||
|
|
||||||
|
```c
|
||||||
|
anonymous.c:12:13: warning: operation on 'P' may be undefined [-Wsequence-point]
|
||||||
|
#define I (P+=4,*L(P-4,0))
|
||||||
|
^
|
||||||
|
```
|
||||||
|
|
||||||
|
With `gdb` I determined that in the function `Runi()` appears to be NULL. I'm
|
||||||
|
not sure if this is relevant or not.
|
||||||
|
|
||||||
|
With `gdb` it appears that the crash happens with:
|
||||||
|
|
||||||
|
```
|
||||||
|
V (v@entry=<optimized out>) at anonymous.c:44
|
||||||
|
44 return E (B[v]);
|
||||||
|
```
|
||||||
|
|
||||||
|
(see [cpp.c](cpp.c)).
|
||||||
|
|
||||||
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md))
|
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md))
|
||||||
## STATUS: probable bug (possibly depending on system) - please help test and if necessary fix
|
## STATUS: probable bug (possibly depending on system) - please help test and if necessary fix
|
||||||
@@ -1229,13 +1275,16 @@ it. [Yusuke Endoh](/winners.html#Yusuke_Endoh) [wrote a little bit about
|
|||||||
it](https://mame-github-io.translate.goog/ioccc-ja-spoilers/2001/anonymous.html?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp) that
|
it](https://mame-github-io.translate.goog/ioccc-ja-spoilers/2001/anonymous.html?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp) that
|
||||||
might or might not help but he too could not get it to work.
|
might or might not help but he too could not get it to work.
|
||||||
|
|
||||||
Tips from Cody:
|
WARNING: the program will to an extent destroy files it is used on! See the
|
||||||
|
author's warning in their comments on that.
|
||||||
|
|
||||||
|
Some tips from Cody:
|
||||||
|
|
||||||
- Try a beautifier on the original C code.
|
- Try a beautifier on the original C code.
|
||||||
- Use cpp to make the functions easier to parse. For instance if you're in the
|
- Use cpp to make the functions easier to parse. For instance if you're in the
|
||||||
directory try `cpp -E anonymous.c > anonymous.cpp` and look at that file to see
|
directory try `cpp -E anonymous.c > anonymous.cpp` and look at that file to see
|
||||||
the functions. It might or might not be helpful to use cpp on the beautified
|
the functions. It might or might not be helpful to use cpp on the beautified
|
||||||
source.
|
source. `cc -E` might or might not be useful as well.
|
||||||
- After beautifying it try changing references of the macros (where not too
|
- After beautifying it try changing references of the macros (where not too
|
||||||
complicated) to their definitions. For instance in vim you might do:
|
complicated) to their definitions. For instance in vim you might do:
|
||||||
`:%s/\<l\>/int */g` and then delete the line that was changed to `#define int *
|
`:%s/\<l\>/int */g` and then delete the line that was changed to `#define int *
|
||||||
@@ -1243,21 +1292,34 @@ int*` (or else do a range substitute so it's not changed). You might not need
|
|||||||
this if you use the cpp. This might be useful anyway to more easily test things.
|
this if you use the cpp. This might be useful anyway to more easily test things.
|
||||||
- If your system has a `setarch` tool that might or might not be of help (I'm
|
- If your system has a `setarch` tool that might or might not be of help (I'm
|
||||||
not too familiar with its internals).
|
not too familiar with its internals).
|
||||||
- The code appears to do everything from one call to `exit(3)` but it makes use
|
- The code appears to do everything from one call to `exit(3)` which actually
|
||||||
of the ternary operator and possibly the comma operator.
|
calls `main()` itself (is this part of the problem? We don't know) but it makes
|
||||||
|
use of the ternary operator and possibly the comma operator (hard to parse
|
||||||
|
without much formatting that's not been done).
|
||||||
- Check the Makefile for the defines but also observe that those are in the
|
- Check the Makefile for the defines but also observe that those are in the
|
||||||
source file. It appears that the entry might try compiling as well but that's
|
source file. It appears that the entry might try compiling as well but that's
|
||||||
from a quick glance.
|
from a quick glance.
|
||||||
- The original main() started like: `main (char *ck, char **k)` but we made it
|
- The original `main()` started like: `main (char *ck, char **k)` but we (Landon
|
||||||
compilable for clang by changing it to be: `main (int cka, char **k) { char *ck
|
and Cody both had the same idea but Landon made the commit before Cody could)
|
||||||
= (char *)cka;` which might or might not be good.
|
made it compilable for clang by changing it to be: `main (int cka, char **k) {
|
||||||
|
char *ck = (char *)cka;` which might or might not be good.
|
||||||
- The author warns that only simple source (once compiled) would work so make
|
- The author warns that only simple source (once compiled) would work so make
|
||||||
use of the provided source file
|
use of the provided source file
|
||||||
[2001/anonymous/anonymous.ten.c](2001/anonymous/anonymous.ten.c). To compile try
|
[2001/anonymous/anonymous.ten.c](2001/anonymous/anonymous.ten.c) that Cody bug
|
||||||
`make anonymous.ten` from the entry directory which you can then run the entry
|
fixed (which is necessary for it to work). To compile try `make anonymous.ten`
|
||||||
on. Note that it needs to be compiled as a x86 program.
|
from the entry directory which you can then run the entry on. Note that it needs
|
||||||
- The program will to an extent destroy files it is used on. See the author's
|
to be compiled as a x86 program so the Makefile uses `-m32`. This will likely
|
||||||
warning in their comments on that.
|
not work in macOS as Apple has unfortunately made it very hard to compile 32-bit
|
||||||
|
code. With Apple's silicon chip it will be impossible as the architecture is
|
||||||
|
entirely incompatible. We don't know if the original program needs to be 32-bit
|
||||||
|
compiled nowadays but since the author said it can run on other platforms we
|
||||||
|
have **NOT** made it use `-m32`. We give instructions on how to compile
|
||||||
|
[anonymous.ten](2001/anonymous/anonymous.ten.c) without specifying 32-bit, in
|
||||||
|
the Makefile, when trying to compile it.
|
||||||
|
|
||||||
|
Cody also recommends that one try breaking apart the `exit()` called in `E`
|
||||||
|
which calls `main()` call and if possible breaking `main()` into more than one
|
||||||
|
function (this might not be possible) into several.
|
||||||
|
|
||||||
|
|
||||||
## [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