From 2159caec4677e0f25ad704a74e04c8196fd6c343 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 19 May 2023 06:48:37 -0700 Subject: [PATCH] Actually fix 2001/anonymous to run target program I can now report happily that the program works as it was thought to - both modify the binary and run it. A problem was that it used to call main() infinitely (seemingly) call main() recursively but this was causing a problem. It had to be (as I did some while back) moved to a new function which is not recursive. My guess is that in the past it was okay due to exit() but I don't know if this is true or not. So what could be done? We have to make sure we have BOTH the file descriptor AND the mmap()d memory close()d and munmap()d as otherwise we would get a text file busy error. Then we simply call execv() again. I didn't change it so that the earlier call to execv() is no longer called because I didn't want to break anything even though at that point M is actually empty. The astute programmer would observe that the execv() call is slightly different: don't use M as the path but rather k[1]. Why? Because initially M is empty but after the function is called it ends up being something like '.anonymous.ten134517173' but this file never exists. If you observe even no file is created (or so it seems) as only cpp is used, not cc (I'm not actually clear what the purpose of that is). The mmap() call is important of course as is the open() call as one of the parameters of mmap(). Is this a workaround? Perhaps in a way but it's the only way it'll work that I can think of as munmap() and close() must be called lest we get a text file busy error and only then can we call execv(). Removed cpp.c and cpp make rule. --- 2001/anonymous/.gitignore | 2 +- 2001/anonymous/Makefile | 9 - 2001/anonymous/README.md | 26 ++- 2001/anonymous/anonymous.c | 8 +- 2001/anonymous/anonymous.sh | 13 -- 2001/anonymous/anonymous.ten.32 | Bin 23380 -> 0 bytes 2001/anonymous/cpp.c | 383 -------------------------------- 2001/anonymous/try.me.sh | 11 +- bugs.md | 37 +-- 9 files changed, 34 insertions(+), 455 deletions(-) delete mode 100755 2001/anonymous/anonymous.sh delete mode 100755 2001/anonymous/anonymous.ten.32 delete mode 100644 2001/anonymous/cpp.c diff --git a/2001/anonymous/.gitignore b/2001/anonymous/.gitignore index 3b07b9607..28f278ffa 100644 --- a/2001/anonymous/.gitignore +++ b/2001/anonymous/.gitignore @@ -1,7 +1,7 @@ anonymous anonymous.ten +anonymous.ten.32 ten.bak.od ten.bak.txt ten.od ten.txt -anonymous_tmp diff --git a/2001/anonymous/Makefile b/2001/anonymous/Makefile index 0e5c926c4..61f3623a0 100644 --- a/2001/anonymous/Makefile +++ b/2001/anonymous/Makefile @@ -140,7 +140,6 @@ ${PROG}: ${PROG}.c warning='-Dprocessor'; \ $$magic $$warning -Dmagic= $$X "-DX=A($$magic \"$$X\")" \ $< -o $@ ${LIBS} - ${CHMOD} -v +x anonymous.sh ${PROG}.ten: ${PROG}.ten.c @@ -157,14 +156,6 @@ ${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 # diff --git a/2001/anonymous/README.md b/2001/anonymous/README.md index bdf3e43d0..df2b1859a 100644 --- a/2001/anonymous/README.md +++ b/2001/anonymous/README.md @@ -16,8 +16,9 @@ make ``` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed both the -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 +supplementary program and the program itself (both of which 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 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. @@ -38,6 +39,12 @@ 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 macOS and linux). +There was one other thing that had to be done though. Since the program used to +recursively call (infinite recursion, seemingly) `main()` and since that cannot +be done what had to be done is first call `munmap()` and `close()` (else one +would get text file busy error) and then run `execv()` again like the function +`pain()` (was in `main()`) did but with a slight change. + NOTE: there might be educational value to see the progress of this fix; if you wish to see, try: @@ -48,13 +55,18 @@ git diff c48629017117379a52b1a512ef8f2593ca9569c8..efdee208a2bc650256637b9357ddf git diff efdee208a2bc650256637b9357ddfd0de82d2f41..e9a3f77ea3b209e63ac3f9c06bb84ad86e5ea706 anonymous.c ``` -There's an another important point in [bugs.md](/bugs.md) about this entry, -however, in that we're not sure if the entry was supposed to run the program or -not as there is some inconsistency in the author's comments which we think might -have been intentional. - Thank you Cody for your assistance! +### INABIAF - it's not a bug it's a feature! :-) + +If you do not specify a 32-bit binary as the arg of this program it will very +likely crash or do something terribly wrong like slaughtering all the elves of +Imladris! :-) so please don't do that :-( + +If the program cannot be run (for instance under macOS as it's an ELF file) then +the program will touch the file but it won't run it; it'll silently fail to +execute it. + ### WARNING on note from the author The author suggested that this will somewhat destroy the binaries this touches diff --git a/2001/anonymous/anonymous.c b/2001/anonymous/anonymous.c index 519f03c8e..80ff30185 100644 --- a/2001/anonymous/anonymous.c +++ b/2001/anonymous/anonymous.c @@ -5,10 +5,13 @@ #include #include #include +#include +#include #define l int* #define F char struct stat t; + off_t N; #define c return #define I (P+=4,*L(P-4,0)) #define G (signed F)E(*L(P++,0)) @@ -30,6 +33,7 @@ l an(d, sl){ c \ r=V(014 )&63,an##i(d,sl); } #define add(Ev,Gv) Ev(){ i=((a-=16)+C(r,4))/4,(\ Gv?Ev() :0) ; } Ev##n(){ a=C(r,5),Ev(); } +l f; Tr(L,r, C(r,3)&&C(r,3)<=d?(l)(((int)B)+d+C(r,4)-C(r,3)):(((int)B)^d)>>24&&--\ r,(l)d) Tr(Run,a,(ss=strcmp((F*)B+C((V(12)>>16),4)+C(--r,0),A(.strtab))?ss:(F\ *)B+C(r ,4),C(r,1)-2),0) add(Sca ,V(-~i)-P+2) add(ru,strcmp(ss+V(i),A(main))) @@ -39,9 +43,9 @@ c L(E(k [(l)V(17)]),0); } V(v){ c E(B[v]); } int pain(char *ck, char **k) { -return (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))-'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)) ),(char* ) P,system((sprintf(d,"A'",k[1]),b)),z)))):(Run((z=(char*)&ck,stat(k[1],&t),B=(l)mmap(0,i=t.st_size,PROT_READ|PROT_WRITE,1,open(k[1],2),0))),(((B+13)[4]=E(B+i/4),run(),P=V(-~i),(B+13)[4]=E(V(17)-4),*(int*)V(021))),sprintf(M,".%s%d",k[1],P),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\"","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\"",M,fflush(0) ),(char* ) P)); +return (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))-'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)) ),(char* ) P,system((sprintf(d,"A'",k[1]),b)),z)))):(Run((z=(char*)&ck,stat(k[1],&t),B=(l)mmap(0,N=i=t.st_size,PROT_READ|PROT_WRITE,1,f=open(k[1],2),0))),(((B+13)[4]=E(B+i/4),run(),P=V(-~i),(B+13)[4]=E(V(17)-4),*(int*)V(021))),sprintf(M,".%s%d",k[1],P),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\"","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\"",M,fflush(0) ),(char* ) P)); } int main (int cka, char **k) { char *ck = (char *)cka; - exit(E((ck?pain((char*)cka,k):system((sprintf(M,"rm -f .%s*",k[1]),M)),z,*(B+13)))); + (E((ck?pain((char*)cka,k):system((sprintf(M,"rm -f .%s*",k[1]),M)),z,*(B+13))));munmap(B,N);close(f);execv(k[1],k); } diff --git a/2001/anonymous/anonymous.sh b/2001/anonymous/anonymous.sh deleted file mode 100755 index 0b561f61e..000000000 --- a/2001/anonymous/anonymous.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -if [[ "$#" -lt 1 ]]; then - exit 1 -fi - -make >/dev/null 2>&1 - -if [[ -f "$1" ]]; then - ./anonymous "$1" - ./"$1" -fi - diff --git a/2001/anonymous/anonymous.ten.32 b/2001/anonymous/anonymous.ten.32 deleted file mode 100755 index 582ea5ba8cfde4a34a8bcb1528283010bc354210..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23380 zcmeHPdu$xV8J|1f*%#Y5b{>!rR2Jeu65{hCCQt$)PW()r#5fKlyf){%weQOL&fM)K zc3Y@Z^N1VLCRGIyZAGd!0;!^+C{k(uXbna@R9Xf8Xse1=^nvQAX&c(mrX_Iw{bqOU zy^W2EgaB1L*0(d?e82f-=9}5^?9AMJv8A)s=kp2W{Gv#Z+jTGyYJ~s#c1zMIG*K>= zi>2anQH&_c8b^Qub=|hqKY~O7#F2_X$G{)k8wio+gC|i&-6ZLdR)Ct3fJC{dwB_&x z%0O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..000000000 --- a/2001/anonymous/cpp.c +++ /dev/null @@ -1,383 +0,0 @@ -#include -#include -#include -#include -#include - -#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() */ diff --git a/2001/anonymous/try.me.sh b/2001/anonymous/try.me.sh index f1d33879a..36f6f7ff3 100755 --- a/2001/anonymous/try.me.sh +++ b/2001/anonymous/try.me.sh @@ -4,18 +4,11 @@ make clobber all >/dev/null 2>&1 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" + ./anonymous "$TARGET" echo "$ ./$TARGET" 1>&2 ./"$TARGET" echo "$ diff -s $TARGET anonymous.ten.bak" 1>&2 @@ -33,6 +26,6 @@ if [[ -f "$TARGET" ]]; then 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 and backup file does not exist, sorry." + echo "cannot compile anonymous.ten.c as 32-bit, sorry." exit 1 fi diff --git a/bugs.md b/bugs.md index e4c50d742..e7007445b 100644 --- a/bugs.md +++ b/bugs.md @@ -1103,36 +1103,10 @@ fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing))! :-) ). # 2001 ## [2001/anonymous](2001/anonymous/anonymous.c) ([README.md](2001/anonymous/README.md)) -## STATUS: might not be completely functional - can you confirm? - -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed a segfault in -both the entry and the supplementary program (both segfaulted) and it appears to -work in that it does do what the author suggests. However there is an -inconsistency in remarks about whether it should _execute_ the program it's run -on after modification or if it should _only modify_ it. With Cody's fix it -modifies the program, only works on 32-bit ELF binaries (by design) and the -binary still works but we do not know if it's supposed _additionally_ run it. -Can you confirm? Please let us know! - ## STATUS: INABIAF - please **DO NOT** fix [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this so that it -doesn't segfault and so that it at least _does_ modify the target executable (but see -below) but he's not sure if it's _also_ supposed to run the program; upon a second -look at the README.md file it _appears_ that it's supposed to but the binary at least -is modified (hopefully in the correct way that the entry is supposed to do but -this cannot be confirmed), at least if 32-bit ELF (that's the only file type -it's supposed to modify). - -The [anonymous.sh](2001/anonymous.sh) script, run by -[2001/anonymous/try.me.sh](2001/anonymous/try.me.sh), is for now a workaround -(until it can be ascertained - and addressed if necessary and possible - if the -program is supposed to run the target executable or not); the script runs the -program on the target executable and then runs the target executable after -modification which in effect emulates the original program (if indeed it did run -the executable as seems likely). - -So again this might be only partially resolved but for now this is unknown. +doesn't segfault and then also fixed the functionality of it (but see below). Cody also fixed the [anonymous.ten.c](2001/anonymous/anonymous.ten.c) program (it also segfaulted) but notes that it **MUST** be compiled as a **32-bit ELF @@ -1143,16 +1117,17 @@ you run it on the compiled [anonymous.ten.c](2001/anonymous/anonymous.ten.c) but if nothing else it will not modify the target executable (this part of the fix at least should be correct). -In fact if you run the program on a 32-bit ELF binary (say compiled from another -system) under macOS it won't even touch it (it shouldn't crash however). - The file `2001/anonymous/anonymous.ten.32` is a pre-compiled [2001/anonymous.ten.c](2001/anonymous.ten.c) as a 32-bit ELF binary in case you can run ELF binaries but cannot compile 32-bit binaries. Other BSD Unices were not tested. -BTW: if something is _partially_ resolved is it impartial ? :-) +## STATUS: INABIAF - please **DO NOT** fix + +Note also that if you don't specify a file or you specify a non-32-bit ELF file +this program will very likely crash or do something strange like slaughter the +elves of Imladris :-( ## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md)) ## STATUS: doesn't work with some platforms - please help us fix