diff options
| -rw-r--r-- | binaryview.cpp | 6 | ||||
| -rw-r--r-- | python/binaryview.py | 22 |
2 files changed, 16 insertions, 12 deletions
diff --git a/binaryview.cpp b/binaryview.cpp index 66ef0e10..f2b33dc3 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -5530,13 +5530,11 @@ void BinaryView::SetUserGlobalPointerValue(const Confidence<RegisterValue>& valu } -optional<pair<string, BNStringType>> BinaryView::StringifyUnicodeData(Architecture* arch, - const DataBuffer& buffer, bool allowShortStrings) +optional<pair<string, BNStringType>> BinaryView::StringifyUnicodeData(Architecture* arch, const DataBuffer& buffer, bool allowShortStrings) { char* str = nullptr; BNStringType type = AsciiString; - if (!BNStringifyUnicodeData(m_object, arch ? arch->GetObject() : nullptr, buffer.GetBufferObject(), - allowShortStrings, &str, &type)) + if (!BNStringifyUnicodeData(m_object, arch ? arch->GetObject() : nullptr, buffer.GetBufferObject(), allowShortStrings, &str, &type)) return nullopt; string result(str); 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: |
