Giter Site home page Giter Site logo

dyci / dyci-main Goto Github PK

View Code? Open in Web Editor NEW
1.1K 51.0 166.0 2.75 MB

Dynamic Code Injection Tool for Objective-C

License: MIT License

Shell 8.66% Objective-C 57.10% Python 12.94% Ruby 13.25% Gherkin 8.05%
dyci code injection dynamic objective-c xcode xcode-plugin playground

dyci-main's Introduction

# DyCI – Dynamic Code Injection

Join the chat at https://gitter.im/DyCI/dyci-main Carthage compatible

This tool allows you to inject code into running iOS application, without restarting it.

  1. DyCI is not about loading new code in application.
  2. DyCI is about speeding up development.
  3. Each time, you are using DyCI, it saves you time.

WARNING

Uninstall DyCI before updating Xcode. If you don't you may need to reinstall xcode. We're currenlty working on this issue... If you've already expirienced this issue - remove and reinstall Xcode.

Installation

1. Install on machine

This is done once per machine. See details on installation page.

2. Add to your project

DyCI needs to integrate with the project as well. If you are using CocoaPods you can add this to your podfile

pod 'dyci', :git => 'https://github.com/DyCI/dyci-main.git'

If you prefer a manual approach you can read about it in the wiki.

Reasons, why do you need this tool

  • apply small logic changes in no time
  • when working with UI and animations you can see the results immediately
  • It's good for debugging purposes. Remember, you can inject any code at runtime, add log statements etc.

Compared to other tools

  • You need minimum moves to enable dyci
  • You aren't writing some kind of script, you are writing your code!
  • You don't need to prepare/modify/lock your code for dyci
  • Your changes are always saved (they will not be discarded on next run)

How it works

You can read all about it in the How it works wiki.

Demos

ic-Tac-Toe game

Tic-Tac-Toe Game recreation

Example

  • There's an interactive demo in the workspace found in the Dynamic Code Injection folder.
  • Krzysztof Zabłocki created KZPlayground.

WARNING

Please, do not use this tool in your real applications, that you will publish to the App Store. DyCI won't work on devices by default, by purpose. Dynamic code injection is good for development, but it will leave huge security hole if you put it in your application.

FAQ

Please open any issue, but be sure to read the FAQ before you do:-)

Other Tools

There's few other tools those works kind'a the same, so if you don't like dyci - you can try those

Author(s)

Taykalo Paul, [email protected]
Find me on twitter.

dyci-main's People

Contributors

alexdenisov avatar artfeel avatar aspcartman avatar bitdeli-chef avatar dehengxu avatar gitter-badger avatar grav avatar hashier avatar hfossli avatar odnairy avatar olegam avatar paultaykalo avatar roman-mazur avatar vixentael avatar yulong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dyci-main's Issues

No code injected when analyzer is switched on in project

Hi, great lib! I find it very useful.

I found a small issue I want to share with you:
When a project has analizer setup to run with every build (RUN_CLANG_STATIC_ANALIZER build setting), then the command captured by DYCI will not be correct, and no code will be injected.

The current workaround is to RUN_CLANG_STATIC_ANALIZER = NO when working with code injection, which is far from ideal.

Thanks!

Getting crashes on minor changes

