refactor: anti-detection hooks

This commit is contained in:
Xmader 2020-11-05 16:54:07 -05:00
parent 04c918d092
commit c7b6f305e7
1 changed files with 13 additions and 16 deletions

View File

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