| 414 | return False |
| 415 | |
| 416 | def patch_exe(self): |
| 417 | start = time.perf_counter() |
| 418 | logger.info("patching driver executable %s" % self.executable_path) |
| 419 | with io.open(self.executable_path, "r+b") as fh: |
| 420 | content = fh.read() |
| 421 | # match_injected_codeblock = re.search(rb"{window.*;}", content) |
| 422 | match_injected_codeblock = re.search(rb"\{window\.cdc.*?;\}", content) |
| 423 | if match_injected_codeblock: |
| 424 | target_bytes = match_injected_codeblock[0] |
| 425 | new_target_bytes = ( |
| 426 | b'{console.log("undetected chromedriver 1337!")}'.ljust( |
| 427 | len(target_bytes), b" " |
| 428 | ) |
| 429 | ) |
| 430 | new_content = content.replace(target_bytes, new_target_bytes) |
| 431 | if new_content == content: |
| 432 | logger.warning( |
| 433 | "something went wrong patching the driver binary. could not find injection code block" |
| 434 | ) |
| 435 | else: |
| 436 | logger.debug( |
| 437 | "found block:\n%s\nreplacing with:\n%s" |
| 438 | % (target_bytes, new_target_bytes) |
| 439 | ) |
| 440 | fh.seek(0) |
| 441 | fh.write(new_content) |
| 442 | logger.debug( |
| 443 | "patching took us {:.2f} seconds".format(time.perf_counter() - start) |
| 444 | ) |
| 445 | |
| 446 | def __repr__(self): |
| 447 | return "{0:s}({1:s})".format( |