wasmer/rustdoc/goblin/index.html
2019-09-06 15:57:44 -07:00

92 lines
15 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `goblin` crate."><meta name="keywords" content="rust, rustlang, rust-lang, goblin"><title>goblin - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../goblin/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate goblin</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all goblin's items</p></a><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#functions">Functions</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'goblin', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/goblin/lib.rs.html#1-369' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>goblin</a></span></h1><div class='docblock'><h1 id="libgoblin" class="section-header"><a href="#libgoblin">libgoblin</a></h1>
<p><img src="https://s-media-cache-ak0.pinimg.com/736x/1b/6a/aa/1b6aaa2bae005e2fed84b1a7c32ecb1b.jpg" alt="say the right words" /></p>
<p><code>libgoblin</code> is a cross-platform trifecta of binary parsing and loading fun. It supports:</p>
<ul>
<li>An ELF32/64 parser, and raw C structs</li>
<li>A 32/64-bit, zero-copy, endian aware, Mach-o parser, and raw C structs</li>
<li>A PE32/PE32+ (64-bit) parser, and raw C structs</li>
<li>A Unix archive parser and loader</li>
</ul>
<p>Goblin requires at least <code>rustc</code> 1.31.1, uses the 2018 rust edition, and is developed on stable.</p>
<p>Goblin primarily supports the following important use cases:</p>
<ol>
<li>
<p>Core, std-free <code>#[repr(C)]</code> structs, tiny compile time, 32/64 (or both) at your leisure</p>
</li>
<li>
<p>Type punning. Define a function once on a type, but have it work on 32 or 64-bit variants - without really changing anything, and no macros! See <code>examples/automagic.rs</code> for a basic example.</p>
</li>
<li>
<p><code>std</code> mode. This throws in read and write impls via <code>Pread</code> and <code>Pwrite</code>, reading from file, convenience allocations, extra methods, etc. This is for clients who can allocate and want to read binaries off disk.</p>
</li>
<li>
<p><code>Endian_fd</code>. A truly terrible name :laughing: this is for binary analysis like in <a href="https://github.com/das-labor/panopticon">panopticon</a> which needs to read binaries of foreign endianness, <em>or</em> as a basis for constructing cross platform foreign architecture binutils, e.g. <a href="https://github.com/m4b/cargo-sym">cargo-sym</a> and <a href="https://github.com/m4b/bingrep">bingrep</a> are simple examples of this, but the sky is the limit.</p>
</li>
</ol>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">goblin</span>::{<span class="ident">error</span>, <span class="ident">Object</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">path</span>::<span class="ident">Path</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">env</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">File</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::<span class="ident">Read</span>;
<span class="kw">fn</span> <span class="ident">run</span> () <span class="op">-</span><span class="op">&gt;</span> <span class="ident">error</span>::<span class="prelude-ty">Result</span><span class="op">&lt;</span>()<span class="op">&gt;</span> {
<span class="kw">for</span> (<span class="ident">i</span>, <span class="ident">arg</span>) <span class="kw">in</span> <span class="ident">env</span>::<span class="ident">args</span>().<span class="ident">enumerate</span>() {
<span class="kw">if</span> <span class="ident">i</span> <span class="op">=</span><span class="op">=</span> <span class="number">1</span> {
<span class="kw">let</span> <span class="ident">path</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="ident">arg</span>.<span class="ident">as_str</span>());
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">fd</span> <span class="op">=</span> <span class="ident">File</span>::<span class="ident">open</span>(<span class="ident">path</span>)<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="ident">Vec</span>::<span class="ident">new</span>();
<span class="ident">fd</span>.<span class="ident">read_to_end</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">buffer</span>)<span class="question-mark">?</span>;
<span class="kw">match</span> <span class="ident">Object</span>::<span class="ident">parse</span>(<span class="kw-2">&amp;</span><span class="ident">buffer</span>)<span class="question-mark">?</span> {
<span class="ident">Object</span>::<span class="ident">Elf</span>(<span class="ident">elf</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;elf: {:#?}&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">elf</span>);
},
<span class="ident">Object</span>::<span class="ident">PE</span>(<span class="ident">pe</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;pe: {:#?}&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">pe</span>);
},
<span class="ident">Object</span>::<span class="ident">Mach</span>(<span class="ident">mach</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;mach: {:#?}&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">mach</span>);
},
<span class="ident">Object</span>::<span class="ident">Archive</span>(<span class="ident">archive</span>) <span class="op">=</span><span class="op">&gt;</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;archive: {:#?}&quot;</span>, <span class="kw-2">&amp;</span><span class="ident">archive</span>);
},
<span class="ident">Object</span>::<span class="ident">Unknown</span>(<span class="ident">magic</span>) <span class="op">=</span><span class="op">&gt;</span> { <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;unknown magic: {:#x}&quot;</span>, <span class="ident">magic</span>) }
}
}
}
<span class="prelude-val">Ok</span>(())
}</pre></div>
<h1 id="feature-usage" class="section-header"><a href="#feature-usage">Feature Usage</a></h1>
<p><code>libgoblin</code> is engineered to be tailored towards very different use-case scenarios, for example:</p>
<ul>
<li>a no-std mode; just simply set default features to false</li>
<li>a endian aware parsing and reading</li>
<li>for binary loaders which don't require this, simply use <code>elf32</code> and <code>elf64</code> (and <code>std</code> of course)</li>
</ul>
<p>For example, if you are writing a 64-bit kernel, or just want a barebones C-like
header interface which defines the structures, just select <code>elf64</code>, <code>--cfg feature=&quot;elf64&quot;</code>, which will compile without <code>std</code>.</p>
<p>Similarly, if you want to use host endianness loading via the various <code>from_fd</code> methods, <code>--cfg feature=&quot;std&quot;</code>, which will not use the <code>byteorder</code> extern crate, and read the bytes
from disk in the endianness of the host machine.</p>
<p>If you want endian aware reading, and you don't use <code>default</code>, then you need to opt in as normal
via <code>endian_fd</code></p>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table><tr class='module-item'><td><a class="mod" href="archive/index.html" title='goblin::archive mod'>archive</a></td><td class='docblock-short'><p>Implements a simple parser and extractor for a Unix Archive.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="container/index.html" title='goblin::container mod'>container</a></td><td class='docblock-short'><p>Binary container size information and byte-order context</p>
</td></tr><tr class='module-item'><td><a class="mod" href="elf/index.html" title='goblin::elf mod'>elf</a></td><td class='docblock-short'><p>The generic ELF module, which gives access to ELF constants and other helper functions, which are independent of ELF bithood. Also defines an <code>Elf</code> struct which implements a unified parser that returns a wrapped <code>Elf64</code> or <code>Elf32</code> binary.</p>
</td></tr><tr class='module-item'><td><a class="mod" href="elf32/index.html" title='goblin::elf32 mod'>elf32</a></td><td class='docblock-short'><p>The ELF 32-bit struct definitions and associated values, re-exported for easy &quot;type-punning&quot;</p>
</td></tr><tr class='module-item'><td><a class="mod" href="elf64/index.html" title='goblin::elf64 mod'>elf64</a></td><td class='docblock-short'><p>The ELF 64-bit struct definitions and associated values, re-exported for easy &quot;type-punning&quot;</p>
</td></tr><tr class='module-item'><td><a class="mod" href="error/index.html" title='goblin::error mod'>error</a></td><td class='docblock-short'><p>A custom Goblin error</p>
</td></tr><tr class='module-item'><td><a class="mod" href="mach/index.html" title='goblin::mach mod'>mach</a></td><td class='docblock-short'><p>The Mach-o, mostly zero-copy, binary format parser and raw struct definitions</p>
</td></tr><tr class='module-item'><td><a class="mod" href="pe/index.html" title='goblin::pe mod'>pe</a></td><td class='docblock-short'><p>A PE32 and PE32+ parser</p>
</td></tr><tr class='module-item'><td><a class="mod" href="strtab/index.html" title='goblin::strtab mod'>strtab</a></td><td class='docblock-short'><p>A byte-offset based string table.
Commonly used in ELF binaries, Unix archives, and even PE binaries.</p>
</td></tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.HintData.html" title='goblin::HintData struct'>HintData</a></td><td class='docblock-short'><p>Information obtained from a peek <code>Hint</code></p>
</td></tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table><tr class='module-item'><td><a class="enum" href="enum.Hint.html" title='goblin::Hint enum'>Hint</a></td><td class='docblock-short'><p>A hint at the underlying binary format for 16 bytes of arbitrary data</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Object.html" title='goblin::Object enum'>Object</a></td><td class='docblock-short'><p>A parseable object that goblin understands</p>
</td></tr></table><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table><tr class='module-item'><td><a class="fn" href="fn.peek.html" title='goblin::peek fn'>peek</a></td><td class='docblock-short'><p>Peeks at the underlying Read object. Requires the underlying bytes to have at least 16 byte length. Resets the seek to <code>Start</code> after reading.</p>
</td></tr><tr class='module-item'><td><a class="fn" href="fn.peek_bytes.html" title='goblin::peek_bytes fn'>peek_bytes</a></td><td class='docblock-short'><p>Peeks at <code>bytes</code>, and returns a <code>Hint</code></p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "goblin";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>