Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
118 lines (101 sloc) 3.92 KB
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
<title>Erasm++ - gendsm</title>
<link rel="stylesheet" type="text/css" href="./css/default.css"></link>
<link rel="stylesheet" type="text/css" href="./css/syntax.css"></link>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29123087-1']);
_gaq.push(['_setDomainName', 'erasmpp.org']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="main">
<div id="sidebar">
<div id="header">
<h1>Erasm++ </h1>
</div>
<!-- <h2>Navigation</h2> -->
<a href="./">About</a>
<ul>
<li> <a href="./erasm.html">ERASM++</a> </li>
<li> <a href="./gendsm.html">GenericDsm</a> </li>
<li> <a href="./meta_prelude.html">MetaPrelude</a> </li>
</ul>
<a href="./download.html">Download/Install</a>
<a href="./manual/manual.html">Online Manual</a>
<a href="./privacy.html">Privacy Policy</a>
</div>
<div id="content">
<h1 id="genericdsm">GenericDsm</h1>
<p>GenericDsm is a generic instruction decoder library for Intel 64/IA-32 architectures. Features include:</p>
<dl>
<dt>Speed.</dt>
<dd><p>Genericity allows specializing to user’s custom needs. In some cases, this leads to an instruction decoder which is more than an order of magnitude faster than non-generic instruction decoders written in C.</p>
</dd>
<dt>Pattern-matching against instructions.</dt>
<dd><p>GenericDsm allows you to “match” against mnemonics and operand types with no runtime overhead, contributing to cleaner and more efficient code.</p>
</dd>
<dt>No dependence on runtime systems.</dt>
<dd><p>Just like ERASM++, the main decoder functions of GenericDsm themselves do not depend on C/C++ runtime systems. They do not throw exceptions, reference vtables, or even allocate memory on the heap although users are free to do so.</p>
</dd>
<dt>Reentrant.</dt>
<dd><p>Since the decoder function itself only uses local stack-allocated variables, it is fully reentrant and thread-safe as long as the user-supplied actions are (assuming the decoded opcodes are constant, of course).</p>
</dd>
</dl>
<p>Here is a simple instruction counter on x86 processors which returns when RET or JMP instructions are encountered:</p>
<pre><code>#include &lt;erasm/dsm_x86_util.hpp&gt;
#include &lt;erasm/dsm_x86.hpp&gt;
#include &lt;iostream&gt;
using namespace std;
using namespace erasm::x86;
using namespace erasm::x86::addr32::data32;
struct MyCounter : public InstructionCounter
{
MyCounter(const_code_ptr start)
: InstructionCounter(start)
{}
// Let the base class handle the default cases
using InstructionCounter::action;
action_result_type
action(const Ret&amp; insn)
{
inc_counter();
return finish(insn);
}
template&lt;class Op&gt;
action_result_type
action(const Jmp&amp; insn,const Op&amp; op)
{
inc_counter();
return finish(insn);
}
};
int main()
{
const_code_ptr p = (const_code_ptr) main;
MyCounter mydsm(p);
const_code_ptr end = decode(p,mydsm);
if (mydsm.failed()) {
cerr &lt;&lt; &quot;Disassembly failed at:&quot;
&lt;&lt; hex &lt;&lt; (void*)end &lt;&lt; endl;
return 1;
}
cout &lt;&lt; &quot;number of instructions = &quot;
&lt;&lt; mydsm.get_counter() &lt;&lt; endl;
return 0;
}
</code></pre>
</div>
</dev>
</body>
</html>