feat: 新增助眠解压相关模块 && bump 4.32.0

This commit is contained in:
MoeFurina
2026-04-17 20:41:31 +08:00
parent 2c36daf07a
commit ba9c6deaee
16 changed files with 341 additions and 51 deletions
+27 -9
View File
@@ -1,5 +1,6 @@
const CryptoJS = require('crypto-js')
const forge = require('node-forge')
const zlib = require('zlib')
const iv = '0102030405060708'
const presetKey = '0CoJUm6Qyw8W8jud'
const linuxapiKey = 'rFgB&h#%2?^eDg:Q'
@@ -44,7 +45,7 @@ const aesDecrypt = (ciphertext, key, iv, format = 'base64') => {
},
)
}
return bytes.toString(CryptoJS.enc.Utf8)
return bytes
}
const rsaEncrypt = (str, key) => {
const forgePublicKey = forge.pki.publicKeyFromPem(key)
@@ -85,20 +86,37 @@ const eapi = (url, object) => {
params: aesEncrypt(data, 'ecb', eapiKey, '', 'hex'),
}
}
const eapiResDecrypt = (encryptedParams) => {
const eapiResDecrypt = (encryptedParams, aeapi = false) => {
// 使用aesDecrypt解密参数
try {
const decryptedData = aesDecrypt(encryptedParams, eapiKey, '', 'hex')
return JSON.parse(decryptedData)
const decrypted = aesDecrypt(encryptedParams, eapiKey, '', 'hex') // WordArray
if (aeapi) {
// 带压缩的解密:先转 Base64 再解压
const decryptedBuffer = Buffer.from(
decrypted.toString(CryptoJS.enc.Base64),
'base64',
)
const decompressed = zlib.gunzipSync(decryptedBuffer)
return JSON.parse(decompressed.toString())
} else {
// 普通解密:直接转 UTF-8 字符串
return JSON.parse(decrypted.toString(CryptoJS.enc.Utf8))
}
} catch (error) {
console.log('eapiResDecrypt error:', error)
console.log(`eapiResDecrypt error:`, error)
return null
}
}
const eapiReqDecrypt = (encryptedParams) => {
// 使用aesDecrypt解密参数
const decryptedData = aesDecrypt(encryptedParams, eapiKey, '', 'hex')
// 使用正则表达式解析出URL和数据
// 使用 aesDecrypt 解密参数
const decryptedData = aesDecrypt(
encryptedParams,
eapiKey,
'',
'hex',
).toString(CryptoJS.enc.Utf8)
// 使用正则表达式解析出 URL 和数据
const match = decryptedData.match(/(.*?)-36cd479b6b5-(.*?)-36cd479b6b5-(.*)/)
if (match) {
const url = match[1]
@@ -106,7 +124,7 @@ const eapiReqDecrypt = (encryptedParams) => {
return { url, data }
}
// 如果没有匹配到,返回null
// 如果没有匹配到,返回 null
return null
}
const decrypt = (cipher) => {
+21 -22
View File
@@ -3,7 +3,6 @@ const encrypt = require('./crypto')
const CryptoJS = require('crypto-js')
const { default: axios } = require('axios')
const { PacProxyAgent } = require('pac-proxy-agent')
const logger = require('./logger')
const http = require('http')
const https = require('https')
const tunnel = require('tunnel')
@@ -160,10 +159,8 @@ const createRequest = (uri, data, options) => {
return new Promise((resolve, reject) => {
// 变量声明和初始化
const headers = options.headers ? { ...options.headers } : {}
const ip =
options.realIP ||
options.ip ||
(options.randomCNIP ? generateRandomChineseIP() : '')
const ip = options.realIP || options.ip || ''
// IP头设置
if (ip) {
headers['X-Real-IP'] = ip
@@ -191,6 +188,13 @@ const createRequest = (uri, data, options) => {
const answer = { status: 500, body: {}, cookie: [] }
data.e_r = toBoolean(
options.e_r !== undefined
? options.e_r
: data.e_r !== undefined
? data.e_r
: ENCRYPT_RESPONSE,
)
// 根据加密方式处理
switch (crypto) {
case 'weapi':
@@ -242,13 +246,7 @@ const createRequest = (uri, data, options) => {
if (crypto === 'eapi') {
// headers['x-aeapi'] = true // 服务器会使用gzip压缩返回值
data.header = header
data.e_r = toBoolean(
options.e_r !== undefined
? options.e_r
: data.e_r !== undefined
? data.e_r
: ENCRYPT_RESPONSE,
)
encryptData = encrypt.eapi(uri, data)
url = (options.domain || API_DOMAIN) + '/eapi/' + uri.substr(5)
} else if (crypto === 'api') {
@@ -258,10 +256,10 @@ const createRequest = (uri, data, options) => {
break
default:
logger.error('Unknown Crypto:', crypto)
console.log('[ERR]', 'Unknown Crypto:', crypto)
break
}
// logger.info(url);
// console.log(url);
// settings创建
let settings = {
method: 'POST',
@@ -272,8 +270,9 @@ const createRequest = (uri, data, options) => {
httpsAgent: createHttpsAgent(),
}
// e_r处理
if (data.e_r) {
// 使用返回值加密
const use_e_r = (crypto === 'eapi' || crypto === 'weapi') && data.e_r
if (use_e_r) {
settings.encoding = null
settings.responseType = 'arraybuffer'
}
@@ -303,16 +302,16 @@ const createRequest = (uri, data, options) => {
settings.httpAgent = agent
settings.proxy = false
} else {
logger.error('代理配置无效,不使用代理')
console.error('代理配置无效,不使用代理')
}
} catch (e) {
logger.error('代理URL解析失败:', e.message)
console.error('代理URL解析失败:', e.message)
}
}
} else {
settings.proxy = false
}
// logger.info(settings.headers);
// console.log(settings.headers);
axios(settings)
.then((res) => {
const body = res.data
@@ -321,7 +320,7 @@ const createRequest = (uri, data, options) => {
)
try {
if (crypto === 'eapi' && data.e_r) {
if (use_e_r) {
answer.body = encrypt.eapiResDecrypt(
body.toString('hex').toUpperCase(),
headers['x-aeapi'],
@@ -352,14 +351,14 @@ const createRequest = (uri, data, options) => {
if (answer.status === 200) {
resolve(answer)
} else {
logger.error(answer)
console.log('[ERR]', answer)
reject(answer)
}
})
.catch((err) => {
answer.status = 502
answer.body = { code: 502, msg: err.message || err }
logger.error(answer)
console.log('[ERR]', answer)
reject(answer)
})
})