johnno1962 / HotReloading

Hot reloading as a Swift Package
MIT License
550 stars 49 forks source link

Cannot reload on M1, getting an “eval101.dylib” can’t be opened because Apple cannot check it for malicious software error. #88

Closed oryonatan closed 11 months ago

oryonatan commented 12 months ago

I've been trying to use HotReloading for an iOS app when running on an Apple Silicon target ("My Mac (Designed for iPhone)").

Whenever I change the a file and the reloading is initiated, I get a security error from my mac saying “eval101.dylib” can’t be opened because Apple cannot check it for malicious software."

What should I do? is there something I can change in the Package.swift to make my mac recognize this dylib as trusted?

oryonatan commented 12 months ago

this seems related to https://github.com/johnno1962/InjectionIII/issues/178 but this issue is marked as solved.

I am running Mac os 13.6.

johnno1962 commented 12 months ago

Hi, Have you tried using HotRekoading in conjunction with running one of the App releases ? Standalone signing from inside a "My Mac (Designed for iPhone)" may be a big ask. You'll also need to have an environment variable INJECTION_DAEMON to force it to connect to the app.

oryonatan commented 11 months ago

I am using app release 4.7.4, and I've set the INJECTION_DAEMON.

johnno1962 commented 11 months ago

You're running the App, your program is connecting (the icon changed to orange) and it's still not working? Have you tried removing the eval101.dylib file it mentions?

johnno1962 commented 11 months ago

OK. I've been able to reproduce this and know what it is. Let we see if this configuration can be supported.

johnno1962 commented 11 months ago

The old recipe for how to get this particular combination injecting no longer works but I've updated the 4.7.5 release candidate of the app so it allows you to inject using the HotReloading project. Thanks for bringing this up. I'm always happy when people tickle the far reaches of what is possible with the project 👍.

oryonatan commented 11 months ago

Hi @johnno1962 thanks for the fast and kind response!\

I've downloaded the binary from the 4.7.5 RC and checked out HotReloading locally to the latest commit 257a4ea17c22606dc56264df8479d6e71e5dcdf8 iOS running on Mac and I am still getting the same security message ... did I miss any step there?

(BTW I am running my tests on the SwiftUI Kit demo project)

johnno1962 commented 11 months ago

Strange, I definitely fixed something and have just tried SwiftUI Kit with the new app and HotReloading main and it works. You're getting the same popup from the OS as before? Can you check that in the pop down menu on the menu bar, when you hover over the "Quit InjectionIII" cell it show a tooltip with a build number of #7866? The menu bar icon is orange?

oryonatan commented 11 months ago

I've checked by hovering over the Quit InjectionIII menu item and indeed the build number is #7866. The icon is orange, I am still getting this message: image

after pressing ok, it tries a couple of times to open it again until finally giving up here is the full console log:

🔥 Sending multicast packet to connect to your development host redacted-MBP.
🔥 If this fails,hardcode your Mac's IP address in HotReloading/Package.swift
   or add an environment variable INJECTION_HOST with this value.
