forked from CrackerCat/r0chrome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.js
137 lines (134 loc) · 5.24 KB
/
proxy.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
dtavm = {}
dtavm.log = console.log
dtavm.proxy = function (obj, objname, type){
function getMethodHandler(WatchName, target_obj) {
let methodhandler = {
apply(target, thisArg, argArray) {
if (this.target_obj){
thisArg = this.target_obj
}
let result = Reflect.apply(target, thisArg, argArray)
if (target.name !== "toString"){
if (target.name === "addEventListener"){
dtavm.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray[0]}], result is [${result}].`)
}else if (WatchName === "window.console"){
}else {
dtavm.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray}], result is [${result}].`)
}
}else{
dtavm.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray}], result is [${result}].`)
}
return result
},
construct(target, argArray, newTarget) {
var result = Reflect.construct(target, argArray, newTarget)
dtavm.log(`[${WatchName}] construct function name is [${target.name}], argArray is [${argArray}], result is [${(result)}].`)
return result;
}
}
methodhandler.target_obj = target_obj
return methodhandler
}
function getObjhandler(WatchName) {
let handler = {
get(target, propKey, receiver) {
let result = target[propKey]
if (result instanceof Object) {
if (typeof result === "function") {
dtavm.log(`[${WatchName}] getting propKey is [${propKey}] , it is function`)
return new Proxy(result,getMethodHandler(WatchName, target))
}
else {
dtavm.log(`[${WatchName}] getting propKey is [${propKey}], result is [${(result)}]`);
}
return new Proxy(result, getObjhandler(`${WatchName}.${propKey}`))
}
if(typeof(propKey) !== "symbol"){
dtavm.log(`[${WatchName}] getting propKey is [${propKey?.description ?? propKey}], result is [${result}]`);
}
return result;
},
set(target, propKey, value, receiver) {
if (value instanceof Object) {
dtavm.log(`[${WatchName}] setting propKey is [${propKey}], value is [${(value)}]`);
} else {
dtavm.log(`[${WatchName}] setting propKey is [${propKey}], value is [${value}]`);
}
return Reflect.set(target, propKey, value, receiver);
},
has(target, propKey) {
var result = Reflect.has(target, propKey);
dtavm.log(`[${WatchName}] has propKey [${propKey}], result is [${result}]`)
return result;
},
deleteProperty(target, propKey) {
var result = Reflect.deleteProperty(target, propKey);
dtavm.log(`[${WatchName}] delete propKey [${propKey}], result is [${result}]`)
return result;
},
defineProperty(target, propKey, attributes) {
var result = Reflect.defineProperty(target, propKey, attributes);
dtavm.log(`[${WatchName}] defineProperty propKey [${propKey}] attributes is [${(attributes)}], result is [${result}]`)
return result
},
getPrototypeOf(target) {
var result = Reflect.getPrototypeOf(target)
dtavm.log(`[${WatchName}] getPrototypeOf result is [${(result)}]`)
return result;
},
setPrototypeOf(target, proto) {
dtavm.log(`[${WatchName}] setPrototypeOf proto is [${(proto)}]`)
return Reflect.setPrototypeOf(target, proto);
},
preventExtensions(target) {
dtavm.log(`[${WatchName}] preventExtensions`)
return Reflect.preventExtensions(target);
},
isExtensible(target) {
var result = Reflect.isExtensible(target)
dtavm.log(`[${WatchName}] isExtensible, result is [${result}]`)
return result;
},
}
return handler;
}
if (type === "method"){
return new Proxy(obj, getMethodHandler(objname, obj));
}
return new Proxy(obj, getObjhandler(objname));
}
Object.defineProperties(globalThis, {
'window': {
configurable: false,
enumerable: true,
get: function get() {
return dtavm.proxy(window_dta, "window")
},
set: undefined
},
'navigator': {
configurable: true,
enumerable: true,
get: function get() {
return dtavm.proxy(navigator_dta, "navigator")
},
set: undefined
},
'document': {
configurable: false,
enumerable: true,
get: function get() {
return dtavm.proxy(document_dta, "document")
},
set: undefined
},
'history': {
configurable: true,
enumerable: true,
get: function get() {
return dtavm.proxy(history_dta, "history")
},
set: undefined
},
})
screen = dtavm.proxy(screen_dta, "screen")