All Projects → MrLujh → SafeObject

MrLujh / SafeObject

Licence: MIT license
IOS崩溃异常的处理,防止数组越界,字典空值处理

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to SafeObject

FFSafeKit
🤖Using NSArray, NSMutableArray, NSDictionary, NSMutableDictionary, NSMutableString safely.
Stars: ✭ 28 (-66.67%)
Mutual labels:  nsmutablearray, nsmutabledictionary
safe-rules
详细的C/C++编程规范指南,由360质量工程部编著,适用于桌面、服务端及嵌入式软件系统。
Stars: ✭ 425 (+405.95%)
Mutual labels:  safe
red-alert
Israeli Pikud Haoref missile detection API
Stars: ✭ 21 (-75%)
Mutual labels:  safe
yoda
GitHub extension for agile project management, using the issues subsystem.
Stars: ✭ 86 (+2.38%)
Mutual labels:  safe
bugsnag-java
Bugsnag error reporting for Java.
Stars: ✭ 51 (-39.29%)
Mutual labels:  crash
safe-json-stringify
A wrapper for JSON.stringify that handles circular references and prevent defined getters from throwing errors.
Stars: ✭ 51 (-39.29%)
Mutual labels:  safe
Safe stl
A safe version of STL
Stars: ✭ 17 (-79.76%)
Mutual labels:  safe
Safari-Crash
Small HTML DoS exploit kit aimed at mobile browsers that allows rapid deployment and testing
Stars: ✭ 32 (-61.9%)
Mutual labels:  crash
Micro
🏎Fast diffing and type safe SwiftUI style data source for UICollectionView
Stars: ✭ 77 (-8.33%)
Mutual labels:  safe
LogServiceCrash
POC code to crash Windows Event Logger Service
Stars: ✭ 23 (-72.62%)
Mutual labels:  crash
XLog
一个简易的日志打印框架(支持打印策略自定义,默认提供2种策略:logcat打印和磁盘打印)
Stars: ✭ 33 (-60.71%)
Mutual labels:  crash
safe-core-sdk
Software developer tools that facilitate the interaction with the Safe contracts and services.
Stars: ✭ 93 (+10.71%)
Mutual labels:  safe
SafeGuard
WTSafeGuard can effectively prevent the IOS system application crash
Stars: ✭ 54 (-35.71%)
Mutual labels:  crash
Crashalert
Set of React Native components that allow reporting of the crashes in RN applications.
Stars: ✭ 68 (-19.05%)
Mutual labels:  crash
kahoot-tools
A website for interacting with kahoot games.
Stars: ✭ 63 (-25%)
Mutual labels:  crash
fast-decode-uri-component
Fast and safe decodeURIComponent
Stars: ✭ 22 (-73.81%)
Mutual labels:  safe
Hemmelig.app
Keep your sensitive information out of chat logs, emails, and more with encrypted secrets.
Stars: ✭ 183 (+117.86%)
Mutual labels:  safe
kotlin-multiplatform-example
A Kotlin multiplatform example app that targets Android, ReactJS, iOS, JavaFx, and Spring Boot
Stars: ✭ 115 (+36.9%)
Mutual labels:  crash
db-safedelete
Attempts to invoke force delete, if it fails - falls back to soft delete
Stars: ✭ 16 (-80.95%)
Mutual labels:  safe
SAFE.Simplified
A lightweight alternative template of SAFE for happy cross-IDE full-stack F# development
Stars: ✭ 97 (+15.48%)
Mutual labels:  safe

SafeObject

支持pod导入

  • pod 'SafeObject'

  • 执行pod search SafeObject提示搜索不到,可以执行以下命令更新本地search_index.json文件

rm ~/Library/Caches/CocoaPods/search_index.json
  • 如果pod search还是搜索不到,执行pod setup命令更新本地spec缓存(可能需要几分钟),然后再搜索就可以了

App常见崩溃,容器越界,字典空值

  • 数组下标越界

示例代码:

- (void)testArrayOutOfBounds
{
    NSArray *testArray = @[@1,@2,@3];
    
    NSNumber *num = testArray[3];
}
  • 字典构造造与修改

示例代码:

- (void)testDicSetNilValueCrash
{
    // 构造不可变字典时 key和value都不能为空
    NSString *nilValue = nil;
    NSString *nilKey = nil;
    NSDictionary *dic1 = @{@"key" : nilValue};
    NSDictionary *dic2 = @{nilKey : @"value"};
}

方法交换

  • Runtime解决数据越界及字典key或value为nil的情况,主要通过Runtime的方法交换实现,可以扩展一下NSObject分类:
+ (void)exchangeInstanceMethodWithSelfClass:(Class)selfClass
                           originalSelector:(SEL)originalSelector
                           swizzledSelector:(SEL)swizzledSelector {
    
    Method originalMethod = class_getInstanceMethod(selfClass, originalSelector);
    Method swizzledMethod = class_getInstanceMethod(selfClass, swizzledSelector);
    BOOL didAddMethod = class_addMethod(selfClass,
                                        originalSelector,
                                        method_getImplementation(swizzledMethod),
                                        method_getTypeEncoding(swizzledMethod));
    if (didAddMethod) {
        class_replaceMethod(selfClass,
                            swizzledSelector,
                            method_getImplementation(originalMethod),
                            method_getTypeEncoding(originalMethod));
    } else {
        method_exchangeImplementations(originalMethod, swizzledMethod);
    }
}
/**
 在range范围内, 移除掉anObject
 
 @param anObject 移除的anObject
 @param range 范围
 */
- (void)safeMutable_removeObject:(id)anObject inRange:(NSRange)range {
    if (range.location > self.count) {
        return;
    }
    
    if (range.length > self.count) {
        return;
    }
    
    if ((range.location + range.length) > self.count) {
        return;
    }
    
    if (!anObject){
        return;
    }
    
    
    return [self safeMutable_removeObject:anObject inRange:range];
    
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].