Skip to content

Commit eaff9d3

Browse files
author
李杰
committed
Support the NSSet,NSMutableSet
1 parent d89d2e4 commit eaff9d3

File tree

11 files changed

+134
-127
lines changed

11 files changed

+134
-127
lines changed

JJException.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "JJException"
19-
s.version = "0.1.2"
19+
s.version = "0.1.3"
2020
s.summary = "Handle the objective-c crash exception."
2121

2222
# This description is used to generate tags and improve search results.

JJException.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
61025B8921563A6400191522 /* NSObject+UnrecognizedSelectorHook.h in Sources */ = {isa = PBXBuildFile; fileRef = 61A7F53E21427E4100C87FA1 /* NSObject+UnrecognizedSelectorHook.h */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
4545
61025B8A21563A6400191522 /* NSObject+UnrecognizedSelectorHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A7F53F21427E4100C87FA1 /* NSObject+UnrecognizedSelectorHook.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
4646
61025B8B21563ABB00191522 /* JJException.h in Headers */ = {isa = PBXBuildFile; fileRef = 613E0A8C21496ED100B8D0DF /* JJException.h */; settings = {ATTRIBUTES = (Public, ); }; };
47+
6109EE7A2198244A00CB15E6 /* NSSet+SetHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 6109EE792198244A00CB15E6 /* NSSet+SetHook.m */; };
48+
6109EE7D2198264F00CB15E6 /* NSMutableSet+MutableSetHook.m in Sources */ = {isa = PBXBuildFile; fileRef = 6109EE7C2198264F00CB15E6 /* NSMutableSet+MutableSetHook.m */; };
4749
61196D4720F261C800022DDC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 61196D4620F261C800022DDC /* AppDelegate.m */; };
4850
61196D4A20F261C800022DDC /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61196D4920F261C800022DDC /* ViewController.m */; };
4951
61196D4D20F261C800022DDC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61196D4B20F261C800022DDC /* Main.storyboard */; };
@@ -87,6 +89,10 @@
8789
61025B4F2153E58F00191522 /* NSMutableAttributedString+MutableAttributedStringHook.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableAttributedString+MutableAttributedStringHook.m"; sourceTree = "<group>"; };
8890
61025B5C215639B700191522 /* JJException.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JJException.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8991
61025B5F215639B700191522 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
92+
6109EE782198244A00CB15E6 /* NSSet+SetHook.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSSet+SetHook.h"; sourceTree = "<group>"; };
93+
6109EE792198244A00CB15E6 /* NSSet+SetHook.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSSet+SetHook.m"; sourceTree = "<group>"; };
94+
6109EE7B2198264F00CB15E6 /* NSMutableSet+MutableSetHook.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableSet+MutableSetHook.h"; sourceTree = "<group>"; };
95+
6109EE7C2198264F00CB15E6 /* NSMutableSet+MutableSetHook.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableSet+MutableSetHook.m"; sourceTree = "<group>"; };
9096
61196D4220F261C800022DDC /* JJException.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JJException.app; sourceTree = BUILT_PRODUCTS_DIR; };
9197
61196D4520F261C800022DDC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
9298
61196D4620F261C800022DDC /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -287,6 +293,10 @@
287293
61025B4C2153E36100191522 /* NSAttributedString+AttributedStringHook.m */,
288294
61025B4E2153E58F00191522 /* NSMutableAttributedString+MutableAttributedStringHook.h */,
289295
61025B4F2153E58F00191522 /* NSMutableAttributedString+MutableAttributedStringHook.m */,
296+
6109EE782198244A00CB15E6 /* NSSet+SetHook.h */,
297+
6109EE792198244A00CB15E6 /* NSSet+SetHook.m */,
298+
6109EE7B2198264F00CB15E6 /* NSMutableSet+MutableSetHook.h */,
299+
6109EE7C2198264F00CB15E6 /* NSMutableSet+MutableSetHook.m */,
290300
);
291301
path = ARC;
292302
sourceTree = "<group>";
@@ -498,7 +508,9 @@
498508
613E0AAD214FF41B00B8D0DF /* NSObject+DeallocBlock.m in Sources */,
499509
61025B502153E58F00191522 /* NSMutableAttributedString+MutableAttributedStringHook.m in Sources */,
500510
613E0A8E21496ED100B8D0DF /* JJException.m in Sources */,
511+
6109EE7D2198264F00CB15E6 /* NSMutableSet+MutableSetHook.m in Sources */,
501512
61196D4720F261C800022DDC /* AppDelegate.m in Sources */,
513+
6109EE7A2198244A00CB15E6 /* NSSet+SetHook.m in Sources */,
502514
61A7F5562144D0FA00C87FA1 /* NSObject+SwizzleHook.m in Sources */,
503515
61A7F54E21427EB700C87FA1 /* NSMutableArray+MutableArrayHook.m in Sources */,
504516
61A7F54D21427EB700C87FA1 /* NSDictionary+DictionaryHook.m in Sources */,

