Skip to content

Commit

Permalink
Add the Hu CFGED algorithm for eval
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Feb 8, 2024
1 parent 4310ccb commit 1e7e4f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions sailreval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion sailreval/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion sailreval/metrics/ged_to_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 1e7e4f3

Please sign in to comment.