Beispiel #1
0
 private void WriteStringHeaderSection(EndianAwareBinaryWriter writer)
 {
     stringSection.Name             = AddToStringTable(".shstrtab");
     stringSection.Type             = SectionType.StringTable;
     stringSection.Flags            = (SectionAttribute)0;
     stringSection.Address          = 0;
     stringSection.Offset           = GetSection(SectionKind.ROData).FileOffset + GetSection(SectionKind.ROData).AlignedSize;
     stringSection.Size             = (uint)stringTable.Count;
     stringSection.Link             = 0;
     stringSection.Info             = 0;
     stringSection.AddressAlignment = 0;
     stringSection.EntrySize        = 0;
     stringSection.Write(writer);
 }
Beispiel #2
0
        private static void WriteNullHeaderSection(EndianAwareBinaryWriter writer)
        {
            var nullsection = new SectionHeader();

            nullsection.Name             = 0;
            nullsection.Type             = SectionType.Null;
            nullsection.Flags            = 0;
            nullsection.Address          = 0;
            nullsection.Offset           = 0;
            nullsection.Size             = 0;
            nullsection.Link             = 0;
            nullsection.Info             = 0;
            nullsection.AddressAlignment = 0;
            nullsection.EntrySize        = 0;
            nullsection.Write(writer);
        }
Beispiel #3
0
        private void WriteSectionHeaders(EndianAwareBinaryWriter writer)
        {
            writer.Position = elfheader.SectionHeaderOffset;

            WriteNullHeaderSection(writer);

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

                var sheader = new SectionHeader();

                sheader.Name = AddToStringTable(section.Name);

                switch (section.SectionKind)
                {
                case SectionKind.Text: sheader.Type = SectionType.ProgBits; sheader.Flags = SectionAttribute.AllocExecute; break;

                case SectionKind.Data: sheader.Type = SectionType.ProgBits; sheader.Flags = SectionAttribute.Alloc | SectionAttribute.Write; break;

                case SectionKind.ROData: sheader.Type = SectionType.ProgBits; sheader.Flags = SectionAttribute.Alloc; break;

                case SectionKind.BSS: sheader.Type = SectionType.NoBits; sheader.Flags = SectionAttribute.Alloc | SectionAttribute.Write; break;
                }

                sheader.Address          = (uint)section.VirtualAddress;
                sheader.Offset           = section.FileOffset;
                sheader.Size             = section.AlignedSize;
                sheader.Link             = 0;
                sheader.Info             = 0;
                sheader.AddressAlignment = 0;
                sheader.EntrySize        = 0;
                sheader.Write(writer);
            }

            WriteStringHeaderSection(writer);
        }
Beispiel #4
0
 private static void WriteNullHeaderSection(EndianAwareBinaryWriter writer)
 {
     var nullsection = new SectionHeader();
     nullsection.Name = 0;
     nullsection.Type = SectionType.Null;
     nullsection.Flags = 0;
     nullsection.Address = 0;
     nullsection.Offset = 0;
     nullsection.Size = 0;
     nullsection.Link = 0;
     nullsection.Info = 0;
     nullsection.AddressAlignment = 0;
     nullsection.EntrySize = 0;
     nullsection.Write(writer);
 }
Beispiel #5
0
        private void WriteSectionHeaders(EndianAwareBinaryWriter writer)
        {
            writer.Position = elfheader.SectionHeaderOffset;

            WriteNullHeaderSection(writer);

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

                var sheader = new SectionHeader();

                sheader.Name = AddToStringTable(section.Name);

                switch (section.SectionKind)
                {
                    case SectionKind.Text: sheader.Type = SectionType.ProgBits; sheader.Flags = SectionAttribute.AllocExecute; break;
                    case SectionKind.Data: sheader.Type = SectionType.ProgBits; sheader.Flags = SectionAttribute.Alloc | SectionAttribute.Write; break;
                    case SectionKind.ROData: sheader.Type = SectionType.ProgBits; sheader.Flags = SectionAttribute.Alloc; break;
                    case SectionKind.BSS: sheader.Type = SectionType.NoBits; sheader.Flags = SectionAttribute.Alloc | SectionAttribute.Write; break;
                }

                sheader.Address = (uint)section.VirtualAddress;
                sheader.Offset = section.FileOffset;
                sheader.Size = section.AlignedSize;
                sheader.Link = 0;
                sheader.Info = 0;
                sheader.AddressAlignment = section.SectionAlignment;
                sheader.EntrySize = 0;
                sheader.Write(writer);
            }

            WriteStringHeaderSection(writer);
        }