mirror of
https://github.com/qitoqito/psyduck.git
synced 2026-01-11 20:20:43 +08:00
fileCrypto
This commit is contained in:
parent
d70ee5bcdb
commit
b3ed104be0
58
fileCrypto.js
Executable file
58
fileCrypto.js
Executable file
@ -0,0 +1,58 @@
|
||||
import {
|
||||
promises as fs,
|
||||
readdirSync,
|
||||
lstatSync
|
||||
} from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
Buffer
|
||||
} from 'buffer';
|
||||
import {
|
||||
fileURLToPath
|
||||
} from 'url';
|
||||
import ini from 'ini'
|
||||
const __filename = fileURLToPath(
|
||||
import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const ENCRYPTION_MARKER = 'PsyDuck:';
|
||||
async function isFileEncrypted(filePath) {
|
||||
try {
|
||||
const content = await fs.readFile(filePath, 'utf-8');
|
||||
return content.startsWith(ENCRYPTION_MARKER);
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
console.error('文件不存在:', filePath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function tripleReverseDecrypt(encryptedHexStr, originalPadding) {
|
||||
let result = '';
|
||||
for (let i = 0; i < encryptedHexStr.length; i += 3) {
|
||||
const segment = encryptedHexStr.substr(i, 3);
|
||||
result += [...segment].reverse().join('');
|
||||
}
|
||||
return originalPadding > 0 ? result.slice(0, -originalPadding) : result;
|
||||
}
|
||||
export async function decryptFile(inputPath, outputPath) {
|
||||
try {
|
||||
if (!await isFileEncrypted(inputPath)) {
|
||||
console.log('文件未加密或格式不正确');
|
||||
return false;
|
||||
}
|
||||
const encryptedContent = await fs.readFile(inputPath, 'utf-8');
|
||||
const data = encryptedContent.slice(ENCRYPTION_MARKER.length);
|
||||
const [paddingHex, encryptedHex] = data.split(':');
|
||||
const originalPadding = parseInt(paddingHex, 16);
|
||||
const decryptedHex = tripleReverseDecrypt(encryptedHex, originalPadding);
|
||||
const base64Str = Buffer.from(decryptedHex, 'hex').toString('utf-8');
|
||||
const fileContent = Buffer.from(base64Str, 'base64');
|
||||
await fs.writeFile(outputPath, fileContent);
|
||||
console.log(`文件解密成功: ${outputPath}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('解密失败:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
qlCreate.js
21
qlCreate.js
@ -5,7 +5,7 @@ import {
|
||||
} from 'url';
|
||||
import ini from 'ini'
|
||||
import axios from "axios";
|
||||
|
||||
import {decryptFile} from "./fileCrypto.js";
|
||||
class Ql {
|
||||
constructor() {
|
||||
console.log(`Readme: 请先初始化config.ini,打开qitoqito_psyduck/config文件夹,将demo.ini重命名为config.ini\n 设置QINGLONG_ClientId和QINGLONG_ClientSecret(前面;符号要去掉才能正常解析)\n 如需使用脚本分身,请先自行创建分类ini\n 以京东为例,在指定的iniPath目录(默认qitoqito_psyduck/config)自行创建jd.ini\n\n [jd_checkCookie]\n map=jd_task_checkCookie\n ;title=自定义脚本名\n ;crontab=自定义定时(6 6 6 6 6)\n\n 将上述节点代码复制到jd.ini,jd_checkCookie就能映射到jd_task_checkCookie脚本\n`)
|
||||
@ -225,6 +225,23 @@ class Ql {
|
||||
let dicts = {}
|
||||
let dir = fs.readdirSync(`${abspath}/parse`);
|
||||
let panelJson = this.panelJson
|
||||
let fileList=[]
|
||||
dir.forEach(async function(item, index) {
|
||||
let config = panelJson.script[item] || {}
|
||||
let delList = config.delete || []
|
||||
let stat = fs.lstatSync(`${abspath}/parse/` + item)
|
||||
if (stat.isDirectory() === true) {
|
||||
for (let script of fs.readdirSync(`${abspath}/parse/${item}`)) {
|
||||
if (script.match(/\w+\_\w+\_\w/)) {
|
||||
fileList.push(`${abspath}/parse/${item}/${script}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this))
|
||||
await this.wait(1000)
|
||||
for(let filePath of fileList){
|
||||
await decryptFile(filePath,filePath)
|
||||
}
|
||||
dir.forEach(async function(item, index) {
|
||||
let config = panelJson.script[item] || {}
|
||||
let delList = config.delete || []
|
||||
@ -377,7 +394,7 @@ import {fileURLToPath, pathToFileURL} from 'url';
|
||||
}
|
||||
}
|
||||
}.bind(this))
|
||||
await this.wait(20000)
|
||||
await this.wait(10000)
|
||||
let commands = Object.values(dicts)
|
||||
for (let i in dicts) {
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user