Skip to content

[Feature Request] Enable preload mode on macOS with SIP disabled #558

@ZeppLu

Description

@ZeppLu

Describe the bug

Currently bear silently enforces wrapper mode on macOS. This behavior causes cross compilers (eg mingw) fail to be recognized.

However, if SIP is disabled, we can actually use DYLD_INSERT_LIBRARIES without any problem. Here is a minimal example:

~/Documents/preload-test cat main.c 
#include <stdio.h>

void impossible() {
        printf("hijack succ\n");
}

int main() {
        return 0;
}
~/Documents/preload-test clang main.c -O0 -o main                                  
~/Documents/preload-test cat preload.c 
extern void impossible();

__attribute__((destructor)) void deinit() {
        impossible();
}
~/Documents/preload-test clang preload.c -O0 -shared -Wl,-U,_impossible -o preload.dylib 
~/Documents/preload-test DYLD_INSERT_LIBRARIES=preload.dylib ./main                     
hijack succ

Expected behavior

On macOS, dynamically check for SIP status at runtime, to determine whether we can use preload mode.

Additionally, a warning log when wrapper mode is being enforced would be helpful

Environment:

  • OS name: macOS
  • OS version: Sonoma 14.1.2
  • OS architecture: x86_64
  • Bear version: 3.1.3
  • Bear install method: macports

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions