Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libr/core/cconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -4569,6 +4569,7 @@ R_API int r_core_config_init(RCore *core) {
SETCB ("scr.color.grep", "false", &cb_scr_color_grep, "enable colors when using ~grep");
SETB ("scr.color.pipe", "false", "enable colors when using pipes");
SETB ("scr.color.ops", "true", "colorize numbers and registers in opcodes");
SETB ("scr.color.ops.unique", "false", "use unique colors for each immediate value");
SETCB ("scr.color.ophex", "false", &cb_scr_color_ophex, "colorize in hexdump depending on opcode type (px)");
SETB ("scr.color.args", "true", "colorize arguments and variables of functions");
SETB ("scr.color.bytes", "true", "colorize bytes that represent the opcodes of the instruction");
Expand Down
1 change: 1 addition & 0 deletions libr/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ static RDisasmState *ds_init(RCore *core) {
ds->show_color_bytes = r_config_get_i (core->config, "scr.color.bytes");
ds->show_color_args = r_config_get_i (core->config, "scr.color.args");
ds->colorop = r_config_get_b (core->config, "scr.color.ops");
core->print->unique_colors = r_config_get_b (core->config, "scr.color.ops.unique");
ds->show_utf8 = r_config_get_i (core->config, "scr.utf8");
ds->acase = r_config_get_b (core->config, "asm.ucase");
ds->capitalize = r_config_get_b (core->config, "asm.capitalize");
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_util/r_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ typedef struct r_print_t {
int cols;
int flags;
bool use_comments;
bool unique_colors;
int addrmod;
int col;
int stride;
Expand Down
26 changes: 26 additions & 0 deletions libr/util/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,29 @@ static bool is_flag(const char *p) {
return len > 3;
}

// Helper function to generate unique color for immediate values
static const char* get_unique_imm_color(ut64 value) {
// Define a palette of visually distinct colors for immediates
static const char *color_palette[] = {
Color_BYELLOW, // Bright Yellow
Color_BCYAN, // Bright Cyan
Color_BMAGENTA, // Bright Magenta
Color_BGREEN, // Bright Green
Color_BRED, // Bright Red
Color_BBLUE, // Bright Blue
Color_YELLOW, // Yellow
Color_CYAN, // Cyan
Color_MAGENTA, // Magenta
Color_BLUE, // Blue
};

// Hash the value to get a consistent color index
const size_t palette_size = sizeof(color_palette) / sizeof(color_palette[0]);
size_t color_idx = value % palette_size;

return color_palette[color_idx];
}

R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr) {
bool expect_reg = true;
int i, j, k, is_mod, is_float = 0, is_arg = 0;
Expand Down Expand Up @@ -2360,6 +2383,9 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con
const char *name = print->offname (print->user, n)? color_flag: NULL;
if (name) {
num2 = name;
} else if (print->unique_colors) {
// Use unique color for each immediate value
num2 = get_unique_imm_color (n);
}
const size_t nlen = strlen (num2);
if (nlen + j >= sizeof (o)) {
Expand Down
Loading