コード最速伝説 Project ltTAKESAKO HASEGAWAgt 青海 遠征編 注意 このプレゼンはノンフィクションであり登場する団体やコードは架空の漫画アニメ ID: 810007
Download The PPT/PDF document "頭文字 $ [ イニシャル" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
頭文字
$
[
イニシャル
]
コード最速伝説
Project $ <TAKESAKO, HASEGAWA>
[
青海
遠征編
]
Slide2注意
このプレゼンはノンフィクションであり、登場する団体やコードは、架空の漫画、アニメ、
TVゲーム等とは一切関係ありません。
This is a nonfictional work. Any resemblance to fictional manga, anime, TV games, is purely coincidental.
Slide3What is Happa-tai?
(葉っぱ隊)
Maniacs for Browser’s charset encodingUTF-7, EBCDIC … XSS, XSS, XSS …
Slide4BATTLE 1 : Hill-Climbing
斜め上
目指して走ります
!proceed obliquely upward!
Slide5BATTLE 1 : Hill-Climbing
J
ava
ScriptPerl
VS.
Slide6BATTLE 1 : Hill-Climbing
p
pencode
by TAKESAKO
Slide7Say “Hello” several languages.
Slide8Programming language C says “Hello”
#include <stdio.h>
int main(void)
{ printf("Hello World!"); return 0;}
Slide9Java says “Hello world!”
class HelloWorld {
static public void main(String args[]) {
System.out.println("Hello World!"); }}
Slide10BASIC says “Hello world!”
10 PRINT "Hello World!"
Slide11COBOL says “Hello world!”
*****************************
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.ENVIRONMENT DIVISION.DATA DIVISION.PROCEDURE DIVISION.MAIN SECTION.DISPLAY "Hello World!"STOP RUN.****************************
Slide12Brainf*ck says “Hello world!”
++++++++++[>+++++++>+++++++
+++>+++<<<-]>++.>+.+++++++.
.+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.
Slide13Perl says “hello world”
package Earth;sub Greet{
%_=('Y','~');$_='$;=!(Middle Earth.age~~~<Eart~~~~~~~~~~~~~h .age)?!(defined$ti~~~~~~~~~~~mez~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~~~~~~~~split("
~~~~~~~~~~~~~~~~~",@_~~~~~~~~~~~~~~~~~~~~~~~~~~[0])) ~~~~~~~~~~~~~~~~):e~~~~~~~~~~~~~~~~~~~~~~~~~~~gexe
~~~~~~~~~~~~~~~;$d~~~~~~~~~~~~~~~~~~~~~~~~~~~="s
~~~~~~~~~~~~~~ort~~~~~~~~~~~~~~~~~~~~~~~~~~<=
~~~~~~~~~~~~>,~~~~~~~~~~~~~~~~~~~~~~~~~~YY
~~~~~~~~~~~@_~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~"~~~~~~~~~~~~~~~~~~~';;
s,(~|\r|\n|\s),,g;s.Y.\x7e.g;
eval};Greet;'the world';
http://www.perlmonks.org/index.pl?node_id=329174
Slide14アンケートPerlが好きな人/嫌いな人(挙手!)
“~が嫌い”
“~が好き”
Perl
Ruby
PHP
Python
212
34
61
15
15
4
29
2
※
参考:
Google
の検索結果
81%
80%
79%
93%
言語
好きな人
の割合
Slide15Quiz: What is this?
#!/usr/bin/perl
s q qq xor print qq else xor print qw sin cos xor printf scalar reverse qq else if cos
→ 正解:標準出力に lsincosl を出力するPerlプログラム
Slide16Perlの予約語 (220個)
lt gt le ge eq ne cmp not and or xor if else elsif while for foreach continue goto last local map my next redo require return use tr y s m q qq qr qw qx x
abs accept alarm atan2 bind binmode bless caller chdir chmod chomp chop chown chr chroot close closedir connect cos crypt dbmclose dbmopen defined delete die do dump each eof eval exec exists exit exp fcntl fileno flock fork formline getc getlogin getpeername getpgrp getppid getpriority getpwnam getgrnam gethostbyname getnetbyname getprotobyname getpwuid getgrgid getservbyname gethostbyaddr getnetbyaddr getprotobynumber getservbyport getpwent getgrent gethostent getnetent getprotoent getservent setpwent setgrent sethostent setnetent setprotoent setservent endpwent endgrent endhostent endnetent endprotoent endservent getsockname getsockopt glob gmtime grep hex import index int ioctl join keys kill lc lcfirst length link listen localtime log lstat mkdir msgctl msgget msgrcv msgsnd no oct open opendir ord pack pipe pop pos print printf push quotemeta rand read readdir readlink recv ref rename reset reverse rewinddir rindex rmdir scalar seek seekdir select semctl semget semop send setpgrp setpriority setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep socket socketpair sort splice split sprintf sqrt srand stat study substr symlink syscall sysread system syswrite tell telldir tie time times truncate uc ucfirst umask undef unlink unpack untie unshift utime values vec wait waitpid wantarray warn write
■ 標準関数 (182)
■ 演算子/制御子 (38)
Slide17予約語プログラミングのルール数字は使わない
0 1 2 3 4 5 6 7 8 9 を使っちゃ駄目!記号も使用禁止!変数
$, @, %, セミコロン ; カンマ
, も駄目!クォート ’ ダブルクォート ” も使用禁止!その他 \ () {} [] + - : ! ? & | #.. も!使用するのはPerlの予約語のみif print open … 本当にできるの?
Slide18http://bit.ly/ppencode
Ajax demo
Slide19予約語プログラミングのテクニック解説セミコロン
; の代わりに xor を使うPerl の論理演算子
and or … xor …open “ファイル”
or dieファイルのopenに失敗したらdieしろopen “ファイル” xor dieファイルのopenの結果によらずdieしろopen “ファイル” ; die と同義
Slide20お前はもう死んでいる
open xor die
Slide21予約語プログラミングのテクニック解説セミコロン
; の代わりに xor を使うq/??/ → q x??x → q else → ’ls’qw(?? ??) → qw x?? ??x
→ qw sin cos → qw(in co) → (’in’, ’co’)print chr ord ”abc” →
先頭文字 a を出力reverse → 文字列を反転 → 末尾文字を出力uc, uppercase → tr/a-z/A-Z/length → 文字列の長さ → 任意のASCIIコード
Slide22誰得
?
Slide23a-y だけでプログラミング可能
Steal the buttons of "$" and ";”, “z”
from Perl monger’s keyboard.
キーボードから「
$」と「;」を盗まれても大丈夫
Slide24BATTLE 1 : Hill-Climbing
J
ava
ScriptPerl
VS.
Slide25BATTLE 1 : Hill-Climbing
jjeencode
by HASEGAWA
Slide26jjencodeのご紹介Introductory jjencode
Slide27Quiz: これは何をするプログラムでしょう?Quiz: How does this program work?
javascript:$=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")[$],_$_:++$,$_$$:({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$$_:(!""+"")[$],$__:++$,$_$:++$,$$__:({}+"")[$],$$_:++$,$$$:++$,$___:++$,$__$:++$};$.$_=($.$_=$+"")[$.$_$]+($._$=$.$_[$.__$])+($.$$=($.$+"")[$.__$])+((!$)+"")[$._$$]+($.__=$.$_[$.$$_])+($.$=(!""+"")[$.__$])+($._=(!""+"")[$._$_])+$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+(!""+"")[$._$$]+$.__+$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];$.$($.$($.$$+"\""+"\\"+$.__$+$.$__+$.__$+"\\"+$.__$+$.$_$+$.$__+"\\"+$.__$+$.$__+$.$_$+"\\"+$.__$+$.$$_+$._$_+"\\"+$.__$+$.$$_+$.$__+"\\"+$.$_$+$.___+"\\"+$.$__+$._$_+"\\"+$.__$+$.__$+$.___+"\\"+$.__$+$.$__+$.$_$+"\\"+$.__$+$.$_$+$.$__+"\\"+$.__$+$.$_$+$.$__+"\\"+$.__$+$.$_$+$.$$$+"\\"+$.$_$+$.$__+"\\"+$.__$+$._$_+$.$$$+"\\"+$.__$+$.$_$+$.$$$+"\\"+$.__$+$.$$_+$._$_+"\\"+$.__$+$.$_$+$.$__+"\\"+$.__$+$.$__+$.$__+"\\"+$.$__+$._$_+"\\"+$.$_$+$.__$+"\"")())();
Answer
→
alert("Hello,World")
Slide28Available lettersWriting JavaScript only with symbols
Symbols Only!No alphabet letters [a-zA-Z]No numerical letters [0-9]Of course, No letters other than US-ASCIIAvailable
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~32 kinds of symbols!
Slide29How it works ?文字の生成
(Generate letters)
$ = ~[]; // -1
Applying bit-not to Empty Array makes integer(-1)$ = (![]+""); // "false"$ = (![]+"")[0]; // "f"$ = ({}+""); // "[object Object]"
$ = ({}+"")[5]; // "c"$ = ({}.$+""); // "undefined"$ = ({}.$+"")[1]; // "n"
数字の生成
(
Generate numbers)
→これで最低限の文字は生成できる
!
makes minumum of letters !
Slide30How it works ?Run text as JavaScript code
(0).constructor == Number
ObjectNumber.constructor == Function ObjectFunction( "alert(1)" )(); // substitute for eval(0)["constructor"][
"constructor"]("alert(1)")();
$ = "constructor";$$ = "alert(1)";
$_ = ~[];
// == -1
($_)[$][$]($$)(); // only symbols
Slide31jjencode - Live demo
http://bit.ly/jjencode
Slide32Sla.ckers.org
「あなたが神か」
Slide33BATTLE 2 : Downhill
斜め上
から走ってきます
!proceed from obliquely upward!
Slide34BATTLE 2 : Downhill
ハ
チロク
86
VS.
詳細不明
U
nspecified
Slide35BATTLE 2 : Downhill
86
ハチロク
by HASEGAWA
Slide36Writing 8086 binary code only with symbols
Slide37Quiz: これは何をするプログラムでしょう?Quiz: How does this program work?
%@"%"@,~,%,!`_______-;>`_______%"!,^,:`_______-@{-`{-?:`_____
__-``-``-@@`_______-`~-``-@$`_______-``-``-@@`_______-`~-``-@#
`_______-+~-/~-?;`_______%!~-;-,;`_______-"$-@~-@``_______-{[-);-@:`_______-/*,%`_______`_______`_______`_______%@$-@;-?;`_______-/~-`&,#`_______-`~-`{,*`_______-@@-$!`_______-:$,[,<`_______-!|-.),!`_______-@{-@`-/(`_______`_______`_______`_______-{!-{.,.`_______-~/-/``_______%""-}@$"`_______%@@-!/,!`_______-:*-=%`[[[[[[[[`^^^^^-%+)@@^^^!;@@_!,((,.((-$+)@*+@!!@-,!"(+@@,$-,!"($%&,&,&_&,"@"'%_&"',&$&-@*@$"
Answer → MS-DOS 16bit COM
mov ah, 09h
mov dx, "Hello, World"
int 21h
Slide38Quiz: これは何をするプログラムでしょう?Quiz: How does this program work?
Slide3986 binary
Writing 8086 binary only with symbolsSymbols Only!No alphabet letters [a-zA-Z]No numerical letters [0-9]Of course, No letters other than US-ASCIIAvailable
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~32 kinds of symbols!16bit COM format
no file header like as "MZ", "ELF"
Slide40How it works ?Available instructions
part of "AND reg, [mem]"part of "SUB reg, [mem]"Transfer data
use "PUSHA" or "POP reg
"Unavailable "MOV"DAA / DAS / AAS - worthless!Self-modifying
Slide41Arbitrary code is encoded as symbols.
place as payload after bootstrap codeBootstrap code expands
decoder code on stackDecoder code expandspayload from 0100H
How it works ?PSPbootstrap
payload(encoded to symbol)0000
stack
0100
FFFF
02E0
payload
(decoded from symbol)
decoder
Slide42How it works ?
AND AX, 2240
AND AX, 4022
SUB AL, 7eSUB AL, 25
SUB AL, 21PUSHAPOP DIPOP DIPOP DI
POP DIPOP DI
POP DIPOP DI
25 40 22
25 22 40
2C 7E
2C 25
2C 21
60
5F
5F5F
5F
5F5F
5F
AX == 0x003C
Push 8 registers
Pop 7 times,
"0x3C 0x00" are
left on stackExpand code on stack
%@"
%"@,~
,%
,!
`
_
_
_
_
_
_
_
Slide43Symbolized 86 - Live demo
http://bit.ly/ToT
Slide44BATTLE 2 : Downhill
ハ
チロク
86
VS.
詳細不明
U
nspecified
Slide45BATTLE 2 : Downhill
U
nspecified
by TAKESAKO
Slide46Unspecified
What
’s this?
Slide47Q. What is it? Which language?
(1) MS-DOS 8086
(2) Javascript
(3) Perl
(4) Ruby
Slide48Final
answer?
Slide49http://preview.tinyurl.com/yapcasia2009
Slide50Polyglot
Programming
Slide51(1) 真偽値の違い
print 0 ? "Ruby" : "Perl" ;
$ perl 1.pPerl
$ ruby 1.pRuby$ vi 1.p
Slide52(2) デクリメント演算子の有無
$ perl 2.p
Perl
$ ruby 2.pRuby
$ vi 2.p$x=1; --$x; print $x==1 ? "Ruby" : "Perl";
Slide53(3) 文字列リテラル
q='''=;
print"Perl"#';print"Ruby"#''';print"Python";
$ perl 3.p
Perl$ ruby 3.pRuby$ python 3.pPython
$ vi 3.p
Slide54(4) C/C++ における sizeof(char) の違い
#include <stdio.h>
int main() {
printf("%s", sizeof('C')==1?"C++":"C");}
$ gcc -xc a.cpp && ./a.outC$ g++ a.cpp && ./a.out
C++
$ vi a.cpp
Slide55(5) C89/C99 の違い
#include <stdio.h>
enum{a=0,b=1};
int main() { if(sizeof(enum{b=0,a=1})); printf("C%d\n",a?89:99);}
$ gcc -xc -std=iso9899:1990 a.c && ./a.outC89
$ gcc -xc -std=gnu99 a.c && ./a.outC99
$ vi a.c
Slide56(6) 5言語 Polyglot
#include/*
q="""*/<stdio.h>
int main() {putchar('C'); if(sizeof('C')-1); else {putchar('+'); putchar('+');}} /*=;print'Perl'#";print'Ruby'#""";print'Python'#*/ $ perl a.cppPerl
$ ruby a.cppRuby$ python a.cppPython
$ gcc -xc a.cpp && ./a.out
C
$ g++ a.cpp && ./a.out
C++
$ vi a.cpp
Slide57Symbolic
Programming
Slide58無名
の
質
anonymous programming
Slide59記号プログラミングのススメ使用するのは記号
32文字のみ!”#$%&’()-=^~¥|`
@{ [ ] } ; + : * <> , . / ? _ |
スペース、タブ、改行も使わないメリットインデントに悩む必要なし1,2,3,4,8スペース、1タブ派の人も安心変数の命名に悩む必要なし_ __ ___ ____ _____ ______ _______
Slide60記号プログラミングの利点
記号しか入力できないキーボードでも大丈夫!
Slide61
Slide62Symbolic 4 Polyglot Programming!
Slide63JavaScript
/* … */
Slide64How to make JavaScript Number
Create Empty array[]Cast (Array to Number)
-[] // unary minus operator~[] // bitwise not
Assign variable $$ = ~[]; // -1$ = -[]; // 0$ = -~[]; // 1$ = $ + $; // 2
Slide65How to make JavaScript String
Create Boolean object![] === falseCast (Boolean to String)
(![] + ’’) === ’false’substr (ECMAScript5th)
$ = (![] + ’’)[0]; // ’f’$ = (![] + ’’)[1]; // ’a’$ = (![] + ’’)[2]; // ’l’$ = (![] + ’’)[3]; // ’s’$ = (![] + ’’)[4]; // ’e’
Slide66How to make JavaScript ‘a’,’b’,’c’…
Create ’a’$ = (![] + ’’); // ’false’$ = (![] + ’’)[1]; // ’a’
Create ’b’$ = ( {} + ’’); // ’[object Object]’
$ = ( {} + ’’)[2]; // ’b’Create ’c’$ = ( {} + ’’); // ’[object Object]’$ = ( {} + ’’)[5]; // ’c’Create ’d’$ = ( {}.$ + ’’); // ’undefined’$ = ( {}.$ + ’’)[2]; // ’d’
Slide67How to eval from JavaScript String
Function object(0).constructor === Number objectNumber.constructor === Function objecteval
Function( "alert(1)" )(); // eval("alert(1)");(0)["constructor"]["constructor"]("alert(1)")();
Only symbols$ = "constructor";$$ = "alert(1)";$_ = -[]; // 0($_)[$][$]($$)(); // It works! jjencode by id:hasegawayosuke
Slide68Perl
# …
Slide69Perl で記号プログラミング解説
Perlの正規表現$a =~ /(…)/$a =~ ‘(…)’正規表現の中でeval
実行が可能$a =~ ‘(?{print”hello\n”;})’$a =~ ( ‘(?{print”hello\n”;})’ )
$a =~ ( ‘(?{‘ . ‘print”hello\n”;’ . ‘})’ )‘…’=~ ( ‘(?{‘ . ‘abc’ ^ ’def’ . ‘})’ )‘…’ !~ ( ‘(?{‘ . ‘abc’ ^ ’def’ . ‘})’ )
Slide70‘000’ xor ‘001’ xor ‘011’ => ‘010’xor
演算子(^)は文字列にも適用可能
Slide71ppencode symbolic version 2
Slide72id:sugyan++
Slide73Ruby
Ruby %#string#
Perl q#string#
Slide74Ruby 1.8 1.9
print"Hello
",0???==63?"Ruby1.8":"Ruby1.9":"Perl","!\n";
$ ruby1.8 xxx.rbHello Ruby1.8!$ ruby1.9 xxx.rbHello Ruby1.9!$ vi xxx.rb
?a
で ASCIIコードの数値を返す仕様が
1.9 から文字列’
a’を返すようになった
Slide75if RUBY_VERSIONRuby1.9
?? => “?”?? % ?? => “?” % “?” => “?”Ruby1.8?? => 63
?? % ?? => 63 % 63 => 0
print"Ruby",??%??==???1.9:1.8sprintf("?","?")63÷63=1余り
0
Slide76Slide77MS-DOS 8086
self-replace x86
Slide788086 自己書き換え使える演算子が限られる
SUBANDレジスタ間のコピーが簡単にできないPUSHA
POP BX自己書き換えコード生成
Slide79帰ってきた ppencode 2009
Slide80all your base32
are belong to us
thanks for listening