diff options
| author | KyleMiles <krm504@nyu.edu> | 2020-09-16 22:34:05 +0000 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2020-09-16 22:50:22 +0000 |
| commit | fb72d65faa0df025cc5a5aaaeca850b401ab1d93 (patch) | |
| tree | dfc38032fae9772f8025a507acc380d369af3dc3 /python/databuffer.py | |
| parent | c18b89e4cabfc28081a7893ccd4cf8956c9a797f (diff) | |
Fix #1857 and #1959; Fix bytes/bytearray/string handling for databuffers
Diffstat (limited to 'python/databuffer.py')
| -rw-r--r-- | python/databuffer.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/python/databuffer.py b/python/databuffer.py index 26347101..86cc4c25 100644 --- a/python/databuffer.py +++ b/python/databuffer.py @@ -25,6 +25,7 @@ from binaryninja import _binaryninjacore as core # 2-3 compatibility from binaryninja import pyNativeStr +from binaryninja import cstr import numbers @@ -37,11 +38,10 @@ class DataBuffer(object): elif isinstance(contents, DataBuffer): self.handle = core.BNDuplicateDataBuffer(contents.handle) else: - if bytes != str and isinstance(contents, str): - contents = contents.encode('charmap') + if isinstance(contents, bytes) or isinstance(contents, bytearray) or isinstance(contents, str): + contents = cstr(contents) else: - if isinstance(contents, bytearray): - contents = bytes(contents) + raise TypeError("DataBuffer contents must be bytes, bytearray, or str") self.handle = core.BNCreateDataBuffer(contents, len(contents)) def __del__(self): |
