jezzmemo / jjexception Goto Github PK
View Code? Open in Web Editor NEWProtect the objective-c application(保护App不闪退)
License: MIT License
Protect the objective-c application(保护App不闪退)
License: MIT License
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Please complete the following information
Describe the bug
我的项目中使用了最新的afnetworking框架3.2.1。pod引入JJException后,按照文档设置好,使用了JJExceptionGuardAll,这个时候运行app大概率会crash,提示afn相关的"KVO removeObserver did not exist key:%@ observer:%@"异常提示并crash。
然后修改配置,去掉KVO相关异常的guard,再运行app就正常了
Please complete the following information
你不是说避免崩溃吗? 我点击第三个button咋崩溃?这个如何应用?
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
每个对象都要写一个同样的方法,感觉不太好啊
Describe the bug
在didFinishLaunchingWithOptions启动startGuardException(含有JJExceptionGuardKVOCrash)与发起网络请求,有一定概率在AFURLSessionManager 142行
progress.totalUnitCount = NSURLSessionTransferSizeUnknown; 崩溃(Thread 1: EXC_BAD_ACCESS)
configExceptionCategory 不含 JJExceptionGuardKVOCrash 则正常
具体闪退规律暂没有找到
Please complete the following information
xcode版本:xcode 10.0
Podfile文件内容如下:
platform:ios, '9.0'
target 'TestJJException' do
pod 'JJException'
end
终端安装报错: [!] Unable to find a specification for JJException
尝试pod search JJException
结果报错:[!] Unable to find a pod with name, author, summary, or description matching JJException
pod search AFNetworking 等其他第三方库正常
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
步骤:
1、[self.textField becomeFirstResponder];// 打开键盘 (无报错)
2、[[[UIApplication sharedApplication] keyWindow] endEditing:YES]; // 关闭键盘 (报错啦!)
环境:
MAC:10.13.6 (17G65)
Version 10.1 (10B61)
Model: iPhone X (Model A1865, A1901, A1902, A1903)
报错信息:
KVO forgot remove keyPath:center from which object:NSKVONotifying_UIInputSetHostView
(
0 xxx 0x00000001049f989c -[JJExceptionProxy handleCrashException:exceptionCategory:extraInfo:] + 144,
1 xxx 0x00000001049f9418 _Z20handleCrashException24JJExceptionGuardCategoryP8NSString + 120,
2 xxx 0x00000001049ff108 -[KVOObjectContainer clearKVOData] + 396,
3 xxx 0x00000001049feee0 -[KVOObjectContainer dealloc] + 40,
4 libobjc.A.dylib 0x0000000222d7a13c <redacted> + 468,
5 libobjc.A.dylib 0x0000000222d74728 objc_destructInstance + 96,
6 libobjc.A.dylib 0x0000000222d74774 object_dispose + 16,
7 xxx 0x0000000104a00824 -[NSObject(ZombieHook) hookDealloc] + 136,
这个库跟RAC是否能兼容呢
Describe the bug
在KVO的时候没有消息通知
Please complete the following information
这不是一个bug 上面内容为你说明的原话,其实你说的“无法提示那些keyPath忘记清理”是可以在相关函数中提示的
1、清除不存在的key也会闪退:hookRemoveObserver里面checkKVOItemExist里面没有else
2、添加监听后没有清除会导致闪退:clearKVOData的时候其实如果正常的话 set里面应该是没有说句的 有数据说明不正常 不正常就要上报
3、添加重复的key导致闪退:hookAddObserver里面的checkKVOItemExist也是没有else
没有恶意啊 我发现 你写代码if都没有else啊 😁😁😁...
你好,请教一个问题。
官方文档写到: 如果方法成功添加,则返回“是”,否则为“否”。
那么为什么会出现添加失败
Class metaclass = objc_getMetaClass(NSStringFromClass(cls).UTF8String);
class_addMethod(metaclass,
originSelector,
method_getImplementation(swizzleSelector),
method_getTypeEncoding(swizzleSelector));
你好,
mrc下的几个文件用了weak的property,
需要改成assign,
主要是字符串的那几个方法:
hookStringWithUTF8String: NSString(StringHook);
hookRangeOfString:options:range:locale: NSString(StringHook);
hookSubstringFromIndex: NSMutableString(MutableStringHook)
hookSubstringToIndex: NSMutableString(MutableStringHook)
hookSubstringWithRange: NSString(StringHook)
开启JJExceptionGuardKVOCrash后,AVFoundation加载本地视频资源偶现只有声音没有视频的异常,关闭则正常,设备版本iOS11 iOS12 都可以复现,视频格式mp4,编码264,目前只有加载本地视频有这个问题。播放的逻辑是检查到AVPlayerItem.status == AVPlayerItemStatusReadyToPlay 则开始播放。
Message from debugger: Terminated due to memory issue
#import "WXExceptionController.h"
#import <JJException/JJException.h>
@interface WXExceptionController ()
@implementation WXExceptionController
(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"异常信息";
[JJException registerExceptionHandle:self];
}
(void)handleCrashException:(NSString *)exceptionMessage exceptionCategory:(JJExceptionGuardCategory)exceptionCategory extraInfo:(NSDictionary *)info {
WXLog(@"exceptionMessage: %@\n exceptionCategory: %@\n extraInfo: %@", exceptionMessage, @(exceptionCategory), info)
}
-(void)handleCrashException:(NSString *)exceptionMessage extraInfo:(NSDictionary *)info {
WXLog(@"exceptionMessage: %@\n extraInfo: %@", exceptionMessage, info)
}
当抛错误时,两个代理方法不会执行,不能记录日志
Class currentClass = self.class;
//Check black list
if (![[[JJExceptionProxy shareExceptionProxy] blackClassesSet] containsObject:currentClass]) {
[self hookDealloc];
return;
}
点击stop guard 闪退 - (void)hookDealloc 死循环
在IOS 12 xcode 10.0
如果能处理,能定位崩溃位置吗
(void) hookAddObject:(id)object {
if (object) {
[self hookAddObject:object];
} else {
handleCrashException(JJExceptionGuardArrayContainer,@"NSSet addObject nil object");
}
}这个方法会造成循环调用吗?
请问作者: 目前这个库稳定了吗, ios11 ->> ios12是否有问题?
Describe the bug
在didFinishLaunchingWithOptions启动startGuardException,包含JJExceptionGuardKVOCrash,在运行到AFURLSessionManagerTaskDelegate中的方法- (instancetype)initWithTask:中的162行:
[progress addObserver:self forKeyPath:NSStringFromSelector(@selector(fractionCompleted))
options:NSKeyValueObservingOptionNew
context:NULL]
时会存在内存泄漏:
0 Malloc +1 1 -[NSPlaceholderString initWithBytes:length:encoding:]
1 Autorelease NSStringFromSelector
2 Retain +1 2 +[NSString(StringHook) hookStringWithUTF8String:]
3 Autorelease -[AFURLSessionManagerTaskDelegate initWithTask:]
4 Retain +1 3 -[AFURLSessionManagerTaskDelegate initWithTask:]
5 Retain +1 4 -[NSObject(KVOCrash) hookAddObserver:forKeyPath:options:context:]
6 Release -1 3 -[AFURLSessionManagerTaskDelegate initWithTask:]
7 Release -1 2 CA::Context::commit_transaction(CA::Transaction*)
8 Release -1 1 CA::Context::commit_transaction(CA::Transaction*)
当不含JJExceptionGuardKVOCrash时,不会存在这个问题。
JJException和AFNetWorking都是最新版本
Please complete the following information
有Swift版本的吗?
有无方法可以全局收集的,例如在根控制器里面实现统一收集?
Describe the bug
开启JJExceptionGuardKVOCrash防护 调用摄像头会闪退
在#import "NSObject+KVOCrash.m"中cleanObservers里面会闪退
打印出 item.observer 是
<AVCaptureSession: 0x28090cee0 [AVCaptureSessionPresetPhoto]>
<AVCaptureDeviceInput: 0x280b865e0 [后置双镜头]> -> (null)
<AVCaptureDeviceInput: 0x280b865e0 [后置双镜头]> -> <AVCapturePhotoOutput: 0x280b945e0>
<AVCaptureDeviceInput: 0x280b865e0 [后置双镜头]> -> <AVCaptureMetadataOutput: 0x280bb6d00>
所有苹果手机型号和系统都会闪退
以下是 exceptionMessager 内容, 而info是空的;
lldb) po exceptionMessage 4402061312 107094016 NSArray objectAtIndexedSubscript invalid index:1 total:0 ( 0 xxx 0x0000000106a30626 -[JJExceptionProxy handleCrashException:exceptionCategory:extraInfo:] + 134, 1 xxx 0x0000000106a30200 _Z20handleCrashException24JJExceptionGuardCategoryP8NSString + 96, 2 xxx 0x0000000106a31b55 -[NSArray(ArrayHook) hookObjectAtIndexedSubscript:] + 197, 3 xxx 0x00000001067777b5 -[TSLStationFilterViewController initialize] + 213, 4 xxx 0x00000001067776da -[TSLStationFilterViewController viewDidLoad] + 74, 5 UIKitCore 0x00000001170b44e1 -[UIViewController loadViewIfRequired] + 1186, 6 UIKitCore 0x00000001170b4940 -[UIViewController view] + 27, 7 UIKitCore 0x0000000116ffea9b -[UINavigationController _startCustomTransition:] + 931, 8 UIKitCore 0x00000001170153f0 -[UINavigationController _startDeferredTransitionIfNeeded:] + 741, 9 UIKitCore 0x00000001170167e0 -[UINavigationController __viewWillLayoutSubviews] + 150, 10 UIKitCore 0x0000000116ff6600 -[UILayoutContainerView layoutSubviews] + 217, 11 UIKit 0x000000012c09a6c4 -[UILayoutContainerViewAccessibility layoutSubviews] + 42, 12 UIKitCore 0x0000000117bbd795 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1441, 13 QuartzCore 0x000000010c896b19 -[CALayer layoutSublayers] + 175, 14 QuartzCore 0x000000010c89b9d3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395, 15 QuartzCore 0x000000010c8147ca _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 342, 16 QuartzCore 0x000000010c84b97e _ZN2CA11Transaction6commitEv + 576, 17 UIKitCore 0x00000001176cd701 _UIApplicationFlushRunLoopCATransactionIfTooLate + 165, 18 UIKitCore 0x00000001177c7569 __handleEventQueueInternal + 6874, 19 CoreFoundation 0x00000001096ad721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17, 20 CoreFoundation 0x00000001096acf93 __CFRunLoopDoSources0 + 243, 21 CoreFoundation 0x00000001096a763f __CFRunLoopRun + 1263, 22 CoreFoundation 0x00000001096a6e11 CFRunLoopRunSpecific + 625, 23 GraphicsServices 0x0000000113ca11dd GSEventRunModal + 62, 24 UIKitCore 0x00000001176d381d UIApplicationMain + 140, 25 TeslaMap 0x000000010663c5a0 main + 112, 26 libdyld.dylib 0x000000010fba2575 start + 1, 27 ??? 0x0000000000000001 0x0 + 1, )
会在object_getClass(self.whichObject) 崩溃,麻烦看下
// 使用参数NSKeyValueObservingOptionInitial就会崩溃
// 仅使用NSKeyValueObservingOptionNew|NSKeyValueObservingOptionPrior|NSKeyValueObservingOptionOld这些参数不会发生崩溃
[self addObserver:self forKeyPath:@"test1" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionInitial context:nil];
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PushViewController 0x7ffa3fc013b0> addObserver:<PushViewController 0x7ffa3fc013b0> forKeyPath:@"test1" options:5 context:0x0] was sent to an object that is not KVC-compliant for the "test1" property.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010476429b __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000103d00735 objc_exception_throw + 48
2 CoreFoundation 0x00000001047640f5 +[NSException raise:format:] + 197
3 Foundation 0x000000010373e7c5 -[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 458
4 JJException 0x00000001033c359a -[NSObject(KVOCrash) hookAddObserver:forKeyPath:options:context:] + 442
总是断点在NSObject+KVOCrash.m P297行,是抓取到crash信息了吗,
[self hookRemoveObserver:observer forKeyPath:keyPath];
有时会断在方法cleanKVOData中的@Try中,不知道是否因为同FBKVOController一起使用导致的,麻烦告知一下,谢谢
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Please complete the following information
pod下来,怎么没有configExceptionCategory方法?
错误日志:
-[NSMutableArray(self=0x00000001cc056560, _cmd="hookAddObject:", anObject=0x00000001c001fe70) hookAddObject:] at NSMutableArray+MutableArrayHook.m:39 frame #2: 0x000000010179e724
-[NSMutableArray(self=0x00000001cc056560, _cmd="hookAddObject:", anObject=0x00000001c001fe70) hookAddObject:] at NSMutableArray+MutableArrayHook.m:39相同的调用 0x000000010179e724 `-[NSMutableArray(self=0x00000001cc056560, _cmd="hookAddObject:", anObject=0x00000001c001fe70) hookAddObject:] at NSMutableArray+MutableArrayHook.m:39 发生了上万次,产生一个内存失效的错误,麻烦看下
在- (void)clearKVOData方法中objc_msgSend这一行崩溃,上次是在上一行代码object_getClass(self.whichObject),麻烦看一下!
NSString,NSMutableString,NSAttributedString,NSMutableAttributedString(下标越界以及参数nil异常)
缺少 NSMutableAttributedString replaceCharactersInRange 越界的拦截
也属于平常常遇到的crash
在用户快速切换语音输入根键盘输入的时候 如果执行这类替换方法会很容易崩,非常感谢
我在读你的源码,有个地方不太理解:
NSObject+UnrecognizedSelectorHook.m --> methodSignatureForSelectorSwizzled --> 32行
// If current class override methodSignatureForSelector return nil
if (originIMP != currentClassIMP){
return nil;
}
这里返回nil的话,不就直接crash了吗?
对于开启kvo异常处理时,对于10.x(测试系统版本10.3.3)系统版本存在自己实现kvo 到remove时,会与JJException的dealloc中clearKVOData一起导致多次remove而crash. 测试环境可以在YYText与此框架同时启用时,具有多次键盘关闭情况下复现。
使用这个对性能有没有影响
这个库会影响上线审核吗,会被苹果拒绝吗?
2018-12-03 19:48:41.599523+0800 project[3300:446877] +[NSSet jj_swizzleNSSet]: unrecognized selector sent to class 0x1d6a2d110
2018-12-03 19:48:41.599749+0800 project[3300:446877] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSSet jj_swizzleNSSet]: unrecognized selector sent to class 0x1d6a2d110'
*** First throw call stack:
(0x19ce6fef8 0x19c03da40 0x19cd8c1fc 0x19ce75810 0x19ce774bc 0x1033d15d8 0x1033d1c2c 0x10033c26c 0x100183254 0x1001833e4 0x1c9db3c68 0x1c9db53d0 0x1c9dbae1c 0x1c965bc18 0x1c96646f0 0x1c965b894 0x1c965c234 0x1c965a334 0x1c9659fe0 0x1c965f1a0 0x1c9660100 0x1c965f058 0x1c9663d9c 0x1c9db9314 0x1c99a4c34 0x19f89f890 0x19f8aa658 0x19f8a9d50 0x104ed8de4 0x104edca2c 0x19f8de640 0x19f8de2cc 0x19f8de8e8 0x19cdfe5b8 0x19cdfe538 0x19cdfde1c 0x19cdf8ce8 0x19cdf85b8 0x19f06c584 0x1c9dbcbc8 0x100184ca8 0x19c8b8b94)
libc++abi.dylib: terminating with uncaught exception of type NSException
NSObject+KVOCrash.m - (void)hookRemoveObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath 中的 [self hookRemoveObserver:observer forKeyPath:keyPath]; 这一行。 打开断点后老是会在这里卡住,断点继续后还是一直又回到这个地方(取消断点可以继续完成后续流程),这里没有设置断点的啊。版本是最新的
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <AVKVODispatcher 0x60400020a540> for the key path "currentItem" from <AVPlayer 0x6000002012c0> because it is not registered as an observer.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000111b811e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000011121e031 objc_exception_throw + 48
2 CoreFoundation 0x0000000111bf6975 +[NSException raise:format:] + 197
3 Foundation 0x000000010d84ce43 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 488
4 Foundation 0x000000010d84cc03 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 84
5 TestDepend 0x000000010aaa60c8 -[NSObject(KVOCrash) hookRemoveObserver:forKeyPath:] + 232
6 Foundation 0x000000010d8aad36 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 177
7 AVFoundation 0x000000010c562659 -[AVPlayer addObserver:forKeyPath:options:context:] + 230
8 AVFoundation 0x000000010c63d743 -[AVKVODispatcher startObservingValueAtKeyPath:ofObject:options:usingBlock:] + 142
9 AVFoundation 0x000000010c63eaf9 -[AVKVODispatcher(LegacyCallbackMethod) startObservingObject:weakObserver:forKeyPath:options:context:] + 145
10 AVFoundation 0x000000010c52fa5d -[AVPlayerLayer _startObservingPlayer:] + 320
11 libdispatch.dylib 0x00000001121d57ab _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x00000001121d67ec _dispatch_client_callout + 8
13 libdispatch.dylib 0x000000011212018-10-12 18:30:38.116325+0800 TestDepend[62153:1447887] obserer:<ZFAVPlayerManager: 0x6000001d9410> keypath:loadedTimeRanges
debe5 _dispatch_queue_serial_drain + 1305
14 libdispatch.dylib 0x00000001121df4fa _dispatch_queue_invoke + 328
15 libdispatch.dylib 0x00000001121db344 _dispatch_queue_override_invoke + 726
16 libdispatch.dylib 0x00000001121e236c _dispatch_root_queue_drain + 664
17 libdispatch.dylib 0x00000001121e2076 _dispatch_worker_thread3 + 132
18 libsystem_pthread.dylib 0x0000000112701169 _pthread_wqthread + 1387
19 libsystem_pthread.dylib 0x0000000112700be9 start_wqthread + 13
)
@protocol SomeProtocol<NSObject>
@optional
-(void)testUndefineSelector;
@end
@interface ViewController ()<JJExceptionHandle,SomeProtocol>
@end
[self performSelector:@selector(testUndefineSelector)];
崩溃了:
2018-09-30 16:11:02.955 JJException[22830:279892] -[ViewController testUndefineSelector]: unrecognized selector sent to instance 0x7f8aaff863c0
2018-09-30 16:11:02.961 JJException[22830:279892] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController testUndefineSelector]: unrecognized selector sent to instance 0x7f8aaff863c0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d6e7f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d161deb objc_exception_throw + 48
2 CoreFoundation 0x000000010d6f058d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010d63dd97 forwarding + 487
4 CoreFoundation 0x000000010d63db28 _CF_forwarding_prep_0 + 120
5 JJException 0x000000010cc42003 -[ViewController testUnrecognizedSelector] + 51
6 JJException 0x000000010cc41d7c -[ViewController testArrayDictionaryUnrecognizedSelector] + 44
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Please complete the following information
Error log: [!] Unable to find a specification for JJException
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.