From b55d894cc624486a6260e6410d7634bb69749869 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 23 Jan 2024 18:57:06 +0100 Subject: [PATCH] make lint with eslint --- typescript/Makefile | 3 ++- typescript/async/base64.ts | 2 +- typescript/async/esil.ts | 32 +++++++++++++++---------------- typescript/async/graph.ts | 4 ++-- typescript/async/index.ts | 2 +- typescript/async/opt.ts | 6 +++--- typescript/async/pdq.ts | 22 +++++++++++---------- typescript/async/r2frida.ts | 2 +- typescript/async/r2papi.ts | 38 ++++++++++++++++++------------------- typescript/async/r2pipe.ts | 4 ++-- typescript/async/shell.ts | 6 +++--- 11 files changed, 62 insertions(+), 59 deletions(-) diff --git a/typescript/Makefile b/typescript/Makefile index c30f76f..eacd7e7 100644 --- a/typescript/Makefile +++ b/typescript/Makefile @@ -16,7 +16,8 @@ SYNCREGEX+=-e 's,R2PapiAsync,R2PapiSync,g' SYNCREGEX+=-e 's/Promise<\(.*\)>/\1/' lint: - eslint async/*.ts + eslint --fix async/*.ts +#eslint async/*.ts sync: rm -rf sync/*.ts diff --git a/typescript/async/base64.ts b/typescript/async/base64.ts index 351c3cc..143c8a6 100644 --- a/typescript/async/base64.ts +++ b/typescript/async/base64.ts @@ -23,4 +23,4 @@ export interface Base64Interface { (message: string, decode?: boolean): string; } -export declare var b64: Base64Interface; +export declare const b64: Base64Interface; diff --git a/typescript/async/esil.ts b/typescript/async/esil.ts index bd869cc..91c6e83 100644 --- a/typescript/async/esil.ts +++ b/typescript/async/esil.ts @@ -1,7 +1,7 @@ import { R2PipeAsync } from "./r2pipe.js"; -declare var console: any; -declare var r2: R2PipeAsync; +declare let console: any; +declare let r2: R2PipeAsync; // ("this is just a comment"), -- comments are also part of the runtime @@ -62,7 +62,7 @@ export class EsilNode { if (left !== "") { left += ","; } - let right = this.rhs.toEsil(); + const right = this.rhs.toEsil(); return `${right},${left}${this.token}`; } return ''; // this.token.text; @@ -84,13 +84,13 @@ export class EsilNode { str += "goto label_" + children.token.position + ";\n"; } else { // console.log(JSON.stringify(this,null, 2)); - let pos = 0; + const pos = 0; str += `goto label_${pos};\n`; } } if (this.children.length > 0) { str += ` (if (${this.rhs})\n`; - for (let children of this.children) { + for (const children of this.children) { if (children !== null) { const x = children.toString(); if (x != "") { @@ -189,7 +189,7 @@ export class EsilParser { // console.log("done"); } async parseFunction(addr?: string) : Promise { - var ep = this; + const ep = this; async function parseAmount(n:number) : Promise { // console.log("PDQ "+n); const output = await r2.cmd("pie " + n + " @e:scr.color=0"); @@ -218,7 +218,7 @@ export class EsilParser { addr = oaddr; } const bbs = await r2.cmdj(`afbj@${addr}`); // XXX this command changes the current seek - for (let bb of bbs) { + for (const bb of bbs) { // console.log("bb_" + bb.addr + ":"); await r2.cmd(`s ${bb.addr}`); await parseAmount (bb.ninstr); @@ -228,7 +228,7 @@ export class EsilParser { parse(expr: string, addr?: string) : void | never { const tokens = expr.trim().split(',').map( (x) => x.trim() ); const from = this.tokens.length; - for (let tok of tokens) { + for (const tok of tokens) { const token = new EsilToken(tok, this.tokens.length); if (addr !== undefined) { token.addr = addr; @@ -309,7 +309,7 @@ export class EsilParser { if (tok === undefined) { return null; } - for (let node of this.nodes) { + for (const node of this.nodes) { if (node.token.position === index) { return node; } @@ -318,7 +318,7 @@ export class EsilParser { return null; } private findNodeFor(index:number): null | EsilNode { - for (let node of this.nodes) { + for (const node of this.nodes) { if (node.token.position === index) { return node; } @@ -359,10 +359,9 @@ export class EsilParser { // no pops or nothing, just does nothing return true; case "DUP": - if (true) { - if (this.stack.length < 1) { - throw new Error("goto cant pop"); - } + if (this.stack.length < 1) { + throw new Error("goto cant pop"); + } else { const destNode = this.stack.pop()!; this.stack.push(destNode); this.stack.push(destNode); @@ -370,6 +369,7 @@ export class EsilParser { return true; case "GOTO": // take previous statement which should be const and add a label + { const prev = this.peek(expr.position - 1); if (prev !== null) { // TODO: check stack @@ -398,6 +398,7 @@ export class EsilParser { } } } + } return true; // controlflow case "?{": // ESIL_TOKEN_IF @@ -406,7 +407,7 @@ export class EsilParser { const i1 = this.stack.pop()!; const nn = new EsilNode(expr, "operation"); nn.setSides(i0, i1); // left side can be ignored for now.. but we can express this somehow - let trueBlock = this.parseUntil(expr.position); + const trueBlock = this.parseUntil(expr.position); let falseBlock = null; // nn.addChildren(trueBlock, falseBlock); if (trueBlock !== null) { @@ -501,4 +502,3 @@ export class EsilParser { return false; } } - diff --git a/typescript/async/graph.ts b/typescript/async/graph.ts index 11b7188..7244111 100644 --- a/typescript/async/graph.ts +++ b/typescript/async/graph.ts @@ -1,4 +1,4 @@ -declare var r2: any; +declare let r2: any; class Graph { constructor () { @@ -38,7 +38,7 @@ class Graph { } export async function main() { - var g = new Graph(); + const g = new Graph(); await g.addNode("hello", "World"); await g.addNode("world", "Hello"); diff --git a/typescript/async/index.ts b/typescript/async/index.ts index 588aa0a..4590783 100644 --- a/typescript/async/index.ts +++ b/typescript/async/index.ts @@ -5,4 +5,4 @@ export { R, NativePointer, R2Papi, Reference, BasicBlock, ThreadClass } from "./ export { EsilNode, EsilParser } from "./esil.js"; export { Base64, Base64Interface } from "./base64.js"; -export declare var r2: R2PipeAsync; +export declare const r2: R2PipeAsync; diff --git a/typescript/async/opt.ts b/typescript/async/opt.ts index 90bae17..32c8678 100644 --- a/typescript/async/opt.ts +++ b/typescript/async/opt.ts @@ -3,13 +3,13 @@ import { EsilParser } from "./esil"; // Type 'R2Pipe' is missing the following properties from type 'R2Pipe': cmdj, callj, plugin, unload // import { R2Pipe } from "./r2pipe"; -declare var r2 : any; +declare let r2 : any; export function plusZero() { } function traverse(ep: EsilParser, child: any) { - for (let child of ep.nodes) { + for (const child of ep.nodes) { if (child) { traverse(ep, child); } @@ -17,7 +17,7 @@ function traverse(ep: EsilParser, child: any) { } } -var ep = new EsilParser(r2); +const ep = new EsilParser(r2); ep.parseFunction(); ep.parse("0,eax,+,ebx,:="); traverse(ep, null); diff --git a/typescript/async/pdq.ts b/typescript/async/pdq.ts index 9436c2f..ec44495 100644 --- a/typescript/async/pdq.ts +++ b/typescript/async/pdq.ts @@ -1,8 +1,8 @@ import { R2PipeAsync } from "./index"; import { EsilParser } from "./esil"; -declare var r2: R2PipeAsync; -declare var r2plugin: any; +declare let r2: R2PipeAsync; +declare let r2plugin: any; /// ========== main =========== /// const ep = new EsilParser(r2); @@ -40,15 +40,17 @@ async function pdq(arg:string) { case "f": case undefined: case "": - const oaddr = (await r2.cmd("?v $$")).trim(); - // const func = r2.cmdj("pdrj"); // XXX this command changes the current seek - const bbs = await r2.cmdj("afbj"); // XXX this command changes the current seek - for (let bb of bbs) { - console.log("bb_" + bb.addr + ":"); - r2.cmd(`s ${bb.addr}`); - await parseAmount (bb.ninstr); + { + const oaddr = (await r2.cmd("?v $$")).trim(); + // const func = r2.cmdj("pdrj"); // XXX this command changes the current seek + const bbs = await r2.cmdj("afbj"); // XXX this command changes the current seek + for (const bb of bbs) { + console.log("bb_" + bb.addr + ":"); + r2.cmd(`s ${bb.addr}`); + await parseAmount (bb.ninstr); + } + r2.cmd(`s ${oaddr}`); } - r2.cmd(`s ${oaddr}`); break; case "e": ep.reset (); diff --git a/typescript/async/r2frida.ts b/typescript/async/r2frida.ts index f7b065b..77ba696 100644 --- a/typescript/async/r2frida.ts +++ b/typescript/async/r2frida.ts @@ -62,4 +62,4 @@ export interface TargetDetails { homedir: string; tmpdir: string; bundledir?:any; -}; +} diff --git a/typescript/async/r2papi.ts b/typescript/async/r2papi.ts index afcab8c..c6a8fa8 100644 --- a/typescript/async/r2papi.ts +++ b/typescript/async/r2papi.ts @@ -13,20 +13,20 @@ export interface SearchResult { offset: number; // TODO: rename to addr type: string; data: string; -}; +} export interface DebugModule { base: string; name: string; path: string; size: number; -}; +} export interface Flag { name: string; size: number; offset: number; -}; +} export type PluginFamily = "core" | "io" | "arch" | "esil" | "lang" | "bin" | "debug" | "anal" | "crypto"; @@ -42,9 +42,9 @@ export interface CallRef { addr: number; type: string; at: number; -}; +} -export interface Function { +export interface FunctionDetails { offset: number; name: string; size: number; @@ -55,7 +55,7 @@ export interface Function { nbbs: number; callrefs: CallRef[]; codexrefs: CallRef[]; -}; +} export interface BinFile { arch: string; @@ -80,7 +80,7 @@ export interface BinFile { linenum: boolean; havecode: boolean; intrp: string; -}; +} export interface Reference { from: number; @@ -91,7 +91,7 @@ export interface Reference { fcn_name: string; realname: string; refname: string; -}; +} export interface BasicBlock { addr: number, @@ -104,7 +104,7 @@ export interface BasicBlock { ninstr: number, instrs: number[], traced: boolean -}; +} export class ThreadClass { api: any = null; @@ -395,7 +395,7 @@ export class R2PapiAsync { if (a.length && a.length > 0) { a = a[0]; } - for (let k of Object.keys(a)) { + for (const k of Object.keys(a)) { const typ = typeof (a[k]); const nam = k; str += ` ${nam}: ${typ};\n`; @@ -587,7 +587,7 @@ export class R2PapiAsync { return this.id(); } setRegisters(obj: any) { - for (let r of Object.keys(obj)) { + for (const r of Object.keys(obj)) { const v = obj[r]; this.r2.cmd("dr " + r + "=" + v); } @@ -746,7 +746,7 @@ export class R2PapiAsync { async enumerateRelocations(): Promise { return this.callj("irj"); } - async enumerateFunctions(): Promise { + async enumerateFunctions(): Promise { return this.cmdj("aflj"); } async enumerateFlags(): Promise { @@ -856,7 +856,7 @@ export class NativePointer { * @returns {string} string containing the hexadecimal dump of memory */ async hexdump(length?: number): Promise { - let len = (length === undefined) ? "" : "" + length; + const len = (length === undefined) ? "" : "" + length; return this.api.cmd(`x${len}@${this.addr}`); } async functionGraph(format?: GraphFormat): Promise { @@ -1082,7 +1082,7 @@ export class NativePointer { return output[0] as Instruction; } async disassemble(length?: number): Promise { - let len = (length === undefined) ? "" : "" + length; + const len = (length === undefined) ? "" : "" + length; return this.api.cmd(`pd ${len}@${this.addr}`); } async analyzeFunction(): Promise { @@ -1105,7 +1105,7 @@ export class NativePointer { const name = await this.api.cmd("isj.@" + this.addr); return name.trim(); } - async getFunction(): Promise { + async getFunction(): Promise { return this.api.cmdj("afij@" + this.addr); } async basicBlock(): Promise { @@ -1132,7 +1132,7 @@ function ptr(x: string|number) { * * @type R2Papi */ -export declare var R: R2Papi; +export declare const R: R2Papi; /** * Global instance of the Module class based on the current radare2 session. @@ -1140,7 +1140,7 @@ export declare var R: R2Papi; * * @type ModuleClass */ -export declare var Module: ModuleClass; +export declare const Module: ModuleClass; /** * Global instance of the Process class based on the current radare2 session. @@ -1148,7 +1148,7 @@ export declare var Module: ModuleClass; * * @type ProcessClass */ -export declare var Process: ProcessClass; +export declare const Process: ProcessClass; /** * Global instance of the Thread class based on the current radare2 session. @@ -1156,4 +1156,4 @@ export declare var Process: ProcessClass; * * @type ThreadClass */ -export declare var Thread: ThreadClass; +export declare const Thread: ThreadClass; diff --git a/typescript/async/r2pipe.ts b/typescript/async/r2pipe.ts index cc89c61..21c79cf 100644 --- a/typescript/async/r2pipe.ts +++ b/typescript/async/r2pipe.ts @@ -26,7 +26,7 @@ export class R2PipeAsyncFromSync { } async plugin(type: string, maker: any): Promise { return this.r2p.plugin(type, maker); - }; + } async unload(type: string, name: string): Promise { return this.r2p.unload(type, name); } @@ -214,4 +214,4 @@ export interface R2PipeAsync { * * @type {R2PipeSync} */ -export declare var r2: R2Pipe; +export declare const r2: R2Pipe; diff --git a/typescript/async/shell.ts b/typescript/async/shell.ts index 0abffc8..9889c9d 100644 --- a/typescript/async/shell.ts +++ b/typescript/async/shell.ts @@ -59,9 +59,9 @@ export class R2Shell { * @param {R2Papi} take the R2Papi intance to used as backend to run the commands * @returns {R2Shell} instance of the shell api */ - constructor(papi: R2Papi) { - this.rp = papi; - } + constructor(papi: R2Papi) { + this.rp = papi; + } /** * Create a new directory in the host system, if the opational recursive argument is set to