From 1c17c20c1b665439fc090bb0ff6b3521602960dd Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 8 Oct 2024 09:08:03 +0200 Subject: [PATCH] Initial support for r2pipe { command --- src/agent/index.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/agent/index.ts b/src/agent/index.ts index fb8c119d..2c86c55b 100644 --- a/src/agent/index.ts +++ b/src/agent/index.ts @@ -37,6 +37,17 @@ global.r2pipe = { } }; +function r2pipe2(arg: string) { + const query = JSON.parse(arg); + const cmd = query.cmd; + const res: any = perform({ command: cmd }); + const objres = { + res: res[0].value, + code: 0 + } + console.log(JSON.stringify(objres)); +} + const commandHandlers = { '!': [system.runSystemCommand, 'execute program with system'], '?': [expr.evalNum, 'evaluate number'], @@ -355,6 +366,9 @@ function perform(params: any) { if (command.startsWith("!")) { command = "! " + command.substr(1); } + if (command.startsWith("{")) { + return r2pipe2(command); + } const tokens = command.split(/ /).map((c: any) => c.trim()).filter((x: any) => x); const [name, ...args] = tokens; if (typeof name === 'undefined') {