Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"TestCases/chapter15/15.7/15.7.3/15.7.3.1/15.7.3.1-2.js",
null,
"TestCases/chapter15/15.7/15.7.4/15.7.4-1.js",
null,
"TestCases/chapter15/15.9/15.9.4/15.9.4.4/15.9.4.4-0-1.js",
"TestCases/chapter15/15.9/15.9.4/15.9.4.4/15.9.4.4-0-2.js",
null,
"TestCases/chapter15/15.9/15.9.5/15.9.5.43/15.9.5.43-0-1.js",
"TestCases/chapter15/15.9/15.9.5/15.9.5.43/15.9.5.43-0-2.js",
null,
"TestCases/chapter15/15.9/15.9.5/15.9.5.44/15.9.5.44-0-1.js",
"TestCases/chapter15/15.9/15.9.5/15.9.5.44/15.9.5.44-0-2.js",
null,
];
e = js2py.EvalJs()
e.execute(Harness)
STATS = {'not_implemented': 0,
'error': 0,
'passed': 0,
'wrong': 0}
PRINT_ERROR = 1
PRINT_WRONG = 0
def run_test_case(path):
if path is None:
return
#print(path)
with open(path, 'r', encoding='utf8') as f: #{'not_implemented': 128, 'wrong': 148, 'passed': 950, 'error': 4}
test = f.read()
try:
result = e.eval(test)
# Date: 2019-08-05 Python: 3.7
"""
百度登陆参数比较多
这里是密码加密生成器
"""
import js2py
class PingDuoDuoSpider(object):
"""
生成百度登陆密码加密结果
"""
context = js2py.EvalJs() # python中使用js
def __init__(self):
# 初始化
with open("encryp.js", "r", encoding="utf-8") as f:
self.context.execute(f.read())
def make(self, password):
pwd = self.context.test(password)
print(pwd) # 打印加密之后的密码
if __name__ == '__main__':
pdd = PingDuoDuoSpider()
key = input("输入密码")
pdd.make(key)
def decodeSawliveUrl(encryptedHtml):
vars = {}
finalUrl = ""
logger.debug("encrypted iframe is: " + encryptedHtml)
'''
if 'unescape' in encryptedHtml:
target = Decoder.extract("unescape(",");",encryptedHtml)
encryptedHtml = encryptedHtml.replace("unescape("+target+")",target)
'''
if 'document.write(' in encryptedHtml:
target = Decoder.extract("document.write(", ");", encryptedHtml)
encryptedHtml = encryptedHtml.replace("document.write(" + target + ")", target)
import js2py
context = js2py.EvalJs()
##define js context with unescape escape functions, used inside script
context.execute("""escape = function(text){pyimport urllib; return urllib.quote(text)};
unescape = function(text){pyimport urllib; return urllib.unquote(text)};
encodeURI = function(text){pyimport urllib; return urllib.quote(text, safe='~@#$&()*!+=:;,.?/\\'')};
decodeURI = unescape;
encodeURIComponent = function(text){pyimport urllib; return urllib.quote(text, safe='~()*!.\\'')};
decodeURIComponent = unescape;""")
response = context.eval(encryptedHtml)
# response = urllib.unquote_plus(response)
logger.debug("js RESPONSE is: " + str(response))
if '+\'">\'' in response:
vars = Decoder.rExtract('document.write(','+\'">\'',response)
response2 = context.eval(vars.split("+'/'+")[0])
logger.debug("js var content by RESPONSE is: " + str(response2))
response3 = context.eval(vars.split("+'/'+")[1])
logger.debug("js var2 content by RESPONSE is: " + str(response3))
# -*- coding: utf-8 -*-
# __author__ = "zok" 362416272@qq.com
# Date: 2019-05-30 Python: 3.7
import js2py
import requests
import json
class AiCha(object):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
'Referer': 'https://www.ickd.cn/'
}
context = js2py.EvalJs() # python中使用js
def __init__(self, express):
self.express = express # 快递单号
with open("make.js", "r", encoding="utf-8") as f:
self.context.execute(f.read())
def make_tm(self):
mt = self.context.make_tm()
return mt
def make_tk(self, mt):
_str = self.express + str(mt)
tk = self.context.sign(_str)
return tk
"""
innerHTML = re.search(
']*)? id="([^<>]*?)">([^<>]*?)<\/div>',
body,
re.MULTILINE | re.DOTALL
)
innerHTML = innerHTML.group(2).replace("'", r"\'") if innerHTML else ""
js = jsunfuck(jsEnv.format(domain=domain, innerHTML=innerHTML, js=js))
def atob(s):
return base64.b64decode('{}'.format(s)).decode('utf-8')
js2py.disable_pyimport()
context = js2py.EvalJs({'atob': atob})
result = context.eval(js)
except Exception:
logging.error("Error executing Cloudflare IUAM Javascript. {}".format(BUG_REPORT))
raise
try:
float(result)
except Exception:
raise ValueError("Cloudflare IUAM challenge returned unexpected answer. {}".format(BUG_REPORT))
return result
def build_cache():
"""
Get current data from the website http://www.lfd.uci.edu/~gohlke/pythonlibs/
Returns
-------
Dictionary containing package details
"""
data = {}
response = requests.request("GET", MAIN_URL, headers=HEADER)
soup = BeautifulSoup(response.text, features="html.parser")
# We mock out a little javascript environment within which to run Gohlke's obfuscation code
context = js2py.EvalJs()
context.execute(
"""
top = {location: {href: ''}};
location = {href: ''};
function setTimeout(f, t) {
f();
};
"""
)
# We grab Gohlke's code and evaluate it within py2js
dl_function = re.search(r"function dl.*\}", soup.find("script").text).group(0)
context.execute(dl_function)
links = soup.find(class_="pylibs").find_all("a")
for link in links:
"""
innerHTML = re.search(
']*)? id="([^<>]*?)">([^<>]*?)<\/div>',
body,
re.MULTILINE | re.DOTALL
)
innerHTML = innerHTML.group(2).replace("'", r"\'") if innerHTML else ""
js = jsunfuck(jsEnv.format(domain=domain, innerHTML=innerHTML, js=js))
def atob(s):
return base64.b64decode('{}'.format(s)).decode('utf-8')
js2py.disable_pyimport()
context = js2py.EvalJs({'atob': atob})
result = context.eval(js)
except Exception:
logging.error("Error executing Cloudflare IUAM Javascript. {}".format(BUG_REPORT))
raise
try:
float(result)
except Exception:
raise ValueError("Cloudflare IUAM challenge returned unexpected answer. {}".format(BUG_REPORT))
return result
# -*- coding: utf-8 -*-
# __author__ = "zok" 362416272@qq.com
# Date: 2019-04-26 Python: 3.7
# 本代码参考 github作者:CriseLYJ
import requests
import js2py
class FanYiSpider(object):
"""
翻译
"""
context = js2py.EvalJs() # python中使用js
def __init__(self, query):
# 初始化
self.url = "https://fanyi.baidu.com/basetrans"
self.query = query
self.headers = {
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Mobile Safari/537.36",
"Referer": "https://fanyi.baidu.com/",
"Cookie": "BAIDUID=714BFAAF02DA927F583935C7A354949A:FG=1; BIDUPSID=714BFAAF02DA927F583935C7A354949A; PSTM=1553390486; delPer=0; PSINO=5; H_PS_PSSID=28742_1463_21125_18559_28723_28557_28697_28585_28640_28604_28626_22160; locale=zh; from_lang_often=%5B%7B%22value%22%3A%22en%22%2C%22text%22%3A%22%u82F1%u8BED%22%7D%2C%7B%22value%22%3A%22zh%22%2C%22text%22%3A%22%u4E2D%u6587%22%7D%5D; to_lang_often=%5B%7B%22value%22%3A%22en%22%2C%22text%22%3A%22%u82F1%u8BED%22%7D%2C%7B%22value%22%3A%22zh%22%2C%22text%22%3A%22%u4E2D%u6587%22%7D%5D; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; Hm_lvt_afd111fa62852d1f37001d1f980b6800=1553658863,1553766321,1553769980,1553770442; Hm_lpvt_afd111fa62852d1f37001d1f980b6800=1553770442; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1553766258,1553766321,1553769980,1553770442; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1553770442",
"Content-Type": "application/x-www-form-urlencoded",
"Origin": "https://fanyi.baidu.com",
"X-Requested-With": "XMLHttpRequest",
}
def make_sign(self):
with open("translate.js", "r", encoding="utf-8") as f:
def __init__(self, username, password):
self.context = js2py.EvalJs() # python中使用js
self.username = username
self.password = password
js_content = f.read()
with open('md5.js', 'r', encoding='utf-8') as f:
js_md5 = f.read()
with open('sha1.js', 'r', encoding='utf-8') as f:
js_sha1 = f.read()
with open('Base64.js', 'r', encoding='utf-8') as f:
js_base64 = f.read()
with open('guid.js','r', encoding='utf-8') as f:
js_guid = f.read()
context = js2py.EvalJs()
context.execute(js_md5)
context.execute(js_sha1)
context.execute(js_base64)
context.execute(js_content)
context.execute(js_guid)
#
print('vl5x:', context.result)
print('guid:', context.guid)