Merge pull request #780 from xexyl/2001-anonymous-orig-cpp
This commit is contained in:
2 files changed
+41
-29
No files matched your search
+38
-26
@@ -22,12 +22,12 @@ 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.
|
||||
|
||||
Although it took a fair bit of debugging it turns out all that
|
||||
needed to be changed was:
|
||||
Although it took a fair bit of debugging it turns out all that had to change
|
||||
was:
|
||||
|
||||
- `#include <sys/mman.h>` for `mmap()`.
|
||||
- have `main()` call another function which is the recursive function; this
|
||||
prevented `main()` from entering an infinite loop.
|
||||
- `#include <sys/mman.h>` for `mmap()` and `munmap()`.
|
||||
- have `main()` call another function which is no longer a recursive function;
|
||||
this prevented `main()` from entering an infinite recursive 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 :-)
|
||||
@@ -41,9 +41,13 @@ 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.
|
||||
be done what had to be done instead is after the new function (`pain()` since it
|
||||
was a pain to fix :-) ) returns to first call `munmap()` and `close()` (else
|
||||
one would get text file busy error) and then the program can call `execv()` again like the
|
||||
function `pain()` (was in `main()`) did but with a slight change. See commit
|
||||
`2159caec4677e0f25ad704a74e04c8196fd6c343` for details. Notice that
|
||||
the location of the calls to `munmap()` and `close() followed by `execv()` do
|
||||
matter!
|
||||
|
||||
NOTE: there might be educational value to see the progress of this fix; if you
|
||||
wish to see, try:
|
||||
@@ -54,10 +58,36 @@ git diff 93aa8d79f208dcccc3c5a2370a727b5cf64e9c53..c48629017117379a52b1a512ef8f2
|
||||
git diff c48629017117379a52b1a512ef8f2593ca9569c8..efdee208a2bc650256637b9357ddfd0de82d2f41 anonymous.c
|
||||
git diff efdee208a2bc650256637b9357ddfd0de82d2f41..e9a3f77ea3b209e63ac3f9c06bb84ad86e5ea706 anonymous.c
|
||||
git diff d2a42f42e8f477f29e9d5ed09ce2bb349eaf7397..2159caec4677e0f25ad704a74e04c8196fd6c343 anonymous.c
|
||||
git diff 2159caec4677e0f25ad704a74e04c8196fd6c343..4bc03de321612869aebf855850c6500df95cb6ef anonymous.c
|
||||
```
|
||||
|
||||
Finally to see from start to finish:
|
||||
|
||||
```sh
|
||||
git diff d2a42f42e8f477f29e9d5ed09ce2bb349eaf7397..4bc03de321612869aebf855850c6500df95cb6ef anonymous.c
|
||||
```
|
||||
|
||||
Thank you Cody for your assistance!
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
./try.me.sh
|
||||
```
|
||||
|
||||
What happens if the x86 program has already been modified by this program? The
|
||||
judges' remarks below might give you a hint!
|
||||
|
||||
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
|
||||
program successfully after it without recompiling?
|
||||
|
||||
|
||||
## 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! :-)
|
||||
|
||||
If you do not specify a 32-bit ELF binary as the arg of this program it will
|
||||
@@ -81,24 +111,6 @@ 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.
|
||||
|
||||
## Try:
|
||||
|
||||
```sh
|
||||
./try.me.sh
|
||||
```
|
||||
|
||||
What happens if the x86 program has already been modified by this program? The
|
||||
judges' remarks below might give you a hint!
|
||||
|
||||
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
|
||||
program successfully after it without recompiling?
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
Is emulation the sincerest form of flattery? This small program does
|
||||
quite a lot of bit twiddling.
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ c L(E(k [(l)V(17)]),0); } V(v){ c E(B[v]); }
|
||||
int
|
||||
pain(char *ck, char **k)
|
||||
{
|
||||
c (z?(stat(M,&t)?P+=a+'{'?0:3:execv(M,k),a=G,i=P,y=G&255,sprintf(Q,y/'@'-3?"*L(V(%d+%d)+%d,0)":"R[%d]",(y&7),'\r',y/0100-1?0:G),(a+127&&a+'}'&&a+1?(a+61&&a+24&&a+025?(P=a+'H'&&a%061<=0?P:i,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:g:I:g,a>0?a&7:"& "[a%3%2+1],a+72?Q:A(*R),a>0|a<-99?g:I,0) ,(char* ) P):(P=i,i=a+61?a+21?E(I):G:0, D(a%' '+29+"P O,\0 U %d,P=%d,",P,P+i,0,0,0) , p(d,"A'",b)),z):(n=g-4?g%5-1?a+127?G:I:0:(Scan(), *( x86?processor :d)=0, (int)(ss+V(i))),g%5<2?d+=sprintf( d,g%5?" %s=E(~-E(%s)), \0 U %s,"+4*g:"%s=E(E(%s)%c%d),",Q,Q,"+ - "[g],n,0 ),(char* ) P:(a=G-'u'?'!':'=', D(g-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+G), p(d,"A'",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,A(.%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\"",__FILE__,"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;
|
||||
c (z?(stat(M,&t)?P+=a+'{'?0:3:execv(M,k),a=G,i=P,y=G&255,sprintf(Q,y/'@'-3?"*L(V(%d+%d)+%d,0)":"R[%d]",(y&7),'\r',y/0100-1?0:G),(a+127&&a+'}'&&a+1?(a+61&&a+24&&a+025?(P=a+'H'&&a%061<=0?P:i,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:g:I:g,a>0?a&7:"& "[a%3%2+1],a+72?Q:A(*R),a>0|a<-99?g:I,0) ,(char* ) P):(P=i,i=a+61?a+21?E(I):G:0, D(a%' '+29+"P O,\0 U %d,P=%d,",P,P+i,0,0,0) , p(d,"A'",b)),z):(n=g-4?g%5-1?a+127?G:I:0:(Scan(), *( x86?processor :d)=0, (int)(ss+V(i))),g%5<2?d+=sprintf( d,g%5?" %s=E(~-E(%s)), \0 U %s,"+4*g:"%s=E(E(%s)%c%d),",Q,Q,"+ - "[g],n,0 ),(char* ) P:(a=G-'u'?'!':'=', D(g-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+G), p(d,"A'",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))), magic((R[4]=E(B+i/4),run(),P=V(-~i), R[4]=E(V(17)-4),*(int*)V(021))), sprintf(M,A(.%s%d),k[1],P), D("%s %s '-DX=A(%s)' -o %s '-Dmagic=",X,__FILE__,X,M,fflush(0)) ,(char* ) P));
|
||||
}
|
||||
int main (int cka, char **k) { char *ck = (char *)cka;
|
||||
(E((ck?pain((char*)cka,k):p(M,A(rm -f .%s),M),*R)));munmap(B,N);close(f);execv(k[1],k);
|
||||
}
|
||||
Reference in new issue
Block a user