'use strict'; const slowCallback = new NativeCallback(value => { console.log('slowCallback hit'); return 43; }, 'int', ['int']); const fastCallback = Memory.alloc(Process.pageSize); Memory.patchCode(fastCallback, 128, code => { const cw = new X86Writer(code, { pc: fastCallback }); cw.putCmpRegI32('edi', 10); cw.putJccShortLabel('je', 'match', 'unlikely'); cw.putLabel('nomatch'); cw.putMovRegU64('rax', 42); cw.putJmpShortLabel('done'); cw.putLabel('match'); cw.putSubRegImm('rsp', 8); cw.putCallAddressWithAlignedArguments(slowCallback, ['edi']); cw.putAddRegImm('rsp', 8); cw.putLabel('done'); cw.putRet(); cw.flush(); }); const cb = new NativeFunction(fastCallback, 'int', ['int']); for (let i = 0; i !== 100; i++) { const result = cb(i) console.log(`${i} => ${result}`); }