diff --git a/typescript/Makefile b/typescript/Makefile index 1ec551e..f8cb923 100644 --- a/typescript/Makefile +++ b/typescript/Makefile @@ -12,3 +12,6 @@ vs vsc: test: make -C examples/hello + +lint: + ./node_modules/.bin/eslint --fix r2pipe/*.ts diff --git a/typescript/r2pipe/base.ts b/typescript/r2pipe/base.ts index eb1b322..8acd84e 100644 --- a/typescript/r2pipe/base.ts +++ b/typescript/r2pipe/base.ts @@ -2,7 +2,7 @@ export abstract class R2PipeBase implements R2PipeCmdInterface { abstract cmd(command: string): Promise; abstract quit(): Promise; - async cmdj(command: string): Promise { + async cmdj(command: string): Promise { const output = await this.cmd(command); try { return JSON.parse(output); @@ -25,7 +25,7 @@ export interface R2PipeCmdInterface { * @param command The radare2 command to execute. * @returns A promise that resolves with the parsed JSON output. */ - cmdj(command: string): Promise; + cmdj(command: string): Promise; /** * Quits and destroys the given instance diff --git a/typescript/r2pipe/http.ts b/typescript/r2pipe/http.ts index fd48cbd..9c57cc0 100644 --- a/typescript/r2pipe/http.ts +++ b/typescript/r2pipe/http.ts @@ -1,5 +1,5 @@ import * as http from "http"; -import {R2PipeBase, R2PipeCmdInterface} from "./base.js"; +import {R2PipeBase} from "./base.js"; export class R2PipeHttp extends R2PipeBase { private baseUrl: string; @@ -20,7 +20,7 @@ export class R2PipeHttp extends R2PipeBase { return new Promise((resolve, reject) => { const url = `${uri}/cmd/${cmd}`; // console.error("==> " + url); - http.get(url, (res: any) => { + http.get(url, (res: http.IncomingMessage) => { if (res.statusCode !== 200) { reject(new Error(`Request Failed. Status Code: ${res.statusCode}`)); res.resume(); // Consume response data to free up memory @@ -32,7 +32,7 @@ export class R2PipeHttp extends R2PipeBase { res.on('end', () => { resolve(rawData); }); - }).on('error', (e: any) => { + }).on('error', (e: Error) => { reject(new Error(`Error making HTTP request: ${e.message}`)); }); }); diff --git a/typescript/r2pipe/index.ts b/typescript/r2pipe/index.ts index 0f3b6bc..effa9b5 100644 --- a/typescript/r2pipe/index.ts +++ b/typescript/r2pipe/index.ts @@ -1,4 +1,4 @@ -import {R2PipeBase, R2PipeCmdInterface} from "./base.js"; +import {R2PipeCmdInterface} from "./base.js"; import {R2PipeHttp} from "./http.js"; import {R2PipeSpawn} from "./spawn.js"; import {R2PipeLocal} from "./local.js"; diff --git a/typescript/r2pipe/local.ts b/typescript/r2pipe/local.ts index 577f00f..07d9d13 100644 --- a/typescript/r2pipe/local.ts +++ b/typescript/r2pipe/local.ts @@ -41,6 +41,7 @@ export class R2PipeLocal extends R2PipeBase { async quit(): Promise { this.stream.dispose(); this.stream = null; + process.kill(process.pid, 'SIGINT'); return true; } } diff --git a/typescript/r2pipe/queue.ts b/typescript/r2pipe/queue.ts index 260e6d0..d8beaa2 100644 --- a/typescript/r2pipe/queue.ts +++ b/typescript/r2pipe/queue.ts @@ -4,7 +4,7 @@ interface R2PipeQueueItem { cmd: string; result: string; cb: any; - error: any; + error: Error; } export class R2PipeQueue { @@ -24,7 +24,7 @@ export class R2PipeQueue { this.input.destroy(); this.output.destroy(); } - cmd(cmd: string, cb: Function) { + cmd(cmd: string, cb: any) { this.pipeQueue.push({ cmd: cmd, cb: cb, diff --git a/typescript/r2pipe/spawn.ts b/typescript/r2pipe/spawn.ts index 71a921c..fd9d8b9 100644 --- a/typescript/r2pipe/spawn.ts +++ b/typescript/r2pipe/spawn.ts @@ -16,11 +16,11 @@ export class R2PipeSpawn extends R2PipeBase { async cmd(command: string): Promise { return new Promise((resolve, reject) => { this.r2cb.cmd(command, (error, res) => { - if (error) { - reject(error); - } else { - resolve(res); - } + if (error) { + reject(error); + } else { + resolve(res); + } }); }); //return this.httpCmd(this.filePath, command); @@ -49,7 +49,7 @@ function pipeCmd(proc, cmd, cb) { } function pipeCmdOutput(proc, data, cb) { - var len = data.length; + let len = data.length; if (this.pipeQueue.length < 1) { return cb(new Error('r2pipe error: No pending commands for incomming data')); @@ -96,15 +96,6 @@ function r2bind(child, cb, r2cmd) { // addr must be a NativePointer not a number this.cmd(s + "@0x" + Number(addr).toString(16), cb2); }, - plugin: function (s, cb2) { - //throw new Exception("not implemented"); - }, - unload: function (s, cb2) { - // throw new Exception("not implemented"); - }, - log: function (msg) { - console.log(msg); - }, /* Run cmd and return plaintext output */ cmd: function (s, cb2) { pipeCmd.bind(r2)(child, s, cb2); @@ -172,7 +163,7 @@ function r2bind(child, cb, r2cmd) { child.on('close', function (code, signal) { running = false; - let error = errmsg ? errmsg : ''; + const error = errmsg ? errmsg : ''; if (signal) { cb(new Error('Child received signal ' + signal + '\n' + error)); } else {