Created
July 2, 2014 14:03
-
-
Save mikecat/148aa741ea3308e0dbe2 to your computer and use it in GitHub Desktop.
CodeIQ 第4回デスマコロシアム 解答コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dw 'Aぉ渥恕けNび&KビHトF#ざ@き4^ブぐO<ur盛CEMこエ(tЗしゐとWv÷zほ灯咒へは吐1×ジSゆ5Tょ%QやんろL$"ゲs',80cDh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dq $68824b002b4e689,80f772753ce00046H,30ED7610FC8002C4h,0xB2E18901B304B0E4,8441203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; うまく命令を調整することにより、UTF-8の文字列を命令列として利用可能にした。 | |
; さらに調整して文字列を表す'以外の重複をゼロにすることで、 | |
; ペナルティを200未満に落とすことに成功した。 | |
; E3 XX は、ECXが0でなければ何もしないので、命令の最初のバイトを文字にしたり、 | |
; 9Xと組み合わせてスペースを埋めたりするのに便利である。 | |
; ------------------------------------------------------------ | |
; 出力するべき内容のメモ | |
; for(diff=2;diff<=16;diff+=2) { | |
; for(c=0x24;c<=0x74;c+=diff)putchar(c); | |
; } | |
; total 115 chars | |
bits 32 | |
global _start | |
; 実行開始時には、espには有効なバッファのアドレスが入っており、 | |
; eax,ebx,ecx,edxはゼロで初期化されると推測される。 | |
; これは経験則であり、仕様なのか、たまたまなのかはわからない。 | |
section .text | |
_start: | |
; 文字列を生成する ---------------------------------------- | |
; コメントの"al"は上のcに相当し、"bl"は上のdiff/2に相当する。 | |
; 必ずしもその場所での実際のレジスタとは一致しない。 | |
inc ecx | |
db 0xe3,0x81 | |
mov esi,esp | |
; bl = 1 | |
mov eax,0x9581E6A5 | |
db 0xe3,0x81 | |
xchg eax,ecx | |
dec esi | |
loop1: | |
; al = 0x24 | |
db 0xe3,0x81 | |
mov bl,0x26 | |
dec ebx | |
db 0xe3,0x83 | |
xchg eax,ebx | |
dec eax | |
loop2: | |
; alをバッファに格納する | |
db 0xe3,0x83 | |
mov byte [esi+0x23],al | |
db 0xe3,0x81 | |
xchg eax,esi | |
inc eax | |
; al += bl*2 | |
db 0xe3,0x81 | |
lea esi,[esi+ebx*2] | |
db 0xe3,0x83 | |
xchg eax,esi | |
; 長さ調整 | |
db 0xe3,0x81,0x90 | |
dec edi | |
cmp al,0x75 | |
; ジャンプの距離に合わせて調整すること | |
jb loop2 | |
db 0x9B,0x9B ; fwait : supposedly do viatually nothing | |
inc ebx | |
; 長さ調整 | |
inc ebp | |
dec ebp | |
; cmp ebx,8 | |
db 0xe3,0x81 | |
xchg eax,ebx | |
db 0xe3,0x82 | |
test al,0x28 | |
; ジャンプの距離に合わせて調整すること | |
jz loop1 | |
db 0x97 | |
; 長さ調整 | |
db 0xe3,0x81,0x97 | |
db 0xe3,0x82,0x90 | |
db 0xe3,0x81 | |
test al,0x57 | |
jna loop1 ; CF=1 or ZF=1 : test -> CF=0 | |
db 0xb7,0x7A | |
; 出力する ---------------------------------------- | |
; eax = 4 | |
db 0xe3,0x81 | |
mov ebx,0xE5AF81E7 | |
db 0x92,0x92 | |
db 0xe3,0x81 | |
mov eax,0xE5AF81E3 | |
nop | |
nop | |
xor ebx,eax | |
db 0x97 ; xchg eax,edi -> not needed to return | |
; ebx = 1 | |
db 0xe3,0x82 | |
mov eax,0x8682E353 | |
xor eax,0x8782E354 | |
and eax,0x8482E351 | |
db 0xe3,0x82 | |
xchg eax,ebx | |
db 0xe3,0x82 | |
; ecx = esp | |
lea ecx,[esp+0x22] | |
; edx = 0x73 | |
db 0xe3,0x82 | |
mov dl,0x73 | |
%if ($ - _start) % 2 == 1 | |
; dwを用いるので、奇数の場合埋めないと死ぬ | |
inc edi | |
%endif | |
; 調整不能(数字で書く) | |
; UTF-8としてはvalidだが、機種依存文字として弾かれる | |
int 0x80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; for(diff=2;diff<=16;diff+=2) { | |
; for(c=0x24;c<=0x74;c+=diff)putchar(c); | |
; } | |
; total 115 chars | |
bits 32 | |
global _start | |
section .text | |
_start: | |
; generete the string | |
mov esi,esp | |
mov ah,2 | |
loop1: | |
mov al,0x24 | |
loop2: | |
mov byte [esi],al | |
inc esi | |
add al,ah | |
cmp al,0x75 | |
jb loop2 | |
add ah,2 | |
cmp ah,16 | |
jbe loop1 | |
; print it | |
xor ah,ah | |
mov al,4 | |
mov bl,1 | |
mov ecx,esp | |
mov dl,115 | |
int 0x80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment