GeezerVison is showing github.com — Fix busted stringify_unicode_data python API. · Vector35/binaryninja-api@77f007b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: binaryview.cpp +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5530,13 +5530,11 @@ void BinaryView::SetUserGlobalPointerValue(const Confidence<RegisterValue>& valu | 5530 | 5530 | } | 5531 | 5531 |
| 5532 | 5532 |
| 5533 | | -optional<pair<string, BNStringType>> BinaryView::StringifyUnicodeData(Architecture* arch, | 5534 | | - const DataBuffer& buffer, bool allowShortStrings) | | 5533 | +optional<pair<string, BNStringType>> BinaryView::StringifyUnicodeData(Architecture* arch, const DataBuffer& buffer, bool allowShortStrings) | 5535 | 5534 | { | 5536 | 5535 | char* str = nullptr; | 5537 | 5536 | BNStringType type = AsciiString; | 5538 | | - if (!BNStringifyUnicodeData(m_object, arch ? arch->GetObject() : nullptr, buffer.GetBufferObject(), | 5539 | | - allowShortStrings, &str, &type)) | | 5537 | + if (!BNStringifyUnicodeData(m_object, arch ? arch->GetObject() : nullptr, buffer.GetBufferObject(), allowShortStrings, &str, &type)) | 5540 | 5538 | return nullopt; | 5541 | 5539 |
| 5542 | 5540 | string result(str); | |
Collapse file Copy file name to clipboardExpand all lines: python/binaryview.py +14-8Lines changed: 14 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10140,19 +10140,25 @@ def memory_map(self): | 10140 | 10140 | """ | 10141 | 10141 | return MemoryMap(handle=self.handle) | 10142 | 10142 |
| 10143 | | - def stringify_unicode_data( | 10144 | | - self, arch: Optional['architecture.Architecture'], buffer: 'databuffer.DataBuffer', | 10145 | | - allow_short_strings: bool = False | 10146 | | - ) -> Tuple[Optional[str], Optional[StringType]]: | | 10143 | + def stringify_unicode_data(self, arch: Optional['architecture.Architecture'], buffer: 'databuffer.DataBuffer', allow_short_strings: bool = False) -> Tuple[Optional[str], Optional[StringType]]: | | 10144 | + """ | | 10145 | + ``stringify_unicode_data`` converts a buffer of unicode data into a string representation. | | 10146 | + :param arch: The architecture to use for stringification, or None to use the current architecture of the BinaryView | | 10147 | + :param buffer: The DataBuffer containing the unicode data to stringify | | 10148 | + :param allow_short_strings: If True, allows short strings to be returned, otherwise only long strings are returned | | 10149 | + :return: A tuple containing the string representation and its type, or (None, None) if the stringification fails | | 10150 | + :rtype: Tuple[Optional[str], Optional[StringType]] | | 10151 | + """ | | 10152 | + if not isinstance(buffer, databuffer.DataBuffer): | | 10153 | + raise TypeError("buffer must be an instance of databuffer.DataBuffer") | 10147 | 10154 | string = ctypes.c_char_p() | 10148 | 10155 | string_type = ctypes.c_int() | 10149 | 10156 | if arch is not None: | 10150 | 10157 | arch = arch.handle | 10151 | | - if not core.BNStringifyUnicodeData( | 10152 | | - self.handle, arch, buffer.handle, allow_short_strings, ctypes.byref(string), ctypes.byref(string_type)): | | 10158 | + if not core.BNStringifyUnicodeData(self.handle, arch, buffer.handle, allow_short_strings, ctypes.byref(string), ctypes.byref(string_type)): | 10153 | 10159 | return None, None | 10154 | | - result = string.value | 10155 | | - core.BNFreeString(string) | | 10160 | + result = string.value.decode('utf-8') | | 10161 | + core.free_string(string) | 10156 | 10162 | return result, StringType(string_type.value) | 10157 | 10163 |
| 10158 | 10164 | class BinaryReader: | |
|