def solve_cf(self, body, domain): k = re.compile( '<div style="display:none;visibility:hidden;" id=".*?">(.*?)<\/div>', re.DOTALL).findall(body) k1 = re.compile( 'function\(p\){var p = eval\(eval.*?atob.*?return \+\(p\)}\(\)', re.DOTALL).findall(body) if k1: body = body.replace(k1[0], k[0]) js = re.search( r"setTimeout\(function\(\){\s+(var " "s,t,o,p,b,r,e,a,k,i,n,g,f.+?\r?\n[\s\S]+?a\.value =.+?)\r?\n", body).group(1) js = re.sub(r"a\.value = ((.+).toFixed\(10\))?", r"\1", js) js = re.sub(r"\s{3,}[a-z](?: = |\.).+", "", js).replace("t.length", str(len(domain))) js = js.replace('; 121', '') reemplazar = re.compile( '(?is)function\(p\)\{return eval.*?\+p\+"\)"\)}', re.DOTALL).findall(js) if reemplazar: js = js.replace(reemplazar[0], 't.charCodeAt') js = re.sub(r"[\n\\']", "", js) js = 'a = {{}}; t = "{}";{}'.format(domain, js) result = seval.eval_js_vm(js) return float(result)
assert js2py.eval_js6(''' var x; for (let a of [1,2,3]) { console.log(a); x = a } typeof a === 'undefined' && x === 3 ''') assert js2py.eval_js6(''' class Shape { constructor (id, x, y) { this.id = id this.move(x, y) } move (x, y) { this.x = x this.y = y } }; a = new Shape(1,2,3) ''').x == 2 print("Passed ECMA 6!") from js2py.internals import seval assert seval.eval_js_vm( "function k() {try {throw 3+8} catch (e) {console.log(e);return e}};k()", debug=True) == 11.0