Remove the given function couple (src index, bin context) from the file's content. Args: bin_ctx (FunctionContext): (binary) context of the removed (binary) function
(self, bin_ctx)
| 294 | floating_representative.disableSources(unused_funcs) |
| 295 | |
| 296 | def remove(self, bin_ctx): |
| 297 | """Remove the given function couple (src index, bin context) from the file's content. |
| 298 | |
| 299 | Args: |
| 300 | bin_ctx (FunctionContext): (binary) context of the removed (binary) function |
| 301 | """ |
| 302 | # check if already removed |
| 303 | if self.located and bin_ctx not in self._bin_functions_ctx: |
| 304 | return |
| 305 | # check the floating file |
| 306 | if not self.located and bin_ctx not in self._engine.floatingBinFunctions(): |
| 307 | return |
| 308 | # only the first "floating" file is the one that does the actions |
| 309 | floating_representative = self._engine.floatingRepresentative() |
| 310 | if not self.located and self != floating_representative: |
| 311 | floating_representative.remove(bin_ctx) |
| 312 | return |
| 313 | # set up the used binary_dictionary |
| 314 | bin_ctxs = self._bin_functions_ctx if self.located else self._engine.floatingBinFunctions() |
| 315 | # locate the inner index |
| 316 | bin_index = bin_ctxs.index(bin_ctx) |
| 317 | # if the file wasn't yet located there is a reason not to simply do: "lower_part = not upper_part" |
| 318 | try: |
| 319 | upper_index = bin_ctxs.index(self._upper_match_ctx) |
| 320 | except ValueError: |
| 321 | self._engine.logger.error(f"Sanity check failed in FileMatch ({self.name}) remove(): upper match ({self._upper_match_ctx.name}) not in bin_ctxs") |
| 322 | raise AssumptionException() |
| 323 | try: |
| 324 | lower_index = bin_ctxs.index(self._lower_match_ctx) |
| 325 | except ValueError: |
| 326 | self._engine.logger.error(f"Sanity check failed in FileMatch ({self.name}) remove(): lower match ({self._lower_match_ctx.name}) not in bin_ctxs") |
| 327 | raise AssumptionException() |
| 328 | upper_part = upper_index < bin_index |
| 329 | lower_part = bin_index < lower_index |
| 330 | # sanity check - more than the upper leftovers |
| 331 | if upper_part and self._upper_leftovers is not None and len(bin_ctxs) - bin_index > self._upper_leftovers: |
| 332 | self._engine.logger.error(f"Sanity check failed on FileMatch ({self.name}) remove(): {bin_index} {len(bin_ctxs)} 0x{bin_ctx.ea:x} {self._upper_leftovers}") |
| 333 | raise AssumptionException() |
| 334 | # sanity check - more than the lower leftovers |
| 335 | elif lower_part and self._lower_leftovers is not None and bin_index + 1 > self._lower_leftovers: |
| 336 | self._engine.logger.error(f"Sanity check failed on FileMatch ({self.name}) remove(): {bin_index} 0x{bin_ctx.ea:x} {self._lower_leftovers}") |
| 337 | raise AssumptionException() |
| 338 | # Now preform the update itself (changes according to the "type" of the file) |
| 339 | if self.located: |
| 340 | if upper_part: |
| 341 | removed_funcs = self._bin_functions_ctx[bin_index:] |
| 342 | self._bin_functions_ctx = self._bin_functions_ctx[:bin_index] |
| 343 | self._upper_leftovers -= len(removed_funcs) |
| 344 | else: |
| 345 | removed_funcs = self._bin_functions_ctx[:bin_index + 1] |
| 346 | self._bin_functions_ctx = self._bin_functions_ctx[bin_index + 1:] |
| 347 | self._lower_leftovers -= len(removed_funcs) |
| 348 | # Now update all of the relevant functions that they are expelled from our file |
| 349 | [x.expel(self) for x in removed_funcs] |
| 350 | # check if we matched all of our binaries |
| 351 | self.checkFinished() |
| 352 | |
| 353 | def match(self, src_index, bin_ctx): |
no test coverage detected