我是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'意思是“宽”,并且将指令的所有字节放在同一行上,而不管列的宽度如何)。 –