Skip to content
An impish, cross-platform binary parsing crate, written in Rust
Branch: master
Clone or download
lzutao and m4b Fix errors and warnings generated by clippy (#146)
* Fix constants have by default a `'static` lifetime
* Fix unneeded unit return type
* Fix unneeded return statement
* Fix redundant closure found
* Fix warning: identical conversion
* Fix redundant field names in struct initialization
* Fix warning: casting u* to u64 may become silently lossy if types change
* Use `Read::read_exact` to handle read amount
* Fix warning: more efficient if passed by value
```
   --> src/lib.rs:139:23
    |
139 |         pub fn is_big(&self) -> bool {
    |                       ^^^^^ help: consider passing by value instead: `self`
    |
    = note: #[warn(clippy::trivially_copy_pass_by_ref)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
* Fix warning: long literal lacking separators
  --> src/elf/program_header.rs:20:26
   |
20 | pub const PT_LOOS: u32 = 0x60000000;
   |                          ^^^^^^^^^^ help: consider: `0x6000_0000`
   |
   = note: #[warn(clippy::unreadable_literal)] on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
```
* Fix warning: methods called `to_*` usually take self by reference
```
warning: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
  --> src/strtab.rs:47:19
   |
47 |     pub fn to_vec(self) -> error::Result<Vec<&'a str>> {
   |                   ^^^^
   |
   = note: #[warn(clippy::wrong_self_convention)] on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention
```
* Fix warning: large size difference between variants
```
   --> src/lib.rs:291:9
    |
291 |         Elf(elf::Elf<'a>),
    |         ^^^^^^^^^^^^^^^^^
    |
    = note: #[warn(clippy::large_enum_variant)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
    |
291 |         Elf(Box<elf::Elf<'a>>),
    |             ^^^^^^^^^^^^^^^^^
```
* Fix warning: the operation is ineffective.
```
  --> src/elf/program_header.rs:45:23
   |
45 | pub const PF_X: u32 = 1 << 0;
   |                       ^^^^^^
   |
   = note: #[warn(clippy::identity_op)] on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
```
* Fix warning: Redundant imports
* Fix warning: this call to `as_ref` does nothing
```
   --> src/mach/exports.rs:248:19
    |
248 |             data: bytes.as_ref(),
    |                   ^^^^^^^^^^^^^^ help: try this: `bytes`
    |
    = note: #[warn(clippy::useless_asref)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref
```
* Fix warning: useless use of `format!` (clippy::useless_format)
* Fix warning: use of `ok_or` followed by a function call
```
  --> src/pe/utils.rs:67:48
   |
67 |     find_offset(rva, sections, file_alignment).ok_or(error::Error::Malformed(msg.to_string()))
   |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `ok_or_else(|| error::Error::Malformed(msg.to_string()))`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
```
* Fix warning: using `clone` on a `Copy` type
```
    --> src/mach/load_command.rs:1371:138
     |
1371 |             _ =>                                                                                             Ok((Unimplemented          (lc.clone()), size)),
     |                                                                                                                                          ^^^^^^^^^^ help: try removing the `clone` call: `lc`
     |
     = note: #[warn(clippy::clone_on_copy)] on by default
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
```
* Fix clippy::len_without_is_empty
* Fix clippy::needless_range_loop
* Fix clippy::match_ref_pats
* Fix clippy::single_match
* Fix clippy::ptr_offset_with_cast
* Fix clippy::assign_op_pattern
* Fix clippy::clone_double_ref
* Fix clippy::map_clone
* Fix clippy::option_map_or_none
* Fix clippy::char_lit_as_u8
* Fix clippy::new_without_default
* Fix warning in elf::dynamic
* Use copy_from_slice instead of for loop
* Fix 5 zeros
Latest commit 34cac38 Apr 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
etc elf.header: add pwrite impl. correct header32 size bug 😭. add pwrite … Jan 17, 2017
examples Fix errors and warnings generated by clippy (#146) Apr 4, 2019
fuzz
src Fix errors and warnings generated by clippy (#146) Apr 4, 2019
tests Fix errors and warnings generated by clippy (#146) Apr 4, 2019
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
Cargo.toml
LICENSE
Makefile
README.md

README.md

libgoblin Build status crates.io version

say the right words

Documentation

https://docs.rs/goblin/

changelog

Usage

Goblin requires rustc 1.31.1.

Add to your Cargo.toml

[dependencies]
goblin = "0.0.21"

Features

  • awesome crate name
  • zero-copy, cross-platform, endian-aware, ELF64/32 implementation - wow!
  • zero-copy, cross-platform, endian-aware, 32/64 bit Mach-o parser - zoiks!
  • PE 32/64-bit parser - bing!
  • a Unix and BSD style archive parser (latter courtesy of @willglynn) - huzzah!
  • many cfg options - it will make your head spin, and make you angry when reading the source!
  • fuzzed - "I am happy to report that goblin withstood 100 million fuzzing runs, 1 million runs each for seed 1~100." - @sanxiyn
  • tests

libgoblin aims to be your one-stop shop for binary parsing, loading, and analysis.

Use-cases

Goblin primarily supports the following important use cases:

  1. Core, std-free #[repr(C)] structs, tiny compile time, 32/64 (or both) at your leisure.

  2. 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 examples/automagic.rs for a basic example.

  3. std mode. This throws in read and write impls via Pread and Pwrite, reading from file, convenience allocations, extra methods, etc. This is for clients who can allocate and want to read binaries off disk.

  4. Endian_fd. A truly terrible name 😆 this is for binary analysis like in panopticon or falcon which needs to read binaries of foreign endianness, or as a basis for constructing cross platform foreign architecture binutils, e.g. cargo-sym and bingrep are simple examples of this, but the sky is the limit.

Here are some things you could do with this crate (or help to implement so they could be done):

  1. Write a compiler and use it to generate binaries (all the raw C structs have Pwrite derived).
  2. Write a binary analysis tool which loads, parses, and analyzes various binary formats, e.g., panopticon or falcon.
  3. Write a semi-functioning dynamic linker.
  4. Write a kernel and load binaries using no_std cfg. I.e., it is essentially just struct and const defs (like a C header) - no fd, no output, no std.
  5. Write a bin2json tool, because why shouldn't binary formats be in JSON?

Cfgs

libgoblin is designed to be massively configurable. The current flags are:

  • elf64 - 64-bit elf binaries, repr(C) struct defs
  • elf32 - 32-bit elf binaries, repr(C) struct defs
  • mach64 - 64-bit mach-o repr(C) struct defs
  • mach32 - 32-bit mach-o repr(C) struct defs
  • pe32 - 32-bit PE repr(C) struct defs
  • pe64 - 64-bit PE repr(C) struct defs
  • archive - a Unix Archive parser
  • endian_fd - parses according to the endianness in the binary
  • std - to allow no_std environments

Contributors

Thank you all ❤️ !

In alphabetic order:

Contributing

  1. Please prefix commits with the affected binary component; the more specific the better, e.g., if you only modify relocations in the elf module, then do "elf.reloc: added new constants for Z80"
  2. Commit messages must explain their change, no generic "changed", or "fix"; if you push commits like this on a PR, be aware @m4b or someone will most likely squash them.
  3. If you are making a large change to a module, please raise an issue first and lets discuss; I don't want to waste your time if its not a good technical direction, or etc.
  4. If your PR is not getting attention, please respond to all relevant comments raised on the PR, and if still no response, ping @m4b, @philipc, or @willglynn in github and also feel free to email @m4b.
  5. Please add tests if you are adding a new feature. Feel free to add tests even if you are not, tests are awesome and easy in rust.
  6. Once cargo format is officially released, please format your patch using the default settings.
You can’t perform that action at this time.