2014-03-20 18:14:27.202 CigaretteDispenser[91836:60b]  - (void)updateOnClassInjection 
2014-03-20 18:14:27.379 CigaretteDispenser[91836:60b] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFSet: 0xa489550> was mutated while being enumerated.'  
*** First throw call stack:     
(   
    0   CoreFoundation                      0x020ba1e4 __exceptionPreprocess + 180  
    1   libobjc.A.dylib                     0x01d838e5 objc_exception_throw + 44  
    2   CoreFoundation                      0x02149cf5 __NSFastEnumerationMutationHandler + 165  
    3   CigaretteDispenser                  0x00177332 -[SFInjectionsNotificationsCenter notifyOnClassInjection:] + 802  
    4   CigaretteDispenser                  0x00175189 -[SFDynamicCodeInjection performInjectionWithClass:] + 361  
    5   CigaretteDispenser                  0x00174f11 -[SFDynamicCodeInjection performInjectionWithClassesInSet:] + 577  
    6   CigaretteDispenser                  0x00175ad3 -[SFDynamicCodeInjection newFileWasFoundAtPath:] + 1251  
    7   CigaretteDispenser                  0x001766ec -[SFFileWatcher checkForFileCreationDate] + 828  
    8   CigaretteDispenser                  0x00176272 __42-[SFFileWatcher   setupHandlerOnFileChange:]_block_invoke_2 + 50  
    9   libdispatch.dylib                   0x023b97b8 _dispatch_call_block_and_release + 15  
    10  libdispatch.dylib                   0x023ce4d0 _dispatch_client_callout + 14  
    11  libdispatch.dylib                   0x023bc726 _dispatch_main_queue_callback_4CF + 340  
    12  CoreFoundation                      0x0211f43e   __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14  
    13  CoreFoundation                      0x020605cb __CFRunLoopRun + 1963  
    14  CoreFoundation                      0x0205f9d3 CFRunLoopRunSpecific + 467  
    15  CoreFoundation                      0x0205f7eb CFRunLoopRunInMode + 123  
    16  GraphicsServices                    0x036175ee GSEventRunModal + 192  
    17  GraphicsServices                    0x0361742b GSEventRun + 104  
    18  UIKit                               0x006d0f9b UIApplicationMain + 1225  
    19  CigaretteDispenser                  0x0000275d main + 141  
    20  libdyld.dylib                       0x02603701 start + 1  
    21  ???                                 0x00000001 0x0 + 1  
)  
libc++abi.dylib: terminating with uncaught exception of type NSException

Unable to use it simultaneously on XCode 5 and XCode 4.6.3.

Working in XCode 5, but not in XCode 4.6.3 now.

  1. I have tried clean and also deleted all DerivedData builds.
  2. Deleted the build from simulator.

Still getting the same issue.
"Couldn't load index file '/Users/prabha-1044/.dyci/index/8845d3f04edeb8499c9547d736a6ba41' (/Users/prabha-1044/Friendtam/Official/NativeApp/HomeViewController.m). Use default compilation instead"

Still working good in XCode 5.

Failed to inject Xib files

I can inject .m files,but I can's inject .xib files.The following is the error information.How to fix it?

Traceback (most recent call last):
File "/Users/guangxikatsurahayashishouzanku/.dyci/scripts/dyci-recompile.py", line 125, in
resultCode = copyResource(xibFilename, DYCI_ROOT_DIR)
File "/Users/guangxikatsurahayashishouzanku/.dyci/scripts/dyci-recompile.py", line 82, in copyResource
shutil.copy(source, bundlePath)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 119, in copy
copyfile(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 21] Is a directory: '/Users/guangxikatsurahayashishouzanku/Library/Developer/CoreSimulator/Devices/59909BFB-FD4C-412F-B04F-79C1A396F7DB/data/Containers/Bundle/Application/49287987-1933-40D8-8433-79F54AD402A8/test-40-AutoLayout.app/Demo1ViewController.nib'

Problems with integration.

I had add dyci to my project via cocoa pods. After few hours I get such message:

2012-11-26 23:39:23.034 Runtime test[28859:c07]
2012-11-26 23:39:23.036 Runtime test[28859:c07] =================================================
2012-11-26 23:39:23.037 Runtime test[28859:c07] Found new DCI ... Loading
2012-11-26 23:39:23.069 Runtime test[28859:c07] DCI was successfully loaded
2012-11-26 23:39:23.069 Runtime test[28859:c07] Searching classes to inject
2012-11-26 23:39:23.075 Runtime test[28859:c07] Injecting class : ARViewController
2012-11-26 23:39:23.076 Runtime test[28859:c07] Injecting meta class : ARViewController
2012-11-26 23:39:23.076 Runtime test[28859:c07] Class (ARViewController) and their subclasses instances would be notified with
2012-11-26 23:39:23.076 Runtime test[28859:c07] - (void)updateOnClassInjection
2012-11-26 23:39:23.077 Runtime test[28859:c07] Class was successfully injected
2012-11-26 23:39:23.077 Runtime test[28859:c07]

But nothing had changed on my screen. After ^x combination. Could you explain why it could be so.

Dlog not supported by Dyci

