MacOS: loading one or another system environment at run time depending on availability

I am working on a macOS tool that uses the Apple Safari framework. When working on macOS 10.13, the tool binds and loads it from

/System/Library/PrivateFrameworks/Safari.framework

and everything is working fine. But when working on macOS 10.12.6, some types of behavior are missing. Based on some research with DTrace, I think this is because my tool should load the latest Staged structure here, which is located here:

/System/Library/StagedFrameworks/Safari/Safari.framework

This, apparently, is what Safari does, because if I join Safari with lldb and run image list, in 10.13 the list includes only the old path, and in 10.12.6 only the last.

I tried the following:

NSBundle* stagedBundle = [NSBundle bundleWithPath:@"/System/Library/StagedFrameworks/Safari/Safari.framework"];

nil 10.13, . 10.12.6 a stagedBundle, :

NSBundle* privateBundle = [NSBundle bundleForClass:[BookmarksController class]];
[privateBundle unload];
[stagedBundle load];

, -, , , -description , Private bundle (), Staged bundle ( ), .

. (1) -bundleForClass:, , , , , . (2) -respondsToSelector:, , , , Staged framework, NO.

_CFBundleFlushBundleCaches(), , .

FRAMEWORK_SEARCH_PATHS Staged framework Mac , , , , .

?

UPDATE

. Apple Framework Programming Guide, , , . :

  • NSBundle -load -unload
  • ,
    • > , Safari, .
    • > -weak_framework Safari
    • > Staged path , , macOS 10.12.6, .

, 10.13, 10.12.6, , -, - 10.12.6. NSLog , , , , Staged framework.

?

+4
1

-, : , . .

, , , Safari , dyld DYLD_VERSIONED_FRAMEWORK_PATH.

dyld :

, . . dyld LC_ID_DYLIB current_version . Dyld . , current_version, , . DYLD_FRAMEWORK_PATH, , , , . . Dyld Info.plist, . Dyld -current_version, .

, , dyld , , . versioned , .

Safari dyld DYLD_VERSIONED_FRAMEWORK_PATH, LC_DYLD_ENVIRONMENT. DYLD_* , dyld , . DYLD_VERSIONED_FRAMEWORK_PATH , .

, , :

OTHER_LDFLAGS = -Wl,-dyld_env -Wl,DYLD_VERSIONED_FRAMEWORK_PATH=/System/Library/StagedFrameworks/Safari;

/S/L/PrivateFrameworks/Safari.framework, . , .


, :

, -, , , - , Private bundle (), Staged bundle ( ), , .

, Objective-C, . , , , , "" NSBundle, dyld .

> Staged path Private, , macOS 10.12.6, .

Framework - , . dyld, .

+3

Source: https://habr.com/ru/post/1695087/


All Articles