Skip to content

Commit 30a4c24

Browse files
author
xgf
committed
init
0 parents  commit 30a4c24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3271
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

FIX.xcodeproj/project.pbxproj

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

FIX.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>FIX.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>2</integer>
11+
</dict>
12+
</dict>
13+
</dict>
14+
</plist>

FIX.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Binary file not shown.

HotFix/HotFix.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// HotFix.h
3+
// FIX
4+
//
5+
// Created by xgf on 2018/6/20.
6+
// Copyright © 2018年 xgf. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface HotFix : NSObject
12+
13+
+ (instancetype)shared;
14+
15+
- (void)fix:(NSString *)js;
16+
17+
@end

HotFix/HotFix.m

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//
2+
// HotFix.m
3+
// FIX
4+
//
5+
// Created by xgf on 2018/6/20.
6+
// Copyright © 2018年 xgf. All rights reserved.
7+
//
8+
9+
#import "HotFix.h"
10+
#import <objc/runtime.h>
11+
#import <JavaScriptCore/JavaScriptCore.h>
12+
#import <Aspects/Aspects.h>
13+
14+
static HotFix *fixManager = nil;
15+
16+
@interface HotFix()
17+
18+
@property(nonatomic, copy)JSContext *context;
19+
20+
@end
21+
22+
@implementation HotFix
23+
24+
+ (instancetype)shared {
25+
static dispatch_once_t onceToken;
26+
dispatch_once(&onceToken, ^{
27+
fixManager = [[HotFix alloc] init];
28+
});
29+
return fixManager;
30+
}
31+
- (instancetype)init {
32+
if(self = [super init]) {
33+
[self setup];
34+
}
35+
return self;
36+
}
37+
- (JSContext *)context {
38+
if(!_context) {
39+
_context = [[JSContext alloc] init];
40+
_context.exceptionHandler = ^(JSContext *context, JSValue *exception) {
41+
NSLog(@"Ohooo: %@",exception);
42+
};
43+
}
44+
return _context;
45+
}
46+
- (void)fix:(NSString *)js {
47+
[self.context evaluateScript:js];
48+
}
49+
- (void)fixWithMethod:(BOOL)isClassMethod aspectionOptions:(AspectOptions)option instanceName:(NSString *)instanceName selectorName:(NSString *)selectorName fixImpl:(JSValue *)fixImpl {
50+
Class klass = NSClassFromString(instanceName);
51+
if (isClassMethod) {
52+
klass = object_getClass(klass);
53+
}
54+
SEL sel = NSSelectorFromString(selectorName);
55+
[klass aspect_hookSelector:sel withOptions:option usingBlock:^(id<AspectInfo> aspectInfo){
56+
[fixImpl callWithArguments:@[aspectInfo.instance, aspectInfo.originalInvocation, aspectInfo.arguments]];
57+
} error:nil];
58+
}
59+
60+
- (id)runClassWithClassName:(NSString *)className selector:(NSString *)selector obj1:(id)obj1 obj2:(id)obj2 {
61+
Class klass = NSClassFromString(className);
62+
#pragma clang diagnostic push
63+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
64+
return [klass performSelector:NSSelectorFromString(selector) withObject:obj1 withObject:obj2];
65+
#pragma clang diagnostic pop
66+
}
67+
68+
- (id)runInstanceWithInstance:(id)instance selector:(NSString *)selector obj1:(id)obj1 obj2:(id)obj2 {
69+
#pragma clang diagnostic push
70+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
71+
return [instance performSelector:NSSelectorFromString(selector) withObject:obj1 withObject:obj2];
72+
#pragma clang diagnostic pop
73+
}
74+
- (void)setup {
75+
__weak typeof(self) wkself = self;
76+
self.context[@"fixInstanceMethodBefore"] = ^(NSString *instanceName, NSString *selectorName, JSValue *fixImpl) {
77+
[wkself fixWithMethod:NO aspectionOptions:AspectPositionBefore instanceName:instanceName selectorName:selectorName fixImpl:fixImpl];
78+
};
79+
[self context][@"fixInstanceMethodReplace"] = ^(NSString *instanceName, NSString *selectorName, JSValue *fixImpl) {
80+
[wkself fixWithMethod:NO aspectionOptions:AspectPositionInstead instanceName:instanceName selectorName:selectorName fixImpl:fixImpl];
81+
};
82+
[self context][@"fixInstanceMethodAfter"] = ^(NSString *instanceName, NSString *selectorName, JSValue *fixImpl) {
83+
[wkself fixWithMethod:NO aspectionOptions:AspectPositionAfter instanceName:instanceName selectorName:selectorName fixImpl:fixImpl];
84+
};
85+
[self context][@"fixClassMethodBefore"] = ^(NSString *instanceName, NSString *selectorName, JSValue *fixImpl) {
86+
[wkself fixWithMethod:YES aspectionOptions:AspectPositionBefore instanceName:instanceName selectorName:selectorName fixImpl:fixImpl];
87+
};
88+
[self context][@"fixClassMethodReplace"] = ^(NSString *instanceName, NSString *selectorName, JSValue *fixImpl) {
89+
[wkself fixWithMethod:YES aspectionOptions:AspectPositionInstead instanceName:instanceName selectorName:selectorName fixImpl:fixImpl];
90+
};
91+
[self context][@"fixClassMethodAfter"] = ^(NSString *instanceName, NSString *selectorName, JSValue *fixImpl) {
92+
[wkself fixWithMethod:YES aspectionOptions:AspectPositionAfter instanceName:instanceName selectorName:selectorName fixImpl:fixImpl];
93+
};
94+
[self context][@"runClassWithNoParamter"] = ^id(NSString *className, NSString *selectorName) {
95+
return [wkself runClassWithClassName:className selector:selectorName obj1:nil obj2:nil];
96+
};
97+
[self context][@"runClassWith1Paramter"] = ^id(NSString *className, NSString *selectorName, id obj1) {
98+
return [wkself runClassWithClassName:className selector:selectorName obj1:obj1 obj2:nil];
99+
};
100+
[self context][@"runClassWith2Paramters"] = ^id(NSString *className, NSString *selectorName, id obj1, id obj2) {
101+
return [wkself runClassWithClassName:className selector:selectorName obj1:obj1 obj2:obj2];
102+
};
103+
[self context][@"runVoidClassWithNoParamter"] = ^(NSString *className, NSString *selectorName) {
104+
[wkself runClassWithClassName:className selector:selectorName obj1:nil obj2:nil];
105+
};
106+
[self context][@"runVoidClassWith1Paramter"] = ^(NSString *className, NSString *selectorName, id obj1) {
107+
[wkself runClassWithClassName:className selector:selectorName obj1:obj1 obj2:nil];
108+
};
109+
[self context][@"runVoidClassWith2Paramters"] = ^(NSString *className, NSString *selectorName, id obj1, id obj2) {
110+
[wkself runClassWithClassName:className selector:selectorName obj1:obj1 obj2:obj2];
111+
};
112+
[self context][@"runInstanceWithNoParamter"] = ^id(id instance, NSString *selectorName) {
113+
return [wkself runInstanceWithInstance:instance selector:selectorName obj1:nil obj2:nil];
114+
};
115+
[self context][@"runInstanceWith1Paramter"] = ^id(id instance, NSString *selectorName, id obj1) {
116+
return [wkself runInstanceWithInstance:instance selector:selectorName obj1:obj1 obj2:nil];
117+
};
118+
[self context][@"runInstanceWith2Paramters"] = ^id(id instance, NSString *selectorName, id obj1, id obj2) {
119+
return [wkself runInstanceWithInstance:instance selector:selectorName obj1:obj1 obj2:obj2];
120+
};
121+
[self context][@"runVoidInstanceWithNoParamter"] = ^(id instance, NSString *selectorName) {
122+
[wkself runInstanceWithInstance:instance selector:selectorName obj1:nil obj2:nil];
123+
};
124+
[self context][@"runVoidInstanceWith1Paramter"] = ^(id instance, NSString *selectorName, id obj1) {
125+
[wkself runInstanceWithInstance:instance selector:selectorName obj1:obj1 obj2:nil];
126+
};
127+
[self context][@"runVoidInstanceWith2Paramters"] = ^(id instance, NSString *selectorName, id obj1, id obj2) {
128+
[wkself runInstanceWithInstance:instance selector:selectorName obj1:obj1 obj2:obj2];
129+
};
130+
[self context][@"runInvocation"] = ^(NSInvocation *invocation) {
131+
[invocation invoke];
132+
};
133+
[[self context] evaluateScript:@"var console = {}"];
134+
[self context][@"console"][@"log"] = ^(id message) {
135+
NSLog(@"Javascript log: %@",message);
136+
};
137+
}
138+
139+
@end

Podfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Uncomment the next line to define a global platform for your project
2+
# platform :ios, '9.0'
3+
4+
target 'FIX' do
5+
inhibit_all_warnings!
6+
# use_frameworks!
7+
# Pods for FIX
8+
pod "Aspects"
9+
end

Podfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PODS:
2+
- Aspects (1.4.1)
3+
4+
DEPENDENCIES:
5+
- Aspects
6+
7+
SPEC CHECKSUMS:
8+
Aspects: 7595ba96a6727a58ebcbfc954497fc5d2fdde546
9+
10+
PODFILE CHECKSUM: 6faffa4a9a2b6c009dd1fd172139bf9fb114ebc0
11+
12+
COCOAPODS: 1.4.0

Pods/Aspects/Aspects.h

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)