Am using xcode and my project is configured to use DLog preprocessor than the default NSLog. I couldn't use Dlog in injectable code section. please let me know if I am missing any.

DYCI directory path is invalid.

I am getting this message, but Ctrl+X not working for me.
Directory path has (null) instead of my username.

2014-10-31 16:44:09.073 MyApp[7479:293707] DYCI directory path is : /Users/(null)/.dyci/
2014-10-31 16:44:09.080 MyApp[7479:293707] ============================================
2014-10-31 16:44:09.080 MyApp[7479:293707] DYCI : Dynamic Code Injection was started...
2014-10-31 16:44:09.080 MyApp[7479:293707] To disable it, paste next line in your application:didFinishLaunching: method :

[NSClassFromString(@"SFDynamicCodeInjection") performSelector:@selector(disable)];

2014-10-31 16:44:09.080 MyApp[7479:293707] or
2014-10-31 16:44:09.080 MyApp[7479:293707] Simply remove dyci from dependencies

AppCode Plugin needed

Ofcourse, it is cool, that we have support of dyci, as "External Tool", But it will be more valuable, if we'll have normal AppCode plugin.

Currenlty external tool have some disadvantages:

  1. If you set up External tool to open Console each time, when compilation performs, this lead to enormous count of opened Consoles in AppCode
  2. If you set up External tool to NOT open Console each time, then in case of Error, you dont' see any valueble Error (only result code == 1)

xcodeLocation = args[2] IndexError: list index out of range

For some reason I can't get DyCI to work. I have never tried it before.

I upgraded Xcode before installing. Then I installed using guide found here https://github.com/DyCI/dyci-main/wiki/Installation

Crash

Traceback (most recent call last):
  File "/Users/hfossli/.dyci/scripts/dyci-recompile.py", line 166, in <module>
    xcodeLocation = args[2]
IndexError: list index out of range

screen shot 2014-10-24 at 13 51 10

System info

Xcode: Version 6.1 (6A1052d) (latest as of today)
OS: 10.10 (14A388a) (latest as of today)

Output when installing DyCI

╰─$ ./install.sh 

== Backing up clang : grep -Fq == CLANG_PROXY == /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
Password:
Done.
== Faking up clang : Done.
== Preparing dyci-recompile directories: Done.
== Copying scripts : Done.
== AppCode 2.x found. Installing DYCI as AppCode plugin : Done.
   Restart Appcode. Plugin should be loaded automaticaly. If not, you may need to install it manually
== Installing Xcode DYCI plugin : Done.
  Now you can use DYCI from the Xcode :P

DYCI was successfully installed!
Use (^X) hot key in your IDE to perform code injections. Have fun.

inject for code only work for the files in pods directory when working with workspace with several projects

