I have just added support for labels in macros to allow radare scripting be
able to make loops and other nice control-flow structures in a very
simple way..
well.. the simple way is at programatic level, but the macro code it is
a bit
longer than its pseudocode...but it works and it is useful as shit.
Here there are two macro implementations for a user-defined disassembler:
(disasm-recursive times
? $0 == 0
?? ()
pd 1
s +$$$
.(disasm-recursive $0-1))
The problem with the recursive implementation is that will easily eat
the stack if you
plan to feed the macro with a large number as argument.
So now it is possible to write the same loop in an iterative format:
(disasm-iterative x
f foo @ $0
label:
pd 1
s +$$$
f foo @ foo-1
? foo != 0
??.label:
)
I know that this syntax looks like a mix of lisp, perl and brainfuck :)
cool huh? ;)
Let's explain a bit how they work:
(disasm-recursive times
? $0 == 0 ; check if arg0 == 0
?? () ; if matches break
pd 1 ; disassemble 1 opcode
s +$$$ ; seek curseek+opcodesize
.(disasm-recursive $0-1)) ; recursive call to me
And now the iterative:
(disasm-iterative x
f foo @ $0 ; foo = arg0
label: ; define label
pd 1 ; disasm 1 opcode
s +$$$ ; seek to next opcode
f foo @ foo-1 ; foo--
? foo != 0 ; if (foo != 0)
??.label: ; goto label
)
Enjoy! :)
_______________________________________________
radare mailing list
[email protected]
http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org