├── injectURLProtocol.cy ├── LICENSE └── README.md /injectURLProtocol.cy: -------------------------------------------------------------------------------- 1 | @import org.cycript.NSLog; 2 | 3 | function loadURLProtocol() { 4 | @implementation InterceptURLProtocol : NSURLProtocol {} 5 | 6 | + (BOOL)canInitWithRequest:(NSURLRequest *)request { 7 | NSLog("Req: " + request.HTTPMethod + " " + request.URL + 8 | " Headers: " + request.allHTTPHeaderFields); 9 | 10 | return NO; 11 | } 12 | 13 | @end 14 | } 15 | 16 | function injectURLProtocol() { 17 | try { 18 | [InterceptURLProtocol class]; 19 | } catch (e) { 20 | loadURLProtocol(); 21 | } 22 | 23 | [NSURLProtocol registerClass:[InterceptURLProtocol class]]; 24 | NSLog("Injected custom NSURLProtocol"); 25 | } 26 | 27 | injectURLProtocol(); 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Keith Smiley (http://keith.so) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the 'Software'), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # injectURLProtocol 2 | 3 | This is a simple [cycript][cycript] script for injecting a custom 4 | [`NSURLProtocol`][protocol] that logs every HTTP request. 5 | 6 | ## Installation 7 | 8 | Install [cycript][cycript]. If you'd like to use [homebrew][brew] 9 | instead you can use [my tap][tap] with: 10 | 11 | ```sh 12 | $ brew install keith/formulae/cycript 13 | ``` 14 | 15 | Then copy `injectURLProtocol.cy` to somewhere you can reference it. 16 | 17 | ## Usage 18 | 19 | Run the script in the process in question: 20 | 21 | ```sh 22 | $ cycript -p APPLICATION injectURLProtocol.cy 23 | ``` 24 | 25 | Then open Console.app to see messages formatted like this: 26 | 27 | ``` 28 | 1/1/70 00:00:00.000 Slack[83206]: Req: POST https://slack.com/api/api.test?error= Headers: { 29 | "Content-Type" = "application/x-www-form-urlencoded"; 30 | Origin = "file://"; 31 | "User-Agent" = "..."; 32 | } 33 | ``` 34 | 35 | **NOTE**: To make it easier to just see these requests, you can filter 36 | by searching for `Req:` 37 | 38 | ## Alternatives 39 | 40 | Depending on what else you're doing with cycript, you might actually be 41 | better off using [`CFNETWORK_DIAGNOSTICS`][cfnetwork] which can provide 42 | similar functionality without any addition configuration. You can simple 43 | using this environment variable when launching the binary in question 44 | like this: 45 | 46 | ```sh 47 | $ CFNETWORK_DIAGNOSTICS=3 path/to/binary 48 | ``` 49 | 50 | ### Warning 51 | 52 | This script could print sensitive information into your console. Be 53 | careful out there! 54 | 55 | [brew]: http://brew.sh/ 56 | [cfnetwork]: https://developer.apple.com/library/mac/qa/qa1887/_index.html 57 | [cycript]: http://www.cycript.org/ 58 | [protocol]: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURLProtocol_Class/index.html 59 | [tap]: https://github.com/keith/homebrew-formulae 60 | --------------------------------------------------------------------------------