unicode module¶
Function |
Description |
|---|---|
Escapes a string for display, passing through any text that decodes to a codepoint in one of the… |
|
Width of a string in character cells, following Unicode Standard Annex #11 (East Asian Width). |
escape_unicode_string¶
- escape_unicode_string(data: str | bytes | bytearray, view: BinaryView | None = None) str[source]¶
Escapes a string for display, passing through any text that decodes to a codepoint in one of the enabled Unicode blocks as unaltered UTF-8.
Which blocks are enabled is controlled by the
analysis.unicode.blockssetting, resolved againstviewwhen one is given. Passthrough additionally requiresanalysis.unicode.utf8to be enabled. Everything else is escaped, including bytes belonging to a truncated or otherwise invalid encoding, sodataneed not be valid UTF-8.This is the escaping used when rendering string contents in HLIL, Pseudo C and Pseudo Rust.
- Parameters:
data (str | bytes | bytearray) – string or raw bytes to escape
view (BinaryView | None) – view whose settings select the enabled blocks, or None to use the global settings
- Returns:
the escaped string
- Example:
>>> Settings().set_string_list("analysis.unicode.blocks", ["Hiragana"], bv) True >>> escape_unicode_string("Unicode: \u3053\u3093\u306b\u3061\u306f", bv) 'Unicode: こんにちは' >>> escape_unicode_string(b"\xff\xfe", bv) '\\xff\\xfe'
- Return type:
unicode_display_width¶
- unicode_display_width(text: str) int[source]¶
Width of a string in character cells, following Unicode Standard Annex #11 (East Asian Width).
Wide and fullwidth codepoints, such as CJK ideographs and kana, occupy two cells; combining marks and other zero width codepoints occupy none; everything else occupies one.
Binary Ninja renders text on a fixed character cell grid, so this, rather than a character count, is the measurement that
InstructionTextToken.widthis expressed in.