我是CS學生,學習IA-32程序集。對於一個項目,我們已經獲得了一個程序的可執行文件。我們可以使用objdump
等工具來檢查二進制文件,但不允許看到原始的源代碼。該程序接受一個輸入字符串並將其與另一個神祕字符串進行比較。如果兩個字符串都是不是相同,程序會發出警報,並且我放棄了這個任務。這將是一個有趣的任務...如果電訊局長會打擾回答我的問題... Grr ...閱讀IA32彙編代碼 - 確定隱藏的字符串?
所以,如果你不介意給我一些指針,我想問問論壇如果我走在正確的軌道上。當我的代碼可執行文件運行objdump -d CODE
,我可以深入看到這個在main()函數:
08048a44 <main>:
...
8048af6: e8 d0 08 00 00 call 80493cb <get_string>
8048afb: 89 04 24 mov %eax,(%esp)
8048afe: e8 ad 00 00 00 call 8048bb0 <test_string>
我有理由確信get_string()
從用戶獲取一個字符串 - 它可能是一個包裝函數對於fscanf()
或其他 - 然後指向該字符串的指針被保存到寄存器%eax
。下一行將指針移動到%esp
,然後調用test_string()
。下面是代碼:
08048bb0 <test_string>:
8048bb0: 83 ec 1c sub $0x1c,%esp
8048bb3: c7 44 24 04 6c a4 04 movl $0x804a46c,0x4(%esp)
8048bba: 08
8048bbb: 8b 44 24 20 mov 0x20(%esp),%eax
8048bbf: 89 04 24 mov %eax,(%esp)
8048bc2: e8 bd 04 00 00 call 8049084 <cmp_strings>
8048bc7: 85 c0 test %eax,%eax
8048bc9: 74 05 je 8048bd0 <test_string+0x20>
8048bcb: e8 bc 07 00 00 call 804938c <alarm>
8048bd0: 83 c4 1c add $0x1c,%esp
8048bd3: c3 ret
這就是我認爲正在發生的事情...
08048bb0 <test_string>:
8048bb0: sub $0x1c,%esp // Adjusts %esp for new function
8048bb3: movl $0x804a46c,0x4(%esp) // test_string is stored at $0x804a46c; move that pointer into %esp
8048bba: // ???
8048bbb: mov 0x20(%esp),%eax // Moves test_string ptr to %eax
8048bbf: mov %eax,(%esp) // Moves test_string ptr to %esp - not sure why...?
8048bc2: call 8049084 <cmp_strings> // Calls cmp_strings(), probably with %eax and %esp as argument strings
8048bc7: test %eax,%eax // %eax is the returned value
8048bc9: je 8048bd0 <test_string+0x20> // Should we jump to alarm()?
8048bcb: call 804938c <alarm> // If we reach here, I flunk
8048bd0: add $0x1c,%esp // restores %esp to original value
8048bd3: ret // exits
所以......如果我是對的,線#2是這裏最重要的一個。我懷疑神祕字符串存儲在內存地址$0x804a46c
。但我不確定。我還注意到,當我使用字符串工具時,我看到:
[linux]$ strings -t x CODE | grep 46c
246c My dog has fleas.
[linux]$
這是有希望的......但不具有說服力。內存地址$0x804a46c
不是246c
。
所以......對於這篇冗長的文章道歉,但人們可以告訴我,如果我在正確的軌道上?任何洞察力或智慧是瘋狂的讚賞!
非常感謝! -RAO
使用'objdump'來查看給定地址處的字符串。 'strings'給你文件偏移量,而不是虛擬地址。當然,如果您再次使用'objdump'查看節標題,那麼也可以翻譯它們。 – Jester
地址爲「8048bba」的「神祕操作碼」只是前面指令的一部分。它可能包含在下一行,因爲指令編碼太長了。請注意,指令中的值是'0x804a46c','6c''a4'和'04'全部列在前一行。 – davmac
@davmac:是的,正好。我通常使用'objdump -drwC'來避免('-w'意思是「寬」,並且將指令的所有字節放在同一行上,而不管列的寬度如何)。 –