Execute Instructions From The Heap

后端 未结 4 1263
失恋的感觉
失恋的感觉 2020-12-11 09:53

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 ex

4条回答
  •  星月不相逢
    2020-12-11 10:21

    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.

提交回复
热议问题