summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2025-06-30 16:40:48 -0400
committerBrian Potchik <brian@vector35.com>2025-06-30 16:40:48 -0400
commit77f007b2cc0a01d2135da53f4071fe2024e42da2 (patch)
tree8a04402c454b4c8df2dbf380bbdbcdb00b9acca0 /python
parent155eb8ba6700084a8eb36d4d3549171930f950fd (diff)
Fix busted stringify_unicode_data python API.
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 4761758a..ee6b63e4 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -10140,19 +10140,25 @@ to a the type "tagRECT" found in the typelibrary "winX64common"
"""
return MemoryMap(handle=self.handle)
- def stringify_unicode_data(
- self, arch: Optional['architecture.Architecture'], buffer: 'databuffer.DataBuffer',
- allow_short_strings: bool = False
- ) -> Tuple[Optional[str], Optional[StringType]]:
+ def stringify_unicode_data(self, arch: Optional['architecture.Architecture'], buffer: 'databuffer.DataBuffer', allow_short_strings: bool = False) -> Tuple[Optional[str], Optional[StringType]]:
+ """
+ ``stringify_unicode_data`` converts a buffer of unicode data into a string representation.
+ :param arch: The architecture to use for stringification, or None to use the current architecture of the BinaryView
+ :param buffer: The DataBuffer containing the unicode data to stringify
+ :param allow_short_strings: If True, allows short strings to be returned, otherwise only long strings are returned
+ :return: A tuple containing the string representation and its type, or (None, None) if the stringification fails
+ :rtype: Tuple[Optional[str], Optional[StringType]]
+ """
+ if not isinstance(buffer, databuffer.DataBuffer):
+ raise TypeError("buffer must be an instance of databuffer.DataBuffer")
string = ctypes.c_char_p()
string_type = ctypes.c_int()
if arch is not None:
arch = arch.handle
- if not core.BNStringifyUnicodeData(
- self.handle, arch, buffer.handle, allow_short_strings, ctypes.byref(string), ctypes.byref(string_type)):
+ if not core.BNStringifyUnicodeData(self.handle, arch, buffer.handle, allow_short_strings, ctypes.byref(string), ctypes.byref(string_type)):
return None, None
- result = string.value
- core.BNFreeString(string)
+ result = string.value.decode('utf-8')
+ core.free_string(string)
return result, StringType(string_type.value)
class BinaryReader: