diff --git a/zforth/README.md b/zforth/README.md new file mode 100644 index 0000000..a61803a --- /dev/null +++ b/zforth/README.md @@ -0,0 +1,26 @@ +# zForth for radare2 + +zforth is a minimalistic implementation of Forth that aims to be easy +to embed, simple and portable. + +This plugin exposes the forth interpreter to be used with radare2. + +Enter the zforth repl. + +``` +$ r2 -c '#!zforth' - +``` + +## Simple programs + +``` +1 3 + . 10 0 sys ( 10 0 sys is the same as printing \n char to stdout ) +``` + +## Using the r2cmd syscall + +``` +s" ?E Hello World " r2cmd tell nl +``` + + diff --git a/zforth/core.zf b/zforth/core.zf index 0e959ca..787d0ff 100644 --- a/zforth/core.zf +++ b/zforth/core.zf @@ -14,6 +14,19 @@ : nl 10 0 sys ; ( new line ) : drop2 drop drop ; +: place over over >r >r char+ swap chars cmove r> r> c! ; + +: append ( a1 n2 a2 --) + over over \ duplicate target and count + >r >r \ save them on the return stack + count chars + \ calculate offset target + swap chars move \ now move the source string + r> r> \ get target and count + dup >r \ duplicate target and save one + c@ + \ calculate new count + r> c! \ get address and store +; + ( dictionary access. These are shortcuts through the primitive operations are !!, @@ and ,, )