MCPcopy Create free account
hub / github.com/MagnetForensics/dumpit-linux / reserve_program_notes

Method reserve_program_notes

src/main.rs:454–502  ·  view source on GitHub ↗
(
        &self,
        endian: P::Endian,
        writer: &mut object::write::elf::Writer,
        in_segments: &[P],
        in_data: &[u8]
    )

Source from the content-addressed store, hash-verified

452 }
453
454 fn reserve_program_notes<P: ProgramHeader<Word = u64>>(
455 &self,
456 endian: P::Endian,
457 writer: &mut object::write::elf::Writer,
458 in_segments: &[P],
459 in_data: &[u8]
460 ) {
461 let mut is_vmci_present = false;
462
463 for section in in_segments.iter() {
464 if let Ok(Some(mut notes)) = section.notes(endian, in_data) {
465 while let Ok(Some(note)) = notes.next() {
466 // For some reasons writer.reserve() doesn't align things properly.
467 writer.reserve(mem::size_of::<NoteHeader64<Endianness>>(), ELF_ALIGN);
468 let pad = round_up(writer.reserved_len(), ELF_ALIGN) - writer.reserved_len();
469 writer.reserve(pad, 1);
470
471 writer.reserve(note.n_namesz(endian) as usize, 4);
472 let pad = round_up(writer.reserved_len(), ELF_ALIGN) - writer.reserved_len();
473 writer.reserve(pad, 1);
474
475 writer.reserve(note.n_descsz(endian) as usize, ELF_ALIGN);
476 let pad = round_up(writer.reserved_len(), ELF_ALIGN) - writer.reserved_len();
477 writer.reserve(pad, 1);
478
479 if note.name() == b"VMCOREINFO" {
480 is_vmci_present = true;
481 break;
482 }
483 }
484 }
485 }
486
487 if is_vmci_present == false {
488 if let Some(data) = &self.vmcoreinfo {
489 writer.reserve(mem::size_of::<NoteHeader64<Endianness>>(), ELF_ALIGN);
490 let pad = round_up(writer.reserved_len(), ELF_ALIGN) - writer.reserved_len();
491 writer.reserve(pad, 1);
492
493 writer.reserve(b"VMCOREINFO\0".len(), ELF_ALIGN);
494 let pad = round_up(writer.reserved_len(), ELF_ALIGN) - writer.reserved_len();
495 writer.reserve(pad, 1);
496
497 writer.reserve(data.len(), ELF_ALIGN);
498 let pad = round_up(writer.reserved_len(), ELF_ALIGN) - writer.reserved_len();
499 writer.reserve(pad, 1);
500 }
501 }
502 }
503
504 fn build_elf_header<P: ProgramHeader<Word = u64, Endian = Endianness>>(
505 &self,

Callers 1

build_elf_headerMethod · 0.80

Calls 1

round_upFunction · 0.85

Tested by

no test coverage detected