refactor: anti-detection hooks

This commit is contained in:
Xmader 2020-11-05 16:54:07 -05:00
parent 04c918d092
commit c7b6f305e7

View file

@ -7,31 +7,26 @@
export const makeNative = (() => {
const l: Set<Function> = new Set()
const target = Function.prototype
const method = 'toString'
const _toString = target[method]
const toString = function () {
hookNative(Function.prototype, 'toString', (_toString) => {
return function () {
if (l.has(this)) {
// "function () {\n [native code]\n}"
return _toString.call(parseInt) as string
}
return _toString.call(this) as string
}
target[method] = toString
// make `Function.prototype.toString` itself "native"
l.add(toString)
})
return (fn: Function) => {
l.add(fn)
}
})()
export const hookNative = <T extends object, M extends (keyof T)> (
export function hookNative<T extends object, M extends (keyof T)> (
target: T,
method: M,
hook: (originalFn: T[M], detach: () => void) => T[M],
): void => {
): void {
// reserve for future hook update
const _fn = target[method]
const detach = () => {
@ -43,5 +38,7 @@ export const hookNative = <T extends object, M extends (keyof T)> (
const hookedFn = hook(_fn, detach)
target[method] = hookedFn
setTimeout(() => {
makeNative(hookedFn as any)
})
}