Loading...
Searching...
No Matches
BinaryNinja::Unicode Namespace Reference

Functions

std::string UTF16ToUTF8 (const uint8_t *utf16, const size_t len)
std::string UTF32ToUTF8 (const uint8_t *utf32)
bool GetBlockRange (const std::string &name, std::pair< uint32_t, uint32_t > &range)
std::vector< std::vector< std::pair< uint32_t, uint32_t > > > GetBlocksForNames (const std::vector< std::string > &names)
std::vector< std::string > GetBlockNames ()
std::map< std::string, std::pair< uint32_t, uint32_t > > GetBlockRanges ()
std::string GetUTF8String (const std::vector< std::vector< std::pair< uint32_t, uint32_t > > > &unicodeBlocks, const uint8_t *data, const size_t offset, const size_t dataLen)
std::string ToEscapedString (const std::vector< std::vector< std::pair< uint32_t, uint32_t > > > &unicodeBlocks, bool utf8Enabled, const void *data, const size_t dataLen)
std::string ToEscapedString (BinaryView *view, const void *data, size_t dataLen)
 Escape a string for display using the Unicode blocks enabled for the given view.
std::string ToEscapedString (BinaryView *view, std::string_view str)
 Escape a string for display using the Unicode blocks enabled for the given view.
size_t GetDisplayWidth (const std::string &str)
 Width of a string in character cells, following Unicode Standard Annex #11 (East Asian Width).
size_t GetNextGraphemeClusterBoundary (const std::string &str, size_t offset)
 Byte offset of the grapheme cluster boundary following the one at offset, which is to say the end of the cluster that starts there.

Function Documentation

◆ UTF16ToUTF8()

std::string BinaryNinja::Unicode::UTF16ToUTF8 ( const uint8_t * utf16,
const size_t len )

◆ UTF32ToUTF8()

std::string BinaryNinja::Unicode::UTF32ToUTF8 ( const uint8_t * utf32)

◆ GetBlockRange()

bool BinaryNinja::Unicode::GetBlockRange ( const std::string & name,
std::pair< uint32_t, uint32_t > & range )

◆ GetBlocksForNames()

std::vector< std::vector< std::pair< uint32_t, uint32_t > > > BinaryNinja::Unicode::GetBlocksForNames ( const std::vector< std::string > & names)

◆ GetBlockNames()

std::vector< std::string > BinaryNinja::Unicode::GetBlockNames ( )

◆ GetBlockRanges()

std::map< std::string, std::pair< uint32_t, uint32_t > > BinaryNinja::Unicode::GetBlockRanges ( )

◆ GetUTF8String()

std::string BinaryNinja::Unicode::GetUTF8String ( const std::vector< std::vector< std::pair< uint32_t, uint32_t > > > & unicodeBlocks,
const uint8_t * data,
const size_t offset,
const size_t dataLen )

◆ ToEscapedString() [1/3]

std::string BinaryNinja::Unicode::ToEscapedString ( const std::vector< std::vector< std::pair< uint32_t, uint32_t > > > & unicodeBlocks,
bool utf8Enabled,
const void * data,
const size_t dataLen )

◆ ToEscapedString() [2/3]

std::string BinaryNinja::Unicode::ToEscapedString ( BinaryView * view,
const void * data,
size_t dataLen )

Escape a string for display using the Unicode blocks enabled for the given view.

Text that decodes to a codepoint in one of the enabled Unicode blocks is passed through as unaltered UTF8. Everything else is escaped, including bytes that are part of a truncated or otherwise invalid encoding, so the input does not need to be valid UTF8.

This is the escaping renderers should use when emitting string contents, such as the value of a derived string produced by a StringRecognizer.

Parameters
viewView whose settings determine the enabled blocks, or nullptr for global settings
dataBytes to escape
dataLenLength of data in bytes
Returns
The escaped string

◆ ToEscapedString() [3/3]

std::string BinaryNinja::Unicode::ToEscapedString ( BinaryView * view,
std::string_view str )

Escape a string for display using the Unicode blocks enabled for the given view.

Parameters
viewView whose settings determine the enabled blocks, or nullptr for global settings
strString to escape, which need not be valid UTF8
Returns
The escaped string

◆ GetDisplayWidth()

size_t BinaryNinja::Unicode::GetDisplayWidth ( const std::string & str)

Width of a string in character cells, following Unicode Standard Annex #11 (East Asian Width).

Wide and fullwidth code points, such as CJK ideographs and kana, occupy two cells; combining marks and other zero-width code points occupy none; everything else occupies one. Text that is not valid UTF8 is measured as one cell per byte.

Binary Ninja renders text on a fixed character cell grid, so this, rather than a byte or code point count, is the measurement that InstructionTextToken widths are expressed in.

Parameters
strString to measure
Returns
Width of the string in character cells

◆ GetNextGraphemeClusterBoundary()

size_t BinaryNinja::Unicode::GetNextGraphemeClusterBoundary ( const std::string & str,
size_t offset )

Byte offset of the grapheme cluster boundary following the one at offset, which is to say the end of the cluster that starts there.

It is the caller's responsibility to pass a boundary: offset must be zero, the length of the string, or a value this returned. Only the cluster at offset is examined, so walking a string a cluster at a time this way costs no more than the clusters it visits.

for (size_t start = 0, end; start < str.size(); start = end)
{
// The cluster is the byte range [start, end)
}
Parameters
strString the offset refers to, which need not be valid UTF8
offsetByte offset of a cluster boundary
Returns
The offset of the next cluster boundary, or the length of the string if there is none