def removeDebugHUD(debugger, command, exe_ctx, result, internal_dict) -> None: """ Syntax: removehud Examples: (lldb) removehud This command is implemented in HMDebugHUD.py """ global gClassName if not HM.existClass(gClassName): HM.DPrint(f"{gClassName} does not exist.") return command_script = f''' UIView *keyWindow = [UIApplication sharedApplication].keyWindow; Class HUDClass = (Class)objc_lookUpClass("{gClassName}"); UIView *objView = nil; for (UIView *subView in keyWindow.subviews) {{ if ([subView isKindOfClass:HUDClass]) {{ objView = subView; break; }} }} [objView removeFromSuperview]; objView; ''' val = HM.evaluateExpressionValue(command_script) if HM.judgeSBValueHasValue(val): HM.DPrint("remove done!") else: HM.DPrint(f"{gClassName} does not exist.")
def register() -> None: if HM.existClass(gClassName): return # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, HMDebugBaseViewController.gClassName) HM.addIvar(classValue.GetValue(), "_leftTextArray", "NSMutableArray *") HM.addIvar(classValue.GetValue(), "_rightTextArray", "NSMutableArray *") HM.registerClass(classValue.GetValue()) # Add methods HM.DPrint(f"Add methods to {gClassName}...") viewDidLoadIMPValue = makeViewDidLoadIMP() if not HM.judgeSBValueHasValue(viewDidLoadIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "viewDidLoad", viewDidLoadIMPValue.GetValue(), "v@:") # Methods related to tableView. HM.DPrint(f"Add methods to {gClassName}......") if not addTableViewMethods(): HMProgressHUD.hide() return HM.DPrint(f"Register {gClassName} done!") HMProgressHUD.hide()
def registerProtocol(): global gProtocolName if HM.existClass(gProtocolName): return # Register class HM.DPrint(f"Register {gProtocolName}...") classValue = HM.allocateClass(gProtocolName, "NSURLProtocol") HM.registerClass(classValue.GetValue()) # Add methods HM.DPrint(f"Add methods to {gProtocolName}...") canInitWithRequestIMPValue = makeCanInitWithRequestIMP() if not HM.judgeSBValueHasValue(canInitWithRequestIMPValue): return HM.addClassMethod(gProtocolName, "canInitWithRequest:", canInitWithRequestIMPValue.GetValue(), "B@:@") HM.DPrint(f"Register {gProtocolName} done!") # register NSURLProtocol registerClassExp = f"[NSURLProtocol registerClass:(Class){classValue.GetValue()}]" HM.evaluateExpressionValue(registerClassExp)
def register() -> None: if HM.existClass(gClassName): return # Register class HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, "UIView") HM.addIvar(classValue.GetValue(), "_contentView", "UIView *") HM.addIvar(classValue.GetValue(), "_indicator", "UIActivityIndicatorView *") HM.addIvar(classValue.GetValue(), "_textLab", "UILabel *") HM.addIvar(classValue.GetValue(), "_hideDelayTimer", "NSTimer *") HM.registerClass(classValue.GetValue()) # Add Class methods HM.DPrint(f"Add methods to {gClassName}...") sharedInstanceIMPValue = makeSharedInstanceIMP() if not HM.judgeSBValueHasValue(sharedInstanceIMPValue): return HM.addClassMethod(gClassName, "sharedInstance", sharedInstanceIMPValue.GetValue(), "@@:") showHUDIMPValue = makeShowHUDIMP() if not HM.judgeSBValueHasValue(showHUDIMPValue): return HM.addClassMethod(gClassName, "showHUD", showHUDIMPValue.GetValue(), "@@:") showOnlyTextIMPValue = makeShowOnlyTextHiddenAfterDelayIMP() if not HM.judgeSBValueHasValue(showOnlyTextIMPValue): return HM.addClassMethod(gClassName, "showOnlyText:hiddenAfterDelay:", showOnlyTextIMPValue.GetValue(), "@@:@i") hideHUDIMPValue = makeHideHUDIMP() if not HM.judgeSBValueHasValue(hideHUDIMPValue): return HM.addClassMethod(gClassName, "hideHUD", hideHUDIMPValue.GetValue(), "@@:") setTextIMPValue = makeSetTextIMP() if not HM.judgeSBValueHasValue(setTextIMPValue): return HM.addClassMethod(gClassName, "setText:", setTextIMPValue.GetValue(), "v@:@") # Add Instance methods HM.DPrint(f"Add methods to {gClassName}......") initWithFrameIMPValue = makeInitWithFrameIMP() if not HM.judgeSBValueHasValue(initWithFrameIMPValue): return HM.addInstanceMethod(gClassName, "initWithFrame:", initWithFrameIMPValue.GetValue(), "@@:{CGRect={CGPoint=dd}{CGSize=dd}}") layoutSubviewsIMPValue = makeLayoutSubviewsIMP() if not HM.judgeSBValueHasValue(layoutSubviewsIMPValue): return HM.addInstanceMethod(gClassName, "layoutSubviews", layoutSubviewsIMPValue.GetValue(), "v@:") HM.DPrint(f"Register {gClassName} done!")
def register() -> None: if HM.existClass(gClassName): return # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, "UIWindow") HM.registerClass(classValue.GetValue()) HM.DPrint(f"Register {gClassName} done!")
def showFPS(debugger, command, exe_ctx, result, internal_dict): """ Syntax: showfps Examples: (lldb) showfps Notice: showfps is deprecated. Use showhud instead. This command is implemented in HMFPSLabel.py """ HM.DPrint("showfps is deprecated. Use showhud instead.") FPSClassName = "HMFPSLabel" if HM.existClass(FPSClassName): HM.DPrint("HMFPSLabel is already on display") return # Register class FPSLabelClassValue = HM.allocateClass(FPSClassName, "UILabel") HM.addIvar(FPSLabelClassValue.GetValue(), "_link", "CADisplayLink *") HM.addIvar(FPSLabelClassValue.GetValue(), "_count", "int") HM.addIvar(FPSLabelClassValue.GetValue(), "_lastTime", "double") HM.registerClass(FPSLabelClassValue.GetValue()) addToKeyWindowIMPValue = makeAddToKeyWindowIMP() if not HM.judgeSBValueHasValue(addToKeyWindowIMPValue): return HM.addClassMethod(FPSClassName, "addToKeyWindow", addToKeyWindowIMPValue.GetValue(), "@@:") tickIMPValue = makeTickIMP() if not HM.judgeSBValueHasValue(tickIMPValue): return HM.addInstanceMethod(FPSClassName, "tick:", tickIMPValue.GetValue(), "v@:@") # Show fps command addToKeyWindowCommand = ''' Class fps = NSClassFromString(@"HMFPSLabel"); (UILabel *)[fps performSelector:@selector(addToKeyWindow)]; ''' HM.evaluateExpressionValue(addToKeyWindowCommand) HM.DPrint("showfps Done!") HM.processContinue()
def register() -> None: if HM.existClass(gClassName): return HMDebugBaseViewController.register() # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, HMDebugBaseViewController.gClassName) HM.registerClass(classValue.GetValue()) # Add methods HM.DPrint(f"Add methods to {gClassName}...") presentIMPValue = makePresentIMP() if not HM.judgeSBValueHasValue(presentIMPValue): HMProgressHUD.hide() return HM.addClassMethod(gClassName, "present", presentIMPValue.GetValue(), "@@:") viewDidLoadIMPValue = makeViewDidLoadIMP() if not HM.judgeSBValueHasValue(viewDidLoadIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "viewDidLoad", viewDidLoadIMPValue.GetValue(), "v@:") dismissSelfIMPValue = makeDismissSelfIMP() if not HM.judgeSBValueHasValue(dismissSelfIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "dismissSelf", dismissSelfIMPValue.GetValue(), "v@:") # Methods related to tableView. HM.DPrint(f"Add methods to {gClassName}......") if not addTableViewMethods(): HMProgressHUD.hide() return # Methods related to features. HM.DPrint(f"Add methods to {gClassName}.........") if not addFeatureMethods(): HMProgressHUD.hide() return HM.DPrint(f"Register {gClassName} done!") HMProgressHUD.hide()
def register() -> None: if HM.existClass(gClassName): return # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, "UIViewController") HM.registerClass(classValue.GetValue()) # Add methods HM.DPrint(f"Add methods to {gClassName}...") viewDidLoadIMPValue = makeViewDidLoadIMP() if not HM.judgeSBValueHasValue(viewDidLoadIMPValue): return HM.addInstanceMethod(gClassName, "viewDidLoad", viewDidLoadIMPValue.GetValue(), "v@:") HM.DPrint(f"Register {gClassName} done!")
def request(debugger, command, exe_ctx, result, internal_dict): """ Syntax: request Examples: (lldb) request Notice: Except WKWebView This command is implemented in HMNetwork.py """ global gProtocolName if HM.existClass(gProtocolName): return registerProtocol() swizzlingProtocolClasses() HM.processContinue()
def swizzlingProtocolClasses(): global gCustomizedSELString # add customized method clsName = "__NSCFURLSessionConfiguration" if not HM.existClass(clsName): clsName = "NSURLSessionConfiguration" HMLLDBProtocolClassesIMPValue = makeHMLLDBProtocolClassesIMP() if not HM.judgeSBValueHasValue(HMLLDBProtocolClassesIMPValue): return HM.addInstanceMethod(clsName, gCustomizedSELString, HMLLDBProtocolClassesIMPValue.GetValue(), "@@:") # exchange implementation command_script = f''' Class cls = NSClassFromString(@"{clsName}"); Method m1 = class_getInstanceMethod(cls, NSSelectorFromString(@"protocolClasses")); Method m2 = class_getInstanceMethod(cls, NSSelectorFromString(@"{gCustomizedSELString}")); method_exchangeImplementations(m1, m2); ''' HM.evaluateExpressionValue(command_script)
def isDisplayingHUD() -> bool: if not HM.existClass(gClassName): return False command_script = f''' BOOL isDisplaying = NO; UIView *keyWindow = [UIApplication sharedApplication].keyWindow; UIView *HUD = nil; Class HUDClass = (Class)objc_lookUpClass("{gClassName}"); for (UIView *subView in keyWindow.subviews) {{ if ([subView isKindOfClass:HUDClass]) {{ isDisplaying = YES; HUD = subView; break; }} }} if (HUD) {{ [keyWindow bringSubviewToFront:HUD]; }} isDisplaying; ''' val = HM.evaluateExpressionValue(command_script) return HM.boolOfSBValue(val)
def register() -> None: if HM.existClass(gClassName): return HMProgressHUD.register() HMDebugWindow.register() HMDebugBaseViewController.register() # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, HMDebugBaseViewController.gClassName) HM.addIvar(classValue.GetValue(), "_previousKeyWindow", "UIWindow *") HM.addIvar(classValue.GetValue(), "_highlightView", "UIView *") HM.addIvar(classValue.GetValue(), "_targetView", "UIView *") HM.addIvar(classValue.GetValue(), "_exitBtn", "UIButton *") HM.addIvar(classValue.GetValue(), "_infoView", "UIView *") HM.addIvar(classValue.GetValue(), "_actionView", "UIButton *") HM.registerClass(classValue.GetValue()) HM.DPrint(f"Add methods to {gClassName}...") startIMPValue = makeStartIMP() if not HM.judgeSBValueHasValue(startIMPValue): HMProgressHUD.hide() return HM.addClassMethod(gClassName, "start", startIMPValue.GetValue(), "@@:") viewDidLoadIMPValue = makeViewDidLoadIMP() if not HM.judgeSBValueHasValue(viewDidLoadIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "viewDidLoad", viewDidLoadIMPValue.GetValue(), "v@:") viewDidLayoutSubviewsIMPValue = makeViewDidLayoutSubviewsIMP() if not HM.judgeSBValueHasValue(viewDidLayoutSubviewsIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "viewDidLayoutSubviews", viewDidLayoutSubviewsIMPValue.GetValue(), "v@:") # event HM.DPrint(f"Add methods to {gClassName}......") clickExitBtnIMPValue = makeClickExitBtnIMP() if not HM.judgeSBValueHasValue(clickExitBtnIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "clickExitBtn", clickExitBtnIMPValue.GetValue(), "v@:") clickCloseBtnIMPValue = makeClickCloseBtnIMP() if not HM.judgeSBValueHasValue(clickCloseBtnIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "clickCloseBtn", clickCloseBtnIMPValue.GetValue(), "v@:") handleTapRecognizerIMPValue = makeHandleTapRecognizerIMP() if not HM.judgeSBValueHasValue(handleTapRecognizerIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "handleTapRecognizer:", handleTapRecognizerIMPValue.GetValue(), "v@:@") findSubviewAtPointInViewIMPValue = makeFindSubviewAtPointInViewIMP() if not HM.judgeSBValueHasValue(findSubviewAtPointInViewIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "findSubviewAtPoint:inView:", findSubviewAtPointInViewIMPValue.GetValue(), "@@:{CGPoint=dd}@") refreshTargetViewIMPValue = makeRefreshTargetViewIMP() if not HM.judgeSBValueHasValue(refreshTargetViewIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "refreshTargetView:", refreshTargetViewIMPValue.GetValue(), "v@:@") getInfoArrayFromTargetViewIMPValue = makeGetInfoArrayFromTargetViewIMP() if not HM.judgeSBValueHasValue(getInfoArrayFromTargetViewIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "getInfoArrayFromTargetView:", getInfoArrayFromTargetViewIMPValue.GetValue(), "@@:@") # function action HM.DPrint(f"Add methods to {gClassName}.........") if not addFunctionMethods(): HMProgressHUD.hide() return HM.DPrint(f"Register {gClassName} done!") HMProgressHUD.hide()
def register() -> None: if HM.existClass(gClassName): return HMProgressHUD.register() HMDebugBaseViewController.register() # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, HMDebugBaseViewController.gClassName) HM.addIvar(classValue.GetValue(), "_tableView", "UITableView *") HM.addIvar(classValue.GetValue(), "_currentPath", "NSString *") HM.addIvar(classValue.GetValue(), "_childPaths", "NSMutableArray *") HM.registerClass(classValue.GetValue()) # Add methods HM.DPrint(f"Add methods to {gClassName}...") viewDidLoadIMPValue = makeViewDidLoadIMP() if not HM.judgeSBValueHasValue(viewDidLoadIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "viewDidLoad", viewDidLoadIMPValue.GetValue(), "v@:") loadPathIMPValue = makeLoadPathIMP() if not HM.judgeSBValueHasValue(loadPathIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "loadPath:", loadPathIMPValue.GetValue(), "v@:@") clickBackItemIMPValue = makeClickBackItemIMP() if not HM.judgeSBValueHasValue(clickBackItemIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "clickBackItem", clickBackItemIMPValue.GetValue(), "v@:") clickPopItemIMPValue = makeClickPopItemIMP() if not HM.judgeSBValueHasValue(clickPopItemIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "clickPopItem", clickPopItemIMPValue.GetValue(), "v@:") deleteFileOrDirIMPValue = makeDeleteFileOrDirIMP() if not HM.judgeSBValueHasValue(deleteFileOrDirIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "deleteFileOrDir:", deleteFileOrDirIMPValue.GetValue(), "v@:@") # Methods related to tableView. HM.DPrint(f"Add methods to {gClassName}......") if not addTableViewMethods(): HMProgressHUD.hide() return HM.DPrint(f"Register {gClassName} done!") HMProgressHUD.hide()
def push(debugger, command, exe_ctx, result, internal_dict): """ Syntax: push <className> push [--instance] <instance> Options: --instance/-i; Push the UIViewController instance. Examples: (lldb) push PersonalViewController (lldb) push -i [[PersonalViewController alloc] init] (lldb) expression -l objc -O -- [PersonalViewController new] <PersonalViewController: 0x7fed30c5a070> (lldb) push -i 0x7fed30c5a070 Notice: "push MyViewController" needs to execute "[[MyViewController alloc] init]" first. If the initializer of the class requires parameters, or the class needs to pass parameters after initialization, this command may cause errors. This command is implemented in HMPushViewController.py """ # HM.DPrint(type(command)) # <class 'str'> # HM.DPrint(type(exe_ctx)) # <class 'lldb.SBExecutionContext'> # HM.DPrint(type(result)) # <class 'lldb.SBCommandReturnObject'> # HM.DPrint(type(internal_dict)) # <class 'dict'> command_args = shlex.split(command) parser = generate_option_parser() try: # options: optparse.Values # args: list (options, args) = parser.parse_args(command_args) except: result.SetError(parser.usage) return if len(args) == 0: HM.DPrint("Error input, plase enter 'help push' for more infomation") return HM.DPrint("Waiting...") navigationVC = getNavigationVC() if navigationVC is None: HM.DPrint("Cannot find a UINavigationController") return state = False if options.instance: instanceExpr: str = "" for string in args: instanceExpr += string + " " instanceExpr = instanceExpr.rstrip() VCObject = HM.evaluateExpressionValue(instanceExpr).GetValue() else: makeVCExpression = f"(UIViewController *)[[NSClassFromString(@\"{args[0]}\") alloc] init]" VCObject = HM.evaluateExpressionValue(makeVCExpression).GetValue() # address if verifyObjIsKindOfClass(VCObject, "UIViewController"): pushExpression = f"(void)[{navigationVC} pushViewController:(id){VCObject} animated:YES]" debugger.HandleCommand('expression -l objc -O -- ' + pushExpression) state = True elif not options.instance: classPrefixes = HM.getClassPrefixes()[0] for prefix in classPrefixes: # for Swift file className = f"{prefix}.{args[0]}" if not HM.existClass(className): continue makeVCExpression = f"(UIViewController *)[[NSClassFromString(@\"{className}\") alloc] init]" VCObject = HM.evaluateExpressionValue(makeVCExpression).GetValue() # address if verifyObjIsKindOfClass(VCObject, "UIViewController"): pushExpression = f"(void)[{navigationVC} pushViewController:(id){VCObject} animated:YES]" debugger.HandleCommand('expression -l objc -O -- ' + pushExpression) state = True break HM.DPrint("push succeed" if state else "push failed") if state: HM.processContinue()
def showDebugHUD(debugger, command, exe_ctx, result, internal_dict): """ Syntax: showhud Examples: (lldb) showhud Summary: Show debug HUD. 1.Memory footprint. 2.CPU utilization. 3.FPS in main thread. The UI style is based on https://github.com/meitu/MTHawkeye This command is implemented in HMDebugHUD.py """ global gClassName if isDisplayingHUD(): HM.DPrint(f"{gClassName} is already on display") HM.processContinue() return elif HM.existClass(gClassName): showHUDFunc() HM.processContinue() return # Register class HMProgressHUD.show(f"Register {gClassName}...") HM.DPrint(f"Register {gClassName}...") classValue = HM.allocateClass(gClassName, "UIView") HM.addIvar(classValue.GetValue(), "_link", "CADisplayLink *") HM.addIvar(classValue.GetValue(), "_count", "int") # count in 1 second HM.addIvar(classValue.GetValue(), "_lastTime", "double") HM.addIvar(classValue.GetValue(), "_memoryLab", "UILabel *") HM.addIvar(classValue.GetValue(), "_cpuUtilizationLab", "UILabel *") HM.addIvar(classValue.GetValue(), "_fpsLab", "UILabel *") HM.registerClass(classValue.GetValue()) # Add methods HM.DPrint(f"Add methods to {gClassName}...") addToKeyWindowIMPValue = makeAddToKeyWindowIMP() if not HM.judgeSBValueHasValue(addToKeyWindowIMPValue): HMProgressHUD.hide() return HM.addClassMethod(gClassName, "addToKeyWindow", addToKeyWindowIMPValue.GetValue(), "@@:") tapSelfIMPValue = makeTapSelfIMP() if not HM.judgeSBValueHasValue(tapSelfIMPValue): HMProgressHUD.hide() return HM.addInstanceMethod(gClassName, "tapSelf", tapSelfIMPValue.GetValue(), "v@:") # Add methods(update) if not addUpdateMethods(): HMProgressHUD.hide() return # Add methods(move) HM.DPrint(f"Add methods to {gClassName}......") if not addMoveMethods(): HMProgressHUD.hide() return # Add breakpoint in tapSelf HM.DPrint("Add breakpoint to hook method...") HM.addOneShotBreakPointInIMP(tapSelfIMPValue, "HMDebugHUD.tapSelfBreakPointHandler", "HMDebugHUD_TapSelf_Breakpoint") HM.DPrint(f"Register {gClassName} done!") # Show HUD command showHUDFunc() HMProgressHUD.hide() HM.processContinue()