[英]Binary Bomb phase 4 confirmation
我目前正在研究這個二元炸彈的第 4 階段,並且我已經為此糾結了幾個小時。 這是我目前的筆記。
第 4 階段拆卸
Dump of assembler code for function phase_4:
=> 0x0000000000401016 <+0>: sub $0x18,%rsp //rsp =-24
0x000000000040101a <+4>: lea 0xc(%rsp),%rcx // second input = rcx
0x000000000040101f <+9>: lea 0x8(%rsp),%rdx // first input = rdx
0x0000000000401024 <+14>: mov $0x4027cd,%esi // answer format is %d %d
0x0000000000401029 <+19>: mov $0x0,%eax // compare 0 and eax
0x000000000040102e <+24>: callq 0x400c30 <__isoc99_sscanf@plt>
0x0000000000401033 <+29>: cmp $0x2,%eax // compared 2 and eax
0x0000000000401036 <+32>: jne 0x401044 <phase_4+46> //if not equal to 2 jump to explode bomb
0x0000000000401038 <+34>: mov 0xc(%rsp),%eax // eax = *rsp+12(second input)
0x000000000040103c <+38>: sub $0x2,%eax // subtract 2 from second input
0x000000000040103f <+41>: cmp $0x2,%eax // compare 2 and second input
0x0000000000401042 <+44>: jbe 0x401049 <phase_4+51> // if below 2 then jump to +51
0x0000000000401044 <+46>: callq 0x401544 <explode_bomb>
0x0000000000401049 <+51>: mov 0xc(%rsp),%esi // second input becomes esi
0x000000000040104d <+55>: mov $0x8,%edi // edi becomes 8
0x0000000000401052 <+60>: callq 0x400fde <func4> //go to func4
0x0000000000401057 <+65>: cmp 0x8(%rsp),%eax // compare first input to eax(from func 4)
0x000000000040105b <+69>: je 0x401062 <phase_4+76> //if equal go to 76
0x000000000040105d <+71>: callq 0x401544 <explode_bomb>
0x0000000000401062 <+76>: add $0x18,%rsp
0x0000000000401066 <+80>: retq
func4 反匯編
Dump of assembler code for function func4:
0x0000000000400fde <+0>: push %r12 // push r12 onto stack
0x0000000000400fe0 <+2>: push %rbp // push rbp onto stack
0x0000000000400fe1 <+3>: push %rbx // push rbx onto stack
0x0000000000400fe2 <+4>: mov %edi,%ebx // ebx becomes edi(8)
0x0000000000400fe4 <+6>: test %edi,%edi // test 8 & 8
0x0000000000400fe6 <+8>: jle 0x40100c <func4+46> //if less than or equal to jump to 46
0x0000000000400fe8 <+10>: mov %esi,%ebp // esi(second input) becomes ebp
0x0000000000400fea <+12>: mov %esi,%eax // esi(second input) becomes eax
0x0000000000400fec <+14>: cmp $0x1,%edi // compare 1 and edi(8)
0x0000000000400fef <+17>: je 0x401011 <func4+51> // if equal then jump to 51
0x0000000000400ff1 <+19>: lea -0x1(%rdi),%edi // subtract 1 from edi(8) address
0x0000000000400ff4 <+22>: callq 0x400fde <func4> // call function 4
0x0000000000400ff9 <+27>: lea (%rax,%rbp,1),%r12d
0x0000000000400ffd <+31>: lea -0x2(%rbx),%edi // subtract 2 from edi address
0x0000000000401000 <+34>: mov %ebp,%esi // ebp becomes esi(8)
0x0000000000401002 <+36>: callq 0x400fde <func4> // call func 4
0x0000000000401007 <+41>: add %r12d,%eax // add r12d and eax
0x000000000040100a <+44>: jmp 0x401011 <func4+51> // jump to 51
0x000000000040100c <+46>: mov $0x0,%eax // eax is 0
0x0000000000401011 <+51>: pop %rbx
0x0000000000401012 <+52>: pop %rbp
0x0000000000401013 <+53>: pop %r12
0x0000000000401015 <+55>: retq
以及我對它們如何協同工作的筆記/輸入應該是什么
輸入是“%d %d”
第二個輸入必須是 2,我想
轉到第 51 行
第二個輸入在減去 2 后變為 ESI(0)
EDI變成8
進入功能 4
edx 變成 EDI(8)
測試 edi 和 edi (8 & 8)
我看過其他類似的問題,但我無法理解人們如何得到問題的答案。 我知道有人與 func4 基本相同,但我不太明白有人給出的答案。
我想更好地弄清楚 func 4 的作用。 我認為,因為它從 edi 和 edi(兩者都是 8)之間的測試開始,它會達到 +46,這使得 eax 為 0,但我不知道它從哪里開始。
我很確定第二個輸入必須在 2 和 4 之間,但我不知道第一個輸入的作用。 我很確定第一個通過 func4 並最終等於第一個輸入是什么。
我理解它正確做什么嗎?
非常感謝您。
因此,查看func4
,您的評論在很大程度上重復了指令的作用,而不是每個指令的含義......我建議找出在任何給定時刻各種寄存器包含的內容,以及每一步都在做什么。 像這樣的東西:
Dump of assembler code for function func4:
0x400fde <+0>: push %r12
0x400fe0 <+2>: push %rbp
0x400fe1 <+3>: push %rbx
// Arguments: a in %edi, b in %esi
0x400fe2 <+4>: mov %edi,%ebx // %ebx = a (copy of)
0x400fe4 <+6>: test %edi,%edi
0x400fe6 <+8>: jle 0x40100c <func4+46> // return 0 if a <= 0
0x400fe8 <+10>: mov %esi,%ebp // %ebp = b (copy of)
0x400fea <+12>: mov %esi,%eax // %eax = b (copy of) also
0x400fec <+14>: cmp $0x1,%edi
0x400fef <+17>: je 0x401011 <func4+51> // return b if a == 1
// Have: a in %edi and %ebx -- a > 1; b in %esi and %ebp
0x400ff1 <+19>: lea -0x1(%rdi),%edi // argument a for func4: a - 1
// argument b already in %esi
0x400ff4 <+22>: callq 0x400fde <func4> // func4(a - 1, b)
0x400ff9 <+27>: lea (%rax,%rbp,1),%r12d // r (%r12d) = b + func4(a - 1, b)
// Have: a in %ebx -- a > 1; b in %ebp ; r = b + func4(a - 1, b) in %r12d
0x400ffd <+31>: lea -0x2(%rbx),%edi // argument a for func4: a - 2
0x401000 <+34>: mov %ebp,%esi // argument b for func4: b
0x401002 <+36>: callq 0x400fde <func4> // func4(a - 2, b)
0x401007 <+41>: add %r12d,%eax // b + func4(a - 1, b) + func4(a - 2, b)
0x40100a <+44>: jmp 0x401011 <func4+51> // return result
0x40100c <+46>: mov $0x0,%eax // return 0
0x401011 <+51>: pop %rbx
0x401012 <+52>: pop %rbp
0x401013 <+53>: pop %r12
0x401015 <+55>: retq
所以現在應該可以弄清楚func4()
在做什么,因此,通過類似的分析, phase_4
在做什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.