MCPcopy Create free account
hub / github.com/CheckPointSW/Karta / compareConsts

Method compareConsts

src/function_context.py:136–158  ·  view source on GitHub ↗

Compare the numerical constants of both contexts and returns the matching score. Args: src_ctx (ComparableContext): context representing the source function bin_ctx (ComparableContext): context representing the binary function Return value floati

(src_ctx, bin_ctx)

Source from the content-addressed store, hash-verified

134
135 @staticmethod
136 def compareConsts(src_ctx, bin_ctx):
137 """Compare the numerical constants of both contexts and returns the matching score.
138
139 Args:
140 src_ctx (ComparableContext): context representing the source function
141 bin_ctx (ComparableContext): context representing the binary function
142
143 Return value
144 floating point score for the constants comparison
145 """
146 score = 0
147 # earn points by ranking the consts in the intersection
148 for const in src_ctx.consts & set(bin_ctx.consts):
149 score += src_ctx._const_ranks[const]
150 # deduce points by ranking the consts in the symmetric difference
151 for const in src_ctx.consts - set(bin_ctx.consts):
152 score -= src_ctx._const_ranks[const]
153 for const in bin_ctx.consts - set(src_ctx.consts):
154 score -= bin_ctx._const_ranks[const]
155 # give a boost for a perfect match
156 if len(src_ctx.consts) > 0 and src_ctx.consts == bin_ctx.consts:
157 score += ARTIFACT_MATCH_SCORE
158 return score
159
160 @staticmethod
161 def compareString(src_ctx, bin_ctx):

Callers 2

compareMethod · 0.80
compareMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected