Skip to content

Commit

Permalink
Make use of the toJSON() for R2Papi and NativePointer for TS
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Oct 23, 2023
1 parent dcead47 commit 0860df8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,17 @@ export class Assembler {
toString() {
return this.program;
}
append(x:string) {
append(x: string) {
this.pc += x.length / 2;
this.program += x;
}
// api
label(s:string) : number {
label(s: string) : number {
const pos = this.pc; // this.#program.length / 4;
this.labels[s] = this.pc;
return pos;
}
asm(s:string) {
asm(s: string) {
let hex = this.r2.cmd('""pa ' + s).trim();
if (hex.length < 16) {
// ok
Expand All @@ -343,6 +343,12 @@ export class R2Papi {
constructor(r2: R2Pipe) {
this.r2 = r2;
}
toString() {
return "[object R2Papi]";
}
toJSON() {
return this.toString();
}
getBaseAddress(): NativePointer {
return new NativePointer(this.cmd("e bin.baddr"));
}
Expand Down Expand Up @@ -374,7 +380,7 @@ export class R2Papi {
this.cmd("-b "+bits);
}
}
setFlagSpace(name:string) {
setFlagSpace(name: string) {
this.cmd('fs ' + name);
}
setLogLevel(level: number) : R2Papi {
Expand Down Expand Up @@ -810,7 +816,10 @@ export class NativePointer {
pointsToNull(): boolean {
return this.readPointer().compare(0);
}
toString() :string {
toJSON() : string {
return this.toString();
}
toString() : string {
return this.addr.trim();
}
writePointer(p: NativePointer) : void {
Expand Down
4 changes: 2 additions & 2 deletions typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2papi",
"version": "0.2.2",
"version": "0.2.3",
"description": "r2api on top of r2pipe for typescript and js",
"author": "",
"homepage": "http://www.radare.org",
Expand Down

0 comments on commit 0860df8

Please sign in to comment.