From 1e7e4f346aad08966eee7ea8d71b573993b17623 Mon Sep 17 00:00:00 2001 From: mahaloz Date: Thu, 8 Feb 2024 08:50:27 -0700 Subject: [PATCH] Add the Hu CFGED algorithm for eval --- sailreval/__init__.py | 1 + sailreval/metrics/__init__.py | 3 ++- sailreval/metrics/ged_to_source.py | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sailreval/__init__.py b/sailreval/__init__.py index 052e87e..2ff8b7d 100755 --- a/sailreval/__init__.py +++ b/sailreval/__init__.py @@ -22,6 +22,7 @@ class SAILR_METRICS: GED_MAX = "ged_max" GED_EXACT = "ged_exact" CFGED = "cfged" + HU_CFGED = "hu_cfged" GRAPH_SIZE = "graph_size" BLOCK_COUNT = "block_count" DEC_TIME = "dec_time" diff --git a/sailreval/metrics/__init__.py b/sailreval/metrics/__init__.py index c57f719..519e374 100755 --- a/sailreval/metrics/__init__.py +++ b/sailreval/metrics/__init__.py @@ -7,7 +7,7 @@ from .nesting_count import count_nesting_ifs from .duplication import count_func_calls from .total_bools import count_if_bools -from .ged_to_source import ged_upperbound_score, cfg_edit_distance, ged_max_score, block_count, ged_exact_score, graph_size +from .ged_to_source import ged_upperbound_score, cfg_edit_distance, ged_max_score, block_count, ged_exact_score, graph_size, hu_cfged_score from .post_metrics import norm_cfged, zero_cfged, funcs_w_goto, goto_func_cfged from sailreval import SAILR_METRICS @@ -36,6 +36,7 @@ SAILR_METRICS.GED_UPPERBOUND: ged_upperbound_score, SAILR_METRICS.GED_MAX: ged_max_score, SAILR_METRICS.GED_EXACT: ged_exact_score, + SAILR_METRICS.HU_CFGED: hu_cfged_score, # Important Metrics SAILR_METRICS.GOTO_COUNT: count_total_gotos, diff --git a/sailreval/metrics/ged_to_source.py b/sailreval/metrics/ged_to_source.py index b18446f..ac8a7a1 100644 --- a/sailreval/metrics/ged_to_source.py +++ b/sailreval/metrics/ged_to_source.py @@ -3,7 +3,7 @@ from typing import Dict from pyjoern.mapping import correct_decompiler_mappings, read_line_maps -from cfgutils.similarity import ged_max, ged_upperbound, ged_exact +from cfgutils.similarity import ged_max, ged_upperbound, ged_exact, hu_cfged from cfgutils.similarity import cfg_edit_distance as _cfg_edit_distance import networkx as nx @@ -160,3 +160,20 @@ def block_count( return None return len(dec_cfg.nodes) + + +# +# More special case GED algorithms +# + +def hu_cfged_score( + func_name, client, source_cfgs: Dict[str, nx.DiGraph] = None, dec_cfgs: Dict[str, nx.DiGraph] = None, + decompiler=None, binary_path=None, **kwargs +): + if decompiler == "source": + return float(0) + source_cfg, dec_cfg = _verify_has_valid_graphs(func_name, client, source_cfgs, dec_cfgs, decompiler, binary_path) + if source_cfg is None or dec_cfg is None: + return None + + return hu_cfged(dec_cfg, source_cfg)