bazarr/libs/cloudscraper/interpreters/js2py.py

45 lines
1.3 KiB
Python
Raw Normal View History

2019-05-12 04:44:35 +00:00
from __future__ import absolute_import
import js2py
import logging
import base64
from . import JavaScriptInterpreter
2020-07-22 02:43:40 +00:00
from .encapsulated import template
2019-05-12 04:44:35 +00:00
from .jsunfuck import jsunfuck
2020-07-22 02:43:40 +00:00
# ------------------------------------------------------------------------------- #
2019-05-12 04:44:35 +00:00
class ChallengeInterpreter(JavaScriptInterpreter):
2020-07-22 02:43:40 +00:00
# ------------------------------------------------------------------------------- #
2019-05-12 04:44:35 +00:00
def __init__(self):
super(ChallengeInterpreter, self).__init__('js2py')
2020-07-22 02:43:40 +00:00
# ------------------------------------------------------------------------------- #
def eval(self, body, domain):
jsPayload = template(body, domain)
2019-05-12 04:44:35 +00:00
if js2py.eval_js('(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]') == '1':
logging.warning('WARNING - Please upgrade your js2py https://github.com/PiotrDabkowski/Js2Py, applying work around for the meantime.')
2020-07-22 02:43:40 +00:00
jsPayload = jsunfuck(jsPayload)
2019-05-12 04:44:35 +00:00
def atob(s):
return base64.b64decode('{}'.format(s)).decode('utf-8')
js2py.disable_pyimport()
context = js2py.EvalJs({'atob': atob})
2020-07-22 02:43:40 +00:00
result = context.eval(jsPayload)
2019-05-12 04:44:35 +00:00
return result
2020-07-22 02:43:40 +00:00
# ------------------------------------------------------------------------------- #
2019-05-12 04:44:35 +00:00
ChallengeInterpreter()