Using with dyci, I found a strange problem:when working with cocoapods, inject code(^X) can only work for the third party files in pods folders, but not work for the files in the project folders(always pop up 'Failed to inject code, Couldn't load index file' hint)

My pod file is like the following:

workspace 'space.xcworkspace'

target 'Base' do
xcodeproj 'project1.xcodeproj'
platform :ios, '5.0'
pod 'dyci', :git => 'https://github.com/DyCI/dyci-main.git'
pod 'MBProgressHUD'
end

target 'Case' do
xcodeproj 'project2.xcodeproj'
platform :ios, '5.0'
pod 'MagicalRecord'
pod 'dyci', :git => 'https://github.com/DyCI/dyci-main.git'
end

It's too hard integrate dyci in project without workspace

I have project, without workspace...

For now, I have to perform too much operations to have dyci running...

  • run install script
  • add dyci.xcodeproj to my project
  • add dyci as dependence project
  • link with libdyci.a
  • add code to app delegate
  • add additional header search path to project settings

- ??

Dynamic framework

Please, cleanup Dynamic Framework installation script, so we can use it without user interaction.

install without sudo

For my case, calling sudo is not permitted.
Install script works without sudo command. Should we remove sudo?

Autosave on CTRL + X ?

Hi, fantastic job, really !

It's there a way to auto save when pressing CTRL + X ? It's not easy to CMD+S and CTRL +X each time, or i have a problem with my installation ?

Thanks

.podspec file seems wrong

I've notice strange line in podspec file

  sp.compiler_flags = '-fobjc-no-arc'

It raises question because if you want to use compiler flag to build file without ARC you should use -fno-objc-arc flag. But original project (not downloaded as pod) using ARC, except one file (not sure if this file need it).
So the question is: Does podspec file correct or i should fix project preferences to avoid unpredictable issues?

Homebrew

Any reason it isn't possible to install via homebrew?

I can have a go at it

KVO context pointers changing on reload

Hi there - we use the static void* kvoContext=&kvoContext pattern (http://nshipster.com/key-value-observing/#correct-context-declarations) for supplying a context for key value observing.

Not surprisingly, this causes problems when DYCI reloads the code, as the pointer value changes. Calls to [self removeObserver:foo forKeyPath:bar context:kvoContext] blow up, as does the call to super in :

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (context == kvoContext) {
        // handle our own changes
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

Any suggestions on working around this?

dyci doesn't work on Xcode 6

Hi,

I'm trying to use dyci for first time, but I can't use it. dyci shows this on console, but nothing changes on simulator:

2014-11-05 13:43:30.969 TestDyci[6884:286286] New file injection detected at path : /Users/mhergon/.dyci/dyci2141745.dylib.ld_EwEn4P
2014-11-05 13:43:30.969 TestDyci[6884:286286]  
2014-11-05 13:43:30.969 TestDyci[6884:286286]  ================================================= 
2014-11-05 13:43:30.969 TestDyci[6884:286286] Found new DCI ... Loading
2014-11-05 13:43:30.977 TestDyci[6884:286286] DYCI was successfully loaded
2014-11-05 13:43:30.977 TestDyci[6884:286286] Searching classes to inject
2014-11-05 13:43:30.981 TestDyci[6884:286286] Injecting  class : AppDelegate
2014-11-05 13:43:30.981 TestDyci[6884:286286] Injecting meta class : AppDelegate
2014-11-05 13:43:30.981 TestDyci[6884:286286] Class (AppDelegate) and their subclasses instances would be notified with
2014-11-05 13:43:30.981 TestDyci[6884:286286]  - (void)updateOnClassInjection 
2014-11-05 13:43:30.981 TestDyci[6884:286286] 1 (AppDelegate) class instanses were notified on Class Injection : 
2014-11-05 13:43:30.981 TestDyci[6884:286286] 1 instanses were notified on Class Injection by injecting class: (AppDelegate)
2014-11-05 13:43:30.982 TestDyci[6884:286286] Class was successfully injected
2014-11-05 13:43:30.982 TestDyci[6884:286286]  

Any idea?
Thanks!

It doesn't work in UITableViewCell's contentView

I inject dyci to my workspace project and it work well.
But when I modify my custom cell's contentView's subViews
and press ^X,and then reload my tableview,the UI
in simulator does not change.

Then I try again.This time I override setFrame: method
and set custom frame to my cell.Save,^X,reload,and
then it works.

So,is that a bug?

AppCode plugin and Xcode version

AppCode 3 does not rely on xcode-select, instead you choose the desired Xcode version in the Preferences.

But I believe the dyci plugin still relies on xcode-select. Is it possible to make the AppCode version of the plugin aware of the AppCode setting instead of using code-select?

Losing Clang on Xcode Update

If dyci is installed, then, when Xcode updates,
it deletes clang-real, and clang-backup

And you can restore it only by fully removing and reinstalling Xcode

That sucks.

Current solution 1:
Uninstall dyci before updating Xcode

Current solution 2:
Remove and reinstall Xcode

Dyci proxy compiler works strange when compiles c++ projects

When I'm trying to compile c++ project Cedar, i see lot of errors

Undefined symbols for architecture x86_64:
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      std::__1::vector<std::__1::shared_ptr<Cedar::Doubles::Argument>, std::__1::allocator<std::__1::shared_ptr<Cedar::Doubles::Argument> > >::allocate(unsigned long) in StubbedMethod.o
      void std::__1::vector<std::__1::shared_ptr<Cedar::Doubles::Argument>, std::__1::allocator<std::__1::shared_ptr<Cedar::Doubles::Argument> > >::__push_back_slow_path<std::__1::shared_ptr<Cedar::Doubles::Argument> const&>(std::__1::shared_ptr<Cedar::Doubles::Argument> const&&&) in InvocationMatcher.o
  "std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
      __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeES9_S9_ in CDRProtocolFake.o
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:

More than that. If I add -lstdc++ in project, all works fine with dyci proxy compiler
But default clang doesn't have to specify that parameter.

not work in ios7

i run it on ios6 simulator it works,but in ios7 ,i can't go into the viewController view,just in a blackColor state~ but when i remove the dyci framework in build phases and rerun xcode i can go into the view controller view ,。it seems that the dyci.framework is not work in iOS 7

Tag the current version of DyCI

We're using the master version of DyCI. It would be great if you could tag it with a version number so we can depend on the specific version instead of having to use master.

Thanks for a great library!

Swift support?

Would it be possible to support Swift? I guess native swift objects cannot be swizzled, but how about everything that inherits from NSObject?

Using dyci on device documentation/instructions

I have zero intention of releasing an app with this; but as a developer who makes unity 3d/cocoa hyrbid AR apps, I would benefit so much from having this run on the device.

Is there any way to do it?
If so it there any documentation?

Does not find .dyci folder when user $HOME is not /Users/<username>

Hi,

thanks for a really useful lib!
When using dyci on my mac at work, I have moved my home folder, so instead of:
/Users/mquinones/
it is
/Volumes/BigSATA/miquHome/

I've debugged the code, and it happens that:
In SFDynamicCodeInjection.m:103:
char * userENV = getenv("USER")
is NULL, and default path override is not working.

Support localized resourses

For the current momnet, we allowing only resources, that will be simply dropped to bundle. This approach won't work on lozalized resourses, that is needed to be placed at correct lproj directory

Storyboard views

If you try to change view position/size etc at storyboard it's not work + send message with error.
Also if you try to change IBOutlets programmatically position/size etc they dismissed from app view.
If you not save changes at file and push ^X changes not injected.

Searching classes to inject, no update after that

After configuring dyci, i am getting the success logs. but when I change my code and try to inject, it says "Searching classes to inject" and no update after that. Can't understand where it gets hanged.

Dyci recompilation with xcode-build

This is just page for my notes :) If you found some of them valuable - feel free to use them :)

xcode-build way

There's a way to peform dyci via partial xcode-build ?
Like this

% make build 2>&1 | tee /dev/stderr | awk '/^CompileC/ { print $2 }' | xargs -I % sh -x ~/dev/ios/dyci-main/bin/gendylib.sh % ~/.dyci/inject_APF_$(date +%s).dylib
  1. Can we actually use it?
    Yes
  2. What time does it take to perform this task?
    Little slower than current dyci, but.. can recompile all affected files
  3. How the installation should work?
    It will install scripts, and user, possibly wil specify some parameters in file in the root of the project
  4. WIll it be easier, and faster than fake clang?
    Easier - YES. Less intrusive - YES. Faster - Defintetely NO. Better - Possibly :)
  5. What command line we should launch
    -- Possibly we can use some file in root of the project
  6. Determination of workspace/scheme vs project parameters
  7. Additional parameters for dylib configuration (-Frameworks path and Libraries paths, isysroot)
  8. Current parameters determination (Configuration, iPhone / Simulator / SDK version)
  9. Xcode vs AppCode

Crash while injecting storyboard

After I'm saving a storyboard and trying to inject it, application is crashing with the following error: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIProxyObject 0x7bff9e90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key collectionView.'
Does DYCI supports storyboards?

DYCI in subprojects not working

I have an app which uses a sub-project, where all code except for the appdelegate is included.

If I include the files from the example projects into the main project, all goes well.

If i do the same inside the subproject, i see this:

0 instanses were notified on Class Injection by injecting class: (DYCIViewController)

And nothing is updated.

If I do the same in any other of my custom classes, nothing at all happens dyci does not seem to be called.
Pressing ctrl-x only seems to show a green bubble on classes that are not currently loaded

The results were the same, no matter if adding as subproject, library or as a Pod

Cocoapods repository

Can you add dyci to Cocoapods specs repo? This will prevent download on each pod update command and help people to find it via 'pod search'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.