Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MachO and PE formats #6

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion .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 Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Add it to your ``Cargo.toml``:

```toml
[dependencies]
lddtree = "0.2"
lddtree = "0.3"
```

## Command line utility
Expand Down
61 changes: 61 additions & 0 deletions src/elf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use goblin::{
elf::{
header::{EI_OSABI, ELFOSABI_GNU, ELFOSABI_NONE},
Elf,
},
Object,
};

use crate::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.clone()
}

/// 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,
}
}
}
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
Loading