pretty_print ¤
Classes:
-
Property–A (property name, property value) pair
Functions:
-
int_to_string–Converts an integer value to string.
-
int_pair_to_string–Converts an integer pair to a string pair.
-
from_properties–When you have (property name, property value) pairs
-
nlines_to_range–When you want to get nlines of output around a certain interesting line, returns
-
format_source–Format source code.
Attributes:
-
max_decimal_number– -
config_property_name_color– -
config_property_value_color– -
config_property_title_color–
max_decimal_number module-attribute ¤
max_decimal_number = add_param(
"max-decimal-number",
9,
"show all numbers greater than this in hex",
param_class=PARAM_ZUINTEGER_UNLIMITED,
help_docstring="\nFor negative numbers, their absolute value is used.\n\nSet the parameter to 'unlimited' if you want all values in decimal.\nSpecially, set the parameter to zero if you want all values in hex.\n\nThe assembly instruction operands come from capstone, and are thus\nnot controlled by this setting. For consistency with them, leave\nthis setting at 9 (the default).\n",
)
config_property_name_color module-attribute ¤
config_property_name_color = add_color_param(
"prop-name-color",
"bold",
"color used to highlight the name in name-value pairs",
help_docstring="\nUsed heavily in mallocng commands.\n",
)
config_property_value_color module-attribute ¤
config_property_value_color = add_color_param(
"prop-value-color",
"yellow",
"color used to highlight the value in name-value pairs",
help_docstring="\nUsed heavily in mallocng commands.\n",
)
config_property_title_color module-attribute ¤
config_property_title_color = add_color_param(
"prop-title-color",
"green",
"color used to highlight the title of name-value pair groups",
help_docstring="\nUsed heavily in mallocng commands.\n",
)
Property dataclass ¤
Property(
name: str,
value: Any,
alt_value: Any = None,
extra: str | list[str] = "",
is_addr: bool = False,
use_hex: bool = True,
name_color_func: Callable[[str], str] | None = None,
value_color_func: Callable[[str], str] | None = None,
)
A (property name, property value) pair with optional extra information.
Used by from_properties().
Attributes:
-
name(str) – -
value(Any) – -
alt_value(Any) – -
extra(str | list[str]) – -
is_addr(bool) – -
use_hex(bool) – -
name_color_func(Callable[[str], str] | None) – -
value_color_func(Callable[[str], str] | None) –
int_to_string ¤
Converts an integer value to string.
Decides whether to format it in decimal or hex depending on the max-decimal-number config.
int_pair_to_string ¤
Converts an integer pair to a string pair.
Decides whether to format them in decimal or hex depending on the max-decimal-number config.
If either value should be hex, both are hex.
from_properties ¤
from_properties(
title: str,
properties: list[Property],
*,
preamble: str = "",
value_offset: int = 14,
extra_offset: int = 16,
title_color_func: Callable[[str], str] | None = None,
name_color_func: Callable[[str], str] | None = None,
value_color_func: Callable[[str], str] | None = None,
indent_size: int = 2,
) -> str
When you have (property name, property value) pairs that you want to print, each on a new line.
A common usecase is printing a struct.
Example
general start: 0x7ffff7ff6040 user start: 0x7ffff7ff6040 aka p end: 0x7ffff7ff606c start + stride - 4 stride: 0x30 distance between adjacent slots user size: 0x20 aka "nominal size", n slack: 0x0 (0x0) slot's unused memory / 0x10
Parameters:
-
title(str) –The title of this property group. An empty string may be provided for a titleless group.
-
properties(list[Property]) –The list of properties to format.
-
preamble(str, default:'') –A string that will be printed between the title and the properties, may be used to denote the address of an object like e.g.
@ 0x408000 - 0x408fe0 -
value_offset(int, default:14) –The number of characters from the start of the name of a property to the start of its value.
-
extra_offset(int, default:16) –The number of characters from the start of the value of a property to the start of its extra text.
-
title_color_func(Callable[[str], str] | None, default:None) –The function to use to color the title.
-
name_color_func(Callable[[str], str] | None, default:None) –The function to use to color names.
-
value_color_func(Callable[[str], str] | None, default:None) –The function to use to color values. This function isn't applied to is_addr=True properties.
-
indent_size(int, default:2) –The indentation to use i.e. the offset from the title to the names.
nlines_to_range ¤
When you want to get nlines of output around a certain interesting line, returns the range to use.
end - start will not be == nlines only if nlines > total.
The current line may not necessarily be centered in the range, if decentering it gets end - start closer to nlines.
Parameters:
-
nlines(int) –The exact amount of lines you want.
-
current(int) –The index of the interesting line (e.g. where PC is in the source context)
-
total(int) –How many lines total you actually have.
Returns:
-
tuple[int, int]–A tuple giving the range of indecies to use. The format is [start, end).
format_source ¤
Format source code.
Use correct tab size, add the code prefix (►), add line numbers, align properly.
Parameters:
-
source(list[str]) –Already highlighted source code. List of lines.
-
nlines(int) –The amount of lines we want back.
-
interesting_line(int) –The line around which to center the output.