diff --git a/commands/FBFindCommands.py b/commands/FBFindCommands.py index f2b7fda..07a511c 100644 --- a/commands/FBFindCommands.py +++ b/commands/FBFindCommands.py @@ -93,7 +93,7 @@ def run(self, arguments, options): def printMatchesInViewOutputStringAndCopyFirstToClipboard(needle, haystack): first = None - for match in re.finditer('.*<.*(' + needle + ').*: (0x[0-9a-fA-F]*);.*', haystack, re.IGNORECASE): + for match in re.finditer('.*<.*(' + needle + ')\\S*: (0x[0-9a-fA-F]*);.*', haystack, re.IGNORECASE): view = match.groups()[-1] className = fb.evaluateExpressionValue('(id)[(' + view + ') class]').GetObjectDescription() print('{} {}'.format(view, className)) diff --git a/commands/FBPrintCommands.py b/commands/FBPrintCommands.py index 6d59094..077e26d 100644 --- a/commands/FBPrintCommands.py +++ b/commands/FBPrintCommands.py @@ -32,6 +32,7 @@ def lldbcommands(): FBPrintApplicationDocumentsPath(), FBPrintData(), FBPrintTargetActions(), + FBPrintJSON(), ] class FBPrintViewHierarchyCommand(fb.FBCommand): @@ -424,3 +425,28 @@ def run(self, arguments, options): actionsDescription = fb.evaluateExpressionValue('(id)[{actions} componentsJoinedByString:@", "]'.format(actions=actions)).GetObjectDescription() print '{target}: {actions}'.format(target=targetDescription, actions=actionsDescription) + +class FBPrintJSON(fb.FBCommand): + + def name(self): + return 'pjson' + + def description(self): + return 'Print JSON representation of NSDictionary or NSArray object' + + def options(self): + return [ + fb.FBCommandArgument(arg='plain', short='-p', long='--plain', boolean=True, default=False, help='Plain JSON') + ] + + def args(self): + return [ fb.FBCommandArgument(arg='object', type='id', help='The NSDictionary or NSArray object to print') ] + + def run(self, arguments, options): + objectToPrint = arguments[0] + pretty = 1 if options.plain is None else 0 + jsonData = fb.evaluateObjectExpression('[NSJSONSerialization dataWithJSONObject:{} options:{} error:nil]'.format(objectToPrint, pretty)) + jsonString = fb.evaluateExpressionValue('(NSString*)[[NSString alloc] initWithData:{} encoding:4]'.format(jsonData)).GetObjectDescription() + + print jsonString +