Spaces:
Running
Running
| const puppeteer = require('puppeteer'); | |
| async function deobfuscateCode(code) { | |
| const browser = await puppeteer.launch({ | |
| headless: true, | |
| args: ['--no-sandbox', '--disable-setuid-sandbox'] | |
| }); | |
| try { | |
| const page = await browser.newPage(); | |
| await page.goto('https://obf-io.deobfuscate.io/', { | |
| waitUntil: 'domcontentloaded', | |
| timeout: 30000 | |
| }); | |
| await new Promise(resolve => setTimeout(resolve, 2000)); | |
| await page.waitForSelector('.cm-content', { timeout: 15000 }); | |
| await page.evaluate((inputCode) => { | |
| const editors = document.querySelectorAll('.cm-content[contenteditable="true"]'); | |
| if (editors.length > 0) { | |
| const editor = editors[0]; | |
| editor.focus(); | |
| document.execCommand('selectAll', false, null); | |
| document.execCommand('insertText', false, inputCode); | |
| } | |
| }, code); | |
| await new Promise(resolve => setTimeout(resolve, 1500)); | |
| const buttonClicked = await page.evaluate(() => { | |
| const buttons = Array.from(document.querySelectorAll('button')); | |
| const deobfButton = buttons.find(btn => btn.textContent.includes('Deobfuscate')); | |
| if (deobfButton) { | |
| deobfButton.click(); | |
| return true; | |
| } | |
| return false; | |
| }); | |
| if (!buttonClicked) { | |
| throw new Error('Deobfuscate button not found'); | |
| } | |
| await new Promise(resolve => setTimeout(resolve, 5000)); | |
| await page.waitForFunction(() => { | |
| const editors = document.querySelectorAll('.cm-content[contenteditable="true"]'); | |
| return editors.length > 1 && editors[1].textContent.trim().length > 0; | |
| }, { timeout: 15000 }).catch(() => {}); | |
| const result = await page.evaluate(() => { | |
| const editors = document.querySelectorAll('.cm-content[contenteditable="true"]'); | |
| if (editors.length > 1) { | |
| const outputEditor = editors[1]; | |
| let text = ''; | |
| const lines = outputEditor.querySelectorAll('.cm-line'); | |
| lines.forEach((line, index) => { | |
| text += line.textContent; | |
| if (index < lines.length - 1) text += '\n'; | |
| }); | |
| return text.trim(); | |
| } | |
| return null; | |
| }); | |
| if (!result) { | |
| throw new Error('No result found'); | |
| } | |
| return result; | |
| } finally { | |
| await browser.close(); | |
| } | |
| } | |
| const handler = async (req, res) => { | |
| try { | |
| const { code } = req.body; | |
| if (!code) { | |
| return res.status(400).json({ | |
| success: false, | |
| error: 'Missing required parameter: code' | |
| }); | |
| } | |
| const deobfuscatedCode = await deobfuscateCode(code); | |
| res.json({ | |
| author: "Herza", | |
| success: true, | |
| result: { | |
| original_length: code.length, | |
| deobfuscated_length: deobfuscatedCode.length, | |
| code: deobfuscatedCode | |
| } | |
| }); | |
| } catch (error) { | |
| res.status(500).json({ | |
| success: false, | |
| error: error.message | |
| }); | |
| } | |
| }; | |
| module.exports = { | |
| name: 'JavaScript Deobfuscator', | |
| description: 'Deobfuscate obfuscated JavaScript code using obf-io.deobfuscate.io', | |
| type: 'POST', | |
| routes: ['api/tools/deobfuscate'], | |
| tags: ['tools', 'javascript', 'deobfuscate', 'code'], | |
| main: ['tools'], | |
| parameters: ['code'], | |
| enabled: true, | |
| limit: 2, | |
| handler | |
| }; |