pijul nest
guest [sign in]

Debugging

pmeunier
Apr 27, 2025, 9:26 PM
ZV57M4VN53TJFCOLDOP7I4M4VAEN667SA37LR2HFFKFN5G2MTWIAC

Dependencies

  • [2] 5PJAXSZ7 Elfedit: correct reallocation of dynstr/dynamic
  • [3] WGAKJ25E Adding a debug_svg command
  • [4] AR2X3TLA Initial commit: introducing elfedit

Change contents

  • edit in elfedit/src/lib.rs at line 82
    [2.132]
    [3.2912]
    #[error("No dynamic section")]
    NoDynamicSection,
  • replacement in elfedit/src/lib.rs at line 95
    [3.3092][3.3092:3115]()
    struct Endianness(u8);
    [3.3092]
    [3.3115]
    pub struct Endianness(u8);
  • edit in elfedit/src/lib.rs at line 108
    [3.3359][3.3359:4026]()
    }
    #[allow(dead_code)]
    impl ABI {
    const SYSTEM_V: Self = ABI(0);
    const HPUX: Self = ABI(1);
    const NET_BSD: Self = ABI(2);
    const LINUX: Self = ABI(3);
    const GNU_HURD: Self = ABI(4);
    const SOLARIS: Self = ABI(6);
    const AIX: Self = ABI(7);
    const IRIX: Self = ABI(8);
    const FREE_BSD: Self = ABI(9);
    const TRU64: Self = ABI(10);
    const NOVELL_MODESTO: Self = ABI(11);
    const OPEN_BSD: Self = ABI(12);
    const OPEN_VMS: Self = ABI(13);
    const NON_STOP_KERNEL: Self = ABI(14);
    const AROS: Self = ABI(15);
    const FENIX_OS: Self = ABI(16);
    const NUXI_CLOUD_ABI: Self = ABI(17);
    const OPEN_VOS: Self = ABI(18);
  • replacement in elfedit/src/lib.rs at line 125
    [3.4358][3.4358:4370]()
    struct Id {
    [3.4358]
    [3.4370]
    pub struct Id {
  • replacement in elfedit/src/lib.rs at line 181
    [3.5590][3.5590:5628]()
    Sht(u32::from_le(e.0 .0))
    [3.5590]
    [3.5628]
    Sht(u32::from_le(e.0.0))
  • replacement in elfedit/src/lib.rs at line 183
    [3.5670][3.5670:5708]()
    Sht(u32::from_be(e.0 .0))
    [3.5670]
    [2.212]
    Sht(u32::from_be(e.0.0))
  • replacement in elfedit/src/lib.rs at line 265
    [2.1462][2.1462:1500]()
    Pht(u32::from_le(e.0 .0))
    [2.1462]
    [2.1500]
    Pht(u32::from_le(e.0.0))
  • replacement in elfedit/src/lib.rs at line 267
    [2.1542][2.1542:1580]()
    Pht(u32::from_be(e.0 .0))
    [2.1542]
    [2.1580]
    Pht(u32::from_be(e.0.0))
  • edit in elfedit/src/lib.rs at line 376
    [3.8470]
    [3.8470]
    // For now we set them to be equal.
    self.set_paddr(h, u);
  • edit in elfedit/src/lib.rs at line 379
    [3.8476]
    [3.8476]
    pub fn set_paddr(&mut self, h: Endianness, u: usize) {
    match self {
    ProgramHeaderMut_::B32(s) => s.paddr = <Endian<u32>>::from(h, u as u32),
    ProgramHeaderMut_::B64(s) => s.paddr = <Endian<u64>>::from(h, u as u64),
    }
    }
  • edit in elfedit/src/lib.rs at line 520
    [3.9977][3.9977:9997]()
    #[allow(dead_code)]
  • edit in elfedit/src/lib.rs at line 521
    [3.10008][3.10008:10039]()
    const NULL: Self = Pht(0);
  • edit in elfedit/src/lib.rs at line 522
    [3.10070][3.10070:10200]()
    const DYNAMIC: Self = Pht(2);
    const INTERP: Self = Pht(3);
    const NOTE: Self = Pht(4);
    const SHLIB: Self = Pht(5);
  • edit in elfedit/src/lib.rs at line 523
    [3.10231][3.10231:10425]()
    const TLS: Self = Pht(7);
    const LOOS: Self = Pht(0x60000000);
    const HIOS: Self = Pht(0x6fffffff);
    const LOPROC: Self = Pht(0x70000000);
    const HIPROC: Self = Pht(0x7fffffff);
  • replacement in elfedit/src/lib.rs at line 563
    [2.5236][2.5236:5290]()
    if e.id().magic == [0x7f, 0x45, 0x4c, 0x46] {
    [2.5236]
    [2.5290]
    if e.map.len() >= std::mem::size_of::<Header<u32>>()
    && e.id().magic == [0x7f, 0x45, 0x4c, 0x46]
    {
  • replacement in elfedit/src/lib.rs at line 815
    [3.15686][3.15686:15712]()
    fn id(&self) -> &Id {
    [3.15686]
    [3.15712]
    pub fn id(&self) -> &Id {
  • replacement in elfedit/src/lib.rs at line 822
    [3.15919][3.15919:16025]()
    // The aligment is guaranteed here by design of the
    // ELF file. The size isn't, however.
    [3.15919]
    [3.16025]
    // The aligment is guaranteed here by design of the ELF
    // file. The size isn't, however, so we need to check it.
  • replacement in elfedit/src/lib.rs at line 885
    [3.18288][3.18288:18339]()
    pub fn parse(&self) -> Result<Parsed, Error> {
    [3.18288]
    [3.18339]
    pub fn parse(&self) -> Result<Option<Parsed>, Error> {
  • replacement in elfedit/src/lib.rs at line 890
    [3.18494][3.18494:18539]()
    let mut dynamic = Dynamic::B32(&[]);
    [3.18494]
    [2.5503]
    let mut dynamic = None;
  • replacement in elfedit/src/lib.rs at line 911
    [2.5659][2.5659:5781]()
    dynamic =
    unsafe { dynamic_from_raw(id.class, self.map.as_ptr().add(offset), size) };
    [2.5659]
    [3.20454]
    dynamic = Some(unsafe {
    dynamic_from_raw(id.class, self.map.as_ptr().add(offset), size)
    });
  • edit in elfedit/src/lib.rs at line 915
    [3.20468]
    [3.20468]
    }
    if let Some(dynamic) = dynamic {
    Ok(Some(Parsed {
    data: id.data,
    dynstr,
    dynamic,
    interp,
    }))
    } else {
    Ok(None)
  • edit in elfedit/src/lib.rs at line 926
    [3.20478]
    [3.20478]
    }
  • replacement in elfedit/src/lib.rs at line 928
    [3.20479][3.20479:20499](),[3.20499][2.5782:5809](),[2.5809][3.20499:20571](),[3.20499][3.20499:20571]()
    Ok(Parsed {
    data: id.data,
    dynstr,
    dynamic,
    interp,
    })
    [3.20479]
    [3.20571]
    pub fn section_bytes(&self, name_: &[u8]) -> Result<Option<&[u8]>, Error> {
    let id = self.id();
    let header = self.header();
    let names = self.names(id.data, &header);
    for i in 0..header.shnum(id.data) {
    let s = self.section(i as usize);
    let name = names.name(s.name(id.data) as usize)?;
    if name.to_bytes() == name_ {
    let offset = s.offset(id.data) as usize;
    let size = s.size(id.data) as usize;
    return Ok(Some(&self.map[offset..offset + size]));
    }
    }
    Ok(None)
  • edit in elfedit/src/lib.rs at line 944
    [3.20578]
    [3.20578]
  • replacement in elfedit/src/lib.rs at line 1025
    [3.23146][3.23146:23266](),[3.23266][2.6366:6374]()
    fn update_section_allocate(
    &mut self,
    id: Endianness,
    new: &[u8],
    interp_i: usize,
    ) {
    [3.23146]
    [3.23301]
    fn update_section_allocate(&mut self, id: Endianness, new: &[u8], interp_i: usize) {
  • replacement in elfedit/src/lib.rs at line 1032
    [2.6503][2.6503:6579]()
    (sh.offset(id) as usize, sh.size(id) as usize, p_ as isize)
    [2.6503]
    [2.6579]
    (sh.offset(id) as usize,
    sh.size(id) as usize,
    sh.type_(id),
    p_ as isize)
  • edit in elfedit/src/lib.rs at line 1041
    [2.6737]
    [2.6737]
    Sht::NULL,
  • replacement in elfedit/src/lib.rs at line 1044
    [2.6765][2.6765:6811]()
    sections.sort_by_key(|(o, _, _)| *o);
    [2.6765]
    [3.23524]
    sections.sort_by_key(|(o, _, _, _)| *o);
  • replacement in elfedit/src/lib.rs at line 1048
    [2.6857][2.6857:6916]()
    .position(|(_, _, i)| *i == interp_i as isize)
    [2.6857]
    [2.6916]
    .position(|(_, _, _, i)| *i == interp_i as isize)
  • replacement in elfedit/src/lib.rs at line 1088
    [3.25044][2.8137:8196]()
    for (off, len, _) in sections.iter().skip(s + 1) {
    [3.25044]
    [2.8196]
    for (off, len, _, _) in sections.iter().skip(s + 1) {
  • replacement in elfedit/src/lib.rs at line 1134
    [2.9991][2.9991:10063]()
    // Combien de sections doit-on déplacer pour ajouter notre
    [2.9991]
    [2.10063]
    // Combien de sections du début du fichier doit-on
    // déplacer à la fin pour ajouter notre nouveau header de
  • replacement in elfedit/src/lib.rs at line 1140
    [2.10164][2.10164:10206]()
    .filter_map(|(o, _, _)| {
    [2.10164]
    [2.10206]
    .filter_map(|(o, _, _, _)| {
  • replacement in elfedit/src/lib.rs at line 1163
    [2.11061][2.11061:11129]()
    for (n, (o, _, _)) in sections.iter().enumerate() {
    [2.11061]
    [2.11129]
    for (n, (o, _, _, _)) in sections.iter().enumerate() {
  • replacement in elfedit/src/lib.rs at line 1173
    [2.11436][2.11436:11513]()
    let current_len = self.f.metadata().unwrap().len() as usize;
    [2.11436]
    [2.11513]
    // Max between the length of the file and the max of
    // the sections' span.
    let current_len =
    sections.iter().map(|(o, l, t, _)|
    if *t != Sht::NOBITS {
    o + l
    } else {
    0
    })
    .max()
    .unwrap_or(
    self.f.metadata().unwrap().len() as usize
    );
  • replacement in elfedit/src/lib.rs at line 1187
    [2.11583][2.11583:11691]()
    let rounded_moved =
    align_next(end_off - init_off, page_size as usize);
    [2.11583]
    [2.11691]
    let rounded_moved = align_next(end_off - init_off, page_size as usize);
  • replacement in elfedit/src/lib.rs at line 1204
    [2.12392][2.12392:12439]()
    let sec_n = sections[s].2;
    [2.12392]
    [2.12439]
    let sec_n = sections[s].3;
  • replacement in elfedit/src/lib.rs at line 1208
    [2.12655][2.12655:12820]()
    sec.set_addr(
    id,
    new_offset + rounded_last_vaddr - rounded_len as usize,
    );
    [2.12655]
    [2.12820]
    sec.set_addr(id, new_offset + rounded_last_vaddr - rounded_len as usize);
  • replacement in elfedit/src/lib.rs at line 1213
    [2.13136][2.13136:13332]()
    p.set_vaddr(
    id,
    new_offset + rounded_last_vaddr - rounded_len as usize,
    );
    [2.13136]
    [2.13332]
    p.set_vaddr(id, new_offset + rounded_last_vaddr - rounded_len as usize);
  • replacement in elfedit/src/lib.rs at line 1229
    [2.13767][2.13767:13844]()
    let current_len = self.f.metadata().unwrap().len() as usize;
    [2.13767]
    [2.13844]
    let current_len =
    sections.iter().map(|(o, l, t, _)| {
    if *t != Sht::NOBITS {
    o + l
    } else {
    0
    }
    })
    .max()
    .unwrap_or(
    self.f.metadata().unwrap().len() as usize
    );
  • replacement in elfedit/src/lib.rs at line 1283
    [2.15227][2.15227:15259]()
    p.set_flags(id, flags);
    [2.15227]
    [2.15259]
    p.set_flags(id, flags | 6); // must be RW since it's at the end.
  • replacement in elfedit/src/lib.rs at line 1307
    [3.27279][3.27279:27319]()
    let parsed = self.parse()?;
    [3.27279]
    [3.27319]
    let Some(parsed) = self.parse()? else {
    return Err(Error::NoDynamicSection)
    };
  • replacement in elfedit/src/lib.rs at line 1330
    [3.28040][3.28040:28080]()
    let parsed = self.parse()?;
    [3.28040]
    [3.28080]
    let Some(parsed) = self.parse()? else {
    return Err(Error::NoDynamicSection)
    };
  • replacement in elfedit/src/lib.rs at line 1348
    [3.28498][3.28498:28534]()
    let parsed = self.parse()?;
    [3.28498]
    [3.28534]
    let Some(parsed) = self.parse()? else {
    return Err(Error::NoDynamicSection)
    };
    let initial_dynamic_len = match dynamic {
    OwnedDynamic::B32(d) => d.len(),
    OwnedDynamic::B64(d) => d.len(),
    };
  • edit in elfedit/src/lib.rs at line 1369
    [2.15901]
    [3.29023]
    }
    match dynamic {
    OwnedDynamic::B32(d) =>
    while d.len() < initial_dynamic_len {
    d.push(u32::dyn_(id, u32::tag_nul(), 0));
    }
    OwnedDynamic::B64(d) =>
    while d.len() < initial_dynamic_len {
    d.push(u64::dyn_(id, u64::tag_nul(), 0));
    }
  • replacement in elfedit/src/lib.rs at line 1386
    [3.29106][3.29106:29137]()
    let p = self.parse()?;
    [3.29106]
    [3.29137]
    let Some(p) = self.parse()? else {
    return Ok(())
    };
  • replacement in elfedit/src/lib.rs at line 1395
    [3.29652][3.29652:29724]()
    let new_needed = std::mem::replace(&mut self.new_needed, None);
    [3.29652]
    [2.15975]
    let new_needed = self.new_needed.take();
  • replacement in elfedit/src/lib.rs at line 1406
    [2.16334][2.16334:16422]()
    self
    .update_section(b".dynamic", dynamic_owned.as_bytes())
    [2.16334]
    [2.16422]
    self.update_section(b".dynamic", dynamic_owned.as_bytes())
  • edit in elfedit/src/lib.rs at line 1427
    [2.16950][2.16950:17001]()
    // f.set_len(current_len + extra as u64)?;
  • edit in elfedit/src/lib.rs at line 1439
    [2.17507]
    [2.17507]
    } else if F::tag(id, *f) == F::dt_gnuhash() {
    let s = self.find_section::<F>(b".gnu.hash").unwrap().unwrap();
    let sec = self.section(s);
    F::set_d_un(id, f, sec.addr(id) as usize)
  • edit in elfedit/src/lib.rs at line 1502
    [3.32039]
    [2.17579]
    /// If the "needed" and/or "runpath" fields in the .dynamic section
    /// point to the end of the .dynstr section, we can optimise the
    /// .dynstr section by removing them first, and then adding them.
    ///
    /// Otherwise, we will (in other functions) leave these fields where
    /// they are, add new ones at the end and ignore the previous values.
  • edit in elfedit/src/lib.rs at line 1513
    [2.17706][3.32135:32160](),[3.32135][3.32135:32160]()
    // Put the tags last
  • replacement in elfedit/src/lib.rs at line 1557
    [2.18461][3.33320:33390](),[3.33320][3.33320:33390]()
    let mut n = 0;
    for (i, x) in dynamic.iter_mut().enumerate() {
    [2.18461]
    [2.18462]
    for x in dynamic.iter_mut() {
  • edit in elfedit/src/lib.rs at line 1574
    [3.34086][2.18614:18665](),[2.18665][3.34133:34151](),[3.34133][3.34133:34151]()
    } else if F::tag(id, *x) != F::tag_nul() {
    n = i
  • replacement in elfedit/src/lib.rs at line 1578
    [3.34224][2.18666:18730]()
    if F::tag(id, dynamic[dynamic.len() - 2]) == F::tag_nul() {
    [3.34224]
    [2.18730]
    // If the dynamic array ends with two DT_NULL, pop one.
    if dynamic.len() >= 2 && F::tag(id, dynamic[dynamic.len() - 2]) == F::tag_nul() {
  • replacement in elfedit/src/lib.rs at line 1582
    [2.18759][2.18759:18824]()
    dynamic.insert(n + 1, F::dyn_(id, F::dt_runpath(), offset));
    [2.18759]
    [3.34280]
    dynamic.insert(0, F::dyn_(id, F::dt_runpath(), offset));
  • edit in elfedit/src/lib.rs at line 1604
    [3.34710]
    [3.34710]
    let initial_dynamic_len = dynamic.len();
  • replacement in elfedit/src/lib.rs at line 1652
    [2.19832][3.36259:36295](),[3.36259][3.36259:36295]()
    if new_dynamic.len() % 1 == 1 {
    [2.19832]
    [3.36295]
    while new_dynamic.len() < initial_dynamic_len {
  • edit in elfedit/src/lib.rs at line 1805
    [3.41385]
    [2.21670]
    fn dt_gnuhash() -> Self::DynTag {
    Self::DynTag::from(0x000000006ffffef5)
    }
  • replacement in elfedit/src/lib.rs at line 1823
    [2.21866][2.21866:21920]()
    DynTag32(EndianT::endian(Endian(e.0 .0), id))
    [2.21866]
    [2.21920]
    DynTag32(EndianT::endian(Endian(e.0.0), id))
  • replacement in elfedit/src/lib.rs at line 1835
    [2.22024][2.22024:22078]()
    DynTag64(EndianT::endian(Endian(e.0 .0), id))
    [2.22024]
    [3.41634]
    DynTag64(EndianT::endian(Endian(e.0.0), id))
  • edit in elfedit/src/lib.rs at line 1927
    [3.43449]
    [3.43449]
    const NOBITS: Self = Sht(8);
  • replacement in elfedit/src/lib.rs at line 2000
    [3.45032][3.45032:45077]()
    fn phnum(&self, id: Endianness) -> u16 {
    [3.45032]
    [3.45077]
    pub fn phnum(&self, id: Endianness) -> u16 {
  • replacement in elfedit/src/lib.rs at line 2019
    [2.24085][2.24085:24260]()
    Dynamic::B32(unsafe { std::slice::from_raw_parts(
    ptr as *const Elf32Dyn,
    size / std::mem::size_of::<Elf32Dyn>(),
    ) })
    [2.24085]
    [2.24260]
    Dynamic::B32(unsafe {
    std::slice::from_raw_parts(
    ptr as *const Elf32Dyn,
    size / std::mem::size_of::<Elf32Dyn>(),
    )
    })
  • replacement in elfedit/src/lib.rs at line 2028
    [2.24371][2.24371:24544]()
    Dynamic::B64(unsafe {std::slice::from_raw_parts(
    ptr as *const Elf64Dyn,
    size / std::mem::size_of::<Elf64Dyn>(),
    )})
    [2.24371]
    [2.24544]
    Dynamic::B64(unsafe {
    std::slice::from_raw_parts(
    ptr as *const Elf64Dyn,
    size / std::mem::size_of::<Elf64Dyn>(),
    )
    })