| 1 |
use crate::errors::ModuleReaderError as Error; |
| 2 |
use crate::mem_reader::MemReader; |
| 3 |
use crate::minidump_format::GUID; |
| 4 |
use goblin::{ |
| 5 |
container::{Container, Ctx, Endian}, |
| 6 |
elf, |
| 7 |
}; |
| 8 |
use std::{borrow::Cow, ffi::CStr}; |
| 9 |
|
| 10 |
type Buf<'buf> = Cow<'buf, [u8]>; |
| 11 |
|
| 12 |
const NOTE_SECTION_NAME: &[u8] = b".note.gnu.build-id\0"; |
| 13 |
|
| 14 |
pub struct ProcessReader { |
| 15 |
inner: MemReader, |
| 16 |
start_address: u64, |
| 17 |
} |
| 18 |
|
| 19 |
impl ProcessReader { |
| 20 |
pub fn new(pid: i32, start_address: usize) -> Self { |
| 21 |
Self { |
| 22 |
inner: MemReader::new(pid), |
| 23 |
start_address: start_address as u64, |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
pub enum ProcessMemory<'buf> { |
| 29 |
Slice(&'buf [u8]), |
| 30 |
Process(ProcessReader), |
| 31 |
} |
| 32 |
|
| 33 |
impl<'buf> From<&'buf [u8]> for ProcessMemory<'buf> { |
| 34 |
fn from(value: &'buf [u8]) -> Self { |
| 35 |
Self::Slice(value) |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
impl From<ProcessReader> for ProcessMemory<'_> { |
| 40 |
fn from(value: ProcessReader) -> Self { |
| 41 |
Self::Process(value) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
impl<'buf> ProcessMemory<'buf> { |
| 46 |
#[inline] |
| 47 |
fn read(&mut self, offset: u64, length: u64) -> Result<Buf<'buf>, Error> { |
| 48 |
let error = move |start_address, error| Error::ReadModuleMemory { |
| 49 |
start_address, |
| 50 |
offset, |
| 51 |
length, |
| 52 |
error, |
| 53 |
}; |
| 54 |
|
| 55 |
match self { |
| 56 |
Self::Process(pr) => { |
| 57 |
let error = |e| error(Some(pr.start_address), e); |
| 58 |
let len = std::num::NonZeroUsize::new(length as usize) |
| 59 |
.ok_or_else(|| error(nix::Error::EINVAL))?; |
| 60 |
let proc_offset = pr |
| 61 |
.start_address |
| 62 |
.checked_add(offset) |
| 63 |
.ok_or_else(|| error(nix::Error::EOVERFLOW))?; |
| 64 |
pr.inner |
| 65 |
.read_to_vec(proc_offset as _, len) |
| 66 |
.map(Cow::Owned) |
| 67 |
.map_err(|err| error(err.source)) |
| 68 |
} |
| 69 |
Self::Slice(s) => { |
| 70 |
let error = |e| error(None, e); |
| 71 |
let end = offset |
| 72 |
.checked_add(length) |
| 73 |
.ok_or_else(|| error(nix::Error::EOVERFLOW))?; |
| 74 |
s.get(offset as usize..end as usize) |
| 75 |
.map(Cow::Borrowed) |
| 76 |
.ok_or_else(|| error(nix::Error::EACCES)) |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/// Calculates the absolute address of the specified relative address |
| 82 |
#[inline] |
| 83 |
fn absolute(&self, addr: u64) -> u64 { |
| 84 |
let Self::Process(pr) = self else { |
| 85 |
return addr; |
| 86 |
}; |
| 87 |
addr.checked_sub(pr.start_address).unwrap_or(addr) |
| 88 |
} |
| 89 |
|
| 90 |
#[inline] |
| 91 |
fn is_process_memory(&self) -> bool { |
| 92 |
matches!(self, Self::Process(_)) |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
#[inline] |
| 97 |
fn is_executable_section(header: &elf::SectionHeader) -> bool { |
| 98 |
header.sh_type == elf::section_header::SHT_PROGBITS |
| 99 |
&& header.sh_flags & u64::from(elf::section_header::SHF_ALLOC) != 0 |
| 100 |
&& header.sh_flags & u64::from(elf::section_header::SHF_EXECINSTR) != 0 |
| 101 |
} |
| 102 |
|
| 103 |
/// Return bytes to use as a build id, computed by hashing the given data. |
| 104 |
/// |
| 105 |
/// This provides `size_of::<GUID>` bytes to keep identifiers produced by this function compatible |
| 106 |
/// with other build ids. |
| 107 |
fn build_id_from_bytes(data: &[u8]) -> Vec<u8> { |
| 108 |
// Only provide mem::size_of(MDGUID) bytes to keep identifiers produced by this |
| 109 |
// function backwards-compatible. |
| 110 |
data.chunks(std::mem::size_of::<GUID>()).fold( |
| 111 |
vec![0u8; std::mem::size_of::<GUID>()], |
| 112 |
|mut bytes, chunk| { |
| 113 |
bytes |
| 114 |
.iter_mut() |
| 115 |
.zip(chunk.iter()) |
| 116 |
.for_each(|(b, c)| *b ^= *c); |
| 117 |
bytes |
| 118 |
}, |
| 119 |
) |
| 120 |
} |
| 121 |
|
| 122 |
// `name` should be null-terminated |
| 123 |
fn section_header_with_name<'sc>( |
| 124 |
section_headers: &'sc elf::SectionHeaders, |
| 125 |
strtab_index: usize, |
| 126 |
name: &[u8], |
| 127 |
module_memory: &mut ProcessMemory<'_>, |
| 128 |
) -> Result<Option<&'sc elf::SectionHeader>, Error> { |
| 129 |
let strtab_section_header = section_headers |
| 130 |
.get(strtab_index) |
| 131 |
.and_then(|hdr| (hdr.sh_type == elf::section_header::SHT_STRTAB).then_some(hdr)) |
| 132 |
.ok_or(Error::NoStrTab)?; |
| 133 |
|
| 134 |
for header in section_headers { |
| 135 |
let sh_name = header.sh_name as u64; |
| 136 |
if sh_name >= strtab_section_header.sh_size { |
| 137 |
log::warn!("invalid sh_name offset for {:?}", name); |
| 138 |
continue; |
| 139 |
} |
| 140 |
if sh_name + name.len() as u64 >= strtab_section_header.sh_size { |
| 141 |
// This can't be a match. |
| 142 |
continue; |
| 143 |
} |
| 144 |
let n = module_memory.read(strtab_section_header.sh_offset + sh_name, name.len() as u64)?; |
| 145 |
if name == &*n { |
| 146 |
return Ok(Some(header)); |
| 147 |
} |
| 148 |
} |
| 149 |
Ok(None) |
| 150 |
} |
| 151 |
|
| 152 |
/// Types which can be read from ProcessMemory. |
| 153 |
pub trait ReadFromModule: Sized { |
| 154 |
fn read_from_module(module_memory: ProcessMemory<'_>) -> Result<Self, Error>; |
| 155 |
|
| 156 |
fn read_from_file(path: &std::path::Path) -> Result<Self, Error> { |
| 157 |
let map = std::fs::File::open(path) |
| 158 |
// Safety: the file is an executable binary (very likely read-only), and won't be changed. |
| 159 |
.and_then(|file| unsafe { memmap2::Mmap::map(&file) }) |
| 160 |
.map_err(|error| Error::MapFile { |
| 161 |
path: path.to_owned(), |
| 162 |
error, |
| 163 |
})?; |
| 164 |
Self::read_from_module(ProcessMemory::Slice(&map)) |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
/// The module build id. |
| 169 |
pub struct BuildId(pub Vec<u8>); |
| 170 |
|
| 171 |
impl ReadFromModule for BuildId { |
| 172 |
fn read_from_module(module_memory: ProcessMemory<'_>) -> Result<Self, Error> { |
| 173 |
let mut reader = ModuleReader::new(module_memory)?; |
| 174 |
let program_headers = match reader.build_id_from_program_headers() { |
| 175 |
Ok(v) => return Ok(BuildId(v)), |
| 176 |
Err(e) => Box::new(e), |
| 177 |
}; |
| 178 |
let section = match reader.build_id_from_section() { |
| 179 |
Ok(v) => return Ok(BuildId(v)), |
| 180 |
Err(e) => Box::new(e), |
| 181 |
}; |
| 182 |
let generated = match reader.build_id_generate_from_text() { |
| 183 |
Ok(v) => return Ok(BuildId(v)), |
| 184 |
Err(e) => Box::new(e), |
| 185 |
}; |
| 186 |
Err(Error::NoBuildId { |
| 187 |
program_headers, |
| 188 |
section, |
| 189 |
generated, |
| 190 |
}) |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
struct DynIter<'a> { |
| 195 |
data: &'a [u8], |
| 196 |
offset: usize, |
| 197 |
ctx: Ctx, |
| 198 |
} |
| 199 |
|
| 200 |
impl<'a> DynIter<'a> { |
| 201 |
pub fn new(data: &'a [u8], ctx: Ctx) -> Self { |
| 202 |
DynIter { |
| 203 |
data, |
| 204 |
offset: 0, |
| 205 |
ctx, |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
impl Iterator for DynIter<'_> { |
| 211 |
type Item = Result<elf::dynamic::Dyn, Error>; |
| 212 |
|
| 213 |
fn next(&mut self) -> Option<Self::Item> { |
| 214 |
use scroll::Pread; |
| 215 |
let dyn_: elf::dynamic::Dyn = match self.data.gread_with(&mut self.offset, self.ctx) { |
| 216 |
Ok(v) => v, |
| 217 |
Err(e) => return Some(Err(e.into())), |
| 218 |
}; |
| 219 |
if dyn_.d_tag == elf::dynamic::DT_NULL { |
| 220 |
None |
| 221 |
} else { |
| 222 |
Some(Ok(dyn_)) |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
/// The module SONAME. |
| 228 |
#[derive(Default, Clone, Debug)] |
| 229 |
pub struct SoName(pub String); |
| 230 |
|
| 231 |
impl ReadFromModule for SoName { |
| 232 |
fn read_from_module(module_memory: ProcessMemory<'_>) -> Result<Self, Error> { |
| 233 |
let mut reader = ModuleReader::new(module_memory)?; |
| 234 |
let program_headers = match reader.soname_from_program_headers() { |
| 235 |
Ok(v) => return Ok(SoName(v)), |
| 236 |
Err(e) => Box::new(e), |
| 237 |
}; |
| 238 |
let section = match reader.soname_from_sections() { |
| 239 |
Ok(v) => return Ok(SoName(v)), |
| 240 |
Err(e) => Box::new(e), |
| 241 |
}; |
| 242 |
Err(Error::NoSoName { |
| 243 |
program_headers, |
| 244 |
section, |
| 245 |
}) |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
pub struct ModuleReader<'buf> { |
| 250 |
module_memory: ProcessMemory<'buf>, |
| 251 |
header: elf::Header, |
| 252 |
context: Ctx, |
| 253 |
} |
| 254 |
|
| 255 |
impl<'buf> ModuleReader<'buf> { |
| 256 |
pub fn new(mut module_memory: ProcessMemory<'buf>) -> Result<Self, Error> { |
| 257 |
// We could use `Ctx::default()` (which defaults to the native system), however to be extra |
| 258 |
// permissive we'll just use a 64-bit ("Big") context which would result in the largest |
| 259 |
// possible header size. |
| 260 |
let header_size = elf::Header::size(Ctx::new(Container::Big, Endian::default())); |
| 261 |
let header_data = module_memory.read(0, header_size as u64)?; |
| 262 |
let header = elf::Elf::parse_header(&header_data)?; |
| 263 |
let context = Ctx::new(header.container()?, header.endianness()?); |
| 264 |
|
| 265 |
Ok(Self { |
| 266 |
module_memory, |
| 267 |
header, |
| 268 |
context, |
| 269 |
}) |
| 270 |
} |
| 271 |
|
| 272 |
/// Read the SONAME using program headers to locate dynamic library information. |
| 273 |
pub fn soname_from_program_headers(&mut self) -> Result<String, Error> { |
| 274 |
let program_headers = self.read_program_headers()?; |
| 275 |
|
| 276 |
let dynamic_segment_header = program_headers |
| 277 |
.iter() |
| 278 |
.find(|h| h.p_type == elf::program_header::PT_DYNAMIC) |
| 279 |
.ok_or(Error::NoDynamicSection)?; |
| 280 |
|
| 281 |
let dynamic_section = self.read_segment(dynamic_segment_header)?; |
| 282 |
|
| 283 |
let mut soname_strtab_offset = None; |
| 284 |
let mut strtab_addr = None; |
| 285 |
let mut strtab_size = None; |
| 286 |
for dyn_ in DynIter::new(&dynamic_section, self.context) { |
| 287 |
let dyn_ = dyn_?; |
| 288 |
match dyn_.d_tag { |
| 289 |
elf::dynamic::DT_SONAME => soname_strtab_offset = Some(dyn_.d_val), |
| 290 |
elf::dynamic::DT_STRTAB => strtab_addr = Some(dyn_.d_val), |
| 291 |
elf::dynamic::DT_STRSZ => strtab_size = Some(dyn_.d_val), |
| 292 |
_ => (), |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
match (strtab_addr, strtab_size, soname_strtab_offset) { |
| 297 |
(None, _, _) | (_, None, _) => Err(Error::NoDynStrSection), |
| 298 |
(_, _, None) => Err(Error::NoSoNameEntry), |
| 299 |
(Some(addr), Some(size), Some(offset)) => { |
| 300 |
// If loaded in memory, the address will be altered to be absolute. |
| 301 |
if offset < size { |
| 302 |
self.read_name_from_strtab(self.module_memory.absolute(addr), size, offset) |
| 303 |
} else { |
| 304 |
log::warn!("soname strtab offset ({offset}) exceeds strtab size ({size})"); |
| 305 |
Err(Error::NoSoNameEntry) |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
/// Read the SONAME using section headers to locate dynamic library information. |
| 312 |
pub fn soname_from_sections(&mut self) -> Result<String, Error> { |
| 313 |
let section_headers = self.read_section_headers()?; |
| 314 |
|
| 315 |
let dynamic_section_header = section_headers |
| 316 |
.iter() |
| 317 |
.find(|h| h.sh_type == elf::section_header::SHT_DYNAMIC) |
| 318 |
.ok_or(Error::NoDynamicSection)?; |
| 319 |
|
| 320 |
let dynstr_section_header = |
| 321 |
match section_headers.get(dynamic_section_header.sh_link as usize) { |
| 322 |
Some(header) if header.sh_type == elf::section_header::SHT_STRTAB => header, |
| 323 |
_ => section_header_with_name( |
| 324 |
§ion_headers, |
| 325 |
self.header.e_shstrndx as usize, |
| 326 |
b".dynstr\0", |
| 327 |
&mut self.module_memory, |
| 328 |
)? |
| 329 |
.ok_or(Error::NoDynStrSection)?, |
| 330 |
}; |
| 331 |
|
| 332 |
let dynamic_section = self.module_memory.read( |
| 333 |
self.section_offset(dynamic_section_header), |
| 334 |
dynamic_section_header.sh_size, |
| 335 |
)?; |
| 336 |
|
| 337 |
for dyn_ in DynIter::new(&dynamic_section, self.context) { |
| 338 |
let dyn_ = dyn_?; |
| 339 |
if dyn_.d_tag == elf::dynamic::DT_SONAME { |
| 340 |
let name_offset = dyn_.d_val; |
| 341 |
if name_offset < dynstr_section_header.sh_size { |
| 342 |
return self.read_name_from_strtab( |
| 343 |
self.section_offset(dynstr_section_header), |
| 344 |
dynstr_section_header.sh_size, |
| 345 |
name_offset, |
| 346 |
); |
| 347 |
} else { |
| 348 |
log::warn!( |
| 349 |
"soname offset ({name_offset}) exceeds dynstr section size ({})", |
| 350 |
dynstr_section_header.sh_size |
| 351 |
); |
| 352 |
} |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
Err(Error::NoSoNameEntry) |
| 357 |
} |
| 358 |
|
| 359 |
/// Read the build id from a program header note. |
| 360 |
pub fn build_id_from_program_headers(&mut self) -> Result<Vec<u8>, Error> { |
| 361 |
let program_headers = self.read_program_headers()?; |
| 362 |
for header in program_headers { |
| 363 |
if header.p_type != elf::program_header::PT_NOTE { |
| 364 |
continue; |
| 365 |
} |
| 366 |
if let Ok(Some(result)) = |
| 367 |
self.find_build_id_note(header.p_offset, header.p_filesz, header.p_align) |
| 368 |
{ |
| 369 |
return Ok(result); |
| 370 |
} |
| 371 |
} |
| 372 |
Err(Error::NoProgramHeaderNote) |
| 373 |
} |
| 374 |
|
| 375 |
/// Read the build id from a notes section. |
| 376 |
pub fn build_id_from_section(&mut self) -> Result<Vec<u8>, Error> { |
| 377 |
let section_headers = self.read_section_headers()?; |
| 378 |
|
| 379 |
let header = section_header_with_name( |
| 380 |
§ion_headers, |
| 381 |
self.header.e_shstrndx as usize, |
| 382 |
NOTE_SECTION_NAME, |
| 383 |
&mut self.module_memory, |
| 384 |
)? |
| 385 |
.ok_or(Error::NoSectionNote)?; |
| 386 |
|
| 387 |
match self.find_build_id_note(header.sh_offset, header.sh_size, header.sh_addralign) { |
| 388 |
Ok(Some(v)) => Ok(v), |
| 389 |
Ok(None) => Err(Error::NoSectionNote), |
| 390 |
Err(e) => Err(e), |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
/// Generate a build id by hashing the first page of the text section. |
| 395 |
pub fn build_id_generate_from_text(&mut self) -> Result<Vec<u8>, Error> { |
| 396 |
let Some(text_header) = self |
| 397 |
.read_section_headers()? |
| 398 |
.into_iter() |
| 399 |
.find(is_executable_section) |
| 400 |
else { |
| 401 |
return Err(Error::NoTextSection); |
| 402 |
}; |
| 403 |
|
| 404 |
// Take at most one page of the text section (we assume page size is 4096 bytes). |
| 405 |
let len = std::cmp::min(4096, text_header.sh_size); |
| 406 |
let text_data = self.module_memory.read(text_header.sh_offset, len)?; |
| 407 |
Ok(build_id_from_bytes(&text_data)) |
| 408 |
} |
| 409 |
|
| 410 |
fn read_segment(&mut self, header: &elf::ProgramHeader) -> Result<Buf<'buf>, Error> { |
| 411 |
let (offset, size) = if self.module_memory.is_process_memory() { |
| 412 |
(header.p_vaddr, header.p_memsz) |
| 413 |
} else { |
| 414 |
(header.p_offset, header.p_filesz) |
| 415 |
}; |
| 416 |
|
| 417 |
self.module_memory.read(offset, size) |
| 418 |
} |
| 419 |
|
| 420 |
fn read_name_from_strtab( |
| 421 |
&mut self, |
| 422 |
strtab_offset: u64, |
| 423 |
strtab_size: u64, |
| 424 |
name_offset: u64, |
| 425 |
) -> Result<String, Error> { |
| 426 |
assert!(name_offset < strtab_size); |
| 427 |
let name = self |
| 428 |
.module_memory |
| 429 |
.read(strtab_offset + name_offset, strtab_size - name_offset)?; |
| 430 |
CStr::from_bytes_until_nul(&name) |
| 431 |
.map(|s| s.to_string_lossy().into_owned()) |
| 432 |
.map_err(|_| Error::StrTabNoNulByte) |
| 433 |
} |
| 434 |
|
| 435 |
fn section_offset(&self, header: &elf::SectionHeader) -> u64 { |
| 436 |
if self.module_memory.is_process_memory() { |
| 437 |
header.sh_addr |
| 438 |
} else { |
| 439 |
header.sh_offset |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
fn read_program_headers(&mut self) -> Result<elf::ProgramHeaders, Error> { |
| 444 |
if self.header.e_phoff == 0 { |
| 445 |
return Err(Error::NoProgramHeaders); |
| 446 |
} |
| 447 |
let program_headers_data = self.module_memory.read( |
| 448 |
self.header.e_phoff, |
| 449 |
self.header.e_phentsize as u64 * self.header.e_phnum as u64, |
| 450 |
)?; |
| 451 |
let program_headers = elf::ProgramHeader::parse( |
| 452 |
&program_headers_data, |
| 453 |
0, |
| 454 |
self.header.e_phnum as usize, |
| 455 |
self.context, |
| 456 |
)?; |
| 457 |
Ok(program_headers) |
| 458 |
} |
| 459 |
|
| 460 |
fn read_section_headers(&mut self) -> Result<elf::SectionHeaders, Error> { |
| 461 |
if self.header.e_shoff == 0 { |
| 462 |
return Err(Error::NoSections); |
| 463 |
} |
| 464 |
|
| 465 |
let section_headers_data = self.module_memory.read( |
| 466 |
self.header.e_shoff, |
| 467 |
self.header.e_shentsize as u64 * self.header.e_shnum as u64, |
| 468 |
)?; |
| 469 |
// Use `parse_from` rather than `parse`, which allows a 0 offset. |
| 470 |
let section_headers = elf::SectionHeader::parse_from( |
| 471 |
§ion_headers_data, |
| 472 |
0, |
| 473 |
self.header.e_shnum as usize, |
| 474 |
self.context, |
| 475 |
)?; |
| 476 |
Ok(section_headers) |
| 477 |
} |
| 478 |
|
| 479 |
fn find_build_id_note( |
| 480 |
&mut self, |
| 481 |
offset: u64, |
| 482 |
size: u64, |
| 483 |
alignment: u64, |
| 484 |
) -> Result<Option<Vec<u8>>, Error> { |
| 485 |
let notes = self.module_memory.read(offset, size)?; |
| 486 |
for note in (elf::note::NoteDataIterator { |
| 487 |
data: ¬es, |
| 488 |
// Note that `NoteDataIterator::size` is poorly named, it is actually an end offset. In |
| 489 |
// this case since our start offset is 0 we still set it to the size. |
| 490 |
size: size as usize, |
| 491 |
offset: 0, |
| 492 |
ctx: (alignment as usize, self.context), |
| 493 |
}) { |
| 494 |
let Ok(note) = note else { break }; |
| 495 |
if note.name == "GNU" && note.n_type == elf::note::NT_GNU_BUILD_ID { |
| 496 |
return Ok(Some(note.desc.to_owned())); |
| 497 |
} |
| 498 |
} |
| 499 |
Ok(None) |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
#[cfg(test)] |
| 504 |
mod test { |
| 505 |
use super::*; |
| 506 |
|
| 507 |
/// This is a small (but valid) 64-bit little-endian elf executable with the following layout: |
| 508 |
/// * ELF header |
| 509 |
/// * program header: text segment |
| 510 |
/// * program header: note |
| 511 |
/// * program header: dynamic |
| 512 |
/// * section header: null |
| 513 |
/// * section header: .text |
| 514 |
/// * section header: .note.gnu.build-id |
| 515 |
/// * section header: .shstrtab |
| 516 |
/// * section header: .dynamic |
| 517 |
/// * section header: .dynstr |
| 518 |
/// * note header (build id note) |
| 519 |
/// * shstrtab |
| 520 |
/// * dynamic (SONAME/STRTAB/STRSZ) |
| 521 |
/// * dynstr (SONAME string = libfoo.so.1) |
| 522 |
/// * program (calls exit(0)) |
| 523 |
const TINY_ELF: &[u8] = &[ |
| 524 |
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 525 |
0x00, 0x02, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x03, 0x40, 0x00, 0x00, 0x00, |
| 526 |
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0x00, 0x00, 0x00, 0x00, |
| 527 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0x03, 0x00, 0x40, 0x00, |
| 528 |
0x06, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x0a, 0x03, 0x00, |
| 529 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 530 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, |
| 531 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 532 |
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 533 |
0x00, 0x68, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 534 |
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, |
| 535 |
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 536 |
0x00, 0x00, 0x00, 0x00, 0xbd, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x02, 0x40, |
| 537 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, |
| 538 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, |
| 539 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 540 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 541 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 542 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 543 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
| 544 |
0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x03, 0x40, |
| 545 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, |
| 546 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 547 |
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 548 |
0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 549 |
0x00, 0x68, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x02, 0x00, 0x00, 0x00, 0x00, |
| 550 |
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 551 |
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 552 |
0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 553 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x02, |
| 554 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 555 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 556 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, |
| 557 |
0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x02, 0x40, 0x00, 0x00, 0x00, |
| 558 |
0x00, 0x00, 0xbd, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, |
| 559 |
0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, |
| 560 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, |
| 561 |
0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x02, |
| 562 |
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, |
| 563 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 564 |
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 565 |
0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x4e, |
| 566 |
0x55, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, |
| 567 |
0x0e, 0x0f, 0x10, 0x00, 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2e, 0x6e, 0x6f, 0x74, 0x65, |
| 568 |
0x2e, 0x67, 0x6e, 0x75, 0x2e, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x2d, 0x69, 0x64, 0x00, 0x2e, |
| 569 |
0x73, 0x68, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x61, 0x6d, |
| 570 |
0x69, 0x63, 0x00, 0x2e, 0x64, 0x79, 0x6e, 0x73, 0x74, 0x72, 0x00, 0x0e, 0x00, 0x00, 0x00, |
| 571 |
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, |
| 572 |
0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, |
| 573 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 574 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 575 |
0x00, 0x6c, 0x69, 0x62, 0x66, 0x6f, 0x6f, 0x2e, 0x73, 0x6f, 0x2e, 0x31, 0x00, 0x6a, 0x3c, |
| 576 |
0x58, 0x31, 0xff, 0x0f, 0x05, |
| 577 |
]; |
| 578 |
|
| 579 |
#[test] |
| 580 |
fn build_id_program_headers() { |
| 581 |
let mut reader = ModuleReader::new(TINY_ELF.into()).unwrap(); |
| 582 |
let id = reader.build_id_from_program_headers().unwrap(); |
| 583 |
assert_eq!( |
| 584 |
id, |
| 585 |
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] |
| 586 |
); |
| 587 |
} |
| 588 |
|
| 589 |
#[test] |
| 590 |
fn build_id_section() { |
| 591 |
let mut reader = ModuleReader::new(TINY_ELF.into()).unwrap(); |
| 592 |
let id = reader.build_id_from_section().unwrap(); |
| 593 |
assert_eq!( |
| 594 |
id, |
| 595 |
vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] |
| 596 |
); |
| 597 |
} |
| 598 |
|
| 599 |
#[test] |
| 600 |
fn build_id_text_hash() { |
| 601 |
let mut reader = ModuleReader::new(TINY_ELF.into()).unwrap(); |
| 602 |
let id = reader.build_id_generate_from_text().unwrap(); |
| 603 |
assert_eq!( |
| 604 |
id, |
| 605 |
vec![0x6a, 0x3c, 0x58, 0x31, 0xff, 0x0f, 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
| 606 |
); |
| 607 |
} |
| 608 |
|
| 609 |
#[test] |
| 610 |
fn soname_program_headers() { |
| 611 |
let mut reader = ModuleReader::new(TINY_ELF.into()).unwrap(); |
| 612 |
let soname = reader.soname_from_program_headers().unwrap(); |
| 613 |
assert_eq!(soname, "libfoo.so.1"); |
| 614 |
} |
| 615 |
|
| 616 |
#[test] |
| 617 |
fn soname_section() { |
| 618 |
let mut reader = ModuleReader::new(TINY_ELF.into()).unwrap(); |
| 619 |
let soname = reader.soname_from_sections().unwrap(); |
| 620 |
assert_eq!(soname, "libfoo.so.1"); |
| 621 |
} |
| 622 |
} |