Self modifying code always segmentation faults on Linux

前端 未结 3 903
忘了有多久
忘了有多久 2020-12-01 10:17

i found an article about self modifying code and tried to do some examples, but i get always segmentation faults. As fas as i can understand, there is a violation in memory

3条回答
  •  有刺的猬
    2020-12-01 10:18

    Modern CPUs have a feature called DEP which prevents execution of code on the stack. Previously, this was possible; now, it is not. The binary is loaded into read-only memory by default.

    With that out of the way, you can use the mprotect system call to mark your binary's location in memory as executable - SO LONG AS YOUR CODE IS NOT DEP-PROTECTED. So don't try to put code and the stack and then jump into it.

提交回复
热议问题