Last active
November 21, 2020 06:34
-
-
Save dbarden/3cf9f4f77a94601a78e2d4b7c0db3573 to your computer and use it in GitHub Desktop.
json chisel command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Example file with custom commands, located at /magical/commands/example.py | |
import lldb | |
import fbchisellldbbase as fb | |
def lldbcommands(): | |
return [ JSON() ] | |
class JSON(fb.FBCommand): | |
def name(self): | |
return 'json' | |
def description(self): | |
return 'Print the json from a data object.' | |
def args(self): | |
return [ | |
fb.FBCommandArgument( | |
arg="data", | |
type="Data", | |
help="Data that will be evaluated when deserializing.", | |
) | |
] | |
def run(self, arguments, options): | |
# It's a good habit to explicitly cast the type of all return | |
# values and arguments. LLDB can't always find them on its own. | |
objectToPrint = fb.evaluateInputExpression("{obj} as NSObject".format(obj=arguments[0])) | |
jsonData = fb.evaluateExpressionValue("(NSString*)[[NSString alloc] initWithData:(NSObject*){} encoding:4]".format(objectToPrint)).GetObjectDescription() | |
print(jsonData) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment