diff --git a/Cargo.lock b/Cargo.lock index 7d7c7e2..30a555e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,27 +20,38 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "elf" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b" - [[package]] name = "freeloader" version = "0.1.0" dependencies = [ - "elf", + "goblin", "log", "uefi", ] +[[package]] +name = "goblin" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47" +dependencies = [ + "log", + "plain", + "scroll", +] + [[package]] name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -79,6 +90,26 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "scroll" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6" +dependencies = [ + "scroll_derive", +] + +[[package]] +name = "scroll_derive" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f81c2fde025af7e69b1d1420531c8a8811ca898919db177141a85313b1cb932" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index e47be2c..5e801f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" [dependencies] uefi = { version = "0.29.0", default-features = false, features = [ "alloc", "global_allocator", "panic_handler", "logger" ] } log = { version = "0.4.22", default-features = false } -elf = { version = "0.7.4", default_features = false } +goblin = { version = "0.8.2", default-features = false, features = [ "elf64", "elf32", "endian_fd" ] } diff --git a/src/object.rs b/src/object.rs index 6efe798..477ff98 100644 --- a/src/object.rs +++ b/src/object.rs @@ -2,11 +2,11 @@ extern crate alloc; use crate::abi::{ModuleInfoItem, ModuleInfoType, ModuleInfoValue, Serialize}; use alloc::vec::Vec; -use elf::{endian::NativeEndian, ElfBytes}; +use goblin::elf::Elf; use log::info; #[cfg(target_arch = "x86_64")] -const NATIVE_ELF_MACHINE: u16 = elf::abi::EM_X86_64; +const NATIVE_ELF_MACHINE: u16 = goblin::elf::header::EM_X86_64; pub trait Module { /// Associated metadata for this module, including name and type @@ -17,24 +17,19 @@ pub struct Kernel<'a> { /// Full ELF elf: &'a [u8], /// Parsed ELF - parsed: ElfBytes<'a, NativeEndian>, + parsed: Elf<'a>, /// Raw ELF header bytes elf_header: &'a [u8], } impl<'a> Kernel<'a> { pub fn from_elf_bytes(elf: &'a [u8]) -> Self { - let parsed = - elf::ElfBytes::::minimal_parse(elf).expect("Failed to parse kernel"); - info!("Kernel is {:?}", parsed.ehdr.class); - if parsed.ehdr.e_machine != NATIVE_ELF_MACHINE { + let parsed = Elf::parse(elf).expect("Failed to parse kernel"); + if parsed.header.e_machine != NATIVE_ELF_MACHINE { panic!("Kernel has wrong ELF machine"); } - let header_size = match parsed.ehdr.class { - elf::file::Class::ELF32 => 0x34, - elf::file::Class::ELF64 => 0x40, - }; + let header_size = if parsed.is_64 { 0x40 } else { 0x34 }; let elf_header = &elf[..header_size]; Self {