Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Mark binary test fixtures to prevent line-ending corruption
tests/test.macho binary
tests/test.pe binary
tests/test.elf binary
52 changes: 24 additions & 28 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

name: CI

Expand All @@ -7,15 +11,9 @@ jobs:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo check

test:
name: Test Suite
Expand All @@ -24,30 +22,28 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test
env:
RUST_BACKTRACE: '1'
with:
command: test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
components: rustfmt
- run: cargo fmt --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
command: fmt
args: --all -- --check
components: clippy
- run: cargo clippy -- -D warnings
65 changes: 65 additions & 0 deletions src/elf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use goblin::{
elf::{
header::{EI_OSABI, ELFOSABI_GNU, ELFOSABI_NONE},
Elf,
},
Object,
};

use crate::{BinaryFormat, InspectDylib};

impl InspectDylib for Elf<'_> {
fn rpaths(&self) -> &[&str] {
if !self.runpaths.is_empty() {
&self.runpaths
} else {
&self.rpaths
}
}

fn libraries(&self) -> Vec<&str> {
self.libraries.clone()
}

fn interpreter(&self) -> Option<&str> {
self.interpreter
}

/// See if two ELFs are compatible
///
/// This compares the aspects of the ELF to see if they're compatible:
/// bit size, endianness, machine type, and operating system.
fn compatible(&self, other: &Object) -> bool {
match other {
Object::Elf(other) => {
if self.is_64 != other.is_64 {
return false;
}
if self.little_endian != other.little_endian {
return false;
}
if self.header.e_machine != other.header.e_machine {
return false;
}
let compatible_osabis = &[
ELFOSABI_NONE, // ELFOSABI_NONE / ELFOSABI_SYSV
ELFOSABI_GNU, // ELFOSABI_GNU / ELFOSABI_LINUX
];
let osabi1 = self.header.e_ident[EI_OSABI];
let osabi2 = other.header.e_ident[EI_OSABI];
if osabi1 != osabi2
&& !compatible_osabis.contains(&osabi1)
&& !compatible_osabis.contains(&osabi2)
{
return false;
}
true
}
_ => false,
}
}

fn format(&self) -> BinaryFormat {
BinaryFormat::Elf
}
}
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum Error {
Io(io::Error),
Goblin(goblin::error::Error),
LdSoConf(LdSoConfError),
UnsupportedBinary,
}

impl fmt::Display for Error {
Expand All @@ -17,6 +18,7 @@ impl fmt::Display for Error {
Error::Io(e) => e.fmt(f),
Error::Goblin(e) => e.fmt(f),
Error::LdSoConf(e) => e.fmt(f),
Error::UnsupportedBinary => write!(f, "Unsupported binary format"),
}
}
}
Expand All @@ -27,6 +29,7 @@ impl error::Error for Error {
Error::Io(e) => e.source(),
Error::Goblin(e) => e.source(),
Error::LdSoConf(e) => e.source(),
Error::UnsupportedBinary => None,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/ld_so_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub fn parse_ld_so_conf(
if line.starts_with("#") {
continue;
}
if line.starts_with("include ") {
let include_path = &line[8..];
if let Some(include_path) = line.strip_prefix("include ") {
let include_path = if !include_path.starts_with('/') {
let parent = path.parent().unwrap();
parent.join(include_path).display().to_string()
Expand Down
Loading