kubo / plthook

Hook function calls by replacing PLT(Procedure Linkage Table) entries.
745 stars 152 forks source link

Library doesn't support the new LC_DYLD_CHAINED_FIXUPS and LC_DYLD_EXPORTS_TRIE macos linker commands #43

Closed pablogsal closed 2 years ago

pablogsal commented 2 years ago

There are two new load commands added in 10.15 / iOS 13 (http://newosxbook.com/articles/13-10.15.html and can be seen in /Applications.Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach-o/loader.h:324

define LC_DYLD_EXPORTS_TRIE (0x33 | LC_REQ_DYLD) / used with linkedit_data_command, payload is trie /

define LC_DYLD_CHAINED_FIXUPS (0x34 | LC_REQ_DYLD) / used with linkedit_data_command /

Without handling these linker commands, the functionality of the library is restricted to macOS < 10.15

kubo commented 2 years ago

Thanks for reporting the issue.

As far as I checked, the load commands are in programs since macOS 12 though they may be in header files since macOS 10.15. Tests passes on macOS 11 with various compiler/linker flags but not on macOS 12 even with default flags.

kubo commented 2 years ago

I fixed plthook to support LC_DYLD_CHAINED_FIXUPS on macOS (intel). I hope it works also on macOS (arm).

pablogsal commented 2 years ago

Thanks a lot for the fantastic work! I will give it a try in amd64

kubo commented 2 years ago

Reopened because it doesn't work for binary compiled for macOS 12 Monterey (ARM).

make test fails on macOS 12 Monterey hosted on bitrise M1 stacks.

When test files are compiled for macOS 11 Big Sur by setting MACOSX_DEPLOYMENT_TARGET=11, make test passes.

kubo commented 2 years ago

Fixed by https://github.com/kubo/plthook/commit/2bc6fa19d96246c6dfbcee52d3d938b9401f97c7.