Created
January 13, 2017 08:10
-
-
Save bricklife/080533e6855c7aef2319baeac60d2b8e to your computer and use it in GitHub Desktop.
LLDB Plugin - curl
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/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