🔥 You'll need to be running a recent copy of the InjectionIII.app downloaded from https://github.com/johnno1962/InjectionIII/releases?
🔥 And have typed: defaults write com.johnholdsworth.InjectionIII deviceUnlock any
InjectionClient/Could not send multicast ping: No route to host
<SwiftEval: 0x121e096c0>.deinit()
🔥 HotReloading connected /Users/redacted/workspace/SwiftUI-Kit/SwiftUI Kit.xcodeproj
🔥 Watching files under the directory /Users/redacted/workspace/SwiftUI-Kit
LSPrefs: could not find untranslocated node for <FSNode 0x60000210a5c0> { isDir = ?, path = <private> }, proceeding on the assumption it is not translocated: Error Domain=NSPOSIXErrorDomain Code=1
LSPrefs: could not find untranslocated node for <FSNode 0x60000210a5c0> { isDir = ?, path = <private> }, proceeding on the assumption it is not translocated: Error Domain=NSPOSIXErrorDomain Code=1
LSPrefs: could not find untranslocated node for <FSNode 0x60000210a5c0> { isDir = ?, path = <private> }, proceeding on the assumption it is not translocated: Error Domain=NSPOSIXErrorDomain Code=1
Class _UIFindNavigatorViewController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.
LSPrefs: could not find untranslocated node for <FSNode 0x60000210a5c0> { isDir = ?, path = <private> }, proceeding on the assumption it is not translocated: Error Domain=NSPOSIXErrorDomain Code=1
🔥 Compiling /Users/redacted/workspace/SwiftUI-Kit/Shared/ContentView.swift
🔥 Selecting Xcode /Applications/Xcode15.app/Contents/Developer
🔥 Loading .dylib ...
🔥 ⚠️ dlopen() error: dlopen(/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib, 0x0002): tried: '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-iphoneos/eval101.dylib' (no such file), '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-watchos/eval101.dylib' (no such file), '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (code signature in <09102868-9916-3389-BD40-2A682DE914F2> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (code signature in <09102868-9916-3389-BD40-2A682DE914F2> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' not valid for use in process: library load disallowed by system policy)
🔥 ⚠️ Injection error: Error Domain=SwiftEval Code=-1 "dlopen() error: dlopen(/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib, 0x0002): tried: '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-iphoneos/eval101.dylib' (no such file), '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-watchos/eval101.dylib' (no such file), '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (code signature in <09102868-9916-3389-BD40-2A682DE914F2> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (code signature in <09102868-9916-3389-BD40-2A682DE914F2> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' not valid for use in process: library load disallowed by system policy)" UserInfo={NSLocalizedDescription=dlopen() error: dlopen(/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib, 0x0002): tried: '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-iphoneos/eval101.dylib' (no such file), '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-watchos/eval101.dylib' (no such file), '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (code signature in <09102868-9916-3389-BD40-2A682DE914F2> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' (code signature in <09102868-9916-3389-BD40-2A682DE914F2> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval101.dylib' not valid for use in process: library load disallowed by system policy)}
🔥 Compiling /Users/redacted/workspace/SwiftUI-Kit/Shared/ContentView.swift
🔥 Loading .dylib ...
🔥 ⚠️ dlopen() error: dlopen(/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib, 0x0002): tried: '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-iphoneos/eval102.dylib' (no such file), '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-watchos/eval102.dylib' (no such file), '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (code signature in <7BA22EC2-AB55-35F4-84EB-501C920C9F40> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (code signature in <7BA22EC2-AB55-35F4-84EB-501C920C9F40> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' not valid for use in process: library load disallowed by system policy)
🔥 ⚠️ Injection error: Error Domain=SwiftEval Code=-1 "dlopen() error: dlopen(/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib, 0x0002): tried: '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-iphoneos/eval102.dylib' (no such file), '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-watchos/eval102.dylib' (no such file), '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (code signature in <7BA22EC2-AB55-35F4-84EB-501C920C9F40> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (code signature in <7BA22EC2-AB55-35F4-84EB-501C920C9F40> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' not valid for use in process: library load disallowed by system policy)" UserInfo={NSLocalizedDescription=dlopen() error: dlopen(/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib, 0x0002): tried: '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-iphoneos/eval102.dylib' (no such file), '/Users/redacted/Library/Developer/Xcode/DerivedData/SwiftUI_Kit-bivomvtiddrttdamkikxglswesil/Build/Products/Debug-watchos/eval102.dylib' (no such file), '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/System/iOSSupport/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (code signature in <7BA22EC2-AB55-35F4-84EB-501C920C9F40> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (no such file), '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' (code signature in <7BA22EC2-AB55-35F4-84EB-501C920C9F40> '/Users/redacted/Library/Containers/2DA45651-72DB-494F-B3F2-0683E3CCA9A2/Data/tmp/eval102.dylib' not valid for use in process: library load disallowed by system policy)}
johnno1962 commented 11 months ago

One last suggestion, can you try launching with an INJECTION_HOST environment variable in your scheme with the value localhost or 127.0.0.1? At the minimum this will help cut down some of the noise.

oryonatan commented 11 months ago

Hi! that seemed to solve the issue!

oryonatan commented 11 months ago

this will probably make injection stop working on device though, right?

johnno1962 commented 11 months ago

Ah, yes, that's right but you'll know why and be able to fix it. It uses the fact it's a local connection to avoid having the app write the .dylib file which is what happens with device injection. I'll see if there is any more I can do about this. Would you know the reliable combination of #ifs to detect iOS on Mac from inside an Objective-C source by any chance?

oryonatan commented 11 months ago

that'll be NSProcessInfo.isIOSAppOnMac https://developer.apple.com/documentation/foundation/nsprocessinfo/3608556-iosapponmac?language=objc

johnno1962 commented 11 months ago

Hmm, yeah you could but that doesn't play well with #ifs and would involve revisiting some fairly dense code I really don't want to have to retest at this stage even it is overdue. I've pushed a new build of the release candidate which should identify a "wider variety of local connections" if you'd like to test it out without the INJECTION_HOST override and let me know how you get on.

oryonatan commented 11 months ago

Latest build seems to work well both on an attached iPhone, and My Mac (Designed for iPhone)🎉

johnno1962 commented 11 months ago

Without the override? That's great! The situation with My Mac (Designed for iPhone) could be better but you may be only one of very few people trying to use it so there is a limit to how much attention it gets. Certainly, I don't want to regress "core users" i.e. iOS in simulator. When you're happy feel free to close this issue and thanks again for pushing the limits and taking the time to raise an issue!

oryonatan commented 11 months ago

Yes it works without any override!

Another - very related topic is that it seems like (in iOS17 at least), when attaching a device by USB the computer establishes a direct network with this device. The network appears as a new en interface with both the Mac and the connected iPhone getting an APIPA address (169.254.xxx.xxx).

Initially trying to use this network doesn't seem to work ... I suspect that there is no local name service running there so the iPhone cannot find the mac using the host name, however I am able to use this network if I hardcode the mac IP address in the INJECTION_HOST variable.

So I wonder if there is any way for the iPhone to find the mac over such network? I guess a broadcast should work here as there are only two devices in this network...

oryonatan commented 11 months ago

BTW regarding people not using My Mac (Designed for iPhone) with injection - in my team it is quite common use case! Our iOS app is quite large, and developing on the mac has the benefit of faster installs which saves us time in the normal day-to-day (and you don't have to worry about the device locking itself or forgetting the cable at home).

johnno1962 commented 11 months ago

I'm surprised you use My Mac (Designed for iPhone) to be honest. I've found the launch times for even the tiniest project very slow but I guess if you use injection the launch time matter right? Re: device connections and broadcasts it's a difficult problem. The simplest approach is that in Package.swift which compiles your Mac's hostname into your app to connect to which generally works. It then falls back to sending a broadcast packet but the code is naive and while it used to be very reliable on my machine it gives a "No route to host" error now and it was never clear if that was because the OS changed or because I reconfigured my home network around that time. The last option is the INJECTION_HOST variable which is at least simple.

If you're up and running I think I'll leave things as they are for now and I'm happy we've found a better solution for My Mac (Designed for iPhone) for those who want to use it.

johnno1962 commented 11 months ago

Closing this now, thanks for dusting this feature off.