Compare the (matched) external 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
(src_ctx, bin_ctx)
| 217 | |
| 218 | @staticmethod |
| 219 | def compareExternals(src_ctx, bin_ctx): |
| 220 | """Compare the (matched) external function calls of both contexts and returns the matching score. |
| 221 | |
| 222 | Args: |
| 223 | src_ctx (ComparableContext): context representing the source function |
| 224 | bin_ctx (ComparableContext): context representing the binary function |
| 225 | |
| 226 | Return value |
| 227 | floating point score for the external calls comparison |
| 228 | """ |
| 229 | # penalty for number of missing external calls |
| 230 | score = -1 * abs(len(src_ctx.externals) - len(bin_ctx.externals)) * EXTERNAL_COUNT_SCORE |
| 231 | for external in [x for x in src_ctx.externals if x.matched()]: |
| 232 | # check for a hit |
| 233 | if external.match in bin_ctx.externals: |
| 234 | if external.name in libc.libc_function_names: |
| 235 | score += LIBC_COMP_FUNC_MATCH_SCORE if external.name in libc.libc_comp_function_names else LIBC_FUNC_MATCH_SCORE |
| 236 | else: |
| 237 | score += EXT_FUNC_MATCH_SCORE |
| 238 | # give a boost for a perfect match |
| 239 | if len(src_ctx.externals) > 0 and len(src_ctx.externals) == len(bin_ctx.externals): |
| 240 | score += ARTIFACT_MATCH_SCORE |
| 241 | return score |
| 242 | |
| 243 | # Technically, BinaryCodeContext is mapped (has an index), and Island don't have an index. |
| 244 | # However this is much easier to implement instead of having a diamond shaped inheritance... |