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" "">
<html xmlns="" xml:lang="en" lang="en">
<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', '']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
<div id="main">
<div id="sidebar">
<div id="header">
<h1>Erasm++ </h1>
<!-- <h2>Navigation</h2> -->
<a href="./">About</a>
<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>
<a href="./download.html">Download/Install</a>
<a href="./manual/manual.html">Online Manual</a>
<a href="./privacy.html">Privacy Policy</a>
<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>
<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>
<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>
<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><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>
<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(const Ret&amp; insn)
return finish(insn);
template&lt;class Op&gt;
action(const Jmp&amp; insn,const Op&amp; op)
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;