Hpmason / retour-rs

A cross-platform detour library written in Rust
Other
99 stars 18 forks source link

MacOS fails in CI #5

Open Hpmason opened 1 year ago

Hpmason commented 1 year ago

Most of the MacOS unit tests fail due to a permission error in CI:

Error: RegionFailure(SystemCall(Os { code: 13, kind: PermissionDenied, message: "Permission denied" }))

Requires more testing outside of CI, but I don't have my Macbook on hand atm to fix.

notpeelz commented 1 year ago

Since MacOS Catalina, the linker makes the __TEXT segment read-only (r-x). It's possible to work around it by patching the Mach-O maxprot field. Unfortunately I don't think there's anything you can do to fix this within the bounds of this library.

You can try it out yourself like this:

  1. Run cargo test to build the test binary (the tests should fail)
  2. Patch the maxprot field of the test binary: printf '\x07' | dd of=./target/debug/deps/retour-*whatever* bs=1 seek=160 count=1 conv=notrunc
  3. Run the patched test binary: ./target/debug/deps/retour-*whatever* (the tests should pass)

Funnily enough, the issue also goes away when a debugger is attached.

Hpmason commented 1 year ago

Wow, that's annoying. I see that darfink had a python script to fix that issue. We'll probably need to use their script or something similar to get it working, then.