refactor: hookNative

This commit is contained in:
Xmader 2020-11-07 21:03:26 -05:00
parent f1a6fd81eb
commit 13afe431c8
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
1 changed files with 7 additions and 7 deletions

View File

@ -5,20 +5,20 @@
* make hooked methods "native"
*/
export const makeNative = (() => {
const l = new Set<Function>()
const l = new Map<Function, Function>()
hookNative(Function.prototype, 'toString', (_toString) => {
return function () {
if (l.has(this)) {
// "function () {\n [native code]\n}"
return _toString.call(parseInt) as string
const _fn = l.get(this) || parseInt // "function () {\n [native code]\n}"
return _toString.call(_fn) as string
}
return _toString.call(this) as string
}
}, true)
return (fn: Function) => {
l.add(fn)
return (fn: Function, original: Function) => {
l.set(fn, original)
}
})()
@ -40,10 +40,10 @@ export function hookNative<T extends object, M extends (keyof T)> (
target[method] = hookedFn
if (!async) {
makeNative(hookedFn as any)
makeNative(hookedFn as any, _fn as any)
} else {
setTimeout(() => {
makeNative(hookedFn as any)
makeNative(hookedFn as any, _fn as any)
})
}
}