File size: 1,165 Bytes
bee6636
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { config } from "../../shared";
import { rewriteJs } from "../../shared/rewriters/js";
import { ScramjetClient } from "../client";

export default function (client: ScramjetClient, self: Self) {
	// used for proxying *direct eval*
	// eval("...") -> eval($scramjet$rewrite("..."))
	Object.defineProperty(self, config.globals.rewritefn, {
		value: function (js: any) {
			if (typeof js !== "string") return js;

			const rewritten = rewriteJs(js, "(direct eval proxy)", client.meta);

			return rewritten;
		},
		writable: false,
		configurable: false,
	});
}

export function indirectEval(this: ScramjetClient, strict: boolean, js: any) {
	// > If the argument of eval() is not a string, eval() returns the argument unchanged
	if (typeof js !== "string") return js;

	let indirection: typeof eval;
	if (this.url.hostname === "accounts.google.com") {
		console.log("USING STRICT EVAL - BOTGUARD");
		indirection = new Function(`

			"use strict";

			return eval;

		`) as typeof eval;
	} else {
		indirection = this.global.eval;
	}

	return indirection(
		rewriteJs(js, "(indirect eval proxy)", this.meta) as string
	);
}