我怎样才能防止strcpy()被优化 [英] How can I prevent strcpy() being optimised
问题描述
我在黑客攻击:剥削的艺术一书中学习了一个例子,我得到了不同的结果。
似乎strcpy()函数编译为如下指令:
0x802384c5< main + 27> ;:调用0x80482C4< strcpy @ plt>
然而,当我编译相同的程序时,它将删除对库的调用并用一系列mov指令:
0x8048475< main + 25> ;: mov DWORD PTR [eax],0x6c6c6548
0x804847b<主+ 31计算值:MOV DWORD PTR [EAX +为0x4],0x6f57206f
0x8048482<主+ 38计算值:MOV DWORD PTR [EAX + 0x8中],0x21646c72
0x8048489<主+ 45计算值:MOV WORD PTR [eax + 0xc],0xa
据我所知,编译器可以进行各种优化,虽然它是默认的,我甚至试着用-O0来编译它,以防止优化。
如何编译代码以便引用外部库? / p>
自从uni以来,我还没有做过任何C或汇编程序,所以请对我轻轻一点:) 方案使用GCC,你可以使用 -fno-builtin
(禁用所有内建函数)或 -fno-builtin-strcpy
(只是禁用内置 strcpy
)。
I'm following an example in the book Hacking: The Art of Exploitation and I am getting different results to the book.
It seems that the strcpy() function in the example compiles to an instruction like:
0x802384c5 <main+27>: call 0x80482C4 <strcpy@plt>
whereas when I compile the same program it removes the call to the library and replaces it with a series of mov instructions:
0x8048475 <main+25>: mov DWORD PTR [eax],0x6c6c6548
0x804847b <main+31>: mov DWORD PTR [eax+0x4],0x6f57206f
0x8048482 <main+38>: mov DWORD PTR [eax+0x8],0x21646c72
0x8048489 <main+45>: mov WORD PTR [eax+0xc],0xa
I understand that the compiler can make various optimizations, but even though it's the default I've even tried compiling it with -O0 which is supposed to prevent optimisations.
How can I compile the code so it references the external library?
I've not done any C or assembly since uni, so be gentle with me :)
With GCC, you can use the -fno-builtin
(disable all builtins) or -fno-builtin-strcpy
(just disable builtin strcpy
).
这篇关于我怎样才能防止strcpy()被优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!