Skip to content

Commit

Permalink
More cleanups and fixes for the async apis
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jun 21, 2024
1 parent 75a163d commit 82276bc
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
25 changes: 22 additions & 3 deletions typescript/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ SYNCREGEX+=-e 's/Promise<\(.*\)>/\1/'
lint:
$(ESLINT) async/*.ts

FILES=r2pipe r2papi opt esil shell base64 ai r2frida index

sync:
rm -rf sync/*.ts
cd async && cp -f r2pipe.ts r2papi.ts opt.ts esil.ts esil.ts shell.ts base64.ts ai.ts r2frida.ts index.ts ../sync
cd async && cp -f $(addsuffix .ts,$(FILES)) ../sync
for a in sync/*.ts ; do sed $(SYNCREGEX) -i=.bak $$a ; done
rm -f sync/*.bak
cp async/tsconfig.json sync
Expand All @@ -32,18 +34,33 @@ abuild: sync
cp -f async/*.ts build
cp -rf async/tsconfig.json build
cd build && $(TSC)
cd build && $(TSC) --declaration r2papi.ts
cd build && \
for a in $(FILES); do \
echo Compiling $$a.r2.js: ; $(TSC) -m node16 --target es2020 $$a.ts && cp -f $$a.js $$a.r2.js ; \
done

build: sync
rm -rf build
mkdir build
cp -f sync/*.ts build
cp -rf async/tsconfig.json build
cp -rf async/tsconfig.json build/tsconfig.json
cd build && $(TSC)
cd build && $(TSC) --declaration r2papi.ts
for a in $(FILES); do \
echo Compiling $$a.r2.js: ; \
(cd build && $(TSC) -m node16 --target es2020 $$a.ts && cp -f $$a.js $$a.r2.js ) ; \
done

buildjs:
cd build && $(TSC) -m node16 --target es2020 index.ts && cp -f index.js index.r2.js
cd build && $(TSC) -m node16 --target es2020 shell.ts && cp -f shell.js shell.r2.js
cd build && $(TSC) -m node16 --target es2020 ai.ts && cp -f ai.js ai.r2.js
cd build && $(TSC) -m node16 --target es2020 esil.ts && cp -f esil.js esil.r2.js
cd build && $(TSC) -m node16 --target es2020 opt.ts && cp -f opt.js opt.r2.js
cd build && $(TSC) -m node16 --target es2020 r2papi.ts && cp -f r2papi.js index.r2.js
cd build && $(TSC) -m node16 --target es2020 r2frida.ts && cp -f r2frida.js r2frida.r2.js
cd build && $(TSC) -m node16 --target es2020 base64.ts && cp -f base64.js base64.r2.js

.PHONY: sync build

Expand Down Expand Up @@ -96,8 +113,10 @@ webdoc:
rm -rf .tmp

npm publish pub:
$(MAKE) abuild
#-------------
# Publishing the sync api
$(MAKE)
$(MAKE) build
cp -f README.md package.json package-lock.json build
cd build && npm publish
# Publishing the async api
Expand Down
9 changes: 7 additions & 2 deletions typescript/async/r2frida.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { r2 } from "r2papi";
import { R2PipeAsync, newAsyncR2PipeFromSync } from "./r2pipe.js";
import { R2Pipe, R2PipeAsync, newAsyncR2PipeFromSync } from "./r2pipe.js";

declare global {
var r2: R2Pipe;
}

export class R2Frida {
isAvailable: boolean;
Expand All @@ -26,6 +29,7 @@ export class R2Frida {
}
}

/*
export async function main() {
console.log("Hello from r2papi-r2frida");
const r2async = newAsyncR2PipeFromSync(r2);
Expand All @@ -35,6 +39,7 @@ export async function main() {
console.log(pid, arch, cwd);
}
main();
*/

export interface TargetDetails {
arch: string;
Expand Down
8 changes: 7 additions & 1 deletion typescript/async/r2pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ export class R2PipeAsyncFromSync {
constructor(r2p: R2Pipe) {
this.r2p = r2p;
}
/**
* Run a command in the associated instance of radare2 and return the output as a string
*
* @param {string} command to be executed inside radare2.
* @returns {string} The output of the command execution
*/
async cmd(command: string): Promise<string> {
return this.r2p.cmd(command);
}
Expand Down Expand Up @@ -51,7 +57,7 @@ export function newAsyncR2PipeFromSync(r2p: R2Pipe): R2PipeAsync {
*/
export interface R2Pipe {
/**
* Run a command in the associated instance of radare2
* Run a command in the associated instance of radare2 and return the output as a string
*
* @param {string} command to be executed inside radare2.
* @returns {string} The output of the command execution
Expand Down
7 changes: 4 additions & 3 deletions typescript/async/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es2017",
"lib": ["es2015", "es2016", "esnext"],
"target": "es2020",
"lib": ["es2020", "esnext"],
"module": "commonjs",
"esModuleInterop": true,
"resolveJsonModule": true,
Expand All @@ -17,6 +17,7 @@
"r2pipe.ts",
"r2papi.ts",
"esil.ts",
"shell.ts"
"shell.ts",
"r2frida.ts"
]
}
5 changes: 4 additions & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2papi",
"version": "0.4.7",
"version": "0.4.9",
"description": "r2api on top of r2pipe for typescript and js",
"author": "[email protected]",
"homepage": "http://www.radare.org",
Expand Down Expand Up @@ -46,6 +46,9 @@
"index.js",
"index.ts",
"index.d.js",
"r2frida.js",
"r2frida.ts",
"r2frida.d.js",
"base64.js",
"base64.ts",
"base64.d.js",
Expand Down

0 comments on commit 82276bc

Please sign in to comment.