hook本质上就是重写函数,因为js反爬也是通过重写函数来进行加密或者反爬的。记录两个小脚本用于hook,虽然我早已经不从事爬虫工作,唉~!

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
f = Function
Function = function(a){
if (a!=='debugger'){return f(a)}
}

Function.prototype.constructor_ = Function.prototype.constructor;
Function.prototype.constructor = function(x){
if (x!=='debugger'){return Function.prototype.constructor_(x)}
}

eval_ = eval;
eval = function(a){
if(a=='debugger')
{return ''}
else{return eval_(a)}
}

setTimeout = function(a,b){
}

setInterval = function(){}

console.log_ = console.log

Function.prototype.constructor_ = Function.prototype.constructor;
Function.prototype.constructor = function(x){
debugger;
return Function.prototype.constructor_(x);
}

(function(){
'use strict'
Object.defineProperty(document, 'cookie', {
get: function() {
debugger;
return "";
},
set: function(value) {
debugger;
return value;
},
});
})()