From 7dfa4bd3965d86ca83ed70a6524c2ac6746271c3 Mon Sep 17 00:00:00 2001 From: Fish Date: Wed, 1 Nov 2023 19:07:56 -0700 Subject: [PATCH] Pseudocode: Give library function calls a different color. (#1111) --- angrmanagement/config/color_schemes.py | 3 +++ angrmanagement/config/config_manager.py | 1 + angrmanagement/ui/widgets/qccode_highlighter.py | 11 ++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/angrmanagement/config/color_schemes.py b/angrmanagement/config/color_schemes.py index 8cf6f3cdf..8a4331609 100644 --- a/angrmanagement/config/color_schemes.py +++ b/angrmanagement/config/color_schemes.py @@ -81,6 +81,7 @@ "feature_map_string_color": QColor(0x00, 0xF0, 0x80), "pseudocode_comment_color": QColor(0x00, 0x80, 0x00, 0xFF), "pseudocode_function_color": QColor(0x00, 0x00, 0xFF, 0xFF), + "pseudocode_library_function_color": QColor(0xFF, 0x00, 0xFF), "pseudocode_quotation_color": QColor(0x00, 0x80, 0x00, 0xFF), "pseudocode_keyword_color": QColor(0x00, 0x00, 0x80, 0xFF), "pseudocode_types_color": QColor(0x10, 0x78, 0x96), @@ -179,6 +180,7 @@ "feature_map_string_color": QColor(0x00, 0xF0, 0x80), "pseudocode_comment_color": QColor(0x00, 0x80, 0x00, 0xFF), "pseudocode_function_color": QColor(0x00, 0xAA, 0xFF), + "pseudocode_library_function_color": QColor(0xAA, 0x00, 0xFF), "pseudocode_quotation_color": QColor(0x00, 0x80, 0x00, 0xFF), "pseudocode_keyword_color": QColor(0xF1, 0xA7, 0xFA), "pseudocode_types_color": QColor(0x00, 0xFF, 0xFF, 0xFF), @@ -272,6 +274,7 @@ "pseudocode_comment_color": QColor(0x62, 0x72, 0xA4), "pseudocode_comment_weight": QFont.Weight.Normal, "pseudocode_function_color": QColor(0x50, 0xFA, 0x7B), + "pseudocode_library_function_color": QColor(0x8B, 0xE9, 0xFD), "pseudocode_quotation_color": QColor(0xF1, 0xFA, 0x8C), "pseudocode_keyword_color": QColor(0xFF, 0x79, 0xC6), "pseudocode_types_color": QColor(0x8B, 0xE9, 0xFD), diff --git a/angrmanagement/config/config_manager.py b/angrmanagement/config/config_manager.py index 857ac764d..2a335131f 100644 --- a/angrmanagement/config/config_manager.py +++ b/angrmanagement/config/config_manager.py @@ -227,6 +227,7 @@ def bool_serializer(config_option, value: bool) -> str: CE("pseudocode_comment_weight", QFont.Weight, QFont.Weight.Bold), CE("pseudocode_comment_style", QFont.Style, QFont.Style.StyleNormal), CE("pseudocode_function_color", QColor, QColor(0x00, 0x00, 0xFF, 0xFF)), + CE("pseudocode_library_function_color", QColor, QColor(0xFF, 0x00, 0xFF)), CE("pseudocode_function_weight", QFont.Weight, QFont.Weight.Bold), CE("pseudocode_function_style", QFont.Style, QFont.Style.StyleNormal), CE("pseudocode_quotation_color", QColor, QColor(0x00, 0x80, 0x00, 0xFF)), diff --git a/angrmanagement/ui/widgets/qccode_highlighter.py b/angrmanagement/ui/widgets/qccode_highlighter.py index 79df00f3b..730f0302e 100644 --- a/angrmanagement/ui/widgets/qccode_highlighter.py +++ b/angrmanagement/ui/widgets/qccode_highlighter.py @@ -47,6 +47,10 @@ def reset_formats(): Conf.pseudocode_function_color, Conf.pseudocode_function_weight, Conf.pseudocode_function_style ) + FORMATS["library_function"] = create_char_format( + Conf.pseudocode_library_function_color, Conf.pseudocode_function_weight, Conf.pseudocode_function_style + ) + FORMATS["comment"] = create_char_format( Conf.pseudocode_comment_color, Conf.pseudocode_comment_weight, Conf.pseudocode_comment_style ) @@ -70,7 +74,12 @@ def _format_node(obj): """ if isinstance(obj, SimType): return FORMATS["type"] - elif isinstance(obj, (CFunctionCall, CFunction)): + elif isinstance(obj, CFunctionCall): + if obj.callee_func is not None: + if obj.callee_func.is_simprocedure or obj.callee_func.is_plt or obj.callee_func.is_syscall: + return FORMATS["library_function"] + return FORMATS["function"] + elif isinstance(obj, CFunction): return FORMATS["function"] elif isinstance(obj, CLabel): return FORMATS["label"]