Skip to content

Commit

Permalink
make lint with eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jan 23, 2024
1 parent 32b575a commit b55d894
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 59 deletions.
3 changes: 2 additions & 1 deletion typescript/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion typescript/async/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export interface Base64Interface {
(message: string, decode?: boolean): string;
}

export declare var b64: Base64Interface;
export declare const b64: Base64Interface;
32 changes: 16 additions & 16 deletions typescript/async/esil.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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;
Expand All @@ -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 != "") {
Expand Down Expand Up @@ -189,7 +189,7 @@ export class EsilParser {
// console.log("done");
}
async parseFunction(addr?: string) : Promise<void> {
var ep = this;
const ep = this;
async function parseAmount(n:number) : Promise<void> {
// console.log("PDQ "+n);
const output = await r2.cmd("pie " + n + " @e:scr.color=0");
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -359,17 +359,17 @@ 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);
}
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
Expand Down Expand Up @@ -398,6 +398,7 @@ export class EsilParser {
}
}
}
}
return true;
// controlflow
case "?{": // ESIL_TOKEN_IF
Expand All @@ -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) {
Expand Down Expand Up @@ -501,4 +502,3 @@ export class EsilParser {
return false;
}
}

4 changes: 2 additions & 2 deletions typescript/async/graph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare var r2: any;
declare let r2: any;

class Graph {
constructor () {
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion typescript/async/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions typescript/async/opt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ 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);
}
traverse(ep, child);
}
}

var ep = new EsilParser(r2);
const ep = new EsilParser(r2);
ep.parseFunction();
ep.parse("0,eax,+,ebx,:=");
traverse(ep, null);
Expand Down
22 changes: 12 additions & 10 deletions typescript/async/pdq.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion typescript/async/r2frida.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ export interface TargetDetails {
homedir: string;
tmpdir: string;
bundledir?:any;
};
}
38 changes: 19 additions & 19 deletions typescript/async/r2papi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand All @@ -55,7 +55,7 @@ export interface Function {
nbbs: number;
callrefs: CallRef[];
codexrefs: CallRef[];
};
}

export interface BinFile {
arch: string;
Expand All @@ -80,7 +80,7 @@ export interface BinFile {
linenum: boolean;
havecode: boolean;
intrp: string;
};
}

export interface Reference {
from: number;
Expand All @@ -91,7 +91,7 @@ export interface Reference {
fcn_name: string;
realname: string;
refname: string;
};
}

export interface BasicBlock {
addr: number,
Expand All @@ -104,7 +104,7 @@ export interface BasicBlock {
ninstr: number,
instrs: number[],
traced: boolean
};
}

export class ThreadClass {
api: any = null;
Expand Down Expand Up @@ -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`;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -746,7 +746,7 @@ export class R2PapiAsync {
async enumerateRelocations(): Promise<any> {
return this.callj("irj");
}
async enumerateFunctions(): Promise<Function[]> {
async enumerateFunctions(): Promise<FunctionDetails[]> {
return this.cmdj("aflj");
}
async enumerateFlags(): Promise<Flag[]> {
Expand Down Expand Up @@ -856,7 +856,7 @@ export class NativePointer {
* @returns {string} string containing the hexadecimal dump of memory
*/
async hexdump(length?: number): Promise<string> {
let len = (length === undefined) ? "" : "" + length;
const len = (length === undefined) ? "" : "" + length;
return this.api.cmd(`x${len}@${this.addr}`);
}
async functionGraph(format?: GraphFormat): Promise<string> {
Expand Down Expand Up @@ -1082,7 +1082,7 @@ export class NativePointer {
return output[0] as Instruction;
}
async disassemble(length?: number): Promise<string> {
let len = (length === undefined) ? "" : "" + length;
const len = (length === undefined) ? "" : "" + length;
return this.api.cmd(`pd ${len}@${this.addr}`);
}
async analyzeFunction(): Promise<NativePointer> {
Expand All @@ -1105,7 +1105,7 @@ export class NativePointer {
const name = await this.api.cmd("isj.@" + this.addr);
return name.trim();
}
async getFunction(): Promise<Function> {
async getFunction(): Promise<FunctionDetails> {
return this.api.cmdj("afij@" + this.addr);
}
async basicBlock(): Promise<BasicBlock> {
Expand All @@ -1132,28 +1132,28 @@ 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.
* This variable mimics the same APIs shipped by Frida.
*
* @type ModuleClass
*/
export declare var Module: ModuleClass;
export declare const Module: ModuleClass;

/**
* Global instance of the Process class based on the current radare2 session.
* This variable mimics the same APIs shipped by Frida.
*
* @type ProcessClass
*/
export declare var Process: ProcessClass;
export declare const Process: ProcessClass;

/**
* Global instance of the Thread class based on the current radare2 session.
* This variable mimics the same APIs shipped by Frida.
*
* @type ThreadClass
*/
export declare var Thread: ThreadClass;
export declare const Thread: ThreadClass;
Loading

0 comments on commit b55d894

Please sign in to comment.