MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / patch_exe

Method patch_exe

seleniumbase/undetected/patcher.py:212–247  ·  view source on GitHub ↗

Patches the ChromeDriver binary

(self)

Source from the content-addressed store, hash-verified

210 return True
211
212 def patch_exe(self):
213 """Patches the ChromeDriver binary"""
214 def gen_js_whitespaces(match):
215 return b"\n" * len(match.group())
216
217 def gen_call_function_js_cache_name(match):
218 rep_len = len(match.group()) - 3
219 ran_len = random.randint(6, rep_len)
220 bb = b"'" + bytes(str().join(random.choices(
221 population=string.ascii_letters, k=ran_len
222 )), 'ascii') + b"';" + (b"\n" * (rep_len - ran_len))
223 return bb
224
225 with io.open(self.executable_path, "r+b") as fh:
226 file_bin = fh.read()
227 file_bin = re.sub(
228 b"window\\.cdc_[a-zA-Z0-9]{22}_"
229 b"(Array|Promise|Symbol|Object|Proxy|JSON|Window) "
230 b"= window\\.(Array|Promise|Symbol|Object|Proxy|JSON|Window);",
231 gen_js_whitespaces,
232 file_bin,
233 )
234 file_bin = re.sub(
235 b"window\\.cdc_[a-zA-Z0-9]{22}_"
236 b"(Array|Promise|Symbol|Object|Proxy|JSON|Window) \\|\\|",
237 gen_js_whitespaces,
238 file_bin,
239 )
240 file_bin = re.sub(
241 b"'\\$cdc_[a-zA-Z0-9]{22}_';",
242 gen_call_function_js_cache_name,
243 file_bin,
244 )
245 fh.seek(0)
246 fh.write(file_bin)
247 return True
248
249 @staticmethod
250 def gen_random_cdc_beta():

Callers 2

autoMethod · 0.95
patchMethod · 0.95

Calls 2

writeMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected