Skip to content

Instantly share code, notes, and snippets.

@bricklife
Created January 13, 2017 08:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricklife/080533e6855c7aef2319baeac60d2b8e to your computer and use it in GitHub Desktop.
Save bricklife/080533e6855c7aef2319baeac60d2b8e to your computer and use it in GitHub Desktop.
LLDB Plugin - curl
#!/usr/bin/env python
import lldb
def process(debugger, command, result, internal_dict):
lldb.debugger.HandleCommand("""
expr -l swift --
func $process(URLRequest: NSURLRequest) {
func curl(URLRequest: NSURLRequest) -> String {
guard let URLString = URLRequest.URL?.absoluteString else {
return "$ curl command could not be created"
}
var components = ["$ curl -i \\"\\(URLString)\\""]
if let HTTPMethod = URLRequest.HTTPMethod where HTTPMethod != "GET" {
components.append("-X \\(HTTPMethod)")
}
if let headerFields = URLRequest.allHTTPHeaderFields {
for (field, value) in headerFields {
switch field {
case "Cookie":
continue
default:
components.append("-H \\"\\(field): \\(value)\\"")
}
}
}
if let
HTTPBodyData = URLRequest.HTTPBody,
HTTPBody = String(data: HTTPBodyData, encoding: NSUTF8StringEncoding) {
let escapedBody = HTTPBody.stringByReplacingOccurrencesOfString("\\"", withString: "\\\\\\"")
components.append("-d \\"\\(escapedBody)\\"")
}
return components.joinWithSeparator(" \\\\\\n\\t")
}
Swift.print(curl(URLRequest))
}
""".strip())
lldb.debugger.HandleCommand('expr -l swift -- $process(' + command + ')')
def __lldb_init_module(debugger,internal_dict):
debugger.HandleCommand("command script add -f curl.process curl")
print "curl command enabled."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment