UNPKG

malware-detector-cli

Version:

Universal malware detection CLI with deep file analysis capabilities

45 lines (37 loc) 1.13 kB
const { spawn } = require('child_process'); const path = require('path'); class MalwareDetector { constructor() { this.pythonPath = process.env.PYTHON_PATH || 'python3'; this.scriptPath = path.join(__dirname, 'detector.py'); } async analyze(filePath) { return new Promise((resolve, reject) => { const pythonProcess = spawn(this.pythonPath, [this.scriptPath, filePath]); let result = ''; let error = ''; pythonProcess.stdout.on('data', (data) => { result += data.toString(); }); pythonProcess.stderr.on('data', (data) => { error += data.toString(); }); pythonProcess.on('close', (code) => { if (code !== 0 || error) { reject(new Error(`Analysis failed: ${error}`)); } else { resolve(this.parseResult(result)); } }); }); } parseResult(output) { const match = output.match(/Final Verdict: (.+?) is (.+)$/); return match ? { file: match[1], result: match[2], isMalicious: match[2].includes('MALICIOUS') } : null; } } module.exports = MalwareDetector;