0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

picoCTF 2019 writeup asm2

Last updated at Posted at 2025-12-09

asm2 (Reverse Engineering)

What does asm2(0x4,0x2d) return? Submit the flag as a hexadecimal value (starting with '0x'). NOTE: Your submission for this question will NOT be in the normal flag format. Source

添付ファイル
・test.S

test.Sを確認する。

asm2:
	<+0>:	push   ebp
	<+1>:	mov    ebp,esp
	<+3>:	sub    esp,0x10
	<+6>:	mov    eax,DWORD PTR [ebp+0xc]
	<+9>:	mov    DWORD PTR [ebp-0x4],eax
	<+12>:	mov    eax,DWORD PTR [ebp+0x8]
	<+15>:	mov    DWORD PTR [ebp-0x8],eax
	<+18>:	jmp    0x50c <asm2+31>
	<+20>:	add    DWORD PTR [ebp-0x4],0x1
	<+24>:	add    DWORD PTR [ebp-0x8],0xd1
	<+31>:	cmp    DWORD PTR [ebp-0x8],0x5fa1
	<+38>:	jle    0x501 <asm2+20>
	<+40>:	mov    eax,DWORD PTR [ebp-0x4]
	<+43>:	leave  
	<+44>:	ret    

第1引数0x4、第2引数0x2dを渡す。
<+6>と<+9>でebp-0x4に0x2d、<+12>と<+15>でebp-0x8に0x4を渡している。
<+18>の無条件ジャンプで<+31>にジャンプする。
<+31>で0x5fa1と0x4を比較し、<+38>で条件に当てはまるので<+20>にジャンプする。
<+20>で0x2d+0x1=0x2e。
<+24>で0x4+0xd1=0xd5。
<+31>で0x5fa1と0xd5を比較。

以上より、この処理は、0x4に0xd1を加算して0x5fa1を超えるまでの繰り返し回数をreturnとしている。
0x5fa1 / 0xd1 = 0x75(余り あり)
であるから、初期値0x2dに0x76を加算して0xA3が最終的なeaxの値である。

フラグが得られた。

0xa3

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?