2012-05-18 33 views
-3

這只是該文件的一個剪輯。這是炸彈中的一個級別。每個級別都由用戶的輸入消除。我們應該解釋反彙編的代碼來確定輸入的內容。在這個特定的級別中,用戶必須輸入5個數字。一旦提供了5個數字,他們就會在這個反彙編代碼中被檢查。如果他們不工作,那麼炸彈就會爆炸。我已經完成了它,並提出了一些關於數字的規則,但有些部分我無法解釋。主要涉及到循環。組裝中的循環 - (澄清)

下面是引用的反彙編代碼:

8048eae:  55      push %ebp 
8048eaf:  89 e5     mov %esp,%ebp 
8048eb1:  83 ec 28    sub $0x28,%esp 
8048eb4:  c7 45 f8 00 00 00 00 movl $0x0,0xfffffff8(%ebp) 
8048ebb:  8d 45 e4    lea 0xffffffe4(%ebp),%eax 
8048ebe:  89 44 24 04    mov %eax,0x4(%esp) 
8048ec2:  8b 45 08    mov 0x8(%ebp),%eax 
8048ec5:  89 04 24    mov %eax,(%esp) 
8048ec8:  e8 69 06 00 00   call 8049536 <read_five_numbers> 
8048ecd:  8b 45 e4    mov 0xffffffe4(%ebp),%eax 
8048ed0:  83 f8 1a    cmp $0x1a,%eax 
8048ed3:  74 05     je  8048eda <level_3+0x2c> 
8048ed5:  e8 a6 10 00 00   call 8049f80 <explode_bomb> 
8048eda:  c7 45 fc 00 00 00 00 movl $0x0,0xfffffffc(%ebp) 
8048ee1:  eb 2c     jmp 8048f0f <level_3+0x61> 
8048ee3:  8b 45 fc    mov 0xfffffffc(%ebp),%eax 
8048ee6:  8b 54 85 e4    mov 0xffffffe4(%ebp,%eax,4),%edx 
8048eea:  8b 45 fc    mov 0xfffffffc(%ebp),%eax 
8048eed:  83 c0 01    add $0x1,%eax 
8048ef0:  8b 44 85 e4    mov 0xffffffe4(%ebp,%eax,4),%eax 
8048ef4:  39 c2     cmp %eax,%edx 
8048ef6:  7f 05     jg  8048efd <level_3+0x4f> 
8048ef8:  e8 83 10 00 00   call 8049f80 <explode_bomb> 
8048efd:  8b 45 fc    mov 0xfffffffc(%ebp),%eax 
8048f00:  8b 44 85 e4    mov 0xffffffe4(%ebp,%eax,4),%eax 
8048f04:  0f af 45 fc    imul 0xfffffffc(%ebp),%eax 
8048f08:  01 45 f8    add %eax,0xfffffff8(%ebp) 
8048f0b:  83 45 fc 01    addl $0x1,0xfffffffc(%ebp) 
8048f0f:  83 7d fc 03    cmpl $0x3,0xfffffffc(%ebp) 
8048f13:  7e ce     jle 8048ee3 <level_3+0x35> 
8048f15:  8b 45 f4    mov 0xfffffff4(%ebp),%eax 
8048f18:  f7 d8     neg %eax 
8048f1a:  3b 45 f8    cmp 0xfffffff8(%ebp),%eax 
8048f1d:  74 05     je  8048f24 <level_3+0x76> 
8048f1f:  e8 5c 10 00 00   call 8049f80 <explode_bomb> 
8048f24:  c9      leave 
8048f25:  c3      ret 

到目前爲止,我有以下規則來查找的數字:

  • 第一個數字應該是26,因爲比較0X1A的。

  • 有一個for循環,迭代4次,並確保每個數小於當前索引 在此間舉行的號碼是我不確定

  • 前四的總和規則數字應該小於等於某物。
  • 最後的數字應該是否定的第一個數字
+0

目的是什麼? –

+2

當你說「在這個代碼中可以工作的5個數字」時,「工作」意味着什麼? –

