pub fn new(bytes: Vec<u8>, base_address: u64) -> Result<Elf> {
        let architecture = {
            let elf = goblin::elf::Elf::parse(&bytes).map_err(|_| "Not a valid elf")?;

            if elf.header.e_machine == goblin::elf::header::EM_386 {
                Box::new(X86::new())
            } else if elf.header.e_machine == goblin::elf::header::EM_MIPS {
                match elf.header.endianness()? {
                    goblin::container::Endian::Big => {
                        Box::new(Mips::new()) as Box<dyn Architecture>
                    }
                    goblin::container::Endian::Little => {
                        Box::new(Mipsel::new()) as Box<dyn Architecture>
                    }
                }
            } else if elf.header.e_machine == goblin::elf::header::EM_PPC {
                match elf.header.endianness()? {
                    goblin::container::Endian::Big => Box::new(Ppc::new()) as Box<dyn Architecture>,
                    goblin::container::Endian::Little => bail!("PPC Little-Endian not supported"),
                }
            } else if elf.header.e_machine == goblin::elf::header::EM_X86_64 {
                Box::new(Amd64::new())
            } else if elf.header.e_machine == goblin::elf::header::EM_AARCH64 {
                match elf.header.endianness()? {
                    goblin::container::Endian::Big => {
                        Box::new(AArch64Eb::new()) as Box<dyn Architecture>
                    }
                    goblin::container::Endian::Little => {
                        Box::new(AArch64::new()) as Box<dyn Architecture>
                    }
                }
            } else {
                bail!("Unsupported Architecture");
            }
        };

        Ok(Elf {
            base_address,
            bytes,
            user_function_entries: Vec::new(),
            architecture,
        })
    }
/// Create a new Elf from the given bytes. This Elf will be rebased to the given
/// base address.
Create a new Elf from the given bytes. This Elf will be rebased to the given
base address.
Create a new Elf from the given bytes . This Elf will be rebased to the given base address .
pub fn new(bytes: Vec<u8>, base_address: u64) -> Result<Elf> {
        let architecture = {
            let elf = goblin::elf::Elf::parse(&bytes).map_err(|_| "Not a valid elf")?;
            if elf.header.e_machine == goblin::elf::header::EM_386 {
                Box::new(X86::new())
            } else if elf.header.e_machine == goblin::elf::header::EM_MIPS {
                match elf.header.endianness()? {
                    goblin::container::Endian::Big => {
                        Box::new(Mips::new()) as Box<dyn Architecture>
                    }
                    goblin::container::Endian::Little => {
                        Box::new(Mipsel::new()) as Box<dyn Architecture>
                    }
                }
            } else if elf.header.e_machine == goblin::elf::header::EM_PPC {
                match elf.header.endianness()? {
                    goblin::container::Endian::Big => Box::new(Ppc::new()) as Box<dyn Architecture>,
                    goblin::container::Endian::Little => bail!("PPC Little-Endian not supported"),
                }
            } else if elf.header.e_machine == goblin::elf::header::EM_X86_64 {
                Box::new(Amd64::new())
            } else if elf.header.e_machine == goblin::elf::header::EM_AARCH64 {
                match elf.header.endianness()? {
                    goblin::container::Endian::Big => {
                        Box::new(AArch64Eb::new()) as Box<dyn Architecture>
                    }
                    goblin::container::Endian::Little => {
                        Box::new(AArch64::new()) as Box<dyn Architecture>
                    }
                }
            } else {
                bail!("Unsupported Architecture");
            }
        };
        Ok(Elf {
            base_address,
            bytes,
            user_function_entries: Vec::new(),
            architecture,
        })
    }
pub fn new ( bytes : Vec < u8 > , base_address : u64 ) -> Result < Elf > { let architecture = { let elf = goblin :: elf :: Elf :: parse ( & bytes ) . map_err ( | _ | " " ) ? ; if elf . header . e_machine == goblin :: elf :: header :: EM_386 { Box :: new ( X86 :: new ( ) ) } else if elf . header . e_machine == goblin :: elf :: header :: EM_MIPS { match elf . header . endianness ( ) ? { goblin :: container :: Endian :: Big => { Box :: new ( Mips :: new ( ) ) as Box < dyn Architecture > } goblin :: container :: Endian :: Little => { Box :: new ( Mipsel :: new ( ) ) as Box < dyn Architecture > } } } else if elf . header . e_machine == goblin :: elf :: header :: EM_PPC { match elf . header . endianness ( ) ? { goblin :: container :: Endian :: Big => Box :: new ( Ppc :: new ( ) ) as Box < dyn Architecture > , goblin :: container :: Endian :: Little => bail ! ( " " ) , } } else if elf . header . e_machine == goblin :: elf :: header :: EM_X86_64 { Box :: new ( Amd64 :: new ( ) ) } else if elf . header . e_machine == goblin :: elf :: header :: EM_AARCH64 { match elf . header . endianness ( ) ? { goblin :: container :: Endian :: Big => { Box :: new ( AArch64Eb :: new ( ) ) as Box < dyn Architecture > } goblin :: container :: Endian :: Little => { Box :: new ( AArch64 :: new ( ) ) as Box < dyn Architecture > } } } else { bail ! ( " " ) ; } } ; Ok ( Elf { base_address , bytes , user_function_entries : Vec :: new ( ) , architecture , } ) }
Create a new Elf from the given bytes.
Create a new Elf from the given bytes .
bytes
Vec<u8>
base_address
u64
bytes
Vec<u8>
base_address
u64