johnno1962 / injectionforxcode

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

Keeps on crashing on IvarAccess.h in getTypeEncodingSwift3 #180

Open bilsou opened 7 years ago

bilsou commented 7 years ago

Hi,

This plugin looks great but unfortunately, using an unsigned Xcode 8 and the instructions to build the sources manually, everything seems to work fine until I try to use the plugin via the Ctrl+=.

Here is the bit of code :

`const char ivar_getTypeEncodingSwift3( Ivar ivar, Class aClass ) { struct _swift_class swiftClass = isSwift( aClass ); struct _swift_data3 swiftData = (struct _swift_data3 )swift3Relative( &swiftClass->swiftData ); const char nameptr = swift3Relative( &swiftData->ivarNames ); const char name = ivar_getName(ivar); int ivarIndex;

for ( ivarIndex=0 ; ivarIndex < swiftData->fieldcount ; ivarIndex++ )
        if ( strcmp( name, nameptr ) == 0 ) // crash here, bad_acess
            break;
        else
            nameptr += strlen(nameptr)+1;

` Any idea how to get around this issue ? Thanks

johnno1962 commented 7 years ago

Please use notifications instead of the -injected method for now.

bilsou commented 7 years ago

Thanks, following the instructions here: https://karlbowden.com/quick-start-hot-reloading-in-swift/ I managed to get it working. It has some limitations though, I have some static methods in structs to create some controls like createButton(). Changing the buttonColor inside that static method doesn't work but if I do it where I subclass UIView and call the method it works. I guess I will have to live with that. Thanks again anyway, really handy tool to have

bilsou commented 7 years ago

On a sideI keep note, I just patched the project to have the injection working on a real device and although it keeps on getting the same error

Error loading /var/mobile/Containers/Data/Application/C154B2AF-B49D-460A-85DF-F3150045D1F8/tmp/InjectionBundle2.bundle/InjectionBundle: dlopen(/var/mobile/Containers/Data/Application/C154B2AF-B49D-460A-85DF-F3150045D1F8/tmp/InjectionBundle2.bundle/InjectionBundle, 265): no suitable image found. Did find: /var/mobile/Containers/Data/Application/C154B2AF-B49D-460A-85DF-F3150045D1F8/tmp/InjectionBundle2.bundle/InjectionBundle: file system sandbox blocked mmap() of '/var/mobile/Containers/Data/Application/C154B2AF-B49D-460A-85DF-F3150045D1F8/tmp/InjectionBundle2.bundle/InjectionBundle' 2016-10-31 12:07:54.353064 *********[6369:1523873] Bundle Load Error 2016-10-31 12:07:54.353391 ********[6369:1523928] *** Bundle has failed to load. If this is due to symbols not found, this may be due to symbols being hidden from dynamic libraries. *** 50 injections performed so far.

Would be cool to have it working on my device, any hint on that ?

johnno1962 commented 7 years ago

Looks like injection won’t work on devices any more due to new sandboxing with iOS 10 :(

bilsou commented 7 years ago

That's a really big shame... Sorry for the late answer and thanks a lot for being quick to answer

johnno1962 commented 7 years ago

Just in time for Christmas I’ve been able to releaes a new binary version of Injection which makes getting up and running a breeze http://johnholdsworth.com/injection.html. If you have any problems please report them on it’s support repo https://github.com/johnno1962/InjectionApp. Happy Holidays! 🎅🍷🎄☃

johnno1962 commented 7 years ago

This should be fixed now in the new release.