/// <summary> /// Collects all required segments from the sections and determines /// their total size. /// </summary> /// <returns></returns> public Dictionary <ElfSection, Elf32_PHdr> ComputeSegmentSizes() { CollectCommonSymbolsIntoSection(); CollectUndefinedSymbolsIntoSection(); var mpToSegment = new Dictionary <ulong, Elf32_PHdr>(); var mpSectionToSegment = new Dictionary <ElfSection, Elf32_PHdr>(); foreach (var section in loader.Sections .Where(s => (s.Flags & ElfLoader.SHF_ALLOC) != 0)) { Elf32_PHdr segment; if (!mpToSegment.TryGetValue(section.Flags, out segment)) { segment = new Elf32_PHdr(); segment.p_flags = SegmentAccess(section.Flags); mpToSegment.Add(section.Flags, segment); Segments.Add(segment); } segment.p_pmemsz = Align(segment.p_pmemsz, (uint)section.Alignment); mpSectionToSegment.Add(section, segment); if (section.Type != SectionHeaderType.SHT_NOBITS) { segment.p_pmemsz += (uint)section.Size; segment.p_filesz += (uint)section.Size; } else { segment.p_pmemsz += (uint)section.Size; segment.p_filesz += 0; } } return(mpSectionToSegment); }
public static Elf32_PHdr Load(ImageReader rdr) { var hdr = new Elf32_PHdr { p_type = (ProgramHeaderType)rdr.ReadUInt32(), p_offset = rdr.ReadUInt32(), p_vaddr = rdr.ReadUInt32(), p_paddr = rdr.ReadUInt32(), p_filesz = rdr.ReadUInt32(), p_pmemsz = rdr.ReadUInt32(), p_flags = rdr.ReadUInt32(), p_align = rdr.ReadUInt32(), }; return hdr; }
public static Elf32_PHdr Load(EndianImageReader rdr) { var hdr = new Elf32_PHdr { p_type = (ProgramHeaderType)rdr.ReadUInt32(), p_offset = rdr.ReadUInt32(), p_vaddr = rdr.ReadUInt32(), p_paddr = rdr.ReadUInt32(), p_filesz = rdr.ReadUInt32(), p_pmemsz = rdr.ReadUInt32(), p_flags = rdr.ReadUInt32(), p_align = rdr.ReadUInt32(), }; return(hdr); }
public override int LoadSegments() { var rdr = imgLoader.CreateReader(Header.e_phoff); for (int i = 0; i < Header.e_phnum; ++i) { var sSeg = Elf32_PHdr.Load(rdr); Segments.Add(new ElfSegment { p_type = sSeg.p_type, p_offset = sSeg.p_offset, p_vaddr = sSeg.p_vaddr, p_paddr = sSeg.p_paddr, p_filesz = sSeg.p_filesz, p_pmemsz = sSeg.p_pmemsz, p_flags = sSeg.p_flags, p_align = sSeg.p_align, }); } return(Segments.Count); }
/// <summary> /// Collects all required segments from the sections and determines /// their total size. /// </summary> /// <returns></returns> public Dictionary<ElfSection, Elf32_PHdr> ComputeSegmentSizes() { CollectCommonSymbolsIntoSection(); CollectUndefinedSymbolsIntoSection(); var mpToSegment = new Dictionary<ulong, Elf32_PHdr>(); var mpSectionToSegment = new Dictionary<ElfSection, Elf32_PHdr>(); foreach (var section in loader.Sections .Where(s => (s.Flags & ElfLoader.SHF_ALLOC) != 0)) { Elf32_PHdr segment; if (!mpToSegment.TryGetValue(section.Flags, out segment)) { segment = new Elf32_PHdr(); segment.p_flags = SegmentAccess(section.Flags); mpToSegment.Add(section.Flags, segment); Segments.Add(segment); } segment.p_pmemsz = Align(segment.p_pmemsz, (uint)section.Alignment); mpSectionToSegment.Add(section, segment); if (section.Type != SectionHeaderType.SHT_NOBITS) { segment.p_pmemsz += (uint) section.Size; segment.p_filesz += (uint) section.Size; } else { segment.p_pmemsz += (uint) section.Size; segment.p_filesz += 0; } } return mpSectionToSegment; }