Executing machine code in memory

后端 未结 9 1498
盖世英雄少女心
盖世英雄少女心 2020-12-04 12:47

I\'m trying to figure out how to execute machine code stored in memory.

I have the following code:

#include 
#include          


        
9条回答
  •  甜味超标
    2020-12-04 12:59

    It is more likely that that it is the code that is jumped to by the call through function-pointer that is causing the segfault rather than the call itself. There is no way from the code you have posted to determine that that code loaded into bin is valid. Your best bet is to use a debugger, switch to assembler view, break on the return statement and step into the function call to determine that the code you expect to run is indeed running, and that it is valid.

    Note also that in order to run at all the code will need to be position independent and fully resolved.

    Moreover if your processor/OS enables data execution prevention, then the attempt is probably doomed. It is at best ill-advised in any case, loading code is what the OS is for.

提交回复
热议问题