|
|
@ -4,7 +4,7 @@ use std::{
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::common::{Relocatable, Section, SectionInfo};
|
|
|
|
use crate::common::{DataIndex, Relocatable, Section, SectionInfo};
|
|
|
|
use crate::{common::BSI, error::Error};
|
|
|
|
use crate::{common::BSI, error::Error};
|
|
|
|
use elf_utilities::{file::ELF64, parser::read_elf64};
|
|
|
|
use elf_utilities::{file::ELF64, parser::read_elf64};
|
|
|
|
|
|
|
|
|
|
|
@ -41,17 +41,15 @@ impl ElfObject {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Relocatable for ElfObject {
|
|
|
|
impl Relocatable for ElfObject {
|
|
|
|
type Index = (usize, usize); // object index, section index
|
|
|
|
fn new(origin: PathBuf, di: DataIndex) -> Result<Self, Error> {
|
|
|
|
|
|
|
|
ElfObject::new(origin, di.object_index)
|
|
|
|
fn new(origin: PathBuf, object_index: usize) -> Result<Self, Error> {
|
|
|
|
|
|
|
|
ElfObject::new(origin, object_index)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn origin(&self) -> &Path {
|
|
|
|
fn origin(&self) -> &Path {
|
|
|
|
&self.origin
|
|
|
|
&self.origin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn sections(&self) -> BSI<(usize, usize)> {
|
|
|
|
fn sections(&self) -> BSI {
|
|
|
|
use elf_utilities::section::{Contents64, Type};
|
|
|
|
use elf_utilities::section::{Contents64, Type};
|
|
|
|
|
|
|
|
|
|
|
|
let iter = self
|
|
|
|
let iter = self
|
|
|
@ -69,7 +67,7 @@ impl Relocatable for ElfObject {
|
|
|
|
let si = SectionInfo {
|
|
|
|
let si = SectionInfo {
|
|
|
|
file_size: s.header.sh_size,
|
|
|
|
file_size: s.header.sh_size,
|
|
|
|
data_size: s.header.sh_size,
|
|
|
|
data_size: s.header.sh_size,
|
|
|
|
data_index: Some((self.object_index, i)),
|
|
|
|
data_index: Some(DataIndex::new(self.object_index, i)),
|
|
|
|
offset: s.header.sh_offset,
|
|
|
|
offset: s.header.sh_offset,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let s_name: &str = &s.name;
|
|
|
|
let s_name: &str = &s.name;
|
|
|
@ -98,9 +96,9 @@ impl Relocatable for ElfObject {
|
|
|
|
Box::new(iter)
|
|
|
|
Box::new(iter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn section_data(&self, index: (usize, usize)) -> Result<&[u8], Error> {
|
|
|
|
fn section_data(&self, index: DataIndex) -> Result<&[u8], Error> {
|
|
|
|
use elf_utilities::section::Contents64;
|
|
|
|
use elf_utilities::section::Contents64;
|
|
|
|
let section = &self.elf.sections[index.1];
|
|
|
|
let section = &self.elf.sections[index.section_index];
|
|
|
|
|
|
|
|
|
|
|
|
match §ion.contents {
|
|
|
|
match §ion.contents {
|
|
|
|
Contents64::Raw(v) => Ok(&v),
|
|
|
|
Contents64::Raw(v) => Ok(&v),
|
|
|
|