22.6 forum: Scripting with lua

Radare can be scripted using lua in a very simple way.

You can call the scripts in batch mode using the -i flag of radare or just calling it using the lua 'hack' plugin.

$ radare -i myscript.lua /bin/ls


radare /bin/ls
> H lua myscript.lua

Take care about having liblua5.1-dev installed in your system and lua.so is properly build and installed.

There's an API provided by LIBDIR/radare/radare.lua where you will easily find the way to call radare commands from lua and viceversa.

There are a lot of tutorials about lua, so I will focus on the use for radare.

I will increase this article while I have some time, ask me your questions and proposals for the scripting on this thread.

Here's a little example searching:

-- search lib and show results
local hits = Radare.Search.string("lib")
for i = 1, #hits do
        print(" => "..hits[i]..": "..Radare.cmd("pz @ "..hits[i]))

will show:

$ radare -vi search-demo.lua /bin/ls
 => 0x00000135: lib/ld-linux.so.2
 => 0x00000b71: librt.so.1
 => 0x00000f2a: libc_start_main

... more examples will come.. smile