UNPKG

obfulox

Version:

Advanced JavaScript code encryptor with multi-layer encryption and obfuscation

72 lines (71 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.obfuscationlox = obfuscationlox; exports.deobfuscationlox = deobfuscationlox; exports.extractIdObfulox = extractIdObfulox; exports.validateIdObfulox = validateIdObfulox; const js_confuser_1 = require("js-confuser"); const generateIdObfulox = () => { return Math.random().toString(36).substr(2, 10); }; async function obfuscationlox(fileName, options) { const idObfulox = generateIdObfulox(); const lock = { antiDebug: options.lock.antiDebug, selfDefending: options.lock.selfDefending, }; const obfuscationOptions = { jsConfuser: options.jsConfuser, arrayObfuscation: options.arrayObfuscation, stringObfuscation: options.stringObfuscation, integrity: options.integrity, deadCode: options.deadCode, uniCodeType: options.uniCodeType, idObfulox, lock, }; const obfuscatedCode = await js_confuser_1.jsConfuser.obfuscateFile({ input: fileName, output: 'obfuscated', options: obfuscationOptions, }); const markedCode = `/* OBFULOX_ID:${idObfulox} */\n${obfuscatedCode}`; return { code: markedCode, idObfulox, metadata: { timestamp: Date.now(), options: { jsConfuser: options.jsConfuser, arrayObfuscation: options.arrayObfuscation, stringObfuscation: options.stringObfuscation, integrity: options.integrity, deadCode: options.deadCode, uniCodeType: options.uniCodeType, lock: options.lock, } } }; } async function deobfuscationlox(obfuscatedCode, idObfulox) { const idMatch = obfuscatedCode.match(/\/\* OBFULOX_ID:(\w+) \*\//); if (!idMatch) { throw new Error('The code does not have a valid obfuscation ID.'); } const extractedId = idMatch[1]; if (extractedId !== idObfulox) { throw new Error('Obfuscation ID mismatch. Decrypt failed..'); } let cleanCode = obfuscatedCode.replace(/\/\* OBFULOX_ID:\w+ \*\/\n?/, ''); console.warn('Full deobfuscation is not possible automatically..'); console.warn('Valid ID. The original code must be stored separately during obfuscation..'); return cleanCode; } function extractIdObfulox(obfuscatedCode) { const idMatch = obfuscatedCode.match(/\/\* OBFULOX_ID:(\w+) \*\//); return idMatch ? idMatch[1] : null; } function validateIdObfulox(obfuscatedCode, idObfulox) { const extractedId = extractIdObfulox(obfuscatedCode); return extractedId === idObfulox; }