UNPKG

funnycode

Version:

obfuscation {js,ts,cjs,mjs} code

29 lines (26 loc) 814 B
import { promises } from 'fs'; import { exit } from 'node:process'; import path from 'path'; import CryptoJS from 'crypto-js'; import { loadCache, error, winPath, cwd, CACHE_PATH } from './utils.mjs'; async function decode(key) { const cache = loadCache(); if (!cache || Object.keys(cache).length === 0) error(3); const cacheArray = Object.entries(cache); for (const c of cacheArray) { const [file, code] = c; const decryptCode = crypto(code, key); await promises.writeFile(winPath(path.join(cwd, file)), decryptCode); console.log(`done ${file}`); } await save(); } function crypto(code, key) { return CryptoJS.AES.decrypt(code, key).toString(CryptoJS.enc.Utf8); } async function save() { await promises.writeFile(CACHE_PATH, "{}"); exit(0); } export { decode as default };