JJException.xcodeproj/xcuserdata/jezz.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -2,128 +2,4 @@
22
<Bucket
33
type = "1"
44
version = "2.0">
5-
<Breakpoints>
6-
<BreakpointProxy
7-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8-
<BreakpointContent
9-
shouldBeEnabled = "Yes"
10-
ignoreCount = "0"
11-
continueAfterRunningActions = "No"
12-
filePath = "JJException/Source/MRC/NSObject+UnrecognizedSelectorHook.m"
13-
timestampString = "561397405.780197"
14-
startingColumnNumber = "9223372036854775807"
15-
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "10"
17-
endingLineNumber = "10"
18-
landmarkName = "unknown"
19-
landmarkType = "0">
20-
</BreakpointContent>
21-
</BreakpointProxy>
22-
<BreakpointProxy
23-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
24-
<BreakpointContent
25-
shouldBeEnabled = "Yes"
26-
ignoreCount = "0"
27-
continueAfterRunningActions = "No"
28-
filePath = "JJException/Source/ARC/NSNotificationCenter+ClearNotification.m"
29-
timestampString = "561635354.75411"
30-
startingColumnNumber = "9223372036854775807"
31-
endingColumnNumber = "9223372036854775807"
32-
startingLineNumber = "29"
33-
endingLineNumber = "29"
34-
landmarkName = "-processAddObserver:selector:name:object:swizzleInfo:"
35-
landmarkType = "7">
36-
</BreakpointContent>
37-
</BreakpointProxy>
38-
<BreakpointProxy
39-
BreakpointExtensionID = "Xcode.Breakpoint.SymbolicBreakpoint">
40-
<BreakpointContent
41-
shouldBeEnabled = "Yes"
42-
ignoreCount = "0"
43-
continueAfterRunningActions = "No"
44-
symbolName = "[__NSArrayM removeObjectsInRange:]"
45-
moduleName = "">
46-
<Locations>
47-
<Location
48-
shouldBeEnabled = "Yes"
49-
ignoreCount = "0"
50-
continueAfterRunningActions = "No"
51-
symbolName = "-[__NSArrayM removeObjectsInRange:]"
52-
moduleName = "CoreFoundation"
53-
usesParentBreakpointCondition = "Yes"
54-
offsetFromSymbolStart = "0">
55-
</Location>
56-
</Locations>
57-
</BreakpointContent>
58-
</BreakpointProxy>
59-
<BreakpointProxy
60-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
61-
<BreakpointContent
62-
shouldBeEnabled = "Yes"
63-
ignoreCount = "0"
64-
continueAfterRunningActions = "No"
65-
filePath = "JJExceptionTests/JJExceptionTests.m"
66-
timestampString = "561806569.301136"
67-
startingColumnNumber = "9223372036854775807"
68-
endingColumnNumber = "9223372036854775807"
69-
startingLineNumber = "127"
70-
endingLineNumber = "127"
71-
landmarkName = "-testMutableString"
72-
landmarkType = "7">
73-
</BreakpointContent>
74-
</BreakpointProxy>
75-
<BreakpointProxy
76-
BreakpointExtensionID = "Xcode.Breakpoint.SymbolicBreakpoint">
77-
<BreakpointContent
78-
shouldBeEnabled = "Yes"
79-
ignoreCount = "0"
80-
continueAfterRunningActions = "No"
81-
symbolName = "[NSMutableArray removeObject:]"
82-
moduleName = "">
83-
<Locations>
84-
<Location
85-
shouldBeEnabled = "Yes"
86-
ignoreCount = "0"
87-
continueAfterRunningActions = "No"
88-
symbolName = "-[NSMutableArray removeObject:]"
89-
moduleName = "CoreFoundation"
90-
usesParentBreakpointCondition = "Yes"
91-
offsetFromSymbolStart = "0">
92-
</Location>
93-
</Locations>
94-
</BreakpointContent>
95-
</BreakpointProxy>
96-
<BreakpointProxy
97-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
98-
<BreakpointContent
99-
shouldBeEnabled = "Yes"
100-
ignoreCount = "0"
101-
continueAfterRunningActions = "No"
102-
filePath = "JJException/Source/MRC/NSMutableArray+MutableArrayHook.m"
103-
timestampString = "561799150.152006"
104-
startingColumnNumber = "9223372036854775807"
105-
endingColumnNumber = "9223372036854775807"
106-
startingLineNumber = "84"
107-
endingLineNumber = "84"
108-
landmarkName = "-hookRemoveObjectsInRange:"
109-
landmarkType = "7">
110-
</BreakpointContent>
111-
</BreakpointProxy>
112-
<BreakpointProxy
113-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
114-
<BreakpointContent
115-
shouldBeEnabled = "Yes"
116-
ignoreCount = "0"
117-
continueAfterRunningActions = "No"
118-
filePath = "JJExceptionTests/JJExceptionTests.m"
119-
timestampString = "561806569.301685"
120-
startingColumnNumber = "9223372036854775807"
121-
endingColumnNumber = "9223372036854775807"
122-
startingLineNumber = "99"
123-
endingLineNumber = "99"
124-
landmarkName = "-testZombieException"
125-
landmarkType = "7">
126-
</BreakpointContent>
127-
</BreakpointProxy>
128-
</Breakpoints>
1295
</Bucket>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// NSMutableSet+MutableSetHook.h
3+
// JJException
4+
//
5+
// Created by Jezz on 2018/11/11.
6+
// Copyright © 2018年 Jezz. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface NSMutableSet (MutableSetHook)
14+
15+
+ (void)jj_swizzleNSMutableSet;
16+
17+
@end
18+
19+
NS_ASSUME_NONNULL_END
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// NSMutableSet+MutableSetHook.m
3+
// JJException
4+
//
5+
// Created by Jezz on 2018/11/11.
6+
// Copyright © 2018年 Jezz. All rights reserved.
7+
//
8+
9+
#import "NSMutableSet+MutableSetHook.h"
10+
#import "NSObject+SwizzleHook.h"
11+
#import <objc/runtime.h>
12+
#import "JJExceptionProxy.h"
13+
14+
@implementation NSMutableSet (MutableSetHook)
15+
16+
+ (void)jj_swizzleNSMutableSet{
17+
NSMutableSet* instanceObject = [NSMutableSet new];
18+
Class cls = object_getClass(instanceObject);
19+
20+
swizzleInstanceMethod(cls,@selector(addObject:), @selector(hookAddObject:));
21+
swizzleInstanceMethod(cls,@selector(removeObject:), @selector(hookRemoveObject:));
22+
}
23+
24+
- (void) hookAddObject:(id)object {
25+
if (object) {
26+
[self hookAddObject:object];
27+
} else {
28+
handleCrashException(JJExceptionGuardArrayContainer,@"NSSet addObject nil object");
29+
}
30+
}
31+
32+
- (void) hookRemoveObject:(id)object {
33+
if (object) {
34+
[self hookRemoveObject:object];
35+
} else {
36+
handleCrashException(JJExceptionGuardArrayContainer,@"NSSet removeObject nil object");
37+
}
38+
}
39+
40+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// NSSet+SetHook.h
3+
// JJException
4+
//
5+
// Created by Jezz on 2018/11/11.
6+
// Copyright © 2018年 Jezz. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface NSSet (SetHook)
14+
15+
+ (void)jj_swizzleNSSet;
16+
17+
@end
18+
19+
NS_ASSUME_NONNULL_END
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// NSSet+SetHook.m
3+
// JJException
4+
//
5+
// Created by Jezz on 2018/11/11.
6+
// Copyright © 2018年 Jezz. All rights reserved.
7+
//
8+
9+
#import "NSSet+SetHook.h"
10+
#import "NSObject+SwizzleHook.h"
11+
#import "JJExceptionProxy.h"
12+
13+
@implementation NSSet (SetHook)
14+
15+
+ (void)jj_swizzleNSSet{
16+
[NSSet jj_swizzleClassMethod:@selector(setWithObject:) withSwizzleMethod:@selector(hookSetWithObject:)];
17+
}
18+
19+
+ (instancetype)hookSetWithObject:(id)object{
20+
if (object){
21+
return [self hookSetWithObject:object];
22+
}
23+
handleCrashException(JJExceptionGuardArrayContainer,@"NSSet setWithObject nil object");
24+
return nil;
25+
}
26+
27+
@end

