Debian Codegraph @

third_party/rust/goblin/README.md

raw
1 # libgoblin
2
3 [![Actions][actions-badge]][actions-url]
4 [![crates.io version][crates-goblin-badge]][crates-goblin]
5
6 <!-- Badges' links -->
7
8 [actions-badge]: https://github.com/m4b/goblin/workflows/CI/badge.svg?branch=master
9 [actions-url]: https://github.com/m4b/goblin/actions
10 [crates-goblin-badge]: https://img.shields.io/crates/v/goblin.svg
11 [crates-goblin]: https://crates.io/crates/goblin
12
13 ![say the right words](https://s-media-cache-ak0.pinimg.com/736x/1b/6a/aa/1b6aaa2bae005e2fed84b1a7c32ecb1b.jpg)
14
15 ### Documentation
16
17 https://docs.rs/goblin/
18
19 [changelog](CHANGELOG.md)
20
21 ### Usage
22
23 Goblin requires `rustc` 1.63.0 (Rust 2021 edition).
24
25 Add to your `Cargo.toml`
26
27 ```toml
28 [dependencies]
29 goblin = "0.9"
30 ```
31
32 ### Features
33
34 * awesome crate name
35 * zero-copy, cross-platform, endian-aware, ELF64/32 implementation - wow!
36 * zero-copy, cross-platform, endian-aware, 32/64 bit Mach-o parser - zoiks!
37 * PE 32/64-bit parser - bing!
38 * a Unix _and_ BSD style archive parser (latter courtesy of [@willglynn]) - huzzah!
39 * many cfg options - it will make your head spin, and make you angry when reading the source!
40 * fuzzed - "I am happy to report that goblin withstood 100 million fuzzing runs, 1 million runs
41 each for seed 1\~100." - [@sanxiyn]
42 * tests
43
44 `libgoblin` aims to be your one-stop shop for binary parsing, loading, and analysis.
45
46 ### Use-cases
47
48 Goblin primarily supports the following important use cases:
49
50 1. Core, std-free `#[repr(C)]` structs, tiny compile time, 32/64 (or both) at your leisure.
51
52 1. Type punning. Define a function once on a type, but have it work on 32 or 64-bit variants -
53 without really changing anything, and no macros! See `examples/automagic.rs` for a basic example.
54
55 1. `std` mode. This throws in read and write impls via `Pread` and `Pwrite`, reading from file,
56 convenience allocations, extra methods, etc. This is for clients who can allocate and want to
57 read binaries off disk.
58
59 1. `Endian_fd`. A truly terrible name :laughing: this is for binary analysis like in [panopticon]
60 or [falcon] which needs to read binaries of foreign endianness, _or_ as a basis for
61 constructing cross platform foreign architecture binutils, e.g. [cargo-sym] and [bingrep] are
62 simple examples of this, but the sky is the limit.
63
64 Here are some things you could do with this crate (or help to implement so they could be done):
65
66 1. Write a compiler and use it to [generate binaries][faerie] (all the raw C structs have
67 [`Pwrite`][scroll] derived).
68 1. Write a binary analysis tool which loads, parses, and analyzes various binary formats, e.g.,
69 [panopticon] or [falcon].
70 1. Write a [semi-functioning dynamic linker][dryad].
71 1. Write a [kernel][redox-os] and load binaries using `no_std` cfg. I.e., it is essentially just
72 struct and const defs (like a C header) - no fd, no output, no std.
73 1. Write a [bin2json] tool, because why shouldn't binary formats be in JSON?
74
75 <!-- Related projects -->
76
77 [PyO3/maturin]: https://github.com/PyO3/maturin
78 [occlum]: https://github.com/occlum/occlum
79 [memflow]: https://github.com/memflow/memflow
80 [cargo-sym]: https://github.com/m4b/cargo-sym
81 [bingrep]: https://github.com/m4b/bingrep
82 [faerie]: https://github.com/m4b/faerie
83 [dryad]: https://github.com/m4b/dryad
84 [scroll]: https://github.com/m4b/scroll
85 [redox-os]: https://github.com/redox-os/redox
86 [bin2json]: https://github.com/m4b/bin2json
87 [panopticon]: https://github.com/das-labor/panopticon
88 [falcon]: https://github.com/endeav0r/falcon
89
90 ### Cfgs
91
92 `libgoblin` is designed to be massively configurable. The current flags are:
93
94 * elf64 - 64-bit elf binaries, `repr(C)` struct defs
95 * elf32 - 32-bit elf binaries, `repr(C)` struct defs
96 * mach64 - 64-bit mach-o `repr(C)` struct defs
97 * mach32 - 32-bit mach-o `repr(C)` struct defs
98 * pe32 - 32-bit PE `repr(C)` struct defs
99 * pe64 - 64-bit PE `repr(C)` struct defs
100 + te - Terse Executable (TE) `repr(C)` struct defs
101 * archive - a Unix Archive parser
102 * endian_fd - parses according to the endianness in the binary
103 * std - to allow `no_std` environments
104
105 # Contributors
106
107 Thank you all :heart: !
108
109 In lexicographic order:
110
111 - [@2vg]
112 - [@5225225]
113 - [@alessandrod]
114 - [@amanieu]
115 - [@anfedotoff]
116 - [@apalm]
117 - [@baloo]
118 - [@burjui]
119 - [@connorkuehl]
120 - [@dancrossnyc]
121 - [@dureuill]
122 - [@Evian-Zhang]
123 - [@ExPixel]
124 - [@flanfly]
125 - [@glandium]
126 - [@h33p]
127 - [@ibabushkin]
128 - [@ideeockus]
129 - [@jackcmay]
130 - [@jan-auer]
131 - [@Javagedes]
132 - [@jessehui]
133 - [@jdub]
134 - [@Jhynjhiruu]
135 - [@johannst]
136 - [@JohnScience]
137 - [@joschock]
138 - [@jrmuizel]
139 - [@jsgf]
140 - [@keith]
141 - [@kjempelodott]
142 - [@kkent030315]
143 - [@ko1n]
144 - [@le-jzr]
145 - [@Lichtso]
146 - [@lion128]
147 - [@lissyx]
148 - [@llogiq]
149 - [@lumag]
150 - [@lzutao]
151 - [@lzybkr]
152 - [@m-hilgendorf]
153 - [@mmaekr]
154 - [@m4b]
155 - [@messense]
156 - [@mitsuhiko]
157 - [@mkroening]
158 - [@mre]
159 - [@Mrmaxmeier]
160 - [n01e0]
161 - [nathaniel-daniel]
162 - [@nick96]
163 - [@nico-abram]
164 - [@npmccallum]
165 - [@pchickey]
166 - [@philipc]
167 - [@Pzixel]
168 - [@quake]
169 - [@raindev]
170 - [@RaitoBezarius]
171 - [@rocallahan]
172 - [@sanxiyn]
173 - [@skdltmxn]
174 - [@sollyucko]
175 - [@Swatinem]
176 - [@SweetVishnya]
177 - [@SquareMan]
178 - [@tathanhdinh]
179 - [@Techno-coder]
180 - [@tiann]
181 - [@ticki]
182 - [@Timmmm]
183 - [@Tiwalun]
184 - [@track-5]
185 - [@tux3]
186 - [@wickerwacka]
187 - [@willglynn]
188 - [@woodruffw]
189 - [@wyxloading]
190 - [@xcoldhandsx]
191 - [@x64k]
192
193 <!-- Contributors -->
194
195 [@2vg]: https://github.com/2vg
196 [@5225225]: https://github.com/5225225
197 [@alessandrod]: https://github.com/alessandrod
198 [@amanieu]: https://github.com/amanieu
199 [@anfedotoff]: https://github.com/anfedotoff
200 [@apalm]: https://github.com/apalm
201 [@baloo]: https://github.com/baloo
202 [@burjui]: https://github.com/burjui
203 [@connorkuehl]: https://github.com/connorkuehl
204 [@crzysdrs]: https://github.com/crzysdrs
205 [@dancrossnyc]: https://github.com/dancrossnyc
206 [@dureuill]: https://github.com/dureuill
207 [@Evian-Zhang]: https://github.com/Evian-Zhang
208 [@ExPixel]: https://github.com/ExPixel
209 [@flanfly]: https://github.com/flanfly
210 [@glandium]: https://github.com/glandium
211 [@h33p]: https://github.com/h33p
212 [@ibabushkin]: https://github.com/ibabushkin
213 [@ideeockus]: https://github.com/ideeockus
214 [@jackcmay]: https://github.com/jackcmay
215 [@jan-auer]: https://github.com/jan-auer
216 [@Javagedes]: https://github.com/Javagedes
217 [@jessehui]: https://github.com/jessehui
218 [@Jhynjhiruu]: https://github.com/Jhynjhiruu
219 [@JohnScience]: https://github.com/JohnScience
220 [@johannst]: https://github.com/johannst
221 [@joschock]: https://github.com/joschock
222 [@jdub]: https://github.com/jdub
223 [@jrmuizel]: https://github.com/jrmuizel
224 [@jsgf]: https://github.com/jsgf
225 [@keith]: https://github.com/keith
226 [@kjempelodott]: https://github.com/kjempelodott
227 [@kkent030315]: https://github.com/kkent030315
228 [@ko1N]: https://github.com/ko1N
229 [@le-jzr]: https://github.com/le-jzr
230 [@Lichtso]: https://github.com/Lichtso
231 [@lion128]: https://github.com/lion128
232 [@lissyx]: https://github.com/lissyx
233 [@llogiq]: https://github.com/llogiq
234 [@lumag]: https://github.com/lumag
235 [@lzutao]: https://github.com/lzutao
236 [@lzybkr]: https://github.com/lzybkr
237 [@m-hilgendorf]: https://github.com/m-hilgendorf
238 [@mmaekr]: https://github.com/mmaekr
239 [@m4b]: https://github.com/m4b
240 [@messense]: https://github.com/messense
241 [@mitsuhiko]: https://github.com/mitsuhiko
242 [@mkroening]: https://github.com/mkroening
243 [@mre]: https://github.com/mre
244 [@Mrmaxmeier]: https://github.com/Mrmaxmeier
245 [n01e0]: https://github.com/n01e0
246 [nathaniel-daniel]: https://github.com/nathaniel-daniel
247 [@nick96]: https://github.com/nick96
248 [@nico-abram]: https://github.com/nico-abram
249 [@npmccallum]: https://github.com/npmccallum
250 [@pchickey]: https://github.com/pchickey
251 [@philipc]: https://github.com/philipc
252 [@Pzixel]: https://github.com/Pzixel
253 [@quake]: https://github.com/quake
254 [@raindev]: https://github.com/raindev
255 [@RaitoBezarius]: https://github.com/RaitoBezarius
256 [@rocallahan]: https://github.com/rocallahan
257 [@sanxiyn]: https://github.com/sanxiyn
258 [@skdltmxn]: https://github.com/skdltmxn
259 [@sollyucko]: https://github.com/sollyucko
260 [@suttonbradley]: https://github.com/suttonbradley
261 [@Swatinem]: https://github.com/Swatinem
262 [@SweetVishnya]: https://github.com/SweetVishnya
263 [@SquareMan]: https://github.com/SquareMan
264 [@tathanhdinh]: https://github.com/tathanhdinh
265 [@Techno-coder]: https://github.com/Techno-coder
266 [@tiann]: https://github.com/tiann
267 [@ticki]: https://github.com/ticki
268 [@Timmmm]: https://github.com/Timmmm
269 [@Tiwalun]: https://github.com/Tiwalun
270 [@track-5]: https://github.com/track-5
271 [@tux3]: https://github.com/tux3
272 [@vadimcn]: https://github.com/vadimcn
273 [@wickerwacka]: https://github.com/wickerwaka
274 [@willglynn]: https://github.com/willglynn
275 [@woodruffw]: https://github.com/woodruffw
276 [@wyxloading]: https://github.com/wyxloading
277 [@xcoldhandsx]: https://github.com/xcoldhandsx
278 [@x64k]: https://github.com/x64k
279
280 ## Contributing
281
282 Unless explicitly stated otherwise, you agree that your contributions are licensed as described in the accompanying LICENSE file (MIT).
283
284 1. Please prefix commits with the affected binary component; the more specific the better, e.g.,
285 if you only modify relocations in the elf module, then do "elf.reloc: added new constants for Z80"
286 1. Commit messages must explain their change, no generic "changed", or "fix"; if you push commits
287 like this on a PR, be aware [@m4b] or someone will most likely squash them.
288 1. If you are making a large change to a module, please raise an issue first and lets discuss;
289 I don't want to waste your time if its not a good technical direction, or etc.
290 1. If your PR is not getting attention, please respond to all relevant comments raised on the PR,
291 and if still no response, ping [@m4b], [@philipc], or [@willglynn] in github and also feel free
292 to email [@m4b].
293 1. Please add tests if you are adding a new feature. Feel free to add tests even if you are not,
294 tests are awesome and easy in rust.
295 1. Once cargo format is officially released, please format your _patch_ using the default settings.