refactor: anti-detection hooks
This commit is contained in:
		
							parent
							
								
									04c918d092
								
							
						
					
					
						commit
						c7b6f305e7
					
				
					 1 changed files with 13 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -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 () {
 | 
			
		||||
    if (l.has(this)) {
 | 
			
		||||
      // "function () {\n    [native code]\n}"
 | 
			
		||||
      return _toString.call(parseInt) as string
 | 
			
		||||
  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
 | 
			
		||||
    }
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
  makeNative(hookedFn as any)
 | 
			
		||||
  setTimeout(() => {
 | 
			
		||||
    makeNative(hookedFn as any)
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue