johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 564 forks source link

AppCode patch issue #188

Open arthabus opened 7 years ago

arthabus commented 7 years ago

While I was finally able to run injection with AppCode and iOS device there are still issues I'm seeing which may probably help to improve this great plugin further.

After setting up Xcode injection (I'm using unsigned Xcode 8.1 as per your other post) I've installed Injection plugin (v3.6) into AppCode (v2016.2.4) and patched the project resulting in the following main.m file:

======= begin main.m ===========

import <UIKit/UIKit.h>

import "AppDelegate.h"

int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }

// From here to end of file added by Injection Plugin //

ifdef DEBUG

define INJECTION_PORT 31444 // AppCode

static char _inMainFilePath[] = FILE; static const char *_inIPAddresses[] = {, 0};

define INJECTION_ENABLED

import "/Users/username/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources//BundleInjection.h"

endif

======= end main.m ===========

Which doesn't compile because of incomplete _inIPAddresses.

I can also see the following error in AppCode log:

Error:/Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/MacOS/InjectionPlugin: mmap() error 1 at address=0x117106000, size=0x00018000 segment=__TEXT in Segment::map() mapping /Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/MacOS/InjectionPlugin" UserInfo={NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/MacOS/InjectionPlugin, NSDebugDescription=dlopen_preflight(/Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/MacOS/InjectionPlugin): no suitable image found. Did find:

Error:/Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/MacOS/InjectionPlugin: mmap() error 1 at address=0x10F348000, size=0x00018000 segment=__TEXT in Segment::map() mapping /Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/MacOS/InjectionPlugin, NSBundlePath=/Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin, NSLocalizedDescription=The bundle “InjectionPlugin” couldn’t be loaded because it is damaged or missing necessary resources.}

When I've manually set the _inIPAddresses array as per Xcode patch (just copy pasted the ip array from main.m produced by patch from Xcode which works fine) it compiled and I was able to inject code though the error above still appeasr in log.

I'm also seeing occasional disconnects from device when on subsequent injections plugin says "application not running/connected" so I have to rebuild everything in order for plugin to reconnect which is kinda annoying - I'll investigate if it's often or not but since I've installed during past 24 hours it's disconnected 3-4 times.

AppCode 2016.2.4 Build #OC-162.2573.4, built on November 9, 2016 JRE: 1.8.0_112-release-287-b3 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Xcode 8.1 (8B62)

Plugin version - as per master brunch on December 3, 2016

I'm happy to provide any additional information which may help to investigate further

Thanks again for the great work!

Ricardo1980 commented 7 years ago

I receive the same error message: "no suitable image found. Did find:"

johnno1962 commented 7 years ago

I think the error message is coming from “xcodebuild” which you may need to unsign as well if it’s affecting you. As for the disconnects it could be a network problem. Try using localhost 127.0.0.1 in the ipAddrs array.

arthabus commented 7 years ago

xcode is actually unsigned.

as for appcode plugin - I've found it pretty unusable with the version I've specified: it constantly losses connection, silently fails to inject code (no effect after injection), lags when injecting code so it's often not clear if the injection process started or nor not and after a while it starts injecting (or doesn't - it depends).

It works pretty stable with Xcode though so I've switched from AppCode to Xcode for injection.

For for the tool anyway - it helps to save time if used properly.

johnno1962 commented 7 years ago

Sounds like AppCode needs some looking at, I’ve not done so for a while now. If only I could remember how it worked...

johnno1962 commented 7 years ago

There is a new version of injection http://johnholdsworth.com/injection.html which has it’s own AppCode Plugin you may have more luck with.

arthabus commented 7 years ago

Thanks a lot for the reference - I'll definitely give it a try!