* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00007fff513f778b libobjc.A.dylib`objc_msgSend + 11
frame #1: 0x00007fff2572290d Foundation`_NSSetLongLongValueAndNotify + 81
frame #2: 0x00000001013ca58d Stinger_Example`ffi_call_unix64 + 85
* frame #3: 0x00000001013c7804 Stinger_Example`ffi_call_int(cif=<unavailable>, fn=<unavailable>, rvalue=<unavailable>, avalue=<unavailable>, closure=<unavailable>) at ffi64_x86_64.c:660:3 [opt]
frame #4: 0x00000001013bb956 Stinger_Example`_st_ffi_function(cif=0x00006000002b82a8, ret=0x00007ffeee853920, args=0x00007ffeee8537b0, userdata=0x00006000002b82a0) at STHookInfoPool.m:338:7
frame #5: 0x00000001013c7a7d Stinger_Example`ffi_closure_unix64_inner(cif=0x00006000002b82a8, fun=(Stinger_Example`_st_ffi_function at STHookInfoPool.m:292), user_data=0x00006000002b82a0, rvalue=0x00007ffeee853920, reg_args=<unavailable>, argp=<unavailable>) at ffi64_x86_64.c:810:3 [opt]
frame #6: 0x00000001013ca732 Stinger_Example`ffi_closure_unix64 + 72
frame #7: 0x00000001013acdf2 Stinger_Example`-[ASViewController test:](self=0x00007fdcd1104c70, _cmd="test:", sender=0x00007fdccef023d0) at ASViewController.m:80:10
frame #8: 0x00007fff48093fff UIKitCore`-[UIApplication sendAction:to:from:forEvent:] + 83
frame #9: 0x00007fff47a6c00e UIKitCore`-[UIControl sendAction:to:forEvent:] + 223
frame #10: 0x00007fff47a6c358 UIKitCore`-[UIControl _sendActionsForEvents:withEvent:] + 398
frame #11: 0x00007fff47a6b2b7 UIKitCore`-[UIControl touchesEnded:withEvent:] + 481
frame #12: 0x00007fff480cebbf UIKitCore`-[UIWindow _sendTouchesForEvent:] + 2604
frame #13: 0x00007fff480d04c6 UIKitCore`-[UIWindow sendEvent:] + 4596
frame #14: 0x00007fff480ab53b UIKitCore`-[UIApplication sendEvent:] + 356
frame #15: 0x00007fff4812c71a UIKitCore`__dispatchPreprocessedEventFromEventQueue + 6847
frame #16: 0x00007fff4812f1e0 UIKitCore`__handleEventQueueInternal + 5980
frame #17: 0x00007fff23bd4471 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
frame #18: 0x00007fff23bd439c CoreFoundation`__CFRunLoopDoSource0 + 76
frame #19: 0x00007fff23bd3b74 CoreFoundation`__CFRunLoopDoSources0 + 180
frame #20: 0x00007fff23bce87f CoreFoundation`__CFRunLoopRun + 1263
frame #21: 0x00007fff23bce066 CoreFoundation`CFRunLoopRunSpecific + 438
frame #22: 0x00007fff384c0bb0 GraphicsServices`GSEventRunModal + 65
frame #23: 0x00007fff48092d4d UIKitCore`UIApplicationMain + 1621
frame #24: 0x00000001013acfa2 Stinger_Example`main(argc=1, argv=0x00007ffeee855cf0) at main.m:15:16
frame #25: 0x00007fff5227ec25 libdyld.dylib`start + 1
//
// ASViewController.m
// Stinger
//
// Created by Assuner on 12/05/2017.
// Copyright (c) 2017 Assuner. All rights reserved.
//
#import "ASViewController.h"
#import <Stinger/Stinger.h>
#import <Aspects/Aspects.h>
@interface ASViewController ()
- (IBAction)test:(id)sender;
@property (nonatomic) NSInteger index;
@property (nonatomic) BOOL didAddKVO;
@property (nonatomic) BOOL didHook;
@end
@implementation ASViewController
- (void)methodA {
}
- (void)setFrame:(CGRect)rect {
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.class st_hookInstanceMethod:@selector(methodA) option:STOptionBefore usingIdentifier:@"hook methodA before" withBlock:^(id<StingerParams> params) {
}];
[self.class st_hookInstanceMethod:@selector(methodA) option:STOptionAfter usingIdentifier:@"hook methodA after" withBlock:^(id<StingerParams> params) {
}];
// [self.class aspect_hookSelector:@selector(methodA) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params) {
//
// } error:nil];
//
// [self.class aspect_hookSelector:@selector(methodA) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> params) {
//
// } error:nil];
}
- (void)addKVO {
if (_didAddKVO) {
return;
}
[self addObserver:self forKeyPath:@"index" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil];
_didAddKVO = YES;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
NSLog(@"KVO: %@", change);
}
- (void)hook_set_index {
if (_didHook) {
return;
}
[self st_hookInstanceMethod:@selector(setIndex:) option:STOptionBefore usingIdentifier:@"setIndex" withBlock:^(id<StingerParams> params, NSInteger index) {
NSLog(@"HOOK: %@", @(index));
}];
_didHook = YES;
}
- (IBAction)test:(id)sender {
// for (NSInteger i = 0; i < 1000000; i++) {
// [self methodA];
// }
NSLog(@"clicked!!");
[self addKVO];
[self hook_set_index];
self.index += 1;
}
@end