pijul nest
guest [sign in]

Elfedit: file sizes not aligned with page boundaries

pmeunier
May 8, 2025, 5:19 PM
VR4QJBTN4467XRJIZ6YYN64YEY5IRCJBRP7X5LCIBCARYYE76TBQC

Dependencies

  • [2] Z43EQIWN Elfedit: edit to file
  • [3] AR2X3TLA Initial commit: introducing elfedit
  • [4] 5PJAXSZ7 Elfedit: correct reallocation of dynstr/dynamic
  • [5] ZV57M4VN Debugging
  • [6] VZTI2E23 Elfedit: handling the case where we move the same section we're adding

Change contents

  • replacement in elfedit/src/lib.rs at line 1084
    [3.7629][3.7629:7706]()
    let rounded_last_vaddr = align_next(last_vaddr as usize, page_size);
    [3.7629]
    [3.24241]
    let mut rounded_last_vaddr = align_next(last_vaddr as usize, page_size);
  • edit in elfedit/src/lib.rs at line 1146
    [3.9990][3.9990:9991](),[3.9991][3.2413:2549](),[3.2549][3.10063:10088](),[3.10063][3.10063:10088]()
    // Combien de sections du début du fichier doit-on
    // déplacer à la fin pour ajouter notre nouveau header de
    // segment ?
  • edit in elfedit/src/lib.rs at line 1161
    [3.10470]
    [3.10470]
    // Can we add a new LOAD segment (i.e. is there space
    // immediately after the program header table?)
  • replacement in elfedit/src/lib.rs at line 1164
    [3.10548][3.10548:10802]()
    // In the absolute worst case, we need 3 new LOAD
    // segments: our new one, and then one for each end of
    // the sequence of sections we need to move to make
    // room for the program headers.
    [3.10548]
    [3.10802]
    // No space. We will move enough sections to the end
    // of the file, in order to make room.
    //
    // In the worst global case of patching, we need 3 new
    // LOAD segments:
    //
    // - two new ones (interp + dynstr)
    // - possibly an extra one for the initial segments we
    // need to move
  • edit in elfedit/src/lib.rs at line 1244
    [3.13746]
    [3.13746]
    rounded_last_vaddr = rounded_last_vaddr + rounded_moved as usize;
  • edit in elfedit/src/lib.rs at line 1246
    [3.13767]
    [2.421]
    // There is space after the program header table, no
    // need to move anything.
  • replacement in elfedit/src/lib.rs at line 1287
    [3.14561][3.14561:14658]()
    self.add_load_segment(id, new_offset, new.len(), last_vaddr as usize, 4, page_size);
    [3.14561]
    [3.26107]
    self.add_load_segment(id, new_offset, new.len(), rounded_last_vaddr as usize, 6, page_size);