├── .gitignore ├── LICENSE ├── OCDebugger.podspec ├── OCDebugger.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── OCDebugger.xcworkspace └── contents.xcworkspacedata ├── OCDebugger ├── Classes │ ├── Common │ │ ├── Core │ │ │ ├── OCDCore.h │ │ │ └── OCDCore.m │ │ ├── Define │ │ │ ├── OCDDefine.h │ │ │ ├── OCDDefine.m │ │ │ ├── OCDHTTPWatcherDefine.h │ │ │ └── OCDHTTPWatcherDefine.m │ │ ├── Helper │ │ │ ├── OCDOutputHelper.h │ │ │ ├── OCDOutputHelper.m │ │ │ ├── OCDProtocolHelper.h │ │ │ ├── OCDProtocolHelper.m │ │ │ ├── OCDValueFormatter.h │ │ │ └── OCDValueFormatter.m │ │ └── Socket │ │ │ ├── Manager │ │ │ ├── OCDSocketServiceManager.h │ │ │ └── OCDSocketServiceManager.m │ │ │ └── Service │ │ │ ├── OCDConnService.h │ │ │ ├── OCDConnService.m │ │ │ ├── OCDDeviceService.h │ │ │ ├── OCDDeviceService.m │ │ │ ├── OCDFinderService.h │ │ │ ├── OCDFinderService.m │ │ │ ├── OCDHTTPWatcherService.h │ │ │ ├── OCDHTTPWatcherService.m │ │ │ ├── OCDLogService.h │ │ │ ├── OCDLogService.m │ │ │ ├── OCDPointService.h │ │ │ ├── OCDPointService.m │ │ │ ├── OCDPubService.h │ │ │ ├── OCDPubService.m │ │ │ ├── OCDSubService.h │ │ │ └── OCDSubService.m │ └── Modules │ │ ├── Dashboard │ │ ├── Application Logic │ │ │ ├── Hooker │ │ │ │ ├── OCDDashboardShakeHooker.h │ │ │ │ └── OCDDashboardShakeHooker.m │ │ │ └── Manager │ │ │ │ ├── OCDDashboardHookManager.h │ │ │ │ └── OCDDashboardHookManager.m │ │ ├── Module Interface │ │ │ ├── OCDDashboardCore.h │ │ │ └── OCDDashboardCore.m │ │ └── User Interface │ │ │ ├── Interactor │ │ │ ├── OCDDashboardPointInteractor.h │ │ │ ├── OCDDashboardPointInteractor.m │ │ │ ├── OCDDashboardPointItemInteractor.h │ │ │ └── OCDDashboardPointItemInteractor.m │ │ │ ├── Presenter │ │ │ ├── OCDDashboardPointPresenter.h │ │ │ └── OCDDashboardPointPresenter.m │ │ │ ├── View │ │ │ ├── OCDDashboardInformationViewController.h │ │ │ ├── OCDDashboardInformationViewController.m │ │ │ ├── OCDDashboardLogViewController.h │ │ │ ├── OCDDashboardLogViewController.m │ │ │ ├── OCDDashboardPointTableViewCell.h │ │ │ ├── OCDDashboardPointTableViewCell.m │ │ │ ├── OCDDashboardPointViewController.h │ │ │ └── OCDDashboardPointViewController.m │ │ │ └── Wireframe │ │ │ ├── OCDDashboardWireframe.h │ │ │ └── OCDDashboardWireframe.m │ │ ├── Finder │ │ ├── Application Logic │ │ │ └── Manager │ │ │ │ ├── OCDFinderManager.h │ │ │ │ └── OCDFinderManager.m │ │ └── Module Interface │ │ │ ├── OCDFinderCore.h │ │ │ └── OCDFinderCore.m │ │ ├── HTTPWatcher │ │ ├── Application Logic │ │ │ ├── Entity │ │ │ │ ├── OCDHTTPWatcherConnectionEntity.h │ │ │ │ ├── OCDHTTPWatcherConnectionEntity.m │ │ │ │ ├── OCDHTTPWatcherHostEntity.h │ │ │ │ ├── OCDHTTPWatcherHostEntity.m │ │ │ │ ├── OCDHTTPWatcherMappingEntity.h │ │ │ │ ├── OCDHTTPWatcherMappingEntity.m │ │ │ │ ├── OCDHTTPWatcherRewriteEntity.h │ │ │ │ └── OCDHTTPWatcherRewriteEntity.m │ │ │ ├── Manager │ │ │ │ ├── OCDHTTPWatcherConnectionManager.h │ │ │ │ ├── OCDHTTPWatcherConnectionManager.m │ │ │ │ ├── OCDHTTPWatcherHostsManager.h │ │ │ │ ├── OCDHTTPWatcherHostsManager.m │ │ │ │ ├── OCDHTTPWatcherModifierManager.h │ │ │ │ └── OCDHTTPWatcherModifierManager.m │ │ │ └── Protocol │ │ │ │ ├── OCDHTTPWatcherURLProtocol.h │ │ │ │ └── OCDHTTPWatcherURLProtocol.m │ │ └── Module Interface │ │ │ ├── OCDHTTPWatcherCore.h │ │ │ └── OCDHTTPWatcherCore.m │ │ ├── OCDLog │ │ ├── Application Logic │ │ │ ├── Entity │ │ │ │ ├── OCDLogEntity.h │ │ │ │ └── OCDLogEntity.m │ │ │ └── Manager │ │ │ │ ├── OCDLogManager.h │ │ │ │ └── OCDLogManager.m │ │ └── Module Interface │ │ │ ├── OCDLogCore.h │ │ │ └── OCDLogCore.m │ │ └── OCDPoint │ │ ├── Application Logic │ │ ├── Entity │ │ │ ├── OCDPointEntity.h │ │ │ └── OCDPointEntity.m │ │ └── Manager │ │ │ ├── OCDPointManager.h │ │ │ └── OCDPointManager.m │ │ └── Module Interface │ │ ├── OCDPointCore.h │ │ └── OCDPointCore.m ├── OCDPrefixHeader.h ├── OCDebugger.h └── OCDebugger.m ├── OCDebuggerDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── OCDebuggerDemoTests ├── Info.plist └── OCDebuggerDemoTests.m ├── OCDebuggerTests └── Info.plist ├── Podfile ├── Podfile.lock ├── README.md └── README_Resources ├── 0.png ├── 1.png ├── 10.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PonyCui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /OCDebugger.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | 4 | s.name = "OCDebugger" 5 | s.version = "0.0.1" 6 | s.summary = "OCDebugger is an easy to use debugging toolset. You use OCDebugger debug your application on Web or iPhone." 7 | 8 | s.description = <<-DESC 9 | OCDebugger is an easy to use debugging toolset. You use OCDebugger debug your application on Web or iPhone. It's a client library and we provide an web application (OCDServer) holding all connection from iOS. Also, we provide a public web application here Open link, please feel free to use it, it's really stable. 10 | DESC 11 | 12 | s.homepage = "https://github.com/PonyCui/OCDebugger" 13 | 14 | s.license = "MIT" 15 | 16 | s.author = { "PonyCui" => "" } 17 | 18 | s.platform = :ios, "6.0" 19 | 20 | s.source = { :git => "https://github.com/PonyCui/OCDebugger.git" , :tag => "0.0.1" } 21 | 22 | s.source_files = "OCDebugger", "OCDebugger/Classes", "OCDebugger/Classes/**", "OCDebugger/Classes/**/**", "OCDebugger/Classes/**/**/**", "OCDebugger/Classes/**/**/**/**", "OCDebugger/Classes/**/**/**/**/**" 23 | 24 | s.requires_arc = true 25 | 26 | s.dependency "Aspects" 27 | s.dependency "SocketRocket" 28 | 29 | end 30 | -------------------------------------------------------------------------------- /OCDebugger.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OCDebugger.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Core/OCDCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDCore.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDHTTPWatcherCore.h" 11 | #import "OCDSocketServiceManager.h" 12 | #import "OCDPointCore.h" 13 | #import "OCDDashboardCore.h" 14 | #import "OCDLogCore.h" 15 | #import "OCDFinderCore.h" 16 | 17 | @interface OCDCore : NSObject 18 | 19 | + (OCDCore *)sharedCore; 20 | 21 | @property (nonatomic, strong) OCDHTTPWatcherCore *HTTPWatcher; 22 | 23 | @property (nonatomic, strong) OCDPointCore *point; 24 | 25 | @property (nonatomic, strong) OCDDashboardCore *dashboard; 26 | 27 | @property (nonatomic, strong) OCDLogCore *log; 28 | 29 | @property (nonatomic, strong) OCDFinderCore *finder; 30 | 31 | @property (nonatomic, strong) OCDSocketServiceManager *socketService; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Core/OCDCore.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDCore.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDCore.h" 10 | 11 | @implementation OCDCore 12 | 13 | + (OCDCore *)sharedCore { 14 | static OCDCore *instance; 15 | static dispatch_once_t onceToken; 16 | dispatch_once(&onceToken, ^{ 17 | instance = [[OCDCore alloc] init]; 18 | }); 19 | return instance; 20 | } 21 | 22 | - (OCDHTTPWatcherCore *)HTTPWatcher { 23 | if (_HTTPWatcher == nil) { 24 | _HTTPWatcher = [[OCDHTTPWatcherCore alloc] init]; 25 | } 26 | return _HTTPWatcher; 27 | } 28 | 29 | - (OCDPointCore *)point { 30 | if (_point == nil) { 31 | _point = [[OCDPointCore alloc] init]; 32 | } 33 | return _point; 34 | } 35 | 36 | - (OCDDashboardCore *)dashboard { 37 | if (_dashboard == nil) { 38 | _dashboard = [[OCDDashboardCore alloc] init]; 39 | } 40 | return _dashboard; 41 | } 42 | 43 | - (OCDLogCore *)log { 44 | if (_log == nil) { 45 | _log = [[OCDLogCore alloc] init]; 46 | } 47 | return _log; 48 | } 49 | 50 | - (OCDFinderCore *)finder { 51 | if (_finder == nil) { 52 | _finder = [[OCDFinderCore alloc] init]; 53 | } 54 | return _finder; 55 | } 56 | 57 | - (OCDSocketServiceManager *)socketService { 58 | if (_socketService == nil) { 59 | _socketService = [[OCDSocketServiceManager alloc] init]; 60 | } 61 | return _socketService; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Define/OCDDefine.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDefine.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDHTTPWatcherDefine.h" 11 | 12 | #define kOCDMessageStorageRequestKey @"OCDMessageStorageRequestKey" 13 | 14 | @interface OCDDefine : NSObject 15 | 16 | + (OCDDefine *)sharedDefine; 17 | 18 | @property (nonatomic, strong) OCDHTTPWatcherDefine *HTTPWatcher; 19 | 20 | @property (nonatomic, readonly) NSString *socketAddressRequestURLString; 21 | 22 | @property (nonatomic, copy) NSString *appID; 23 | 24 | @property (nonatomic, copy) NSString *appToken; 25 | 26 | - (NSString *)uniqueIdentifier; 27 | 28 | - (NSString *)storageAddAddressWithIdentifier:(NSString *)identifier; 29 | 30 | - (NSString *)storageFetchAddressWithIdentifier:(NSString *)identifier; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Define/OCDDefine.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | // 4 | // OCDDefine.m 5 | // OCDebugger 6 | // 7 | // Created by 崔 明辉 on 15/6/8. 8 | // Copyright (c) 2015年 PonyCui. All rights reserved. 9 | // 10 | 11 | #import "OCDDefine.h" 12 | #import 13 | 14 | @implementation OCDDefine 15 | 16 | + (OCDDefine *)sharedDefine { 17 | static OCDDefine *instance; 18 | static dispatch_once_t onceToken; 19 | dispatch_once(&onceToken, ^{ 20 | instance = [[OCDDefine alloc] init]; 21 | }); 22 | return instance; 23 | } 24 | 25 | - (OCDHTTPWatcherDefine *)HTTPWatcher { 26 | if (_HTTPWatcher == nil) { 27 | _HTTPWatcher = [[OCDHTTPWatcherDefine alloc] init]; 28 | } 29 | return _HTTPWatcher; 30 | } 31 | 32 | - (NSString *)socketAddressRequestURLString { 33 | // return @"http://localhost/OCDServer/index.php/pubsub/index"; 34 | return @"http://ocdebugger.sinaapp.com/index.php/pubsub/index"; 35 | } 36 | 37 | - (NSString *)uniqueIdentifier { 38 | return [NSString stringWithFormat:@"%@_%u_%u_%u", 39 | [[[[UIDevice currentDevice] identifierForVendor] UUIDString] substringToIndex:8], 40 | arc4random(), 41 | arc4random(), 42 | arc4random()]; 43 | } 44 | 45 | - (NSString *)storageAddAddressWithIdentifier:(NSString *)identifier { 46 | // return [NSString stringWithFormat:@"http://localhost/OCDServer/index.php/storage/add?identifier=%@", identifier]; 47 | return [NSString stringWithFormat:@"http://ocdebugger.sinaapp.com/index.php/storage/add?identifier=%@", identifier]; 48 | } 49 | 50 | - (NSString *)storageFetchAddressWithIdentifier:(NSString *)identifier { 51 | // return [NSString stringWithFormat:@"http://localhost/OCDServer/index.php/storage/fetch?identifier=%@", identifier]; 52 | return [NSString stringWithFormat:@"http://ocdebugger.sinaapp.com/index.php/storage/fetch?identifier=%@", identifier]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Define/OCDHTTPWatcherDefine.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherDefine.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherDefine : NSObject 12 | 13 | @property (nonatomic, assign) BOOL enabled; 14 | 15 | @property (nonatomic, readonly) NSString *modifierRequestURLString; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Define/OCDHTTPWatcherDefine.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherDefine.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherDefine.h" 10 | #import "OCDCore.h" 11 | #import "OCDDefine.h" 12 | 13 | @implementation OCDHTTPWatcherDefine 14 | 15 | - (void)setEnabled:(BOOL)enabled { 16 | _enabled = enabled; 17 | _enabled ? [[[OCDCore sharedCore] HTTPWatcher] install] : [[[OCDCore sharedCore] HTTPWatcher] uninstall]; 18 | } 19 | 20 | - (NSString *)modifierRequestURLString { 21 | // return [NSString stringWithFormat:@"http://localhost/OCDServer/index.php/modifier/fetch?appid=%@&apptoken=%@", 22 | // [[OCDDefine sharedDefine] appID], 23 | // [[OCDDefine sharedDefine] appToken]]; 24 | return [NSString stringWithFormat:@"http://ocdebugger.sinaapp.com/index.php/modifier/fetch?appid=%@&apptoken=%@", 25 | [[OCDDefine sharedDefine] appID], 26 | [[OCDDefine sharedDefine] appToken]]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Helper/OCDOutputHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // PPMOutputHelper.h 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15-3-29. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^PPMOutputHelperRequestDataObjectCompletionBlock)(id dataObject); 12 | 13 | @interface OCDOutputHelper : NSObject 14 | 15 | @property (nonatomic, strong) NSError *error; 16 | 17 | - (instancetype)initWithJSONObject:(id)JSONObject; 18 | 19 | - (instancetype)initWithJSONObject:(id)JSONObject eagerTypes:(NSDictionary *)eagerTypes; 20 | 21 | - (void)requestDataObjectWithCompletionBlock:(PPMOutputHelperRequestDataObjectCompletionBlock)completionBlock; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Helper/OCDOutputHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // PPMOutputHelper.m 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15-3-29. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import "OCDOutputHelper.h" 10 | #import "OCDValueFormatter.h" 11 | 12 | @interface OCDOutputHelper () 13 | 14 | @property (nonatomic, strong) id JSONObject; 15 | 16 | @property (nonatomic, strong) NSDictionary *eagerTypes; 17 | 18 | @end 19 | 20 | @implementation OCDOutputHelper 21 | 22 | - (instancetype)initWithJSONObject:(id)JSONObject { 23 | return [self initWithJSONObject:JSONObject eagerTypes:nil]; 24 | } 25 | 26 | - (instancetype)initWithJSONObject:(id)JSONObject eagerTypes:(NSDictionary *)eagerTypes { 27 | self = [super init]; 28 | if (self && [JSONObject isKindOfClass:[NSDictionary class]]) { 29 | if ([JSONObject[@"error_code"] integerValue] != 0) { 30 | NSString *errorDescription = JSONObject[@"error_description"]; 31 | if (errorDescription == nil) { 32 | errorDescription = @""; 33 | } 34 | self.error = [NSError errorWithDomain:@"PPM.outputHelper" 35 | code:[JSONObject[@"error_code"] integerValue] 36 | userInfo:@{NSLocalizedDescriptionKey: errorDescription}]; 37 | } 38 | self.JSONObject = JSONObject; 39 | self.eagerTypes = eagerTypes; 40 | } 41 | else if (self) { 42 | self.error = [NSError errorWithDomain:@"PPM.outputHelper" 43 | code:-1 44 | userInfo:@{NSLocalizedDescriptionKey: @"invalid response."}]; 45 | } 46 | return self; 47 | } 48 | 49 | - (void)requestDataObjectWithCompletionBlock:(PPMOutputHelperRequestDataObjectCompletionBlock)completionBlock { 50 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 51 | if (completionBlock) { 52 | completionBlock([self eagerTypesDataObject:self.JSONObject rootKey:nil][@"data"]); 53 | } 54 | }); 55 | } 56 | 57 | - (id)eagerTypesDataObject:(id)theObject rootKey:(NSString *)rootKey { 58 | if (self.eagerTypes == nil) { 59 | return theObject; 60 | } 61 | else { 62 | if ([theObject isKindOfClass:[NSDictionary class]]) { 63 | NSMutableDictionary *mutableObject = [theObject mutableCopy]; 64 | [(NSDictionary *)theObject enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { 65 | if (self.eagerTypes[key] != nil) { 66 | id eagerObject = [OCDValueFormatter objectAsClass:NSClassFromString(self.eagerTypes[key]) 67 | withObject:obj]; 68 | if (eagerObject != nil) { 69 | [mutableObject setObject:eagerObject forKey:key]; 70 | } 71 | else { 72 | [mutableObject removeObjectForKey:key]; 73 | } 74 | } 75 | if ([mutableObject[key] isKindOfClass:[NSDictionary class]] || 76 | [mutableObject[key] isKindOfClass:[NSArray class]]) { 77 | [mutableObject setObject:[self eagerTypesDataObject:mutableObject[key] rootKey:key] 78 | forKey:key]; 79 | } 80 | }]; 81 | return [mutableObject copy]; 82 | } 83 | else if ([theObject isKindOfClass:[NSArray class]]) { 84 | NSMutableArray *mutableObject = [theObject mutableCopy]; 85 | [(NSArray *)theObject enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 86 | NSString *arrayKey = [NSString stringWithFormat:@"%@[]", rootKey]; 87 | if (self.eagerTypes[arrayKey] != nil) { 88 | id eagerObject = [OCDValueFormatter 89 | objectAsClass:NSClassFromString(self.eagerTypes[arrayKey]) 90 | withObject:obj]; 91 | if (eagerObject != nil) { 92 | [mutableObject setObject:eagerObject atIndexedSubscript:idx]; 93 | } 94 | } 95 | if ([[mutableObject objectAtIndex:idx] isKindOfClass:[NSDictionary class]] || 96 | [[mutableObject objectAtIndex:idx] isKindOfClass:[NSArray class]]) { 97 | [mutableObject setObject:[self eagerTypesDataObject:[mutableObject objectAtIndex:idx] rootKey:arrayKey] 98 | atIndexedSubscript:idx]; 99 | } 100 | }]; 101 | return [mutableObject copy]; 102 | } 103 | else { 104 | return theObject; 105 | } 106 | } 107 | } 108 | 109 | @end 110 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Helper/OCDProtocolHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // PPMProtocolHelper.h 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15-3-29. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDProtocolHelper : NSObject 12 | 13 | @property (nonatomic, strong) NSError *error; 14 | 15 | @property (nonatomic, copy) NSString *service; 16 | 17 | @property (nonatomic, copy) NSString *method; 18 | 19 | @property (nonatomic, strong) id params; 20 | 21 | - (instancetype)initWithMessageString:(NSString *)messageString; 22 | 23 | + (NSString *)messageWithService:(NSString *)service method:(NSString *)method params:(id)params; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Helper/OCDProtocolHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // PPMProtocolHelper.m 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15-3-29. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import "OCDProtocolHelper.h" 10 | #import "OCDValueFormatter.h" 11 | 12 | @interface OCDProtocolHelper () 13 | 14 | @end 15 | 16 | @implementation OCDProtocolHelper 17 | 18 | - (instancetype)initWithMessageString:(NSString *)messageString 19 | { 20 | self = [super init]; 21 | if (self && [messageString isKindOfClass:[NSString class]]) { 22 | NSData *messageData = [messageString dataUsingEncoding:NSUTF8StringEncoding]; 23 | if (messageData != nil) { 24 | NSError *error; 25 | NSDictionary *messageObject = [NSJSONSerialization JSONObjectWithData:messageData options:kNilOptions error:&error]; 26 | if (error != nil) { 27 | self.error = error; 28 | } 29 | else { 30 | self.service = TOString(TODictionary(messageObject)[@"s"]); 31 | self.method = TOString(TODictionary(messageObject)[@"m"]); 32 | self.params = TODictionary(messageObject)[@"p"]; 33 | } 34 | } 35 | } 36 | else if (self) { 37 | self.error = [NSError errorWithDomain:@"PPM.ProtocolHelper" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"invalid message."}]; 38 | } 39 | return self; 40 | } 41 | 42 | + (NSString *)messageWithService:(NSString *)service method:(NSString *)method params:(id)params { 43 | NSDictionary *messageDictionary; 44 | if (params == nil) { 45 | messageDictionary = @{@"s": TOString(service), @"m": TOString(method)}; 46 | } 47 | else { 48 | messageDictionary = @{@"s": TOString(service), @"m": TOString(method), @"p": params}; 49 | } 50 | NSError *error; 51 | NSString *messageString = [[NSString alloc] 52 | initWithData:[NSJSONSerialization dataWithJSONObject:messageDictionary 53 | options:kNilOptions error:&error] 54 | encoding:NSUTF8StringEncoding]; 55 | if (error == nil) { 56 | return messageString; 57 | } 58 | else { 59 | return @""; 60 | } 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Helper/OCDValueFormatter.h: -------------------------------------------------------------------------------- 1 | // 2 | // AFUObjectFormater.h 3 | // AFUtils 4 | // 5 | // Created by 崔 明辉 on 14/12/22. 6 | // Copyright (c) 2014年 多玩事业部 iOS开发组 YY Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #ifndef OCDObjectFormatterMacros 12 | 13 | #define OCDObjectFormatterMacros 14 | 15 | #define TOString(object) (NSString *)[OCDValueFormatter objectAsClass:[NSString class] withObject:object] 16 | #define TONumber(object) (NSNumber *)[OCDValueFormatter objectAsClass:[NSNumber class] withObject:object] 17 | #define TOInteger(object) [[OCDValueFormatter objectAsClass:[NSNumber class] withObject:object] integerValue] 18 | #define TOFloat(object) [[OCDValueFormatter objectAsClass:[NSNumber class] withObject:object] floatValue] 19 | #define TODictionary(object) (NSDictionary *)[OCDValueFormatter objectAsClass:[NSDictionary class] withObject:object] 20 | #define TOArray(object) (NSArray *)[OCDValueFormatter objectAsClass:[NSArray class] withObject:object] 21 | #define ISValidArray(theObject, theIndex) (BOOL)[OCDValueFormatter isValidArray:theObject atIndex:theIndex] 22 | 23 | #endif 24 | 25 | @interface OCDValueFormatter : NSObject 26 | 27 | + (id)objectAsClass:(Class)argClass withObject:(id)argObject; 28 | 29 | + (BOOL)isValidArray:(id)argObject atIndex:(NSUInteger)argIndex; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Helper/OCDValueFormatter.m: -------------------------------------------------------------------------------- 1 | // 2 | // AFUObjectFormater.m 3 | // AFUtils 4 | // 5 | // Created by 崔 明辉 on 14/12/22. 6 | // Copyright (c) 2014年 多玩事业部 iOS开发组 YY Inc. All rights reserved. 7 | // 8 | 9 | #import "OCDValueFormatter.h" 10 | 11 | @implementation OCDValueFormatter 12 | 13 | + (id)objectAsClass:(Class)argClass withObject:(id)argObject { 14 | if ([argObject isKindOfClass:argClass]) { 15 | return argObject; 16 | } 17 | else { 18 | return [self formatAsClass:argClass withObject:argObject]; 19 | } 20 | } 21 | 22 | + (id)formatAsClass:(Class)argClass withObject:(id)argObject { 23 | if ([argObject isKindOfClass:[NSString class]] && argClass == [NSNumber class]) { 24 | NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; 25 | NSNumber *numberObject = [numberFormatter numberFromString:argObject]; 26 | return numberObject == NULL ? @0 : [numberFormatter numberFromString:argObject]; 27 | } 28 | else if ([argObject isKindOfClass:[NSNumber class]] && argClass == [NSString class]) { 29 | return [NSString stringWithFormat:@"%@", argObject]; 30 | } 31 | else if (argClass == [NSNumber class]) { 32 | return @0; 33 | } 34 | else if ([[argClass alloc] respondsToSelector:@selector(init)]) { 35 | return [[argClass alloc] init]; 36 | } 37 | else { 38 | return [NSNull null]; 39 | } 40 | } 41 | 42 | + (BOOL)isValidArray:(id)argObject atIndex:(NSUInteger)argIndex { 43 | if ([argObject isKindOfClass:[NSArray class]]) { 44 | if (argIndex < [argObject count]) { 45 | return YES; 46 | } 47 | else { 48 | return NO; 49 | } 50 | } 51 | else { 52 | return NO; 53 | } 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Manager/OCDSocketServiceManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // PPMSyncSocketServiceManager.h 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15/4/1. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDConnService.h" 11 | #import "OCDPubService.h" 12 | #import "OCDSubService.h" 13 | #import "OCDDeviceService.h" 14 | #import "OCDPointService.h" 15 | #import "OCDLogService.h" 16 | #import "OCDHTTPWatcherService.h" 17 | #import "OCDFinderService.h" 18 | 19 | @class OCDConnService, OCDSubService, OCDPubService; 20 | 21 | @interface OCDSocketServiceManager : NSObject 22 | 23 | @property (nonatomic, readonly) OCDConnService *conn; 24 | 25 | @property (nonatomic, readonly) OCDSubService *sub; 26 | 27 | @property (nonatomic, readonly) OCDPubService *pub; 28 | 29 | @property (nonatomic, readonly) OCDDeviceService *device; 30 | 31 | @property (nonatomic, readonly) OCDPointService *point; 32 | 33 | @property (nonatomic, readonly) OCDLogService *log; 34 | 35 | @property (nonatomic, readonly) OCDHTTPWatcherService *HTTPWatcher; 36 | 37 | @property (nonatomic, readonly) OCDFinderService *finder; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Manager/OCDSocketServiceManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // PPMSyncSocketServiceManager.m 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15/4/1. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import "OCDSocketServiceManager.h" 10 | 11 | @implementation OCDSocketServiceManager 12 | 13 | - (instancetype)init 14 | { 15 | self = [super init]; 16 | if (self) { 17 | _conn = [[OCDConnService alloc] init]; 18 | _sub = [[OCDSubService alloc] init]; 19 | _pub = [[OCDPubService alloc] init]; 20 | _device = [[OCDDeviceService alloc] init]; 21 | _point = [[OCDPointService alloc] init]; 22 | _log = [[OCDLogService alloc] init]; 23 | _HTTPWatcher = [[OCDHTTPWatcherService alloc] init]; 24 | _finder = [[OCDFinderService alloc] init]; 25 | } 26 | return self; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDConnService.h: -------------------------------------------------------------------------------- 1 | // 2 | // PPMSyncConnService.h 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15/4/1. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDConnService : NSObject 12 | 13 | - (void)connect; 14 | 15 | - (void)sendMessage:(id)message; 16 | 17 | - (void)disconnect; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDConnService.m: -------------------------------------------------------------------------------- 1 | // 2 | // PPMSyncConnService.m 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15/4/1. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import "OCDConnService.h" 10 | #import "OCDProtocolHelper.h" 11 | #import "OCDSubService.h" 12 | #import "OCDCore.h" 13 | #import "OCDDefine.h" 14 | #import "OCDValueFormatter.h" 15 | #import 16 | 17 | @interface OCDConnService () 18 | 19 | @property (nonatomic, strong) SRWebSocket *webSocketConnection; 20 | 21 | @property (nonatomic, copy) NSString *webSocketURLString; 22 | 23 | @property (nonatomic, assign) NSUInteger retryCount; 24 | 25 | @end 26 | 27 | @implementation OCDConnService 28 | 29 | - (void)dealloc 30 | { 31 | self.webSocketConnection.delegate = nil; 32 | } 33 | 34 | - (instancetype)init 35 | { 36 | self = [super init]; 37 | if (self) { 38 | } 39 | return self; 40 | } 41 | 42 | - (void)requestWebSocketURLStringWithCompletionBlock:(void (^)())completionBlock { 43 | NSString *URLString = [[OCDDefine sharedDefine] socketAddressRequestURLString]; 44 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]]; 45 | [NSURLConnection 46 | sendAsynchronousRequest:request 47 | queue:[NSOperationQueue mainQueue] 48 | completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 49 | if (connectionError == nil && [data isKindOfClass:[NSData class]]) { 50 | NSString *responseString = [[NSString alloc] initWithData:data 51 | encoding:NSUTF8StringEncoding]; 52 | if (responseString.length) { 53 | self.webSocketURLString = responseString; 54 | if (completionBlock) { 55 | completionBlock(); 56 | } 57 | } 58 | } 59 | else { 60 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 61 | [self requestWebSocketURLStringWithCompletionBlock:completionBlock]; 62 | }); 63 | } 64 | }]; 65 | } 66 | 67 | - (void)connect { 68 | if (self.webSocketURLString == nil || ![self.webSocketURLString hasPrefix:@"ws://"]) { 69 | [self requestWebSocketURLStringWithCompletionBlock:^{ 70 | [self connect]; 71 | }]; 72 | return; 73 | } 74 | else { 75 | self.webSocketConnection = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:self.webSocketURLString]]; 76 | self.webSocketConnection.delegate = self; 77 | [self.webSocketConnection open]; 78 | } 79 | } 80 | 81 | - (void)sendMessage:(id)message { 82 | if ([message isKindOfClass:[NSString class]] && 83 | [message lengthOfBytesUsingEncoding:NSUTF8StringEncoding] > 1024 * 8) { 84 | //Bigger than 4KB data use HTTP alone channel. 85 | NSString *storageIdentifier = [[OCDDefine sharedDefine] uniqueIdentifier]; 86 | NSMutableURLRequest *storageRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[[OCDDefine sharedDefine] storageAddAddressWithIdentifier:storageIdentifier]]]; 87 | [storageRequest setHTTPMethod:@"POST"]; 88 | [storageRequest setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]]; 89 | [storageRequest setValue: @"application/raw" forHTTPHeaderField:@"Content-Type"]; 90 | [NSURLProtocol setProperty:@"1" forKey:kOCDMessageStorageRequestKey inRequest:storageRequest]; 91 | [NSURLConnection sendAsynchronousRequest:storageRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 92 | if (connectionError == nil) { 93 | NSDictionary *storageDictionary = @{ 94 | @"_storageIdentifier": storageIdentifier 95 | }; 96 | NSString *storageMessage = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:storageDictionary options:kNilOptions error:NULL] encoding:NSUTF8StringEncoding]; 97 | [self.webSocketConnection send:storageMessage]; 98 | } 99 | }]; 100 | } 101 | else { 102 | [self.webSocketConnection send:message]; 103 | } 104 | } 105 | 106 | - (void)disconnect { 107 | [self.webSocketConnection close]; 108 | } 109 | 110 | #pragma mark - SRWebSocketDelegate 111 | 112 | - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error { 113 | [[[[OCDCore sharedCore] socketService] sub] setIsObserverAdded:NO]; 114 | if (self.retryCount < 10) { 115 | NSLog(@"Will reconnect after 5s."); 116 | self.retryCount++; 117 | [self performSelector:@selector(connect) withObject:nil afterDelay:5.0]; 118 | } 119 | } 120 | 121 | - (void)webSocketDidOpen:(SRWebSocket *)webSocket { 122 | self.retryCount = 0; 123 | [[[[OCDCore sharedCore] socketService] sub] addObserver]; 124 | } 125 | 126 | #pragma GCC diagnostic push 127 | #pragma GCC diagnostic ignored "-Warc-performSelector-leaks" 128 | - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { 129 | OCDProtocolHelper *protoHelper = [[OCDProtocolHelper alloc] initWithMessageString:message]; 130 | if (protoHelper.error == nil) { 131 | if ([[[OCDCore sharedCore] socketService] respondsToSelector:NSSelectorFromString(protoHelper.service)]) { 132 | NSObject *serviceObject = [[[OCDCore sharedCore] socketService] performSelector:NSSelectorFromString(protoHelper.service) 133 | withObject:nil]; 134 | if ([serviceObject respondsToSelector:NSSelectorFromString(protoHelper.method)]) { 135 | [serviceObject performSelector:NSSelectorFromString(protoHelper.method) withObject:nil]; 136 | } 137 | else if ([serviceObject respondsToSelector:NSSelectorFromString([protoHelper.method stringByAppendingString:@":"])]) { 138 | [serviceObject performSelector:NSSelectorFromString([protoHelper.method stringByAppendingString:@":"]) 139 | withObject:protoHelper.params]; 140 | } 141 | } 142 | } 143 | } 144 | #pragma GCC diagnostic pop 145 | 146 | - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { 147 | [[[[OCDCore sharedCore] socketService] sub] setIsObserverAdded:NO]; 148 | [self requestWebSocketURLStringWithCompletionBlock:^{ 149 | [self connect]; 150 | }]; 151 | } 152 | 153 | @end 154 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDDeviceService.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDeviceService.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/9. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDeviceService : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDDeviceService.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDeviceService.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/9. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDDeviceService.h" 11 | #import "OCDValueFormatter.h" 12 | #import "OCDCore.h" 13 | 14 | @interface OCDDeviceService () 15 | 16 | @property (nonatomic, strong) NSTimer *updateTimer; 17 | 18 | @end 19 | 20 | @implementation OCDDeviceService 21 | 22 | - (instancetype)init 23 | { 24 | self = [super init]; 25 | if (self) { 26 | dispatch_async(dispatch_get_main_queue(), ^{ 27 | self.updateTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(handleUpdateTimerTrigger) userInfo:nil repeats:YES]; 28 | }); 29 | } 30 | return self; 31 | } 32 | 33 | - (void)handleUpdateTimerTrigger { 34 | [[[[OCDCore sharedCore] socketService] pub] 35 | pubMessageToService:@"device" 36 | method:@"updateDevice" 37 | params:@{ 38 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 39 | @"deviceName": TOString([[UIDevice currentDevice] name]), 40 | @"deviceSystemVersion": TOString([[UIDevice currentDevice] systemVersion]), 41 | @"deviceModel": TOString([[UIDevice currentDevice] model]) 42 | }]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDFinderService.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDFinderService.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDFinderService : NSObject 12 | 13 | - (void)commitShell:(NSDictionary *)params; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDFinderService.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDFinderService.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDFinderService.h" 10 | #import "OCDCore.h" 11 | #import "OCDValueFormatter.h" 12 | #import 13 | 14 | @implementation OCDFinderService 15 | 16 | - (void)commitShell:(NSDictionary *)params { 17 | if ([TOString(params[@"deviceIdentifier"]) isEqualToString:[[[UIDevice currentDevice] identifierForVendor] UUIDString]]) { 18 | NSString *result = [[[[OCDCore sharedCore] finder] manager] executeShell:TOString(params[@"shell"])]; 19 | [[[[OCDCore sharedCore] socketService] pub] 20 | pubMessageToService:@"finder" 21 | method:@"updateResult" 22 | params:@{ 23 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 24 | @"result": TOString(result) 25 | }]; 26 | } 27 | } 28 | 29 | - (void)requireSubPaths:(NSDictionary *)params { 30 | if ([TOString(params[@"deviceIdentifier"]) isEqualToString:[[[UIDevice currentDevice] identifierForVendor] UUIDString]]) { 31 | [[[[OCDCore sharedCore] socketService] pub] 32 | pubMessageToService:@"finder" 33 | method:@"updateSubPaths" 34 | params:@{ 35 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 36 | @"subPaths": TOArray([[[[OCDCore sharedCore] finder] manager] currentSubPaths]) 37 | }]; 38 | } 39 | } 40 | 41 | - (void)saveViContent:(NSDictionary *)params { 42 | if ([TOString(params[@"deviceIdentifier"]) isEqualToString:[[[UIDevice currentDevice] identifierForVendor] UUIDString]]) { 43 | NSString *filePath = TOString(params[@"filePath"]); 44 | NSString *fileContent = TOString(params[@"fileContent"]); 45 | [fileContent writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:NULL]; 46 | } 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDHTTPWatcherService.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherService.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherService : NSObject 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDHTTPWatcherService.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherService.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherService.h" 10 | #import "OCDValueFormatter.h" 11 | #import "OCDCore.h" 12 | #import 13 | 14 | @implementation OCDHTTPWatcherService 15 | 16 | - (void)resendConnection:(NSDictionary *)params { 17 | if ([TOString(params[@"deviceIdentifier"]) isEqualToString:[[[UIDevice currentDevice] identifierForVendor] UUIDString]]) { 18 | NSMutableURLRequest *resendRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:TOString(params[@"requestURLString"])]]; 19 | [resendRequest setHTTPMethod:TOString(params[@"requestMethod"])]; 20 | [resendRequest setHTTPBody:[TOString(params[@"requestBody"]) dataUsingEncoding:NSUTF8StringEncoding]]; 21 | NSDictionary *headerParams = TODictionary([NSJSONSerialization JSONObjectWithData:[TOString(params[@"requestHeader"]) dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:NULL]); 22 | [resendRequest setAllHTTPHeaderFields:headerParams]; 23 | [resendRequest setValue:@"1" forHTTPHeaderField:@"_OCD.ResendConnection"]; 24 | [NSURLConnection sendAsynchronousRequest:resendRequest queue:[NSOperationQueue mainQueue] completionHandler:nil]; 25 | } 26 | } 27 | 28 | - (void)updateModifiers { 29 | [[[[OCDCore sharedCore] HTTPWatcher] modifierManager] fetchModifiers]; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDLogService.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogService.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDLogEntity; 12 | 13 | @interface OCDLogService : NSObject 14 | 15 | - (void)sendLogItem:(OCDLogEntity *)item; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDLogService.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogService.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDLogService.h" 10 | #import "OCDCore.h" 11 | 12 | @implementation OCDLogService 13 | 14 | - (void)sendLogItem:(OCDLogEntity *)item { 15 | [[[[OCDCore sharedCore] socketService] pub] pubMessageToService:@"log" 16 | method:@"updateLog" 17 | params:[item toDictionary]]; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDPointService.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointService.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDPointService : NSObject 12 | 13 | - (void)requestPoints; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDPointService.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointService.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDPointService.h" 11 | #import "OCDCore.h" 12 | #import "OCDValueFormatter.h" 13 | 14 | @implementation OCDPointService 15 | 16 | - (void)requestPoints { 17 | NSMutableArray *dataItems = [NSMutableArray array]; 18 | NSArray *items = [[[[OCDCore sharedCore] point] manager] allItems]; 19 | [items enumerateObjectsUsingBlock:^(OCDPointEntity *obj, NSUInteger idx, BOOL *stop) { 20 | [dataItems addObject:TODictionary([obj toDictionary])]; 21 | }]; 22 | [[[[OCDCore sharedCore] socketService] pub] 23 | pubMessageToService:@"point" 24 | method:@"updatePoints" 25 | params:@{ 26 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 27 | @"points": dataItems 28 | }]; 29 | } 30 | 31 | - (void)validPoint:(NSDictionary *)params { 32 | NSString *pointIdentifier = TOString(params[@"id"]); 33 | [[[[[OCDCore sharedCore] point] manager] pointWithIdentifier:pointIdentifier] setIsValid:YES]; 34 | } 35 | 36 | - (void)invalidPoint:(NSDictionary *)params { 37 | NSString *pointIdentifier = TOString(params[@"id"]); 38 | [[[[[OCDCore sharedCore] point] manager] pointWithIdentifier:pointIdentifier] setIsValid:NO]; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDPubService.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPubService.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/9. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDPubService : NSObject 12 | 13 | - (void)pubMessageToService:(NSString *)service method:(NSString *)method params:(NSDictionary *)params; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDPubService.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPubService.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/9. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDPubService.h" 10 | #import "OCDProtocolHelper.h" 11 | #import "OCDValueFormatter.h" 12 | #import "OCDCore.h" 13 | 14 | @interface OCDPubService () 15 | 16 | @property (nonatomic, copy) NSArray *disconnectStoreObjects; 17 | 18 | @property (nonatomic, strong) NSTimer *retryTimer; 19 | 20 | @end 21 | 22 | @implementation OCDPubService 23 | 24 | - (instancetype)init 25 | { 26 | self = [super init]; 27 | if (self) { 28 | dispatch_async(dispatch_get_main_queue(), ^{ 29 | self.retryTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 30 | target:self 31 | selector:@selector(handleRetryTimerTrigger) 32 | userInfo:nil 33 | repeats:YES]; 34 | }); 35 | } 36 | return self; 37 | } 38 | 39 | - (void)pubMessageToService:(NSString *)service method:(NSString *)method params:(NSDictionary *)params { 40 | NSString *message = [OCDProtocolHelper messageWithService:@"pub" 41 | method:@"submit" 42 | params:@{ 43 | @"service": TOString(service), 44 | @"method": TOString(method), 45 | @"params": TODictionary(params) 46 | }]; 47 | if ([[[[OCDCore sharedCore] socketService] sub] isObserverAdded]) { 48 | [self pubStoreMessages]; 49 | [[[[OCDCore sharedCore] socketService] conn] sendMessage:message]; 50 | } 51 | else { 52 | [self addMessageToStore:message]; 53 | } 54 | } 55 | 56 | - (void)handleRetryTimerTrigger { 57 | if ([[[[OCDCore sharedCore] socketService] sub] isObserverAdded] && 58 | [self.disconnectStoreObjects count] > 0) { 59 | [self pubStoreMessages]; 60 | } 61 | } 62 | 63 | - (void)pubStoreMessages { 64 | [self.disconnectStoreObjects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 65 | [[[[OCDCore sharedCore] socketService] conn] sendMessage:obj]; 66 | }]; 67 | self.disconnectStoreObjects = @[]; 68 | } 69 | 70 | - (void)addMessageToStore:(NSString *)message { 71 | if (message != nil) { 72 | NSMutableArray *stores = [[self disconnectStoreObjects] mutableCopy]; 73 | [stores addObject:message]; 74 | self.disconnectStoreObjects = stores; 75 | } 76 | } 77 | 78 | #pragma mark - Getter 79 | 80 | - (NSArray *)disconnectStoreObjects { 81 | if (_disconnectStoreObjects == nil) { 82 | _disconnectStoreObjects = @[]; 83 | } 84 | return _disconnectStoreObjects; 85 | } 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDSubService.h: -------------------------------------------------------------------------------- 1 | // 2 | // PPMSyncSubService.h 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15/4/1. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDSubService : NSObject 12 | 13 | @property (nonatomic, assign) BOOL isObserverAdded; 14 | 15 | - (void)addObserver; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Common/Socket/Service/OCDSubService.m: -------------------------------------------------------------------------------- 1 | // 2 | // PPMSyncSubService.m 3 | // PonyMessenger 4 | // 5 | // Created by 崔 明辉 on 15/4/1. 6 | // Copyright (c) 2015年 崔 明辉. All rights reserved. 7 | // 8 | 9 | #import "OCDSubService.h" 10 | #import "OCDConnService.h" 11 | #import "OCDProtocolHelper.h" 12 | #import "OCDValueFormatter.h" 13 | #import "OCDCore.h" 14 | #import "OCDDefine.h" 15 | 16 | @interface OCDSubService () 17 | 18 | @property (nonatomic, strong) NSTimer *heartBeatTimer; 19 | 20 | @property (nonatomic, strong) NSTimer *heartBeatTimeoutTimer; 21 | 22 | @end 23 | 24 | @implementation OCDSubService 25 | 26 | - (void)addObserver { 27 | NSString *userID = TOString([[OCDDefine sharedDefine] appID]); 28 | NSString *sessionToken = TOString([[OCDDefine sharedDefine] appToken]); 29 | NSString *message = [OCDProtocolHelper messageWithService:@"sub" 30 | method:@"addObserver" 31 | params:@{@"user_id":userID, 32 | @"session_token":sessionToken}]; 33 | [[[[OCDCore sharedCore] socketService] conn] sendMessage:message]; 34 | } 35 | 36 | - (void)heartBeat { 37 | NSString *message = [OCDProtocolHelper messageWithService:@"sub" method:@"heartBeat" params:nil]; 38 | [[[[OCDCore sharedCore] socketService] conn] sendMessage:message]; 39 | self.heartBeatTimeoutTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 40 | target:self 41 | selector:@selector(heartBeatTimeoutTimer) 42 | userInfo:nil 43 | repeats:NO]; 44 | } 45 | 46 | - (void)heartBeatTimeout { 47 | self.isObserverAdded = NO; 48 | NSLog(@"[Error] fail to receive heart beat."); 49 | [[[[OCDCore sharedCore] socketService] conn] disconnect]; 50 | } 51 | 52 | - (void)didAddObserver { 53 | self.isObserverAdded = YES; 54 | NSLog(@"didAddObserver"); 55 | [self.heartBeatTimer invalidate]; 56 | self.heartBeatTimer = [NSTimer scheduledTimerWithTimeInterval:60.0 57 | target:self 58 | selector:@selector(heartBeat) 59 | userInfo:nil 60 | repeats:YES]; 61 | } 62 | 63 | - (void)didReceivedError:(NSDictionary *)params { 64 | self.isObserverAdded = NO; 65 | NSLog(@"[Error] code:%@, desc:%@", TODictionary(params)[@"error_code"], TODictionary(params)[@"error_description"]); 66 | } 67 | 68 | - (void)didReceivedHeartBeat { 69 | NSLog(@"didReceivedHeartBeat"); 70 | [self.heartBeatTimeoutTimer invalidate]; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/Application Logic/Hooker/OCDDashboardShakeHooker.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardSharkHooker.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDashboardShakeHooker : NSObject 12 | 13 | - (void)install; 14 | 15 | - (void)uninstall; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/Application Logic/Hooker/OCDDashboardShakeHooker.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardSharkHooker.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardShakeHooker.h" 10 | #import "OCDCore.h" 11 | #import 12 | #import 13 | 14 | @interface OCDDashboardShakeHooker () 15 | 16 | @property (nonatomic, strong) id viewDidAppearToken; 17 | @property (nonatomic, strong) id motionEndToken; 18 | 19 | @end 20 | 21 | @implementation OCDDashboardShakeHooker 22 | 23 | - (void)install { 24 | self.viewDidAppearToken = [UIViewController aspect_hookSelector:@selector(viewDidAppear:) 25 | withOptions:AspectPositionAfter 26 | usingBlock:^(id info){ 27 | UIViewController *viewController = [info instance]; 28 | [[UIApplication sharedApplication] setApplicationSupportsShakeToEdit:YES]; 29 | [viewController becomeFirstResponder]; 30 | } 31 | error:NULL]; 32 | self.motionEndToken = [UIResponder aspect_hookSelector:@selector(motionEnded:withEvent:) 33 | withOptions:AspectPositionAfter 34 | usingBlock:^(){ 35 | [[[[OCDCore sharedCore] dashboard] wireframe] showAlertView]; 36 | } 37 | error:NULL]; 38 | } 39 | 40 | - (void)uninstall { 41 | [self.viewDidAppearToken remove]; 42 | [self.motionEndToken remove]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/Application Logic/Manager/OCDDashboardHookManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardHookManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDashboardHookManager : NSObject 12 | 13 | - (void)registerHooks; 14 | 15 | - (void)unregister; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/Application Logic/Manager/OCDDashboardHookManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardHookManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardHookManager.h" 10 | #import "OCDDashboardShakeHooker.h" 11 | 12 | @interface OCDDashboardHookManager () 13 | 14 | @property (nonatomic, strong) OCDDashboardShakeHooker *shakeHooker; 15 | 16 | @end 17 | 18 | @implementation OCDDashboardHookManager 19 | 20 | - (void)registerHooks { 21 | [self.shakeHooker install]; 22 | } 23 | 24 | - (void)unregister { 25 | [self.shakeHooker uninstall]; 26 | } 27 | 28 | #pragma mark - Getter 29 | 30 | - (OCDDashboardShakeHooker *)shakeHooker { 31 | if (_shakeHooker == nil) { 32 | _shakeHooker = [[OCDDashboardShakeHooker alloc] init]; 33 | } 34 | return _shakeHooker; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/Module Interface/OCDDashboardCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardCore.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDDashboardHookManager.h" 11 | #import "OCDDashboardWireframe.h" 12 | 13 | @interface OCDDashboardCore : NSObject 14 | 15 | @property (nonatomic, strong) OCDDashboardHookManager *hookManager; 16 | 17 | @property (nonatomic, strong) OCDDashboardWireframe *wireframe; 18 | 19 | - (void)install; 20 | 21 | - (void)uninstall; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/Module Interface/OCDDashboardCore.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardCore.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardCore.h" 10 | 11 | @implementation OCDDashboardCore 12 | 13 | - (void)install { 14 | [self.hookManager registerHooks]; 15 | } 16 | 17 | - (void)uninstall { 18 | [self.hookManager unregister]; 19 | } 20 | 21 | #pragma mark - Getter 22 | 23 | - (OCDDashboardHookManager *)hookManager { 24 | if (_hookManager == nil) { 25 | _hookManager = [[OCDDashboardHookManager alloc] init]; 26 | } 27 | return _hookManager; 28 | } 29 | 30 | - (OCDDashboardWireframe *)wireframe { 31 | if (_wireframe == nil) { 32 | _wireframe = [[OCDDashboardWireframe alloc] init]; 33 | } 34 | return _wireframe; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Interactor/OCDDashboardPointInteractor.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointInteractor.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDDashboardPointItemInteractor.h" 11 | 12 | @protocol OCDDashboardPointInteractorDelegate 13 | 14 | - (void)foundItems; 15 | 16 | @end 17 | 18 | @interface OCDDashboardPointInteractor : NSObject 19 | 20 | @property (nonatomic, weak) id delegate; 21 | 22 | @property (nonatomic, copy) NSArray *items; 23 | 24 | - (void)findItems; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Interactor/OCDDashboardPointInteractor.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointInteractor.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardPointInteractor.h" 10 | #import "OCDCore.h" 11 | 12 | @implementation OCDDashboardPointInteractor 13 | 14 | - (void)findItems { 15 | NSArray *items = [[[[OCDCore sharedCore] point] manager] allItems]; 16 | NSMutableArray *itemInteractors = [NSMutableArray array]; 17 | [items enumerateObjectsUsingBlock:^(OCDPointEntity *obj, NSUInteger idx, BOOL *stop) { 18 | OCDDashboardPointItemInteractor *itemInteractor = [[OCDDashboardPointItemInteractor alloc] 19 | initWithItem:obj]; 20 | [itemInteractors addObject:itemInteractor]; 21 | }]; 22 | self.items = itemInteractors; 23 | [self.delegate foundItems]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Interactor/OCDDashboardPointItemInteractor.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointItemInteractor.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDPointEntity; 12 | 13 | @interface OCDDashboardPointItemInteractor : NSObject 14 | 15 | @property (nonatomic, copy) NSString *title; 16 | 17 | @property (nonatomic, copy) NSString *subTitle; 18 | 19 | @property (nonatomic, assign) BOOL isOn; 20 | 21 | - (instancetype)initWithItem:(OCDPointEntity *)item; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Interactor/OCDDashboardPointItemInteractor.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointItemInteractor.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardPointItemInteractor.h" 10 | #import "OCDPointEntity.h" 11 | #import "OCDCore.h" 12 | 13 | @interface OCDDashboardPointItemInteractor () 14 | 15 | @property (nonatomic, strong) OCDPointEntity *item; 16 | 17 | @end 18 | 19 | @implementation OCDDashboardPointItemInteractor 20 | 21 | - (instancetype)initWithItem:(OCDPointEntity *)item 22 | { 23 | self = [super init]; 24 | if (self) { 25 | _item = item; 26 | _title = item.pointIdentifier; 27 | if (item.pointObject != nil) { 28 | _subTitle = [NSString stringWithFormat:@"Object:%@", [item.pointObject description]]; 29 | } 30 | else { 31 | _subTitle = [NSString stringWithFormat:@"Value:%ld", (long)item.pointValue]; 32 | } 33 | _isOn = item.isValid; 34 | } 35 | return self; 36 | } 37 | 38 | - (void)setIsOn:(BOOL)isOn { 39 | _isOn = isOn; 40 | [[[[[OCDCore sharedCore] point] manager] pointWithIdentifier:self.item.pointIdentifier] setIsValid:_isOn]; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Presenter/OCDDashboardPointPresenter.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointPresenter.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDDashboardPointViewController, OCDDashboardPointInteractor; 12 | 13 | @interface OCDDashboardPointPresenter : NSObject 14 | 15 | @property (nonatomic, weak) OCDDashboardPointViewController *userInterface; 16 | 17 | @property (nonatomic, strong) OCDDashboardPointInteractor *pointInteractor; 18 | 19 | - (void)updateView; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Presenter/OCDDashboardPointPresenter.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointPresenter.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardPointPresenter.h" 10 | #import "OCDDashboardPointViewController.h" 11 | #import "OCDDashboardPointInteractor.h" 12 | 13 | @interface OCDDashboardPointPresenter () 14 | 15 | @end 16 | 17 | @implementation OCDDashboardPointPresenter 18 | 19 | - (instancetype)init 20 | { 21 | self = [super init]; 22 | if (self) { 23 | self.pointInteractor = [[OCDDashboardPointInteractor alloc] init]; 24 | self.pointInteractor.delegate = self; 25 | } 26 | return self; 27 | } 28 | 29 | - (void)updateView { 30 | [self.pointInteractor findItems]; 31 | } 32 | 33 | #pragma mark - OCDDashboardPointInteractorDelegate 34 | 35 | - (void)foundItems { 36 | dispatch_async(dispatch_get_main_queue(), ^{ 37 | [self.userInterface reloadData]; 38 | }); 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardInformationViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardInformationViewController.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDashboardInformationViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardInformationViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardInformationViewController.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardInformationViewController.h" 10 | 11 | @interface OCDDashboardInformationViewController () 12 | 13 | @property (nonatomic, strong) UIBarButtonItem *closeButtonItem; 14 | 15 | @end 16 | 17 | @implementation OCDDashboardInformationViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | self.title = @"Information"; 22 | self.navigationItem.rightBarButtonItem = self.closeButtonItem; 23 | } 24 | 25 | - (void)didReceiveMemoryWarning { 26 | [super didReceiveMemoryWarning]; 27 | } 28 | 29 | #pragma mark - Table view data source 30 | 31 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 32 | return 1; 33 | } 34 | 35 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 36 | return 4; 37 | } 38 | 39 | 40 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 41 | static NSString *reuseIdentifier = @"Cell"; 42 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; 43 | if (cell == nil) { 44 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 45 | reuseIdentifier:reuseIdentifier]; 46 | } 47 | [self configureCell:cell atIndex:indexPath.row]; 48 | return cell; 49 | } 50 | 51 | - (void)configureCell:(UITableViewCell *)cell atIndex:(NSInteger)index { 52 | if (index == 0) { 53 | cell.textLabel.text = @"IDFV"; 54 | NSString *UUIDString = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; 55 | cell.detailTextLabel.text = [UUIDString substringFromIndex:[UUIDString length] - 6]; 56 | } 57 | else if (index == 1) { 58 | cell.textLabel.text = @"Device Name"; 59 | cell.detailTextLabel.text = [[UIDevice currentDevice] name]; 60 | } 61 | else if (index == 2) { 62 | cell.textLabel.text = @"Device System Version"; 63 | cell.detailTextLabel.text = [[UIDevice currentDevice] systemVersion]; 64 | } 65 | else if (index == 3) { 66 | cell.textLabel.text = @"Device Model"; 67 | cell.detailTextLabel.text = [[UIDevice currentDevice] model]; 68 | } 69 | } 70 | 71 | #pragma mark - Events 72 | 73 | - (void)handleCloseButtonTapped { 74 | [self.navigationController dismissViewControllerAnimated:YES completion:nil]; 75 | } 76 | 77 | #pragma mark - Getter 78 | 79 | - (UIBarButtonItem *)closeButtonItem { 80 | if (_closeButtonItem == nil) { 81 | _closeButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" 82 | style:UIBarButtonItemStyleDone 83 | target:self 84 | action:@selector(handleCloseButtonTapped)]; 85 | } 86 | return _closeButtonItem; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardLogViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardLogViewController.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDashboardLogViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardLogViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardLogViewController.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardLogViewController.h" 10 | #import "OCDCore.h" 11 | 12 | @interface OCDDashboardLogViewController () 13 | 14 | @property (nonatomic, strong) UIBarButtonItem *closeButtonItem; 15 | @property (nonatomic, strong) UITextView *textView; 16 | 17 | @property (nonatomic, strong) NSTimer *refreshTimer; 18 | 19 | @end 20 | 21 | @implementation OCDDashboardLogViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | self.title = @"Log"; 26 | self.navigationItem.rightBarButtonItem = self.closeButtonItem; 27 | [self.view addSubview:self.textView]; 28 | self.textView.text = [[[[OCDCore sharedCore] log] manager] consoleText]; 29 | // Do any additional setup after loading the view. 30 | } 31 | 32 | - (void)viewDidAppear:(BOOL)animated { 33 | [super viewDidAppear:animated]; 34 | self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(handleRefreshTimerTrigger) userInfo:nil repeats:YES]; 35 | } 36 | 37 | - (void)viewDidDisappear:(BOOL)animated { 38 | [super viewDidDisappear:animated]; 39 | [self.refreshTimer invalidate]; 40 | } 41 | 42 | - (void)didReceiveMemoryWarning { 43 | [super didReceiveMemoryWarning]; 44 | // Dispose of any resources that can be recreated. 45 | } 46 | 47 | - (void)viewWillLayoutSubviews { 48 | self.textView.frame = self.view.bounds; 49 | } 50 | 51 | #pragma mark - Events 52 | 53 | - (void)handleCloseButtonTapped { 54 | [self.navigationController dismissViewControllerAnimated:YES completion:nil]; 55 | } 56 | 57 | - (void)handleRefreshTimerTrigger { 58 | self.textView.text = [[[[OCDCore sharedCore] log] manager] consoleText]; 59 | } 60 | 61 | #pragma mark - Getter 62 | 63 | - (UITextView *)textView { 64 | if (_textView == nil) { 65 | _textView = [[UITextView alloc] initWithFrame:self.view.bounds]; 66 | _textView.editable = NO; 67 | } 68 | return _textView; 69 | } 70 | 71 | - (UIBarButtonItem *)closeButtonItem { 72 | if (_closeButtonItem == nil) { 73 | _closeButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" 74 | style:UIBarButtonItemStyleDone 75 | target:self 76 | action:@selector(handleCloseButtonTapped)]; 77 | } 78 | return _closeButtonItem; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardPointTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointTableViewCell.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDDashboardPointItemInteractor; 12 | 13 | @protocol OCDDashboardPointTableViewCellDelegate 14 | 15 | - (void)switchPointValid:(UITableViewCell *)cell isValid:(BOOL)isValid; 16 | 17 | @end 18 | 19 | @interface OCDDashboardPointTableViewCell : UITableViewCell 20 | 21 | @property (nonatomic, weak) id delegate; 22 | 23 | - (void)updateWithItemInteractor:(OCDDashboardPointItemInteractor *)itemInteractor; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardPointTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointTableViewCell.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardPointTableViewCell.h" 10 | #import "OCDDashboardPointItemInteractor.h" 11 | 12 | @interface OCDDashboardPointTableViewCell () 13 | 14 | @property (nonatomic, strong) UISwitch *switcher; 15 | 16 | @end 17 | 18 | @implementation OCDDashboardPointTableViewCell 19 | 20 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 21 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 22 | if (self) { 23 | [self.contentView addSubview:self.switcher]; 24 | } 25 | return self; 26 | } 27 | 28 | - (void)awakeFromNib { 29 | // Initialization code 30 | } 31 | 32 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 33 | [super setSelected:selected animated:animated]; 34 | 35 | // Configure the view for the selected state 36 | } 37 | 38 | - (void)updateWithItemInteractor:(OCDDashboardPointItemInteractor *)itemInteractor { 39 | self.textLabel.text = itemInteractor.title; 40 | self.detailTextLabel.text = itemInteractor.subTitle; 41 | [self.switcher setOn:itemInteractor.isOn]; 42 | } 43 | 44 | - (void)handleSwitcherValueChanged { 45 | [self.delegate switchPointValid:self isValid:self.switcher.isOn]; 46 | } 47 | 48 | #pragma mark - Getter 49 | 50 | - (UISwitch *)switcher { 51 | if (_switcher == nil) { 52 | _switcher = [[UISwitch alloc] init]; 53 | _switcher.center = CGPointMake(self.frame.size.width - _switcher.frame.size.width / 2.0 - 8.0, 54 | self.frame.size.height / 2.0); 55 | [_switcher addTarget:self action:@selector(handleSwitcherValueChanged) forControlEvents:UIControlEventValueChanged]; 56 | _switcher.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; 57 | } 58 | return _switcher; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardPointViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointViewController.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDashboardPointViewController : UITableViewController 12 | 13 | - (void)reloadData; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/View/OCDDashboardPointViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardPointViewController.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardPointViewController.h" 10 | #import "OCDDashboardPointPresenter.h" 11 | #import "OCDDashboardPointInteractor.h" 12 | #import "OCDDashboardPointTableViewCell.h" 13 | 14 | @interface OCDDashboardPointViewController () 15 | 16 | @property (nonatomic, strong) OCDDashboardPointPresenter *eventHandler; 17 | 18 | @property (nonatomic, strong) UIBarButtonItem *closeButtonItem; 19 | 20 | @end 21 | 22 | @implementation OCDDashboardPointViewController 23 | 24 | - (instancetype)init 25 | { 26 | self = [super init]; 27 | if (self) { 28 | self.title = @"Debug Point"; 29 | self.eventHandler = [[OCDDashboardPointPresenter alloc] init]; 30 | self.eventHandler.userInterface = self; 31 | } 32 | return self; 33 | } 34 | 35 | - (void)viewDidLoad { 36 | [super viewDidLoad]; 37 | 38 | self.navigationItem.rightBarButtonItem = self.closeButtonItem; 39 | 40 | [self.eventHandler updateView]; 41 | 42 | // Uncomment the following line to preserve selection between presentations. 43 | // self.clearsSelectionOnViewWillAppear = NO; 44 | 45 | // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 46 | // self.navigationItem.rightBarButtonItem = self.editButtonItem; 47 | } 48 | 49 | - (void)didReceiveMemoryWarning { 50 | [super didReceiveMemoryWarning]; 51 | // Dispose of any resources that can be recreated. 52 | } 53 | 54 | #pragma mark - Events 55 | 56 | - (void)handleCloseButtonTapped { 57 | [self.navigationController dismissViewControllerAnimated:YES completion:nil]; 58 | } 59 | 60 | - (void)reloadData { 61 | [self.tableView reloadData]; 62 | } 63 | 64 | #pragma mark - Table view data source 65 | 66 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 67 | return 1; 68 | } 69 | 70 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 71 | return [self.eventHandler.pointInteractor.items count]; 72 | } 73 | 74 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 75 | static NSString *reuseIdentifier = @"Cell"; 76 | 77 | OCDDashboardPointTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; 78 | 79 | if (cell == nil) { 80 | cell = [[OCDDashboardPointTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; 81 | cell.delegate = self; 82 | } 83 | 84 | if (indexPath.row < [self.eventHandler.pointInteractor.items count]) { 85 | cell.tag = indexPath.row; 86 | OCDDashboardPointItemInteractor *itemInteractor = self.eventHandler.pointInteractor.items[indexPath.row]; 87 | [cell updateWithItemInteractor:itemInteractor]; 88 | } 89 | 90 | return cell; 91 | } 92 | 93 | #pragma mark - OCDDashboardPointTableViewCellDelegate 94 | 95 | - (void)switchPointValid:(UITableViewCell *)cell isValid:(BOOL)isValid { 96 | if (cell.tag < [self.eventHandler.pointInteractor.items count]) { 97 | OCDDashboardPointItemInteractor *itemInteractor = self.eventHandler.pointInteractor.items[cell.tag]; 98 | [itemInteractor setIsOn:isValid]; 99 | } 100 | } 101 | 102 | #pragma mark - Getter 103 | 104 | - (UIBarButtonItem *)closeButtonItem { 105 | if (_closeButtonItem == nil) { 106 | _closeButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" 107 | style:UIBarButtonItemStyleDone 108 | target:self 109 | action:@selector(handleCloseButtonTapped)]; 110 | } 111 | return _closeButtonItem; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Wireframe/OCDDashboardWireframe.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardWireframe.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDDashboardWireframe : NSObject 12 | 13 | - (void)showAlertView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Dashboard/User Interface/Wireframe/OCDDashboardWireframe.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDDashboardWireframe.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDDashboardWireframe.h" 10 | #import "OCDDashboardInformationViewController.h" 11 | #import "OCDDashboardPointViewController.h" 12 | #import "OCDDashboardLogViewController.h" 13 | #import 14 | 15 | @interface OCDDashboardWireframe () 16 | 17 | @property (nonatomic, strong) UIAlertView *alertView; 18 | 19 | @end 20 | 21 | @implementation OCDDashboardWireframe 22 | 23 | - (void)dealloc 24 | { 25 | self.alertView.delegate = nil; 26 | } 27 | 28 | - (void)showAlertView { 29 | [self.alertView show]; 30 | } 31 | 32 | - (void)presentInformationViewController { 33 | OCDDashboardInformationViewController *viewController = [[OCDDashboardInformationViewController alloc] init]; 34 | UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 35 | [[[[[UIApplication sharedApplication] delegate] window] rootViewController] 36 | presentViewController:navigationController animated:YES completion:nil]; 37 | } 38 | 39 | - (void)presentPointViewController { 40 | OCDDashboardPointViewController *viewController = [[OCDDashboardPointViewController alloc] init]; 41 | UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 42 | [[[[[UIApplication sharedApplication] delegate] window] rootViewController] 43 | presentViewController:navigationController animated:YES completion:nil]; 44 | } 45 | 46 | - (void)presentLogViewController { 47 | OCDDashboardLogViewController *viewController = [[OCDDashboardLogViewController alloc] init]; 48 | UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 49 | [[[[[UIApplication sharedApplication] delegate] window] rootViewController] 50 | presentViewController:navigationController animated:YES completion:nil]; 51 | } 52 | 53 | #pragma mark - UIAlertViewDelegate 54 | 55 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 56 | NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; 57 | if ([buttonTitle isEqualToString:@"Device Information"]) { 58 | [self presentInformationViewController]; 59 | } 60 | else if ([buttonTitle isEqualToString:@"Debug Point"]) { 61 | [self presentPointViewController]; 62 | } 63 | else if ([buttonTitle isEqualToString:@"Log"]) { 64 | [self presentLogViewController]; 65 | } 66 | } 67 | 68 | #pragma mark - Getter 69 | 70 | - (UIAlertView *)alertView { 71 | if (_alertView == nil) { 72 | _alertView = [[UIAlertView alloc] init]; 73 | _alertView.delegate = self; 74 | _alertView.title = @"OCDebugger Dashboard"; 75 | [_alertView addButtonWithTitle:@"Device Information"]; 76 | [_alertView addButtonWithTitle:@"Debug Point"]; 77 | [_alertView addButtonWithTitle:@"Log"]; 78 | // [_alertView addButtonWithTitle:@"HTTP Watcher"]; 79 | [_alertView addButtonWithTitle:@"Cancel"]; 80 | [_alertView setCancelButtonIndex:[_alertView numberOfButtons]-1]; 81 | } 82 | return _alertView; 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Finder/Application Logic/Manager/OCDFinderManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDFinderManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDFinderManager : NSObject 12 | 13 | @property (nonatomic, copy) NSString *currentPath; 14 | 15 | - (NSArray *)currentSubPaths; 16 | 17 | - (NSString *)executeShell:(NSString *)shell; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Finder/Application Logic/Manager/OCDFinderManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDFinderManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDFinderManager.h" 10 | #import "OCDCore.h" 11 | #import "OCDValueFormatter.h" 12 | #import 13 | 14 | @implementation OCDFinderManager 15 | 16 | - (NSArray *)currentSubPaths { 17 | NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self absolutelyPathWithPath:self.currentPath] error:NULL]; 18 | return files; 19 | } 20 | 21 | - (NSString *)executeShell:(NSString *)shell { 22 | NSMutableString *baseString = [NSMutableString stringWithFormat:@"app:%@ developer$ %@\n", 23 | self.currentPath, shell]; 24 | if ([shell hasPrefix:@"ls"]) { 25 | [baseString appendString:[self ls:shell]]; 26 | } 27 | else if ([shell hasPrefix:@"cd"]) { 28 | [baseString appendString:[self cd:shell]]; 29 | } 30 | else if ([shell hasPrefix:@"rm"]) { 31 | [baseString appendString:[self rm:shell]]; 32 | } 33 | else if ([shell hasPrefix:@"vi"]) { 34 | [baseString appendString:[self vi:shell]]; 35 | } 36 | else { 37 | [baseString appendString:@"command not found."]; 38 | } 39 | [baseString appendString:@"\n\n"]; 40 | return [baseString copy]; 41 | } 42 | 43 | #pragma mark - ls 44 | 45 | - (NSString *)ls:(NSString *)shell { 46 | if ([shell isEqualToString:@"ls"]) { 47 | return [self ls]; 48 | } 49 | else { 50 | return [self lsDirectory:[shell substringFromIndex:3]]; 51 | } 52 | return nil; 53 | } 54 | 55 | - (NSString *)ls { 56 | NSMutableString *resultString = [NSMutableString string]; 57 | NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self absolutelyPathWithPath:self.currentPath] error:NULL]; 58 | [files enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 59 | NSString *filePath = [[self absolutelyPathWithPath:self.currentPath] stringByAppendingFormat:@"/%@", obj]; 60 | NSDictionary *fileAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL]; 61 | [resultString appendFormat:@"%04ld %@ %@ %@\n", 62 | (long)[fileAttrs[NSFileSize] integerValue], [fileAttrs[NSFileModificationDate] description], fileAttrs[NSFileType], obj]; 63 | }]; 64 | return [resultString copy]; 65 | } 66 | 67 | - (NSString *)lsDirectory:(NSString *)directory { 68 | NSMutableString *resultString = [NSMutableString string]; 69 | NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self absolutelyPathWithPath:directory] error:NULL]; 70 | [files enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 71 | NSString *filePath = [[self absolutelyPathWithPath:self.currentPath] stringByAppendingFormat:@"/%@", obj]; 72 | NSDictionary *fileAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL]; 73 | [resultString appendFormat:@"%04ld %@ %@ %@\n", 74 | (long)[fileAttrs[NSFileSize] integerValue], [fileAttrs[NSFileModificationDate] description], fileAttrs[NSFileType], obj]; 75 | }]; 76 | return [resultString copy]; 77 | } 78 | 79 | #pragma mark - cd 80 | 81 | - (NSString *)cd:(NSString *)shell { 82 | if ([shell isEqualToString:@"cd.."] || [shell isEqualToString:@"cd .."]) { 83 | NSMutableArray *components = [[self.currentPath componentsSeparatedByString:@"/"] mutableCopy]; 84 | if ([components count] > 0) { 85 | [components removeLastObject]; 86 | } 87 | self.currentPath = [components componentsJoinedByString:@"/"]; 88 | if (self.currentPath.length == 0) { 89 | self.currentPath = @"/"; 90 | } 91 | } 92 | else if ([shell hasPrefix:@"cd "]) { 93 | if ([[NSFileManager defaultManager] fileExistsAtPath:[self absolutelyPathWithPath:[shell substringFromIndex:3]]]) { 94 | if ([[shell substringFromIndex:3] hasPrefix:@"/"]) { 95 | self.currentPath = [shell substringFromIndex:3]; 96 | } 97 | else if ([self.currentPath hasSuffix:@"/"]) { 98 | self.currentPath = [self.currentPath stringByAppendingString:[shell substringFromIndex:3]]; 99 | } 100 | else { 101 | self.currentPath = [self.currentPath stringByAppendingFormat:@"/%@", [shell substringFromIndex:3]]; 102 | } 103 | } 104 | } 105 | return [NSString stringWithFormat:@"Current Path = %@", self.currentPath]; 106 | } 107 | 108 | #pragma mark - rm 109 | 110 | - (NSString *)rm:(NSString *)shell { 111 | if ([shell isEqualToString:@"rm *"]) { 112 | NSMutableString *result = [NSMutableString string]; 113 | NSArray *subPaths = [self currentSubPaths]; 114 | [subPaths enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 115 | NSError *rmError; 116 | [[NSFileManager defaultManager] removeItemAtPath:[self absolutelyPathWithPath:obj] 117 | error:&rmError]; 118 | if (rmError == nil) { 119 | [result appendFormat:@"%@ Deleted\n", obj]; 120 | } 121 | else { 122 | [result appendFormat:@"%@ Delete failed, reason:%@\n", obj, rmError.localizedDescription]; 123 | } 124 | }]; 125 | return [result copy]; 126 | } 127 | else if ([shell hasPrefix:@"rm "]) { 128 | if ([[NSFileManager defaultManager] fileExistsAtPath:[self absolutelyPathWithPath:[shell substringFromIndex:3]]]) { 129 | NSError *rmError; 130 | [[NSFileManager defaultManager] removeItemAtPath:[self absolutelyPathWithPath:[shell substringFromIndex:3]] error:&rmError]; 131 | if (rmError == nil) { 132 | return @"Deleted"; 133 | } 134 | else { 135 | return rmError.localizedDescription; 136 | } 137 | } 138 | } 139 | return @"Nothing changed."; 140 | } 141 | 142 | #pragma mark - vi 143 | 144 | - (NSString *)vi:(NSString *)shell { 145 | if ([shell hasPrefix:@"vi "]) { 146 | if ([[NSFileManager defaultManager] fileExistsAtPath:[self absolutelyPathWithPath:[shell substringFromIndex:3]]]) { 147 | NSString *fileContent = [NSString stringWithContentsOfFile:[self absolutelyPathWithPath:[shell substringFromIndex:3]] encoding:NSUTF8StringEncoding error:NULL]; 148 | if (fileContent == nil || [fileContent length] > 1024 * 8 || ![fileContent isKindOfClass:[NSString class]]) { 149 | return @"Not a text file or file size large than 8KB."; 150 | } 151 | [[[[OCDCore sharedCore] socketService] pub] 152 | pubMessageToService:@"finder" 153 | method:@"viMode" 154 | params:@{ 155 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 156 | @"filePath": TOString([self absolutelyPathWithPath:[shell substringFromIndex:3]]), 157 | @"fileContent": TOString(fileContent) 158 | }]; 159 | return @""; 160 | } 161 | } 162 | return @"File not exist."; 163 | } 164 | 165 | #pragma mark - Path Helper 166 | 167 | - (NSString *)absolutelyPathWithPath:(NSString *)path { 168 | if ([path hasPrefix:@"/"]) { 169 | return [NSHomeDirectory() stringByAppendingFormat:@"%@", path]; 170 | } 171 | else { 172 | if ([path hasPrefix:@"./"]) { 173 | path = [path substringFromIndex:2]; 174 | } 175 | if ([self.currentPath hasSuffix:@"/"]) { 176 | return [NSHomeDirectory() stringByAppendingFormat:@"%@%@", self.currentPath, path]; 177 | } 178 | else { 179 | return [NSHomeDirectory() stringByAppendingFormat:@"%@/%@", self.currentPath, path]; 180 | } 181 | } 182 | } 183 | 184 | 185 | #pragma mark - Getter 186 | 187 | - (NSString *)currentPath { 188 | if (_currentPath == nil) { 189 | _currentPath = @"/"; 190 | } 191 | return _currentPath; 192 | } 193 | 194 | @end 195 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Finder/Module Interface/OCDFinderCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDFinderCore.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDFinderManager.h" 11 | 12 | @interface OCDFinderCore : NSObject 13 | 14 | @property (nonatomic, strong) OCDFinderManager *manager; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/Finder/Module Interface/OCDFinderCore.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDFinderCore.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDFinderCore.h" 10 | 11 | @implementation OCDFinderCore 12 | 13 | - (OCDFinderManager *)manager { 14 | if (_manager == nil) { 15 | _manager = [[OCDFinderManager alloc] init]; 16 | } 17 | return _manager; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherConnectionEntity.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherConnectionEntity.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherConnectionEntity : NSObject 12 | 13 | @property (nonatomic, copy) NSString *orderID; 14 | 15 | @property (nonatomic, copy) NSString *requestURLString; 16 | 17 | @property (nonatomic, strong) NSDate *requestDate; 18 | 19 | @property (nonatomic, copy) NSString *requestMethod; 20 | 21 | @property (nonatomic, copy) NSString *requestHeader; 22 | 23 | @property (nonatomic, copy) NSString *requestBody; 24 | 25 | @property (nonatomic, copy) NSString *responseURLString; 26 | 27 | @property (nonatomic, copy) NSString *responseStatusCode; 28 | 29 | @property (nonatomic, copy) NSString *responseMIMEType; 30 | 31 | @property (nonatomic, copy) NSString *responseHeader; 32 | 33 | @property (nonatomic, copy) NSString *responseString; 34 | 35 | @property (nonatomic, copy) NSString *responseDataSize; 36 | 37 | @property (nonatomic, copy) NSString *timeUse; 38 | 39 | - (instancetype)initWithReqeust:(NSURLRequest *)request; 40 | 41 | - (instancetype)initWithResponse:(NSURLResponse *)response data:(NSData *)data; 42 | 43 | - (NSDictionary *)toDictionary; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherConnectionEntity.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherConnectionEntity.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDHTTPWatcherConnectionEntity.h" 11 | #import "OCDValueFormatter.h" 12 | 13 | @implementation OCDHTTPWatcherConnectionEntity 14 | 15 | - (instancetype)initWithReqeust:(NSURLRequest *)request 16 | { 17 | self = [super init]; 18 | if (self) { 19 | self.requestURLString = request.URL.absoluteString; 20 | self.requestDate = [NSDate date]; 21 | self.requestMethod = [request HTTPMethod]; 22 | self.requestHeader = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:TODictionary([request allHTTPHeaderFields]) options:kNilOptions error:NULL] encoding:NSUTF8StringEncoding]; 23 | if ([request.HTTPBody length] > 1024 * 64) { 24 | self.requestBody = @"Bigger than 64K, will discard transfer to server."; 25 | } 26 | else { 27 | self.requestBody = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding]; 28 | } 29 | } 30 | return self; 31 | } 32 | 33 | - (instancetype)initWithResponse:(NSURLResponse *)response data:(NSData *)data { 34 | self = [super init]; 35 | if (self) { 36 | self.responseURLString = response.URL.absoluteString; 37 | self.responseMIMEType = response.MIMEType; 38 | if ([response isKindOfClass:[NSHTTPURLResponse class]]) { 39 | NSHTTPURLResponse *theResponse = (id)response; 40 | self.responseStatusCode = [NSString stringWithFormat:@"%ld", (long)theResponse.statusCode]; 41 | self.responseHeader = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:TODictionary([theResponse allHeaderFields]) options:kNilOptions error:NULL] encoding:NSUTF8StringEncoding]; 42 | 43 | NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 44 | if (dataString != nil && [dataString isKindOfClass:[NSString class]]) { 45 | NSString *base64String = [[NSString alloc] initWithData:[data base64EncodedDataWithOptions:kNilOptions] encoding:NSUTF8StringEncoding]; 46 | if ([base64String lengthOfBytesUsingEncoding:NSUTF8StringEncoding] > 1024 * 64) { 47 | self.responseString = @"(Bigger than 64K, will discard transfer to server.)"; 48 | } 49 | else { 50 | self.responseString = base64String; 51 | } 52 | } 53 | else { 54 | self.responseString = @"(Binary response)"; 55 | } 56 | self.responseDataSize = [NSString stringWithFormat:@"%.2fKB", [data length] / 1024.0]; 57 | } 58 | 59 | } 60 | return self; 61 | } 62 | 63 | - (NSDictionary *)toDictionary { 64 | return @{ 65 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 66 | @"orderID": TOString(self.orderID), 67 | @"requestURLString": TOString(self.requestURLString), 68 | @"requestDate": [NSString stringWithFormat:@"%ld", 69 | (long)[self.requestDate timeIntervalSince1970]], 70 | @"requestMethod": TOString(self.requestMethod), 71 | @"requestHeader": TOString(self.requestHeader), 72 | @"responseURLString": TOString(self.responseURLString), 73 | @"responseMIMEType": TOString(self.responseMIMEType), 74 | @"responseStatusCode": TOString(self.responseStatusCode), 75 | @"responseHeader": TOString(self.responseHeader), 76 | @"responseString": TOString(self.responseString), 77 | @"responseDataSize": TOString(self.responseDataSize), 78 | @"timeUse": TOString(self.timeUse), 79 | @"requestBody": TOString(self.requestBody) 80 | }; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherHostEntity.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherHostEntity.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherHostEntity : NSObject 12 | 13 | @property (nonatomic, copy) NSString *domain; 14 | 15 | @property (nonatomic, copy) NSString *hostIP; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherHostEntity.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherHostEntity.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherHostEntity.h" 10 | 11 | @implementation OCDHTTPWatcherHostEntity 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherMappingEntity.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherMappingEntity.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/16. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherMappingEntity : NSObject 12 | 13 | @property (nonatomic, copy) NSString *fromURLStringPattern; 14 | 15 | @property (nonatomic, copy) NSString *toURLStringPattern; 16 | 17 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary; 18 | 19 | - (BOOL)isValidRequest:(NSURLRequest *)request; 20 | 21 | - (NSURLRequest *)modifiedRequest:(NSURLRequest *)reqeust; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherMappingEntity.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherMappingEntity.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/16. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherMappingEntity.h" 10 | #import "OCDValueFormatter.h" 11 | 12 | @implementation OCDHTTPWatcherMappingEntity 13 | 14 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary 15 | { 16 | self = [super init]; 17 | if (self && [dictionary isKindOfClass:[NSDictionary class]]) { 18 | self.fromURLStringPattern = TOString(dictionary[@"fromPattern"]); 19 | self.toURLStringPattern = TOString(dictionary[@"toPattern"]); 20 | } 21 | return self; 22 | } 23 | 24 | - (BOOL)isValidRequest:(NSURLRequest *)request { 25 | if ([request.URL.absoluteString rangeOfString:self.fromURLStringPattern options:NSCaseInsensitiveSearch | NSRegularExpressionSearch].location != NSNotFound) { 26 | return YES; 27 | } 28 | else { 29 | return NO; 30 | } 31 | } 32 | 33 | - (NSURLRequest *)modifiedRequest:(NSURLRequest *)reqeust { 34 | NSString *URLString = reqeust.URL.absoluteString; 35 | URLString = [URLString stringByReplacingOccurrencesOfString:self.fromURLStringPattern withString:self.toURLStringPattern options:NSCaseInsensitiveSearch | NSRegularExpressionSearch range:NSMakeRange(0, [URLString length])]; 36 | NSMutableURLRequest *modifiedRequest = [reqeust mutableCopy]; 37 | [modifiedRequest setURL:[NSURL URLWithString:URLString]]; 38 | return [modifiedRequest copy]; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherRewriteEntity.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherRewriteEntity.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/18. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherRewriteEntity : NSObject 12 | 13 | @property (nonatomic, copy) NSString *fromURLStringPattern; 14 | 15 | @property (nonatomic, copy) NSString *originWord; 16 | 17 | @property (nonatomic, copy) NSString *actionWord; 18 | 19 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary; 20 | 21 | - (BOOL)isValidResponse:(NSURLResponse *)response; 22 | 23 | - (NSData *)modifiedData:(NSData *)data; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Entity/OCDHTTPWatcherRewriteEntity.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherRewriteEntity.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/18. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherRewriteEntity.h" 10 | #import "OCDValueFormatter.h" 11 | 12 | @implementation OCDHTTPWatcherRewriteEntity 13 | 14 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary 15 | { 16 | self = [super init]; 17 | if (self && [dictionary isKindOfClass:[NSDictionary class]]) { 18 | self.fromURLStringPattern = TOString(dictionary[@"fromPattern"]); 19 | self.originWord = TOString(dictionary[@"originWord"]); 20 | self.actionWord = TOString(dictionary[@"actionWord"]); 21 | } 22 | return self; 23 | } 24 | 25 | - (BOOL)isValidResponse:(NSURLResponse *)response { 26 | if ([response.URL.absoluteString rangeOfString:self.fromURLStringPattern options:NSCaseInsensitiveSearch | NSRegularExpressionSearch].location != NSNotFound) { 27 | return YES; 28 | } 29 | else { 30 | return NO; 31 | } 32 | } 33 | 34 | - (NSData *)modifiedData:(NSData *)data { 35 | NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 36 | if (text != nil) { 37 | text = [text stringByReplacingOccurrencesOfString:self.originWord withString:self.actionWord]; 38 | return [text dataUsingEncoding:NSUTF8StringEncoding]; 39 | } 40 | else { 41 | return data; 42 | } 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Manager/OCDHTTPWatcherConnectionManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherConnectionManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDHTTPWatcherConnectionEntity; 12 | 13 | @interface OCDHTTPWatcherConnectionManager : NSObject 14 | 15 | - (void)registerHookers; 16 | 17 | - (void)unregisterHookers; 18 | 19 | - (void)deliverItem:(OCDHTTPWatcherConnectionEntity *)item; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Manager/OCDHTTPWatcherConnectionManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherConnectionManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherConnectionManager.h" 10 | #import "OCDHTTPWatcherURLProtocol.h" 11 | #import "OCDHTTPWatcherConnectionEntity.h" 12 | #import "OCDCore.h" 13 | #import 14 | 15 | @interface OCDHTTPWatcherConnectionManager () 16 | 17 | @end 18 | 19 | @implementation OCDHTTPWatcherConnectionManager 20 | 21 | - (void)registerHookers { 22 | [NSURLProtocol registerClass:[OCDHTTPWatcherURLProtocol class]]; 23 | } 24 | 25 | - (void)unregisterHookers { 26 | [NSURLProtocol unregisterClass:[OCDHTTPWatcherURLProtocol class]]; 27 | } 28 | 29 | - (void)deliverItem:(OCDHTTPWatcherConnectionEntity *)item { 30 | [[[[OCDCore sharedCore] socketService] pub] pubMessageToService:@"HTTPWatcher" 31 | method:@"updateConnection" 32 | params:[item toDictionary]]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Manager/OCDHTTPWatcherHostsManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherHostsManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDHTTPWatcherHostEntity.h" 11 | 12 | @class OCDHTTPWatcherHostEntity; 13 | 14 | @interface OCDHTTPWatcherHostsManager : NSObject 15 | 16 | - (void)addHostItem:(OCDHTTPWatcherHostEntity *)item; 17 | 18 | - (NSURLRequest *)hostedRequestWithRequest:(NSURLRequest *)originRequest; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Manager/OCDHTTPWatcherHostsManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherHostsManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/12. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherHostsManager.h" 10 | #import "OCDHTTPWatcherHostEntity.h" 11 | #import "OCDValueFormatter.h" 12 | 13 | @interface OCDHTTPWatcherHostsManager () 14 | 15 | @property (nonatomic, copy) NSDictionary *items; 16 | 17 | @end 18 | 19 | @implementation OCDHTTPWatcherHostsManager 20 | 21 | - (void)addHostItem:(OCDHTTPWatcherHostEntity *)item { 22 | NSMutableDictionary *items = [self.items mutableCopy]; 23 | [items setObject:item forKey:item.domain]; 24 | self.items = items; 25 | } 26 | 27 | - (NSURLRequest *)hostedRequestWithRequest:(NSURLRequest *)originRequest { 28 | if (self.items[[TOString(originRequest.URL.host) lowercaseString]] != nil) { 29 | NSMutableURLRequest *mutableRequest = [originRequest mutableCopy]; 30 | NSRange hostRange = [originRequest.URL.absoluteString 31 | rangeOfString:[TOString(originRequest.URL.host) lowercaseString]]; 32 | NSString *replacedURLString = [originRequest.URL.absoluteString stringByReplacingCharactersInRange:hostRange withString:[self.items[[TOString(originRequest.URL.host) lowercaseString]] hostIP]]; 33 | [mutableRequest setURL:[NSURL URLWithString:replacedURLString]]; 34 | [mutableRequest setValue:originRequest.URL.host forHTTPHeaderField:@"Host"]; 35 | return [mutableRequest copy]; 36 | } 37 | return originRequest; 38 | } 39 | 40 | - (NSDictionary *)items { 41 | if (_items == nil) { 42 | _items = @{}; 43 | } 44 | return _items; 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Manager/OCDHTTPWatcherModifierManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherModifierManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/16. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherModifierManager : NSObject 12 | 13 | - (void)fetchModifiers; 14 | 15 | - (NSURLRequest *)modifiedRequest:(NSURLRequest *)request; 16 | 17 | - (NSData *)modifiedDataForResponse:(NSURLResponse *)response withData:(NSData *)data; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Manager/OCDHTTPWatcherModifierManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherModifierManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/16. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherModifierManager.h" 10 | #import "OCDHTTPWatcherMappingEntity.h" 11 | #import "OCDHTTPWatcherRewriteEntity.h" 12 | #import "OCDDefine.h" 13 | #import "OCDValueFormatter.h" 14 | 15 | @interface OCDHTTPWatcherModifierManager () 16 | 17 | @property (nonatomic, copy) NSArray *mappingItems; 18 | 19 | @property (nonatomic, copy) NSArray *rewriteItems; 20 | 21 | @end 22 | 23 | @implementation OCDHTTPWatcherModifierManager 24 | 25 | - (instancetype)init 26 | { 27 | self = [super init]; 28 | if (self) { 29 | [self fetchModifiers]; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)fetchModifiers { 35 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[[[OCDDefine sharedDefine] HTTPWatcher] modifierRequestURLString]]]; 36 | [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 37 | if (connectionError == nil) { 38 | 39 | NSMutableArray *mappingItems = [NSMutableArray array]; 40 | NSMutableArray *rewriteItems = [NSMutableArray array]; 41 | 42 | NSArray *modifiers = TOArray([NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:NULL]); 43 | [modifiers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 44 | NSDictionary *itemDictionary = TODictionary(obj); 45 | if (![TOString(itemDictionary[@"is_valid"]) isEqualToString:@"1"]) { 46 | return ; 47 | } 48 | if (itemDictionary[@"modifier_params"] != nil) { 49 | NSData *paramsData = [TOString(itemDictionary[@"modifier_params"]) dataUsingEncoding:NSUTF8StringEncoding]; 50 | NSDictionary *paramsDictionary = TODictionary([NSJSONSerialization JSONObjectWithData:paramsData options:kNilOptions error:NULL]); 51 | if ([TOString(paramsDictionary[@"type"]) isEqualToString:@"mapping"]) { 52 | [mappingItems addObject:[[OCDHTTPWatcherMappingEntity alloc] initWithDictionary:paramsDictionary]]; 53 | } 54 | else if ([TOString(paramsDictionary[@"type"]) isEqualToString:@"rewrite"]) { 55 | [rewriteItems addObject:[[OCDHTTPWatcherRewriteEntity alloc] initWithDictionary:paramsDictionary]]; 56 | } 57 | } 58 | }]; 59 | self.mappingItems = mappingItems; 60 | self.rewriteItems = rewriteItems; 61 | } 62 | }]; 63 | } 64 | 65 | - (NSURLRequest *)modifiedRequest:(NSURLRequest *)request { 66 | __block NSURLRequest *modifiedRequest = request; 67 | [self.mappingItems enumerateObjectsUsingBlock:^(OCDHTTPWatcherMappingEntity *obj, NSUInteger idx, BOOL *stop) { 68 | if ([obj isValidRequest:request]) { 69 | modifiedRequest = [obj modifiedRequest:modifiedRequest]; 70 | } 71 | }]; 72 | return modifiedRequest; 73 | } 74 | 75 | - (NSData *)modifiedDataForResponse:(NSURLResponse *)response withData:(NSData *)data { 76 | __block NSData *modifiedData = data; 77 | [self.rewriteItems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 78 | if ([obj isValidResponse:response]) { 79 | modifiedData = [obj modifiedData:modifiedData]; 80 | } 81 | }]; 82 | return modifiedData; 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Protocol/OCDHTTPWatcherURLProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherConnectionProtocol.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDHTTPWatcherURLProtocol : NSURLProtocol 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Application Logic/Protocol/OCDHTTPWatcherURLProtocol.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherConnectionProtocol.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherURLProtocol.h" 10 | #import "OCDHTTPWatcherConnectionEntity.h" 11 | #import "OCDCore.h" 12 | #import "OCDDefine.h" 13 | 14 | static int watchOrderID = 0; 15 | 16 | @interface OCDHTTPWatcherURLProtocol () 17 | 18 | @property (nonatomic, strong) NSURLConnection *connection; 19 | 20 | @property (nonatomic, strong) NSURLResponse *response; 21 | 22 | @property (nonatomic, strong) NSMutableData *data; 23 | 24 | @property (nonatomic, strong) NSDate *startDate; 25 | 26 | @end 27 | 28 | @implementation OCDHTTPWatcherURLProtocol 29 | 30 | + (void)load { 31 | watchOrderID = arc4random() % 1000000; 32 | } 33 | 34 | + (BOOL)canInitWithRequest:(NSURLRequest *)request { 35 | if (![request.URL.scheme isEqualToString:@"http"] && 36 | ![request.URL.scheme isEqualToString:@"https"]) { 37 | return NO; 38 | } 39 | if ([NSURLProtocol propertyForKey:@"OCDHTTPWatcher" inRequest:request] != nil) { 40 | return NO; 41 | } 42 | if ([NSURLProtocol propertyForKey:kOCDMessageStorageRequestKey inRequest:request] != nil) { 43 | return NO; 44 | } 45 | return YES; 46 | } 47 | 48 | + (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request { 49 | request = [[[[OCDCore sharedCore] HTTPWatcher] modifierManager] modifiedRequest:request]; 50 | request = [[[[OCDCore sharedCore] HTTPWatcher] hostsManager] hostedRequestWithRequest:request]; 51 | NSMutableURLRequest *mutableReqeust = [request mutableCopy]; 52 | [NSURLProtocol setProperty:[NSString stringWithFormat:@"%ld", (long)watchOrderID] 53 | forKey:@"OCDHTTPWatcher" 54 | inRequest:mutableReqeust]; 55 | watchOrderID++; 56 | return [mutableReqeust copy]; 57 | } 58 | 59 | - (void)startLoading { 60 | self.startDate = [NSDate date]; 61 | OCDHTTPWatcherConnectionEntity *connectionItem = [[OCDHTTPWatcherConnectionEntity alloc] 62 | initWithReqeust:self.request]; 63 | connectionItem.orderID = [NSURLProtocol propertyForKey:@"OCDHTTPWatcher" inRequest:self.request]; 64 | [[[[OCDCore sharedCore] HTTPWatcher] connectionManager] deliverItem:connectionItem]; 65 | self.data = [NSMutableData data]; 66 | self.connection = [[NSURLConnection alloc] initWithRequest:[[self class] canonicalRequestForRequest:self.request] delegate:self startImmediately:YES]; 67 | } 68 | 69 | - (void)stopLoading { 70 | [self.connection cancel]; 71 | } 72 | 73 | #pragma mark - NSURLConnectionDelegate 74 | 75 | - (void)connection:(NSURLConnection *)connection 76 | didFailWithError:(NSError *)error 77 | { 78 | [[self client] URLProtocol:self didFailWithError:error]; 79 | } 80 | 81 | - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection { 82 | return YES; 83 | } 84 | 85 | - (void)connection:(NSURLConnection *)connection 86 | didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 87 | [[self client] URLProtocol:self didReceiveAuthenticationChallenge:challenge]; 88 | } 89 | 90 | - (void)connection:(NSURLConnection *)connection 91 | didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 92 | [[self client] URLProtocol:self didCancelAuthenticationChallenge:challenge]; 93 | } 94 | 95 | #pragma mark - NSURLConnectionDataDelegate 96 | 97 | - (void)connection:(NSURLConnection *)connection 98 | didReceiveResponse:(NSURLResponse *)response 99 | { 100 | [[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageAllowed]; 101 | self.response = response; 102 | } 103 | 104 | - (void)connection:(NSURLConnection *)connection 105 | didReceiveData:(NSData *)data 106 | { 107 | data = [[[[OCDCore sharedCore] HTTPWatcher] modifierManager] modifiedDataForResponse:self.response withData:data]; 108 | [[self client] URLProtocol:self didLoadData:data]; 109 | [self.data appendData:data]; 110 | } 111 | 112 | - (NSCachedURLResponse *)connection:(NSURLConnection *)connection 113 | willCacheResponse:(NSCachedURLResponse *)cachedResponse 114 | { 115 | return cachedResponse; 116 | } 117 | 118 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection { 119 | self.data = [[[[[OCDCore sharedCore] HTTPWatcher] modifierManager] modifiedDataForResponse:self.response withData:self.data] mutableCopy]; 120 | [[self client] URLProtocolDidFinishLoading:self]; 121 | OCDHTTPWatcherConnectionEntity *connectionItem = [[OCDHTTPWatcherConnectionEntity alloc] 122 | initWithResponse:self.response 123 | data:[self.data copy]]; 124 | connectionItem.orderID = [NSURLProtocol propertyForKey:@"OCDHTTPWatcher" inRequest:self.request]; 125 | connectionItem.timeUse = [NSString stringWithFormat:@"%.2fs", fabs([self.startDate timeIntervalSinceNow])]; 126 | [[[[OCDCore sharedCore] HTTPWatcher] connectionManager] deliverItem:connectionItem]; 127 | } 128 | 129 | @end 130 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Module Interface/OCDHTTPWatcherCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherCore.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDHTTPWatcherConnectionManager.h" 11 | #import "OCDHTTPWatcherHostsManager.h" 12 | #import "OCDHTTPWatcherModifierManager.h" 13 | 14 | @interface OCDHTTPWatcherCore : NSObject 15 | 16 | @property (nonatomic, strong) OCDHTTPWatcherConnectionManager *connectionManager; 17 | 18 | @property (nonatomic, strong) OCDHTTPWatcherHostsManager *hostsManager; 19 | 20 | @property (nonatomic, strong) OCDHTTPWatcherModifierManager *modifierManager; 21 | 22 | - (void)install; 23 | 24 | - (void)uninstall; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/HTTPWatcher/Module Interface/OCDHTTPWatcherCore.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDHTTPWatcherCore.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDHTTPWatcherCore.h" 10 | 11 | @implementation OCDHTTPWatcherCore 12 | 13 | - (void)install { 14 | [self.connectionManager registerHookers]; 15 | } 16 | 17 | - (void)uninstall { 18 | [self.connectionManager unregisterHookers]; 19 | } 20 | 21 | #pragma mark - Getter 22 | 23 | - (OCDHTTPWatcherConnectionManager *)connectionManager { 24 | if (_connectionManager == nil) { 25 | _connectionManager = [[OCDHTTPWatcherConnectionManager alloc] init]; 26 | } 27 | return _connectionManager; 28 | } 29 | 30 | - (OCDHTTPWatcherHostsManager *)hostsManager { 31 | if (_hostsManager == nil) { 32 | _hostsManager = [[OCDHTTPWatcherHostsManager alloc] init]; 33 | } 34 | return _hostsManager; 35 | } 36 | 37 | - (OCDHTTPWatcherModifierManager *)modifierManager { 38 | if (_modifierManager == nil) { 39 | _modifierManager = [[OCDHTTPWatcherModifierManager alloc] init]; 40 | } 41 | return _modifierManager; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDLog/Application Logic/Entity/OCDLogEntity.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogEntity.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDLogEntity : NSObject 12 | 13 | @property (nonatomic, copy) NSString *logFileName; 14 | 15 | @property (nonatomic, copy) NSString *logFunctionName; 16 | 17 | @property (nonatomic, copy) NSString *logLineNumber; 18 | 19 | @property (nonatomic, copy) NSString *logBody; 20 | 21 | - (NSDictionary *)toDictionary; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDLog/Application Logic/Entity/OCDLogEntity.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogEntity.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDLogEntity.h" 10 | #import "OCDValueFormatter.h" 11 | #import 12 | 13 | @implementation OCDLogEntity 14 | 15 | - (NSDictionary *)toDictionary { 16 | return @{ 17 | @"deviceIdentifier": TOString([[[UIDevice currentDevice] identifierForVendor] UUIDString]), 18 | @"logFileName": TOString(self.logFileName), 19 | @"logFunctionName": TOString(self.logFunctionName), 20 | @"logLineNumber": TOString(self.logLineNumber), 21 | @"logBody": TOString(self.logBody) 22 | }; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDLog/Application Logic/Manager/OCDLogManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDLogEntity; 12 | 13 | @interface OCDLogManager : NSObject 14 | 15 | - (void)saveLogItem:(OCDLogEntity *)item; 16 | 17 | - (NSString *)consoleText; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDLog/Application Logic/Manager/OCDLogManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDLogManager.h" 10 | #import "OCDLogEntity.h" 11 | #import "OCDCore.h" 12 | 13 | @interface OCDLogManager () 14 | 15 | @property (nonatomic, copy) NSArray *items; 16 | 17 | @end 18 | 19 | @implementation OCDLogManager 20 | 21 | - (void)saveLogItem:(OCDLogEntity *)item { 22 | if (item == nil) { 23 | return; 24 | } 25 | NSMutableArray *items = [self.items mutableCopy]; 26 | [items addObject:item]; 27 | self.items = items; 28 | [[[[OCDCore sharedCore] socketService] log] sendLogItem:item]; 29 | } 30 | 31 | - (NSString *)consoleText { 32 | NSMutableString *text = [NSMutableString string]; 33 | [self.items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 34 | if ([obj logBody] != nil) { 35 | [text appendString:[obj logBody]]; 36 | } 37 | }]; 38 | return [text copy]; 39 | } 40 | 41 | #pragma mark - Getter 42 | 43 | - (NSArray *)items { 44 | if (_items == nil) { 45 | _items = @[]; 46 | } 47 | return _items; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDLog/Module Interface/OCDLogCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogCore.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDLogEntity.h" 11 | #import "OCDLogManager.h" 12 | 13 | void OCDLog(const char * file, int lineNumber, const char *functionName, NSString *format, ...); 14 | 15 | @interface OCDLogCore : NSObject 16 | 17 | @property (nonatomic, assign) BOOL enabled; 18 | 19 | @property (nonatomic, strong) OCDLogManager *manager; 20 | 21 | + (void)addLogItem:(OCDLogEntity *)item; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDLog/Module Interface/OCDLogCore.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDLogCore.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/11. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDLogCore.h" 10 | #import "OCDCore.h" 11 | 12 | void OCDLog(const char * file, int lineNumber, const char *functionName, NSString *format, ...) { 13 | if (![[[OCDCore sharedCore] log] enabled]) { 14 | va_list ap; 15 | va_start(ap, format); 16 | NSLogv(format, ap); 17 | va_end (ap); 18 | return; 19 | } 20 | va_list ap; 21 | va_start(ap, format); 22 | if (![format hasSuffix: @"\n"]) 23 | { 24 | format = [format stringByAppendingString: @"\n"]; 25 | } 26 | NSString *body = [[NSString alloc] initWithFormat:format arguments:ap]; 27 | va_end (ap); 28 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 29 | dateFormatter.dateFormat = @"HH:mm:ss"; 30 | NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; 31 | fprintf(stderr, "[OCDLog] %s %s", [dateString UTF8String], [body UTF8String]); 32 | OCDLogEntity *item = [[OCDLogEntity alloc] init]; 33 | item.logFileName = [[NSString stringWithUTF8String:file] lastPathComponent]; 34 | item.logFunctionName = [NSString stringWithUTF8String:functionName]; 35 | item.logLineNumber = [NSString stringWithFormat:@"%d", lineNumber]; 36 | item.logBody = [NSString stringWithFormat:@"%@ %@", dateString, body]; 37 | [OCDLogCore addLogItem:item]; 38 | } 39 | 40 | @implementation OCDLogCore 41 | 42 | + (void)addLogItem:(OCDLogEntity *)item { 43 | [[[[OCDCore sharedCore] log] manager] saveLogItem:item]; 44 | } 45 | 46 | #pragma mark - Getter 47 | 48 | - (OCDLogManager *)manager { 49 | if (_manager == nil) { 50 | _manager = [[OCDLogManager alloc] init]; 51 | } 52 | return _manager; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDPoint/Application Logic/Entity/OCDPointEntity.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointEntity.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface OCDPointEntity : NSObject 12 | 13 | @property (nonatomic, copy) NSString *pointIdentifier; 14 | 15 | @property (nonatomic, assign) NSInteger pointValue; 16 | 17 | @property (nonatomic, strong) id pointObject; 18 | 19 | @property (nonatomic, assign) BOOL isValid; 20 | 21 | - (NSDictionary *)toDictionary; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDPoint/Application Logic/Entity/OCDPointEntity.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointEntity.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDPointEntity.h" 10 | #import "OCDValueFormatter.h" 11 | #import "OCDCore.h" 12 | 13 | @implementation OCDPointEntity 14 | 15 | - (NSDictionary *)toDictionary { 16 | return @{ 17 | @"pointIdentifier": TOString(self.pointIdentifier), 18 | @"pointValue": @(self.pointValue), 19 | @"pointObject": TOString([self.pointObject description]), 20 | @"isValid": @(self.isValid) 21 | }; 22 | } 23 | 24 | - (NSString *)cacheKey { 25 | return [NSString stringWithFormat:@"OCDebugger.Point.Identifier.%@", self.pointIdentifier]; 26 | } 27 | 28 | #pragma mark - Setter 29 | 30 | - (void)setIsValid:(BOOL)isValid { 31 | _isValid = isValid; 32 | [[NSUserDefaults standardUserDefaults] setObject:@(_isValid) forKey:[self cacheKey]]; 33 | [[NSUserDefaults standardUserDefaults] synchronize]; 34 | [[[[OCDCore sharedCore] socketService] point] requestPoints]; 35 | } 36 | 37 | - (void)setPointIdentifier:(NSString *)pointIdentifier { 38 | _pointIdentifier = pointIdentifier; 39 | _isValid = [[[NSUserDefaults standardUserDefaults] objectForKey:[self cacheKey]] boolValue]; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDPoint/Application Logic/Manager/OCDPointManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointManager.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OCDPointEntity; 12 | 13 | @interface OCDPointManager : NSObject 14 | 15 | - (NSArray *)allItems; 16 | 17 | - (void)addPointItem:(OCDPointEntity *)item; 18 | 19 | - (OCDPointEntity *)pointWithIdentifier:(NSString *)pointIdentifier; 20 | 21 | - (BOOL)isPointValidWithPointIdentifier:(NSString *)pointIdentifier; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDPoint/Application Logic/Manager/OCDPointManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointManager.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDPointManager.h" 10 | #import "OCDPointEntity.h" 11 | 12 | @interface OCDPointManager () 13 | 14 | @property (nonatomic, copy) NSDictionary *items; 15 | 16 | @end 17 | 18 | @implementation OCDPointManager 19 | 20 | - (NSArray *)allItems { 21 | return [self.items allValues]; 22 | } 23 | 24 | - (void)addPointItem:(OCDPointEntity *)item { 25 | if (self.items[item.pointIdentifier] != nil) { 26 | return; 27 | } 28 | NSMutableDictionary *items = [self.items mutableCopy]; 29 | [items setObject:item forKey:item.pointIdentifier]; 30 | self.items = items; 31 | } 32 | 33 | - (OCDPointEntity *)pointWithIdentifier:(NSString *)pointIdentifier { 34 | return self.items[pointIdentifier]; 35 | } 36 | 37 | - (BOOL)isPointValidWithPointIdentifier:(NSString *)pointIdentifier { 38 | return [self.items[pointIdentifier] isValid]; 39 | } 40 | 41 | #pragma mark - Getter 42 | 43 | - (NSDictionary *)items { 44 | if (_items == nil) { 45 | _items = @{}; 46 | } 47 | return _items; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDPoint/Module Interface/OCDPointCore.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointCore.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDPointEntity.h" 11 | #import "OCDPointManager.h" 12 | 13 | @interface OCDPointCore : NSObject 14 | 15 | @property (nonatomic, strong) OCDPointManager *manager; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OCDebugger/Classes/Modules/OCDPoint/Module Interface/OCDPointCore.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDPointCore.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/10. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDPointCore.h" 10 | 11 | @implementation OCDPointCore 12 | 13 | #pragma mark - Getter 14 | 15 | - (OCDPointManager *)manager { 16 | if (_manager == nil) { 17 | _manager = [[OCDPointManager alloc] init]; 18 | } 19 | return _manager; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /OCDebugger/OCDPrefixHeader.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | This file should be copy to your project independ of Pods directory. 4 | It helps you to prevent any build error while OCDebugger removed. 5 | Caution: I don't recommend you put OCDebugger into production, before you release application, OCDebugger should be remove from CocoaPods and execute 'pod update'. 6 | **/ 7 | 8 | #ifndef OCDValuePoint 9 | #define OCDValuePoint(...) {} 10 | #endif 11 | 12 | #ifndef OCDObjectPoint 13 | #define OCDObjectPoint(...) {} 14 | #endif -------------------------------------------------------------------------------- /OCDebugger/OCDebugger.h: -------------------------------------------------------------------------------- 1 | // 2 | // OCDebugger.h 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "OCDLogCore.h" 11 | 12 | #ifdef DEBUG 13 | #define NSLog(args...) OCDLog(__FILE__,__LINE__,__PRETTY_FUNCTION__,args); 14 | #else 15 | #define NSLog(...) {} 16 | #endif 17 | 18 | #define OCDValuePoint(ID, VALUE) [OCDebugger addPointWithIdentifier:ID pointValue:VALUE pointObject:nil];if([OCDebugger isPointValid:ID]) {return [OCDebugger pointValue:ID];} 19 | 20 | #define OCDObjectPoint(ID, OBJECT) [OCDebugger addPointWithIdentifier:ID pointValue:0 pointObject:OBJECT];if([OCDebugger isPointValid:ID]) {return [OCDebugger pointObject:ID];} 21 | 22 | @interface OCDebugger : NSObject 23 | 24 | #pragma mark - Public 25 | 26 | /** 27 | * @brief go to web application request an appid with apptoken. 28 | **/ 29 | + (void)setAppID:(NSString *)appID appToken:(NSString *)appToken; 30 | 31 | /** 32 | * @brief enable/disable OCDebugger 33 | **/ 34 | + (void)setEnabled:(BOOL)enabled; 35 | 36 | /** 37 | * @brief bind an IP to Host, just like /etc/hosts 38 | **/ 39 | + (void)setHost:(NSString *)theHost IPAddress:(NSString *)theIPAddress; 40 | 41 | #pragma mark - Private 42 | 43 | + (void)addPointWithIdentifier:(NSString *)identifier pointValue:(NSInteger)pointValue pointObject:(id)pointObject; 44 | 45 | + (BOOL)isPointValid:(NSString *)identifier; 46 | 47 | + (BOOL)pointValue:(NSString *)identifier; 48 | 49 | + (id)pointObject:(NSString *)identifier; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /OCDebugger/OCDebugger.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDebugger.m 3 | // OCDebugger 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "OCDebugger.h" 10 | #import "OCDCore.h" 11 | #import "OCDDefine.h" 12 | #import "OCDHTTPWatcherMappingEntity.h" 13 | 14 | static BOOL isEnabled; 15 | 16 | @implementation OCDebugger 17 | 18 | + (void)setAppID:(NSString *)appID appToken:(NSString *)appToken { 19 | [[OCDDefine sharedDefine] setAppID:appID]; 20 | [[OCDDefine sharedDefine] setAppToken:appToken]; 21 | } 22 | 23 | + (void)setEnabled:(BOOL)enabled { 24 | isEnabled = enabled; 25 | if (enabled) { 26 | [[[OCDDefine sharedDefine] HTTPWatcher] setEnabled:YES]; 27 | [[[[OCDCore sharedCore] socketService] conn] connect]; 28 | [[[OCDCore sharedCore] dashboard] install]; 29 | [[[OCDCore sharedCore] log] setEnabled:YES]; 30 | [[[[OCDCore sharedCore] HTTPWatcher] modifierManager] fetchModifiers]; 31 | } 32 | else { 33 | [[[OCDDefine sharedDefine] HTTPWatcher] setEnabled:NO]; 34 | [[[[OCDCore sharedCore] socketService] conn] disconnect]; 35 | [[[OCDCore sharedCore] dashboard] uninstall]; 36 | [[[OCDCore sharedCore] log] setEnabled:NO]; 37 | } 38 | } 39 | 40 | + (void)setHost:(NSString *)theHost IPAddress:(NSString *)theIPAddress { 41 | OCDHTTPWatcherHostEntity *item = [[OCDHTTPWatcherHostEntity alloc] init]; 42 | item.domain = theHost; 43 | item.hostIP = theIPAddress; 44 | [[[[OCDCore sharedCore] HTTPWatcher] hostsManager] addHostItem:item]; 45 | } 46 | 47 | + (void)addPointWithIdentifier:(NSString *)identifier pointValue:(NSInteger)pointValue pointObject:(id)pointObject { 48 | OCDPointEntity *pointItem = [[OCDPointEntity alloc] init]; 49 | pointItem.pointIdentifier = identifier; 50 | pointItem.pointValue = pointValue; 51 | pointItem.pointObject = pointObject; 52 | [[[[OCDCore sharedCore] point] manager] addPointItem:pointItem]; 53 | } 54 | 55 | + (BOOL)isPointValid:(NSString *)identifier { 56 | if (!isEnabled) { 57 | return NO; 58 | } 59 | return [[[[OCDCore sharedCore] point] manager] isPointValidWithPointIdentifier:identifier]; 60 | } 61 | 62 | + (BOOL)pointValue:(NSString *)identifier { 63 | return [[[[[OCDCore sharedCore] point] manager] pointWithIdentifier:identifier] pointValue]; 64 | } 65 | 66 | + (id)pointObject:(NSString *)identifier { 67 | return [[[[[OCDCore sharedCore] point] manager] pointWithIdentifier:identifier] pointObject]; 68 | } 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /OCDebuggerDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // OCDebuggerDemo 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /OCDebuggerDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // OCDebuggerDemo 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "OCDebugger.h" 11 | #import "OCDPrefixHeader.h" 12 | 13 | @interface AppDelegate () 14 | 15 | @end 16 | 17 | @implementation AppDelegate 18 | 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 21 | [OCDebugger setAppID:@"1" appToken:@"testToken"]; 22 | [OCDebugger setEnabled:YES]; 23 | NSLog(@"123"); 24 | // Override point for customization after application launch. 25 | return YES; 26 | } 27 | 28 | - (void)applicationWillResignActive:(UIApplication *)application { 29 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 30 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 31 | } 32 | 33 | - (void)applicationDidEnterBackground:(UIApplication *)application { 34 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 35 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 36 | } 37 | 38 | - (void)applicationWillEnterForeground:(UIApplication *)application { 39 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 40 | } 41 | 42 | - (void)applicationDidBecomeActive:(UIApplication *)application { 43 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 44 | } 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /OCDebuggerDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /OCDebuggerDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /OCDebuggerDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /OCDebuggerDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.ponycui.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /OCDebuggerDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // OCDebuggerDemo 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /OCDebuggerDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // OCDebuggerDemo 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "OCDebugger.h" 11 | #import "OCDPrefixHeader.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (weak, nonatomic) IBOutlet UIWebView *webView; 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.github.com"]]]; 24 | [self test]; 25 | [NSTimer scheduledTimerWithTimeInterval:15.0 26 | target:self 27 | selector:@selector(test) 28 | userInfo:nil 29 | repeats:YES]; 30 | // Do any additional setup after loading the view, typically from a nib. 31 | } 32 | 33 | - (void)test { 34 | NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/AFNetworking/2.5.4/AFNetworking.podspec.json"]]; 35 | [postRequest setHTTPMethod:@"POST"]; 36 | NSData *postData = [@"key1=value1&key2=value2" dataUsingEncoding:NSUTF8StringEncoding]; 37 | [postRequest setHTTPBody:postData]; 38 | 39 | [NSURLConnection sendAsynchronousRequest:postRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 40 | 41 | }]; 42 | [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com/"]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 43 | 44 | }]; 45 | NSLog(@"testPoint Bool = %d", [self testPoint]); 46 | NSLog(@"testText text = %@", [self testText]); 47 | } 48 | 49 | - (BOOL)testPoint { 50 | OCDValuePoint(@"test", YES); 51 | return NO; 52 | } 53 | 54 | - (NSString *)testText { 55 | OCDObjectPoint(@"How", @"How?"); 56 | return @"What?"; 57 | } 58 | 59 | - (void)didReceiveMemoryWarning { 60 | [super didReceiveMemoryWarning]; 61 | // Dispose of any resources that can be recreated. 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /OCDebuggerDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OCDebuggerDemo 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /OCDebuggerDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.ponycui.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /OCDebuggerDemoTests/OCDebuggerDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // OCDebuggerDemoTests.m 3 | // OCDebuggerDemoTests 4 | // 5 | // Created by 崔 明辉 on 15/6/8. 6 | // Copyright (c) 2015年 PonyCui. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface OCDebuggerDemoTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation OCDebuggerDemoTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /OCDebuggerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.ponycui.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '6.0' 3 | 4 | target 'OCDebugger' do 5 | 6 | pod 'Aspects' 7 | pod 'SocketRocket' 8 | 9 | end 10 | 11 | target 'OCDebuggerTests' do 12 | 13 | end 14 | 15 | target 'OCDebuggerDemo' do 16 | 17 | pod 'Aspects' 18 | pod 'SocketRocket' 19 | 20 | end 21 | 22 | target 'OCDebuggerDemoTests' do 23 | 24 | end 25 | 26 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Aspects (1.4.1) 3 | - SocketRocket (0.2.0) 4 | 5 | DEPENDENCIES: 6 | - Aspects 7 | - SocketRocket 8 | 9 | SPEC CHECKSUMS: 10 | Aspects: 7595ba96a6727a58ebcbfc954497fc5d2fdde546 11 | SocketRocket: 54a4ac2f354c4e8c51ef5dcd4a13bc556d4f2b7c 12 | 13 | COCOAPODS: 0.35.0 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OCDebugger Introduce 2 | 3 | [Chinese edition](https://github.com/PonyCui/OCDebugger/wiki/%E6%9C%80%E9%80%82%E5%90%88iOS%E5%BC%80%E5%8F%91%E8%80%85%E4%BD%BF%E7%94%A8%E7%9A%84%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7-OCDebugger) 4 | 5 | In the iOS development process, an easy to use, efficient debugging tools for developers, can play a multiplier effect. I've used a lot of network packet capture tools including Fiddler, Paros, Charles, PonyDebugger, these tools have their own advantages, but there are some drawbacks. 6 | 7 | Fiddler is developed using C #, does not work on mac installation of iOS developers, tasteless chant; 8 | 9 | Paros is developed using Java, I always do not like Paros interface, and install configuration Paros is not easy; 10 | 11 | Charles is friendly for developer, but still needs proxy setting. 12 | 13 | Personally, I just hope I develop applications that run in the proxy server, when you quit the application, I hope to return to the real environment. Said capture tools have a common drawback is the need to install a fake cert to capture HTTPS connections, along with the increasing number https server arrangement, configure it will be quite troublesome. 14 | 15 | For this reason, I also began to refer PonyDebugger developed new debugging tools OCDebugger, why should develop this tool? I think PonyDebugger been too long not updated, the functionality and experience have been behind the claim, and PonyDebugger also requires developers to install their own server application and use Chrome developer tools, is cumbersome. 16 | 17 | ## OCDebugger functionalities 18 | ### Network tools 19 | 1. Supports SSL (non-proxy mode), without generating a fake certificate you can capture all http / https requests. 20 | 2. Restful interface debug support (future might support Protobuf, WUP debugging), can be directly formatted JSON. 21 | 3. Support retransmission network requests and network requests are executed in real machine again. 22 | 4. Support modifying the network request parameters (Header, URL, Body, Method), modified retransmittable network requests. 23 | 5. Support the modification (Mapping) network requests, while supporting network returns the results to modify (Rewrite). 24 | 6. Hosts binding(/etc/hosts. 25 | 26 | ### Debug tool 27 | 1. NSLog() remotely and locally. 28 | 2. Debug Point 29 | 3. Finder view delete and fix sandbox files. 30 | 31 | ## OCDebugger Installing 32 | ### Use CocoaPods 33 | add ```pod 'OCDebugger'``` to Podfile ,and pod install 34 | ### Request appid and apptoken 35 | Use any kinds of web browser [Dashboard](http://ocdebugger.sinaapp.com/dashboard/) at the top-right side of Dashboard click "Request AppID", just wait a moment, you will gain your appid and apptoken, copy it. 36 | ### Configure 37 | after Pod install ,at AppDelegate ```applicaton:didFinishLaunchingWithOptions:``` block,paste below code 38 | ``` 39 | [OCDebugger setAppID:@"yourappid" appToken:@"yourapptoken"]; 40 | [OCDebugger setEnabled:YES]; 41 | ``` 42 | ### View data 43 | at Dashboard, click top-right side Change AppID,input your appid and apptoken, and then run your app。 44 | 45 | ## Use OCDebugeer helps iOS developer 46 | ### Sniff iPhone network connections 47 | #### Sniffer 48 | OCDebugger default will be all you http / https requests data to the server, you do not need other proxy settings. In the Dashboard, you can see something like the following information. 49 | 50 | ![](https://raw.githubusercontent.com/PonyCui/OCDebugger/master/README_Resources/1.png) 51 | 52 | 1. Device ID is your device ID, each device has a six-digit ID; 53 | 2. The table at the top of the input box to filter out results you want. 54 | 3. Tap Clear to empty all results 55 | 56 | #### View Results 57 | To see the specific results of the request, click on the corresponding Host or Path, pop-up layer has the Request, Response corresponding to the requested content, in response to the content, which respond to the contents if they meet the JSON format will be automatically converted into JSONEditor easy reading. 58 | 59 | #### Modification request content and the retransmission request 60 | Sometimes in order to debug the server's interface, we need to repeatedly request different network parameters. OCDebugger can be easily implemented modifications and retransmission function network requests. 61 | 62 | 1. To re-send the request to enter the corresponding request detailed results page, then click the Resend button. 63 | 2. To modify the corresponding request parameters, modify the corresponding parameter directly in the Request tab, and then click Resend can. 64 | 3. resend request will be successful red in the results list, enabling developers to easily distinguished. 65 | 66 | #### Mapping Function 67 | Mapping functions OCDebugger with Charles's Map feature to keep a hold, Mapping feature allows you to specify a network request is redirected to another URL. 68 | HTTP Connections heading in the right side, there is a Modifier entry, click on it. 69 | 70 | Then click "Create Mapping Rule", you can see the following dialog 71 | 72 | ![](https://raw.githubusercontent.com/PonyCui/OCDebugger/master/README_Resources/9.png) 73 | 74 | We need to fill in each source and destination addresses of network redirection that do not need or do not need to modify the conditions of restrictions, empty it. The figure is an example, to redirect all requests to www.google.com www.github.com 75 | 76 | #### Rewrite function 77 | Rewrite functions are suitable to meet the requirements of network requests to be replaced (currently only supports simple search and replace, which only supports alternate return results). 78 | You need to open the Modifier window, then click Rewrite tab, click on the "Create Rewrite Rule", you can see the following dialog 79 | 80 | ![](https://raw.githubusercontent.com/PonyCui/OCDebugger/master/README_Resources/10.png) 81 | 82 | The figure is an example, we have the word of all requests result www.github.com under the domain name of GitHub replaced Hacked. 83 | 84 | #### Attention 85 | 86 | Note that, Mapping and Rewrite function after need to get data from the server to take effect, therefore, the application is started, there will be a brief unusable state (later versions will join the caching mechanism). 87 | 88 | #### Hosts 89 | 90 | To iOS real machine Specify the IP address for a domain name is not easy, even if the machine is jailbreak, use OCDebugger, just a word to complete the hosts bind. 91 | ``` 92 | [OCDebugger setHost:@"www.github.com" IPAddress:@"127.0.0.1"]; 93 | ``` 94 | 95 | ### Debug tools 96 | #### remote and local NSLog() 97 | 98 | Pony had used NSLog, DDLog, both of which are less than satisfactory, really does not use the USB connection to xcode, you want to look at the log is not easy. To this end, OCDebugger integrated log save, send to the server functionality, this feature is enabled by default. 99 | 100 | To view the Log, only need to open the Dashboard, click the Online Deivces you want to view the Log of the machine you can be seen. 101 | 102 | You can also see Log on real machine, at any interface, shake your iPhone, it will pop up actionSheet, select the Log button. 103 | 104 | #### Point 105 | 106 | Pony will often use this feature to achieve one thing, and that is the real machine interface, fast switching "formal environment" and "test environment", as the following code is a simple practice 107 | 108 | ``` 109 | - (BOOL)isTestEnvironment { 110 | OCDValuePoint(@"测试环境", YES); 111 | return NO; 112 | } 113 | ``` 114 | 115 | When the need to switch the environment, shake iPhone, select Debug Point, you can turn on or off the test environment. Of course, Point of use is not limited thereto. 116 | 117 | #### Finder 118 | 119 | When developers want to view the application sandbox files, the most primitive way is to connect your phone to the Mac, using tools such ifunbox view. 120 | 121 | We have no more simple way? OCDebugger default to support this feature, use the Dashboard, select the device to be operated in Online devices, select Finder tab, enter the command you want to execute the shell can be. ** Sandbox root directory is the home directory ** 122 | 123 | 1. use ls list files 124 | 2. use rm delete files 125 | 3. use vi edit a file 126 | 4. use cd change path 127 | 128 | OCDebugger only a small part of the package of useful commands, hope you like. 129 | 130 | ## Ending 131 | 132 | Pony OCDebugger just outside working hours a little work, which, of course, there are many defects, welcomed the various proposed issue corrected, although considerable effort, but none of strict write a lot of code, it is inevitable dyslexia. 133 | 134 | Before you apply on-line, be sure to OCDebugger removed from Podfile file and execute pod update. 135 | 136 | Pony will continue to develop OCDebugger, added more features. 137 | 138 | ## Reference 139 | 140 | 1. 《iOS开发进阶》第3章 唐巧 著。 141 | -------------------------------------------------------------------------------- /README_Resources/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/0.png -------------------------------------------------------------------------------- /README_Resources/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/1.png -------------------------------------------------------------------------------- /README_Resources/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/10.png -------------------------------------------------------------------------------- /README_Resources/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/2.png -------------------------------------------------------------------------------- /README_Resources/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/3.png -------------------------------------------------------------------------------- /README_Resources/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/4.png -------------------------------------------------------------------------------- /README_Resources/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/5.png -------------------------------------------------------------------------------- /README_Resources/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/6.png -------------------------------------------------------------------------------- /README_Resources/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/7.png -------------------------------------------------------------------------------- /README_Resources/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/8.png -------------------------------------------------------------------------------- /README_Resources/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PonyCui/OCDebugger/1f527d38f318f189810eaffbf92d5bdc7fad7839/README_Resources/9.png --------------------------------------------------------------------------------