从堆执行指令 [英] Execute Instructions From The Heap
问题描述
我可以在堆上分配一个块,将其字节设置为与函数调用及其参数相对应的值,然后使用函数调用和取消引用运算符执行该序列吗?
问题在于堆位于数据段中,并且当今的CPU /操作系统已采取措施来防止这种情况的发生。一种行为(被称为NX位,对于x86 CPU称为No-eXecute位)。如果一个段标记为NX,则无法从中执行代码。这样做是为了阻止计算机病毒使用缓冲区溢出将可执行代码放置在数据/堆/堆栈存储器中,然后尝试调用程序执行此类代码。
请注意,DLL和库加载在 code 段中,这当然允许代码执行。
Can I allocate a block on the heap, set its bytes to values that correspond to a function call and its parameters, then use the function call and dereference operators to execute that sequence?
So if I read you right you want to dynamically create CPU assembly instructions on the heap and execute them. A bit like self-modifying code. In theory that's possible, but in practice maybe not.
The problem is that the heap is in a data segment, and CPU's/operating systems nowadays have measures to prevent exactly this kind of behavior (it's called the NX bit, or No-eXecute bit for x86 CPUs). If a segement is marked as NX, you can't execute code from it. This was invented to stop computer virusses from using buffer overflows to place exectuable code in data/heap/stack memory and then try the calling program to execute such code.
Note that DLL's and libraries are loaded in the code segment, which of course allows code execution.
这篇关于从堆执行指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!