johnno1962 / InjectionNext

Fourth evolution of Code Injection for Xcode
MIT License
76 stars 2 forks source link

Not connecting with physical device #2

Closed lachlanhawthorne closed 4 months ago

lachlanhawthorne commented 5 months ago

Hi there,

I'm experiencing an issue with InjectionNext on a physical iOS device. While it works fine on the simulator, I can't get it to connect when running on my device. Here's what I've done:

Setup steps:

  1. Run InjectionNext.app from /Applications
  2. Launch Xcode from InjectionNext
  3. Add -Xlinker and -interposable to "Other Linker Flags" (Debug config only and across multiple lines)
  4. Select "Enable Devices" in InjectionNext
  5. Enter ${EXPANDED_CODE_SIGN_IDENTITY} in the popup
  6. Add the clipboard copy_test_frameworks.sh script to a "Run Script" Build Phase
if [ -f "/Applications/InjectionNext.app/Contents/Resources/copy_test_frameworks.sh" ]; then
    "/Applications/InjectionNext.app/Contents/Resources/copy_test_frameworks.sh"
fi

Issue:

When running on a physical device, the app doesn't connect to InjectionNext. I see these messages:

🔥 InjectionNext: Locating developer's Mac. Have you selected "Enable Devices"?
Broadcasting to pdp_ip0.8:192.0.0.2 to locate InjectionNext host...
Broadcasting to en0.21:192.168.0.255 to locate InjectionNext host...

Environment:

Any help or suggestions would be greatly appreciated. Thanks for your work on this fantastic tool!

johnno1962 commented 5 months ago

Connecting over the network can be a bit tricky. Can you unplug and reconnect your deivce? Sometimes the USB network doesn't come up the first time. Look for a 169.something network.

lachlanhawthorne commented 5 months ago

Thank you so much for the quick response! I've tried the following:

Still seeing similar broadcast messages:

🔥 InjectionNext: Locating developer's Mac. Have you selected "Enable Devices"?
Broadcasting to pdp_ip0.3:192.0.0.2 to locate InjectionNext host...
Broadcasting to en2.16:169.254.255.255 to locate InjectionNext host...
Broadcasting to en0.22:192.168.0.255 to locate InjectionNext host...

I have noticed that the app icon turns to yellow after a while, but I can't get an error message from the "Show Last Error" popup, I just get "No error."

I'll keep investigating for a bit. Is there anything specific I should keep an eye out for or look into that might help solve this issue? I'm keen to help troubleshoot and get this working from my end.

lachlanhawthorne commented 5 months ago

NB: I am using InjectionNext 1.0.8 from the zip file

I've attached a copy of the source code I am using for reference: HotReloadingExample.zip

johnno1962 commented 5 months ago

Thanks for the detailed reprt. When you selected "Enable Deivces" was there a system popup asking "Do you want the application “InjectionNext.app” to accept incoming network connections?". Have you clicked "Deny" at some time in the past? If so, can you build you own versio of the app and try that, clicking "Allow". The other thing to check is whether the port is open:

Johns-Mac-mini:API $ netstat -an | grep 8887
tcp4       0      0  *.8887                 *.*                    LISTEN     

It's important there is a "*.8887" there.

lachlanhawthorne commented 5 months ago

Thanks so much for your help.

I built the app from the repo and got the "Accept incoming network connections" prompt, where I clicked "Allow." Additionally, running netstat -an | grep 8887 returned:

tcp4       0      0  *.8887                 *.*                    LISTEN
udp4       0      0  *.8887                 *.*                    

Unfortunately I still can't get it to work - I'll use InjectionIII in the meantime. It seems quite weird and may be an issue with my setup. I'll look further into it and circle back later.

Thanks again for your assistance.

johnno1962 commented 5 months ago

Try running the app from the command line and looking out for the message:

        NSLog(@"%@: Multicast recvfrom %s (%s) %u c.f. %u\n",

Either the packet isn't making it to your machine for some reason or it is not being "echoed" if the "hshes" of your identity (path to your home directory) are not the same. More likely though, your network seems a little unusual. I've not seen a 192.0.. network before. That shouldn't matter though as the 169.254.255.255 USB network seems to be up now.

lachlanhawthorne commented 4 months ago

I was able to resolve this issue:

To run InjectionNext from command line:

/Applications/InjectionNext.app/Contents/MacOS/InjectionNext

To anyone looking to quickly get the Expanded Code Signing Identity, you can add this script to build phase:

echo "Expanded Code Signing Identity: ${EXPANDED_CODE_SIGN_IDENTITY}" >> ${PROJECT_DIR}/expanded_codesign_identity.log

This creates a expanded_codesign_identity.log file in the project directory containing the the Expanded Code Signing Identity

Thanks for your quick help and this fantastic library.

Closing issue as it's now working smoothly.

johnno1962 commented 4 months ago

Happy you got things up and running. It was probably your firewall tripping things up. You should be able to replace your script with a defaults write com.johnholdsworth.InjectionNext signingidentity "${EXPANDED_CODE_SIGN_IDENTITY}" to poke the value directly into the app.