commit
3a52c8cbdd
|
@ -17,7 +17,7 @@ by UltrafunkAmsterdam (https://github.com/ultrafunkamsterdam)
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
__version__ = "3.4.2"
|
__version__ = "3.4.4"
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
@ -470,18 +470,18 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
||||||
{
|
{
|
||||||
"source": """
|
"source": """
|
||||||
|
|
||||||
Object.defineProperty(window, 'navigator', {
|
Object.defineProperty(window, "navigator", {
|
||||||
|
Object.defineProperty(window, "navigator", {
|
||||||
value: new Proxy(navigator, {
|
value: new Proxy(navigator, {
|
||||||
has: (target, key) => (key === 'webdriver' ? false : key in target),
|
has: (target, key) => (key === "webdriver" ? false : key in target),
|
||||||
get: (target, key) =>
|
get: (target, key) =>
|
||||||
key === 'webdriver' ?
|
key === "webdriver"
|
||||||
false :
|
? false
|
||||||
typeof target[key] === 'function' ?
|
: typeof target[key] === "function"
|
||||||
target[key].bind(target) :
|
? target[key].bind(target)
|
||||||
target[key]
|
: target[key],
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
"""
|
"""
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -94,9 +94,7 @@ class Patcher(object):
|
||||||
self.version_full = None
|
self.version_full = None
|
||||||
|
|
||||||
def auto(self, executable_path=None, force=False, version_main=None):
|
def auto(self, executable_path=None, force=False, version_main=None):
|
||||||
|
|
||||||
if executable_path:
|
if executable_path:
|
||||||
|
|
||||||
self.executable_path = executable_path
|
self.executable_path = executable_path
|
||||||
self._custom_exe_path = True
|
self._custom_exe_path = True
|
||||||
|
|
||||||
|
@ -207,25 +205,24 @@ class Patcher(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def gen_random_cdc():
|
def gen_random_cdc():
|
||||||
# make cdc_variables without underscores
|
|
||||||
cdc = random.choices(string.ascii_letters, k=27)
|
cdc = random.choices(string.ascii_letters, k=27)
|
||||||
|
|
||||||
# cdc[-6:-4] = map(str.upper, cdc[-6:-4])
|
|
||||||
# cdc[2] = cdc[0]
|
|
||||||
# cdc[3] = "_"
|
|
||||||
return "".join(cdc).encode()
|
return "".join(cdc).encode()
|
||||||
|
|
||||||
def is_binary_patched(self, executable_path=None):
|
def is_binary_patched(self, executable_path=None):
|
||||||
executable_path = executable_path or self.executable_path
|
executable_path = executable_path or self.executable_path
|
||||||
|
try:
|
||||||
with io.open(executable_path, "rb") as fh:
|
with io.open(executable_path, "rb") as fh:
|
||||||
return fh.read().find(b"undetected chromedriver") != -1
|
return fh.read().find(b"undetected chromedriver") != -1
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
def patch_exe(self):
|
def patch_exe(self):
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
logger.info("patching driver executable %s" % self.executable_path)
|
logger.info("patching driver executable %s" % self.executable_path)
|
||||||
with io.open(self.executable_path, "r+b") as fh:
|
with io.open(self.executable_path, "r+b") as fh:
|
||||||
content = fh.read()
|
content = fh.read()
|
||||||
match_injected_codeblock = re.search(rb"{window.*;}", content)
|
# match_injected_codeblock = re.search(rb"{window.*;}", content)
|
||||||
|
match_injected_codeblock = re.search(rb"\{window\.cdc.*?;\}", content)
|
||||||
if match_injected_codeblock:
|
if match_injected_codeblock:
|
||||||
target_bytes = match_injected_codeblock[0]
|
target_bytes = match_injected_codeblock[0]
|
||||||
new_target_bytes = (
|
new_target_bytes = (
|
||||||
|
@ -245,18 +242,6 @@ class Patcher(object):
|
||||||
)
|
)
|
||||||
fh.seek(0)
|
fh.seek(0)
|
||||||
fh.write(new_content)
|
fh.write(new_content)
|
||||||
|
|
||||||
# we just keep the cdc variables as they can't be injected anyways so no harm
|
|
||||||
# keeping for reference
|
|
||||||
# fh.seek(0)
|
|
||||||
# for line in iter( lambda: fh.readline() , b"" ):
|
|
||||||
# if b'cdc_' in line:
|
|
||||||
# fh.seek( -len( line ) , 1 )
|
|
||||||
# new_line = re.sub( b"cdc_.{22}_" , self.gen_random_cdc() , line )
|
|
||||||
# logger.debug( 'replaced %s\n\twith:%s' % (line , new_line) )
|
|
||||||
# fh.write( new_line )
|
|
||||||
else:
|
|
||||||
logger.info("%s seems already patched ?!?!" % self.executable_path)
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"patching took us {:.2f} seconds".format(time.perf_counter() - start)
|
"patching took us {:.2f} seconds".format(time.perf_counter() - start)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue