-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## R2JS Plugins | ||
|
||
The javascript runtime embedded in radare2 provides a way to implement different types of plugins. | ||
|
||
Check out the `r2skel` project for more examples, but we will cover the basics now. | ||
|
||
```js | ||
(function () { | ||
r2.unload("core", "mycore"); | ||
r2.plugin("core", function () { | ||
console.log("==> The 'mycore' plugin has been instantiated. Type 'mycore' to test it"); | ||
function coreCall(cmd) { | ||
if (cmd.startsWith("mycore")) { | ||
console.log("Hello From My Core!"); | ||
return true; | ||
} | ||
return false; | ||
} | ||
return { | ||
"name": "mycore", | ||
"license": "MIT", | ||
"desc": "simple core plugin in typescript for radare2", | ||
"call": coreCall, | ||
}; | ||
}); | ||
})(); | ||
``` | ||
|
||
Some notes on this code: | ||
|
||
* The whole code is wrapped inside an anonymous function call, this way we don't polute the global scope. | ||
* Use r2.unload() and r2.plugin() to unload and register new plugins | ||
* Register a plugin by passing the plugin type and a function | ||
* The initialization function returns a object describing it | ||
|
||
This code runs inside radare2, this means that it will be *fast*, and by fast I mean faster than Python, r2pipe and will be closer to the `C` plugins. Not just for running, but also for loading, because the js runtime is already there, use r2js plugins if possible if you care about performance. | ||
|
||
You can find other plugin examples in the examples directory in radare2. |