+0

這意味着如果用戶提供5個數字的炸彈不應該爆炸 – user1386132

回答

1

基於函數的開始,您可以查看棧佈局,因爲這:

int v[5], c0, c1; 

ebp+e4 | v1 
ebp+e8 | v2 
ebp+ec | v3 
ebp+f0 | v4 
ebp+f4 | v5 
ebp+f8 | c0 
ebp+fc | c1 

我轉錄的代碼進入僞代碼,這應該回答你的問題。當然,爲了便於閱讀,goto可以轉換成do/while循環,一旦你明白了發生了什麼。

8048eae push %ebp       
8048eaf mov %esp,%ebp      
8048eb1 sub $0x28,%esp      

8048eb4 movl $0x0,0xfffffff8(%ebp)   c0 = 0; 
8048ebb lea 0xffffffe4(%ebp),%eax   
8048ebe mov %eax,0x4(%esp)     
8048ec2 mov 0x8(%ebp),%eax     
8048ec5 mov %eax,(%esp)      
8048ec8 call 8049536 <read_five_numbers> read_five_numbers(v); 
8048ecd mov 0xffffffe4(%ebp),%eax   eax = v[0]; 
8048ed0 cmp $0x1a,%eax      
8048ed3 je 8048eda <level_3+0x2c>   unless(eax == 0x1A) 
              { 
8048ed5 call 8049f80 <explode_bomb>   explode_bomb(); 
              } 
8048eda movl $0x0,0xfffffffc(%ebp)   c1 = 0; 
8048ee1 jmp 8048f0f <level_3+0x61>   goto loop_condition; 
              loop_body: 
8048ee3 mov 0xfffffffc(%ebp),%eax   eax = c1; 
8048ee6 mov 0xffffffe4(%ebp,%eax,4),%edx edx = v[eax]; 
8048eea mov 0xfffffffc(%ebp),%eax   eax = c1; 
8048eed add $0x1,%eax      ++eax; 
8048ef0 mov 0xffffffe4(%ebp,%eax,4),%eax eax = v[eax]; 
8048ef4 cmp %eax,%edx      
8048ef6 jg 8048efd <level_3+0x4f>   unless(edx > eax) 
              { 
8048ef8 call 8049f80 <explode_bomb>   explode_bomb(); 
              } 
8048efd mov 0xfffffffc(%ebp),%eax   eax = c1; 
8048f00 mov 0xffffffe4(%ebp,%eax,4),%eax eax = v[eax]; 
8048f04 imul 0xfffffffc(%ebp),%eax   eax *= c1; 
8048f08 add %eax,0xfffffff8(%ebp)   c0 += eax; 
8048f0b addl $0x1,0xfffffffc(%ebp)   ++c1; 
              loop_condition: 
8048f0f cmpl $0x3,0xfffffffc(%ebp)   if(c1 <= 3) { 
8048f13 jle 8048ee3 <level_3+0x35>   goto loop_body; 
              } 
8048f15 mov 0xfffffff4(%ebp),%eax   eax = v[4]; 
8048f18 neg %eax       eax = -eax; 
8048f1a cmp 0xfffffff8(%ebp),%eax   
8048f1d je 8048f24 <level_3+0x76>   unless(c0 == eax) 
              { 
8048f1f call 8049f80 <explode_bomb>   explode_bomb(); 
              } 
8048f24 leave         
8048f25 ret         

所以,如果我讀這個權利,你的號碼必須是:

  • 第一個必須等​​於0x1A的。
  • 第二個必須小於第一個。
  • 第三個必須小於第二個。
  • 第四個必須小於第三個。
  • (1 * second + 2 * third + 3 * fourth)必須等於第五個數字的負數。
+0

非常感謝。這是我所需要的。 – user1386132

+0

結果是num1> num2> num3> num4,這意味着該數字必須小於當前索引處的數字。除此之外,其他一切工作。謝謝。 – user1386132

+0

@ user1386132:對不起!我習慣了英特爾的語法,所以我誤解了'cmp; JG;'。 – DCoder