Beispiel #1
0
        private void WriteProgramHeaders()
        {
            elfheader.ProgramHeaderOffset = ElfHeader.GetEntrySize(linkerFormatType);

            writer.Position = elfheader.ProgramHeaderOffset;

            elfheader.ProgramHeaderNumber = 0;

            foreach (var section in linker.LinkerSections)
            {
                if (section.Size == 0 && section.SectionKind != SectionKind.BSS)
                {
                    continue;
                }

                var programHeader = new ProgramHeader
                {
                    Alignment       = section.SectionAlignment,
                    FileSize        = section.AlignedSize,
                    MemorySize      = section.AlignedSize,
                    Offset          = section.FileOffset,
                    VirtualAddress  = section.VirtualAddress,
                    PhysicalAddress = section.VirtualAddress,
                    Type            = ProgramHeaderType.Load,
                    Flags           =
                        (section.SectionKind == SectionKind.Text) ? ProgramHeaderFlags.Read | ProgramHeaderFlags.Execute :
                        (section.SectionKind == SectionKind.ROData) ? ProgramHeaderFlags.Read : ProgramHeaderFlags.Read | ProgramHeaderFlags.Write
                };

                programHeader.Write(linkerFormatType, writer);

                elfheader.ProgramHeaderNumber++;
            }
        }
Beispiel #2
0
        private void WriteSectionHeaders()
        {
            elfheader.SectionHeaderOffset = elfheader.ProgramHeaderOffset + (ProgramHeader.GetEntrySize(linkerFormatType) * elfheader.ProgramHeaderNumber);

            writer.SetPosition(elfheader.SectionHeaderOffset);

            foreach (var section in sections)
            {
                section.WriteSectionHeader(linkerFormatType, writer);
            }
        }
Beispiel #3
0
        private void WriteProgramHeader(BinaryWriter writer)
        {
            elfheader.ProgramHeaderOffset = ElfHeader.GetEntrySize(LinkerFormatType);

            writer.SetPosition(elfheader.ProgramHeaderOffset);

            elfheader.ProgramHeaderNumber = 0;

            foreach (var section in sections)
            {
                if (section.SectionKind == SectionKind.Unknown)
                {
                    continue;
                }

                if (section.Size == 0 && section.SectionKind != SectionKind.BSS)
                {
                    continue;
                }

                if (section.Address == 0)
                {
                    continue;
                }

                var programHeader = new ProgramHeader
                {
                    Alignment       = SectionAlignment,
                    FileSize        = Alignment.AlignUp(section.Size, SectionAlignment),
                    MemorySize      = Alignment.AlignUp(section.Size, SectionAlignment),
                    Offset          = section.Offset,
                    VirtualAddress  = section.Address,
                    PhysicalAddress = section.Address,
                    Type            = ProgramHeaderType.Load,
                    Flags           =
                        (section.SectionKind == SectionKind.Text) ? ProgramHeaderFlags.Read | ProgramHeaderFlags.Execute :
                        (section.SectionKind == SectionKind.ROData) ? ProgramHeaderFlags.Read : ProgramHeaderFlags.Read | ProgramHeaderFlags.Write
                };

                programHeader.Write(LinkerFormatType, writer);

                elfheader.ProgramHeaderNumber++;
            }
        }