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

Method compareString

src/function_context.py:161–189  ·  view source on GitHub ↗

Compare the strings 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 point sco

(src_ctx, bin_ctx)

Source from the content-addressed store, hash-verified

159
160 @staticmethod
161 def compareString(src_ctx, bin_ctx):
162 """Compare the strings of both contexts and returns the matching score.
163
164 Args:
165 src_ctx (ComparableContext): context representing the source function
166 bin_ctx (ComparableContext): context representing the binary function
167
168 Return value
169 floating point score for the strings comparison
170 """
171 score = 0
172 # start with a bonus score in case the string is contained in the source function's name
173 try:
174 score += STRING_NAME_SCORE * len(list(filter(lambda s: s in src_ctx.name, bin_ctx.strings)))
175 except UnicodeDecodeError:
176 pass
177 # now actually match the strings (intersection and symmetric difference)
178 for string in src_ctx.strings & bin_ctx.strings:
179 score += len(string) * STRING_MATCH_SCORE
180 # duplicate the bonus in this case
181 if string in src_ctx.name:
182 score += STRING_NAME_SCORE
183 # deduce points for strings in the symmetric difference
184 for string in src_ctx.strings.symmetric_difference(bin_ctx.strings):
185 score -= len(string) * STRING_MISMATCH_SCORE
186 # give a boost for a perfect match
187 if len(src_ctx.strings) > 0 and src_ctx.strings == bin_ctx.strings:
188 score += ARTIFACT_MATCH_SCORE
189 return score
190
191 @staticmethod
192 def compareCalls(src_ctx, bin_ctx):

Callers 2

compareMethod · 0.80
compareMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected