:: krowemoh

Tuesday | 11 NOV 2025
Posts Links Other About Now

previous

2025-11-09
Javascript Decorators

javascript, reverse-engineering

Javascript decorators are handy and I need to use them more often.

The below function will start a tcpdump capture and then execute a function. It will then pause for a moment before killing the tcpdump. This way I can quickly write scripts and generate packet traces for my rpc reverse engineering project.

const { exec } = require('child_process');

function withTcpdump(fn, outfile = 'capture.pcap') {
    let x = async () => {
        const tcpdump = exec('/usr/sbin/tcpdump -i lo -n -A "port 1231" -w ' + outfile);
        try {
            await fn();
        } finally {
            await new Promise(r => setTimeout(r, 3000));
            tcpdump.kill('SIGINT');
            console.log('tcpdump stopped');
        }
    }
    return x
}
module.exports = { withTcpdump };