Skip to content

Commit

Permalink
Support Earl Grey swizzles in network recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoNatan committed May 12, 2019
1 parent d80d9cb commit 5705dad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DetoxInstruments/DetoxInstruments/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
<key>CFBundleShortVersionString</key>
<string>1.10</string>
<key>CFBundleVersion</key>
<string>10233</string>
<string>10238</string>
<key>DTXBuildDate</key>
<date>2019-04-24T00:28:55Z</date>
<date>2019-05-12T13:41:41Z</date>
<key>DTXSourceRoot</key>
<string>$(DTXSRCROOT)</string>
<key>LSMinimumSystemVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions Profiler/DTXProfiler/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundleShortVersionString</key>
<string>1.10</string>
<key>CFBundleVersion</key>
<string>10233</string>
<string>10238</string>
<key>DTXBuildDate</key>
<date>2019-04-24T00:28:55Z</date>
<date>2019-05-12T13:41:41Z</date>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,37 @@ + (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(resume));
Class cls = NSClassFromString(@"__NSCFLocalDataTask");

Method m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalDataTask"), NSSelectorFromString(@"greyswizzled_resume"));
if(m1 == NULL)
{
m1 = class_getInstanceMethod(cls, @selector(resume));
}
Method m2 = class_getInstanceMethod(self.class, @selector(__dtx_resume));
method_exchangeImplementations(m1, m2);

m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(connection:didReceiveResponse:completion:));
m1 = class_getInstanceMethod(cls, @selector(connection:didReceiveResponse:completion:));
m2 = class_getInstanceMethod(self.class, @selector(__dtx_connection:didReceiveResponse:completion:));
method_exchangeImplementations(m1, m2);

m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(connection:didFinishLoadingWithError:));
m1 = class_getInstanceMethod(cls, @selector(connection:didFinishLoadingWithError:));
m2 = class_getInstanceMethod(self.class, @selector(__dtx_connection:didFinishLoadingWithError:));
method_exchangeImplementations(m1, m2);

m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(connection:didReceiveData:completion:));
m1 = class_getInstanceMethod(cls, @selector(connection:didReceiveData:completion:));
m2 = class_getInstanceMethod(self.class, @selector(__dtx_connection:didReceiveData:completion:));
method_exchangeImplementations(m1, m2);

m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(connection:didFinishCollectingMetrics:completion:));
m1 = class_getInstanceMethod(cls, @selector(connection:didFinishCollectingMetrics:completion:));
m2 = class_getInstanceMethod(self.class, @selector(__dtx_connection:didFinishCollectingMetrics:completion:));
method_exchangeImplementations(m1, m2);

m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(initWithOriginalRequest:updatedRequest:ident:session:));
m1 = class_getInstanceMethod(cls, @selector(initWithOriginalRequest:updatedRequest:ident:session:));
m2 = class_getInstanceMethod(self.class, @selector(initWithOriginalRequest__dtx:updatedRequest:ident:session:));
method_exchangeImplementations(m1, m2);

m1 = class_getInstanceMethod(NSClassFromString(@"__NSCFLocalSessionTask"), @selector(_onqueue_didFinishCollectingMetrics:completion:));
m1 = class_getInstanceMethod(cls, @selector(_onqueue_didFinishCollectingMetrics:completion:));
m2 = class_getInstanceMethod(self.class, @selector(__dtx_onqueue_didFinishCollectingMetrics:completion:));
method_exchangeImplementations(m1, m2);
});
Expand Down

0 comments on commit 5705dad

Please sign in to comment.