const commandHandlers = {};

function pluginRegister (name, ch) {
  if (commandHandlers.hasOwnPropertyDescriptor(name)) {
    console.log('Cannot register the same handler twice');
    return false;
  }
  commandHandlers[name] = ch;
  return true;
}

function pluginUnregister (name) {
  if (commandHandlers.hasOwnPropertyDescriptor(name)) {
    delete commandHandlers[name];
    return true;
  }
  return false;
}

function commandHandler (name) {
  for (const key of Object.keys(commandHandlers)) {
    const ch = commandHandlers[key];
    if (typeof ch === 'function') {
      const handler = ch(name);
      if (handler !== undefined) {
        return handler;
      }
    }
  }
  return undefined;
}

function pluginList () {
  return Object.keys(commandHandlers).join('\n');
}

global.r2frida = {
  version: require('../../package.json').version,
  commandHandler: commandHandler,
  pluginRegister: pluginRegister,
  pluginUnregister: pluginUnregister,
  pluginList: pluginList,
  // io hook plugin API //
  hookedRead: null,
  hookedWrite: null,
  hookedRanges: null,
  hookedScan: null
};

module.exports = global.r2frida;

@@ -57,32 +57,40 @@
 me, ch) %7B%0A  if (
+name in 
 commandHandlers.
@@ -92,39 +92,8 @@
 lers
-.hasOwnPropertyDescriptor(name)
 ) %7B%0A
@@ -262,16 +262,24 @@
 %7B%0A  if (
+name in 
 commandH
@@ -289,39 +289,8 @@
 lers
-.hasOwnPropertyDescriptor(name)
 ) %7B%0A

Fix agent plugins regression