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

Method compareCalls

src/function_context.py:192–216  ·  view source on GitHub ↗

Compare the function calls 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 floating po

(src_ctx, bin_ctx)

Source from the content-addressed store, hash-verified

190
191 @staticmethod
192 def compareCalls(src_ctx, bin_ctx):
193 """Compare the function calls of both contexts and returns the matching score.
194
195 Args:
196 src_ctx (ComparableContext): context representing the source function
197 bin_ctx (ComparableContext): context representing the binary function
198
199 Return value
200 floating point score for the calls comparison
201 """
202 score = -1 * abs(len(src_ctx.calls) - len(bin_ctx.calls)) * CALL_COUNT_SCORE
203 # penalty for missing matched calls
204 src_matched = [x for x in src_ctx.calls if x.matched()]
205 bin_matched = [x for x in bin_ctx.calls if x.matched()]
206 mismatching = []
207 mismatching += [x for x in src_matched if x.match not in bin_ctx.calls]
208 mismatching += [x for x in bin_matched if x.match not in src_ctx.calls]
209 matching = [x for x in src_matched if x.match in bin_ctx.calls]
210 # the penalty is halved because we the list will most probably contain duplicates
211 score -= CALL_COUNT_SCORE * len(mismatching) * 1.0 / 2
212 score += MATCHED_CALL_SCORE * len(matching)
213 # give a boost for a perfect match
214 if len(mismatching) == 0 and len(src_ctx.calls) > 0 and len(src_ctx.calls) == len(bin_ctx.calls):
215 score += ARTIFACT_MATCH_SCORE
216 return score
217
218 @staticmethod
219 def compareExternals(src_ctx, bin_ctx):

Callers 2

compareMethod · 0.80
compareMethod · 0.80

Calls 1

matchedMethod · 0.45

Tested by

no test coverage detected