Note that 2001/bellard only works for i386 linux

The author stated this directly. It is noted in the bugs.md file and the
README.

I also included a suggested change by Yusuke Endoh. This is not
necessary for compilers that support -Wl,-z,execstack but not all
compilers do (though the only one I've found that has this problem is
macOS which it won't work under anyway just like -m32 won't which we
also now use).

Added the 'more portable' version by the author. This does not compile
at least under 64-bit linux (not macOS either though of course it
wouldn't work in macOS as if you look at the code you see hardcoded
paths for linux ld-linux.so).

I note that there's a de-obfuscated version on the author's page for the
entry which might give some clues. I might look at it in the future but
it appears that unless someone can provide a 64-bit linux version this
will be one of the entries (now far fewer with many fixes made) that
simply no longer work.

This thus completes for now 2001/bellard even with disappointing
circumstances.
This commit is contained in:
Cody Boone Ferguson committed 2023-04-22 09:11:15 -07:00
1 parent 82ac1237fa
commit 0d0c2c4250
6 files changed
+680 -19

No files matched your search

+1
View File
@@ -1,2 +1,3 @@
bellard
bellard.otccex
otccelf
+3 -3
View File
@@ -38,7 +38,7 @@ include ../../var.mk
# Common C compiler warnings to silence
#
CSILENCE= #-Wno-bitwise-op-parentheses -Wno-error -Wno-implicit-function-declaration \
CSILENCE= -Wno-bitwise-op-parentheses -Wno-error -Wno-implicit-function-declaration \
-Wno-implicit-int -Wno-int-conversion -Wno-int-to-pointer-cast \
-Wno-parentheses -Wno-return-type
@@ -55,7 +55,7 @@ CSTD= -std=gnu99
# Some entries require 32-bitness: ARCH= -m32
# Some entries require 64-bitness: ARCH= -m64
#
ARCH=
ARCH= -m32
# Defines that are needed to compile
#
@@ -71,7 +71,7 @@ OPT= -O3
# Default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} -rdynamic
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} -rdynamic -fno-pie
# Libraries needed to build
#
+24 -11
View File
@@ -19,17 +19,30 @@ make
```
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) partially fixed this
but he notes that this will not work without some possibly serious debugging. As
it is it segfaults. He fixed an earlier segfault so that at least the file can
be opened and he also changed some of the macro uses to what they expanded to
but mostly he kept it the same. He also fixed
[bellard.otccex.c](bellard.otccex.c) so it does not
segfault and seemingly works okay (it did not work at all). The author stated
that they used [gcc
but he notes that this will not work without (according to the author) i386
linux or else some skill in resolving the portability issues. As it is it
segfaults in 64-bit linux (and as expected macOS). He fixed an earlier segfault
so that at least the file can be opened (but perhaps that will be wrong in i386
linux?) and he also changed some of the macro used to what they evaluate to but
mostly he kept it the same. He also fixed [bellard.otccex.c](bellard.otccex.c)
so it does not segfault and seemingly works okay (it did not work at all) but
still this appears to not work in 64-bit linux. See below portability notes.
Thank you Cody for your assistance!
### Portability notes:
With a tip from [Yusuke Endoh](/winners.html#Yusuke_Endoh) we rediscovered the
author's [web page for this program](https://bellard.org/otcc/) where it is
stated that this will only work in i386 linux. The author also stated in the
remarks in this document that they used that they used [gcc
2.95.2](https://ftp.gnu.org/gnu/gcc/gcc-2.95.2/gcc-everything-2.95.2.tar.gz) but
we don't know if that's relevant or not. Thank you Cody for your assistance! Can
you fix the entry? We welcome your help! If you can please look at
[bugs.md](/bugs.md) for more information. Thank you!
we don't know if that's relevant or not.
Yusuke offered a modification which is not needed with gcc but with some
versions of `clang` it is. With `gcc` we can get away with `-rdynamic -fno-pie
-Wl,-z,execstack` which solves the problem of execution in memory but any
compiler that does not support this would not work. Thus we use the modification
by Yusuke. Thank you Yusuke!
## Try:
@@ -40,7 +53,7 @@ you fix the entry? We welcome your help! If you can please look at
## Judges' remarks:
<JUDGES_COMMENTS> :-)
\<JUDGES_COMMENTS\> :-)
## Author's remarks:
+3 -1
View File
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/mman.h>
#define k *(int*)
#define a if(
#define c ad()
@@ -8,7 +10,7 @@
#define p while(
#define x *(char*)
#define b ==
#define V =calloc(1,99999)
#define V =mmap(NULL, 99999, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)
#define f ()
#define J return
#define l ae(
+621
View File
@@ -0,0 +1,621 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/mman.h>
#define r *(char*)
#define b if(
#define t *(int*)
#define k else
#define u while(
#define g av()
#define c ax(
#define f ==
#define aj =mmap(NULL, 99999, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)
#define j ()
#define O return
#define l a)
#define A int
#define n 0)
#define o aw(
#define p 1)
#define q s)
A e,C,J,m,T,U,K,v,P,i,ak,Q,D,V,al,Z,G,R,y;
L(l{
r D++=a;
}
w j{
b V){
m=r V++;
b m f 2){
V=0;
m=al;
}
}
k m=fgetc(ak);
}
am j{
O isalnum(m)|m f 95;
}
an j{
b m f 92){
w j;
b m f 110)m=10;
}
}
g{
A a,s,h;
u isspace(m)|m f 35){
b m f 35){
w j;
g;
b e f 536){
g;
L(32);
t e=1;
t(e+4)=D;
}
u m!=10){
L(m);
w j;
}
L(m);
L(2);
}
w j;
}
J=0;
e=m;
b am j){
L(32);
Z=D;
u am j){
L(m);
w j;
}
b isdigit(e)){
C=strtol(Z,0,n;
e=2;
}
k{
r D=32;
e=strstr(Q,Z-p-Q;
r D=0;
e=e*8+256;
b e>536){
e=T+e;
b t e f p{
V=t(e+4);
al=m;
w j;
g;
}
}
}
}
k{
w j;
b e f 39){
e=2;
an j;
C=m;
w j;
w j;
}
k b e f 47&m f 42){
w j;
u m){
u m!=42)w j;
w j;
b m f 47)m=0;
}
w j;
g;
}
k{
a="++#m--%am*@R<^1c/@%[_[H3c%@%[_[H3c+@.B#d-@%:_^BKd<<Z/03e>>`/03e<=0f>=/f<@.f>@1f==&g!='g&&k||#l&@.BCh^@.BSi|@.B+j~@/%Yd!@&d*@b";
u s=r a++){
h=r a++;
C=0;
u(J=r a++-98)<n C=C*64+J+64;
b s f e&(h f m|h f 64)){
b h f m){
w j;
e=1;
}
break;
}
}
}
}
}
o d){
u d&&d!=-p{
r v++=d;
d=d>>8;
}
}
E(a,d){
r a++=d;
r a++=d>>8;
r a++=d>>16;
r a++=d>>24;
}
ao(l{
A d;
return(r a&255)|(r(a+p&255)<<8|(r(a+2)&255)<<16|(r(a+3)&255)<<24;
}
ap(a,z){
A d;
u l{
d=ao(l;
b r(a-p f 5){
b z>=G&&z<i)E(a,z+y);
k E(a,z-K+R+y);
}
k{
E(a,z-a-4);
}
a=d;
}
}
H(l{
ap(a,v);
}
x(d,l{
o d);
E(v,l;
a=v;
v=v+4;
O a;
}
M(l{
x(184,l;
}
I(l{
O x(233,l;
}
aa(s,l{
o 1032325);
O x(132+s,l;
}
aq(l{
o 49465);
M(n;
o 15);
o a+144);
o 192);
}
W(s,l{
A d;
o s+131);
d=t a;
b d&&d<512)x(133,d);
k{
a=a+4;
t a=x(5,t l;
}
}
ab(q{
A d,a,h,F;
d=1;
b e f 34){
M(i+y);
u m!=34){
an j;
r i++=m;
w j;
}
r i=0;
i=i+4&-4;
w j;
g;
}
k{
F=J;
h=C;
a=e;
g;
b a f 2){
M(h);
}
k b F f 2){
ab(n;
x(185,n;
b a f 33)aq(h);
k o h);
}
k b a f 40){
B j;
g;
}
k b a f 42){
g;
a=e;
g;
g;
b e f 42){
g;
g;
g;
g;
a=0;
}
g;
ab(n;
b e f 61){
g;
o 80);
B j;
o 89);
o 392+(a f 256));
}
k b l{
b a f 256)o 139);
k o 48655);
v++;
}
}
k b a f 38){
W(10,e);
g;
}
k{
d=0;
b e f 61&q{
g;
B j;
W(6,l;
}
k b e!=40){
W(8,l;
b J f 11){
W(0,l;
o C);
g;
}
}
}
}
b e f 40){
b d)o 80);
h=x(60545,n;
g;
s=0;
u e!=41){
B j;
x(2393225,q;
b e f 44)g;
s=s+4;
}
E(h,q;
g;
b d){
x(2397439,q;
s=s+4;
}
k{
a=a+4;
t a=x(232,t l;
}
b q x(50305,q;
}
}
X(q{
A a,d,h;
b s--f p ab(p;
k{
X(q;
h=0;
u s f J){
d=e;
a=C;
g;
b s>8){
h=aa(a,h);
X(q;
}
k{
o 80);
X(q;
o 89);
b s f 4|s f 5){
aq(l;
}
k{
o l;
b d f 37)o 146);
}
}
}
b h&&s>8){
h=aa(a,h);
M(a^p;
I(5);
H(h);
M(l;
}
}
}
B j{
X(11);
}
ac j{
B j;
O aa(0,n;
}
S(q{
A h,d,a;
b e f 288){
g;
g;
h=ac j;
g;
S(q;
b e f 312){
g;
d=I(n;
H(h);
S(q;
H(d);
}
k{
H(h);
}
}
k b e f 352|e f 504){
a=e;
g;
g;
b a f 352){
d=v;
h=ac j;
}
k{
b e!=59)B j;
g;
d=v;
h=0;
b e!=59)h=ac j;
g;
b e!=41){
a=I(n;
B j;
I(d-v-5);
H(l;
d=a+4;
}
}
g;
S(&h);
I(d-v-5);
H(h);
}
k b e f 123){
g;
ar(p;
u e!=125)S(q;
g;
}
k{
b e f 448){
g;
b e!=59)B j;
U=I(U);
}
k b e f 400){
g;
t s=I(t q;
}
k b e!=59)B j;
g;
}
}
ar(q{
A h;
u e f 256|e!=-1&!q{
b e f 256){
g;
u e!=59){
b q{
P=P+4;
t e=-P;
}
k{
t e=i;
i=i+4;
}
g;
b e f 44)g;
}
g;
}
k{
t e=v;
g;
g;
h=8;
u e!=41){
t e=h;
h=h+4;
g;
b e f 44)g;
}
g;
U=P=0;
o 15042901);
h=x(60545,n;
S(n;
H(U);
o 50121);
E(h,P);
}
}
}
c d){
E(i,d);
i=i+4;
}
ad(d,l{
c d);
d=d+134512640;
c d);
c d);
c l;
c l;
}
ae(q{
A a,h,d,N,z,F;
N=0;
a=Q;
u p{
a++;
h=a;
u r a!=32&&a<D)a++;
b a f D)break;
e=T+(h-Q)*8+256-8;
z=t e;
d=t(e+4);
b d&&z!=p{
b!z){
b!q{
memcpy(i,h,a-h);
i=i+a-h+1;
}
k b s f p{
c N+22);
c n;
c n;
c 16);
N=N+a-h+1;
}
k{
N++;
u d){
h=ao(d);
F=r(d-p!=5;
E(d,-F*4);
c d-K+R+y);
c N*256+F+p;
d=h;
}
}
}
k b!q{
ap(d,z);
}
}
}
}
au(F){
A Y,af,as,ag,at,ah,d,a,ai;
R=i;
ai=v-K;
v=K;
o 5264472);
a=t(T+592);
x(232,a-v-5);
o 50057);
M(p;
o 32973);
i=i+ai;
af=i;
i++;
i=strcpy(i,"libc.so.6")+10;
i=strcpy(i,"libdl.so.2")+11;
ae(n;
as=i-af;
i=(i+3)&-4;
ag=i;
c n;
c n;
c n;
c n;
ae(p;
at=i;
d=(i-ag)/16;
c p;
c d);
c p;
c n;
a=2;
u a<d)c a++);
c n;
ah=i;
ae(2);
memcpy(R,K,ai);
Y=i;
i=G;
c 1179403647);
c 65793);
c n;
c n;
c 196610);
c p;
c R+y);
c 48);
c n;
c n;
c 2097204);
c 3);
c 3);
ad(144,19);
c 4);
c p;
c p;
ad(0,Y-G);
c 7);
c 4096);
c 2);
ad(164,88);
c 6);
c 4);
i=strcpy(i,"/lib/ld-linux.so.2")+20;
c p;
c p;
c p;
c 11);
c 4);
c at+y);
c 6);
c ag+y);
c 5);
c af+y);
c 10);
c as);
c 11);
c 16);
c 17);
c ah+y);
c 18);
c Y-ah);
c 19);
c 8);
c n;
c n;
a=fopen(F,"w");
fwrite(G,1,Y-G,l;
fclose(l;
}
main(int d, char **l{
b d<3){
printf("usage: otccelf file.c outfile\n");
O 0;
}
D=strcpy(Q aj," int if else while break return for define main ")+48;
i=G aj;
v=K aj;
T aj;
a=a+4;
ak=fopen(t a,"r");
y=134512640-G;
i=i+252;
v=v+17;
w j;
g;
ar(n;
a=a+4;
au(t l;
O 0;
}
+28 -4
View File
@@ -1030,19 +1030,43 @@ fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing))! :-) ).
# 2001
## [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: doesn't work with some platforms - please help us fix
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed an initial
segfault and he also fixed the [supplementary program
bellard.otccex.c](2001/bellard/bellard.otccex.c) but this still crashes. Cody
will probably be looking at this in the not too distant future but if you have a
fix we welcome it.
bellard.otccex.c](2001/bellard/bellard.otccex.c) but this still crashes. Below
are some notes about getting this entry to work but the gist of it is that it
requires i386 linux. Can you fix it for 64-bit linux? We welcome your help! Here
are some notes of interest:
The author said that they compiled it with [gcc version
2.95.2](https://ftp.gnu.org/gnu/gcc/gcc-2.95.2/gcc-everything-2.95.2.tar.gz). We
don't know if a certain gcc version is necessary but it might be helpful to
download and compile that version to test it - or it might not.
I (Cody) have no i386 system to test this but perhaps this is why I can't get it
to work. Yusuke was able to get this to work with `-m32` but it seems with an
emulator.
On the author's [web page for this program](https://bellard.org/otcc/) where it
is stated it requires i386 linux.
There I found what should be a more portable version which is included as
[otccelf.c](2001/bellard/otccelf.c) (after adding some `#include`s and the
modification by Yusuke noted in the README.md file) but it appears this also
requires i386 linux; indeed looking at the code it hard codes paths that are
i386 specific to linux.
Another point of interest is that the author provided de-obfuscated versions
which might be of value to look at. I might do that as well but this entry is
very likely never going to work for 64-bit linux.
Or maybe you have a fix for 64-bit CPUs? You might like to look at the otccelf
version but note that it at least in 64-bit linux (and macOS) have compilation
errors.
Either way we welcome your help! Thank you!
## [2001/cheong](2001/cheong/cheong.c) ([README.md](2001/cheong/README.md))
## STATUS: INABIAF - please **DO NOT** fix