GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix busted stringify_unicode_data python API. · Vector35/binaryninja-api@77f007b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • binaryview.cpp
  • python
    • binaryview.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎binaryview.cpp‎

Copy file name to clipboardExpand all lines: binaryview.cpp
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5530,13 +5530,11 @@ void BinaryView::SetUserGlobalPointerValue(const Confidence<RegisterValue>& valu
55305530
}
55315531

55325532

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)
55355534
{
55365535
char* str = nullptr;
55375536
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))
55405538
return nullopt;
55415539

55425540
string result(str);
Collapse file

‎python/binaryview.py‎

Copy file name to clipboardExpand all lines: python/binaryview.py
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10140,19 +10140,25 @@ def memory_map(self):
1014010140
"""
1014110141
return MemoryMap(handle=self.handle)
1014210142

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")
1014710154
string = ctypes.c_char_p()
1014810155
string_type = ctypes.c_int()
1014910156
if arch is not None:
1015010157
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)):
1015310159
return None, None
10154-
result = string.value
10155-
core.BNFreeString(string)
10160+
result = string.value.decode('utf-8')
10161+
core.free_string(string)
1015610162
return result, StringType(string_type.value)
1015710163

1015810164
class BinaryReader:

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.