-
hook函数
old_func = func
func = function(arguments){
// 自己的操作逻辑
return old_func.apply(arguments)
}
func.prototype... = ....
重写原型链,为了抹去hook痕迹 -
hook对象属性, 如:
(function() {
'use strict';
var cookie_cache = document.cookie;
Object.defineProperty(document, 'cookie', {
get: function() {
console.log(cookie_cache);
return cookie_cache;
},
set: function(val) {
debugger;
var cookie = val.split(";")[0];
var ncookie = cookie.split("=");
var flag = false;
var cache = cookie_cache.split(";");
cache = cache.map(function(a){
if (a.split("=")[0] === ncookie[0]){
flag = true;
return cookie;
}
return a;
})
cookie_cache = cache.join(";");
if (!flag){
cookie_cache += cookie + ";";
}
},
});
})();
网友评论