Skip to content

Commit

Permalink
build: the great feature polarity inversion of 2016. fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
m4b committed Oct 16, 2016
1 parent 374f3af commit 9336696
Show file tree
Hide file tree
Showing 24 changed files with 157 additions and 150 deletions.
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goblin"
version = "0.0.2"
version = "0.0.3"
authors = ["m4b <[email protected]>", "seu <[email protected]>"]
readme = "README.md"
keywords = ["binary", "elf", "mach", "pe", "cross-platform"]
Expand All @@ -16,13 +16,13 @@ version = "0.5"
optional = true

[features]
default = ["byteorder"]
no_elf32 = []
no_elf = []
no_mach = []
no_mach32 = []
no_pe = []
no_pe32 = []
no_goblin = []
no_endian_fd = []
pure = []
default = ["std", "elf32", "elf64", "mach32", "mach64", "pe32", "pe64", "goblin", "endian_fd"]
std = []
elf32 = []
elf64 = []
mach32 = []
mach64 = []
pe32 = []
pe64 = []
goblin = []
endian_fd = ["byteorder"]
2 changes: 1 addition & 1 deletion src/elf/_32/dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const SIZEOF_DYN: usize = 8;

elf_dyn_impure_impl!(
u32,
pub fn from_fd(mut fd: &File, phdrs: &[ProgramHeader], is_lsb: bool) -> io::Result<Option<Vec<Dyn>>> {
pub fn parse(mut fd: &File, phdrs: &[ProgramHeader], is_lsb: bool) -> io::Result<Option<Vec<Dyn>>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
for phdr in phdrs {
if phdr.p_type == PT_DYNAMIC {
Expand Down
4 changes: 2 additions & 2 deletions src/elf/_32/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ elf_header_impure_impl!(
impl Header {
elf_header_from_bytes!();
elf_header_from_fd!();
#[cfg(not(feature = "no_endian_fd"))]
pub fn from_fd(fd: &mut File) -> io::Result<Header> {
#[cfg(feature = "endian_fd")]
pub fn parse(fd: &mut File) -> io::Result<Header> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
use std::io::Seek;
use std::io::SeekFrom::Start;
Expand Down
9 changes: 6 additions & 3 deletions src/elf/_32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ pub mod dyn;
//#[path="rela32.rs"]
pub mod rela;

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
pub use elf::strtab;

#[cfg(all(feature = "std", feature = "endian_fd"))]
pub use self::impure::*;

#[cfg(not(feature = "pure"))]
#[cfg(all(feature = "std", feature = "endian_fd"))]
mod impure {
elf_from_fd!(!0);
elf_from!(!0);
}
4 changes: 2 additions & 2 deletions src/elf/_32/program_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ elf_program_header_impure_impl!(
elf_program_header_from_bytes!();
elf_program_header_from_raw_parts!();
elf_program_header_from_fd!();
#[cfg(not(feature = "no_endian_fd"))]
pub fn from_fd(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<ProgramHeader>> {
#[cfg(feature = "endian_fd")]
pub fn parse(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<ProgramHeader>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};

let mut phdrs = vec![];
Expand Down
4 changes: 2 additions & 2 deletions src/elf/_32/rela.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use elf::rela::*;
// I think 32-bit binaries are stupid relics from the past in case that wasn't clear
#[repr(C)]
#[derive(Clone, PartialEq, Default)]
#[cfg_attr(not(feature = "pure"), derive(Debug))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Rel {
/// address
pub r_offset: u32,
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn r_info(sym: u32, typ: u32) -> u32 {
}

elf_rela_impure_impl!(
pub fn from_fd(fd: &mut File, offset: usize, size: usize, is_lsb: bool) -> io::Result<Vec<Rela>> {
pub fn parse(fd: &mut File, offset: usize, size: usize, is_lsb: bool) -> io::Result<Vec<Rela>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
let count = size / SIZEOF_RELA;
let mut res = Vec::with_capacity(count);
Expand Down
4 changes: 2 additions & 2 deletions src/elf/_32/section_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ elf_section_header_impure_impl!(
elf_section_header_from_bytes!();
elf_section_header_from_raw_parts!();
elf_section_header_from_fd!();
#[cfg(not(feature = "no_endian_fd"))]
pub fn from_fd(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<SectionHeader>> {
#[cfg(feature = "endian_fd")]
pub fn parse(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<SectionHeader>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};

let mut shdrs = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/elf/_32/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Sym {
pub const SIZEOF_SYM: usize = 4 + 1 + 1 + 2 + 4 + 4;

elf_sym_impure_impl!(
pub fn from_fd(fd: &mut File, offset: usize, count: usize, is_lsb: bool) -> io::Result<Vec<Sym>> {
pub fn parse(fd: &mut File, offset: usize, count: usize, is_lsb: bool) -> io::Result<Vec<Sym>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
let mut syms = Vec::with_capacity(count);

Expand Down
2 changes: 1 addition & 1 deletion src/elf/_64/dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const SIZEOF_DYN: usize = 16;

elf_dyn_impure_impl!(
u64,
pub fn from_fd(mut fd: &File, phdrs: &[ProgramHeader], is_lsb: bool) -> io::Result<Option<Vec<Dyn>>> {
pub fn parse(mut fd: &File, phdrs: &[ProgramHeader], is_lsb: bool) -> io::Result<Option<Vec<Dyn>>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
for phdr in phdrs {
if phdr.p_type == PT_DYNAMIC {
Expand Down
4 changes: 2 additions & 2 deletions src/elf/_64/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ elf_header_impure_impl!(
impl Header {
elf_header_from_bytes!();
elf_header_from_fd!();
#[cfg(not(feature = "no_endian_fd"))]
pub fn from_fd(fd: &mut File) -> io::Result<Header> {
#[cfg(feature = "endian_fd")]
pub fn parse(fd: &mut File) -> io::Result<Header> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
use std::io::Seek;
use std::io::SeekFrom::Start;
Expand Down
11 changes: 7 additions & 4 deletions src/elf/_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ pub mod dyn;
//#[path="rela64.rs"]
pub mod rela;

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
pub mod gnu_hash;

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
pub use elf::strtab;

#[cfg(all(feature = "std", feature = "endian_fd"))]
pub use self::impure::*;

#[cfg(not(feature = "pure"))]
#[cfg(all(feature = "std", feature = "endian_fd"))]
mod impure {

elf_from_fd!(::std::u64::MAX);
elf_from!(::std::u64::MAX);

#[cfg(test)]
mod tests {
Expand Down
4 changes: 2 additions & 2 deletions src/elf/_64/program_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ elf_program_header_impure_impl!(
elf_program_header_from_bytes!();
elf_program_header_from_raw_parts!();
elf_program_header_from_fd!();
#[cfg(not(feature = "no_endian_fd"))]
pub fn from_fd(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<ProgramHeader>> {
#[cfg(feature = "endian_fd")]
pub fn parse(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<ProgramHeader>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};

let mut phdrs = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/elf/_64/rela.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn r_info(sym: u64, typ: u64) -> u64 {
}

elf_rela_impure_impl!(
pub fn from_fd(fd: &mut File, offset: usize, size: usize, is_lsb: bool) -> io::Result<Vec<Rela>> {
pub fn parse(fd: &mut File, offset: usize, size: usize, is_lsb: bool) -> io::Result<Vec<Rela>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
let count = size / SIZEOF_RELA;
let mut res = Vec::with_capacity(count);
Expand Down
4 changes: 2 additions & 2 deletions src/elf/_64/section_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ elf_section_header_impure_impl!(
elf_section_header_from_bytes!();
elf_section_header_from_raw_parts!();
elf_section_header_from_fd!();
#[cfg(not(feature = "no_endian_fd"))]
pub fn from_fd(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<SectionHeader>> {
#[cfg(feature = "endian_fd")]
pub fn parse(fd: &mut File, offset: u64, count: usize, is_lsb: bool) -> io::Result<Vec<SectionHeader>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};

let mut shdrs = Vec::with_capacity(count);
Expand Down
2 changes: 1 addition & 1 deletion src/elf/_64/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Sym {
pub const SIZEOF_SYM: usize = 4 + 1 + 1 + 2 + 8 + 8;

elf_sym_impure_impl!(
pub fn from_fd(fd: &mut File, offset: usize, count: usize, is_lsb: bool) -> io::Result<Vec<Sym>> {
pub fn parse(fd: &mut File, offset: usize, count: usize, is_lsb: bool) -> io::Result<Vec<Sym>> {
use byteorder::{LittleEndian,BigEndian,ReadBytesExt};
let mut syms = Vec::with_capacity(count);

Expand Down
17 changes: 8 additions & 9 deletions src/elf/dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ pub const DF_1_GLOBAUDIT: u64 = 0x01000000;
pub const DF_1_SINGLETON: u64 = 0x02000000;

macro_rules! elf_dyn_impure_impl {
($size:ident, $from_fd_endian:item) => {
($size:ident, $from_endian:item) => {

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
pub use self::impure::*;

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
mod impure {

use std::fs::File;
Expand All @@ -282,7 +282,7 @@ macro_rules! elf_dyn_impure_impl {
use std::fmt;
use std::slice;
use super::super::program_header::{ProgramHeader, PT_DYNAMIC};
use super::super::super::elf::strtab::Strtab;
use elf::strtab::Strtab;

use super::*;

Expand Down Expand Up @@ -325,9 +325,8 @@ macro_rules! elf_dyn_impure_impl {
}
}

#[cfg(feature = "no_endian_fd")]
/// Returns a vector of dynamic entries from the given fd and program headers
pub fn from_fd(mut fd: &File, phdrs: &[ProgramHeader], _: bool) -> io::Result<Option<Vec<Dyn>>> {
pub fn from_fd(mut fd: &File, phdrs: &[ProgramHeader]) -> io::Result<Option<Vec<Dyn>>> {
use std::io::Read;
for phdr in phdrs {
if phdr.p_type == PT_DYNAMIC {
Expand Down Expand Up @@ -381,9 +380,9 @@ macro_rules! elf_dyn_impure_impl {
needed
}

#[cfg(not(feature = "no_endian_fd"))]
/// Returns a vector of dynamic entries from the given fd and program headers
$from_fd_endian
#[cfg(feature = "endian_fd")]
/// Returns a vector of dynamic entries from the given `R: Read` and program headers
$from_endian

}

Expand Down
9 changes: 4 additions & 5 deletions src/elf/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ pub fn et_to_str(et: u16) -> &'static str {
}
}

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
pub use self::impure::*;

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
mod impure {
use super::*;

Expand Down Expand Up @@ -154,7 +154,6 @@ macro_rules! elf_header_from_bytes {
macro_rules! elf_header_from_fd {
() => {
/// Load a header from a file.
#[cfg(feature = "no_endian_fd")]
pub fn from_fd(fd: &mut File) -> io::Result<Header> {
let mut elf_header = [0; SIZEOF_EHDR];
try!(fd.read(&mut elf_header));
Expand Down Expand Up @@ -187,10 +186,10 @@ macro_rules! elf_header_test_peek {

macro_rules! elf_header_impure_impl {
($header:item) => {
#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
pub use self::impure::*;

#[cfg(not(feature = "pure"))]
#[cfg(feature = "std")]
mod impure {

use super::*;
Expand Down
Loading

0 comments on commit 9336696

Please sign in to comment.