Coder Social home page Coder Social logo

pandahook's Introduction

PandaHook

CI Status Version License Platform

    在学习和使用了aspect后,对于我自己的runtime理解有很大提升。随着我们需求的提升,aspect有些特性并不能满足实际需要。
比如:aspect同一个类的同一个方法只能hook一次,第一次hook成功后的所有hook都会失败。但实际应用中,其他组件可能引用
aspect进行某方法A的hook,导致其他地方就不能使用aspectd对该方法A 进行hook了。并且aspect并不能hook block。在此背景下,我写了这个组件。
    PandaHook的特点有:
        支持普通OC类和block的hook;
        支持同一个类同一个方法的不同时机hook(比如之前、之后、或者替换掉原来实现);
        甚至支持同一个类、同一个方法的相同时机hook。(也就是说,在A组件里hook TargetClass 的 s 方法,同时在其他组件或主工程hook......,均会有效)。
    感谢开源世界,感谢aspect和它的开发者,以及为开源世界做出贡献的所有人!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

    //hook成功会返回自定义实现的block对象,需要外部管理其生命周期
    self.hookBlock = [PandaHook hookClass:targetClass               //要hook的类
                              whichMethod:@selector(targetSel:)     //要hook的方法
                            isClassMethod:YES                       //hook的方法是类方法还是对象方法
                                     when:PandaHookTimeBefore       //PandaHookTime 枚举中的定义值,自定义代码的执行时机
                                     with:^(NSArray *contextArr)    //自定义代码blok,数组内是原方法的参数
    {
        //这里调用自定义实现
    }];

Requirements

Installation

PandaHook is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PandaHook'

Author

[email protected]

License

PandaHook is available under the MIT license. See the LICENSE file for more info.

pandahook's People

Contributors

tianyun1201 avatar feiduduhaha avatar

Stargazers

mypxq avatar Ezreal avatar  avatar GFun avatar 陈嘉欢 avatar  avatar DC-iOSers avatar

Watchers

GFun avatar

pandahook's Issues

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.