Skip to content

Commit

Permalink
Add r2bolt PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed May 4, 2023
1 parent 6f7d02b commit ecfee39
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions www/bolt/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PWD=$(shell pwd)
all:
r2 -qcq -e http.sandbox=false -e http.root=${PWD} -c=H -
38 changes: 38 additions & 0 deletions www/bolt/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<html>
<script src="r2.js"></script>
<script>
let cflags = '';
let compiler = "gcc -S";
const $ = (x) => document.getElementById(x);
function compile() {
const cc = btoa($('compiler').value);
const cs = btoa($('source').value);
const cmd = `""!!sh ./r2bolt.sh '' '${cs}'`;
r2.cmd(cmd, (res) => {
if (res.trim()) {
$('output').innerHTML = res;
}
});
}
compile();
</script>
<body>
<table width="100%">
<tr>
<td colspan=2>
<input type="button" value="r2bolt" onclick="javascript:compile()"></input>
<input id="compiler" value="gcc -S" /></td>
</tr>
<tr>
<td valign="top">
<textarea rows=20 id="source" onkeyup="compile()">
#include &lt;stdio.h&gt;
int main() {
return 1 + 2;
}
</textarea></td>
<td><div id="output" style="font-size:0.7em;font-family:Courier;white-space: pre;"></div></td>
</tr>
</table>
</body>
</html>
1 change: 1 addition & 0 deletions www/bolt/r2.js

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

28 changes: 28 additions & 0 deletions www/bolt/r2bolt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# arg1 = compiler+flags
# arg2 = base64(source)

if [ -z "$1" ]; then
CC="gcc -S"
else
CC="`rax2 -D $1`"
fi
if [ -z "$2" ]; then
CS="main() {}"
else
CS="`rax2 -D $2`"
fi

USE_R2=1
if [ "$USE_R2" = 1 ]; then
echo "$CS" > .a.c
gcc -o a.out .a.c
# r2 -qcq -e scr.color=0 -e asm.lines=0 -e asm.bytes=0 -c'pD $SS@$S;aa;agf' a.out
r2 -qcq -e scr.color=0 -e asm.lines=0 -e asm.bytes=0 -c'af;agf' a.out
rm -f .a.c a.out
else
echo "$CS" > .a.c
$CC .a.c
cat .a.s
rm -f .a.s .a.c
fi

0 comments on commit ecfee39

Please sign in to comment.