fix: anti-detection

This commit is contained in:
Xmader 2020-11-05 16:36:24 -05:00
parent 67dc352004
commit f51e0742d7
2 changed files with 28 additions and 9 deletions

26
src/anti-detection.ts Normal file
View File

@ -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<Function> = 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)
}
})()

View File

@ -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> | 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<string> => {