Native self-modifying code on Android

前端 未结 1 1068
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 13:05

I am trying to make some self-modifing native code on Android and run it in the emulator. My sample is based on the HelloJNI sample from the android-ndk. It looks like this:

相关标签:
1条回答
  • 2021-02-08 13:33

    At a guess, nope() was compiled as Thumb, but you're calling it as ARM (assuming mmap returns a word-aligned pointer). To call Thumb code, the low bit of the address should be set. Try something like this:

    ( (FUNC)(((unsigned int)code)|1) )();
    

    To do it properly, you should ensure alignment of the allocated memory (2 for Thumb and 4 for ARM), make sure that the code you're trying to run is Thumb (or ARM) and set the bit 0 accordingly.

    0 讨论(0)
提交回复
热议问题