From 77f007b2cc0a01d2135da53f4071fe2024e42da2 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 30 Jun 2025 16:40:48 -0400 Subject: Fix busted stringify_unicode_data python API. --- python/binaryview.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'python') 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: -- cgit v1.3.1