taybenlor / runno

Browser-based runtime for programming languages and WASI binaries.

Home Page:https://runno.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for radare2

trufae opened this issue · comments

radare2 is a widely known commandline tool for reverse engineering which is actively developed and

I'm looking forward to get support for radare2 in runno for two different purposes:

  • write interactive changelogs (on a website that embeds runno, containing an r2 script and let users modify it and run it to see the output)
  • have a website like it was https://webassembly.sh, but it got broken after latest wapm changes.

For now I would like to focus on the first point, because i think it should be feasible, and maybe make it official to "runno" so it would be as easy as selecting "radare2" as the language. Ideally it should be also possible to add custom files in the filesystem (or write the script to run as a file in there).

I can confirm that radare2 wapm builds work well in https://runno.dev/wasi i can pass arguments, use stdin, set environment or add files to the filesystem. I'm not sure if I really need to report that here or if it's already possible if the package is already published via wapm

You can download the release builds (wasm files compiled with the wasi sdk) in the release page https://github.com/radareorg/radare2/releases/tag/5.8.8 but it's also available via wasmer, but having the ability to let users run it in the browser would be ideal (like i did before wasmer broke everything again).

I would like to have some insights on this as I think other people can also benefit from running r2 scripts inside the browser

Hey @trufae! Thanks for dropping this in. radare2 looks like a super useful tool, but probably isn't the right fit for a programming language on Runno. However that doesn't mean you can't use Runno to run it!

I wrote an article Running WASI binaries from your HTML using Web Components about how to run your own WASI binaries from HTML. You should be able to use this to run radare2 if you have a working WASI binary for it!

The article goes through how to use the WASI Web Component, including adding controls, and specifying the file system.

Does that solve your problem?

Radare2 have it's own scripting capabilties, as well as it's also integrating the quickjs runtime having access to all the internal features of the tool. So it can be kind-of considered a "language" too. But I understand that maybe a bit out of context for the project.

I've never used web components and i have already read the article, tried building the examples (without success) and I still miss some steps or commands to run to get a hello world to work. It is possible to just download a precompiled css/js and embed it into a plain html file to use it?

Having the ability to use this component will clearly work for me!

Thanks!

Ahh of course! You'd do plain HTML, no bundler, with https://www.unpkg.com/. I'm too busy right now to write up an example, but could you see if there's enough there for you? If not I'll write up a codepen soon.

I found a different way to get this to work by using the api instead of the web component:

I wrote a proof of concept here: https://radare.org/w

So this works for me but i agree that it would be great if you could provide a more direct way to use the runno component.

I can download the script to not depend on third party servers to make this work too.

I guess you can close this ticket now as long as it works for my needs now :)

the only question I have (which i can probably solve if i play a little more) is about handling the stdin in an async way. Aka simulating the whole tty, the stdin callback takes the data when requested instead of when available. But that’s probably unrelated to this ticket.

thank you!

Having a quick play it seems like I'm not shipping a JS build that can be used without a bundler or import. My apologies!

In modern browsers you can do something like this:

<script type="module">import "https://cdn.jsdelivr.net/npm/@runno/runtime@0.6.2/dist/runtime.js";</script>
<runno-wasi src="https://radare.org/w/radare2.wasm?v=5.8.8" controls></runno-wasi>

You'll need SharedArrayBuffer for that to work, see Quickstart.

It depends on the browser having support for modules, but they are pretty widely supported now.

If you'd like to roll your own implementation, my docs for @runno/wasi explain how you can do async io. https://runno.dev/docs/wasi/

I'll close this, but I'm happy to answer further questions on the Discussions page

Thank you! <3