|
|
@ -1,4 +1,8 @@
|
|
|
|
use std::{convert::TryFrom, fmt::Display, path::{Path, PathBuf}};
|
|
|
|
use std::{
|
|
|
|
|
|
|
|
convert::TryFrom,
|
|
|
|
|
|
|
|
fmt::Display,
|
|
|
|
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::common::{Relocatable, Section, SectionInfo};
|
|
|
|
use crate::common::{Relocatable, Section, SectionInfo};
|
|
|
|
use crate::{common::BSI, error::Error};
|
|
|
|
use crate::{common::BSI, error::Error};
|
|
|
@ -41,46 +45,46 @@ impl Relocatable for ElfObject {
|
|
|
|
fn sections<'iter>(self: &'iter Self) -> BSI<'iter, (usize, usize)> {
|
|
|
|
fn sections<'iter>(self: &'iter Self) -> BSI<'iter, (usize, usize)> {
|
|
|
|
use elf_utilities::section::{Contents64, Type};
|
|
|
|
use elf_utilities::section::{Contents64, Type};
|
|
|
|
|
|
|
|
|
|
|
|
let iter = self
|
|
|
|
let iter =
|
|
|
|
.elf
|
|
|
|
self.elf
|
|
|
|
.sections
|
|
|
|
.sections
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.enumerate()
|
|
|
|
.filter_map(|(i, s)| match s.header.get_type() {
|
|
|
|
.filter_map(|(i, s)| match s.header.get_type() {
|
|
|
|
Type::ProgBits => {
|
|
|
|
Type::ProgBits => {
|
|
|
|
if s.header.sh_size > 0 {
|
|
|
|
if s.header.sh_size > 0 {
|
|
|
|
if let Some(di) = match &s.contents {
|
|
|
|
if let Some(di) = match &s.contents {
|
|
|
|
Contents64::Raw(v) => Some(v),
|
|
|
|
Contents64::Raw(v) => Some(v),
|
|
|
|
_ => None,
|
|
|
|
_ => None,
|
|
|
|
} {
|
|
|
|
} {
|
|
|
|
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((0, i)), // TODO
|
|
|
|
data_index: Some((0, i)), // TODO
|
|
|
|
offset: s.header.sh_offset,
|
|
|
|
offset: s.header.sh_offset,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let s_name: &str = &s.name;
|
|
|
|
let s_name: &str = &s.name;
|
|
|
|
|
|
|
|
|
|
|
|
match Section::try_from((s_name, si)) {
|
|
|
|
match Section::try_from((s_name, si)) {
|
|
|
|
Ok(s) => Some(Ok(s)),
|
|
|
|
Ok(s) => Some(Ok(s)),
|
|
|
|
Err(Error::InvalidSectionName) => None, // skip
|
|
|
|
Err(Error::InvalidSectionName) => None, // skip
|
|
|
|
Err(err) => Some(Err(err)),
|
|
|
|
Err(err) => Some(Err(err)),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Some(Err(Error::InvalidSectionData))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Some(Err(Error::InvalidSectionData))
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Type::NoBits => Some(Ok(Section::Bss(SectionInfo {
|
|
|
|
Type::NoBits => Some(Ok(Section::Bss(SectionInfo {
|
|
|
|
file_size: 0,
|
|
|
|
file_size: 0,
|
|
|
|
data_size: s.header.sh_size,
|
|
|
|
data_size: s.header.sh_size,
|
|
|
|
data_index: None,
|
|
|
|
data_index: None,
|
|
|
|
offset: s.header.sh_offset,
|
|
|
|
offset: s.header.sh_offset,
|
|
|
|
}))),
|
|
|
|
}))),
|
|
|
|
_ => None,
|
|
|
|
_ => None,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(iter)
|
|
|
|
Box::new(iter)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,7 +95,7 @@ impl Relocatable for ElfObject {
|
|
|
|
|
|
|
|
|
|
|
|
match §ion.contents {
|
|
|
|
match §ion.contents {
|
|
|
|
Contents64::Raw(v) => Ok(&v),
|
|
|
|
Contents64::Raw(v) => Ok(&v),
|
|
|
|
_ => Err(Error::InvalidSectionData)
|
|
|
|
_ => Err(Error::InvalidSectionData),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|