forked from sukyoung/safe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenpre.py
executable file
·106 lines (84 loc) · 2.9 KB
/
genpre.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python
# Generate JavaScript file that hooks built-in functions
builtins = {
"":
[
#"eval",
"parseInt", "parseFloat", "isNaN", "isFinite",
"decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent",
],
"Object":
["getPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyNames",
"create", "defineProperty", "defineProperties", "seal", "freeze",
"preventExtensions", "isSealed", "isFrozen", "isExtensible", "keys"],
"Object.prototype":
[
"toString",
"toLocaleString", "valueOf", "hasOwnProperty", "isPropertyOf", "propertyIsEnumerable"],
"Function.prototype":
[
#"apply",
"toString", "call", "bind"],
"Array":
["isArray"],
"Array.prototype":
[
"toString", "indexOf", "toLocaleString", "concat", "join", "pop", "push", "reverse",
"shift", "slice", "sort", "splice", "unshift", "lastIndexOf", "every", "some",
"forEach", "map", "filter", "reduce", "reduceRight"],
"String":
["fromCharCode"],
"String.prototype":
[
"toString",
"valueOf", "charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf",
"localeCompare", "match", "replace", "search", "slice", "split", "substring",
"toLowerCase", "toLocaleLowerCase", "toUpperCase", "toLocaleUpperCase", "trim" ],
"Boolean.prototype":
[
"toString", "valueOf" ],
"Number.prototype":
[
"toString", "toLocaleString", "valueOf", "toFixed", "toExponential", "toPrecision"],
"Math":
["abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "exp", "floor",
"log", "max", "min", "pow", "random", "round", "sin", "sqrt", "tan"],
"Date":
[ "parse", "UTC", "now"],
"Date.prototype":
[
"toString", "toDateString", "toTimeString", "toLocaleString", "toLocaleTimeString",
"valueOf", "getTime", "getFullYear", "getUTCFullYear", "getMonth",
"getUTCMonth", "getDate", "getUTCDate", "getDay", "getUTCDay", "getHours",
"getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds", "getUTCSeconds",
"getMilliseconds", "getUTCMilliseconds", "getTimezoneOffset", "setTime",
"setMilliseconds", "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes",
"setUTCMinutes", "setHours", "setUTCHours"],
"RegExp.prototype":
[ "exec", "test", "toString" ],
"JSON":
["parse","stringify"],
"Error.prototype": ["toString"],
"EvalError.prototype": ["toString"],
"RangeError.prototype": ["toString"],
"ReferenceError.prototype": ["toString"],
"SyntaxError.prototype": ["toString"],
"TypeError.prototype": ["toString"],
"URIError.prototype": ["toString"],
}
print "var _used = [];"
fn = 0
for o, ms in builtins.iteritems():
for m in ms:
if len(o) == 0:
om = m
else:
om = o+"."+m
print """
var _oldmethod_%d = %s;
%s = function() {
if(_used[%d] === undefined) { _used[%d] = 1; print('%s'); }
return _oldmethod_%d.apply(this, arguments);
};
""" % (fn, om, om, fn, fn, om, fn)
fn = fn + 1