/LWAspectsHook

LWAspectsHook, 实现切面注入,方法Hook相关功能

Primary LanguageObjective-CMIT LicenseMIT

LWAspectsHook

LWAspectsHook, 实现切面注入,方法Hook相关功能

CI Status Version License Platform

Example

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

+ (void)load {
    [super load];

    [UIResponder setupWithConfiguration:[LWAppDelegate hookEventDict]];
}

+ (NSDictionary *)hookEventDict {
    return @{
            @"LWViewController": @{
                    Hook_TrackedEvents: @[
                            @{
                                    Hook_EventName: @"hookTest方法调用前",
                                    Hook_Option: @(AspectPositionBefore),
                                    Hook_EventSelectorName: @"hookTest:",
                                    Hook_EventHandlerBlock: ^(id <AspectInfo> aspectInfo) {
                                        LWLog(@"========hookTest before hooked =======");
                                        LWLog(@"====== instance:%@  method:%@  arguments:%@ ", aspectInfo.instance, NSStringFromSelector(aspectInfo.originalInvocation.selector), aspectInfo.arguments);
                                    },
                            },
                            @{
                                    Hook_EventName: @"hookTest方法调用后",
                                    Hook_Option: @(AspectPositionAfter),
                                    Hook_EventSelectorName: @"hookTest:",
                                    Hook_EventHandlerBlock: ^(id <AspectInfo> aspectInfo) {
                                        LWLog(@"========hookTest after hooked =======");
                                        id returnVal;
                                        [aspectInfo.originalInvocation getReturnValue:&returnVal];
                                        LWLog(@"====== instance:%@  method:%@  returnVal:%@ ", aspectInfo.instance, NSStringFromSelector(aspectInfo.originalInvocation.selector), returnVal);
                                    },
                            },
                    ],
            },

            @"LWAppDelegate": @{
            }
    };
}

Requirements

Installation

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

pod 'LWAspectsHook'

Carthage

github "luowei/LWAspectsHook"
carthage update --platform iOS
# carthage update --no-use-binaries --platform iOS

Author

luowei, luowei@wodedata.com

License

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