Update 2001/anonymous - cpp, 32-bit ELF ten.c etc.
Add back cpp.c which is a C pre-processed version of anonymous.c. Added comments and tried to format it some. Perhaps I should use a formatted / de-obfuscator from some years ago in the IOCCC (by Dave Burton) but I didn't think of that until much later on: I'll consider it another time. The Makefile builds cpp by default. Works as well as anonymous.c: will modify 32-bit ELF binaries in the right systems (it won't touch them in macOS - I pre-compiled anonymous.ten.c as 32-bit ELF in linux and added it to the repo as anonymous.ten.32 mostly for those who might be able to run 32-bit ELF binaries but have no way to compile them though maybe no system has that but it also allows for partly 'testing' the program in macOS). Change main target to compile to anonymous and not anonymous_tmp. This is because otherwise running make would repeatedly try and build it. I did try changing the target but that didn't want to work possibly due to the cp updating the timestamp though that's a quick thought in the head of someone who's been awake too long at the hour. Instead anonymous.sh is the script to run to 'emulate' the running of the target program (again assuming that's correct which does seem likely but is still unconfirmed). The anonymous.sh script now checks for compiling anonymous.ten.c but uses anonymous.ten.32 as a backup if it exists. Update bugs.md and README.md. Anything else I'm afraid I've forgotten.
This commit is contained in:
1 parent
0571930501
commit
31fef7fa43
7 files changed
+464
-40
No files matched your search
+13
-4
@@ -117,9 +117,9 @@ PROG= ${ENTRY}
|
||||
#
|
||||
OBJ= ${PROG}.o
|
||||
DATA=
|
||||
TARGET= ${PROG} ${PROG}.ten
|
||||
TARGET= ${PROG} cpp ${PROG}.ten
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
|
||||
|
||||
@@ -139,8 +139,8 @@ ${PROG}: ${PROG}.c
|
||||
X='-DA(X)=#X'; \
|
||||
warning='-Dprocessor'; \
|
||||
$$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
||||
$< -o $@_tmp ${LIBS}
|
||||
${CP} -af anonymous.sh $@
|
||||
$< -o $@ ${LIBS}
|
||||
${CHMOD} -v +x anonymous.sh
|
||||
|
||||
|
||||
${PROG}.ten: ${PROG}.ten.c
|
||||
@@ -157,6 +157,15 @@ ${PROG}.ten: ${PROG}.ten.c
|
||||
@echo
|
||||
${CC} ${CFLAGS} -m32 $< -o $@ ${LIBS}
|
||||
|
||||
cpp: cpp.c
|
||||
magic='${CC} ${CFLAGS}'; \
|
||||
X='-DA(X)=#X'; \
|
||||
warning='-Dprocessor'; \
|
||||
$$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \
|
||||
$< -o $@ ${LIBS}
|
||||
${CHMOD} -v +x anonymous.sh
|
||||
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: data ${ALT_TARGET}
|
||||
|
||||
@@ -16,10 +16,10 @@ make
|
||||
```
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed both the
|
||||
supplementary program and the program itself, both of which segfaulted. He
|
||||
managed to do this with linux but it will not work with macOS (see
|
||||
[bugs.md](/bugs.md) for why this is); this is not a bug but a feature inherent
|
||||
in what it does.
|
||||
supplementary program and the program itself (but for the program itself see
|
||||
[bugs.md](/bugs.md), both of which segfaulted. He managed to do this with linux
|
||||
but it will not work with macOS (see [bugs.md](/bugs.md) for why this is); this
|
||||
is not a bug but a feature inherent in what it does.
|
||||
|
||||
Although it took a fair bit of debugging it turns out all that
|
||||
needed to be changed was:
|
||||
@@ -30,8 +30,9 @@ prevented `main()` from entering an infinite loop.
|
||||
|
||||
Without either of these it would crash and prevent modification of the 32-bit
|
||||
[ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) (not elf :-)
|
||||
) binary. The following change was also made to be more portable, in case the
|
||||
constants `PROT_READ` and/or `PROT_WRITE` are not standardised:
|
||||
) binary. But again see [bugs.md](/bugs.md) here. The following change was also
|
||||
made to be more portable, in case the constants `PROT_READ` and/or `PROT_WRITE`
|
||||
are not standardised:
|
||||
|
||||
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
|
||||
@@ -60,9 +61,11 @@ The author suggested that this will somewhat destroy the binaries this touches
|
||||
but Cody did not observe this. It does indeed modify the files as the script
|
||||
below will show you (though not all files are modified: can you figure out why
|
||||
that is?) but Cody did not notice any problems in using them. Perhaps it's
|
||||
something he's not aware of. If you follow the try commands below you will
|
||||
notice that although the binaries do differ it's not many differences. See the
|
||||
author's warning about this.
|
||||
something he's not aware of possibly including the fact that the modification
|
||||
might or might not be complete. If you follow the try commands below you will
|
||||
notice that although the binaries do differ it's not many differences and the
|
||||
output of the supplementary program both before and after is the same. See the
|
||||
author's warning about this in their remarks.
|
||||
|
||||
### INABIAF - it's not a bug it's a feature! :-)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ fi
|
||||
make >/dev/null 2>&1
|
||||
|
||||
if [[ -f "$1" ]]; then
|
||||
./anonymous_tmp "$1"
|
||||
./anonymous "$1"
|
||||
./"$1"
|
||||
fi
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,383 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <sys/mman.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
|
||||
pain(char *ck, char **k)
|
||||
{
|
||||
return (z ?
|
||||
(stat(M,&t) ?
|
||||
P+= a+'{' ?
|
||||
0 : 3
|
||||
: execv(M,k), /* note: M appears to be empty here but this used to be recursive main()
|
||||
so M might have been modified on additional calls */
|
||||
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))
|
||||
), /* ends sprintf() on line 175 */
|
||||
(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 ) /* end sprintf on line 195 */
|
||||
,(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 ), /* ends sprintf() on 242 */
|
||||
(char* ) P,
|
||||
system(
|
||||
(sprintf(d,"A'",k[1]),
|
||||
b) /* sprintf IN system() on line 252 (above line) */
|
||||
) /* ends system on 252 */
|
||||
,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 ), /* V(i ) in index from line 274 */
|
||||
0100)/*ends index() on line 274 */
|
||||
?(char*)index(ss +
|
||||
V(i ), /* V(i) in index() on line 277 */
|
||||
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 ) /* ends sprintf() on line 288 */
|
||||
,(char* ) P
|
||||
:
|
||||
(a=(signed char) E(
|
||||
*L(P++,0) /* *L() in E() from line 301 */
|
||||
) /* ends E() on line * 301 */
|
||||
-'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) /* *L() in E() in sprintf() from line 308 */
|
||||
)
|
||||
) /* ends sprintf() on line 308 */
|
||||
|
||||
,(char* ) P,
|
||||
system(
|
||||
(sprintf(d,"A'",k[1]), /* ends sprintf() in system() on line 323 */
|
||||
b)) /* ends system() on line 323 but appears that b is what's system()d */
|
||||
,z)
|
||||
)
|
||||
)
|
||||
)
|
||||
:
|
||||
(Run(
|
||||
(z=(char*)&ck,
|
||||
stat(k[1],&t), /* stat() in Run() on line 331 */
|
||||
B =
|
||||
(l)mmap(0,i=t.st_size,PROT_READ|PROT_WRITE,1,
|
||||
open(k[1],2),0) /* open() in mmap() (line 325) in Run() (line 331 */
|
||||
)
|
||||
), /* ends Run() on line 331 */
|
||||
(((B+13)[4]
|
||||
=
|
||||
E(B+i/4),
|
||||
run(),
|
||||
P = V(-~i),
|
||||
(B+13)[4] =
|
||||
E(
|
||||
V(17)- /* V() in E() on line 345 */
|
||||
4),*(int*)V(021))), /* second V() in E() on line 345 */
|
||||
sprintf(M,
|
||||
".%s%d",k[1],P), /* ends sprintf() on line 348 */
|
||||
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 -E \"-DA(X)=#X\"", /* end first string in sprintf() %s from line 350 */
|
||||
|
||||
"anonymous.c", /* second string in sprintf() on line 350.
|
||||
note it appears to run the above cpp on 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 -E \"-DA(X)=#X\"",
|
||||
/* above line is third string in sprintf() on line 350 */
|
||||
M, /* fourth string in sprintf() on 350, possibly running cpp from above line on M */
|
||||
fflush(0) ), /* end sprintf() on line 350 */
|
||||
(char* ) P) /* ends Run() on line 331 */
|
||||
);
|
||||
|
||||
}
|
||||
int
|
||||
main (int cka, char **k)
|
||||
{
|
||||
char *ck = (char *)cka;
|
||||
|
||||
/* main calls exit() which calls E() which has a call to pain() if
|
||||
ck ((char *)cka - was originally a char * as first arg to main()) with
|
||||
second arg being argv or k. Otherwise it calls system() with a convoluted sprintf() */
|
||||
exit (E(
|
||||
(ck?pain((char*)cka,k): /* if ck ((char *)argc which used to be a char *) run pain() which used to be main() */
|
||||
system( /* otherwise if !ck call system() with ... */
|
||||
(sprintf(M,"rm -f .%s*",k[1]),M) /* sprintf() writing to M a convoluted string including itself (which
|
||||
iirc is undefined but perhaps it's my tiredness: I can't think of what
|
||||
the '*' does in sprintf()) */
|
||||
), /* ends system() from line 374 */
|
||||
z,*(B+13))) /* end E() which calls either pain() or system() (which calls sprintf() on M) from line 372 from exit() on line 372 */
|
||||
|
||||
);
|
||||
|
||||
} /* end main() */
|
||||
+22
-15
@@ -2,30 +2,37 @@
|
||||
|
||||
make clobber all >/dev/null 2>&1
|
||||
|
||||
if [[ -f "anonymous.ten" ]]; then
|
||||
|
||||
make anonymous 2>/dev/null
|
||||
echo "$ cp anonymous.ten anonymous.ten.bak" 1>&2
|
||||
cp anonymous.ten anonymous.ten.bak
|
||||
echo "$ ./anonymous anonymous.ten" 1>&2
|
||||
./anonymous anonymous.ten
|
||||
echo "$ ./anonymous.ten" 1>&2
|
||||
./anonymous.ten
|
||||
echo "$ diff -s anonymous.ten anonymous.ten.bak" 1>&2
|
||||
diff -s anonymous.ten anonymous.ten.bak
|
||||
echo "$ od -t x1 anonymous.ten > ten.od" 1>&2
|
||||
od -t x1 anonymous.ten > ten.od
|
||||
TARGET="anonymous.ten"
|
||||
|
||||
if [[ ! -f "$TARGET" ]]; then
|
||||
TARGET="anonymous.ten.32"
|
||||
echo "cannot compile anonymous.ten.c as 32-BIT, trying anonymous.ten.32 as backup"
|
||||
echo "if your system cannot run 32-bit ELF binaries this might fail"
|
||||
fi
|
||||
|
||||
if [[ -f "$TARGET" ]]; then
|
||||
echo "$ cp $TARGET anonymous.ten.bak" 1>&2
|
||||
cp "$TARGET" anonymous.ten.bak
|
||||
echo "$ ./anonymous $TARGET" 1>&2
|
||||
./anonymous.sh "$TARGET"
|
||||
echo "$ ./$TARGET" 1>&2
|
||||
./"$TARGET"
|
||||
echo "$ diff -s $TARGET anonymous.ten.bak" 1>&2
|
||||
diff -s "$TARGET" anonymous.ten.bak
|
||||
echo "$ od -t x1 $TARGET > ten.od" 1>&2
|
||||
od -t x1 "$TARGET" > ten.od
|
||||
echo "$ od -t x1 anonymous.ten.bak > ten.bak.od" 1>&2
|
||||
od -t x1 anonymous.ten.bak > ten.bak.od
|
||||
echo "$ diff ten.bak.od ten.od" 1>&2
|
||||
diff ten.bak.od ten.od
|
||||
echo "$ ./anonymous.ten > ten.txt" 1>&2
|
||||
./anonymous.ten > ten.txt
|
||||
echo "$ ./$TARGET > ten.txt" 1>&2
|
||||
./"$TARGET" > ten.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 "cannot compile anonymous.ten.c as 32-bit, sorry."
|
||||
echo "cannot compile anonymous.ten.c as 32-bit and backup file does not exist, sorry."
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user