summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2020-02-16 10:19:19 -0500
committerBrian Potchik <brian@vector35.com>2020-02-16 10:19:19 -0500
commit4842373127779da2471960cfb25a5d549c30f099 (patch)
tree09c0c98a3f102ba2d4b142eba4ce3cb7775209f7 /python
parent21663ec58b1798731dff3d346a10daf935427666 (diff)
Add get_response helper to python DownloadInstance.
Diffstat (limited to 'python')
-rw-r--r--python/downloadprovider.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/python/downloadprovider.py b/python/downloadprovider.py
index b17ed8d5..632a5f25 100644
--- a/python/downloadprovider.py
+++ b/python/downloadprovider.py
@@ -40,6 +40,7 @@ from binaryninja import range
class DownloadInstance(object):
_registered_instances = []
+ _response = b""
def __init__(self, provider, handle = None):
if handle is None:
self._cb = core.BNDownloadInstanceCallbacks()
@@ -79,6 +80,23 @@ class DownloadInstance(object):
def perform_request(self, ctxt, url):
raise NotImplementedError
+ def _write_callback(self, data, len, ctxt):
+ try:
+ str_ptr = ctypes.cast(data, ctypes.c_char_p)
+ str_bytes = str_ptr.value
+ self._response = self._response + str_bytes
+ return len
+ except:
+ log.log_error(traceback.format_exc())
+
+ def get_response(self, url):
+ callbacks = core.BNDownloadInstanceOutputCallbacks()
+ callbacks.writeCallback = callbacks.writeCallback.__class__(self._write_callback)
+ callbacks.writeContext = 0
+ callbacks.progressContext = 0
+ self._response = b""
+ result = core.BNPerformDownloadRequest(self.handle, url, callbacks)
+ return (result, self._response)
class _DownloadProviderMetaclass(type):
@property