/usr/share/doc/radare-doc/html/Section10.4.html is in radare-doc 1:1.5.2-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=US-ASCII">
<title>Language bindings</title>
<link rel="previous" href="Section10.3.2.html">
<link rel="ToC" href="contents.html">
<link rel="next" href="Section10.5.html">
</head>
<body>
<h1><a name="langs"></a>10.4 Language bindings</h1>
<p>
All language bindings supported by radare to script some actions are implemented as hack plugins.
</p>
<p>
LUA is probably the cleaner implementation of a language binding for radare, i recommend you to read the source at 'src/plug/hack/lua.c'. Here's the structure to register the plugin:
</p>
<pre><code>int radare_plugin_type = PLUGIN_TYPE_HACK;
struct plugin_hack_t radare_plugin = {
.name = "lua",
.desc = "lua plugin",
.callback = &lua_hack_cmd
};
</code></pre>
<p>
The 'lua_hack_cmd' accepts a string as argument which is the argument given when calling the plugin from the radare shell:
</p>
<pre><code>[0x00000000]> H lua my-script.lua
</code></pre>
<p>
If no arguments given, the plugin will loop in a prompt executing the lines given as lua statements.
</p>
<p>
The same happens with other language bindings like ruby, python or perl.
</p>
<p>
In the same directory where the plugins are installed, there's a "radare.py" or "radare.lua" which describes the API for that language.
</p>
<p>
The APIs in radare for language bindings are just wrappers for the basic 'r.cmd()' function handled by the core which is hooked to 'radare_cmd()'.
</p>
<p>
Here's a small part of radare.py to exemplify this:
</p>
<pre><code>def flag_get(name):
return r.cmd("? %s"%name).split(" ")[0].strip()
def flag_set(name, addr=None):
if addr == None:
r.cmd("f %s"%name)
else:
r.cmd("f %s @ 0xx"%name, addr)
def analyze_opcode(addr=None):
"""
Returns a hashtable containing the information of the analysis of the opcode in the current seek.
This is: 'opcode', 'size', 'type', 'bytes', 'offset', 'ref', 'jump' and 'fail'
"""
if addr == None:
return __str.to_hash(r.cmd("ao"))
return __str.to_hash(r.cmd("ao @ 0x%x"%addr))
</code></pre>
<p>
The use of these functions is quite natural:
</p>
<pre><code>from radare import *
aop = analyze_opcode(flag_get("eip"))
if aop["type"] == "jump":
print "Jumping to 0x%08x"%aop["jump"]
</code></pre>
<p>
Read the 'scripting' chapter to get a deeper look on this topic.
</p>
<p>
The clearest example about how to implement a language binding for radare is done in Ruby. Read it at src/plug/hack/ruby.c
</p>
<!-- version IDs:
$Id: radare.but 2009-04-25 pancake $
-->
</body>
</html>
|