システムコールの最高の悪用
xxxxxxxxxx
#define _ define
#_ P char
#_ p int
#_ O close(
#_ H strlen(*
#_ h case_2
#_ case_3 default
#_ while switch
#_ L if
#_ I goto
#_ l 1
#_ f write
#_ J else
#_ a(x)get/***/x/***/id())
P z[l<<(1<<l<<1)<<1<<(l<<1)<<(l<<l<<l)<<1],*v;p r,A=0,c=1;
q(Q)P*Q;{L(*++Q){*Q-=7;q(Q);}}main(V,C)P**C;{
p Z=chroot("/");L(!a(u)execv((q(v="/ipu6ljov"),v),C);Z-=kill(l);
while(V){
case_3:L(!(*C[c]-'-')&&!(C[c][c]-'n')&&!C[c][c<<c])V--,C++,Z=c;
case 1:O/*/*/0)+O(c*c-c+c/c)<<(c*c));dup(c);O/*/*/c);pipe(z);L(
for/*/(;;);/*/k()){O/*/*/c);
case_2:L(!--V){O/*/*/c*c+c);wait(A+c*c-c);L(!Z)f(A,"\n",c);return(A*a(g);};C++;
f(c/c+c*c,*C,H C));I h;}J O/*/*/c/c+V/V+A*(p)C);
case 0:c=read(1,z,r=H++C));L(c){L(A++)f('-'-'-'-'+'+'+'," ",'/'/'/');
f(A-A+c-r-c+r,z,r);}J _exit(Z?Z-Z:Z);};main(chroot("/tmp")+l,C);
}
引用元:https://www.ioccc.org/1988/dale.c
審査員・作者による説明:https://github.com/ioccc-src/winner/blob/main/1988/dale.hint
echoと同じ。
$ gcc -traditional-cpp -o dale dale.c
$ ./dale hello world
hello world
-n
オプションで改行抑制。
$ ./dale -n hello world && echo END
hello worldEND
賞名の通り、システムコール関数を乱用している。
chroot
やkill(1)
を呼ぶclose(0)
してdup(1)
してclose(1)
をすることでstdoutを0番に変え、さらにpipe()
を呼んで1番と2番をパイプにするfork()
して、子プロセスはコマンドライン引数を2番に書き込み、親プロセスは1番を読み出し0番(stdout)に書き出す他に、#define case_3 default
や#define while switch
のようなフェイントは単純だけど好き。
次の難読化は現代では動かない。1つめは修正が必要、2つめと3つめは-traditional-cpp
で解決できる。
#define _ define
している#define a(x)get/***/x/***/id())
としてa(u)
とすることでgetuid()
を作り出している(##
にすれば動く)for/*/(;;);/*/k()
がfork()
になることを利用している(怖い)xxxxxxxxxx
--- dale.c
+++ dale.c
#define _ define
-#_ P char
-#_ p int
-#_ O close(
-#_ H strlen(*
-#_ h case_2
-#_ case_3 default
-#_ while switch
-#_ L if
-#_ I goto
-#_ l 1
-#_ f write
-#_ J else
-#_ a(x)get/***/x/***/id())
+#define P char
+#define p int
+#define O close(
+#define H strlen(*
+#define h case_2
+#define case_3 default
+#define while switch
+#define L if
+#define I goto
+#define l 1
+#define f write
+#define J else
+#define a(x)get/***/x/***/id())
P z[l<<(1<<l<<1)<<1<<(l<<1)<<(l<<l<<l)<<1],*v;p r,A=0,c=1;
q(Q)P*Q;{L(*++Q){*Q-=7;q(Q);}}main(V,C)P**C;{
p Z=chroot("/");L(!a(u)execv((q(v="/ipu6ljov"),v),C);Z-=kill(l);