补环境框架笔记
补环境框架笔记
1.浏览器环境下一些特殊的变量
window === self window === top window.self === self.top.window document.all 能得到HTMLAllCollection对象 typeof document.all 却是 undefined

2.fiddler插件个函数最新的顺序:
OnBoot: 初始化时 OnAttach: 插件启动时 OnExecAction: 命令执行时 OnPeekAtRequestHeaders: 请求头拼接 OnBeforeRequests:请求开始时 OnPeekAtResponseHeaders:返回头解析时 OnBeforeResponse: 接收头解析时 OnDetach: 插件销毁时
3.简单的补canvas:参考https://github.com/fingerprintjs/fingerprintjs/blob/master/src/sources/canvas.ts

4.有些对象的浏览器上无法直接看到其属性可以通过dir()查看 比如dir(Window)


5.获取原型对象下的所有属性和方法,补环境的时候需要把这些属性和方法都补上
Object.getOwnPropertyDescriptors(Window)

6.补原型的属性
//Window设置属性
Object.defineProperty(Window, "PERSISTENT", {
configurable: true,
enumerable: true,
writable: true,
value: 1
});
//Window原型设置属性
Object.defineProperty(Window.prototype, "PERSISTENT", {
configurable: true,
enumerable: true,
writable: true,
value: 1
});
7.设置函数原型
//Window
Window = function Window(){
}
// 函数Native 保护toString方法
ldvm.toolsFunc.setNative(Window, "Window")
// 修改函数名称
ldvm.toolsFunc.reNameObj(Window, "Window")
// 定义window对象
window = globalThis;
// 给window函数设置原型
Object.setPrototypeOf(window, Window.prototype)
8.保护函数
// 保护函数 保护toString方法
!function () {
const $toString = Function.prototype.toString;
const symbol = Symbol();
const myToString = function () {
return typeof this === 'function' && this[symbol] || $toString.call(this);
};
function set_native(func, key, value) {
Object.defineProperty(func, key, {
"enumerable": false,
"configurable": true,
"writable": true,
"value": value
})
};
delete Function.prototype['toString']; //删除原型链上的toString
set_native(Function.prototype, "toString", myToString); //自己定义个getter方法
set_native(Function.prototype.toString, symbol, "function toString() { [native code] }"); //套个娃 保护一下我们定义的toString 否则就暴露了
globalThis.safefunction = function (func, funcname) {
set_native(func, symbol, `function ${funcname || func.name || ''}() { [native code] }`);
}; //导出函数到globalThis
}();
9.函数重命名
// 函数重命名
reNaneFunc = function reNaneFunc(func, name) {
Object.defineProperty(func, "name", {
"value": name, // 值
"writable": false, // 是否可写
"enumerable": false, // 是否可遍历
"configurable": true, // 是否可配置
})
}
add = function xxx() {
return a + b;
}
reNaneFunc(add, "get add")
console.log(add.name);
10.对象重命名
// 对象重命名
reNaneObj = function reNaneObj(obj, objName) {
Object.defineProperty(obj.prototype, Symbol.toString(), {
configurable: true,
enumerable: false,
writable: true,
value: objName
})
}