From f51e0742d7b1597e212150c6bd5a1042ab3e9b88 Mon Sep 17 00:00:00 2001 From: Xmader Date: Thu, 5 Nov 2020 16:36:24 -0500 Subject: [PATCH] fix: anti-detection --- src/anti-detection.ts | 26 ++++++++++++++++++++++++++ src/file.ts | 11 ++--------- 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/anti-detection.ts diff --git a/src/anti-detection.ts b/src/anti-detection.ts new file mode 100644 index 0000000..65ed729 --- /dev/null +++ b/src/anti-detection.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-extend-native */ +/* eslint-disable @typescript-eslint/ban-types */ + +/** + * make hooked methods "native" + */ +export const makeNative = (() => { + const l: Set = new Set() + + const _toString = Function.prototype['toString'] + const toString = function () { + if (l.has(this)) { + // "function () {\n [native code]\n}" + return _toString.call(parseInt) as string + } + return _toString.call(this) as string + } + Function.prototype.toString = toString + + // make `Function.prototype.toString` itself "native" + l.add(toString) + + return (fn: Function) => { + l.add(fn) + } +})() diff --git a/src/file.ts b/src/file.ts index 2cc6f54..0d41ca1 100644 --- a/src/file.ts +++ b/src/file.ts @@ -2,6 +2,7 @@ import scoreinfo from './scoreinfo' import { webpackHook } from './webpack-hook' +import { makeNative } from './anti-detection' const FILE_URL_MODULE_ID = 'iNJA' const MAGIC_REG = /^\d+(img|mp3|midi)\d(.+)$/ @@ -35,15 +36,7 @@ let magic: Promise | string = new Promise((resolve) => { } target[method] = hookFn - // make hooked methods "native" - const _toString = Function.prototype['toString'] - Function.prototype.toString = function s () { - if (this === hookFn || this === s) { - // "function () {\n [native code]\n}" - return _toString.call(parseInt) as string - } - return _toString.call(this) as string - } + makeNative(hookFn) }) export const getFileUrl = async (type: FileType, index = 0): Promise => {