Closed tobegit3hub closed 4 years ago
It seems that subhook_install
fail with MacOS Catalina 10.15.4 and the tests will work in Linux.
We have traced the code and find out the system call of mprotect
was failed in new MacOS.
The following function returns zero in MacOS and make the _hook
object as NULL.
if (mprotect(address, size, PROT_READ | PROT_WRITE | PROT_EXEC) == 0) ...
Same issue for https://github.com/agiledragon/gomonkey/issues/10 .
https://stackoverflow.com/questions/60654834/using-mprotect-to-make-text-segment-writable-on-macos
As mentioned in this post, in Catalina the linker sets maxprot
in 64-bit executables to read+execute rather than read+write+execute as in earliner versions, which makes mprotect
fail if PROT_WRITE
is passed in the protection flags parameter.
It seems that the only way to make hooking work there is to manually overwrite the flags after compiling your program.
For the subhhok's test program I used this command from the SO post:
printf '\x07' | dd of=tests/Debug/test bs=1 seek=160 count=1 conv=notrunc
Great and this could fix for me.
printf '\x07' | dd of=tests/test bs=1 seek=160 count=1 conv=notrunc
printf '\x07' | dd of=tests/test++ bs=1 seek=160 count=1 conv=notrunc
Here is the error log.