JJException/Source/MRC/NSObject+KVOCrash.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ - (void)dealloc{
134134
- (void)clearKVOData{
135135
for (KVOObjectItem* item in self.kvoObjectSet) {
136136
//Invoke the origin removeObserver,do not check array
137-
handleCrashException(JJExceptionGuardKVOCrash,[NSString stringWithFormat:@"KVO forgot remove keyPath:%@",item.keyPath]);
137+
handleCrashException(JJExceptionGuardKVOCrash,[NSString stringWithFormat:@"KVO forgot remove keyPath:%@ from which object:%@",item.keyPath,NSStringFromClass(object_getClass(self.whichObject))]);
138138
#pragma clang diagnostic push
139139
#pragma clang diagnostic ignored "-Wundeclared-selector"
140140
@try {

JJException/Source/Main/JJExceptionProxy.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ - (void)setIsProtectException:(BOOL)isProtectException{
144144
if(self.exceptionGuardCategory & JJExceptionGuardArrayContainer){
145145
[NSArray performSelector:@selector(jj_swizzleNSArray)];
146146
[NSMutableArray performSelector:@selector(jj_swizzleNSMutableArray)];
147+
[NSSet performSelector:@selector(jj_swizzleNSSet)];
148+
[NSMutableSet performSelector:@selector(jj_swizzleNSMutableSet)];
147149
}
148150
if(self.exceptionGuardCategory & JJExceptionGuardDictionaryContainer){
149151
[NSDictionary performSelector:@selector(jj_swizzleNSDictionary)];

0 commit comments

Comments
 (0)