Native Self-modifying Code On Android
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: #defin
Solution 1:
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)(((unsignedint)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.
Post a Comment for "Native Self-modifying Code On Android"